Annotation of loncom/interface/loncommon.pm, revision 1.1211
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1211 ! raeburn 4: # $Id: loncommon.pm,v 1.1210 2015/04/01 23:22:10 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 74: use DateTime::TimeZone;
1.687 raeburn 75: use DateTime::Locale::Catalog;
1.1091 foxr 76: use Text::Aspell;
1.1094 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1174 raeburn 79: use Crypt::DES;
80: use DynaLoader; # for Crypt::DES version
1.117 www 81:
1.517 raeburn 82: # ---------------------------------------------- Designs
83: use vars qw(%defaultdesign);
84:
1.22 www 85: my $readit;
86:
1.517 raeburn 87:
1.157 matthew 88: ##
89: ## Global Variables
90: ##
1.46 matthew 91:
1.643 foxr 92:
93: # ----------------------------------------------- SSI with retries:
94: #
95:
96: =pod
97:
1.648 raeburn 98: =head1 Server Side include with retries:
1.643 foxr 99:
100: =over 4
101:
1.648 raeburn 102: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 103:
104: Performs an ssi with some number of retries. Retries continue either
105: until the result is ok or until the retry count supplied by the
106: caller is exhausted.
107:
108: Inputs:
1.648 raeburn 109:
110: =over 4
111:
1.643 foxr 112: resource - Identifies the resource to insert.
1.648 raeburn 113:
1.643 foxr 114: retries - Count of the number of retries allowed.
1.648 raeburn 115:
1.643 foxr 116: form - Hash that identifies the rendering options.
117:
1.648 raeburn 118: =back
119:
120: Returns:
121:
122: =over 4
123:
1.643 foxr 124: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 125:
1.643 foxr 126: response - The response from the last attempt (which may or may not have been successful.
127:
1.648 raeburn 128: =back
129:
130: =back
131:
1.643 foxr 132: =cut
133:
134: sub ssi_with_retries {
135: my ($resource, $retries, %form) = @_;
136:
137:
138: my $ok = 0; # True if we got a good response.
139: my $content;
140: my $response;
141:
142: # Try to get the ssi done. within the retries count:
143:
144: do {
145: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
146: $ok = $response->is_success;
1.650 www 147: if (!$ok) {
148: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
149: }
1.643 foxr 150: $retries--;
151: } while (!$ok && ($retries > 0));
152:
153: if (!$ok) {
154: $content = ''; # On error return an empty content.
155: }
156: return ($content, $response);
157:
158: }
159:
160:
161:
1.20 www 162: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 163: my %language;
1.124 www 164: my %supported_language;
1.1088 foxr 165: my %supported_codes;
1.1048 foxr 166: my %latex_language; # For choosing hyphenation in <transl..>
167: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 168: my %cprtag;
1.192 taceyjo1 169: my %scprtag;
1.351 www 170: my %fe; my %fd; my %fm;
1.41 ng 171: my %category_extensions;
1.12 harris41 172:
1.46 matthew 173: # ---------------------------------------------- Thesaurus variables
1.144 matthew 174: #
175: # %Keywords:
176: # A hash used by &keyword to determine if a word is considered a keyword.
177: # $thesaurus_db_file
178: # Scalar containing the full path to the thesaurus database.
1.46 matthew 179:
180: my %Keywords;
181: my $thesaurus_db_file;
182:
1.144 matthew 183: #
184: # Initialize values from language.tab, copyright.tab, filetypes.tab,
185: # thesaurus.tab, and filecategories.tab.
186: #
1.18 www 187: BEGIN {
1.46 matthew 188: # Variable initialization
189: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
190: #
1.22 www 191: unless ($readit) {
1.12 harris41 192: # ------------------------------------------------------------------- languages
193: {
1.158 raeburn 194: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
195: '/language.tab';
196: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 197: while (my $line = <$fh>) {
198: next if ($line=~/^\#/);
199: chomp($line);
1.1088 foxr 200: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 201: $language{$key}=$val.' - '.$enc;
202: if ($sup) {
203: $supported_language{$key}=$sup;
1.1088 foxr 204: $supported_codes{$key} = $code;
1.158 raeburn 205: }
1.1048 foxr 206: if ($latex) {
207: $latex_language_bykey{$key} = $latex;
1.1088 foxr 208: $latex_language{$code} = $latex;
1.1048 foxr 209: }
1.158 raeburn 210: }
211: close($fh);
212: }
1.12 harris41 213: }
214: # ------------------------------------------------------------------ copyrights
215: {
1.158 raeburn 216: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
217: '/copyright.tab';
218: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 219: while (my $line = <$fh>) {
220: next if ($line=~/^\#/);
221: chomp($line);
222: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 223: $cprtag{$key}=$val;
224: }
225: close($fh);
226: }
1.12 harris41 227: }
1.351 www 228: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 229: {
230: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
231: '/source_copyright.tab';
232: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 233: while (my $line = <$fh>) {
234: next if ($line =~ /^\#/);
235: chomp($line);
236: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 237: $scprtag{$key}=$val;
238: }
239: close($fh);
240: }
241: }
1.63 www 242:
1.517 raeburn 243: # -------------------------------------------------------------- default domain designs
1.63 www 244: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 245: my $designfile = $designdir.'/default.tab';
246: if ( open (my $fh,"<$designfile") ) {
247: while (my $line = <$fh>) {
248: next if ($line =~ /^\#/);
249: chomp($line);
250: my ($key,$val)=(split(/\=/,$line));
251: if ($val) { $defaultdesign{$key}=$val; }
252: }
253: close($fh);
1.63 www 254: }
255:
1.15 harris41 256: # ------------------------------------------------------------- file categories
257: {
1.158 raeburn 258: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
259: '/filecategories.tab';
260: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 261: while (my $line = <$fh>) {
262: next if ($line =~ /^\#/);
263: chomp($line);
264: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 265: push @{$category_extensions{lc($category)}},$extension;
266: }
267: close($fh);
268: }
269:
1.15 harris41 270: }
1.12 harris41 271: # ------------------------------------------------------------------ file types
272: {
1.158 raeburn 273: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
274: '/filetypes.tab';
275: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 276: while (my $line = <$fh>) {
277: next if ($line =~ /^\#/);
278: chomp($line);
279: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 280: if ($descr ne '') {
281: $fe{$ending}=lc($emb);
282: $fd{$ending}=$descr;
1.351 www 283: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 284: }
285: }
286: close($fh);
287: }
1.12 harris41 288: }
1.22 www 289: &Apache::lonnet::logthis(
1.705 tempelho 290: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 291: $readit=1;
1.46 matthew 292: } # end of unless($readit)
1.32 matthew 293:
294: }
1.112 bowersj2 295:
1.42 matthew 296: ###############################################################
297: ## HTML and Javascript Helper Functions ##
298: ###############################################################
299:
300: =pod
301:
1.112 bowersj2 302: =head1 HTML and Javascript Functions
1.42 matthew 303:
1.112 bowersj2 304: =over 4
305:
1.648 raeburn 306: =item * &browser_and_searcher_javascript()
1.112 bowersj2 307:
308: X<browsing, javascript>X<searching, javascript>Returns a string
309: containing javascript with two functions, C<openbrowser> and
310: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
311: tags.
1.42 matthew 312:
1.648 raeburn 313: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 314:
315: inputs: formname, elementname, only, omit
316:
317: formname and elementname indicate the name of the html form and name of
318: the element that the results of the browsing selection are to be placed in.
319:
320: Specifying 'only' will restrict the browser to displaying only files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
323: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
1.648 raeburn 326: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 327:
328: Inputs: formname, elementname
329:
330: formname and elementname specify the name of the html form and the name
331: of the element the selection from the search results will be placed in.
1.542 raeburn 332:
1.42 matthew 333: =cut
334:
335: sub browser_and_searcher_javascript {
1.199 albertel 336: my ($mode)=@_;
337: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 338: my $resurl=&escape_single(&lastresurl());
1.42 matthew 339: return <<END;
1.219 albertel 340: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 341: var editbrowser = null;
1.135 albertel 342: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 343: var url = '$resurl/?';
1.42 matthew 344: if (editbrowser == null) {
345: url += 'launch=1&';
346: }
347: url += 'catalogmode=interactive&';
1.199 albertel 348: url += 'mode=$mode&';
1.611 albertel 349: url += 'inhibitmenu=yes&';
1.42 matthew 350: url += 'form=' + formname + '&';
351: if (only != null) {
352: url += 'only=' + only + '&';
1.217 albertel 353: } else {
354: url += 'only=&';
355: }
1.42 matthew 356: if (omit != null) {
357: url += 'omit=' + omit + '&';
1.217 albertel 358: } else {
359: url += 'omit=&';
360: }
1.135 albertel 361: if (titleelement != null) {
362: url += 'titleelement=' + titleelement + '&';
1.217 albertel 363: } else {
364: url += 'titleelement=&';
365: }
1.42 matthew 366: url += 'element=' + elementname + '';
367: var title = 'Browser';
1.435 albertel 368: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 369: options += ',width=700,height=600';
370: editbrowser = open(url,title,options,'1');
371: editbrowser.focus();
372: }
373: var editsearcher;
1.135 albertel 374: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 375: var url = '/adm/searchcat?';
376: if (editsearcher == null) {
377: url += 'launch=1&';
378: }
379: url += 'catalogmode=interactive&';
1.199 albertel 380: url += 'mode=$mode&';
1.42 matthew 381: url += 'form=' + formname + '&';
1.135 albertel 382: if (titleelement != null) {
383: url += 'titleelement=' + titleelement + '&';
1.217 albertel 384: } else {
385: url += 'titleelement=&';
386: }
1.42 matthew 387: url += 'element=' + elementname + '';
388: var title = 'Search';
1.435 albertel 389: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 390: options += ',width=700,height=600';
391: editsearcher = open(url,title,options,'1');
392: editsearcher.focus();
393: }
1.219 albertel 394: // END LON-CAPA Internal -->
1.42 matthew 395: END
1.170 www 396: }
397:
398: sub lastresurl {
1.258 albertel 399: if ($env{'environment.lastresurl'}) {
400: return $env{'environment.lastresurl'}
1.170 www 401: } else {
402: return '/res';
403: }
404: }
405:
406: sub storeresurl {
407: my $resurl=&Apache::lonnet::clutter(shift);
408: unless ($resurl=~/^\/res/) { return 0; }
409: $resurl=~s/\/$//;
410: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 411: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 412: return 1;
1.42 matthew 413: }
414:
1.74 www 415: sub studentbrowser_javascript {
1.111 www 416: unless (
1.258 albertel 417: (($env{'request.course.id'}) &&
1.302 albertel 418: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
419: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
420: '/'.$env{'request.course.sec'})
421: ))
1.258 albertel 422: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 423: ) { return ''; }
1.74 www 424: return (<<'ENDSTDBRW');
1.776 bisitz 425: <script type="text/javascript" language="Javascript">
1.824 bisitz 426: // <![CDATA[
1.74 www 427: var stdeditbrowser;
1.999 www 428: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 429: var url = '/adm/pickstudent?';
430: var filter;
1.558 albertel 431: if (!ignorefilter) {
432: eval('filter=document.'+formname+'.'+uname+'.value;');
433: }
1.74 www 434: if (filter != null) {
435: if (filter != '') {
436: url += 'filter='+filter+'&';
437: }
438: }
439: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 440: '&udomelement='+udom+
441: '&clicker='+clicker;
1.111 www 442: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 443: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 444: var title = 'Student_Browser';
1.74 www 445: var options = 'scrollbars=1,resizable=1,menubar=0';
446: options += ',width=700,height=600';
447: stdeditbrowser = open(url,title,options,'1');
448: stdeditbrowser.focus();
449: }
1.824 bisitz 450: // ]]>
1.74 www 451: </script>
452: ENDSTDBRW
453: }
1.42 matthew 454:
1.1003 www 455: sub resourcebrowser_javascript {
456: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 457: return (<<'ENDRESBRW');
1.1003 www 458: <script type="text/javascript" language="Javascript">
459: // <![CDATA[
460: var reseditbrowser;
1.1004 www 461: function openresbrowser(formname,reslink) {
1.1005 www 462: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 463: var title = 'Resource_Browser';
464: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 465: options += ',width=700,height=500';
1.1004 www 466: reseditbrowser = open(url,title,options,'1');
467: reseditbrowser.focus();
1.1003 www 468: }
469: // ]]>
470: </script>
1.1004 www 471: ENDRESBRW
1.1003 www 472: }
473:
1.74 www 474: sub selectstudent_link {
1.999 www 475: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
476: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
477: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
478: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 479: if ($env{'request.course.id'}) {
1.302 albertel 480: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
481: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
482: '/'.$env{'request.course.sec'})) {
1.111 www 483: return '';
484: }
1.999 www 485: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 486: if ($courseadvonly) {
487: $callargs .= ",'',1,1";
488: }
489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.74 www 492: }
1.258 albertel 493: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 494: $callargs .= ",'',1";
1.793 raeburn 495: return '<span class="LC_nobreak">'.
496: '<a href="javascript:openstdbrowser('.$callargs.');">'.
497: &mt('Select User').'</a></span>';
1.111 www 498: }
499: return '';
1.91 www 500: }
501:
1.1004 www 502: sub selectresource_link {
503: my ($form,$reslink,$arg)=@_;
504:
505: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
506: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
507: unless ($env{'request.course.id'}) { return $arg; }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openresbrowser('.$callargs.');">'.
510: $arg.'</a></span>';
511: }
512:
513:
514:
1.653 raeburn 515: sub authorbrowser_javascript {
516: return <<"ENDAUTHORBRW";
1.776 bisitz 517: <script type="text/javascript" language="JavaScript">
1.824 bisitz 518: // <![CDATA[
1.653 raeburn 519: var stdeditbrowser;
520:
521: function openauthorbrowser(formname,udom) {
522: var url = '/adm/pickauthor?';
523: url += 'form='+formname+'&roledom='+udom;
524: var title = 'Author_Browser';
525: var options = 'scrollbars=1,resizable=1,menubar=0';
526: options += ',width=700,height=600';
527: stdeditbrowser = open(url,title,options,'1');
528: stdeditbrowser.focus();
529: }
530:
1.824 bisitz 531: // ]]>
1.653 raeburn 532: </script>
533: ENDAUTHORBRW
534: }
535:
1.91 www 536: sub coursebrowser_javascript {
1.1116 raeburn 537: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
538: $credits_element) = @_;
1.932 raeburn 539: my $wintitle = 'Course_Browser';
1.931 raeburn 540: if ($crstype eq 'Community') {
1.932 raeburn 541: $wintitle = 'Community_Browser';
1.909 raeburn 542: }
1.876 raeburn 543: my $id_functions = &javascript_index_functions();
544: my $output = '
1.776 bisitz 545: <script type="text/javascript" language="JavaScript">
1.824 bisitz 546: // <![CDATA[
1.468 raeburn 547: var stdeditbrowser;'."\n";
1.876 raeburn 548:
549: $output .= <<"ENDSTDBRW";
1.909 raeburn 550: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 551: var url = '/adm/pickcourse?';
1.895 raeburn 552: var formid = getFormIdByName(formname);
1.876 raeburn 553: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 554: if (domainfilter != null) {
555: if (domainfilter != '') {
556: url += 'domainfilter='+domainfilter+'&';
557: }
558: }
1.91 www 559: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 560: '&cdomelement='+udom+
561: '&cnameelement='+desc;
1.468 raeburn 562: if (extra_element !=null && extra_element != '') {
1.594 raeburn 563: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 564: url += '&roleelement='+extra_element;
565: if (domainfilter == null || domainfilter == '') {
566: url += '&domainfilter='+extra_element;
567: }
1.234 raeburn 568: }
1.468 raeburn 569: else {
570: if (formname == 'portform') {
571: url += '&setroles='+extra_element;
1.800 raeburn 572: } else {
573: if (formname == 'rules') {
574: url += '&fixeddom='+extra_element;
575: }
1.468 raeburn 576: }
577: }
1.230 raeburn 578: }
1.909 raeburn 579: if (type != null && type != '') {
580: url += '&type='+type;
581: }
582: if (type_elem != null && type_elem != '') {
583: url += '&typeelement='+type_elem;
584: }
1.872 raeburn 585: if (formname == 'ccrs') {
586: var ownername = document.forms[formid].ccuname.value;
587: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
588: url += '&cloner='+ownername+':'+ownerdom;
589: }
1.293 raeburn 590: if (multflag !=null && multflag != '') {
591: url += '&multiple='+multflag;
592: }
1.909 raeburn 593: var title = '$wintitle';
1.91 www 594: var options = 'scrollbars=1,resizable=1,menubar=0';
595: options += ',width=700,height=600';
596: stdeditbrowser = open(url,title,options,'1');
597: stdeditbrowser.focus();
598: }
1.876 raeburn 599: $id_functions
600: ENDSTDBRW
1.1116 raeburn 601: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
602: $output .= &setsec_javascript($sec_element,$formname,$role_element,
603: $credits_element);
1.876 raeburn 604: }
605: $output .= '
606: // ]]>
607: </script>';
608: return $output;
609: }
610:
611: sub javascript_index_functions {
612: return <<"ENDJS";
613:
614: function getFormIdByName(formname) {
615: for (var i=0;i<document.forms.length;i++) {
616: if (document.forms[i].name == formname) {
617: return i;
618: }
619: }
620: return -1;
621: }
622:
623: function getIndexByName(formid,item) {
624: for (var i=0;i<document.forms[formid].elements.length;i++) {
625: if (document.forms[formid].elements[i].name == item) {
626: return i;
627: }
628: }
629: return -1;
630: }
1.468 raeburn 631:
1.876 raeburn 632: function getDomainFromSelectbox(formname,udom) {
633: var userdom;
634: var formid = getFormIdByName(formname);
635: if (formid > -1) {
636: var domid = getIndexByName(formid,udom);
637: if (domid > -1) {
638: if (document.forms[formid].elements[domid].type == 'select-one') {
639: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
640: }
641: if (document.forms[formid].elements[domid].type == 'hidden') {
642: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 643: }
644: }
645: }
1.876 raeburn 646: return userdom;
647: }
648:
649: ENDJS
1.468 raeburn 650:
1.876 raeburn 651: }
652:
1.1017 raeburn 653: sub javascript_array_indexof {
1.1018 raeburn 654: return <<ENDJS;
1.1017 raeburn 655: <script type="text/javascript" language="JavaScript">
656: // <![CDATA[
657:
658: if (!Array.prototype.indexOf) {
659: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
660: "use strict";
661: if (this === void 0 || this === null) {
662: throw new TypeError();
663: }
664: var t = Object(this);
665: var len = t.length >>> 0;
666: if (len === 0) {
667: return -1;
668: }
669: var n = 0;
670: if (arguments.length > 0) {
671: n = Number(arguments[1]);
1.1088 foxr 672: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 673: n = 0;
674: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
675: n = (n > 0 || -1) * Math.floor(Math.abs(n));
676: }
677: }
678: if (n >= len) {
679: return -1;
680: }
681: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
682: for (; k < len; k++) {
683: if (k in t && t[k] === searchElement) {
684: return k;
685: }
686: }
687: return -1;
688: }
689: }
690:
691: // ]]>
692: </script>
693:
694: ENDJS
695:
696: }
697:
1.876 raeburn 698: sub userbrowser_javascript {
699: my $id_functions = &javascript_index_functions();
700: return <<"ENDUSERBRW";
701:
1.888 raeburn 702: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 703: var url = '/adm/pickuser?';
704: var userdom = getDomainFromSelectbox(formname,udom);
705: if (userdom != null) {
706: if (userdom != '') {
707: url += 'srchdom='+userdom+'&';
708: }
709: }
710: url += 'form=' + formname + '&unameelement='+uname+
711: '&udomelement='+udom+
712: '&ulastelement='+ulast+
713: '&ufirstelement='+ufirst+
714: '&uemailelement='+uemail+
1.881 raeburn 715: '&hideudomelement='+hideudom+
716: '&coursedom='+crsdom;
1.888 raeburn 717: if ((caller != null) && (caller != undefined)) {
718: url += '&caller='+caller;
719: }
1.876 raeburn 720: var title = 'User_Browser';
721: var options = 'scrollbars=1,resizable=1,menubar=0';
722: options += ',width=700,height=600';
723: var stdeditbrowser = open(url,title,options,'1');
724: stdeditbrowser.focus();
725: }
726:
1.888 raeburn 727: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 728: var formid = getFormIdByName(formname);
729: if (formid > -1) {
1.888 raeburn 730: var unameid = getIndexByName(formid,uname);
1.876 raeburn 731: var domid = getIndexByName(formid,udom);
732: var hidedomid = getIndexByName(formid,origdom);
733: if (hidedomid > -1) {
734: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 735: var unameval = document.forms[formid].elements[unameid].value;
736: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
737: if (domid > -1) {
738: var slct = document.forms[formid].elements[domid];
739: if (slct.type == 'select-one') {
740: var i;
741: for (i=0;i<slct.length;i++) {
742: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
743: }
744: }
745: if (slct.type == 'hidden') {
746: slct.value = fixeddom;
1.876 raeburn 747: }
748: }
1.468 raeburn 749: }
750: }
751: }
1.876 raeburn 752: return;
753: }
754:
755: $id_functions
756: ENDUSERBRW
1.468 raeburn 757: }
758:
759: sub setsec_javascript {
1.1116 raeburn 760: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 761: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
762: $communityrolestr);
763: if ($role_element ne '') {
764: my @allroles = ('st','ta','ep','in','ad');
765: foreach my $crstype ('Course','Community') {
766: if ($crstype eq 'Community') {
767: foreach my $role (@allroles) {
768: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
769: }
770: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
771: } else {
772: foreach my $role (@allroles) {
773: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
774: }
775: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
776: }
777: }
778: $rolestr = '"'.join('","',@allroles).'"';
779: $courserolestr = '"'.join('","',@courserolenames).'"';
780: $communityrolestr = '"'.join('","',@communityrolenames).'"';
781: }
1.468 raeburn 782: my $setsections = qq|
783: function setSect(sectionlist) {
1.629 raeburn 784: var sectionsArray = new Array();
785: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
786: sectionsArray = sectionlist.split(",");
787: }
1.468 raeburn 788: var numSections = sectionsArray.length;
789: document.$formname.$sec_element.length = 0;
790: if (numSections == 0) {
791: document.$formname.$sec_element.multiple=false;
792: document.$formname.$sec_element.size=1;
793: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
794: } else {
795: if (numSections == 1) {
796: document.$formname.$sec_element.multiple=false;
797: document.$formname.$sec_element.size=1;
798: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
799: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
800: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
801: } else {
802: for (var i=0; i<numSections; i++) {
803: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
804: }
805: document.$formname.$sec_element.multiple=true
806: if (numSections < 3) {
807: document.$formname.$sec_element.size=numSections;
808: } else {
809: document.$formname.$sec_element.size=3;
810: }
811: document.$formname.$sec_element.options[0].selected = false
812: }
813: }
1.91 www 814: }
1.905 raeburn 815:
816: function setRole(crstype) {
1.468 raeburn 817: |;
1.905 raeburn 818: if ($role_element eq '') {
819: $setsections .= ' return;
820: }
821: ';
822: } else {
823: $setsections .= qq|
824: var elementLength = document.$formname.$role_element.length;
825: var allroles = Array($rolestr);
826: var courserolenames = Array($courserolestr);
827: var communityrolenames = Array($communityrolestr);
828: if (elementLength != undefined) {
829: if (document.$formname.$role_element.options[5].value == 'cc') {
830: if (crstype == 'Course') {
831: return;
832: } else {
833: allroles[5] = 'co';
834: for (var i=0; i<6; i++) {
835: document.$formname.$role_element.options[i].value = allroles[i];
836: document.$formname.$role_element.options[i].text = communityrolenames[i];
837: }
838: }
839: } else {
840: if (crstype == 'Community') {
841: return;
842: } else {
843: allroles[5] = 'cc';
844: for (var i=0; i<6; i++) {
845: document.$formname.$role_element.options[i].value = allroles[i];
846: document.$formname.$role_element.options[i].text = courserolenames[i];
847: }
848: }
849: }
850: }
851: return;
852: }
853: |;
854: }
1.1116 raeburn 855: if ($credits_element) {
856: $setsections .= qq|
857: function setCredits(defaultcredits) {
858: document.$formname.$credits_element.value = defaultcredits;
859: return;
860: }
861: |;
862: }
1.468 raeburn 863: return $setsections;
864: }
865:
1.91 www 866: sub selectcourse_link {
1.909 raeburn 867: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
868: $typeelement) = @_;
869: my $type = $selecttype;
1.871 raeburn 870: my $linktext = &mt('Select Course');
871: if ($selecttype eq 'Community') {
1.909 raeburn 872: $linktext = &mt('Select Community');
1.906 raeburn 873: } elsif ($selecttype eq 'Course/Community') {
874: $linktext = &mt('Select Course/Community');
1.909 raeburn 875: $type = '';
1.1019 raeburn 876: } elsif ($selecttype eq 'Select') {
877: $linktext = &mt('Select');
878: $type = '';
1.871 raeburn 879: }
1.787 bisitz 880: return '<span class="LC_nobreak">'
881: ."<a href='"
882: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
883: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 884: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 885: ."'>".$linktext.'</a>'
1.787 bisitz 886: .'</span>';
1.74 www 887: }
1.42 matthew 888:
1.653 raeburn 889: sub selectauthor_link {
890: my ($form,$udom)=@_;
891: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
892: &mt('Select Author').'</a>';
893: }
894:
1.876 raeburn 895: sub selectuser_link {
1.881 raeburn 896: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 897: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 898: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 899: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 900: ');">'.$linktext.'</a>';
1.876 raeburn 901: }
902:
1.273 raeburn 903: sub check_uncheck_jscript {
904: my $jscript = <<"ENDSCRT";
905: function checkAll(field) {
906: if (field.length > 0) {
907: for (i = 0; i < field.length; i++) {
1.1093 raeburn 908: if (!field[i].disabled) {
909: field[i].checked = true;
910: }
1.273 raeburn 911: }
912: } else {
1.1093 raeburn 913: if (!field.disabled) {
914: field.checked = true;
915: }
1.273 raeburn 916: }
917: }
918:
919: function uncheckAll(field) {
920: if (field.length > 0) {
921: for (i = 0; i < field.length; i++) {
922: field[i].checked = false ;
1.543 albertel 923: }
924: } else {
1.273 raeburn 925: field.checked = false ;
926: }
927: }
928: ENDSCRT
929: return $jscript;
930: }
931:
1.656 www 932: sub select_timezone {
1.659 raeburn 933: my ($name,$selected,$onchange,$includeempty)=@_;
934: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
935: if ($includeempty) {
936: $output .= '<option value=""';
937: if (($selected eq '') || ($selected eq 'local')) {
938: $output .= ' selected="selected" ';
939: }
940: $output .= '> </option>';
941: }
1.657 raeburn 942: my @timezones = DateTime::TimeZone->all_names;
943: foreach my $tzone (@timezones) {
944: $output.= '<option value="'.$tzone.'"';
945: if ($tzone eq $selected) {
946: $output.=' selected="selected"';
947: }
948: $output.=">$tzone</option>\n";
1.656 www 949: }
950: $output.="</select>";
951: return $output;
952: }
1.273 raeburn 953:
1.687 raeburn 954: sub select_datelocale {
955: my ($name,$selected,$onchange,$includeempty)=@_;
956: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
957: if ($includeempty) {
958: $output .= '<option value=""';
959: if ($selected eq '') {
960: $output .= ' selected="selected" ';
961: }
962: $output .= '> </option>';
963: }
964: my (@possibles,%locale_names);
965: my @locales = DateTime::Locale::Catalog::Locales;
966: foreach my $locale (@locales) {
967: if (ref($locale) eq 'HASH') {
968: my $id = $locale->{'id'};
969: if ($id ne '') {
970: my $en_terr = $locale->{'en_territory'};
971: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 972: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 973: if (grep(/^en$/,@languages) || !@languages) {
974: if ($en_terr ne '') {
975: $locale_names{$id} = '('.$en_terr.')';
976: } elsif ($native_terr ne '') {
977: $locale_names{$id} = $native_terr;
978: }
979: } else {
980: if ($native_terr ne '') {
981: $locale_names{$id} = $native_terr.' ';
982: } elsif ($en_terr ne '') {
983: $locale_names{$id} = '('.$en_terr.')';
984: }
985: }
986: push (@possibles,$id);
987: }
988: }
989: }
990: foreach my $item (sort(@possibles)) {
991: $output.= '<option value="'.$item.'"';
992: if ($item eq $selected) {
993: $output.=' selected="selected"';
994: }
995: $output.=">$item";
996: if ($locale_names{$item} ne '') {
997: $output.=" $locale_names{$item}</option>\n";
998: }
999: $output.="</option>\n";
1000: }
1001: $output.="</select>";
1002: return $output;
1003: }
1004:
1.792 raeburn 1005: sub select_language {
1006: my ($name,$selected,$includeempty) = @_;
1007: my %langchoices;
1008: if ($includeempty) {
1.1117 raeburn 1009: %langchoices = ('' => 'No language preference');
1.792 raeburn 1010: }
1011: foreach my $id (&languageids()) {
1012: my $code = &supportedlanguagecode($id);
1013: if ($code) {
1014: $langchoices{$code} = &plainlanguagedescription($id);
1015: }
1016: }
1.1117 raeburn 1017: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1018: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1019: }
1020:
1.42 matthew 1021: =pod
1.36 matthew 1022:
1.1088 foxr 1023:
1024: =item * &list_languages()
1025:
1026: Returns an array reference that is suitable for use in language prompters.
1027: Each array element is itself a two element array. The first element
1028: is the language code. The second element a descsriptiuon of the
1029: language itself. This is suitable for use in e.g.
1030: &Apache::edit::select_arg (once dereferenced that is).
1031:
1032: =cut
1033:
1034: sub list_languages {
1035: my @lang_choices;
1036:
1037: foreach my $id (&languageids()) {
1038: my $code = &supportedlanguagecode($id);
1039: if ($code) {
1040: my $selector = $supported_codes{$id};
1041: my $description = &plainlanguagedescription($id);
1042: push (@lang_choices, [$selector, $description]);
1043: }
1044: }
1045: return \@lang_choices;
1046: }
1047:
1048: =pod
1049:
1.648 raeburn 1050: =item * &linked_select_forms(...)
1.36 matthew 1051:
1052: linked_select_forms returns a string containing a <script></script> block
1053: and html for two <select> menus. The select menus will be linked in that
1054: changing the value of the first menu will result in new values being placed
1055: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1056: order unless a defined order is provided.
1.36 matthew 1057:
1058: linked_select_forms takes the following ordered inputs:
1059:
1060: =over 4
1061:
1.112 bowersj2 1062: =item * $formname, the name of the <form> tag
1.36 matthew 1063:
1.112 bowersj2 1064: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1065:
1.112 bowersj2 1066: =item * $firstdefault, the default value for the first menu
1.36 matthew 1067:
1.112 bowersj2 1068: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1069:
1.112 bowersj2 1070: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1071:
1.112 bowersj2 1072: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1073:
1.609 raeburn 1074: =item * $menuorder, the order of values in the first menu
1075:
1.1115 raeburn 1076: =item * $onchangefirst, additional javascript call to execute for an onchange
1077: event for the first <select> tag
1078:
1079: =item * $onchangesecond, additional javascript call to execute for an onchange
1080: event for the second <select> tag
1081:
1.41 ng 1082: =back
1083:
1.36 matthew 1084: Below is an example of such a hash. Only the 'text', 'default', and
1085: 'select2' keys must appear as stated. keys(%menu) are the possible
1086: values for the first select menu. The text that coincides with the
1.41 ng 1087: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1088: and text for the second menu are given in the hash pointed to by
1089: $menu{$choice1}->{'select2'}.
1090:
1.112 bowersj2 1091: my %menu = ( A1 => { text =>"Choice A1" ,
1092: default => "B3",
1093: select2 => {
1094: B1 => "Choice B1",
1095: B2 => "Choice B2",
1096: B3 => "Choice B3",
1097: B4 => "Choice B4"
1.609 raeburn 1098: },
1099: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1100: },
1101: A2 => { text =>"Choice A2" ,
1102: default => "C2",
1103: select2 => {
1104: C1 => "Choice C1",
1105: C2 => "Choice C2",
1106: C3 => "Choice C3"
1.609 raeburn 1107: },
1108: order => ['C2','C1','C3'],
1.112 bowersj2 1109: },
1110: A3 => { text =>"Choice A3" ,
1111: default => "D6",
1112: select2 => {
1113: D1 => "Choice D1",
1114: D2 => "Choice D2",
1115: D3 => "Choice D3",
1116: D4 => "Choice D4",
1117: D5 => "Choice D5",
1118: D6 => "Choice D6",
1119: D7 => "Choice D7"
1.609 raeburn 1120: },
1121: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1122: }
1123: );
1.36 matthew 1124:
1125: =cut
1126:
1127: sub linked_select_forms {
1128: my ($formname,
1129: $middletext,
1130: $firstdefault,
1131: $firstselectname,
1132: $secondselectname,
1.609 raeburn 1133: $hashref,
1134: $menuorder,
1.1115 raeburn 1135: $onchangefirst,
1136: $onchangesecond
1.36 matthew 1137: ) = @_;
1138: my $second = "document.$formname.$secondselectname";
1139: my $first = "document.$formname.$firstselectname";
1140: # output the javascript to do the changing
1141: my $result = '';
1.776 bisitz 1142: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1143: $result.="// <![CDATA[\n";
1.36 matthew 1144: $result.="var select2data = new Object();\n";
1145: $" = '","';
1146: my $debug = '';
1147: foreach my $s1 (sort(keys(%$hashref))) {
1148: $result.="select2data.d_$s1 = new Object();\n";
1149: $result.="select2data.d_$s1.def = new String('".
1150: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1151: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1152: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1153: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1154: @s2values = @{$hashref->{$s1}->{'order'}};
1155: }
1.36 matthew 1156: $result.="\"@s2values\");\n";
1157: $result.="select2data.d_$s1.texts = new Array(";
1158: my @s2texts;
1159: foreach my $value (@s2values) {
1160: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1161: }
1162: $result.="\"@s2texts\");\n";
1163: }
1164: $"=' ';
1165: $result.= <<"END";
1166:
1167: function select1_changed() {
1168: // Determine new choice
1169: var newvalue = "d_" + $first.value;
1170: // update select2
1171: var values = select2data[newvalue].values;
1172: var texts = select2data[newvalue].texts;
1173: var select2def = select2data[newvalue].def;
1174: var i;
1175: // out with the old
1176: for (i = 0; i < $second.options.length; i++) {
1177: $second.options[i] = null;
1178: }
1179: // in with the nuclear
1180: for (i=0;i<values.length; i++) {
1181: $second.options[i] = new Option(values[i]);
1.143 matthew 1182: $second.options[i].value = values[i];
1.36 matthew 1183: $second.options[i].text = texts[i];
1184: if (values[i] == select2def) {
1185: $second.options[i].selected = true;
1186: }
1187: }
1188: }
1.824 bisitz 1189: // ]]>
1.36 matthew 1190: </script>
1191: END
1192: # output the initial values for the selection lists
1.1115 raeburn 1193: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1194: my @order = sort(keys(%{$hashref}));
1195: if (ref($menuorder) eq 'ARRAY') {
1196: @order = @{$menuorder};
1197: }
1198: foreach my $value (@order) {
1.36 matthew 1199: $result.=" <option value=\"$value\" ";
1.253 albertel 1200: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1201: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1202: }
1203: $result .= "</select>\n";
1204: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1205: $result .= $middletext;
1.1115 raeburn 1206: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1207: if ($onchangesecond) {
1208: $result .= ' onchange="'.$onchangesecond.'"';
1209: }
1210: $result .= ">\n";
1.36 matthew 1211: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1212:
1213: my @secondorder = sort(keys(%select2));
1214: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1215: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1216: }
1217: foreach my $value (@secondorder) {
1.36 matthew 1218: $result.=" <option value=\"$value\" ";
1.253 albertel 1219: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1220: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1221: }
1222: $result .= "</select>\n";
1223: # return $debug;
1224: return $result;
1225: } # end of sub linked_select_forms {
1226:
1.45 matthew 1227: =pod
1.44 bowersj2 1228:
1.973 raeburn 1229: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1230:
1.112 bowersj2 1231: Returns a string corresponding to an HTML link to the given help
1232: $topic, where $topic corresponds to the name of a .tex file in
1233: /home/httpd/html/adm/help/tex, with underscores replaced by
1234: spaces.
1235:
1236: $text will optionally be linked to the same topic, allowing you to
1237: link text in addition to the graphic. If you do not want to link
1238: text, but wish to specify one of the later parameters, pass an
1239: empty string.
1240:
1241: $stayOnPage is a value that will be interpreted as a boolean. If true,
1242: the link will not open a new window. If false, the link will open
1243: a new window using Javascript. (Default is false.)
1244:
1245: $width and $height are optional numerical parameters that will
1246: override the width and height of the popped up window, which may
1.973 raeburn 1247: be useful for certain help topics with big pictures included.
1248:
1249: $imgid is the id of the img tag used for the help icon. This may be
1250: used in a javascript call to switch the image src. See
1251: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1252:
1253: =cut
1254:
1255: sub help_open_topic {
1.973 raeburn 1256: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1257: $text = "" if (not defined $text);
1.44 bowersj2 1258: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1259: $width = 500 if (not defined $width);
1.44 bowersj2 1260: $height = 400 if (not defined $height);
1261: my $filename = $topic;
1262: $filename =~ s/ /_/g;
1263:
1.48 bowersj2 1264: my $template = "";
1265: my $link;
1.572 banghart 1266:
1.159 www 1267: $topic=~s/\W/\_/g;
1.44 bowersj2 1268:
1.572 banghart 1269: if (!$stayOnPage) {
1.1033 www 1270: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1271: } elsif ($stayOnPage eq 'popup') {
1272: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1273: } else {
1.48 bowersj2 1274: $link = "/adm/help/${filename}.hlp";
1275: }
1276:
1277: # Add the text
1.755 neumanie 1278: if ($text ne "") {
1.763 bisitz 1279: $template.='<span class="LC_help_open_topic">'
1280: .'<a target="_top" href="'.$link.'">'
1281: .$text.'</a>';
1.48 bowersj2 1282: }
1283:
1.763 bisitz 1284: # (Always) Add the graphic
1.179 matthew 1285: my $title = &mt('Online Help');
1.667 raeburn 1286: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1287: if ($imgid ne '') {
1288: $imgid = ' id="'.$imgid.'"';
1289: }
1.763 bisitz 1290: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1291: .'<img src="'.$helpicon.'" border="0"'
1292: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1293: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1294: .' /></a>';
1295: if ($text ne "") {
1296: $template.='</span>';
1297: }
1.44 bowersj2 1298: return $template;
1299:
1.106 bowersj2 1300: }
1301:
1302: # This is a quicky function for Latex cheatsheet editing, since it
1303: # appears in at least four places
1304: sub helpLatexCheatsheet {
1.1037 www 1305: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1306: my $out;
1.106 bowersj2 1307: my $addOther = '';
1.732 raeburn 1308: if ($topic) {
1.1037 www 1309: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1310: }
1311: $out = '<span>' # Start cheatsheet
1312: .$addOther
1313: .'<span>'
1.1037 www 1314: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1315: .'</span> <span>'
1.1037 www 1316: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1317: .'</span>';
1.732 raeburn 1318: unless ($not_author) {
1.1186 kruse 1319: $out .= '<span>'
1320: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1321: .'</span> <span>'
1322: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1323: .'</span>';
1.732 raeburn 1324: }
1.763 bisitz 1325: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1326: return $out;
1.172 www 1327: }
1328:
1.430 albertel 1329: sub general_help {
1330: my $helptopic='Student_Intro';
1331: if ($env{'request.role'}=~/^(ca|au)/) {
1332: $helptopic='Authoring_Intro';
1.907 raeburn 1333: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1334: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1335: } elsif ($env{'request.role'}=~/^dc/) {
1336: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1337: }
1338: return $helptopic;
1339: }
1340:
1341: sub update_help_link {
1342: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1343: my $origurl = $ENV{'REQUEST_URI'};
1344: $origurl=~s|^/~|/priv/|;
1345: my $timestamp = time;
1346: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1347: $$datum = &escape($$datum);
1348: }
1349:
1350: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1351: my $output .= <<"ENDOUTPUT";
1352: <script type="text/javascript">
1.824 bisitz 1353: // <![CDATA[
1.430 albertel 1354: banner_link = '$banner_link';
1.824 bisitz 1355: // ]]>
1.430 albertel 1356: </script>
1357: ENDOUTPUT
1358: return $output;
1359: }
1360:
1361: # now just updates the help link and generates a blue icon
1.193 raeburn 1362: sub help_open_menu {
1.430 albertel 1363: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1364: = @_;
1.949 droeschl 1365: $stayOnPage = 1;
1.430 albertel 1366: my $output;
1367: if ($component_help) {
1368: if (!$text) {
1369: $output=&help_open_topic($component_help,undef,$stayOnPage,
1370: $width,$height);
1371: } else {
1372: my $help_text;
1373: $help_text=&unescape($topic);
1374: $output='<table><tr><td>'.
1375: &help_open_topic($component_help,$help_text,$stayOnPage,
1376: $width,$height).'</td></tr></table>';
1377: }
1378: }
1379: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1380: return $output.$banner_link;
1381: }
1382:
1383: sub top_nav_help {
1384: my ($text) = @_;
1.436 albertel 1385: $text = &mt($text);
1.949 droeschl 1386: my $stay_on_page = 1;
1387:
1.1168 raeburn 1388: my ($link,$banner_link);
1389: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1390: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1391: : "javascript:helpMenu('open')";
1392: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1393: }
1.201 raeburn 1394: my $title = &mt('Get help');
1.1168 raeburn 1395: if ($link) {
1396: return <<"END";
1.436 albertel 1397: $banner_link
1.1159 raeburn 1398: <a href="$link" title="$title">$text</a>
1.436 albertel 1399: END
1.1168 raeburn 1400: } else {
1401: return ' '.$text.' ';
1402: }
1.436 albertel 1403: }
1404:
1405: sub help_menu_js {
1.1154 raeburn 1406: my ($httphost) = @_;
1.949 droeschl 1407: my $stayOnPage = 1;
1.436 albertel 1408: my $width = 620;
1409: my $height = 600;
1.430 albertel 1410: my $helptopic=&general_help();
1.1154 raeburn 1411: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1412: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1413: my $start_page =
1414: &Apache::loncommon::start_page('Help Menu', undef,
1415: {'frameset' => 1,
1416: 'js_ready' => 1,
1.1154 raeburn 1417: 'use_absolute' => $httphost,
1.331 albertel 1418: 'add_entries' => {
1.1168 raeburn 1419: 'border' => '0',
1.579 raeburn 1420: 'rows' => "110,*",},});
1.331 albertel 1421: my $end_page =
1422: &Apache::loncommon::end_page({'frameset' => 1,
1423: 'js_ready' => 1,});
1424:
1.436 albertel 1425: my $template .= <<"ENDTEMPLATE";
1426: <script type="text/javascript">
1.877 bisitz 1427: // <![CDATA[
1.253 albertel 1428: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1429: var banner_link = '';
1.243 raeburn 1430: function helpMenu(target) {
1431: var caller = this;
1432: if (target == 'open') {
1433: var newWindow = null;
1434: try {
1.262 albertel 1435: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1436: }
1437: catch(error) {
1438: writeHelp(caller);
1439: return;
1440: }
1441: if (newWindow) {
1442: caller = newWindow;
1443: }
1.193 raeburn 1444: }
1.243 raeburn 1445: writeHelp(caller);
1446: return;
1447: }
1448: function writeHelp(caller) {
1.1168 raeburn 1449: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1450: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1451: caller.document.close();
1452: caller.focus();
1.193 raeburn 1453: }
1.877 bisitz 1454: // END LON-CAPA Internal -->
1.253 albertel 1455: // ]]>
1.436 albertel 1456: </script>
1.193 raeburn 1457: ENDTEMPLATE
1458: return $template;
1459: }
1460:
1.172 www 1461: sub help_open_bug {
1462: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1463: unless ($env{'user.adv'}) { return ''; }
1.172 www 1464: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1465: $text = "" if (not defined $text);
1466: $stayOnPage=1;
1.184 albertel 1467: $width = 600 if (not defined $width);
1468: $height = 600 if (not defined $height);
1.172 www 1469:
1470: $topic=~s/\W+/\+/g;
1471: my $link='';
1472: my $template='';
1.379 albertel 1473: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1474: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1475: if (!$stayOnPage)
1476: {
1477: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1478: }
1479: else
1480: {
1481: $link = $url;
1482: }
1483: # Add the text
1484: if ($text ne "")
1485: {
1486: $template .=
1487: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1488: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1489: }
1490:
1491: # Add the graphic
1.179 matthew 1492: my $title = &mt('Report a Bug');
1.215 albertel 1493: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1494: $template .= <<"ENDTEMPLATE";
1.436 albertel 1495: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1496: ENDTEMPLATE
1497: if ($text ne '') { $template.='</td></tr></table>' };
1498: return $template;
1499:
1500: }
1501:
1502: sub help_open_faq {
1503: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1504: unless ($env{'user.adv'}) { return ''; }
1.172 www 1505: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1506: $text = "" if (not defined $text);
1507: $stayOnPage=1;
1508: $width = 350 if (not defined $width);
1509: $height = 400 if (not defined $height);
1510:
1511: $topic=~s/\W+/\+/g;
1512: my $link='';
1513: my $template='';
1514: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1515: if (!$stayOnPage)
1516: {
1517: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1518: }
1519: else
1520: {
1521: $link = $url;
1522: }
1523:
1524: # Add the text
1525: if ($text ne "")
1526: {
1527: $template .=
1.173 www 1528: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1529: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1530: }
1531:
1532: # Add the graphic
1.179 matthew 1533: my $title = &mt('View the FAQ');
1.215 albertel 1534: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1535: $template .= <<"ENDTEMPLATE";
1.436 albertel 1536: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1537: ENDTEMPLATE
1538: if ($text ne '') { $template.='</td></tr></table>' };
1539: return $template;
1540:
1.44 bowersj2 1541: }
1.37 matthew 1542:
1.180 matthew 1543: ###############################################################
1544: ###############################################################
1545:
1.45 matthew 1546: =pod
1547:
1.648 raeburn 1548: =item * &change_content_javascript():
1.256 matthew 1549:
1550: This and the next function allow you to create small sections of an
1551: otherwise static HTML page that you can update on the fly with
1552: Javascript, even in Netscape 4.
1553:
1554: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1555: must be written to the HTML page once. It will prove the Javascript
1556: function "change(name, content)". Calling the change function with the
1557: name of the section
1558: you want to update, matching the name passed to C<changable_area>, and
1559: the new content you want to put in there, will put the content into
1560: that area.
1561:
1562: B<Note>: Netscape 4 only reserves enough space for the changable area
1563: to contain room for the original contents. You need to "make space"
1564: for whatever changes you wish to make, and be B<sure> to check your
1565: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1566: it's adequate for updating a one-line status display, but little more.
1567: This script will set the space to 100% width, so you only need to
1568: worry about height in Netscape 4.
1569:
1570: Modern browsers are much less limiting, and if you can commit to the
1571: user not using Netscape 4, this feature may be used freely with
1572: pretty much any HTML.
1573:
1574: =cut
1575:
1576: sub change_content_javascript {
1577: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1578: if ($env{'browser.type'} eq 'netscape' &&
1579: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1580: return (<<NETSCAPE4);
1581: function change(name, content) {
1582: doc = document.layers[name+"___escape"].layers[0].document;
1583: doc.open();
1584: doc.write(content);
1585: doc.close();
1586: }
1587: NETSCAPE4
1588: } else {
1589: # Otherwise, we need to use semi-standards-compliant code
1590: # (technically, "innerHTML" isn't standard but the equivalent
1591: # is really scary, and every useful browser supports it
1592: return (<<DOMBASED);
1593: function change(name, content) {
1594: element = document.getElementById(name);
1595: element.innerHTML = content;
1596: }
1597: DOMBASED
1598: }
1599: }
1600:
1601: =pod
1602:
1.648 raeburn 1603: =item * &changable_area($name,$origContent):
1.256 matthew 1604:
1605: This provides a "changable area" that can be modified on the fly via
1606: the Javascript code provided in C<change_content_javascript>. $name is
1607: the name you will use to reference the area later; do not repeat the
1608: same name on a given HTML page more then once. $origContent is what
1609: the area will originally contain, which can be left blank.
1610:
1611: =cut
1612:
1613: sub changable_area {
1614: my ($name, $origContent) = @_;
1615:
1.258 albertel 1616: if ($env{'browser.type'} eq 'netscape' &&
1617: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1618: # If this is netscape 4, we need to use the Layer tag
1619: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1620: } else {
1621: return "<span id='$name'>$origContent</span>";
1622: }
1623: }
1624:
1625: =pod
1626:
1.648 raeburn 1627: =item * &viewport_geometry_js
1.590 raeburn 1628:
1629: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1630:
1631: =cut
1632:
1633:
1634: sub viewport_geometry_js {
1635: return <<"GEOMETRY";
1636: var Geometry = {};
1637: function init_geometry() {
1638: if (Geometry.init) { return };
1639: Geometry.init=1;
1640: if (window.innerHeight) {
1641: Geometry.getViewportHeight = function() { return window.innerHeight; };
1642: Geometry.getViewportWidth = function() { return window.innerWidth; };
1643: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1644: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1645: }
1646: else if (document.documentElement && document.documentElement.clientHeight) {
1647: Geometry.getViewportHeight =
1648: function() { return document.documentElement.clientHeight; };
1649: Geometry.getViewportWidth =
1650: function() { return document.documentElement.clientWidth; };
1651:
1652: Geometry.getHorizontalScroll =
1653: function() { return document.documentElement.scrollLeft; };
1654: Geometry.getVerticalScroll =
1655: function() { return document.documentElement.scrollTop; };
1656: }
1657: else if (document.body.clientHeight) {
1658: Geometry.getViewportHeight =
1659: function() { return document.body.clientHeight; };
1660: Geometry.getViewportWidth =
1661: function() { return document.body.clientWidth; };
1662: Geometry.getHorizontalScroll =
1663: function() { return document.body.scrollLeft; };
1664: Geometry.getVerticalScroll =
1665: function() { return document.body.scrollTop; };
1666: }
1667: }
1668:
1669: GEOMETRY
1670: }
1671:
1672: =pod
1673:
1.648 raeburn 1674: =item * &viewport_size_js()
1.590 raeburn 1675:
1676: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1677:
1678: =cut
1679:
1680: sub viewport_size_js {
1681: my $geometry = &viewport_geometry_js();
1682: return <<"DIMS";
1683:
1684: $geometry
1685:
1686: function getViewportDims(width,height) {
1687: init_geometry();
1688: width.value = Geometry.getViewportWidth();
1689: height.value = Geometry.getViewportHeight();
1690: return;
1691: }
1692:
1693: DIMS
1694: }
1695:
1696: =pod
1697:
1.648 raeburn 1698: =item * &resize_textarea_js()
1.565 albertel 1699:
1700: emits the needed javascript to resize a textarea to be as big as possible
1701:
1702: creates a function resize_textrea that takes two IDs first should be
1703: the id of the element to resize, second should be the id of a div that
1704: surrounds everything that comes after the textarea, this routine needs
1705: to be attached to the <body> for the onload and onresize events.
1706:
1.648 raeburn 1707: =back
1.565 albertel 1708:
1709: =cut
1710:
1711: sub resize_textarea_js {
1.590 raeburn 1712: my $geometry = &viewport_geometry_js();
1.565 albertel 1713: return <<"RESIZE";
1714: <script type="text/javascript">
1.824 bisitz 1715: // <![CDATA[
1.590 raeburn 1716: $geometry
1.565 albertel 1717:
1.588 albertel 1718: function getX(element) {
1719: var x = 0;
1720: while (element) {
1721: x += element.offsetLeft;
1722: element = element.offsetParent;
1723: }
1724: return x;
1725: }
1726: function getY(element) {
1727: var y = 0;
1728: while (element) {
1729: y += element.offsetTop;
1730: element = element.offsetParent;
1731: }
1732: return y;
1733: }
1734:
1735:
1.565 albertel 1736: function resize_textarea(textarea_id,bottom_id) {
1737: init_geometry();
1738: var textarea = document.getElementById(textarea_id);
1739: //alert(textarea);
1740:
1.588 albertel 1741: var textarea_top = getY(textarea);
1.565 albertel 1742: var textarea_height = textarea.offsetHeight;
1743: var bottom = document.getElementById(bottom_id);
1.588 albertel 1744: var bottom_top = getY(bottom);
1.565 albertel 1745: var bottom_height = bottom.offsetHeight;
1746: var window_height = Geometry.getViewportHeight();
1.588 albertel 1747: var fudge = 23;
1.565 albertel 1748: var new_height = window_height-fudge-textarea_top-bottom_height;
1749: if (new_height < 300) {
1750: new_height = 300;
1751: }
1752: textarea.style.height=new_height+'px';
1753: }
1.824 bisitz 1754: // ]]>
1.565 albertel 1755: </script>
1756: RESIZE
1757:
1758: }
1759:
1.1205 golterma 1760: sub colorfuleditor_js {
1761: return <<"COLORFULEDIT"
1762: <script type="text/javascript">
1763: // <![CDATA[>
1764: function fold_box(curDepth, lastresource){
1765:
1766: // we need a list because there can be several blocks you need to fold in one tag
1767: var block = document.getElementsByName('foldblock_'+curDepth);
1768: // but there is only one folding button per tag
1769: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1770:
1771: if(block.item(0).style.display == 'none'){
1772:
1773: foldbutton.value = '@{[&mt("Hide")]}';
1774: for (i = 0; i < block.length; i++){
1775: block.item(i).style.display = '';
1776: }
1777: }else{
1778:
1779: foldbutton.value = '@{[&mt("Show")]}';
1780: for (i = 0; i < block.length; i++){
1781: // block.item(i).style.visibility = 'collapse';
1782: block.item(i).style.display = 'none';
1783: }
1784: };
1785: saveState(lastresource);
1786: }
1787:
1788: function saveState (lastresource) {
1789:
1790: var tag_list = getTagList();
1791: if(tag_list != null){
1792: var timestamp = new Date().getTime();
1793: var key = lastresource;
1794:
1795: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1796: // starting with timestamp
1797: var value = timestamp+';';
1798:
1799: // building the list of key-value pairs
1800: for(var i = 0; i < tag_list.length; i++){
1801: value += tag_list[i]+',';
1802: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1803: }
1804:
1805: // only iterate whole storage if nothing to override
1806: if(localStorage.getItem(key) == null){
1807:
1808: // prevent storage from growing large
1809: if(localStorage.length > 50){
1810: var regex_getTimestamp = /^(?:\d)+;/;
1811: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1812: var oldest_key;
1813:
1814: for(var i = 1; i < localStorage.length; i++){
1815: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1816: oldest_key = localStorage.key(i);
1817: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1818: }
1819: }
1820: localStorage.removeItem(oldest_key);
1821: }
1822: }
1823: localStorage.setItem(key,value);
1824: }
1825: }
1826:
1827: // restore folding status of blocks (on page load)
1828: function restoreState (lastresource) {
1829: if(localStorage.getItem(lastresource) != null){
1830: var key = lastresource;
1831: var value = localStorage.getItem(key);
1832: var regex_delTimestamp = /^\d+;/;
1833:
1834: value.replace(regex_delTimestamp, '');
1835:
1836: var valueArr = value.split(';');
1837: var pairs;
1838: var elements;
1839: for (var i = 0; i < valueArr.length; i++){
1840: pairs = valueArr[i].split(',');
1841: elements = document.getElementsByName(pairs[0]);
1842:
1843: for (var j = 0; j < elements.length; j++){
1844: elements[j].style.display = pairs[1];
1845: if (pairs[1] == "none"){
1846: var regex_id = /([_\\d]+)\$/;
1847: regex_id.exec(pairs[0]);
1848: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1849: }
1850: }
1851: }
1852: }
1853: }
1854:
1855: function getTagList () {
1856:
1857: var stringToSearch = document.lonhomework.innerHTML;
1858:
1859: var ret = new Array();
1860: var regex_findBlock = /(foldblock_.*?)"/g;
1861: var tag_list = stringToSearch.match(regex_findBlock);
1862:
1863: if(tag_list != null){
1864: for(var i = 0; i < tag_list.length; i++){
1865: ret.push(tag_list[i].replace(/"/, ''));
1866: }
1867: }
1868: return ret;
1869: }
1870:
1871: function saveScrollPosition (resource) {
1872: var tag_list = getTagList();
1873:
1874: // we dont always want to jump to the first block
1875: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1876: if(\$(window).scrollTop() > 170){
1877: if(tag_list != null){
1878: var result;
1879: for(var i = 0; i < tag_list.length; i++){
1880: if(isElementInViewport(tag_list[i])){
1881: result += tag_list[i]+';';
1882: }
1883: }
1884: sessionStorage.setItem('anchor_'+resource, result);
1885: }
1886: } else {
1887: // we dont need to save zero, just delete the item to leave everything tidy
1888: sessionStorage.removeItem('anchor_'+resource);
1889: }
1890: }
1891:
1892: function restoreScrollPosition(resource){
1893:
1894: var elem = sessionStorage.getItem('anchor_'+resource);
1895: if(elem != null){
1896: var tag_list = elem.split(';');
1897: var elem_list;
1898:
1899: for(var i = 0; i < tag_list.length; i++){
1900: elem_list = document.getElementsByName(tag_list[i]);
1901:
1902: if(elem_list.length > 0){
1903: elem = elem_list[0];
1904: break;
1905: }
1906: }
1907: elem.scrollIntoView();
1908: }
1909: }
1910:
1911: function isElementInViewport(el) {
1912:
1913: // change to last element instead of first
1914: var elem = document.getElementsByName(el);
1915: var rect = elem[0].getBoundingClientRect();
1916:
1917: return (
1918: rect.top >= 0 &&
1919: rect.left >= 0 &&
1920: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1921: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1922: );
1923: }
1924:
1925: function autosize(depth){
1926: var cmInst = window['cm'+depth];
1927: var fitsizeButton = document.getElementById('fitsize'+depth);
1928:
1929: // is fixed size, switching to dynamic
1930: if (sessionStorage.getItem("autosized_"+depth) == null) {
1931: cmInst.setSize("","auto");
1932: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1933: sessionStorage.setItem("autosized_"+depth, "yes");
1934:
1935: // is dynamic size, switching to fixed
1936: } else {
1937: cmInst.setSize("","300px");
1938: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1939: sessionStorage.removeItem("autosized_"+depth);
1940: }
1941: }
1942:
1943:
1944:
1945: // ]]>
1946: </script>
1947: COLORFULEDIT
1948: }
1949:
1950: sub xmleditor_js {
1951: return <<XMLEDIT
1952: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1953: <script type="text/javascript">
1954: // <![CDATA[>
1955:
1956: function saveScrollPosition (resource) {
1957:
1958: var scrollPos = \$(window).scrollTop();
1959: sessionStorage.setItem(resource,scrollPos);
1960: }
1961:
1962: function restoreScrollPosition(resource){
1963:
1964: var scrollPos = sessionStorage.getItem(resource);
1965: \$(window).scrollTop(scrollPos);
1966: }
1967:
1968: // unless internet explorer
1969: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1970:
1971: \$(document).ready(function() {
1972: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1973: });
1974: }
1975:
1976: // inserts text at cursor position into codemirror (xml editor only)
1977: function insertText(text){
1978: cm.focus();
1979: var curPos = cm.getCursor();
1980: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1981: }
1982: // ]]>
1983: </script>
1984: XMLEDIT
1985: }
1986:
1987: sub insert_folding_button {
1988: my $curDepth = $Apache::lonxml::curdepth;
1989: my $lastresource = $env{'request.ambiguous'};
1990:
1991: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1992: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1993: }
1994:
1.565 albertel 1995: =pod
1996:
1.256 matthew 1997: =head1 Excel and CSV file utility routines
1998:
1999: =cut
2000:
2001: ###############################################################
2002: ###############################################################
2003:
2004: =pod
2005:
1.1162 raeburn 2006: =over 4
2007:
1.648 raeburn 2008: =item * &csv_translate($text)
1.37 matthew 2009:
1.185 www 2010: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2011: format.
2012:
2013: =cut
2014:
1.180 matthew 2015: ###############################################################
2016: ###############################################################
1.37 matthew 2017: sub csv_translate {
2018: my $text = shift;
2019: $text =~ s/\"/\"\"/g;
1.209 albertel 2020: $text =~ s/\n/ /g;
1.37 matthew 2021: return $text;
2022: }
1.180 matthew 2023:
2024: ###############################################################
2025: ###############################################################
2026:
2027: =pod
2028:
1.648 raeburn 2029: =item * &define_excel_formats()
1.180 matthew 2030:
2031: Define some commonly used Excel cell formats.
2032:
2033: Currently supported formats:
2034:
2035: =over 4
2036:
2037: =item header
2038:
2039: =item bold
2040:
2041: =item h1
2042:
2043: =item h2
2044:
2045: =item h3
2046:
1.256 matthew 2047: =item h4
2048:
2049: =item i
2050:
1.180 matthew 2051: =item date
2052:
2053: =back
2054:
2055: Inputs: $workbook
2056:
2057: Returns: $format, a hash reference.
2058:
1.1057 foxr 2059:
1.180 matthew 2060: =cut
2061:
2062: ###############################################################
2063: ###############################################################
2064: sub define_excel_formats {
2065: my ($workbook) = @_;
2066: my $format;
2067: $format->{'header'} = $workbook->add_format(bold => 1,
2068: bottom => 1,
2069: align => 'center');
2070: $format->{'bold'} = $workbook->add_format(bold=>1);
2071: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2072: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2073: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2074: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2075: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2076: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2077: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2078: return $format;
2079: }
2080:
2081: ###############################################################
2082: ###############################################################
1.113 bowersj2 2083:
2084: =pod
2085:
1.648 raeburn 2086: =item * &create_workbook()
1.255 matthew 2087:
2088: Create an Excel worksheet. If it fails, output message on the
2089: request object and return undefs.
2090:
2091: Inputs: Apache request object
2092:
2093: Returns (undef) on failure,
2094: Excel worksheet object, scalar with filename, and formats
2095: from &Apache::loncommon::define_excel_formats on success
2096:
2097: =cut
2098:
2099: ###############################################################
2100: ###############################################################
2101: sub create_workbook {
2102: my ($r) = @_;
2103: #
2104: # Create the excel spreadsheet
2105: my $filename = '/prtspool/'.
1.258 albertel 2106: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2107: time.'_'.rand(1000000000).'.xls';
2108: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2109: if (! defined($workbook)) {
2110: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2111: $r->print(
2112: '<p class="LC_error">'
2113: .&mt('Problems occurred in creating the new Excel file.')
2114: .' '.&mt('This error has been logged.')
2115: .' '.&mt('Please alert your LON-CAPA administrator.')
2116: .'</p>'
2117: );
1.255 matthew 2118: return (undef);
2119: }
2120: #
1.1014 foxr 2121: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2122: #
2123: my $format = &Apache::loncommon::define_excel_formats($workbook);
2124: return ($workbook,$filename,$format);
2125: }
2126:
2127: ###############################################################
2128: ###############################################################
2129:
2130: =pod
2131:
1.648 raeburn 2132: =item * &create_text_file()
1.113 bowersj2 2133:
1.542 raeburn 2134: Create a file to write to and eventually make available to the user.
1.256 matthew 2135: If file creation fails, outputs an error message on the request object and
2136: return undefs.
1.113 bowersj2 2137:
1.256 matthew 2138: Inputs: Apache request object, and file suffix
1.113 bowersj2 2139:
1.256 matthew 2140: Returns (undef) on failure,
2141: Filehandle and filename on success.
1.113 bowersj2 2142:
2143: =cut
2144:
1.256 matthew 2145: ###############################################################
2146: ###############################################################
2147: sub create_text_file {
2148: my ($r,$suffix) = @_;
2149: if (! defined($suffix)) { $suffix = 'txt'; };
2150: my $fh;
2151: my $filename = '/prtspool/'.
1.258 albertel 2152: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2153: time.'_'.rand(1000000000).'.'.$suffix;
2154: $fh = Apache::File->new('>/home/httpd'.$filename);
2155: if (! defined($fh)) {
2156: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2157: $r->print(
2158: '<p class="LC_error">'
2159: .&mt('Problems occurred in creating the output file.')
2160: .' '.&mt('This error has been logged.')
2161: .' '.&mt('Please alert your LON-CAPA administrator.')
2162: .'</p>'
2163: );
1.113 bowersj2 2164: }
1.256 matthew 2165: return ($fh,$filename)
1.113 bowersj2 2166: }
2167:
2168:
1.256 matthew 2169: =pod
1.113 bowersj2 2170:
2171: =back
2172:
2173: =cut
1.37 matthew 2174:
2175: ###############################################################
1.33 matthew 2176: ## Home server <option> list generating code ##
2177: ###############################################################
1.35 matthew 2178:
1.169 www 2179: # ------------------------------------------
2180:
2181: sub domain_select {
2182: my ($name,$value,$multiple)=@_;
2183: my %domains=map {
1.514 albertel 2184: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2185: } &Apache::lonnet::all_domains();
1.169 www 2186: if ($multiple) {
2187: $domains{''}=&mt('Any domain');
1.550 albertel 2188: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2189: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2190: } else {
1.550 albertel 2191: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2192: return &select_form($name,$value,\%domains);
1.169 www 2193: }
2194: }
2195:
1.282 albertel 2196: #-------------------------------------------
2197:
2198: =pod
2199:
1.519 raeburn 2200: =head1 Routines for form select boxes
2201:
2202: =over 4
2203:
1.648 raeburn 2204: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2205:
2206: Returns a string containing a <select> element int multiple mode
2207:
2208:
2209: Args:
2210: $name - name of the <select> element
1.506 raeburn 2211: $value - scalar or array ref of values that should already be selected
1.282 albertel 2212: $size - number of rows long the select element is
1.283 albertel 2213: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2214: (shown text should already have been &mt())
1.506 raeburn 2215: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2216:
1.282 albertel 2217: =cut
2218:
2219: #-------------------------------------------
1.169 www 2220: sub multiple_select_form {
1.284 albertel 2221: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2222: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2223: my $output='';
1.191 matthew 2224: if (! defined($size)) {
2225: $size = 4;
1.283 albertel 2226: if (scalar(keys(%$hash))<4) {
2227: $size = scalar(keys(%$hash));
1.191 matthew 2228: }
2229: }
1.734 bisitz 2230: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2231: my @order;
1.506 raeburn 2232: if (ref($order) eq 'ARRAY') {
2233: @order = @{$order};
2234: } else {
2235: @order = sort(keys(%$hash));
1.501 banghart 2236: }
2237: if (exists($$hash{'select_form_order'})) {
2238: @order = @{$$hash{'select_form_order'}};
2239: }
2240:
1.284 albertel 2241: foreach my $key (@order) {
1.356 albertel 2242: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2243: $output.='selected="selected" ' if ($selected{$key});
2244: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2245: }
2246: $output.="</select>\n";
2247: return $output;
2248: }
2249:
1.88 www 2250: #-------------------------------------------
2251:
2252: =pod
2253:
1.970 raeburn 2254: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2255:
2256: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2257: allow a user to select options from a ref to a hash containing:
2258: option_name => displayed text. An optional $onchange can include
2259: a javascript onchange item, e.g., onchange="this.form.submit();"
2260:
1.88 www 2261: See lonrights.pm for an example invocation and use.
2262:
2263: =cut
2264:
2265: #-------------------------------------------
2266: sub select_form {
1.970 raeburn 2267: my ($def,$name,$hashref,$onchange) = @_;
2268: return unless (ref($hashref) eq 'HASH');
2269: if ($onchange) {
2270: $onchange = ' onchange="'.$onchange.'"';
2271: }
2272: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2273: my @keys;
1.970 raeburn 2274: if (exists($hashref->{'select_form_order'})) {
2275: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2276: } else {
1.970 raeburn 2277: @keys=sort(keys(%{$hashref}));
1.128 albertel 2278: }
1.356 albertel 2279: foreach my $key (@keys) {
2280: $selectform.=
2281: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2282: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2283: ">".$hashref->{$key}."</option>\n";
1.88 www 2284: }
2285: $selectform.="</select>";
2286: return $selectform;
2287: }
2288:
1.475 www 2289: # For display filters
2290:
2291: sub display_filter {
1.1074 raeburn 2292: my ($context) = @_;
1.475 www 2293: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2294: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2295: my $phraseinput = 'hidden';
2296: my $includeinput = 'hidden';
2297: my ($checked,$includetypestext);
2298: if ($env{'form.displayfilter'} eq 'containing') {
2299: $phraseinput = 'text';
2300: if ($context eq 'parmslog') {
2301: $includeinput = 'checkbox';
2302: if ($env{'form.includetypes'}) {
2303: $checked = ' checked="checked"';
2304: }
2305: $includetypestext = &mt('Include parameter types');
2306: }
2307: } else {
2308: $includetypestext = ' ';
2309: }
2310: my ($additional,$secondid,$thirdid);
2311: if ($context eq 'parmslog') {
2312: $additional =
2313: '<label><input type="'.$includeinput.'" name="includetypes"'.
2314: $checked.' name="includetypes" value="1" id="includetypes" />'.
2315: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2316: '</label>';
2317: $secondid = 'includetypes';
2318: $thirdid = 'includetypestext';
2319: }
2320: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2321: '$secondid','$thirdid')";
2322: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2323: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2324: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2325: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2326: &mt('Filter: [_1]',
1.477 www 2327: &select_form($env{'form.displayfilter'},
2328: 'displayfilter',
1.970 raeburn 2329: {'currentfolder' => 'Current folder/page',
1.477 www 2330: 'containing' => 'Containing phrase',
1.1074 raeburn 2331: 'none' => 'None'},$onchange)).' '.
2332: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2333: &HTML::Entities::encode($env{'form.containingphrase'}).
2334: '" />'.$additional;
2335: }
2336:
2337: sub display_filter_js {
2338: my $includetext = &mt('Include parameter types');
2339: return <<"ENDJS";
2340:
2341: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2342: var firstType = 'hidden';
2343: if (setter.options[setter.selectedIndex].value == 'containing') {
2344: firstType = 'text';
2345: }
2346: firstObject = document.getElementById(firstid);
2347: if (typeof(firstObject) == 'object') {
2348: if (firstObject.type != firstType) {
2349: changeInputType(firstObject,firstType);
2350: }
2351: }
2352: if (context == 'parmslog') {
2353: var secondType = 'hidden';
2354: if (firstType == 'text') {
2355: secondType = 'checkbox';
2356: }
2357: secondObject = document.getElementById(secondid);
2358: if (typeof(secondObject) == 'object') {
2359: if (secondObject.type != secondType) {
2360: changeInputType(secondObject,secondType);
2361: }
2362: }
2363: var textItem = document.getElementById(thirdid);
2364: var currtext = textItem.innerHTML;
2365: var newtext;
2366: if (firstType == 'text') {
2367: newtext = '$includetext';
2368: } else {
2369: newtext = ' ';
2370: }
2371: if (currtext != newtext) {
2372: textItem.innerHTML = newtext;
2373: }
2374: }
2375: return;
2376: }
2377:
2378: function changeInputType(oldObject,newType) {
2379: var newObject = document.createElement('input');
2380: newObject.type = newType;
2381: if (oldObject.size) {
2382: newObject.size = oldObject.size;
2383: }
2384: if (oldObject.value) {
2385: newObject.value = oldObject.value;
2386: }
2387: if (oldObject.name) {
2388: newObject.name = oldObject.name;
2389: }
2390: if (oldObject.id) {
2391: newObject.id = oldObject.id;
2392: }
2393: oldObject.parentNode.replaceChild(newObject,oldObject);
2394: return;
2395: }
2396:
2397: ENDJS
1.475 www 2398: }
2399:
1.167 www 2400: sub gradeleveldescription {
2401: my $gradelevel=shift;
2402: my %gradelevels=(0 => 'Not specified',
2403: 1 => 'Grade 1',
2404: 2 => 'Grade 2',
2405: 3 => 'Grade 3',
2406: 4 => 'Grade 4',
2407: 5 => 'Grade 5',
2408: 6 => 'Grade 6',
2409: 7 => 'Grade 7',
2410: 8 => 'Grade 8',
2411: 9 => 'Grade 9',
2412: 10 => 'Grade 10',
2413: 11 => 'Grade 11',
2414: 12 => 'Grade 12',
2415: 13 => 'Grade 13',
2416: 14 => '100 Level',
2417: 15 => '200 Level',
2418: 16 => '300 Level',
2419: 17 => '400 Level',
2420: 18 => 'Graduate Level');
2421: return &mt($gradelevels{$gradelevel});
2422: }
2423:
1.163 www 2424: sub select_level_form {
2425: my ($deflevel,$name)=@_;
2426: unless ($deflevel) { $deflevel=0; }
1.167 www 2427: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2428: for (my $i=0; $i<=18; $i++) {
2429: $selectform.="<option value=\"$i\" ".
1.253 albertel 2430: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2431: ">".&gradeleveldescription($i)."</option>\n";
2432: }
2433: $selectform.="</select>";
2434: return $selectform;
1.163 www 2435: }
1.167 www 2436:
1.35 matthew 2437: #-------------------------------------------
2438:
1.45 matthew 2439: =pod
2440:
1.1121 raeburn 2441: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2442:
2443: Returns a string containing a <select name='$name' size='1'> form to
2444: allow a user to select the domain to preform an operation in.
2445: See loncreateuser.pm for an example invocation and use.
2446:
1.90 www 2447: If the $includeempty flag is set, it also includes an empty choice ("no domain
2448: selected");
2449:
1.743 raeburn 2450: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2451:
1.910 raeburn 2452: 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.
2453:
1.1121 raeburn 2454: The optional $incdoms is a reference to an array of domains which will be the only available options.
2455:
2456: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2457:
1.35 matthew 2458: =cut
2459:
2460: #-------------------------------------------
1.34 matthew 2461: sub select_dom_form {
1.1121 raeburn 2462: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2463: if ($onchange) {
1.874 raeburn 2464: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2465: }
1.1121 raeburn 2466: my (@domains,%exclude);
1.910 raeburn 2467: if (ref($incdoms) eq 'ARRAY') {
2468: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2469: } else {
2470: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2471: }
1.90 www 2472: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2473: if (ref($excdoms) eq 'ARRAY') {
2474: map { $exclude{$_} = 1; } @{$excdoms};
2475: }
1.743 raeburn 2476: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2477: foreach my $dom (@domains) {
1.1121 raeburn 2478: next if ($exclude{$dom});
1.356 albertel 2479: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2480: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2481: if ($showdomdesc) {
2482: if ($dom ne '') {
2483: my $domdesc = &Apache::lonnet::domain($dom,'description');
2484: if ($domdesc ne '') {
2485: $selectdomain .= ' ('.$domdesc.')';
2486: }
2487: }
2488: }
2489: $selectdomain .= "</option>\n";
1.34 matthew 2490: }
2491: $selectdomain.="</select>";
2492: return $selectdomain;
2493: }
2494:
1.35 matthew 2495: #-------------------------------------------
2496:
1.45 matthew 2497: =pod
2498:
1.648 raeburn 2499: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2500:
1.586 raeburn 2501: input: 4 arguments (two required, two optional) -
2502: $domain - domain of new user
2503: $name - name of form element
2504: $default - Value of 'default' causes a default item to be first
2505: option, and selected by default.
2506: $hide - Value of 'hide' causes hiding of the name of the server,
2507: if 1 server found, or default, if 0 found.
1.594 raeburn 2508: output: returns 2 items:
1.586 raeburn 2509: (a) form element which contains either:
2510: (i) <select name="$name">
2511: <option value="$hostid1">$hostid $servers{$hostid}</option>
2512: <option value="$hostid2">$hostid $servers{$hostid}</option>
2513: </select>
2514: form item if there are multiple library servers in $domain, or
2515: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2516: if there is only one library server in $domain.
2517:
2518: (b) number of library servers found.
2519:
2520: See loncreateuser.pm for example of use.
1.35 matthew 2521:
2522: =cut
2523:
2524: #-------------------------------------------
1.586 raeburn 2525: sub home_server_form_item {
2526: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2527: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2528: my $result;
2529: my $numlib = keys(%servers);
2530: if ($numlib > 1) {
2531: $result .= '<select name="'.$name.'" />'."\n";
2532: if ($default) {
1.804 bisitz 2533: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2534: '</option>'."\n";
2535: }
2536: foreach my $hostid (sort(keys(%servers))) {
2537: $result.= '<option value="'.$hostid.'">'.
2538: $hostid.' '.$servers{$hostid}."</option>\n";
2539: }
2540: $result .= '</select>'."\n";
2541: } elsif ($numlib == 1) {
2542: my $hostid;
2543: foreach my $item (keys(%servers)) {
2544: $hostid = $item;
2545: }
2546: $result .= '<input type="hidden" name="'.$name.'" value="'.
2547: $hostid.'" />';
2548: if (!$hide) {
2549: $result .= $hostid.' '.$servers{$hostid};
2550: }
2551: $result .= "\n";
2552: } elsif ($default) {
2553: $result .= '<input type="hidden" name="'.$name.
2554: '" value="default" />';
2555: if (!$hide) {
2556: $result .= &mt('default');
2557: }
2558: $result .= "\n";
1.33 matthew 2559: }
1.586 raeburn 2560: return ($result,$numlib);
1.33 matthew 2561: }
1.112 bowersj2 2562:
2563: =pod
2564:
1.534 albertel 2565: =back
2566:
1.112 bowersj2 2567: =cut
1.87 matthew 2568:
2569: ###############################################################
1.112 bowersj2 2570: ## Decoding User Agent ##
1.87 matthew 2571: ###############################################################
2572:
2573: =pod
2574:
1.112 bowersj2 2575: =head1 Decoding the User Agent
2576:
2577: =over 4
2578:
2579: =item * &decode_user_agent()
1.87 matthew 2580:
2581: Inputs: $r
2582:
2583: Outputs:
2584:
2585: =over 4
2586:
1.112 bowersj2 2587: =item * $httpbrowser
1.87 matthew 2588:
1.112 bowersj2 2589: =item * $clientbrowser
1.87 matthew 2590:
1.112 bowersj2 2591: =item * $clientversion
1.87 matthew 2592:
1.112 bowersj2 2593: =item * $clientmathml
1.87 matthew 2594:
1.112 bowersj2 2595: =item * $clientunicode
1.87 matthew 2596:
1.112 bowersj2 2597: =item * $clientos
1.87 matthew 2598:
1.1137 raeburn 2599: =item * $clientmobile
2600:
1.1141 raeburn 2601: =item * $clientinfo
2602:
1.1194 raeburn 2603: =item * $clientosversion
2604:
1.87 matthew 2605: =back
2606:
1.157 matthew 2607: =back
2608:
1.87 matthew 2609: =cut
2610:
2611: ###############################################################
2612: ###############################################################
2613: sub decode_user_agent {
1.247 albertel 2614: my ($r)=@_;
1.87 matthew 2615: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2616: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2617: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2618: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2619: my $clientbrowser='unknown';
2620: my $clientversion='0';
2621: my $clientmathml='';
2622: my $clientunicode='0';
1.1137 raeburn 2623: my $clientmobile=0;
1.1194 raeburn 2624: my $clientosversion='';
1.87 matthew 2625: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2626: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2627: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2628: $clientbrowser=$bname;
2629: $httpbrowser=~/$vreg/i;
2630: $clientversion=$1;
2631: $clientmathml=($clientversion>=$minv);
2632: $clientunicode=($clientversion>=$univ);
2633: }
2634: }
2635: my $clientos='unknown';
1.1141 raeburn 2636: my $clientinfo;
1.87 matthew 2637: if (($httpbrowser=~/linux/i) ||
2638: ($httpbrowser=~/unix/i) ||
2639: ($httpbrowser=~/ux/i) ||
2640: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2641: if (($httpbrowser=~/vax/i) ||
2642: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2643: if ($httpbrowser=~/next/i) { $clientos='next'; }
2644: if (($httpbrowser=~/mac/i) ||
2645: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2646: if ($httpbrowser=~/win/i) {
2647: $clientos='win';
2648: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2649: $clientosversion = $1;
2650: }
2651: }
1.87 matthew 2652: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2653: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2654: $clientmobile=lc($1);
2655: }
1.1141 raeburn 2656: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2657: $clientinfo = 'firefox-'.$1;
2658: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2659: $clientinfo = 'chromeframe-'.$1;
2660: }
1.87 matthew 2661: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2662: $clientunicode,$clientos,$clientmobile,$clientinfo,
2663: $clientosversion);
1.87 matthew 2664: }
2665:
1.32 matthew 2666: ###############################################################
2667: ## Authentication changing form generation subroutines ##
2668: ###############################################################
2669: ##
2670: ## All of the authform_xxxxxxx subroutines take their inputs in a
2671: ## hash, and have reasonable default values.
2672: ##
2673: ## formname = the name given in the <form> tag.
1.35 matthew 2674: #-------------------------------------------
2675:
1.45 matthew 2676: =pod
2677:
1.112 bowersj2 2678: =head1 Authentication Routines
2679:
2680: =over 4
2681:
1.648 raeburn 2682: =item * &authform_xxxxxx()
1.35 matthew 2683:
2684: The authform_xxxxxx subroutines provide javascript and html forms which
2685: handle some of the conveniences required for authentication forms.
2686: This is not an optimal method, but it works.
2687:
2688: =over 4
2689:
1.112 bowersj2 2690: =item * authform_header
1.35 matthew 2691:
1.112 bowersj2 2692: =item * authform_authorwarning
1.35 matthew 2693:
1.112 bowersj2 2694: =item * authform_nochange
1.35 matthew 2695:
1.112 bowersj2 2696: =item * authform_kerberos
1.35 matthew 2697:
1.112 bowersj2 2698: =item * authform_internal
1.35 matthew 2699:
1.112 bowersj2 2700: =item * authform_filesystem
1.35 matthew 2701:
2702: =back
2703:
1.648 raeburn 2704: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2705:
1.35 matthew 2706: =cut
2707:
2708: #-------------------------------------------
1.32 matthew 2709: sub authform_header{
2710: my %in = (
2711: formname => 'cu',
1.80 albertel 2712: kerb_def_dom => '',
1.32 matthew 2713: @_,
2714: );
2715: $in{'formname'} = 'document.' . $in{'formname'};
2716: my $result='';
1.80 albertel 2717:
2718: #---------------------------------------------- Code for upper case translation
2719: my $Javascript_toUpperCase;
2720: unless ($in{kerb_def_dom}) {
2721: $Javascript_toUpperCase =<<"END";
2722: switch (choice) {
2723: case 'krb': currentform.elements[choicearg].value =
2724: currentform.elements[choicearg].value.toUpperCase();
2725: break;
2726: default:
2727: }
2728: END
2729: } else {
2730: $Javascript_toUpperCase = "";
2731: }
2732:
1.165 raeburn 2733: my $radioval = "'nochange'";
1.591 raeburn 2734: if (defined($in{'curr_authtype'})) {
2735: if ($in{'curr_authtype'} ne '') {
2736: $radioval = "'".$in{'curr_authtype'}."arg'";
2737: }
1.174 matthew 2738: }
1.165 raeburn 2739: my $argfield = 'null';
1.591 raeburn 2740: if (defined($in{'mode'})) {
1.165 raeburn 2741: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2742: if (defined($in{'curr_autharg'})) {
2743: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2744: $argfield = "'$in{'curr_autharg'}'";
2745: }
2746: }
2747: }
2748: }
2749:
1.32 matthew 2750: $result.=<<"END";
2751: var current = new Object();
1.165 raeburn 2752: current.radiovalue = $radioval;
2753: current.argfield = $argfield;
1.32 matthew 2754:
2755: function changed_radio(choice,currentform) {
2756: var choicearg = choice + 'arg';
2757: // If a radio button in changed, we need to change the argfield
2758: if (current.radiovalue != choice) {
2759: current.radiovalue = choice;
2760: if (current.argfield != null) {
2761: currentform.elements[current.argfield].value = '';
2762: }
2763: if (choice == 'nochange') {
2764: current.argfield = null;
2765: } else {
2766: current.argfield = choicearg;
2767: switch(choice) {
2768: case 'krb':
2769: currentform.elements[current.argfield].value =
2770: "$in{'kerb_def_dom'}";
2771: break;
2772: default:
2773: break;
2774: }
2775: }
2776: }
2777: return;
2778: }
1.22 www 2779:
1.32 matthew 2780: function changed_text(choice,currentform) {
2781: var choicearg = choice + 'arg';
2782: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2783: $Javascript_toUpperCase
1.32 matthew 2784: // clear old field
2785: if ((current.argfield != choicearg) && (current.argfield != null)) {
2786: currentform.elements[current.argfield].value = '';
2787: }
2788: current.argfield = choicearg;
2789: }
2790: set_auth_radio_buttons(choice,currentform);
2791: return;
1.20 www 2792: }
1.32 matthew 2793:
2794: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2795: var numauthchoices = currentform.login.length;
2796: if (typeof numauthchoices == "undefined") {
2797: return;
2798: }
1.32 matthew 2799: var i=0;
1.986 raeburn 2800: while (i < numauthchoices) {
1.32 matthew 2801: if (currentform.login[i].value == newvalue) { break; }
2802: i++;
2803: }
1.986 raeburn 2804: if (i == numauthchoices) {
1.32 matthew 2805: return;
2806: }
2807: current.radiovalue = newvalue;
2808: currentform.login[i].checked = true;
2809: return;
2810: }
2811: END
2812: return $result;
2813: }
2814:
1.1106 raeburn 2815: sub authform_authorwarning {
1.32 matthew 2816: my $result='';
1.144 matthew 2817: $result='<i>'.
2818: &mt('As a general rule, only authors or co-authors should be '.
2819: 'filesystem authenticated '.
2820: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2821: return $result;
2822: }
2823:
1.1106 raeburn 2824: sub authform_nochange {
1.32 matthew 2825: my %in = (
2826: formname => 'document.cu',
2827: kerb_def_dom => 'MSU.EDU',
2828: @_,
2829: );
1.1106 raeburn 2830: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2831: my $result;
1.1104 raeburn 2832: if (!$authnum) {
1.1105 raeburn 2833: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2834: } else {
2835: $result = '<label>'.&mt('[_1] Do not change login data',
2836: '<input type="radio" name="login" value="nochange" '.
2837: 'checked="checked" onclick="'.
1.281 albertel 2838: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2839: '</label>';
1.586 raeburn 2840: }
1.32 matthew 2841: return $result;
2842: }
2843:
1.591 raeburn 2844: sub authform_kerberos {
1.32 matthew 2845: my %in = (
2846: formname => 'document.cu',
2847: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2848: kerb_def_auth => 'krb4',
1.32 matthew 2849: @_,
2850: );
1.586 raeburn 2851: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2852: $autharg,$jscall);
1.1106 raeburn 2853: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2854: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2855: $check5 = ' checked="checked"';
1.80 albertel 2856: } else {
1.772 bisitz 2857: $check4 = ' checked="checked"';
1.80 albertel 2858: }
1.165 raeburn 2859: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2860: if (defined($in{'curr_authtype'})) {
2861: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2862: $krbcheck = ' checked="checked"';
1.623 raeburn 2863: if (defined($in{'mode'})) {
2864: if ($in{'mode'} eq 'modifyuser') {
2865: $krbcheck = '';
2866: }
2867: }
1.591 raeburn 2868: if (defined($in{'curr_kerb_ver'})) {
2869: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2870: $check5 = ' checked="checked"';
1.591 raeburn 2871: $check4 = '';
2872: } else {
1.772 bisitz 2873: $check4 = ' checked="checked"';
1.591 raeburn 2874: $check5 = '';
2875: }
1.586 raeburn 2876: }
1.591 raeburn 2877: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2878: $krbarg = $in{'curr_autharg'};
2879: }
1.586 raeburn 2880: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2881: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2882: $result =
2883: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2884: $in{'curr_autharg'},$krbver);
2885: } else {
2886: $result =
2887: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2888: }
2889: return $result;
2890: }
2891: }
2892: } else {
2893: if ($authnum == 1) {
1.784 bisitz 2894: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2895: }
2896: }
1.586 raeburn 2897: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2898: return;
1.587 raeburn 2899: } elsif ($authtype eq '') {
1.591 raeburn 2900: if (defined($in{'mode'})) {
1.587 raeburn 2901: if ($in{'mode'} eq 'modifycourse') {
2902: if ($authnum == 1) {
1.1104 raeburn 2903: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2904: }
2905: }
2906: }
1.586 raeburn 2907: }
2908: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2909: if ($authtype eq '') {
2910: $authtype = '<input type="radio" name="login" value="krb" '.
2911: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2912: $krbcheck.' />';
2913: }
2914: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2915: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2916: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2917: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2918: $in{'curr_authtype'} eq 'krb4')) {
2919: $result .= &mt
1.144 matthew 2920: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2921: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2922: '<label>'.$authtype,
1.281 albertel 2923: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2924: 'value="'.$krbarg.'" '.
1.144 matthew 2925: 'onchange="'.$jscall.'" />',
1.281 albertel 2926: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2927: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2928: '</label>');
1.586 raeburn 2929: } elsif ($can_assign{'krb4'}) {
2930: $result .= &mt
2931: ('[_1] Kerberos authenticated with domain [_2] '.
2932: '[_3] Version 4 [_4]',
2933: '<label>'.$authtype,
2934: '</label><input type="text" size="10" name="krbarg" '.
2935: 'value="'.$krbarg.'" '.
2936: 'onchange="'.$jscall.'" />',
2937: '<label><input type="hidden" name="krbver" value="4" />',
2938: '</label>');
2939: } elsif ($can_assign{'krb5'}) {
2940: $result .= &mt
2941: ('[_1] Kerberos authenticated with domain [_2] '.
2942: '[_3] Version 5 [_4]',
2943: '<label>'.$authtype,
2944: '</label><input type="text" size="10" name="krbarg" '.
2945: 'value="'.$krbarg.'" '.
2946: 'onchange="'.$jscall.'" />',
2947: '<label><input type="hidden" name="krbver" value="5" />',
2948: '</label>');
2949: }
1.32 matthew 2950: return $result;
2951: }
2952:
1.1106 raeburn 2953: sub authform_internal {
1.586 raeburn 2954: my %in = (
1.32 matthew 2955: formname => 'document.cu',
2956: kerb_def_dom => 'MSU.EDU',
2957: @_,
2958: );
1.586 raeburn 2959: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2960: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2961: if (defined($in{'curr_authtype'})) {
2962: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2963: if ($can_assign{'int'}) {
1.772 bisitz 2964: $intcheck = 'checked="checked" ';
1.623 raeburn 2965: if (defined($in{'mode'})) {
2966: if ($in{'mode'} eq 'modifyuser') {
2967: $intcheck = '';
2968: }
2969: }
1.591 raeburn 2970: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2971: $intarg = $in{'curr_autharg'};
2972: }
2973: } else {
2974: $result = &mt('Currently internally authenticated.');
2975: return $result;
1.165 raeburn 2976: }
2977: }
1.586 raeburn 2978: } else {
2979: if ($authnum == 1) {
1.784 bisitz 2980: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2981: }
2982: }
2983: if (!$can_assign{'int'}) {
2984: return;
1.587 raeburn 2985: } elsif ($authtype eq '') {
1.591 raeburn 2986: if (defined($in{'mode'})) {
1.587 raeburn 2987: if ($in{'mode'} eq 'modifycourse') {
2988: if ($authnum == 1) {
1.1104 raeburn 2989: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2990: }
2991: }
2992: }
1.165 raeburn 2993: }
1.586 raeburn 2994: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2995: if ($authtype eq '') {
2996: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2997: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2998: }
1.605 bisitz 2999: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 3000: $intarg.'" onchange="'.$jscall.'" />';
3001: $result = &mt
1.144 matthew 3002: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3003: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 3004: $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 3005: return $result;
3006: }
3007:
1.1104 raeburn 3008: sub authform_local {
1.32 matthew 3009: my %in = (
3010: formname => 'document.cu',
3011: kerb_def_dom => 'MSU.EDU',
3012: @_,
3013: );
1.586 raeburn 3014: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3015: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3016: if (defined($in{'curr_authtype'})) {
3017: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3018: if ($can_assign{'loc'}) {
1.772 bisitz 3019: $loccheck = 'checked="checked" ';
1.623 raeburn 3020: if (defined($in{'mode'})) {
3021: if ($in{'mode'} eq 'modifyuser') {
3022: $loccheck = '';
3023: }
3024: }
1.591 raeburn 3025: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3026: $locarg = $in{'curr_autharg'};
3027: }
3028: } else {
3029: $result = &mt('Currently using local (institutional) authentication.');
3030: return $result;
1.165 raeburn 3031: }
3032: }
1.586 raeburn 3033: } else {
3034: if ($authnum == 1) {
1.784 bisitz 3035: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3036: }
3037: }
3038: if (!$can_assign{'loc'}) {
3039: return;
1.587 raeburn 3040: } elsif ($authtype eq '') {
1.591 raeburn 3041: if (defined($in{'mode'})) {
1.587 raeburn 3042: if ($in{'mode'} eq 'modifycourse') {
3043: if ($authnum == 1) {
1.1104 raeburn 3044: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3045: }
3046: }
3047: }
1.165 raeburn 3048: }
1.586 raeburn 3049: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3050: if ($authtype eq '') {
3051: $authtype = '<input type="radio" name="login" value="loc" '.
3052: $loccheck.' onchange="'.$jscall.'" onclick="'.
3053: $jscall.'" />';
3054: }
3055: $autharg = '<input type="text" size="10" name="locarg" value="'.
3056: $locarg.'" onchange="'.$jscall.'" />';
3057: $result = &mt('[_1] Local Authentication with argument [_2]',
3058: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3059: return $result;
3060: }
3061:
1.1106 raeburn 3062: sub authform_filesystem {
1.32 matthew 3063: my %in = (
3064: formname => 'document.cu',
3065: kerb_def_dom => 'MSU.EDU',
3066: @_,
3067: );
1.586 raeburn 3068: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3069: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3070: if (defined($in{'curr_authtype'})) {
3071: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3072: if ($can_assign{'fsys'}) {
1.772 bisitz 3073: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3074: if (defined($in{'mode'})) {
3075: if ($in{'mode'} eq 'modifyuser') {
3076: $fsyscheck = '';
3077: }
3078: }
1.586 raeburn 3079: } else {
3080: $result = &mt('Currently Filesystem Authenticated.');
3081: return $result;
3082: }
3083: }
3084: } else {
3085: if ($authnum == 1) {
1.784 bisitz 3086: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3087: }
3088: }
3089: if (!$can_assign{'fsys'}) {
3090: return;
1.587 raeburn 3091: } elsif ($authtype eq '') {
1.591 raeburn 3092: if (defined($in{'mode'})) {
1.587 raeburn 3093: if ($in{'mode'} eq 'modifycourse') {
3094: if ($authnum == 1) {
1.1104 raeburn 3095: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3096: }
3097: }
3098: }
1.586 raeburn 3099: }
3100: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3101: if ($authtype eq '') {
3102: $authtype = '<input type="radio" name="login" value="fsys" '.
3103: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3104: $jscall.'" />';
3105: }
3106: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3107: ' onchange="'.$jscall.'" />';
3108: $result = &mt
1.144 matthew 3109: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3110: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3111: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3112: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3113: 'onchange="'.$jscall.'" />');
1.32 matthew 3114: return $result;
3115: }
3116:
1.586 raeburn 3117: sub get_assignable_auth {
3118: my ($dom) = @_;
3119: if ($dom eq '') {
3120: $dom = $env{'request.role.domain'};
3121: }
3122: my %can_assign = (
3123: krb4 => 1,
3124: krb5 => 1,
3125: int => 1,
3126: loc => 1,
3127: );
3128: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3129: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3130: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3131: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3132: my $context;
3133: if ($env{'request.role'} =~ /^au/) {
3134: $context = 'author';
3135: } elsif ($env{'request.role'} =~ /^dc/) {
3136: $context = 'domain';
3137: } elsif ($env{'request.course.id'}) {
3138: $context = 'course';
3139: }
3140: if ($context) {
3141: if (ref($authhash->{$context}) eq 'HASH') {
3142: %can_assign = %{$authhash->{$context}};
3143: }
3144: }
3145: }
3146: }
3147: my $authnum = 0;
3148: foreach my $key (keys(%can_assign)) {
3149: if ($can_assign{$key}) {
3150: $authnum ++;
3151: }
3152: }
3153: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3154: $authnum --;
3155: }
3156: return ($authnum,%can_assign);
3157: }
3158:
1.80 albertel 3159: ###############################################################
3160: ## Get Kerberos Defaults for Domain ##
3161: ###############################################################
3162: ##
3163: ## Returns default kerberos version and an associated argument
3164: ## as listed in file domain.tab. If not listed, provides
3165: ## appropriate default domain and kerberos version.
3166: ##
3167: #-------------------------------------------
3168:
3169: =pod
3170:
1.648 raeburn 3171: =item * &get_kerberos_defaults()
1.80 albertel 3172:
3173: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3174: version and domain. If not found, it defaults to version 4 and the
3175: domain of the server.
1.80 albertel 3176:
1.648 raeburn 3177: =over 4
3178:
1.80 albertel 3179: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3180:
1.648 raeburn 3181: =back
3182:
3183: =back
3184:
1.80 albertel 3185: =cut
3186:
3187: #-------------------------------------------
3188: sub get_kerberos_defaults {
3189: my $domain=shift;
1.641 raeburn 3190: my ($krbdef,$krbdefdom);
3191: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3192: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3193: $krbdef = $domdefaults{'auth_def'};
3194: $krbdefdom = $domdefaults{'auth_arg_def'};
3195: } else {
1.80 albertel 3196: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3197: my $krbdefdom=$1;
3198: $krbdefdom=~tr/a-z/A-Z/;
3199: $krbdef = "krb4";
3200: }
3201: return ($krbdef,$krbdefdom);
3202: }
1.112 bowersj2 3203:
1.32 matthew 3204:
1.46 matthew 3205: ###############################################################
3206: ## Thesaurus Functions ##
3207: ###############################################################
1.20 www 3208:
1.46 matthew 3209: =pod
1.20 www 3210:
1.112 bowersj2 3211: =head1 Thesaurus Functions
3212:
3213: =over 4
3214:
1.648 raeburn 3215: =item * &initialize_keywords()
1.46 matthew 3216:
3217: Initializes the package variable %Keywords if it is empty. Uses the
3218: package variable $thesaurus_db_file.
3219:
3220: =cut
3221:
3222: ###################################################
3223:
3224: sub initialize_keywords {
3225: return 1 if (scalar keys(%Keywords));
3226: # If we are here, %Keywords is empty, so fill it up
3227: # Make sure the file we need exists...
3228: if (! -e $thesaurus_db_file) {
3229: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3230: " failed because it does not exist");
3231: return 0;
3232: }
3233: # Set up the hash as a database
3234: my %thesaurus_db;
3235: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3236: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3237: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3238: $thesaurus_db_file);
3239: return 0;
3240: }
3241: # Get the average number of appearances of a word.
3242: my $avecount = $thesaurus_db{'average.count'};
3243: # Put keywords (those that appear > average) into %Keywords
3244: while (my ($word,$data)=each (%thesaurus_db)) {
3245: my ($count,undef) = split /:/,$data;
3246: $Keywords{$word}++ if ($count > $avecount);
3247: }
3248: untie %thesaurus_db;
3249: # Remove special values from %Keywords.
1.356 albertel 3250: foreach my $value ('total.count','average.count') {
3251: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3252: }
1.46 matthew 3253: return 1;
3254: }
3255:
3256: ###################################################
3257:
3258: =pod
3259:
1.648 raeburn 3260: =item * &keyword($word)
1.46 matthew 3261:
3262: Returns true if $word is a keyword. A keyword is a word that appears more
3263: than the average number of times in the thesaurus database. Calls
3264: &initialize_keywords
3265:
3266: =cut
3267:
3268: ###################################################
1.20 www 3269:
3270: sub keyword {
1.46 matthew 3271: return if (!&initialize_keywords());
3272: my $word=lc(shift());
3273: $word=~s/\W//g;
3274: return exists($Keywords{$word});
1.20 www 3275: }
1.46 matthew 3276:
3277: ###############################################################
3278:
3279: =pod
1.20 www 3280:
1.648 raeburn 3281: =item * &get_related_words()
1.46 matthew 3282:
1.160 matthew 3283: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3284: an array of words. If the keyword is not in the thesaurus, an empty array
3285: will be returned. The order of the words returned is determined by the
3286: database which holds them.
3287:
3288: Uses global $thesaurus_db_file.
3289:
1.1057 foxr 3290:
1.46 matthew 3291: =cut
3292:
3293: ###############################################################
3294: sub get_related_words {
3295: my $keyword = shift;
3296: my %thesaurus_db;
3297: if (! -e $thesaurus_db_file) {
3298: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3299: "failed because the file does not exist");
3300: return ();
3301: }
3302: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3303: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3304: return ();
3305: }
3306: my @Words=();
1.429 www 3307: my $count=0;
1.46 matthew 3308: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3309: # The first element is the number of times
3310: # the word appears. We do not need it now.
1.429 www 3311: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3312: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3313: my $threshold=$mostfrequentcount/10;
3314: foreach my $possibleword (@RelatedWords) {
3315: my ($word,$wordcount)=split(/\,/,$possibleword);
3316: if ($wordcount>$threshold) {
3317: push(@Words,$word);
3318: $count++;
3319: if ($count>10) { last; }
3320: }
1.20 www 3321: }
3322: }
1.46 matthew 3323: untie %thesaurus_db;
3324: return @Words;
1.14 harris41 3325: }
1.1090 foxr 3326: ###############################################################
3327: #
3328: # Spell checking
3329: #
3330:
3331: =pod
3332:
1.1142 raeburn 3333: =back
3334:
1.1090 foxr 3335: =head1 Spell checking
3336:
3337: =over 4
3338:
3339: =item * &check_spelling($wordlist $language)
3340:
3341: Takes a string containing words and feeds it to an external
3342: spellcheck program via a pipeline. Returns a string containing
3343: them mis-spelled words.
3344:
3345: Parameters:
3346:
3347: =over 4
3348:
3349: =item - $wordlist
3350:
3351: String that will be fed into the spellcheck program.
3352:
3353: =item - $language
3354:
3355: Language string that specifies the language for which the spell
3356: check will be performed.
3357:
3358: =back
3359:
3360: =back
3361:
3362: Note: This sub assumes that aspell is installed.
3363:
3364:
3365: =cut
3366:
1.46 matthew 3367:
1.1090 foxr 3368: sub check_spelling {
3369: my ($wordlist, $language) = @_;
1.1091 foxr 3370: my @misspellings;
3371:
3372: # Generate the speller and set the langauge.
3373: # if explicitly selected:
1.1090 foxr 3374:
1.1091 foxr 3375: my $speller = Text::Aspell->new;
1.1090 foxr 3376: if ($language) {
1.1091 foxr 3377: $speller->set_option('lang', $language);
1.1090 foxr 3378: }
3379:
1.1091 foxr 3380: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3381:
1.1091 foxr 3382: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3383:
1.1091 foxr 3384: foreach my $word (@words) {
3385: if(! $speller->check($word)) {
3386: push(@misspellings, $word);
1.1090 foxr 3387: }
3388: }
1.1091 foxr 3389: return join(' ', @misspellings);
3390:
1.1090 foxr 3391: }
3392:
1.61 www 3393: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3394: =pod
3395:
1.112 bowersj2 3396: =head1 User Name Functions
3397:
3398: =over 4
3399:
1.648 raeburn 3400: =item * &plainname($uname,$udom,$first)
1.81 albertel 3401:
1.112 bowersj2 3402: Takes a users logon name and returns it as a string in
1.226 albertel 3403: "first middle last generation" form
3404: if $first is set to 'lastname' then it returns it as
3405: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3406:
3407: =cut
1.61 www 3408:
1.295 www 3409:
1.81 albertel 3410: ###############################################################
1.61 www 3411: sub plainname {
1.226 albertel 3412: my ($uname,$udom,$first)=@_;
1.537 albertel 3413: return if (!defined($uname) || !defined($udom));
1.295 www 3414: my %names=&getnames($uname,$udom);
1.226 albertel 3415: my $name=&Apache::lonnet::format_name($names{'firstname'},
3416: $names{'middlename'},
3417: $names{'lastname'},
3418: $names{'generation'},$first);
3419: $name=~s/^\s+//;
1.62 www 3420: $name=~s/\s+$//;
3421: $name=~s/\s+/ /g;
1.353 albertel 3422: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3423: return $name;
1.61 www 3424: }
1.66 www 3425:
3426: # -------------------------------------------------------------------- Nickname
1.81 albertel 3427: =pod
3428:
1.648 raeburn 3429: =item * &nickname($uname,$udom)
1.81 albertel 3430:
3431: Gets a users name and returns it as a string as
3432:
3433: ""nickname""
1.66 www 3434:
1.81 albertel 3435: if the user has a nickname or
3436:
3437: "first middle last generation"
3438:
3439: if the user does not
3440:
3441: =cut
1.66 www 3442:
3443: sub nickname {
3444: my ($uname,$udom)=@_;
1.537 albertel 3445: return if (!defined($uname) || !defined($udom));
1.295 www 3446: my %names=&getnames($uname,$udom);
1.68 albertel 3447: my $name=$names{'nickname'};
1.66 www 3448: if ($name) {
3449: $name='"'.$name.'"';
3450: } else {
3451: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3452: $names{'lastname'}.' '.$names{'generation'};
3453: $name=~s/\s+$//;
3454: $name=~s/\s+/ /g;
3455: }
3456: return $name;
3457: }
3458:
1.295 www 3459: sub getnames {
3460: my ($uname,$udom)=@_;
1.537 albertel 3461: return if (!defined($uname) || !defined($udom));
1.433 albertel 3462: if ($udom eq 'public' && $uname eq 'public') {
3463: return ('lastname' => &mt('Public'));
3464: }
1.295 www 3465: my $id=$uname.':'.$udom;
3466: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3467: if ($cached) {
3468: return %{$names};
3469: } else {
3470: my %loadnames=&Apache::lonnet::get('environment',
3471: ['firstname','middlename','lastname','generation','nickname'],
3472: $udom,$uname);
3473: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3474: return %loadnames;
3475: }
3476: }
1.61 www 3477:
1.542 raeburn 3478: # -------------------------------------------------------------------- getemails
1.648 raeburn 3479:
1.542 raeburn 3480: =pod
3481:
1.648 raeburn 3482: =item * &getemails($uname,$udom)
1.542 raeburn 3483:
3484: Gets a user's email information and returns it as a hash with keys:
3485: notification, critnotification, permanentemail
3486:
3487: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3488: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3489:
1.648 raeburn 3490:
1.542 raeburn 3491: =cut
3492:
1.648 raeburn 3493:
1.466 albertel 3494: sub getemails {
3495: my ($uname,$udom)=@_;
3496: if ($udom eq 'public' && $uname eq 'public') {
3497: return;
3498: }
1.467 www 3499: if (!$udom) { $udom=$env{'user.domain'}; }
3500: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3501: my $id=$uname.':'.$udom;
3502: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3503: if ($cached) {
3504: return %{$names};
3505: } else {
3506: my %loadnames=&Apache::lonnet::get('environment',
3507: ['notification','critnotification',
3508: 'permanentemail'],
3509: $udom,$uname);
3510: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3511: return %loadnames;
3512: }
3513: }
3514:
1.551 albertel 3515: sub flush_email_cache {
3516: my ($uname,$udom)=@_;
3517: if (!$udom) { $udom =$env{'user.domain'}; }
3518: if (!$uname) { $uname=$env{'user.name'}; }
3519: return if ($udom eq 'public' && $uname eq 'public');
3520: my $id=$uname.':'.$udom;
3521: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3522: }
3523:
1.728 raeburn 3524: # -------------------------------------------------------------------- getlangs
3525:
3526: =pod
3527:
3528: =item * &getlangs($uname,$udom)
3529:
3530: Gets a user's language preference and returns it as a hash with key:
3531: language.
3532:
3533: =cut
3534:
3535:
3536: sub getlangs {
3537: my ($uname,$udom) = @_;
3538: if (!$udom) { $udom =$env{'user.domain'}; }
3539: if (!$uname) { $uname=$env{'user.name'}; }
3540: my $id=$uname.':'.$udom;
3541: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3542: if ($cached) {
3543: return %{$langs};
3544: } else {
3545: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3546: $udom,$uname);
3547: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3548: return %loadlangs;
3549: }
3550: }
3551:
3552: sub flush_langs_cache {
3553: my ($uname,$udom)=@_;
3554: if (!$udom) { $udom =$env{'user.domain'}; }
3555: if (!$uname) { $uname=$env{'user.name'}; }
3556: return if ($udom eq 'public' && $uname eq 'public');
3557: my $id=$uname.':'.$udom;
3558: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3559: }
3560:
1.61 www 3561: # ------------------------------------------------------------------ Screenname
1.81 albertel 3562:
3563: =pod
3564:
1.648 raeburn 3565: =item * &screenname($uname,$udom)
1.81 albertel 3566:
3567: Gets a users screenname and returns it as a string
3568:
3569: =cut
1.61 www 3570:
3571: sub screenname {
3572: my ($uname,$udom)=@_;
1.258 albertel 3573: if ($uname eq $env{'user.name'} &&
3574: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3575: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3576: return $names{'screenname'};
1.62 www 3577: }
3578:
1.212 albertel 3579:
1.802 bisitz 3580: # ------------------------------------------------------------- Confirm Wrapper
3581: =pod
3582:
1.1142 raeburn 3583: =item * &confirmwrapper($message)
1.802 bisitz 3584:
3585: Wrap messages about completion of operation in box
3586:
3587: =cut
3588:
3589: sub confirmwrapper {
3590: my ($message)=@_;
3591: if ($message) {
3592: return "\n".'<div class="LC_confirm_box">'."\n"
3593: .$message."\n"
3594: .'</div>'."\n";
3595: } else {
3596: return $message;
3597: }
3598: }
3599:
1.62 www 3600: # ------------------------------------------------------------- Message Wrapper
3601:
3602: sub messagewrapper {
1.369 www 3603: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3604: return
1.441 albertel 3605: '<a href="/adm/email?compose=individual&'.
3606: 'recname='.$username.'&recdom='.$domain.
3607: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3608: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3609: }
1.802 bisitz 3610:
1.74 www 3611: # --------------------------------------------------------------- Notes Wrapper
3612:
3613: sub noteswrapper {
3614: my ($link,$un,$do)=@_;
3615: return
1.896 amueller 3616: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3617: }
1.802 bisitz 3618:
1.62 www 3619: # ------------------------------------------------------------- Aboutme Wrapper
3620:
3621: sub aboutmewrapper {
1.1070 raeburn 3622: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3623: if (!defined($username) && !defined($domain)) {
3624: return;
3625: }
1.1096 raeburn 3626: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3627: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3628: }
3629:
3630: # ------------------------------------------------------------ Syllabus Wrapper
3631:
3632: sub syllabuswrapper {
1.707 bisitz 3633: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3634: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3635: }
1.14 harris41 3636:
1.802 bisitz 3637: # -----------------------------------------------------------------------------
3638:
1.208 matthew 3639: sub track_student_link {
1.887 raeburn 3640: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3641: my $link ="/adm/trackstudent?";
1.208 matthew 3642: my $title = 'View recent activity';
3643: if (defined($sname) && $sname !~ /^\s*$/ &&
3644: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3645: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3646: $title .= ' of this student';
1.268 albertel 3647: }
1.208 matthew 3648: if (defined($target) && $target !~ /^\s*$/) {
3649: $target = qq{target="$target"};
3650: } else {
3651: $target = '';
3652: }
1.268 albertel 3653: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3654: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3655: $title = &mt($title);
3656: $linktext = &mt($linktext);
1.448 albertel 3657: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3658: &help_open_topic('View_recent_activity');
1.208 matthew 3659: }
3660:
1.781 raeburn 3661: sub slot_reservations_link {
3662: my ($linktext,$sname,$sdom,$target) = @_;
3663: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3664: my $title = 'View slot reservation history';
3665: if (defined($sname) && $sname !~ /^\s*$/ &&
3666: defined($sdom) && $sdom !~ /^\s*$/) {
3667: $link .= "&uname=$sname&udom=$sdom";
3668: $title .= ' of this student';
3669: }
3670: if (defined($target) && $target !~ /^\s*$/) {
3671: $target = qq{target="$target"};
3672: } else {
3673: $target = '';
3674: }
3675: $title = &mt($title);
3676: $linktext = &mt($linktext);
3677: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3678: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3679:
3680: }
3681:
1.508 www 3682: # ===================================================== Display a student photo
3683:
3684:
1.509 albertel 3685: sub student_image_tag {
1.508 www 3686: my ($domain,$user)=@_;
3687: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3688: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3689: return '<img src="'.$imgsrc.'" align="right" />';
3690: } else {
3691: return '';
3692: }
3693: }
3694:
1.112 bowersj2 3695: =pod
3696:
3697: =back
3698:
3699: =head1 Access .tab File Data
3700:
3701: =over 4
3702:
1.648 raeburn 3703: =item * &languageids()
1.112 bowersj2 3704:
3705: returns list of all language ids
3706:
3707: =cut
3708:
1.14 harris41 3709: sub languageids {
1.16 harris41 3710: return sort(keys(%language));
1.14 harris41 3711: }
3712:
1.112 bowersj2 3713: =pod
3714:
1.648 raeburn 3715: =item * &languagedescription()
1.112 bowersj2 3716:
3717: returns description of a specified language id
3718:
3719: =cut
3720:
1.14 harris41 3721: sub languagedescription {
1.125 www 3722: my $code=shift;
3723: return ($supported_language{$code}?'* ':'').
3724: $language{$code}.
1.126 www 3725: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3726: }
3727:
1.1048 foxr 3728: =pod
3729:
3730: =item * &plainlanguagedescription
3731:
3732: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3733: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3734:
3735: =cut
3736:
1.145 www 3737: sub plainlanguagedescription {
3738: my $code=shift;
3739: return $language{$code};
3740: }
3741:
1.1048 foxr 3742: =pod
3743:
3744: =item * &supportedlanguagecode
3745:
3746: Returns the supported language code (e.g. sptutf maps to pt) given a language
3747: code.
3748:
3749: =cut
3750:
1.145 www 3751: sub supportedlanguagecode {
3752: my $code=shift;
3753: return $supported_language{$code};
1.97 www 3754: }
3755:
1.112 bowersj2 3756: =pod
3757:
1.1048 foxr 3758: =item * &latexlanguage()
3759:
3760: Given a language key code returns the correspondnig language to use
3761: to select the correct hyphenation on LaTeX printouts. This is undef if there
3762: is no supported hyphenation for the language code.
3763:
3764: =cut
3765:
3766: sub latexlanguage {
3767: my $code = shift;
3768: return $latex_language{$code};
3769: }
3770:
3771: =pod
3772:
3773: =item * &latexhyphenation()
3774:
3775: Same as above but what's supplied is the language as it might be stored
3776: in the metadata.
3777:
3778: =cut
3779:
3780: sub latexhyphenation {
3781: my $key = shift;
3782: return $latex_language_bykey{$key};
3783: }
3784:
3785: =pod
3786:
1.648 raeburn 3787: =item * ©rightids()
1.112 bowersj2 3788:
3789: returns list of all copyrights
3790:
3791: =cut
3792:
3793: sub copyrightids {
3794: return sort(keys(%cprtag));
3795: }
3796:
3797: =pod
3798:
1.648 raeburn 3799: =item * ©rightdescription()
1.112 bowersj2 3800:
3801: returns description of a specified copyright id
3802:
3803: =cut
3804:
3805: sub copyrightdescription {
1.166 www 3806: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3807: }
1.197 matthew 3808:
3809: =pod
3810:
1.648 raeburn 3811: =item * &source_copyrightids()
1.192 taceyjo1 3812:
3813: returns list of all source copyrights
3814:
3815: =cut
3816:
3817: sub source_copyrightids {
3818: return sort(keys(%scprtag));
3819: }
3820:
3821: =pod
3822:
1.648 raeburn 3823: =item * &source_copyrightdescription()
1.192 taceyjo1 3824:
3825: returns description of a specified source copyright id
3826:
3827: =cut
3828:
3829: sub source_copyrightdescription {
3830: return &mt($scprtag{shift(@_)});
3831: }
1.112 bowersj2 3832:
3833: =pod
3834:
1.648 raeburn 3835: =item * &filecategories()
1.112 bowersj2 3836:
3837: returns list of all file categories
3838:
3839: =cut
3840:
3841: sub filecategories {
3842: return sort(keys(%category_extensions));
3843: }
3844:
3845: =pod
3846:
1.648 raeburn 3847: =item * &filecategorytypes()
1.112 bowersj2 3848:
3849: returns list of file types belonging to a given file
3850: category
3851:
3852: =cut
3853:
3854: sub filecategorytypes {
1.356 albertel 3855: my ($cat) = @_;
3856: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3857: }
3858:
3859: =pod
3860:
1.648 raeburn 3861: =item * &fileembstyle()
1.112 bowersj2 3862:
3863: returns embedding style for a specified file type
3864:
3865: =cut
3866:
3867: sub fileembstyle {
3868: return $fe{lc(shift(@_))};
1.169 www 3869: }
3870:
1.351 www 3871: sub filemimetype {
3872: return $fm{lc(shift(@_))};
3873: }
3874:
1.169 www 3875:
3876: sub filecategoryselect {
3877: my ($name,$value)=@_;
1.189 matthew 3878: return &select_form($value,$name,
1.970 raeburn 3879: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3880: }
3881:
3882: =pod
3883:
1.648 raeburn 3884: =item * &filedescription()
1.112 bowersj2 3885:
3886: returns description for a specified file type
3887:
3888: =cut
3889:
3890: sub filedescription {
1.188 matthew 3891: my $file_description = $fd{lc(shift())};
3892: $file_description =~ s:([\[\]]):~$1:g;
3893: return &mt($file_description);
1.112 bowersj2 3894: }
3895:
3896: =pod
3897:
1.648 raeburn 3898: =item * &filedescriptionex()
1.112 bowersj2 3899:
3900: returns description for a specified file type with
3901: extra formatting
3902:
3903: =cut
3904:
3905: sub filedescriptionex {
3906: my $ex=shift;
1.188 matthew 3907: my $file_description = $fd{lc($ex)};
3908: $file_description =~ s:([\[\]]):~$1:g;
3909: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3910: }
3911:
3912: # End of .tab access
3913: =pod
3914:
3915: =back
3916:
3917: =cut
3918:
3919: # ------------------------------------------------------------------ File Types
3920: sub fileextensions {
3921: return sort(keys(%fe));
3922: }
3923:
1.97 www 3924: # ----------------------------------------------------------- Display Languages
3925: # returns a hash with all desired display languages
3926: #
3927:
3928: sub display_languages {
3929: my %languages=();
1.695 raeburn 3930: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3931: $languages{$lang}=1;
1.97 www 3932: }
3933: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3934: if ($env{'form.displaylanguage'}) {
1.356 albertel 3935: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3936: $languages{$lang}=1;
1.97 www 3937: }
3938: }
3939: return %languages;
1.14 harris41 3940: }
3941:
1.582 albertel 3942: sub languages {
3943: my ($possible_langs) = @_;
1.695 raeburn 3944: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3945: if (!ref($possible_langs)) {
3946: if( wantarray ) {
3947: return @preferred_langs;
3948: } else {
3949: return $preferred_langs[0];
3950: }
3951: }
3952: my %possibilities = map { $_ => 1 } (@$possible_langs);
3953: my @preferred_possibilities;
3954: foreach my $preferred_lang (@preferred_langs) {
3955: if (exists($possibilities{$preferred_lang})) {
3956: push(@preferred_possibilities, $preferred_lang);
3957: }
3958: }
3959: if( wantarray ) {
3960: return @preferred_possibilities;
3961: }
3962: return $preferred_possibilities[0];
3963: }
3964:
1.742 raeburn 3965: sub user_lang {
3966: my ($touname,$toudom,$fromcid) = @_;
3967: my @userlangs;
3968: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3969: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3970: $env{'course.'.$fromcid.'.languages'}));
3971: } else {
3972: my %langhash = &getlangs($touname,$toudom);
3973: if ($langhash{'languages'} ne '') {
3974: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3975: } else {
3976: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3977: if ($domdefs{'lang_def'} ne '') {
3978: @userlangs = ($domdefs{'lang_def'});
3979: }
3980: }
3981: }
3982: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3983: my $user_lh = Apache::localize->get_handle(@languages);
3984: return $user_lh;
3985: }
3986:
3987:
1.112 bowersj2 3988: ###############################################################
3989: ## Student Answer Attempts ##
3990: ###############################################################
3991:
3992: =pod
3993:
3994: =head1 Alternate Problem Views
3995:
3996: =over 4
3997:
1.648 raeburn 3998: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 3999: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4000:
4001: Return string with previous attempt on problem. Arguments:
4002:
4003: =over 4
4004:
4005: =item * $symb: Problem, including path
4006:
4007: =item * $username: username of the desired student
4008:
4009: =item * $domain: domain of the desired student
1.14 harris41 4010:
1.112 bowersj2 4011: =item * $course: Course ID
1.14 harris41 4012:
1.112 bowersj2 4013: =item * $getattempt: Leave blank for all attempts, otherwise put
4014: something
1.14 harris41 4015:
1.112 bowersj2 4016: =item * $regexp: if string matches this regexp, the string will be
4017: sent to $gradesub
1.14 harris41 4018:
1.112 bowersj2 4019: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4020:
1.1199 raeburn 4021: =item * $usec: section of the desired student
4022:
4023: =item * $identifier: counter for student (multiple students one problem) or
4024: problem (one student; whole sequence).
4025:
1.112 bowersj2 4026: =back
1.14 harris41 4027:
1.112 bowersj2 4028: The output string is a table containing all desired attempts, if any.
1.16 harris41 4029:
1.112 bowersj2 4030: =cut
1.1 albertel 4031:
4032: sub get_previous_attempt {
1.1199 raeburn 4033: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4034: my $prevattempts='';
1.43 ng 4035: no strict 'refs';
1.1 albertel 4036: if ($symb) {
1.3 albertel 4037: my (%returnhash)=
4038: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4039: if ($returnhash{'version'}) {
4040: my %lasthash=();
4041: my $version;
4042: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 4043: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
4044: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 4045: }
1.1 albertel 4046: }
1.596 albertel 4047: $prevattempts=&start_data_table().&start_data_table_header_row();
4048: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4049: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4050: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4051: foreach my $key (sort(keys(%lasthash))) {
4052: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4053: if ($#parts > 0) {
1.31 albertel 4054: my $data=$parts[-1];
1.989 raeburn 4055: next if ($data eq 'foilorder');
1.31 albertel 4056: pop(@parts);
1.1010 www 4057: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4058: if ($data eq 'type') {
4059: unless ($showsurv) {
4060: my $id = join(',',@parts);
4061: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4062: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4063: $lasthidden{$ign.'.'.$id} = 1;
4064: }
1.945 raeburn 4065: }
1.1199 raeburn 4066: if ($identifier ne '') {
4067: my $id = join(',',@parts);
4068: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4069: $domain,$username,$usec,undef,$course) =~ /^no/) {
4070: $hidestatus{$ign.'.'.$id} = 1;
4071: }
4072: }
4073: } elsif ($data eq 'regrader') {
4074: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4075: my $id = join(',',@parts);
4076: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4077: }
1.1010 www 4078: }
1.31 albertel 4079: } else {
1.41 ng 4080: if ($#parts == 0) {
4081: $prevattempts.='<th>'.$parts[0].'</th>';
4082: } else {
4083: $prevattempts.='<th>'.$ign.'</th>';
4084: }
1.31 albertel 4085: }
1.16 harris41 4086: }
1.596 albertel 4087: $prevattempts.=&end_data_table_header_row();
1.40 ng 4088: if ($getattempt eq '') {
1.1199 raeburn 4089: my (%solved,%resets,%probstatus);
1.1200 raeburn 4090: if (($identifier ne '') && (keys(%regraded) > 0)) {
4091: for ($version=1;$version<=$returnhash{'version'};$version++) {
4092: foreach my $id (keys(%regraded)) {
4093: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4094: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4095: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4096: push(@{$resets{$id}},$version);
1.1199 raeburn 4097: }
4098: }
4099: }
1.1200 raeburn 4100: }
4101: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4102: my (@hidden,@unsolved);
1.945 raeburn 4103: if (%typeparts) {
4104: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4105: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4106: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4107: push(@hidden,$id);
1.1199 raeburn 4108: } elsif ($identifier ne '') {
4109: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4110: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4111: ($hidestatus{$id})) {
1.1200 raeburn 4112: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4113: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4114: push(@{$solved{$id}},$version);
4115: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4116: (ref($solved{$id}) eq 'ARRAY')) {
4117: my $skip;
4118: if (ref($resets{$id}) eq 'ARRAY') {
4119: foreach my $reset (@{$resets{$id}}) {
4120: if ($reset > $solved{$id}[-1]) {
4121: $skip=1;
4122: last;
4123: }
4124: }
4125: }
4126: unless ($skip) {
4127: my ($ign,$partslist) = split(/\./,$id,2);
4128: push(@unsolved,$partslist);
4129: }
4130: }
4131: }
1.945 raeburn 4132: }
4133: }
4134: }
4135: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4136: '<td>'.&mt('Transaction [_1]',$version);
4137: if (@unsolved) {
4138: $prevattempts .= '<span class="LC_nobreak"><label>'.
4139: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4140: &mt('Hide').'</label></span>';
4141: }
4142: $prevattempts .= '</td>';
1.945 raeburn 4143: if (@hidden) {
4144: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4145: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4146: my $hide;
4147: foreach my $id (@hidden) {
4148: if ($key =~ /^\Q$id\E/) {
4149: $hide = 1;
4150: last;
4151: }
4152: }
4153: if ($hide) {
4154: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4155: if (($data eq 'award') || ($data eq 'awarddetail')) {
4156: my $value = &format_previous_attempt_value($key,
4157: $returnhash{$version.':'.$key});
1.1173 kruse 4158: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4159: } else {
4160: $prevattempts.='<td> </td>';
4161: }
4162: } else {
4163: if ($key =~ /\./) {
4164: my $value = &format_previous_attempt_value($key,
4165: $returnhash{$version.':'.$key});
1.1173 kruse 4166: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4167: } else {
4168: $prevattempts.='<td> </td>';
4169: }
4170: }
4171: }
4172: } else {
4173: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4174: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4175: my $value = &format_previous_attempt_value($key,
4176: $returnhash{$version.':'.$key});
1.1173 kruse 4177: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4178: }
4179: }
4180: $prevattempts.=&end_data_table_row();
1.40 ng 4181: }
1.1 albertel 4182: }
1.945 raeburn 4183: my @currhidden = keys(%lasthidden);
1.596 albertel 4184: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4185: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4186: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4187: if (%typeparts) {
4188: my $hidden;
4189: foreach my $id (@currhidden) {
4190: if ($key =~ /^\Q$id\E/) {
4191: $hidden = 1;
4192: last;
4193: }
4194: }
4195: if ($hidden) {
4196: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4197: if (($data eq 'award') || ($data eq 'awarddetail')) {
4198: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4199: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4200: $value = &$gradesub($value);
4201: }
1.1173 kruse 4202: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4203: } else {
4204: $prevattempts.='<td> </td>';
4205: }
4206: } else {
4207: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4208: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4209: $value = &$gradesub($value);
4210: }
1.1173 kruse 4211: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4212: }
4213: } else {
4214: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4215: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4216: $value = &$gradesub($value);
4217: }
1.1173 kruse 4218: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4219: }
1.16 harris41 4220: }
1.596 albertel 4221: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4222: } else {
1.596 albertel 4223: $prevattempts=
4224: &start_data_table().&start_data_table_row().
4225: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4226: &end_data_table_row().&end_data_table();
1.1 albertel 4227: }
4228: } else {
1.596 albertel 4229: $prevattempts=
4230: &start_data_table().&start_data_table_row().
4231: '<td>'.&mt('No data.').'</td>'.
4232: &end_data_table_row().&end_data_table();
1.1 albertel 4233: }
1.10 albertel 4234: }
4235:
1.581 albertel 4236: sub format_previous_attempt_value {
4237: my ($key,$value) = @_;
1.1011 www 4238: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4239: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4240: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4241: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4242: } elsif ($key =~ /answerstring$/) {
4243: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4244: my @answer = %answers;
4245: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4246: my @anskeys = sort(keys(%answers));
4247: if (@anskeys == 1) {
4248: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4249: if ($answer =~ m{\0}) {
4250: $answer =~ s{\0}{,}g;
1.988 raeburn 4251: }
4252: my $tag_internal_answer_name = 'INTERNAL';
4253: if ($anskeys[0] eq $tag_internal_answer_name) {
4254: $value = $answer;
4255: } else {
4256: $value = $anskeys[0].'='.$answer;
4257: }
4258: } else {
4259: foreach my $ans (@anskeys) {
4260: my $answer = $answers{$ans};
1.1001 raeburn 4261: if ($answer =~ m{\0}) {
4262: $answer =~ s{\0}{,}g;
1.988 raeburn 4263: }
4264: $value .= $ans.'='.$answer.'<br />';;
4265: }
4266: }
1.581 albertel 4267: } else {
1.1173 kruse 4268: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4269: }
4270: return $value;
4271: }
4272:
4273:
1.107 albertel 4274: sub relative_to_absolute {
4275: my ($url,$output)=@_;
4276: my $parser=HTML::TokeParser->new(\$output);
4277: my $token;
4278: my $thisdir=$url;
4279: my @rlinks=();
4280: while ($token=$parser->get_token) {
4281: if ($token->[0] eq 'S') {
4282: if ($token->[1] eq 'a') {
4283: if ($token->[2]->{'href'}) {
4284: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4285: }
4286: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4287: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4288: } elsif ($token->[1] eq 'base') {
4289: $thisdir=$token->[2]->{'href'};
4290: }
4291: }
4292: }
4293: $thisdir=~s-/[^/]*$--;
1.356 albertel 4294: foreach my $link (@rlinks) {
1.726 raeburn 4295: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4296: ($link=~/^\//) ||
4297: ($link=~/^javascript:/i) ||
4298: ($link=~/^mailto:/i) ||
4299: ($link=~/^\#/)) {
4300: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4301: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4302: }
4303: }
4304: # -------------------------------------------------- Deal with Applet codebases
4305: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4306: return $output;
4307: }
4308:
1.112 bowersj2 4309: =pod
4310:
1.648 raeburn 4311: =item * &get_student_view()
1.112 bowersj2 4312:
4313: show a snapshot of what student was looking at
4314:
4315: =cut
4316:
1.10 albertel 4317: sub get_student_view {
1.186 albertel 4318: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4319: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4320: my (%form);
1.10 albertel 4321: my @elements=('symb','courseid','domain','username');
4322: foreach my $element (@elements) {
1.186 albertel 4323: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4324: }
1.186 albertel 4325: if (defined($moreenv)) {
4326: %form=(%form,%{$moreenv});
4327: }
1.236 albertel 4328: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4329: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4330: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4331: $userview=~s/\<body[^\>]*\>//gi;
4332: $userview=~s/\<\/body\>//gi;
4333: $userview=~s/\<html\>//gi;
4334: $userview=~s/\<\/html\>//gi;
4335: $userview=~s/\<head\>//gi;
4336: $userview=~s/\<\/head\>//gi;
4337: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4338: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4339: if (wantarray) {
4340: return ($userview,$response);
4341: } else {
4342: return $userview;
4343: }
4344: }
4345:
4346: sub get_student_view_with_retries {
4347: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4348:
4349: my $ok = 0; # True if we got a good response.
4350: my $content;
4351: my $response;
4352:
4353: # Try to get the student_view done. within the retries count:
4354:
4355: do {
4356: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4357: $ok = $response->is_success;
4358: if (!$ok) {
4359: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4360: }
4361: $retries--;
4362: } while (!$ok && ($retries > 0));
4363:
4364: if (!$ok) {
4365: $content = ''; # On error return an empty content.
4366: }
1.651 www 4367: if (wantarray) {
4368: return ($content, $response);
4369: } else {
4370: return $content;
4371: }
1.11 albertel 4372: }
4373:
1.112 bowersj2 4374: =pod
4375:
1.648 raeburn 4376: =item * &get_student_answers()
1.112 bowersj2 4377:
4378: show a snapshot of how student was answering problem
4379:
4380: =cut
4381:
1.11 albertel 4382: sub get_student_answers {
1.100 sakharuk 4383: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4384: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4385: my (%moreenv);
1.11 albertel 4386: my @elements=('symb','courseid','domain','username');
4387: foreach my $element (@elements) {
1.186 albertel 4388: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4389: }
1.186 albertel 4390: $moreenv{'grade_target'}='answer';
4391: %moreenv=(%form,%moreenv);
1.497 raeburn 4392: $feedurl = &Apache::lonnet::clutter($feedurl);
4393: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4394: return $userview;
1.1 albertel 4395: }
1.116 albertel 4396:
4397: =pod
4398:
4399: =item * &submlink()
4400:
1.242 albertel 4401: Inputs: $text $uname $udom $symb $target
1.116 albertel 4402:
4403: Returns: A link to grades.pm such as to see the SUBM view of a student
4404:
4405: =cut
4406:
4407: ###############################################
4408: sub submlink {
1.242 albertel 4409: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4410: if (!($uname && $udom)) {
4411: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4412: &Apache::lonnet::whichuser($symb);
1.116 albertel 4413: if (!$symb) { $symb=$cursymb; }
4414: }
1.254 matthew 4415: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4416: $symb=&escape($symb);
1.960 bisitz 4417: if ($target) { $target=" target=\"$target\""; }
4418: return
4419: '<a href="/adm/grades?command=submission'.
4420: '&symb='.$symb.
4421: '&student='.$uname.
4422: '&userdom='.$udom.'"'.
4423: $target.'>'.$text.'</a>';
1.242 albertel 4424: }
4425: ##############################################
4426:
4427: =pod
4428:
4429: =item * &pgrdlink()
4430:
4431: Inputs: $text $uname $udom $symb $target
4432:
4433: Returns: A link to grades.pm such as to see the PGRD view of a student
4434:
4435: =cut
4436:
4437: ###############################################
4438: sub pgrdlink {
4439: my $link=&submlink(@_);
4440: $link=~s/(&command=submission)/$1&showgrading=yes/;
4441: return $link;
4442: }
4443: ##############################################
4444:
4445: =pod
4446:
4447: =item * &pprmlink()
4448:
4449: Inputs: $text $uname $udom $symb $target
4450:
4451: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4452: student and a specific resource
1.242 albertel 4453:
4454: =cut
4455:
4456: ###############################################
4457: sub pprmlink {
4458: my ($text,$uname,$udom,$symb,$target)=@_;
4459: if (!($uname && $udom)) {
4460: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4461: &Apache::lonnet::whichuser($symb);
1.242 albertel 4462: if (!$symb) { $symb=$cursymb; }
4463: }
1.254 matthew 4464: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4465: $symb=&escape($symb);
1.242 albertel 4466: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4467: return '<a href="/adm/parmset?command=set&'.
4468: 'symb='.$symb.'&uname='.$uname.
4469: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4470: }
4471: ##############################################
1.37 matthew 4472:
1.112 bowersj2 4473: =pod
4474:
4475: =back
4476:
4477: =cut
4478:
1.37 matthew 4479: ###############################################
1.51 www 4480:
4481:
4482: sub timehash {
1.687 raeburn 4483: my ($thistime) = @_;
4484: my $timezone = &Apache::lonlocal::gettimezone();
4485: my $dt = DateTime->from_epoch(epoch => $thistime)
4486: ->set_time_zone($timezone);
4487: my $wday = $dt->day_of_week();
4488: if ($wday == 7) { $wday = 0; }
4489: return ( 'second' => $dt->second(),
4490: 'minute' => $dt->minute(),
4491: 'hour' => $dt->hour(),
4492: 'day' => $dt->day_of_month(),
4493: 'month' => $dt->month(),
4494: 'year' => $dt->year(),
4495: 'weekday' => $wday,
4496: 'dayyear' => $dt->day_of_year(),
4497: 'dlsav' => $dt->is_dst() );
1.51 www 4498: }
4499:
1.370 www 4500: sub utc_string {
4501: my ($date)=@_;
1.371 www 4502: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4503: }
4504:
1.51 www 4505: sub maketime {
4506: my %th=@_;
1.687 raeburn 4507: my ($epoch_time,$timezone,$dt);
4508: $timezone = &Apache::lonlocal::gettimezone();
4509: eval {
4510: $dt = DateTime->new( year => $th{'year'},
4511: month => $th{'month'},
4512: day => $th{'day'},
4513: hour => $th{'hour'},
4514: minute => $th{'minute'},
4515: second => $th{'second'},
4516: time_zone => $timezone,
4517: );
4518: };
4519: if (!$@) {
4520: $epoch_time = $dt->epoch;
4521: if ($epoch_time) {
4522: return $epoch_time;
4523: }
4524: }
1.51 www 4525: return POSIX::mktime(
4526: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4527: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4528: }
4529:
4530: #########################################
1.51 www 4531:
4532: sub findallcourses {
1.482 raeburn 4533: my ($roles,$uname,$udom) = @_;
1.355 albertel 4534: my %roles;
4535: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4536: my %courses;
1.51 www 4537: my $now=time;
1.482 raeburn 4538: if (!defined($uname)) {
4539: $uname = $env{'user.name'};
4540: }
4541: if (!defined($udom)) {
4542: $udom = $env{'user.domain'};
4543: }
4544: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4545: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4546: if (!%roles) {
4547: %roles = (
4548: cc => 1,
1.907 raeburn 4549: co => 1,
1.482 raeburn 4550: in => 1,
4551: ep => 1,
4552: ta => 1,
4553: cr => 1,
4554: st => 1,
4555: );
4556: }
4557: foreach my $entry (keys(%roleshash)) {
4558: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4559: if ($trole =~ /^cr/) {
4560: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4561: } else {
4562: next if (!exists($roles{$trole}));
4563: }
4564: if ($tend) {
4565: next if ($tend < $now);
4566: }
4567: if ($tstart) {
4568: next if ($tstart > $now);
4569: }
1.1058 raeburn 4570: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4571: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4572: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4573: if ($secpart eq '') {
4574: ($cnum,$role) = split(/_/,$cnumpart);
4575: $sec = 'none';
1.1058 raeburn 4576: $value .= $cnum.'/';
1.482 raeburn 4577: } else {
4578: $cnum = $cnumpart;
4579: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4580: $value .= $cnum.'/'.$sec;
4581: }
4582: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4583: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4584: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4585: }
4586: } else {
4587: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4588: }
1.482 raeburn 4589: }
4590: } else {
4591: foreach my $key (keys(%env)) {
1.483 albertel 4592: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4593: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4594: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4595: next if ($role eq 'ca' || $role eq 'aa');
4596: next if (%roles && !exists($roles{$role}));
4597: my ($starttime,$endtime)=split(/\./,$env{$key});
4598: my $active=1;
4599: if ($starttime) {
4600: if ($now<$starttime) { $active=0; }
4601: }
4602: if ($endtime) {
4603: if ($now>$endtime) { $active=0; }
4604: }
4605: if ($active) {
1.1058 raeburn 4606: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4607: if ($sec eq '') {
4608: $sec = 'none';
1.1058 raeburn 4609: } else {
4610: $value .= $sec;
4611: }
4612: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4613: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4614: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4615: }
4616: } else {
4617: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4618: }
1.474 raeburn 4619: }
4620: }
1.51 www 4621: }
4622: }
1.474 raeburn 4623: return %courses;
1.51 www 4624: }
1.37 matthew 4625:
1.54 www 4626: ###############################################
1.474 raeburn 4627:
4628: sub blockcheck {
1.1189 raeburn 4629: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4630:
1.1189 raeburn 4631: if (defined($udom) && defined($uname)) {
4632: # If uname and udom are for a course, check for blocks in the course.
4633: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4634: my ($startblock,$endblock,$triggerblock) =
4635: &get_blocks($setters,$activity,$udom,$uname,$url);
4636: return ($startblock,$endblock,$triggerblock);
4637: }
4638: } else {
1.490 raeburn 4639: $udom = $env{'user.domain'};
4640: $uname = $env{'user.name'};
4641: }
4642:
1.502 raeburn 4643: my $startblock = 0;
4644: my $endblock = 0;
1.1062 raeburn 4645: my $triggerblock = '';
1.482 raeburn 4646: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4647:
1.490 raeburn 4648: # If uname is for a user, and activity is course-specific, i.e.,
4649: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4650:
1.490 raeburn 4651: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4652: $activity eq 'groups' || $activity eq 'printout') &&
4653: ($env{'request.course.id'})) {
1.490 raeburn 4654: foreach my $key (keys(%live_courses)) {
4655: if ($key ne $env{'request.course.id'}) {
4656: delete($live_courses{$key});
4657: }
4658: }
4659: }
4660:
4661: my $otheruser = 0;
4662: my %own_courses;
4663: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4664: # Resource belongs to user other than current user.
4665: $otheruser = 1;
4666: # Gather courses for current user
4667: %own_courses =
4668: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4669: }
4670:
4671: # Gather active course roles - course coordinator, instructor,
4672: # exam proctor, ta, student, or custom role.
1.474 raeburn 4673:
4674: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4675: my ($cdom,$cnum);
4676: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4677: $cdom = $env{'course.'.$course.'.domain'};
4678: $cnum = $env{'course.'.$course.'.num'};
4679: } else {
1.490 raeburn 4680: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4681: }
4682: my $no_ownblock = 0;
4683: my $no_userblock = 0;
1.533 raeburn 4684: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4685: # Check if current user has 'evb' priv for this
4686: if (defined($own_courses{$course})) {
4687: foreach my $sec (keys(%{$own_courses{$course}})) {
4688: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4689: if ($sec ne 'none') {
4690: $checkrole .= '/'.$sec;
4691: }
4692: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4693: $no_ownblock = 1;
4694: last;
4695: }
4696: }
4697: }
4698: # if they have 'evb' priv and are currently not playing student
4699: next if (($no_ownblock) &&
4700: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4701: }
1.474 raeburn 4702: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4703: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4704: if ($sec ne 'none') {
1.482 raeburn 4705: $checkrole .= '/'.$sec;
1.474 raeburn 4706: }
1.490 raeburn 4707: if ($otheruser) {
4708: # Resource belongs to user other than current user.
4709: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4710: my (%allroles,%userroles);
4711: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4712: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4713: my ($trole,$tdom,$tnum,$tsec);
4714: if ($entry =~ /^cr/) {
4715: ($trole,$tdom,$tnum,$tsec) =
4716: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4717: } else {
4718: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4719: }
4720: my ($spec,$area,$trest);
4721: $area = '/'.$tdom.'/'.$tnum;
4722: $trest = $tnum;
4723: if ($tsec ne '') {
4724: $area .= '/'.$tsec;
4725: $trest .= '/'.$tsec;
4726: }
4727: $spec = $trole.'.'.$area;
4728: if ($trole =~ /^cr/) {
4729: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4730: $tdom,$spec,$trest,$area);
4731: } else {
4732: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4733: $tdom,$spec,$trest,$area);
4734: }
4735: }
4736: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4737: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4738: if ($1) {
4739: $no_userblock = 1;
4740: last;
4741: }
1.486 raeburn 4742: }
4743: }
1.490 raeburn 4744: } else {
4745: # Resource belongs to current user
4746: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4747: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4748: $no_ownblock = 1;
4749: last;
4750: }
1.474 raeburn 4751: }
4752: }
4753: # if they have the evb priv and are currently not playing student
1.482 raeburn 4754: next if (($no_ownblock) &&
1.491 albertel 4755: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4756: next if ($no_userblock);
1.474 raeburn 4757:
1.866 kalberla 4758: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4759: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4760:
1.1062 raeburn 4761: my ($start,$end,$trigger) =
4762: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4763: if (($start != 0) &&
4764: (($startblock == 0) || ($startblock > $start))) {
4765: $startblock = $start;
1.1062 raeburn 4766: if ($trigger ne '') {
4767: $triggerblock = $trigger;
4768: }
1.502 raeburn 4769: }
4770: if (($end != 0) &&
4771: (($endblock == 0) || ($endblock < $end))) {
4772: $endblock = $end;
1.1062 raeburn 4773: if ($trigger ne '') {
4774: $triggerblock = $trigger;
4775: }
1.502 raeburn 4776: }
1.490 raeburn 4777: }
1.1062 raeburn 4778: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4779: }
4780:
4781: sub get_blocks {
1.1062 raeburn 4782: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4783: my $startblock = 0;
4784: my $endblock = 0;
1.1062 raeburn 4785: my $triggerblock = '';
1.490 raeburn 4786: my $course = $cdom.'_'.$cnum;
4787: $setters->{$course} = {};
4788: $setters->{$course}{'staff'} = [];
4789: $setters->{$course}{'times'} = [];
1.1062 raeburn 4790: $setters->{$course}{'triggers'} = [];
4791: my (@blockers,%triggered);
4792: my $now = time;
4793: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4794: if ($activity eq 'docs') {
4795: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4796: foreach my $block (@blockers) {
4797: if ($block =~ /^firstaccess____(.+)$/) {
4798: my $item = $1;
4799: my $type = 'map';
4800: my $timersymb = $item;
4801: if ($item eq 'course') {
4802: $type = 'course';
4803: } elsif ($item =~ /___\d+___/) {
4804: $type = 'resource';
4805: } else {
4806: $timersymb = &Apache::lonnet::symbread($item);
4807: }
4808: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4809: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4810: $triggered{$block} = {
4811: start => $start,
4812: end => $end,
4813: type => $type,
4814: };
4815: }
4816: }
4817: } else {
4818: foreach my $block (keys(%commblocks)) {
4819: if ($block =~ m/^(\d+)____(\d+)$/) {
4820: my ($start,$end) = ($1,$2);
4821: if ($start <= time && $end >= time) {
4822: if (ref($commblocks{$block}) eq 'HASH') {
4823: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4824: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4825: unless(grep(/^\Q$block\E$/,@blockers)) {
4826: push(@blockers,$block);
4827: }
4828: }
4829: }
4830: }
4831: }
4832: } elsif ($block =~ /^firstaccess____(.+)$/) {
4833: my $item = $1;
4834: my $timersymb = $item;
4835: my $type = 'map';
4836: if ($item eq 'course') {
4837: $type = 'course';
4838: } elsif ($item =~ /___\d+___/) {
4839: $type = 'resource';
4840: } else {
4841: $timersymb = &Apache::lonnet::symbread($item);
4842: }
4843: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4844: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4845: if ($start && $end) {
4846: if (($start <= time) && ($end >= time)) {
4847: unless (grep(/^\Q$block\E$/,@blockers)) {
4848: push(@blockers,$block);
4849: $triggered{$block} = {
4850: start => $start,
4851: end => $end,
4852: type => $type,
4853: };
4854: }
4855: }
1.490 raeburn 4856: }
1.1062 raeburn 4857: }
4858: }
4859: }
4860: foreach my $blocker (@blockers) {
4861: my ($staff_name,$staff_dom,$title,$blocks) =
4862: &parse_block_record($commblocks{$blocker});
4863: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4864: my ($start,$end,$triggertype);
4865: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4866: ($start,$end) = ($1,$2);
4867: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4868: $start = $triggered{$blocker}{'start'};
4869: $end = $triggered{$blocker}{'end'};
4870: $triggertype = $triggered{$blocker}{'type'};
4871: }
4872: if ($start) {
4873: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4874: if ($triggertype) {
4875: push(@{$$setters{$course}{'triggers'}},$triggertype);
4876: } else {
4877: push(@{$$setters{$course}{'triggers'}},0);
4878: }
4879: if ( ($startblock == 0) || ($startblock > $start) ) {
4880: $startblock = $start;
4881: if ($triggertype) {
4882: $triggerblock = $blocker;
1.474 raeburn 4883: }
4884: }
1.1062 raeburn 4885: if ( ($endblock == 0) || ($endblock < $end) ) {
4886: $endblock = $end;
4887: if ($triggertype) {
4888: $triggerblock = $blocker;
4889: }
4890: }
1.474 raeburn 4891: }
4892: }
1.1062 raeburn 4893: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4894: }
4895:
4896: sub parse_block_record {
4897: my ($record) = @_;
4898: my ($setuname,$setudom,$title,$blocks);
4899: if (ref($record) eq 'HASH') {
4900: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4901: $title = &unescape($record->{'event'});
4902: $blocks = $record->{'blocks'};
4903: } else {
4904: my @data = split(/:/,$record,3);
4905: if (scalar(@data) eq 2) {
4906: $title = $data[1];
4907: ($setuname,$setudom) = split(/@/,$data[0]);
4908: } else {
4909: ($setuname,$setudom,$title) = @data;
4910: }
4911: $blocks = { 'com' => 'on' };
4912: }
4913: return ($setuname,$setudom,$title,$blocks);
4914: }
4915:
1.854 kalberla 4916: sub blocking_status {
1.1189 raeburn 4917: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4918: my %setters;
1.890 droeschl 4919:
1.1061 raeburn 4920: # check for active blocking
1.1062 raeburn 4921: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 4922: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4923: my $blocked = 0;
4924: if ($startblock && $endblock) {
4925: $blocked = 1;
4926: }
1.890 droeschl 4927:
1.1061 raeburn 4928: # caller just wants to know whether a block is active
4929: if (!wantarray) { return $blocked; }
4930:
4931: # build a link to a popup window containing the details
4932: my $querystring = "?activity=$activity";
4933: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4934: if ($activity eq 'port') {
4935: $querystring .= "&udom=$udom" if $udom;
4936: $querystring .= "&uname=$uname" if $uname;
4937: } elsif ($activity eq 'docs') {
4938: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4939: }
1.1061 raeburn 4940:
4941: my $output .= <<'END_MYBLOCK';
4942: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4943: var options = "width=" + w + ",height=" + h + ",";
4944: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4945: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4946: var newWin = window.open(url, wdwName, options);
4947: newWin.focus();
4948: }
1.890 droeschl 4949: END_MYBLOCK
1.854 kalberla 4950:
1.1061 raeburn 4951: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4952:
1.1061 raeburn 4953: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4954: my $text = &mt('Communication Blocked');
4955: if ($activity eq 'docs') {
4956: $text = &mt('Content Access Blocked');
1.1063 raeburn 4957: } elsif ($activity eq 'printout') {
4958: $text = &mt('Printing Blocked');
1.1062 raeburn 4959: }
1.1061 raeburn 4960: $output .= <<"END_BLOCK";
1.867 kalberla 4961: <div class='LC_comblock'>
1.869 kalberla 4962: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4963: title='$text'>
4964: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4965: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4966: title='$text'>$text</a>
1.867 kalberla 4967: </div>
4968:
4969: END_BLOCK
1.474 raeburn 4970:
1.1061 raeburn 4971: return ($blocked, $output);
1.854 kalberla 4972: }
1.490 raeburn 4973:
1.60 matthew 4974: ###############################################
4975:
1.682 raeburn 4976: sub check_ip_acc {
1.1201 raeburn 4977: my ($acc,$clientip)=@_;
1.682 raeburn 4978: &Apache::lonxml::debug("acc is $acc");
4979: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4980: return 1;
4981: }
4982: my $allowed=0;
1.1201 raeburn 4983: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
1.682 raeburn 4984:
4985: my $name;
4986: foreach my $pattern (split(',',$acc)) {
4987: $pattern =~ s/^\s*//;
4988: $pattern =~ s/\s*$//;
4989: if ($pattern =~ /\*$/) {
4990: #35.8.*
4991: $pattern=~s/\*//;
4992: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4993: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4994: #35.8.3.[34-56]
4995: my $low=$2;
4996: my $high=$3;
4997: $pattern=$1;
4998: if ($ip =~ /^\Q$pattern\E/) {
4999: my $last=(split(/\./,$ip))[3];
5000: if ($last <=$high && $last >=$low) { $allowed=1; }
5001: }
5002: } elsif ($pattern =~ /^\*/) {
5003: #*.msu.edu
5004: $pattern=~s/\*//;
5005: if (!defined($name)) {
5006: use Socket;
5007: my $netaddr=inet_aton($ip);
5008: ($name)=gethostbyaddr($netaddr,AF_INET);
5009: }
5010: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5011: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5012: #127.0.0.1
5013: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5014: } else {
5015: #some.name.com
5016: if (!defined($name)) {
5017: use Socket;
5018: my $netaddr=inet_aton($ip);
5019: ($name)=gethostbyaddr($netaddr,AF_INET);
5020: }
5021: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5022: }
5023: if ($allowed) { last; }
5024: }
5025: return $allowed;
5026: }
5027:
5028: ###############################################
5029:
1.60 matthew 5030: =pod
5031:
1.112 bowersj2 5032: =head1 Domain Template Functions
5033:
5034: =over 4
5035:
5036: =item * &determinedomain()
1.60 matthew 5037:
5038: Inputs: $domain (usually will be undef)
5039:
1.63 www 5040: Returns: Determines which domain should be used for designs
1.60 matthew 5041:
5042: =cut
1.54 www 5043:
1.60 matthew 5044: ###############################################
1.63 www 5045: sub determinedomain {
5046: my $domain=shift;
1.531 albertel 5047: if (! $domain) {
1.60 matthew 5048: # Determine domain if we have not been given one
1.893 raeburn 5049: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5050: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5051: if ($env{'request.role.domain'}) {
5052: $domain=$env{'request.role.domain'};
1.60 matthew 5053: }
5054: }
1.63 www 5055: return $domain;
5056: }
5057: ###############################################
1.517 raeburn 5058:
1.518 albertel 5059: sub devalidate_domconfig_cache {
5060: my ($udom)=@_;
5061: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5062: }
5063:
5064: # ---------------------- Get domain configuration for a domain
5065: sub get_domainconf {
5066: my ($udom) = @_;
5067: my $cachetime=1800;
5068: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5069: if (defined($cached)) { return %{$result}; }
5070:
5071: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5072: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5073: my (%designhash,%legacy);
1.518 albertel 5074: if (keys(%domconfig) > 0) {
5075: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5076: if (keys(%{$domconfig{'login'}})) {
5077: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5078: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5079: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5080: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5081: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5082: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5083: if ($key eq 'loginvia') {
5084: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5085: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5086: $designhash{$udom.'.login.loginvia'} = $server;
5087: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5088:
5089: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5090: } else {
5091: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5092: }
1.948 raeburn 5093: }
1.1208 raeburn 5094: } elsif ($key eq 'headtag') {
5095: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5096: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5097: }
1.946 raeburn 5098: }
1.1208 raeburn 5099: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5100: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5101: }
1.946 raeburn 5102: }
5103: }
5104: }
5105: } else {
5106: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5107: $designhash{$udom.'.login.'.$key.'_'.$img} =
5108: $domconfig{'login'}{$key}{$img};
5109: }
1.699 raeburn 5110: }
5111: } else {
5112: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5113: }
1.632 raeburn 5114: }
5115: } else {
5116: $legacy{'login'} = 1;
1.518 albertel 5117: }
1.632 raeburn 5118: } else {
5119: $legacy{'login'} = 1;
1.518 albertel 5120: }
5121: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5122: if (keys(%{$domconfig{'rolecolors'}})) {
5123: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5124: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5125: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5126: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5127: }
1.518 albertel 5128: }
5129: }
1.632 raeburn 5130: } else {
5131: $legacy{'rolecolors'} = 1;
1.518 albertel 5132: }
1.632 raeburn 5133: } else {
5134: $legacy{'rolecolors'} = 1;
1.518 albertel 5135: }
1.948 raeburn 5136: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5137: if ($domconfig{'autoenroll'}{'co-owners'}) {
5138: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5139: }
5140: }
1.632 raeburn 5141: if (keys(%legacy) > 0) {
5142: my %legacyhash = &get_legacy_domconf($udom);
5143: foreach my $item (keys(%legacyhash)) {
5144: if ($item =~ /^\Q$udom\E\.login/) {
5145: if ($legacy{'login'}) {
5146: $designhash{$item} = $legacyhash{$item};
5147: }
5148: } else {
5149: if ($legacy{'rolecolors'}) {
5150: $designhash{$item} = $legacyhash{$item};
5151: }
1.518 albertel 5152: }
5153: }
5154: }
1.632 raeburn 5155: } else {
5156: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5157: }
5158: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5159: $cachetime);
5160: return %designhash;
5161: }
5162:
1.632 raeburn 5163: sub get_legacy_domconf {
5164: my ($udom) = @_;
5165: my %legacyhash;
5166: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5167: my $designfile = $designdir.'/'.$udom.'.tab';
5168: if (-e $designfile) {
5169: if ( open (my $fh,"<$designfile") ) {
5170: while (my $line = <$fh>) {
5171: next if ($line =~ /^\#/);
5172: chomp($line);
5173: my ($key,$val)=(split(/\=/,$line));
5174: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5175: }
5176: close($fh);
5177: }
5178: }
1.1026 raeburn 5179: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5180: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5181: }
5182: return %legacyhash;
5183: }
5184:
1.63 www 5185: =pod
5186:
1.112 bowersj2 5187: =item * &domainlogo()
1.63 www 5188:
5189: Inputs: $domain (usually will be undef)
5190:
5191: Returns: A link to a domain logo, if the domain logo exists.
5192: If the domain logo does not exist, a description of the domain.
5193:
5194: =cut
1.112 bowersj2 5195:
1.63 www 5196: ###############################################
5197: sub domainlogo {
1.517 raeburn 5198: my $domain = &determinedomain(shift);
1.518 albertel 5199: my %designhash = &get_domainconf($domain);
1.517 raeburn 5200: # See if there is a logo
5201: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5202: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5203: if ($imgsrc =~ m{^/(adm|res)/}) {
5204: if ($imgsrc =~ m{^/res/}) {
5205: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5206: &Apache::lonnet::repcopy($local_name);
5207: }
5208: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5209: }
5210: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5211: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5212: return &Apache::lonnet::domain($domain,'description');
1.59 www 5213: } else {
1.60 matthew 5214: return '';
1.59 www 5215: }
5216: }
1.63 www 5217: ##############################################
5218:
5219: =pod
5220:
1.112 bowersj2 5221: =item * &designparm()
1.63 www 5222:
5223: Inputs: $which parameter; $domain (usually will be undef)
5224:
5225: Returns: value of designparamter $which
5226:
5227: =cut
1.112 bowersj2 5228:
1.397 albertel 5229:
1.400 albertel 5230: ##############################################
1.397 albertel 5231: sub designparm {
5232: my ($which,$domain)=@_;
5233: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5234: return $env{'environment.color.'.$which};
1.96 www 5235: }
1.63 www 5236: $domain=&determinedomain($domain);
1.1016 raeburn 5237: my %domdesign;
5238: unless ($domain eq 'public') {
5239: %domdesign = &get_domainconf($domain);
5240: }
1.520 raeburn 5241: my $output;
1.517 raeburn 5242: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5243: $output = $domdesign{$domain.'.'.$which};
1.63 www 5244: } else {
1.520 raeburn 5245: $output = $defaultdesign{$which};
5246: }
5247: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5248: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5249: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5250: if ($output =~ m{^/res/}) {
5251: my $local_name = &Apache::lonnet::filelocation('',$output);
5252: &Apache::lonnet::repcopy($local_name);
5253: }
1.520 raeburn 5254: $output = &lonhttpdurl($output);
5255: }
1.63 www 5256: }
1.520 raeburn 5257: return $output;
1.63 www 5258: }
1.59 www 5259:
1.822 bisitz 5260: ##############################################
5261: =pod
5262:
1.832 bisitz 5263: =item * &authorspace()
5264:
1.1028 raeburn 5265: Inputs: $url (usually will be undef).
1.832 bisitz 5266:
1.1132 raeburn 5267: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5268: directory being viewed (or for which action is being taken).
5269: If $url is provided, and begins /priv/<domain>/<uname>
5270: the path will be that portion of the $context argument.
5271: Otherwise the path will be for the author space of the current
5272: user when the current role is author, or for that of the
5273: co-author/assistant co-author space when the current role
5274: is co-author or assistant co-author.
1.832 bisitz 5275:
5276: =cut
5277:
5278: sub authorspace {
1.1028 raeburn 5279: my ($url) = @_;
5280: if ($url ne '') {
5281: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5282: return $1;
5283: }
5284: }
1.832 bisitz 5285: my $caname = '';
1.1024 www 5286: my $cadom = '';
1.1028 raeburn 5287: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5288: ($cadom,$caname) =
1.832 bisitz 5289: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5290: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5291: $caname = $env{'user.name'};
1.1024 www 5292: $cadom = $env{'user.domain'};
1.832 bisitz 5293: }
1.1028 raeburn 5294: if (($caname ne '') && ($cadom ne '')) {
5295: return "/priv/$cadom/$caname/";
5296: }
5297: return;
1.832 bisitz 5298: }
5299:
5300: ##############################################
5301: =pod
5302:
1.822 bisitz 5303: =item * &head_subbox()
5304:
5305: Inputs: $content (contains HTML code with page functions, etc.)
5306:
5307: Returns: HTML div with $content
5308: To be included in page header
5309:
5310: =cut
5311:
5312: sub head_subbox {
5313: my ($content)=@_;
5314: my $output =
1.993 raeburn 5315: '<div class="LC_head_subbox">'
1.822 bisitz 5316: .$content
5317: .'</div>'
5318: }
5319:
5320: ##############################################
5321: =pod
5322:
5323: =item * &CSTR_pageheader()
5324:
1.1026 raeburn 5325: Input: (optional) filename from which breadcrumb trail is built.
5326: In most cases no input as needed, as $env{'request.filename'}
5327: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5328:
5329: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5330: To be included on Authoring Space pages
1.822 bisitz 5331:
5332: =cut
5333:
5334: sub CSTR_pageheader {
1.1026 raeburn 5335: my ($trailfile) = @_;
5336: if ($trailfile eq '') {
5337: $trailfile = $env{'request.filename'};
5338: }
5339:
5340: # this is for resources; directories have customtitle, and crumbs
5341: # and select recent are created in lonpubdir.pm
5342:
5343: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5344: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5345: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5346: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5347: $formaction =~ s{/+}{/}g;
1.822 bisitz 5348:
5349: my $parentpath = '';
5350: my $lastitem = '';
5351: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5352: $parentpath = $1;
5353: $lastitem = $2;
5354: } else {
5355: $lastitem = $thisdisfn;
5356: }
1.921 bisitz 5357:
5358: my $output =
1.822 bisitz 5359: '<div>'
5360: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5361: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5362: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5363: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5364: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5365:
5366: if ($lastitem) {
5367: $output .=
5368: '<span class="LC_filename">'
5369: .$lastitem
5370: .'</span>';
5371: }
5372: $output .=
5373: '<br />'
1.822 bisitz 5374: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5375: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5376: .'</form>'
5377: .&Apache::lonmenu::constspaceform()
5378: .'</div>';
1.921 bisitz 5379:
5380: return $output;
1.822 bisitz 5381: }
5382:
1.60 matthew 5383: ###############################################
5384: ###############################################
5385:
5386: =pod
5387:
1.112 bowersj2 5388: =back
5389:
1.549 albertel 5390: =head1 HTML Helpers
1.112 bowersj2 5391:
5392: =over 4
5393:
5394: =item * &bodytag()
1.60 matthew 5395:
5396: Returns a uniform header for LON-CAPA web pages.
5397:
5398: Inputs:
5399:
1.112 bowersj2 5400: =over 4
5401:
5402: =item * $title, A title to be displayed on the page.
5403:
5404: =item * $function, the current role (can be undef).
5405:
5406: =item * $addentries, extra parameters for the <body> tag.
5407:
5408: =item * $bodyonly, if defined, only return the <body> tag.
5409:
5410: =item * $domain, if defined, force a given domain.
5411:
5412: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5413: text interface only)
1.60 matthew 5414:
1.814 bisitz 5415: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5416: navigational links
1.317 albertel 5417:
1.338 albertel 5418: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5419:
1.460 albertel 5420: =item * $args, optional argument valid values are
5421: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5422: inherit_jsmath -> when creating popup window in a page,
5423: should it have jsmath forced on by the
5424: current page
1.460 albertel 5425:
1.1096 raeburn 5426: =item * $advtoolsref, optional argument, ref to an array containing
5427: inlineremote items to be added in "Functions" menu below
5428: breadcrumbs.
5429:
1.112 bowersj2 5430: =back
5431:
1.60 matthew 5432: Returns: A uniform header for LON-CAPA web pages.
5433: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5434: If $bodyonly is undef or zero, an html string containing a <body> tag and
5435: other decorations will be returned.
5436:
5437: =cut
5438:
1.54 www 5439: sub bodytag {
1.831 bisitz 5440: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5441: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5442:
1.954 raeburn 5443: my $public;
5444: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5445: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5446: $public = 1;
5447: }
1.460 albertel 5448: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5449: my $httphost = $args->{'use_absolute'};
1.339 albertel 5450:
1.183 matthew 5451: $function = &get_users_function() if (!$function);
1.339 albertel 5452: my $img = &designparm($function.'.img',$domain);
5453: my $font = &designparm($function.'.font',$domain);
5454: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5455:
1.803 bisitz 5456: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5457: 'bgcolor' => $pgbg,
1.339 albertel 5458: 'text' => $font,
5459: 'alink' => &designparm($function.'.alink',$domain),
5460: 'vlink' => &designparm($function.'.vlink',$domain),
5461: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5462: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5463:
1.63 www 5464: # role and realm
1.1178 raeburn 5465: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5466: if ($realm) {
5467: $realm = '/'.$realm;
5468: }
1.378 raeburn 5469: if ($role eq 'ca') {
1.479 albertel 5470: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5471: $realm = &plainname($rname,$rdom);
1.378 raeburn 5472: }
1.55 www 5473: # realm
1.258 albertel 5474: if ($env{'request.course.id'}) {
1.378 raeburn 5475: if ($env{'request.role'} !~ /^cr/) {
5476: $role = &Apache::lonnet::plaintext($role,&course_type());
5477: }
1.898 raeburn 5478: if ($env{'request.course.sec'}) {
5479: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5480: }
1.359 albertel 5481: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5482: } else {
5483: $role = &Apache::lonnet::plaintext($role);
1.54 www 5484: }
1.433 albertel 5485:
1.359 albertel 5486: if (!$realm) { $realm=' '; }
1.330 albertel 5487:
1.438 albertel 5488: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5489:
1.101 www 5490: # construct main body tag
1.359 albertel 5491: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5492: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5493:
1.1131 raeburn 5494: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5495:
1.1130 raeburn 5496: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5497: return $bodytag;
1.1130 raeburn 5498: }
1.359 albertel 5499:
1.954 raeburn 5500: if ($public) {
1.433 albertel 5501: undef($role);
5502: }
1.359 albertel 5503:
1.762 bisitz 5504: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5505: #
5506: # Extra info if you are the DC
5507: my $dc_info = '';
5508: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5509: $env{'course.'.$env{'request.course.id'}.
5510: '.domain'}.'/'})) {
5511: my $cid = $env{'request.course.id'};
1.917 raeburn 5512: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5513: $dc_info =~ s/\s+$//;
1.359 albertel 5514: }
5515:
1.898 raeburn 5516: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5517:
1.903 droeschl 5518: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5519:
5520: # if ($env{'request.state'} eq 'construct') {
5521: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5522: # }
5523:
1.1130 raeburn 5524: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5525: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5526:
1.1130 raeburn 5527: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5528:
1.916 droeschl 5529: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5530: if ($dc_info) {
5531: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5532: }
1.1130 raeburn 5533: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5534: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5535: return $bodytag;
5536: }
1.894 droeschl 5537:
1.927 raeburn 5538: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5539: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5540: }
1.916 droeschl 5541:
1.1130 raeburn 5542: $bodytag .= $right;
1.852 droeschl 5543:
1.917 raeburn 5544: if ($dc_info) {
5545: $dc_info = &dc_courseid_toggle($dc_info);
5546: }
5547: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5548:
1.1169 raeburn 5549: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5550: if ($args->{'no_secondary_menu'}) {
5551: return $bodytag;
5552: }
1.1169 raeburn 5553: #don't show menus for public users
1.954 raeburn 5554: if (!$public){
1.1154 raeburn 5555: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5556: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5557: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5558: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5559: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5560: $args->{'bread_crumbs'});
1.1096 raeburn 5561: } elsif ($forcereg) {
5562: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5563: $args->{'group'});
5564: } else {
5565: $bodytag .=
5566: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5567: $forcereg,$args->{'group'},
5568: $args->{'bread_crumbs'},
5569: $advtoolsref);
1.920 raeburn 5570: }
1.903 droeschl 5571: }else{
5572: # this is to seperate menu from content when there's no secondary
5573: # menu. Especially needed for public accessible ressources.
5574: $bodytag .= '<hr style="clear:both" />';
5575: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5576: }
1.903 droeschl 5577:
1.235 raeburn 5578: return $bodytag;
1.182 matthew 5579: }
5580:
1.917 raeburn 5581: sub dc_courseid_toggle {
5582: my ($dc_info) = @_;
1.980 raeburn 5583: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5584: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5585: &mt('(More ...)').'</a></span>'.
5586: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5587: }
5588:
1.330 albertel 5589: sub make_attr_string {
5590: my ($register,$attr_ref) = @_;
5591:
5592: if ($attr_ref && !ref($attr_ref)) {
5593: die("addentries Must be a hash ref ".
5594: join(':',caller(1))." ".
5595: join(':',caller(0))." ");
5596: }
5597:
5598: if ($register) {
1.339 albertel 5599: my ($on_load,$on_unload);
5600: foreach my $key (keys(%{$attr_ref})) {
5601: if (lc($key) eq 'onload') {
5602: $on_load.=$attr_ref->{$key}.';';
5603: delete($attr_ref->{$key});
5604:
5605: } elsif (lc($key) eq 'onunload') {
5606: $on_unload.=$attr_ref->{$key}.';';
5607: delete($attr_ref->{$key});
5608: }
5609: }
1.953 droeschl 5610: $attr_ref->{'onload'} = $on_load;
5611: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5612: }
1.339 albertel 5613:
1.330 albertel 5614: my $attr_string;
1.1159 raeburn 5615: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5616: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5617: }
5618: return $attr_string;
5619: }
5620:
5621:
1.182 matthew 5622: ###############################################
1.251 albertel 5623: ###############################################
5624:
5625: =pod
5626:
5627: =item * &endbodytag()
5628:
5629: Returns a uniform footer for LON-CAPA web pages.
5630:
1.635 raeburn 5631: Inputs: 1 - optional reference to an args hash
5632: If in the hash, key for noredirectlink has a value which evaluates to true,
5633: a 'Continue' link is not displayed if the page contains an
5634: internal redirect in the <head></head> section,
5635: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5636:
5637: =cut
5638:
5639: sub endbodytag {
1.635 raeburn 5640: my ($args) = @_;
1.1080 raeburn 5641: my $endbodytag;
5642: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5643: $endbodytag='</body>';
5644: }
1.269 albertel 5645: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5646: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5647: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5648: $endbodytag=
5649: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5650: &mt('Continue').'</a>'.
5651: $endbodytag;
5652: }
1.315 albertel 5653: }
1.251 albertel 5654: return $endbodytag;
5655: }
5656:
1.352 albertel 5657: =pod
5658:
5659: =item * &standard_css()
5660:
5661: Returns a style sheet
5662:
5663: Inputs: (all optional)
5664: domain -> force to color decorate a page for a specific
5665: domain
5666: function -> force usage of a specific rolish color scheme
5667: bgcolor -> override the default page bgcolor
5668:
5669: =cut
5670:
1.343 albertel 5671: sub standard_css {
1.345 albertel 5672: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5673: $function = &get_users_function() if (!$function);
5674: my $img = &designparm($function.'.img', $domain);
5675: my $tabbg = &designparm($function.'.tabbg', $domain);
5676: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5677: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5678: #second colour for later usage
1.345 albertel 5679: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5680: my $pgbg_or_bgcolor =
5681: $bgcolor ||
1.352 albertel 5682: &designparm($function.'.pgbg', $domain);
1.382 albertel 5683: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5684: my $alink = &designparm($function.'.alink', $domain);
5685: my $vlink = &designparm($function.'.vlink', $domain);
5686: my $link = &designparm($function.'.link', $domain);
5687:
1.602 albertel 5688: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5689: my $mono = 'monospace';
1.850 bisitz 5690: my $data_table_head = $sidebg;
5691: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5692: my $data_table_dark = '#E0E0E0';
1.470 banghart 5693: my $data_table_darker = '#CCCCCC';
1.349 albertel 5694: my $data_table_highlight = '#FFFF00';
1.352 albertel 5695: my $mail_new = '#FFBB77';
5696: my $mail_new_hover = '#DD9955';
5697: my $mail_read = '#BBBB77';
5698: my $mail_read_hover = '#999944';
5699: my $mail_replied = '#AAAA88';
5700: my $mail_replied_hover = '#888855';
5701: my $mail_other = '#99BBBB';
5702: my $mail_other_hover = '#669999';
1.391 albertel 5703: my $table_header = '#DDDDDD';
1.489 raeburn 5704: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5705: my $lg_border_color = '#C8C8C8';
1.952 onken 5706: my $button_hover = '#BF2317';
1.392 albertel 5707:
1.608 albertel 5708: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5709: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5710: : '0 3px 0 4px';
1.448 albertel 5711:
1.523 albertel 5712:
1.343 albertel 5713: return <<END;
1.947 droeschl 5714:
5715: /* needed for iframe to allow 100% height in FF */
5716: body, html {
5717: margin: 0;
5718: padding: 0 0.5%;
5719: height: 99%; /* to avoid scrollbars */
5720: }
5721:
1.795 www 5722: body {
1.911 bisitz 5723: font-family: $sans;
5724: line-height:130%;
5725: font-size:0.83em;
5726: color:$font;
1.795 www 5727: }
5728:
1.959 onken 5729: a:focus,
5730: a:focus img {
1.795 www 5731: color: red;
5732: }
1.698 harmsja 5733:
1.911 bisitz 5734: form, .inline {
5735: display: inline;
1.795 www 5736: }
1.721 harmsja 5737:
1.795 www 5738: .LC_right {
1.911 bisitz 5739: text-align:right;
1.795 www 5740: }
5741:
5742: .LC_middle {
1.911 bisitz 5743: vertical-align:middle;
1.795 www 5744: }
1.721 harmsja 5745:
1.1130 raeburn 5746: .LC_floatleft {
5747: float: left;
5748: }
5749:
5750: .LC_floatright {
5751: float: right;
5752: }
5753:
1.911 bisitz 5754: .LC_400Box {
5755: width:400px;
5756: }
1.721 harmsja 5757:
1.947 droeschl 5758: .LC_iframecontainer {
5759: width: 98%;
5760: margin: 0;
5761: position: fixed;
5762: top: 8.5em;
5763: bottom: 0;
5764: }
5765:
5766: .LC_iframecontainer iframe{
5767: border: none;
5768: width: 100%;
5769: height: 100%;
5770: }
5771:
1.778 bisitz 5772: .LC_filename {
5773: font-family: $mono;
5774: white-space:pre;
1.921 bisitz 5775: font-size: 120%;
1.778 bisitz 5776: }
5777:
5778: .LC_fileicon {
5779: border: none;
5780: height: 1.3em;
5781: vertical-align: text-bottom;
5782: margin-right: 0.3em;
5783: text-decoration:none;
5784: }
5785:
1.1008 www 5786: .LC_setting {
5787: text-decoration:underline;
5788: }
5789:
1.350 albertel 5790: .LC_error {
5791: color: red;
5792: }
1.795 www 5793:
1.1097 bisitz 5794: .LC_warning {
5795: color: darkorange;
5796: }
5797:
1.457 albertel 5798: .LC_diff_removed {
1.733 bisitz 5799: color: red;
1.394 albertel 5800: }
1.532 albertel 5801:
5802: .LC_info,
1.457 albertel 5803: .LC_success,
5804: .LC_diff_added {
1.350 albertel 5805: color: green;
5806: }
1.795 www 5807:
1.802 bisitz 5808: div.LC_confirm_box {
5809: background-color: #FAFAFA;
5810: border: 1px solid $lg_border_color;
5811: margin-right: 0;
5812: padding: 5px;
5813: }
5814:
5815: div.LC_confirm_box .LC_error img,
5816: div.LC_confirm_box .LC_success img {
5817: vertical-align: middle;
5818: }
5819:
1.440 albertel 5820: .LC_icon {
1.771 droeschl 5821: border: none;
1.790 droeschl 5822: vertical-align: middle;
1.771 droeschl 5823: }
5824:
1.543 albertel 5825: .LC_docs_spacer {
5826: width: 25px;
5827: height: 1px;
1.771 droeschl 5828: border: none;
1.543 albertel 5829: }
1.346 albertel 5830:
1.532 albertel 5831: .LC_internal_info {
1.735 bisitz 5832: color: #999999;
1.532 albertel 5833: }
5834:
1.794 www 5835: .LC_discussion {
1.1050 www 5836: background: $data_table_dark;
1.911 bisitz 5837: border: 1px solid black;
5838: margin: 2px;
1.794 www 5839: }
5840:
5841: .LC_disc_action_left {
1.1050 www 5842: background: $sidebg;
1.911 bisitz 5843: text-align: left;
1.1050 www 5844: padding: 4px;
5845: margin: 2px;
1.794 www 5846: }
5847:
5848: .LC_disc_action_right {
1.1050 www 5849: background: $sidebg;
1.911 bisitz 5850: text-align: right;
1.1050 www 5851: padding: 4px;
5852: margin: 2px;
1.794 www 5853: }
5854:
5855: .LC_disc_new_item {
1.911 bisitz 5856: background: white;
5857: border: 2px solid red;
1.1050 www 5858: margin: 4px;
5859: padding: 4px;
1.794 www 5860: }
5861:
5862: .LC_disc_old_item {
1.911 bisitz 5863: background: white;
1.1050 www 5864: margin: 4px;
5865: padding: 4px;
1.794 www 5866: }
5867:
1.458 albertel 5868: table.LC_pastsubmission {
5869: border: 1px solid black;
5870: margin: 2px;
5871: }
5872:
1.924 bisitz 5873: table#LC_menubuttons {
1.345 albertel 5874: width: 100%;
5875: background: $pgbg;
1.392 albertel 5876: border: 2px;
1.402 albertel 5877: border-collapse: separate;
1.803 bisitz 5878: padding: 0;
1.345 albertel 5879: }
1.392 albertel 5880:
1.801 tempelho 5881: table#LC_title_bar a {
5882: color: $fontmenu;
5883: }
1.836 bisitz 5884:
1.807 droeschl 5885: table#LC_title_bar {
1.819 tempelho 5886: clear: both;
1.836 bisitz 5887: display: none;
1.807 droeschl 5888: }
5889:
1.795 www 5890: table#LC_title_bar,
1.933 droeschl 5891: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5892: table#LC_title_bar.LC_with_remote {
1.359 albertel 5893: width: 100%;
1.392 albertel 5894: border-color: $pgbg;
5895: border-style: solid;
5896: border-width: $border;
1.379 albertel 5897: background: $pgbg;
1.801 tempelho 5898: color: $fontmenu;
1.392 albertel 5899: border-collapse: collapse;
1.803 bisitz 5900: padding: 0;
1.819 tempelho 5901: margin: 0;
1.359 albertel 5902: }
1.795 www 5903:
1.933 droeschl 5904: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5905: margin: 0;
5906: padding: 0;
1.933 droeschl 5907: position: relative;
5908: list-style: none;
1.913 droeschl 5909: }
1.933 droeschl 5910: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5911: display: inline;
5912: }
1.933 droeschl 5913:
5914: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5915: padding: 0;
1.933 droeschl 5916: margin: 0;
5917: float: left;
1.913 droeschl 5918: }
1.933 droeschl 5919: .LC_breadcrumb_tools_tools {
5920: padding: 0;
5921: margin: 0;
1.913 droeschl 5922: float: right;
5923: }
5924:
1.359 albertel 5925: table#LC_title_bar td {
5926: background: $tabbg;
5927: }
1.795 www 5928:
1.911 bisitz 5929: table#LC_menubuttons img {
1.803 bisitz 5930: border: none;
1.346 albertel 5931: }
1.795 www 5932:
1.842 droeschl 5933: .LC_breadcrumbs_component {
1.911 bisitz 5934: float: right;
5935: margin: 0 1em;
1.357 albertel 5936: }
1.842 droeschl 5937: .LC_breadcrumbs_component img {
1.911 bisitz 5938: vertical-align: middle;
1.777 tempelho 5939: }
1.795 www 5940:
1.383 albertel 5941: td.LC_table_cell_checkbox {
5942: text-align: center;
5943: }
1.795 www 5944:
5945: .LC_fontsize_small {
1.911 bisitz 5946: font-size: 70%;
1.705 tempelho 5947: }
5948:
1.844 bisitz 5949: #LC_breadcrumbs {
1.911 bisitz 5950: clear:both;
5951: background: $sidebg;
5952: border-bottom: 1px solid $lg_border_color;
5953: line-height: 2.5em;
1.933 droeschl 5954: overflow: hidden;
1.911 bisitz 5955: margin: 0;
5956: padding: 0;
1.995 raeburn 5957: text-align: left;
1.819 tempelho 5958: }
1.862 bisitz 5959:
1.1098 bisitz 5960: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5961: clear:both;
5962: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5963: border: 1px solid $sidebg;
1.1098 bisitz 5964: margin: 0 0 10px 0;
1.966 bisitz 5965: padding: 3px;
1.995 raeburn 5966: text-align: left;
1.822 bisitz 5967: }
5968:
1.795 www 5969: .LC_fontsize_medium {
1.911 bisitz 5970: font-size: 85%;
1.705 tempelho 5971: }
5972:
1.795 www 5973: .LC_fontsize_large {
1.911 bisitz 5974: font-size: 120%;
1.705 tempelho 5975: }
5976:
1.346 albertel 5977: .LC_menubuttons_inline_text {
5978: color: $font;
1.698 harmsja 5979: font-size: 90%;
1.701 harmsja 5980: padding-left:3px;
1.346 albertel 5981: }
5982:
1.934 droeschl 5983: .LC_menubuttons_inline_text img{
5984: vertical-align: middle;
5985: }
5986:
1.1051 www 5987: li.LC_menubuttons_inline_text img {
1.951 onken 5988: cursor:pointer;
1.1002 droeschl 5989: text-decoration: none;
1.951 onken 5990: }
5991:
1.526 www 5992: .LC_menubuttons_link {
5993: text-decoration: none;
5994: }
1.795 www 5995:
1.522 albertel 5996: .LC_menubuttons_category {
1.521 www 5997: color: $font;
1.526 www 5998: background: $pgbg;
1.521 www 5999: font-size: larger;
6000: font-weight: bold;
6001: }
6002:
1.346 albertel 6003: td.LC_menubuttons_text {
1.911 bisitz 6004: color: $font;
1.346 albertel 6005: }
1.706 harmsja 6006:
1.346 albertel 6007: .LC_current_location {
6008: background: $tabbg;
6009: }
1.795 www 6010:
1.938 bisitz 6011: table.LC_data_table {
1.347 albertel 6012: border: 1px solid #000000;
1.402 albertel 6013: border-collapse: separate;
1.426 albertel 6014: border-spacing: 1px;
1.610 albertel 6015: background: $pgbg;
1.347 albertel 6016: }
1.795 www 6017:
1.422 albertel 6018: .LC_data_table_dense {
6019: font-size: small;
6020: }
1.795 www 6021:
1.507 raeburn 6022: table.LC_nested_outer {
6023: border: 1px solid #000000;
1.589 raeburn 6024: border-collapse: collapse;
1.803 bisitz 6025: border-spacing: 0;
1.507 raeburn 6026: width: 100%;
6027: }
1.795 www 6028:
1.879 raeburn 6029: table.LC_innerpickbox,
1.507 raeburn 6030: table.LC_nested {
1.803 bisitz 6031: border: none;
1.589 raeburn 6032: border-collapse: collapse;
1.803 bisitz 6033: border-spacing: 0;
1.507 raeburn 6034: width: 100%;
6035: }
1.795 www 6036:
1.911 bisitz 6037: table.LC_data_table tr th,
6038: table.LC_calendar tr th,
1.879 raeburn 6039: table.LC_prior_tries tr th,
6040: table.LC_innerpickbox tr th {
1.349 albertel 6041: font-weight: bold;
6042: background-color: $data_table_head;
1.801 tempelho 6043: color:$fontmenu;
1.701 harmsja 6044: font-size:90%;
1.347 albertel 6045: }
1.795 www 6046:
1.879 raeburn 6047: table.LC_innerpickbox tr th,
6048: table.LC_innerpickbox tr td {
6049: vertical-align: top;
6050: }
6051:
1.711 raeburn 6052: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6053: background-color: #CCCCCC;
1.711 raeburn 6054: font-weight: bold;
6055: text-align: left;
6056: }
1.795 www 6057:
1.912 bisitz 6058: table.LC_data_table tr.LC_odd_row > td {
6059: background-color: $data_table_light;
6060: padding: 2px;
6061: vertical-align: top;
6062: }
6063:
1.809 bisitz 6064: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6065: background-color: $data_table_light;
1.912 bisitz 6066: vertical-align: top;
6067: }
6068:
6069: table.LC_data_table tr.LC_even_row > td {
6070: background-color: $data_table_dark;
1.425 albertel 6071: padding: 2px;
1.900 bisitz 6072: vertical-align: top;
1.347 albertel 6073: }
1.795 www 6074:
1.809 bisitz 6075: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6076: background-color: $data_table_dark;
1.900 bisitz 6077: vertical-align: top;
1.347 albertel 6078: }
1.795 www 6079:
1.425 albertel 6080: table.LC_data_table tr.LC_data_table_highlight td {
6081: background-color: $data_table_darker;
6082: }
1.795 www 6083:
1.639 raeburn 6084: table.LC_data_table tr td.LC_leftcol_header {
6085: background-color: $data_table_head;
6086: font-weight: bold;
6087: }
1.795 www 6088:
1.451 albertel 6089: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6090: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6091: font-weight: bold;
6092: font-style: italic;
6093: text-align: center;
6094: padding: 8px;
1.347 albertel 6095: }
1.795 www 6096:
1.1114 raeburn 6097: table.LC_data_table tr.LC_empty_row td,
6098: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6099: background-color: $sidebg;
6100: }
6101:
6102: table.LC_nested tr.LC_empty_row td {
6103: background-color: #FFFFFF;
6104: }
6105:
1.890 droeschl 6106: table.LC_caption {
6107: }
6108:
1.507 raeburn 6109: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6110: padding: 4ex
6111: }
1.795 www 6112:
1.507 raeburn 6113: table.LC_nested_outer tr th {
6114: font-weight: bold;
1.801 tempelho 6115: color:$fontmenu;
1.507 raeburn 6116: background-color: $data_table_head;
1.701 harmsja 6117: font-size: small;
1.507 raeburn 6118: border-bottom: 1px solid #000000;
6119: }
1.795 www 6120:
1.507 raeburn 6121: table.LC_nested_outer tr td.LC_subheader {
6122: background-color: $data_table_head;
6123: font-weight: bold;
6124: font-size: small;
6125: border-bottom: 1px solid #000000;
6126: text-align: right;
1.451 albertel 6127: }
1.795 www 6128:
1.507 raeburn 6129: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6130: background-color: #CCCCCC;
1.451 albertel 6131: font-weight: bold;
6132: font-size: small;
1.507 raeburn 6133: text-align: center;
6134: }
1.795 www 6135:
1.589 raeburn 6136: table.LC_nested tr.LC_info_row td.LC_left_item,
6137: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6138: text-align: left;
1.451 albertel 6139: }
1.795 www 6140:
1.507 raeburn 6141: table.LC_nested td {
1.735 bisitz 6142: background-color: #FFFFFF;
1.451 albertel 6143: font-size: small;
1.507 raeburn 6144: }
1.795 www 6145:
1.507 raeburn 6146: table.LC_nested_outer tr th.LC_right_item,
6147: table.LC_nested tr.LC_info_row td.LC_right_item,
6148: table.LC_nested tr.LC_odd_row td.LC_right_item,
6149: table.LC_nested tr td.LC_right_item {
1.451 albertel 6150: text-align: right;
6151: }
6152:
1.507 raeburn 6153: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6154: background-color: #EEEEEE;
1.451 albertel 6155: }
6156:
1.473 raeburn 6157: table.LC_createuser {
6158: }
6159:
6160: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6161: font-size: small;
1.473 raeburn 6162: }
6163:
6164: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6165: background-color: #CCCCCC;
1.473 raeburn 6166: font-weight: bold;
6167: text-align: center;
6168: }
6169:
1.349 albertel 6170: table.LC_calendar {
6171: border: 1px solid #000000;
6172: border-collapse: collapse;
1.917 raeburn 6173: width: 98%;
1.349 albertel 6174: }
1.795 www 6175:
1.349 albertel 6176: table.LC_calendar_pickdate {
6177: font-size: xx-small;
6178: }
1.795 www 6179:
1.349 albertel 6180: table.LC_calendar tr td {
6181: border: 1px solid #000000;
6182: vertical-align: top;
1.917 raeburn 6183: width: 14%;
1.349 albertel 6184: }
1.795 www 6185:
1.349 albertel 6186: table.LC_calendar tr td.LC_calendar_day_empty {
6187: background-color: $data_table_dark;
6188: }
1.795 www 6189:
1.779 bisitz 6190: table.LC_calendar tr td.LC_calendar_day_current {
6191: background-color: $data_table_highlight;
1.777 tempelho 6192: }
1.795 www 6193:
1.938 bisitz 6194: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6195: background-color: $mail_new;
6196: }
1.795 www 6197:
1.938 bisitz 6198: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6199: background-color: $mail_new_hover;
6200: }
1.795 www 6201:
1.938 bisitz 6202: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6203: background-color: $mail_read;
6204: }
1.795 www 6205:
1.938 bisitz 6206: /*
6207: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6208: background-color: $mail_read_hover;
6209: }
1.938 bisitz 6210: */
1.795 www 6211:
1.938 bisitz 6212: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6213: background-color: $mail_replied;
6214: }
1.795 www 6215:
1.938 bisitz 6216: /*
6217: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6218: background-color: $mail_replied_hover;
6219: }
1.938 bisitz 6220: */
1.795 www 6221:
1.938 bisitz 6222: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6223: background-color: $mail_other;
6224: }
1.795 www 6225:
1.938 bisitz 6226: /*
6227: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6228: background-color: $mail_other_hover;
6229: }
1.938 bisitz 6230: */
1.494 raeburn 6231:
1.777 tempelho 6232: table.LC_data_table tr > td.LC_browser_file,
6233: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6234: background: #AAEE77;
1.389 albertel 6235: }
1.795 www 6236:
1.777 tempelho 6237: table.LC_data_table tr > td.LC_browser_file_locked,
6238: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6239: background: #FFAA99;
1.387 albertel 6240: }
1.795 www 6241:
1.777 tempelho 6242: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6243: background: #888888;
1.779 bisitz 6244: }
1.795 www 6245:
1.777 tempelho 6246: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6247: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6248: background: #F8F866;
1.777 tempelho 6249: }
1.795 www 6250:
1.696 bisitz 6251: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6252: background: #E0E8FF;
1.387 albertel 6253: }
1.696 bisitz 6254:
1.707 bisitz 6255: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6256: /* background: #77FF77; */
1.707 bisitz 6257: }
1.795 www 6258:
1.707 bisitz 6259: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6260: border-right: 8px solid #FFFF77;
1.707 bisitz 6261: }
1.795 www 6262:
1.707 bisitz 6263: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6264: border-right: 8px solid #FFAA77;
1.707 bisitz 6265: }
1.795 www 6266:
1.707 bisitz 6267: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6268: border-right: 8px solid #FF7777;
1.707 bisitz 6269: }
1.795 www 6270:
1.707 bisitz 6271: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6272: border-right: 8px solid #AAFF77;
1.707 bisitz 6273: }
1.795 www 6274:
1.707 bisitz 6275: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6276: border-right: 8px solid #11CC55;
1.707 bisitz 6277: }
6278:
1.388 albertel 6279: span.LC_current_location {
1.701 harmsja 6280: font-size:larger;
1.388 albertel 6281: background: $pgbg;
6282: }
1.387 albertel 6283:
1.1029 www 6284: span.LC_current_nav_location {
6285: font-weight:bold;
6286: background: $sidebg;
6287: }
6288:
1.395 albertel 6289: span.LC_parm_menu_item {
6290: font-size: larger;
6291: }
1.795 www 6292:
1.395 albertel 6293: span.LC_parm_scope_all {
6294: color: red;
6295: }
1.795 www 6296:
1.395 albertel 6297: span.LC_parm_scope_folder {
6298: color: green;
6299: }
1.795 www 6300:
1.395 albertel 6301: span.LC_parm_scope_resource {
6302: color: orange;
6303: }
1.795 www 6304:
1.395 albertel 6305: span.LC_parm_part {
6306: color: blue;
6307: }
1.795 www 6308:
1.911 bisitz 6309: span.LC_parm_folder,
6310: span.LC_parm_symb {
1.395 albertel 6311: font-size: x-small;
6312: font-family: $mono;
6313: color: #AAAAAA;
6314: }
6315:
1.977 bisitz 6316: ul.LC_parm_parmlist li {
6317: display: inline-block;
6318: padding: 0.3em 0.8em;
6319: vertical-align: top;
6320: width: 150px;
6321: border-top:1px solid $lg_border_color;
6322: }
6323:
1.795 www 6324: td.LC_parm_overview_level_menu,
6325: td.LC_parm_overview_map_menu,
6326: td.LC_parm_overview_parm_selectors,
6327: td.LC_parm_overview_restrictions {
1.396 albertel 6328: border: 1px solid black;
6329: border-collapse: collapse;
6330: }
1.795 www 6331:
1.396 albertel 6332: table.LC_parm_overview_restrictions td {
6333: border-width: 1px 4px 1px 4px;
6334: border-style: solid;
6335: border-color: $pgbg;
6336: text-align: center;
6337: }
1.795 www 6338:
1.396 albertel 6339: table.LC_parm_overview_restrictions th {
6340: background: $tabbg;
6341: border-width: 1px 4px 1px 4px;
6342: border-style: solid;
6343: border-color: $pgbg;
6344: }
1.795 www 6345:
1.398 albertel 6346: table#LC_helpmenu {
1.803 bisitz 6347: border: none;
1.398 albertel 6348: height: 55px;
1.803 bisitz 6349: border-spacing: 0;
1.398 albertel 6350: }
6351:
6352: table#LC_helpmenu fieldset legend {
6353: font-size: larger;
6354: }
1.795 www 6355:
1.397 albertel 6356: table#LC_helpmenu_links {
6357: width: 100%;
6358: border: 1px solid black;
6359: background: $pgbg;
1.803 bisitz 6360: padding: 0;
1.397 albertel 6361: border-spacing: 1px;
6362: }
1.795 www 6363:
1.397 albertel 6364: table#LC_helpmenu_links tr td {
6365: padding: 1px;
6366: background: $tabbg;
1.399 albertel 6367: text-align: center;
6368: font-weight: bold;
1.397 albertel 6369: }
1.396 albertel 6370:
1.795 www 6371: table#LC_helpmenu_links a:link,
6372: table#LC_helpmenu_links a:visited,
1.397 albertel 6373: table#LC_helpmenu_links a:active {
6374: text-decoration: none;
6375: color: $font;
6376: }
1.795 www 6377:
1.397 albertel 6378: table#LC_helpmenu_links a:hover {
6379: text-decoration: underline;
6380: color: $vlink;
6381: }
1.396 albertel 6382:
1.417 albertel 6383: .LC_chrt_popup_exists {
6384: border: 1px solid #339933;
6385: margin: -1px;
6386: }
1.795 www 6387:
1.417 albertel 6388: .LC_chrt_popup_up {
6389: border: 1px solid yellow;
6390: margin: -1px;
6391: }
1.795 www 6392:
1.417 albertel 6393: .LC_chrt_popup {
6394: border: 1px solid #8888FF;
6395: background: #CCCCFF;
6396: }
1.795 www 6397:
1.421 albertel 6398: table.LC_pick_box {
6399: border-collapse: separate;
6400: background: white;
6401: border: 1px solid black;
6402: border-spacing: 1px;
6403: }
1.795 www 6404:
1.421 albertel 6405: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6406: background: $sidebg;
1.421 albertel 6407: font-weight: bold;
1.900 bisitz 6408: text-align: left;
1.740 bisitz 6409: vertical-align: top;
1.421 albertel 6410: width: 184px;
6411: padding: 8px;
6412: }
1.795 www 6413:
1.579 raeburn 6414: table.LC_pick_box td.LC_pick_box_value {
6415: text-align: left;
6416: padding: 8px;
6417: }
1.795 www 6418:
1.579 raeburn 6419: table.LC_pick_box td.LC_pick_box_select {
6420: text-align: left;
6421: padding: 8px;
6422: }
1.795 www 6423:
1.424 albertel 6424: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6425: padding: 0;
1.421 albertel 6426: height: 1px;
6427: background: black;
6428: }
1.795 www 6429:
1.421 albertel 6430: table.LC_pick_box td.LC_pick_box_submit {
6431: text-align: right;
6432: }
1.795 www 6433:
1.579 raeburn 6434: table.LC_pick_box td.LC_evenrow_value {
6435: text-align: left;
6436: padding: 8px;
6437: background-color: $data_table_light;
6438: }
1.795 www 6439:
1.579 raeburn 6440: table.LC_pick_box td.LC_oddrow_value {
6441: text-align: left;
6442: padding: 8px;
6443: background-color: $data_table_light;
6444: }
1.795 www 6445:
1.579 raeburn 6446: span.LC_helpform_receipt_cat {
6447: font-weight: bold;
6448: }
1.795 www 6449:
1.424 albertel 6450: table.LC_group_priv_box {
6451: background: white;
6452: border: 1px solid black;
6453: border-spacing: 1px;
6454: }
1.795 www 6455:
1.424 albertel 6456: table.LC_group_priv_box td.LC_pick_box_title {
6457: background: $tabbg;
6458: font-weight: bold;
6459: text-align: right;
6460: width: 184px;
6461: }
1.795 www 6462:
1.424 albertel 6463: table.LC_group_priv_box td.LC_groups_fixed {
6464: background: $data_table_light;
6465: text-align: center;
6466: }
1.795 www 6467:
1.424 albertel 6468: table.LC_group_priv_box td.LC_groups_optional {
6469: background: $data_table_dark;
6470: text-align: center;
6471: }
1.795 www 6472:
1.424 albertel 6473: table.LC_group_priv_box td.LC_groups_functionality {
6474: background: $data_table_darker;
6475: text-align: center;
6476: font-weight: bold;
6477: }
1.795 www 6478:
1.424 albertel 6479: table.LC_group_priv td {
6480: text-align: left;
1.803 bisitz 6481: padding: 0;
1.424 albertel 6482: }
6483:
6484: .LC_navbuttons {
6485: margin: 2ex 0ex 2ex 0ex;
6486: }
1.795 www 6487:
1.423 albertel 6488: .LC_topic_bar {
6489: font-weight: bold;
6490: background: $tabbg;
1.918 wenzelju 6491: margin: 1em 0em 1em 2em;
1.805 bisitz 6492: padding: 3px;
1.918 wenzelju 6493: font-size: 1.2em;
1.423 albertel 6494: }
1.795 www 6495:
1.423 albertel 6496: .LC_topic_bar span {
1.918 wenzelju 6497: left: 0.5em;
6498: position: absolute;
1.423 albertel 6499: vertical-align: middle;
1.918 wenzelju 6500: font-size: 1.2em;
1.423 albertel 6501: }
1.795 www 6502:
1.423 albertel 6503: table.LC_course_group_status {
6504: margin: 20px;
6505: }
1.795 www 6506:
1.423 albertel 6507: table.LC_status_selector td {
6508: vertical-align: top;
6509: text-align: center;
1.424 albertel 6510: padding: 4px;
6511: }
1.795 www 6512:
1.599 albertel 6513: div.LC_feedback_link {
1.616 albertel 6514: clear: both;
1.829 kalberla 6515: background: $sidebg;
1.779 bisitz 6516: width: 100%;
1.829 kalberla 6517: padding-bottom: 10px;
6518: border: 1px $tabbg solid;
1.833 kalberla 6519: height: 22px;
6520: line-height: 22px;
6521: padding-top: 5px;
6522: }
6523:
6524: div.LC_feedback_link img {
6525: height: 22px;
1.867 kalberla 6526: vertical-align:middle;
1.829 kalberla 6527: }
6528:
1.911 bisitz 6529: div.LC_feedback_link a {
1.829 kalberla 6530: text-decoration: none;
1.489 raeburn 6531: }
1.795 www 6532:
1.867 kalberla 6533: div.LC_comblock {
1.911 bisitz 6534: display:inline;
1.867 kalberla 6535: color:$font;
6536: font-size:90%;
6537: }
6538:
6539: div.LC_feedback_link div.LC_comblock {
6540: padding-left:5px;
6541: }
6542:
6543: div.LC_feedback_link div.LC_comblock a {
6544: color:$font;
6545: }
6546:
1.489 raeburn 6547: span.LC_feedback_link {
1.858 bisitz 6548: /* background: $feedback_link_bg; */
1.599 albertel 6549: font-size: larger;
6550: }
1.795 www 6551:
1.599 albertel 6552: span.LC_message_link {
1.858 bisitz 6553: /* background: $feedback_link_bg; */
1.599 albertel 6554: font-size: larger;
6555: position: absolute;
6556: right: 1em;
1.489 raeburn 6557: }
1.421 albertel 6558:
1.515 albertel 6559: table.LC_prior_tries {
1.524 albertel 6560: border: 1px solid #000000;
6561: border-collapse: separate;
6562: border-spacing: 1px;
1.515 albertel 6563: }
1.523 albertel 6564:
1.515 albertel 6565: table.LC_prior_tries td {
1.524 albertel 6566: padding: 2px;
1.515 albertel 6567: }
1.523 albertel 6568:
6569: .LC_answer_correct {
1.795 www 6570: background: lightgreen;
6571: color: darkgreen;
6572: padding: 6px;
1.523 albertel 6573: }
1.795 www 6574:
1.523 albertel 6575: .LC_answer_charged_try {
1.797 www 6576: background: #FFAAAA;
1.795 www 6577: color: darkred;
6578: padding: 6px;
1.523 albertel 6579: }
1.795 www 6580:
1.779 bisitz 6581: .LC_answer_not_charged_try,
1.523 albertel 6582: .LC_answer_no_grade,
6583: .LC_answer_late {
1.795 www 6584: background: lightyellow;
1.523 albertel 6585: color: black;
1.795 www 6586: padding: 6px;
1.523 albertel 6587: }
1.795 www 6588:
1.523 albertel 6589: .LC_answer_previous {
1.795 www 6590: background: lightblue;
6591: color: darkblue;
6592: padding: 6px;
1.523 albertel 6593: }
1.795 www 6594:
1.779 bisitz 6595: .LC_answer_no_message {
1.777 tempelho 6596: background: #FFFFFF;
6597: color: black;
1.795 www 6598: padding: 6px;
1.779 bisitz 6599: }
1.795 www 6600:
1.779 bisitz 6601: .LC_answer_unknown {
6602: background: orange;
6603: color: black;
1.795 www 6604: padding: 6px;
1.777 tempelho 6605: }
1.795 www 6606:
1.529 albertel 6607: span.LC_prior_numerical,
6608: span.LC_prior_string,
6609: span.LC_prior_custom,
6610: span.LC_prior_reaction,
6611: span.LC_prior_math {
1.925 bisitz 6612: font-family: $mono;
1.523 albertel 6613: white-space: pre;
6614: }
6615:
1.525 albertel 6616: span.LC_prior_string {
1.925 bisitz 6617: font-family: $mono;
1.525 albertel 6618: white-space: pre;
6619: }
6620:
1.523 albertel 6621: table.LC_prior_option {
6622: width: 100%;
6623: border-collapse: collapse;
6624: }
1.795 www 6625:
1.911 bisitz 6626: table.LC_prior_rank,
1.795 www 6627: table.LC_prior_match {
1.528 albertel 6628: border-collapse: collapse;
6629: }
1.795 www 6630:
1.528 albertel 6631: table.LC_prior_option tr td,
6632: table.LC_prior_rank tr td,
6633: table.LC_prior_match tr td {
1.524 albertel 6634: border: 1px solid #000000;
1.515 albertel 6635: }
6636:
1.855 bisitz 6637: .LC_nobreak {
1.544 albertel 6638: white-space: nowrap;
1.519 raeburn 6639: }
6640:
1.576 raeburn 6641: span.LC_cusr_emph {
6642: font-style: italic;
6643: }
6644:
1.633 raeburn 6645: span.LC_cusr_subheading {
6646: font-weight: normal;
6647: font-size: 85%;
6648: }
6649:
1.861 bisitz 6650: div.LC_docs_entry_move {
1.859 bisitz 6651: border: 1px solid #BBBBBB;
1.545 albertel 6652: background: #DDDDDD;
1.861 bisitz 6653: width: 22px;
1.859 bisitz 6654: padding: 1px;
6655: margin: 0;
1.545 albertel 6656: }
6657:
1.861 bisitz 6658: table.LC_data_table tr > td.LC_docs_entry_commands,
6659: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6660: font-size: x-small;
6661: }
1.795 www 6662:
1.861 bisitz 6663: .LC_docs_entry_parameter {
6664: white-space: nowrap;
6665: }
6666:
1.544 albertel 6667: .LC_docs_copy {
1.545 albertel 6668: color: #000099;
1.544 albertel 6669: }
1.795 www 6670:
1.544 albertel 6671: .LC_docs_cut {
1.545 albertel 6672: color: #550044;
1.544 albertel 6673: }
1.795 www 6674:
1.544 albertel 6675: .LC_docs_rename {
1.545 albertel 6676: color: #009900;
1.544 albertel 6677: }
1.795 www 6678:
1.544 albertel 6679: .LC_docs_remove {
1.545 albertel 6680: color: #990000;
6681: }
6682:
1.547 albertel 6683: .LC_docs_reinit_warn,
6684: .LC_docs_ext_edit {
6685: font-size: x-small;
6686: }
6687:
1.545 albertel 6688: table.LC_docs_adddocs td,
6689: table.LC_docs_adddocs th {
6690: border: 1px solid #BBBBBB;
6691: padding: 4px;
6692: background: #DDDDDD;
1.543 albertel 6693: }
6694:
1.584 albertel 6695: table.LC_sty_begin {
6696: background: #BBFFBB;
6697: }
1.795 www 6698:
1.584 albertel 6699: table.LC_sty_end {
6700: background: #FFBBBB;
6701: }
6702:
1.589 raeburn 6703: table.LC_double_column {
1.803 bisitz 6704: border-width: 0;
1.589 raeburn 6705: border-collapse: collapse;
6706: width: 100%;
6707: padding: 2px;
6708: }
6709:
6710: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6711: top: 2px;
1.589 raeburn 6712: left: 2px;
6713: width: 47%;
6714: vertical-align: top;
6715: }
6716:
6717: table.LC_double_column tr td.LC_right_col {
6718: top: 2px;
1.779 bisitz 6719: right: 2px;
1.589 raeburn 6720: width: 47%;
6721: vertical-align: top;
6722: }
6723:
1.591 raeburn 6724: div.LC_left_float {
6725: float: left;
6726: padding-right: 5%;
1.597 albertel 6727: padding-bottom: 4px;
1.591 raeburn 6728: }
6729:
6730: div.LC_clear_float_header {
1.597 albertel 6731: padding-bottom: 2px;
1.591 raeburn 6732: }
6733:
6734: div.LC_clear_float_footer {
1.597 albertel 6735: padding-top: 10px;
1.591 raeburn 6736: clear: both;
6737: }
6738:
1.597 albertel 6739: div.LC_grade_show_user {
1.941 bisitz 6740: /* border-left: 5px solid $sidebg; */
6741: border-top: 5px solid #000000;
6742: margin: 50px 0 0 0;
1.936 bisitz 6743: padding: 15px 0 5px 10px;
1.597 albertel 6744: }
1.795 www 6745:
1.936 bisitz 6746: div.LC_grade_show_user_odd_row {
1.941 bisitz 6747: /* border-left: 5px solid #000000; */
6748: }
6749:
6750: div.LC_grade_show_user div.LC_Box {
6751: margin-right: 50px;
1.597 albertel 6752: }
6753:
6754: div.LC_grade_submissions,
6755: div.LC_grade_message_center,
1.936 bisitz 6756: div.LC_grade_info_links {
1.597 albertel 6757: margin: 5px;
6758: width: 99%;
6759: background: #FFFFFF;
6760: }
1.795 www 6761:
1.597 albertel 6762: div.LC_grade_submissions_header,
1.936 bisitz 6763: div.LC_grade_message_center_header {
1.705 tempelho 6764: font-weight: bold;
6765: font-size: large;
1.597 albertel 6766: }
1.795 www 6767:
1.597 albertel 6768: div.LC_grade_submissions_body,
1.936 bisitz 6769: div.LC_grade_message_center_body {
1.597 albertel 6770: border: 1px solid black;
6771: width: 99%;
6772: background: #FFFFFF;
6773: }
1.795 www 6774:
1.613 albertel 6775: table.LC_scantron_action {
6776: width: 100%;
6777: }
1.795 www 6778:
1.613 albertel 6779: table.LC_scantron_action tr th {
1.698 harmsja 6780: font-weight:bold;
6781: font-style:normal;
1.613 albertel 6782: }
1.795 www 6783:
1.779 bisitz 6784: .LC_edit_problem_header,
1.614 albertel 6785: div.LC_edit_problem_footer {
1.705 tempelho 6786: font-weight: normal;
6787: font-size: medium;
1.602 albertel 6788: margin: 2px;
1.1060 bisitz 6789: background-color: $sidebg;
1.600 albertel 6790: }
1.795 www 6791:
1.600 albertel 6792: div.LC_edit_problem_header,
1.602 albertel 6793: div.LC_edit_problem_header div,
1.614 albertel 6794: div.LC_edit_problem_footer,
6795: div.LC_edit_problem_footer div,
1.602 albertel 6796: div.LC_edit_problem_editxml_header,
6797: div.LC_edit_problem_editxml_header div {
1.600 albertel 6798: margin-top: 5px;
1.1205 golterma 6799: z-index: 100;
1.600 albertel 6800: }
1.795 www 6801:
1.600 albertel 6802: div.LC_edit_problem_header_title {
1.705 tempelho 6803: font-weight: bold;
6804: font-size: larger;
1.602 albertel 6805: background: $tabbg;
6806: padding: 3px;
1.1060 bisitz 6807: margin: 0 0 5px 0;
1.602 albertel 6808: }
1.795 www 6809:
1.602 albertel 6810: table.LC_edit_problem_header_title {
6811: width: 100%;
1.600 albertel 6812: background: $tabbg;
1.602 albertel 6813: }
6814:
6815: div.LC_edit_problem_discards {
6816: float: left;
1.1205 golterma 6817: }
6818:
6819: div.LC_edit_actionbar {
6820: margin: -5px 0px 0px 0px !important;
6821: background-color: $sidebg;
6822: height: 31px;
1.602 albertel 6823: }
1.795 www 6824:
1.602 albertel 6825: div.LC_edit_problem_saves {
6826: float: right;
6827: padding-bottom: 5px;
1.600 albertel 6828: }
1.795 www 6829:
1.1124 bisitz 6830: .LC_edit_opt {
6831: padding-left: 1em;
6832: white-space: nowrap;
6833: }
6834:
1.1152 golterma 6835: .LC_edit_problem_latexhelper{
6836: text-align: right;
6837: }
6838:
6839: #LC_edit_problem_colorful div{
6840: margin-left: 40px;
6841: }
6842:
1.1205 golterma 6843: #LC_edit_problem_codemirror div{
6844: margin-left: 0px;
6845: }
6846:
1.911 bisitz 6847: img.stift {
1.803 bisitz 6848: border-width: 0;
6849: vertical-align: middle;
1.677 riegler 6850: }
1.680 riegler 6851:
1.923 bisitz 6852: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6853: vertical-align: top;
1.777 tempelho 6854: }
1.795 www 6855:
1.716 raeburn 6856: div.LC_createcourse {
1.911 bisitz 6857: margin: 10px 10px 10px 10px;
1.716 raeburn 6858: }
6859:
1.917 raeburn 6860: .LC_dccid {
1.1130 raeburn 6861: float: right;
1.917 raeburn 6862: margin: 0.2em 0 0 0;
6863: padding: 0;
6864: font-size: 90%;
6865: display:none;
6866: }
6867:
1.897 wenzelju 6868: ol.LC_primary_menu a:hover,
1.721 harmsja 6869: ol#LC_MenuBreadcrumbs a:hover,
6870: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6871: ul#LC_secondary_menu a:hover,
1.721 harmsja 6872: .LC_FormSectionClearButton input:hover
1.795 www 6873: ul.LC_TabContent li:hover a {
1.952 onken 6874: color:$button_hover;
1.911 bisitz 6875: text-decoration:none;
1.693 droeschl 6876: }
6877:
1.779 bisitz 6878: h1 {
1.911 bisitz 6879: padding: 0;
6880: line-height:130%;
1.693 droeschl 6881: }
1.698 harmsja 6882:
1.911 bisitz 6883: h2,
6884: h3,
6885: h4,
6886: h5,
6887: h6 {
6888: margin: 5px 0 5px 0;
6889: padding: 0;
6890: line-height:130%;
1.693 droeschl 6891: }
1.795 www 6892:
6893: .LC_hcell {
1.911 bisitz 6894: padding:3px 15px 3px 15px;
6895: margin: 0;
6896: background-color:$tabbg;
6897: color:$fontmenu;
6898: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6899: }
1.795 www 6900:
1.840 bisitz 6901: .LC_Box > .LC_hcell {
1.911 bisitz 6902: margin: 0 -10px 10px -10px;
1.835 bisitz 6903: }
6904:
1.721 harmsja 6905: .LC_noBorder {
1.911 bisitz 6906: border: 0;
1.698 harmsja 6907: }
1.693 droeschl 6908:
1.721 harmsja 6909: .LC_FormSectionClearButton input {
1.911 bisitz 6910: background-color:transparent;
6911: border: none;
6912: cursor:pointer;
6913: text-decoration:underline;
1.693 droeschl 6914: }
1.763 bisitz 6915:
6916: .LC_help_open_topic {
1.911 bisitz 6917: color: #FFFFFF;
6918: background-color: #EEEEFF;
6919: margin: 1px;
6920: padding: 4px;
6921: border: 1px solid #000033;
6922: white-space: nowrap;
6923: /* vertical-align: middle; */
1.759 neumanie 6924: }
1.693 droeschl 6925:
1.911 bisitz 6926: dl,
6927: ul,
6928: div,
6929: fieldset {
6930: margin: 10px 10px 10px 0;
6931: /* overflow: hidden; */
1.693 droeschl 6932: }
1.795 www 6933:
1.1211 ! raeburn 6934: article.geogebraweb div {
! 6935: margin: 0;
! 6936: }
! 6937:
1.838 bisitz 6938: fieldset > legend {
1.911 bisitz 6939: font-weight: bold;
6940: padding: 0 5px 0 5px;
1.838 bisitz 6941: }
6942:
1.813 bisitz 6943: #LC_nav_bar {
1.911 bisitz 6944: float: left;
1.995 raeburn 6945: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6946: margin: 0 0 2px 0;
1.807 droeschl 6947: }
6948:
1.916 droeschl 6949: #LC_realm {
6950: margin: 0.2em 0 0 0;
6951: padding: 0;
6952: font-weight: bold;
6953: text-align: center;
1.995 raeburn 6954: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6955: }
6956:
1.911 bisitz 6957: #LC_nav_bar em {
6958: font-weight: bold;
6959: font-style: normal;
1.807 droeschl 6960: }
6961:
1.897 wenzelju 6962: ol.LC_primary_menu {
1.934 droeschl 6963: margin: 0;
1.1076 raeburn 6964: padding: 0;
1.807 droeschl 6965: }
6966:
1.852 droeschl 6967: ol#LC_PathBreadcrumbs {
1.911 bisitz 6968: margin: 0;
1.693 droeschl 6969: }
6970:
1.897 wenzelju 6971: ol.LC_primary_menu li {
1.1076 raeburn 6972: color: RGB(80, 80, 80);
6973: vertical-align: middle;
6974: text-align: left;
6975: list-style: none;
1.1205 golterma 6976: position: relative;
1.1076 raeburn 6977: float: left;
1.1205 golterma 6978: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
6979: line-height: 1.5em;
1.1076 raeburn 6980: }
6981:
1.1205 golterma 6982: ol.LC_primary_menu li a,
6983: ol.LC_primary_menu li p {
1.1076 raeburn 6984: display: block;
6985: margin: 0;
6986: padding: 0 5px 0 10px;
6987: text-decoration: none;
6988: }
6989:
1.1205 golterma 6990: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
6991: display: inline-block;
6992: width: 95%;
6993: text-align: left;
6994: }
6995:
6996: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
6997: display: inline-block;
6998: width: 5%;
6999: float: right;
7000: text-align: right;
7001: font-size: 70%;
7002: }
7003:
7004: ol.LC_primary_menu ul {
1.1076 raeburn 7005: display: none;
1.1205 golterma 7006: width: 15em;
1.1076 raeburn 7007: background-color: $data_table_light;
1.1205 golterma 7008: position: absolute;
7009: top: 100%;
1.1076 raeburn 7010: }
7011:
1.1205 golterma 7012: ol.LC_primary_menu ul ul {
7013: left: 100%;
7014: top: 0;
7015: }
7016:
7017: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7018: display: block;
7019: position: absolute;
7020: margin: 0;
7021: padding: 0;
1.1078 raeburn 7022: z-index: 2;
1.1076 raeburn 7023: }
7024:
7025: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7026: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7027: font-size: 90%;
1.911 bisitz 7028: vertical-align: top;
1.1076 raeburn 7029: float: none;
1.1079 raeburn 7030: border-left: 1px solid black;
7031: border-right: 1px solid black;
1.1205 golterma 7032: /* A dark bottom border to visualize different menu options;
7033: overwritten in the create_submenu routine for the last border-bottom of the menu */
7034: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7035: }
7036:
1.1205 golterma 7037: ol.LC_primary_menu li li p:hover {
7038: color:$button_hover;
7039: text-decoration:none;
7040: background-color:$data_table_dark;
1.1076 raeburn 7041: }
7042:
7043: ol.LC_primary_menu li li a:hover {
7044: color:$button_hover;
7045: background-color:$data_table_dark;
1.693 droeschl 7046: }
7047:
1.1205 golterma 7048: /* Font-size equal to the size of the predecessors*/
7049: ol.LC_primary_menu li:hover li li {
7050: font-size: 100%;
7051: }
7052:
1.897 wenzelju 7053: ol.LC_primary_menu li img {
1.911 bisitz 7054: vertical-align: bottom;
1.934 droeschl 7055: height: 1.1em;
1.1077 raeburn 7056: margin: 0.2em 0 0 0;
1.693 droeschl 7057: }
7058:
1.897 wenzelju 7059: ol.LC_primary_menu a {
1.911 bisitz 7060: color: RGB(80, 80, 80);
7061: text-decoration: none;
1.693 droeschl 7062: }
1.795 www 7063:
1.949 droeschl 7064: ol.LC_primary_menu a.LC_new_message {
7065: font-weight:bold;
7066: color: darkred;
7067: }
7068:
1.975 raeburn 7069: ol.LC_docs_parameters {
7070: margin-left: 0;
7071: padding: 0;
7072: list-style: none;
7073: }
7074:
7075: ol.LC_docs_parameters li {
7076: margin: 0;
7077: padding-right: 20px;
7078: display: inline;
7079: }
7080:
1.976 raeburn 7081: ol.LC_docs_parameters li:before {
7082: content: "\\002022 \\0020";
7083: }
7084:
7085: li.LC_docs_parameters_title {
7086: font-weight: bold;
7087: }
7088:
7089: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7090: content: "";
7091: }
7092:
1.897 wenzelju 7093: ul#LC_secondary_menu {
1.1107 raeburn 7094: clear: right;
1.911 bisitz 7095: color: $fontmenu;
7096: background: $tabbg;
7097: list-style: none;
7098: padding: 0;
7099: margin: 0;
7100: width: 100%;
1.995 raeburn 7101: text-align: left;
1.1107 raeburn 7102: float: left;
1.808 droeschl 7103: }
7104:
1.897 wenzelju 7105: ul#LC_secondary_menu li {
1.911 bisitz 7106: font-weight: bold;
7107: line-height: 1.8em;
1.1107 raeburn 7108: border-right: 1px solid black;
7109: float: left;
7110: }
7111:
7112: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7113: background-color: $data_table_light;
7114: }
7115:
7116: ul#LC_secondary_menu li a {
1.911 bisitz 7117: padding: 0 0.8em;
1.1107 raeburn 7118: }
7119:
7120: ul#LC_secondary_menu li ul {
7121: display: none;
7122: }
7123:
7124: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7125: display: block;
7126: position: absolute;
7127: margin: 0;
7128: padding: 0;
7129: list-style:none;
7130: float: none;
7131: background-color: $data_table_light;
7132: z-index: 2;
7133: margin-left: -1px;
7134: }
7135:
7136: ul#LC_secondary_menu li ul li {
7137: font-size: 90%;
7138: vertical-align: top;
7139: border-left: 1px solid black;
1.911 bisitz 7140: border-right: 1px solid black;
1.1119 raeburn 7141: background-color: $data_table_light;
1.1107 raeburn 7142: list-style:none;
7143: float: none;
7144: }
7145:
7146: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7147: background-color: $data_table_dark;
1.807 droeschl 7148: }
7149:
1.847 tempelho 7150: ul.LC_TabContent {
1.911 bisitz 7151: display:block;
7152: background: $sidebg;
7153: border-bottom: solid 1px $lg_border_color;
7154: list-style:none;
1.1020 raeburn 7155: margin: -1px -10px 0 -10px;
1.911 bisitz 7156: padding: 0;
1.693 droeschl 7157: }
7158:
1.795 www 7159: ul.LC_TabContent li,
7160: ul.LC_TabContentBigger li {
1.911 bisitz 7161: float:left;
1.741 harmsja 7162: }
1.795 www 7163:
1.897 wenzelju 7164: ul#LC_secondary_menu li a {
1.911 bisitz 7165: color: $fontmenu;
7166: text-decoration: none;
1.693 droeschl 7167: }
1.795 www 7168:
1.721 harmsja 7169: ul.LC_TabContent {
1.952 onken 7170: min-height:20px;
1.721 harmsja 7171: }
1.795 www 7172:
7173: ul.LC_TabContent li {
1.911 bisitz 7174: vertical-align:middle;
1.959 onken 7175: padding: 0 16px 0 10px;
1.911 bisitz 7176: background-color:$tabbg;
7177: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7178: border-left: solid 1px $font;
1.721 harmsja 7179: }
1.795 www 7180:
1.847 tempelho 7181: ul.LC_TabContent .right {
1.911 bisitz 7182: float:right;
1.847 tempelho 7183: }
7184:
1.911 bisitz 7185: ul.LC_TabContent li a,
7186: ul.LC_TabContent li {
7187: color:rgb(47,47,47);
7188: text-decoration:none;
7189: font-size:95%;
7190: font-weight:bold;
1.952 onken 7191: min-height:20px;
7192: }
7193:
1.959 onken 7194: ul.LC_TabContent li a:hover,
7195: ul.LC_TabContent li a:focus {
1.952 onken 7196: color: $button_hover;
1.959 onken 7197: background:none;
7198: outline:none;
1.952 onken 7199: }
7200:
7201: ul.LC_TabContent li:hover {
7202: color: $button_hover;
7203: cursor:pointer;
1.721 harmsja 7204: }
1.795 www 7205:
1.911 bisitz 7206: ul.LC_TabContent li.active {
1.952 onken 7207: color: $font;
1.911 bisitz 7208: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7209: border-bottom:solid 1px #FFFFFF;
7210: cursor: default;
1.744 ehlerst 7211: }
1.795 www 7212:
1.959 onken 7213: ul.LC_TabContent li.active a {
7214: color:$font;
7215: background:#FFFFFF;
7216: outline: none;
7217: }
1.1047 raeburn 7218:
7219: ul.LC_TabContent li.goback {
7220: float: left;
7221: border-left: none;
7222: }
7223:
1.870 tempelho 7224: #maincoursedoc {
1.911 bisitz 7225: clear:both;
1.870 tempelho 7226: }
7227:
7228: ul.LC_TabContentBigger {
1.911 bisitz 7229: display:block;
7230: list-style:none;
7231: padding: 0;
1.870 tempelho 7232: }
7233:
1.795 www 7234: ul.LC_TabContentBigger li {
1.911 bisitz 7235: vertical-align:bottom;
7236: height: 30px;
7237: font-size:110%;
7238: font-weight:bold;
7239: color: #737373;
1.841 tempelho 7240: }
7241:
1.957 onken 7242: ul.LC_TabContentBigger li.active {
7243: position: relative;
7244: top: 1px;
7245: }
7246:
1.870 tempelho 7247: ul.LC_TabContentBigger li a {
1.911 bisitz 7248: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7249: height: 30px;
7250: line-height: 30px;
7251: text-align: center;
7252: display: block;
7253: text-decoration: none;
1.958 onken 7254: outline: none;
1.741 harmsja 7255: }
1.795 www 7256:
1.870 tempelho 7257: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7258: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7259: color:$font;
1.744 ehlerst 7260: }
1.795 www 7261:
1.870 tempelho 7262: ul.LC_TabContentBigger li b {
1.911 bisitz 7263: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7264: display: block;
7265: float: left;
7266: padding: 0 30px;
1.957 onken 7267: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7268: }
7269:
1.956 onken 7270: ul.LC_TabContentBigger li:hover b {
7271: color:$button_hover;
7272: }
7273:
1.870 tempelho 7274: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7275: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7276: color:$font;
1.957 onken 7277: border: 0;
1.741 harmsja 7278: }
1.693 droeschl 7279:
1.870 tempelho 7280:
1.862 bisitz 7281: ul.LC_CourseBreadcrumbs {
7282: background: $sidebg;
1.1020 raeburn 7283: height: 2em;
1.862 bisitz 7284: padding-left: 10px;
1.1020 raeburn 7285: margin: 0;
1.862 bisitz 7286: list-style-position: inside;
7287: }
7288:
1.911 bisitz 7289: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7290: ol#LC_PathBreadcrumbs {
1.911 bisitz 7291: padding-left: 10px;
7292: margin: 0;
1.933 droeschl 7293: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7294: }
7295:
1.911 bisitz 7296: ol#LC_MenuBreadcrumbs li,
7297: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7298: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7299: display: inline;
1.933 droeschl 7300: white-space: normal;
1.693 droeschl 7301: }
7302:
1.823 bisitz 7303: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7304: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7305: text-decoration: none;
7306: font-size:90%;
1.693 droeschl 7307: }
1.795 www 7308:
1.969 droeschl 7309: ol#LC_MenuBreadcrumbs h1 {
7310: display: inline;
7311: font-size: 90%;
7312: line-height: 2.5em;
7313: margin: 0;
7314: padding: 0;
7315: }
7316:
1.795 www 7317: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7318: text-decoration:none;
7319: font-size:100%;
7320: font-weight:bold;
1.693 droeschl 7321: }
1.795 www 7322:
1.840 bisitz 7323: .LC_Box {
1.911 bisitz 7324: border: solid 1px $lg_border_color;
7325: padding: 0 10px 10px 10px;
1.746 neumanie 7326: }
1.795 www 7327:
1.1020 raeburn 7328: .LC_DocsBox {
7329: border: solid 1px $lg_border_color;
7330: padding: 0 0 10px 10px;
7331: }
7332:
1.795 www 7333: .LC_AboutMe_Image {
1.911 bisitz 7334: float:left;
7335: margin-right:10px;
1.747 neumanie 7336: }
1.795 www 7337:
7338: .LC_Clear_AboutMe_Image {
1.911 bisitz 7339: clear:left;
1.747 neumanie 7340: }
1.795 www 7341:
1.721 harmsja 7342: dl.LC_ListStyleClean dt {
1.911 bisitz 7343: padding-right: 5px;
7344: display: table-header-group;
1.693 droeschl 7345: }
7346:
1.721 harmsja 7347: dl.LC_ListStyleClean dd {
1.911 bisitz 7348: display: table-row;
1.693 droeschl 7349: }
7350:
1.721 harmsja 7351: .LC_ListStyleClean,
7352: .LC_ListStyleSimple,
7353: .LC_ListStyleNormal,
1.795 www 7354: .LC_ListStyleSpecial {
1.911 bisitz 7355: /* display:block; */
7356: list-style-position: inside;
7357: list-style-type: none;
7358: overflow: hidden;
7359: padding: 0;
1.693 droeschl 7360: }
7361:
1.721 harmsja 7362: .LC_ListStyleSimple li,
7363: .LC_ListStyleSimple dd,
7364: .LC_ListStyleNormal li,
7365: .LC_ListStyleNormal dd,
7366: .LC_ListStyleSpecial li,
1.795 www 7367: .LC_ListStyleSpecial dd {
1.911 bisitz 7368: margin: 0;
7369: padding: 5px 5px 5px 10px;
7370: clear: both;
1.693 droeschl 7371: }
7372:
1.721 harmsja 7373: .LC_ListStyleClean li,
7374: .LC_ListStyleClean dd {
1.911 bisitz 7375: padding-top: 0;
7376: padding-bottom: 0;
1.693 droeschl 7377: }
7378:
1.721 harmsja 7379: .LC_ListStyleSimple dd,
1.795 www 7380: .LC_ListStyleSimple li {
1.911 bisitz 7381: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7382: }
7383:
1.721 harmsja 7384: .LC_ListStyleSpecial li,
7385: .LC_ListStyleSpecial dd {
1.911 bisitz 7386: list-style-type: none;
7387: background-color: RGB(220, 220, 220);
7388: margin-bottom: 4px;
1.693 droeschl 7389: }
7390:
1.721 harmsja 7391: table.LC_SimpleTable {
1.911 bisitz 7392: margin:5px;
7393: border:solid 1px $lg_border_color;
1.795 www 7394: }
1.693 droeschl 7395:
1.721 harmsja 7396: table.LC_SimpleTable tr {
1.911 bisitz 7397: padding: 0;
7398: border:solid 1px $lg_border_color;
1.693 droeschl 7399: }
1.795 www 7400:
7401: table.LC_SimpleTable thead {
1.911 bisitz 7402: background:rgb(220,220,220);
1.693 droeschl 7403: }
7404:
1.721 harmsja 7405: div.LC_columnSection {
1.911 bisitz 7406: display: block;
7407: clear: both;
7408: overflow: hidden;
7409: margin: 0;
1.693 droeschl 7410: }
7411:
1.721 harmsja 7412: div.LC_columnSection>* {
1.911 bisitz 7413: float: left;
7414: margin: 10px 20px 10px 0;
7415: overflow:hidden;
1.693 droeschl 7416: }
1.721 harmsja 7417:
1.795 www 7418: table em {
1.911 bisitz 7419: font-weight: bold;
7420: font-style: normal;
1.748 schulted 7421: }
1.795 www 7422:
1.779 bisitz 7423: table.LC_tableBrowseRes,
1.795 www 7424: table.LC_tableOfContent {
1.911 bisitz 7425: border:none;
7426: border-spacing: 1px;
7427: padding: 3px;
7428: background-color: #FFFFFF;
7429: font-size: 90%;
1.753 droeschl 7430: }
1.789 droeschl 7431:
1.911 bisitz 7432: table.LC_tableOfContent {
7433: border-collapse: collapse;
1.789 droeschl 7434: }
7435:
1.771 droeschl 7436: table.LC_tableBrowseRes a,
1.768 schulted 7437: table.LC_tableOfContent a {
1.911 bisitz 7438: background-color: transparent;
7439: text-decoration: none;
1.753 droeschl 7440: }
7441:
1.795 www 7442: table.LC_tableOfContent img {
1.911 bisitz 7443: border: none;
7444: height: 1.3em;
7445: vertical-align: text-bottom;
7446: margin-right: 0.3em;
1.753 droeschl 7447: }
1.757 schulted 7448:
1.795 www 7449: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7450: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7451: }
7452:
1.795 www 7453: a#LC_content_toolbar_everything {
1.911 bisitz 7454: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7455: }
7456:
1.795 www 7457: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7458: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7459: }
7460:
1.795 www 7461: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7462: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7463: }
7464:
1.795 www 7465: a#LC_content_toolbar_changefolder {
1.911 bisitz 7466: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7467: }
7468:
1.795 www 7469: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7470: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7471: }
7472:
1.1043 raeburn 7473: a#LC_content_toolbar_edittoplevel {
7474: background-image:url(/res/adm/pages/edittoplevel.gif);
7475: }
7476:
1.795 www 7477: ul#LC_toolbar li a:hover {
1.911 bisitz 7478: background-position: bottom center;
1.757 schulted 7479: }
7480:
1.795 www 7481: ul#LC_toolbar {
1.911 bisitz 7482: padding: 0;
7483: margin: 2px;
7484: list-style:none;
7485: position:relative;
7486: background-color:white;
1.1082 raeburn 7487: overflow: auto;
1.757 schulted 7488: }
7489:
1.795 www 7490: ul#LC_toolbar li {
1.911 bisitz 7491: border:1px solid white;
7492: padding: 0;
7493: margin: 0;
7494: float: left;
7495: display:inline;
7496: vertical-align:middle;
1.1082 raeburn 7497: white-space: nowrap;
1.911 bisitz 7498: }
1.757 schulted 7499:
1.783 amueller 7500:
1.795 www 7501: a.LC_toolbarItem {
1.911 bisitz 7502: display:block;
7503: padding: 0;
7504: margin: 0;
7505: height: 32px;
7506: width: 32px;
7507: color:white;
7508: border: none;
7509: background-repeat:no-repeat;
7510: background-color:transparent;
1.757 schulted 7511: }
7512:
1.915 droeschl 7513: ul.LC_funclist {
7514: margin: 0;
7515: padding: 0.5em 1em 0.5em 0;
7516: }
7517:
1.933 droeschl 7518: ul.LC_funclist > li:first-child {
7519: font-weight:bold;
7520: margin-left:0.8em;
7521: }
7522:
1.915 droeschl 7523: ul.LC_funclist + ul.LC_funclist {
7524: /*
7525: left border as a seperator if we have more than
7526: one list
7527: */
7528: border-left: 1px solid $sidebg;
7529: /*
7530: this hides the left border behind the border of the
7531: outer box if element is wrapped to the next 'line'
7532: */
7533: margin-left: -1px;
7534: }
7535:
1.843 bisitz 7536: ul.LC_funclist li {
1.915 droeschl 7537: display: inline;
1.782 bisitz 7538: white-space: nowrap;
1.915 droeschl 7539: margin: 0 0 0 25px;
7540: line-height: 150%;
1.782 bisitz 7541: }
7542:
1.974 wenzelju 7543: .LC_hidden {
7544: display: none;
7545: }
7546:
1.1030 www 7547: .LCmodal-overlay {
7548: position:fixed;
7549: top:0;
7550: right:0;
7551: bottom:0;
7552: left:0;
7553: height:100%;
7554: width:100%;
7555: margin:0;
7556: padding:0;
7557: background:#999;
7558: opacity:.75;
7559: filter: alpha(opacity=75);
7560: -moz-opacity: 0.75;
7561: z-index:101;
7562: }
7563:
7564: * html .LCmodal-overlay {
7565: position: absolute;
7566: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7567: }
7568:
7569: .LCmodal-window {
7570: position:fixed;
7571: top:50%;
7572: left:50%;
7573: margin:0;
7574: padding:0;
7575: z-index:102;
7576: }
7577:
7578: * html .LCmodal-window {
7579: position:absolute;
7580: }
7581:
7582: .LCclose-window {
7583: position:absolute;
7584: width:32px;
7585: height:32px;
7586: right:8px;
7587: top:8px;
7588: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7589: text-indent:-99999px;
7590: overflow:hidden;
7591: cursor:pointer;
7592: }
7593:
1.1100 raeburn 7594: /*
7595: styles used by TTH when "Default set of options to pass to tth/m
7596: when converting TeX" in course settings has been set
7597:
7598: option passed: -t
7599:
7600: */
7601:
7602: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7603: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7604: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7605: td div.norm {line-height:normal;}
7606:
7607: /*
7608: option passed -y3
7609: */
7610:
7611: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7612: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7613: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7614:
1.343 albertel 7615: END
7616: }
7617:
1.306 albertel 7618: =pod
7619:
7620: =item * &headtag()
7621:
7622: Returns a uniform footer for LON-CAPA web pages.
7623:
1.307 albertel 7624: Inputs: $title - optional title for the head
7625: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7626: $args - optional arguments
1.319 albertel 7627: force_register - if is true call registerurl so the remote is
7628: informed
1.415 albertel 7629: redirect -> array ref of
7630: 1- seconds before redirect occurs
7631: 2- url to redirect to
7632: 3- whether the side effect should occur
1.315 albertel 7633: (side effect of setting
7634: $env{'internal.head.redirect'} to the url
7635: redirected too)
1.352 albertel 7636: domain -> force to color decorate a page for a specific
7637: domain
7638: function -> force usage of a specific rolish color scheme
7639: bgcolor -> override the default page bgcolor
1.460 albertel 7640: no_auto_mt_title
7641: -> prevent &mt()ing the title arg
1.464 albertel 7642:
1.306 albertel 7643: =cut
7644:
7645: sub headtag {
1.313 albertel 7646: my ($title,$head_extra,$args) = @_;
1.306 albertel 7647:
1.363 albertel 7648: my $function = $args->{'function'} || &get_users_function();
7649: my $domain = $args->{'domain'} || &determinedomain();
7650: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7651: my $httphost = $args->{'use_absolute'};
1.418 albertel 7652: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7653: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7654: #time(),
1.418 albertel 7655: $env{'environment.color.timestamp'},
1.363 albertel 7656: $function,$domain,$bgcolor);
7657:
1.369 www 7658: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7659:
1.308 albertel 7660: my $result =
7661: '<head>'.
1.1160 raeburn 7662: &font_settings($args);
1.319 albertel 7663:
1.1188 raeburn 7664: my $inhibitprint;
7665: if ($args->{'print_suppress'}) {
7666: $inhibitprint = &print_suppression();
7667: }
1.1064 raeburn 7668:
1.461 albertel 7669: if (!$args->{'frameset'}) {
7670: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7671: }
1.962 droeschl 7672: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7673: $result .= Apache::lonxml::display_title();
1.319 albertel 7674: }
1.436 albertel 7675: if (!$args->{'no_nav_bar'}
7676: && !$args->{'only_body'}
7677: && !$args->{'frameset'}) {
1.1154 raeburn 7678: $result .= &help_menu_js($httphost);
1.1032 www 7679: $result.=&modal_window();
1.1038 www 7680: $result.=&togglebox_script();
1.1034 www 7681: $result.=&wishlist_window();
1.1041 www 7682: $result.=&LCprogressbarUpdate_script();
1.1034 www 7683: } else {
7684: if ($args->{'add_modal'}) {
7685: $result.=&modal_window();
7686: }
7687: if ($args->{'add_wishlist'}) {
7688: $result.=&wishlist_window();
7689: }
1.1038 www 7690: if ($args->{'add_togglebox'}) {
7691: $result.=&togglebox_script();
7692: }
1.1041 www 7693: if ($args->{'add_progressbar'}) {
7694: $result.=&LCprogressbarUpdate_script();
7695: }
1.436 albertel 7696: }
1.314 albertel 7697: if (ref($args->{'redirect'})) {
1.414 albertel 7698: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7699: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7700: if (!$inhibit_continue) {
7701: $env{'internal.head.redirect'} = $url;
7702: }
1.313 albertel 7703: $result.=<<ADDMETA
7704: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7705: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7706: ADDMETA
1.1210 raeburn 7707: } else {
7708: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7709: my $requrl = $env{'request.uri'};
7710: if ($requrl eq '') {
7711: $requrl = $ENV{'REQUEST_URI'};
7712: $requrl =~ s/\?.+$//;
7713: }
7714: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7715: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7716: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7717: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7718: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7719: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7720: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7721: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7722: if ($domdefs{'offloadnow'}{$lonhost}) {
7723: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7724: if (($newserver) && ($newserver ne $lonhost)) {
7725: my $numsec = 5;
7726: my $timeout = $numsec * 1000;
7727: my ($newurl,$locknum,%locks,$msg);
7728: if ($env{'request.role.adv'}) {
7729: ($locknum,%locks) = &Apache::lonnet::get_locks();
7730: }
7731: my $disable_submit = 0;
7732: if ($requrl =~ /$LONCAPA::assess_re/) {
7733: $disable_submit = 1;
7734: }
7735: if ($locknum) {
7736: my @lockinfo = sort(values(%locks));
7737: $msg = &mt('Once the following tasks are complete: ')."\\n".
7738: join(", ",sort(values(%locks)))."\\n".
7739: &mt('your session will be transferred to a different server, after you click "Roles".');
7740: } else {
7741: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7742: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7743: }
7744: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7745: $newurl = '/adm/switchserver?otherserver='.$newserver;
7746: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7747: $newurl .= '&role='.$env{'request.role'};
7748: }
7749: if ($env{'request.symb'}) {
7750: $newurl .= '&symb='.$env{'request.symb'};
7751: } else {
7752: $newurl .= '&origurl='.$requrl;
7753: }
7754: }
7755: $result.=<<OFFLOAD
7756: <meta http-equiv="pragma" content="no-cache" />
7757: <script type="text/javascript">
7758: function LC_Offload_Now() {
7759: var dest = "$newurl";
7760: if (dest != '') {
7761: window.location.href="$newurl";
7762: }
7763: }
7764: window.alert('$msg');
7765: if ($disable_submit) {
7766: \$(document).ready(function () {
7767: \$(".LC_hwk_submit").prop("disabled", true);
7768: \$( ".LC_textline" ).prop( "readonly", "readonly");
7769: });
7770: }
7771: setTimeout('LC_Offload_Now()', $timeout);
7772: </script>
7773: OFFLOAD
7774: }
7775: }
7776: }
7777: }
7778: }
7779: }
1.313 albertel 7780: }
1.306 albertel 7781: if (!defined($title)) {
7782: $title = 'The LearningOnline Network with CAPA';
7783: }
1.460 albertel 7784: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7785: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7786: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7787: if (!$args->{'frameset'}) {
7788: $result .= ' /';
7789: }
7790: $result .= '>'
1.1064 raeburn 7791: .$inhibitprint
1.414 albertel 7792: .$head_extra;
1.1137 raeburn 7793: if ($env{'browser.mobile'}) {
7794: $result .= '
7795: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7796: <meta name="apple-mobile-web-app-capable" content="yes" />';
7797: }
1.962 droeschl 7798: return $result.'</head>';
1.306 albertel 7799: }
7800:
7801: =pod
7802:
1.340 albertel 7803: =item * &font_settings()
7804:
7805: Returns neccessary <meta> to set the proper encoding
7806:
1.1160 raeburn 7807: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7808:
7809: =cut
7810:
7811: sub font_settings {
1.1160 raeburn 7812: my ($args) = @_;
1.340 albertel 7813: my $headerstring='';
1.1160 raeburn 7814: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7815: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7816: $headerstring.=
7817: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7818: if (!$args->{'frameset'}) {
7819: $headerstring.= ' /';
7820: }
7821: $headerstring .= '>'."\n";
1.340 albertel 7822: }
7823: return $headerstring;
7824: }
7825:
1.341 albertel 7826: =pod
7827:
1.1064 raeburn 7828: =item * &print_suppression()
7829:
7830: In course context returns css which causes the body to be blank when media="print",
7831: if printout generation is unavailable for the current resource.
7832:
7833: This could be because:
7834:
7835: (a) printstartdate is in the future
7836:
7837: (b) printenddate is in the past
7838:
7839: (c) there is an active exam block with "printout"
7840: functionality blocked
7841:
7842: Users with pav, pfo or evb privileges are exempt.
7843:
7844: Inputs: none
7845:
7846: =cut
7847:
7848:
7849: sub print_suppression {
7850: my $noprint;
7851: if ($env{'request.course.id'}) {
7852: my $scope = $env{'request.course.id'};
7853: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7854: (&Apache::lonnet::allowed('pfo',$scope))) {
7855: return;
7856: }
7857: if ($env{'request.course.sec'} ne '') {
7858: $scope .= "/$env{'request.course.sec'}";
7859: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7860: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7861: return;
1.1064 raeburn 7862: }
7863: }
7864: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7865: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 7866: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7867: if ($blocked) {
7868: my $checkrole = "cm./$cdom/$cnum";
7869: if ($env{'request.course.sec'} ne '') {
7870: $checkrole .= "/$env{'request.course.sec'}";
7871: }
7872: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7873: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7874: $noprint = 1;
7875: }
7876: }
7877: unless ($noprint) {
7878: my $symb = &Apache::lonnet::symbread();
7879: if ($symb ne '') {
7880: my $navmap = Apache::lonnavmaps::navmap->new();
7881: if (ref($navmap)) {
7882: my $res = $navmap->getBySymb($symb);
7883: if (ref($res)) {
7884: if (!$res->resprintable()) {
7885: $noprint = 1;
7886: }
7887: }
7888: }
7889: }
7890: }
7891: if ($noprint) {
7892: return <<"ENDSTYLE";
7893: <style type="text/css" media="print">
7894: body { display:none }
7895: </style>
7896: ENDSTYLE
7897: }
7898: }
7899: return;
7900: }
7901:
7902: =pod
7903:
1.341 albertel 7904: =item * &xml_begin()
7905:
7906: Returns the needed doctype and <html>
7907:
7908: Inputs: none
7909:
7910: =cut
7911:
7912: sub xml_begin {
1.1168 raeburn 7913: my ($is_frameset) = @_;
1.341 albertel 7914: my $output='';
7915:
7916: if ($env{'browser.mathml'}) {
7917: $output='<?xml version="1.0"?>'
7918: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7919: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7920:
7921: # .'<!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">] >'
7922: .'<!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">'
7923: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7924: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 7925: } elsif ($is_frameset) {
7926: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7927: '<html>'."\n";
1.341 albertel 7928: } else {
1.1168 raeburn 7929: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7930: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7931: }
7932: return $output;
7933: }
1.340 albertel 7934:
7935: =pod
7936:
1.306 albertel 7937: =item * &start_page()
7938:
7939: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7940:
1.648 raeburn 7941: Inputs:
7942:
7943: =over 4
7944:
7945: $title - optional title for the page
7946:
7947: $head_extra - optional extra HTML to incude inside the <head>
7948:
7949: $args - additional optional args supported are:
7950:
7951: =over 8
7952:
7953: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7954: arg on
1.814 bisitz 7955: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7956: add_entries -> additional attributes to add to the <body>
7957: domain -> force to color decorate a page for a
1.317 albertel 7958: specific domain
1.648 raeburn 7959: function -> force usage of a specific rolish color
1.317 albertel 7960: scheme
1.648 raeburn 7961: redirect -> see &headtag()
7962: bgcolor -> override the default page bg color
7963: js_ready -> return a string ready for being used in
1.317 albertel 7964: a javascript writeln
1.648 raeburn 7965: html_encode -> return a string ready for being used in
1.320 albertel 7966: a html attribute
1.648 raeburn 7967: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7968: $forcereg arg
1.648 raeburn 7969: frameset -> if true will start with a <frameset>
1.330 albertel 7970: rather than <body>
1.648 raeburn 7971: skip_phases -> hash ref of
1.338 albertel 7972: head -> skip the <html><head> generation
7973: body -> skip all <body> generation
1.648 raeburn 7974: no_auto_mt_title -> prevent &mt()ing the title arg
7975: inherit_jsmath -> when creating popup window in a page,
7976: should it have jsmath forced on by the
7977: current page
1.867 kalberla 7978: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7979: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7980: group -> includes the current group, if page is for a
7981: specific group
1.361 albertel 7982:
1.648 raeburn 7983: =back
1.460 albertel 7984:
1.648 raeburn 7985: =back
1.562 albertel 7986:
1.306 albertel 7987: =cut
7988:
7989: sub start_page {
1.309 albertel 7990: my ($title,$head_extra,$args) = @_;
1.318 albertel 7991: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7992:
1.315 albertel 7993: $env{'internal.start_page'}++;
1.1096 raeburn 7994: my ($result,@advtools);
1.964 droeschl 7995:
1.338 albertel 7996: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 7997: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7998: }
7999:
8000: if (! exists($args->{'skip_phases'}{'body'}) ) {
8001: if ($args->{'frameset'}) {
8002: my $attr_string = &make_attr_string($args->{'force_register'},
8003: $args->{'add_entries'});
8004: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8005: } else {
8006: $result .=
8007: &bodytag($title,
8008: $args->{'function'}, $args->{'add_entries'},
8009: $args->{'only_body'}, $args->{'domain'},
8010: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8011: $args->{'bgcolor'}, $args,
8012: \@advtools);
1.831 bisitz 8013: }
1.330 albertel 8014: }
1.338 albertel 8015:
1.315 albertel 8016: if ($args->{'js_ready'}) {
1.713 kaisler 8017: $result = &js_ready($result);
1.315 albertel 8018: }
1.320 albertel 8019: if ($args->{'html_encode'}) {
1.713 kaisler 8020: $result = &html_encode($result);
8021: }
8022:
1.813 bisitz 8023: # Preparation for new and consistent functionlist at top of screen
8024: # if ($args->{'functionlist'}) {
8025: # $result .= &build_functionlist();
8026: #}
8027:
1.964 droeschl 8028: # Don't add anything more if only_body wanted or in const space
8029: return $result if $args->{'only_body'}
8030: || $env{'request.state'} eq 'construct';
1.813 bisitz 8031:
8032: #Breadcrumbs
1.758 kaisler 8033: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8034: &Apache::lonhtmlcommon::clear_breadcrumbs();
8035: #if any br links exists, add them to the breadcrumbs
8036: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8037: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8038: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8039: }
8040: }
1.1096 raeburn 8041: # if @advtools array contains items add then to the breadcrumbs
8042: if (@advtools > 0) {
8043: &Apache::lonmenu::advtools_crumbs(@advtools);
8044: }
1.758 kaisler 8045:
8046: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8047: if(exists($args->{'bread_crumbs_component'})){
8048: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
8049: }else{
8050: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8051: }
1.320 albertel 8052: }
1.315 albertel 8053: return $result;
1.306 albertel 8054: }
8055:
8056: sub end_page {
1.315 albertel 8057: my ($args) = @_;
8058: $env{'internal.end_page'}++;
1.330 albertel 8059: my $result;
1.335 albertel 8060: if ($args->{'discussion'}) {
8061: my ($target,$parser);
8062: if (ref($args->{'discussion'})) {
8063: ($target,$parser) =($args->{'discussion'}{'target'},
8064: $args->{'discussion'}{'parser'});
8065: }
8066: $result .= &Apache::lonxml::xmlend($target,$parser);
8067: }
1.330 albertel 8068: if ($args->{'frameset'}) {
8069: $result .= '</frameset>';
8070: } else {
1.635 raeburn 8071: $result .= &endbodytag($args);
1.330 albertel 8072: }
1.1080 raeburn 8073: unless ($args->{'notbody'}) {
8074: $result .= "\n</html>";
8075: }
1.330 albertel 8076:
1.315 albertel 8077: if ($args->{'js_ready'}) {
1.317 albertel 8078: $result = &js_ready($result);
1.315 albertel 8079: }
1.335 albertel 8080:
1.320 albertel 8081: if ($args->{'html_encode'}) {
8082: $result = &html_encode($result);
8083: }
1.335 albertel 8084:
1.315 albertel 8085: return $result;
8086: }
8087:
1.1034 www 8088: sub wishlist_window {
8089: return(<<'ENDWISHLIST');
1.1046 raeburn 8090: <script type="text/javascript">
1.1034 www 8091: // <![CDATA[
8092: // <!-- BEGIN LON-CAPA Internal
8093: function set_wishlistlink(title, path) {
8094: if (!title) {
8095: title = document.title;
8096: title = title.replace(/^LON-CAPA /,'');
8097: }
1.1175 raeburn 8098: title = encodeURIComponent(title);
1.1203 raeburn 8099: title = title.replace("'","\\\'");
1.1034 www 8100: if (!path) {
8101: path = location.pathname;
8102: }
1.1175 raeburn 8103: path = encodeURIComponent(path);
1.1203 raeburn 8104: path = path.replace("'","\\\'");
1.1034 www 8105: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8106: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8107: }
8108: // END LON-CAPA Internal -->
8109: // ]]>
8110: </script>
8111: ENDWISHLIST
8112: }
8113:
1.1030 www 8114: sub modal_window {
8115: return(<<'ENDMODAL');
1.1046 raeburn 8116: <script type="text/javascript">
1.1030 www 8117: // <![CDATA[
8118: // <!-- BEGIN LON-CAPA Internal
8119: var modalWindow = {
8120: parent:"body",
8121: windowId:null,
8122: content:null,
8123: width:null,
8124: height:null,
8125: close:function()
8126: {
8127: $(".LCmodal-window").remove();
8128: $(".LCmodal-overlay").remove();
8129: },
8130: open:function()
8131: {
8132: var modal = "";
8133: modal += "<div class=\"LCmodal-overlay\"></div>";
8134: 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;\">";
8135: modal += this.content;
8136: modal += "</div>";
8137:
8138: $(this.parent).append(modal);
8139:
8140: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8141: $(".LCclose-window").click(function(){modalWindow.close();});
8142: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8143: }
8144: };
1.1140 raeburn 8145: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8146: {
1.1203 raeburn 8147: source = source.replace("'","'");
1.1030 www 8148: modalWindow.windowId = "myModal";
8149: modalWindow.width = width;
8150: modalWindow.height = height;
1.1196 raeburn 8151: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8152: modalWindow.open();
1.1208 raeburn 8153: };
1.1030 www 8154: // END LON-CAPA Internal -->
8155: // ]]>
8156: </script>
8157: ENDMODAL
8158: }
8159:
8160: sub modal_link {
1.1140 raeburn 8161: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8162: unless ($width) { $width=480; }
8163: unless ($height) { $height=400; }
1.1031 www 8164: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8165: unless ($transparency) { $transparency='true'; }
8166:
1.1074 raeburn 8167: my $target_attr;
8168: if (defined($target)) {
8169: $target_attr = 'target="'.$target.'"';
8170: }
8171: return <<"ENDLINK";
1.1140 raeburn 8172: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8173: $linktext</a>
8174: ENDLINK
1.1030 www 8175: }
8176:
1.1032 www 8177: sub modal_adhoc_script {
8178: my ($funcname,$width,$height,$content)=@_;
8179: return (<<ENDADHOC);
1.1046 raeburn 8180: <script type="text/javascript">
1.1032 www 8181: // <![CDATA[
8182: var $funcname = function()
8183: {
8184: modalWindow.windowId = "myModal";
8185: modalWindow.width = $width;
8186: modalWindow.height = $height;
8187: modalWindow.content = '$content';
8188: modalWindow.open();
8189: };
8190: // ]]>
8191: </script>
8192: ENDADHOC
8193: }
8194:
1.1041 www 8195: sub modal_adhoc_inner {
8196: my ($funcname,$width,$height,$content)=@_;
8197: my $innerwidth=$width-20;
8198: $content=&js_ready(
1.1140 raeburn 8199: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8200: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8201: $content.
1.1041 www 8202: &end_scrollbox().
1.1140 raeburn 8203: &end_page()
1.1041 www 8204: );
8205: return &modal_adhoc_script($funcname,$width,$height,$content);
8206: }
8207:
8208: sub modal_adhoc_window {
8209: my ($funcname,$width,$height,$content,$linktext)=@_;
8210: return &modal_adhoc_inner($funcname,$width,$height,$content).
8211: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8212: }
8213:
8214: sub modal_adhoc_launch {
8215: my ($funcname,$width,$height,$content)=@_;
8216: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8217: <script type="text/javascript">
8218: // <![CDATA[
8219: $funcname();
8220: // ]]>
8221: </script>
8222: ENDLAUNCH
8223: }
8224:
8225: sub modal_adhoc_close {
8226: return (<<ENDCLOSE);
8227: <script type="text/javascript">
8228: // <![CDATA[
8229: modalWindow.close();
8230: // ]]>
8231: </script>
8232: ENDCLOSE
8233: }
8234:
1.1038 www 8235: sub togglebox_script {
8236: return(<<ENDTOGGLE);
8237: <script type="text/javascript">
8238: // <![CDATA[
8239: function LCtoggleDisplay(id,hidetext,showtext) {
8240: link = document.getElementById(id + "link").childNodes[0];
8241: with (document.getElementById(id).style) {
8242: if (display == "none" ) {
8243: display = "inline";
8244: link.nodeValue = hidetext;
8245: } else {
8246: display = "none";
8247: link.nodeValue = showtext;
8248: }
8249: }
8250: }
8251: // ]]>
8252: </script>
8253: ENDTOGGLE
8254: }
8255:
1.1039 www 8256: sub start_togglebox {
8257: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8258: unless ($heading) { $heading=''; } else { $heading.=' '; }
8259: unless ($showtext) { $showtext=&mt('show'); }
8260: unless ($hidetext) { $hidetext=&mt('hide'); }
8261: unless ($headerbg) { $headerbg='#FFFFFF'; }
8262: return &start_data_table().
8263: &start_data_table_header_row().
8264: '<td bgcolor="'.$headerbg.'">'.$heading.
8265: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8266: $showtext.'\')">'.$showtext.'</a>]</td>'.
8267: &end_data_table_header_row().
8268: '<tr id="'.$id.'" style="display:none""><td>';
8269: }
8270:
8271: sub end_togglebox {
8272: return '</td></tr>'.&end_data_table();
8273: }
8274:
1.1041 www 8275: sub LCprogressbar_script {
1.1045 www 8276: my ($id)=@_;
1.1041 www 8277: return(<<ENDPROGRESS);
8278: <script type="text/javascript">
8279: // <![CDATA[
1.1045 www 8280: \$('#progressbar$id').progressbar({
1.1041 www 8281: value: 0,
8282: change: function(event, ui) {
8283: var newVal = \$(this).progressbar('option', 'value');
8284: \$('.pblabel', this).text(LCprogressTxt);
8285: }
8286: });
8287: // ]]>
8288: </script>
8289: ENDPROGRESS
8290: }
8291:
8292: sub LCprogressbarUpdate_script {
8293: return(<<ENDPROGRESSUPDATE);
8294: <style type="text/css">
8295: .ui-progressbar { position:relative; }
8296: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8297: </style>
8298: <script type="text/javascript">
8299: // <![CDATA[
1.1045 www 8300: var LCprogressTxt='---';
8301:
8302: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8303: LCprogressTxt=progresstext;
1.1045 www 8304: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8305: }
8306: // ]]>
8307: </script>
8308: ENDPROGRESSUPDATE
8309: }
8310:
1.1042 www 8311: my $LClastpercent;
1.1045 www 8312: my $LCidcnt;
8313: my $LCcurrentid;
1.1042 www 8314:
1.1041 www 8315: sub LCprogressbar {
1.1042 www 8316: my ($r)=(@_);
8317: $LClastpercent=0;
1.1045 www 8318: $LCidcnt++;
8319: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8320: my $starting=&mt('Starting');
8321: my $content=(<<ENDPROGBAR);
1.1045 www 8322: <div id="progressbar$LCcurrentid">
1.1041 www 8323: <span class="pblabel">$starting</span>
8324: </div>
8325: ENDPROGBAR
1.1045 www 8326: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8327: }
8328:
8329: sub LCprogressbarUpdate {
1.1042 www 8330: my ($r,$val,$text)=@_;
8331: unless ($val) {
8332: if ($LClastpercent) {
8333: $val=$LClastpercent;
8334: } else {
8335: $val=0;
8336: }
8337: }
1.1041 www 8338: if ($val<0) { $val=0; }
8339: if ($val>100) { $val=0; }
1.1042 www 8340: $LClastpercent=$val;
1.1041 www 8341: unless ($text) { $text=$val.'%'; }
8342: $text=&js_ready($text);
1.1044 www 8343: &r_print($r,<<ENDUPDATE);
1.1041 www 8344: <script type="text/javascript">
8345: // <![CDATA[
1.1045 www 8346: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8347: // ]]>
8348: </script>
8349: ENDUPDATE
1.1035 www 8350: }
8351:
1.1042 www 8352: sub LCprogressbarClose {
8353: my ($r)=@_;
8354: $LClastpercent=0;
1.1044 www 8355: &r_print($r,<<ENDCLOSE);
1.1042 www 8356: <script type="text/javascript">
8357: // <![CDATA[
1.1045 www 8358: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8359: // ]]>
8360: </script>
8361: ENDCLOSE
1.1044 www 8362: }
8363:
8364: sub r_print {
8365: my ($r,$to_print)=@_;
8366: if ($r) {
8367: $r->print($to_print);
8368: $r->rflush();
8369: } else {
8370: print($to_print);
8371: }
1.1042 www 8372: }
8373:
1.320 albertel 8374: sub html_encode {
8375: my ($result) = @_;
8376:
1.322 albertel 8377: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8378:
8379: return $result;
8380: }
1.1044 www 8381:
1.317 albertel 8382: sub js_ready {
8383: my ($result) = @_;
8384:
1.323 albertel 8385: $result =~ s/[\n\r]/ /xmsg;
8386: $result =~ s/\\/\\\\/xmsg;
8387: $result =~ s/'/\\'/xmsg;
1.372 albertel 8388: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8389:
8390: return $result;
8391: }
8392:
1.315 albertel 8393: sub validate_page {
8394: if ( exists($env{'internal.start_page'})
1.316 albertel 8395: && $env{'internal.start_page'} > 1) {
8396: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8397: $env{'internal.start_page'}.' '.
1.316 albertel 8398: $ENV{'request.filename'});
1.315 albertel 8399: }
8400: if ( exists($env{'internal.end_page'})
1.316 albertel 8401: && $env{'internal.end_page'} > 1) {
8402: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8403: $env{'internal.end_page'}.' '.
1.316 albertel 8404: $env{'request.filename'});
1.315 albertel 8405: }
8406: if ( exists($env{'internal.start_page'})
8407: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8408: &Apache::lonnet::logthis('start_page called without end_page '.
8409: $env{'request.filename'});
1.315 albertel 8410: }
8411: if ( ! exists($env{'internal.start_page'})
8412: && exists($env{'internal.end_page'})) {
1.316 albertel 8413: &Apache::lonnet::logthis('end_page called without start_page'.
8414: $env{'request.filename'});
1.315 albertel 8415: }
1.306 albertel 8416: }
1.315 albertel 8417:
1.996 www 8418:
8419: sub start_scrollbox {
1.1140 raeburn 8420: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8421: unless ($outerwidth) { $outerwidth='520px'; }
8422: unless ($width) { $width='500px'; }
8423: unless ($height) { $height='200px'; }
1.1075 raeburn 8424: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8425: if ($id ne '') {
1.1140 raeburn 8426: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8427: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8428: }
1.1075 raeburn 8429: if ($bgcolor ne '') {
8430: $tdcol = "background-color: $bgcolor;";
8431: }
1.1137 raeburn 8432: my $nicescroll_js;
8433: if ($env{'browser.mobile'}) {
1.1140 raeburn 8434: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8435: }
8436: return <<"END";
8437: $nicescroll_js
8438:
8439: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8440: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8441: END
8442: }
8443:
8444: sub end_scrollbox {
8445: return '</div></td></tr></table>';
8446: }
8447:
8448: sub nicescroll_javascript {
8449: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8450: my %options;
8451: if (ref($cursor) eq 'HASH') {
8452: %options = %{$cursor};
8453: }
8454: unless ($options{'railalign'} =~ /^left|right$/) {
8455: $options{'railalign'} = 'left';
8456: }
8457: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8458: my $function = &get_users_function();
8459: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8460: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8461: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8462: }
1.1140 raeburn 8463: }
8464: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8465: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8466: $options{'cursoropacity'}='1.0';
8467: }
1.1140 raeburn 8468: } else {
8469: $options{'cursoropacity'}='1.0';
8470: }
8471: if ($options{'cursorfixedheight'} eq 'none') {
8472: delete($options{'cursorfixedheight'});
8473: } else {
8474: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8475: }
8476: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8477: delete($options{'railoffset'});
8478: }
8479: my @niceoptions;
8480: while (my($key,$value) = each(%options)) {
8481: if ($value =~ /^\{.+\}$/) {
8482: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8483: } else {
1.1140 raeburn 8484: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8485: }
1.1140 raeburn 8486: }
8487: my $nicescroll_js = '
1.1137 raeburn 8488: $(document).ready(
1.1140 raeburn 8489: function() {
8490: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8491: }
1.1137 raeburn 8492: );
8493: ';
1.1140 raeburn 8494: if ($framecheck) {
8495: $nicescroll_js .= '
8496: function expand_div(caller) {
8497: if (top === self) {
8498: document.getElementById("'.$id.'").style.width = "auto";
8499: document.getElementById("'.$id.'").style.height = "auto";
8500: } else {
8501: try {
8502: if (parent.frames) {
8503: if (parent.frames.length > 1) {
8504: var framesrc = parent.frames[1].location.href;
8505: var currsrc = framesrc.replace(/\#.*$/,"");
8506: if ((caller == "search") || (currsrc == "'.$location.'")) {
8507: document.getElementById("'.$id.'").style.width = "auto";
8508: document.getElementById("'.$id.'").style.height = "auto";
8509: }
8510: }
8511: }
8512: } catch (e) {
8513: return;
8514: }
1.1137 raeburn 8515: }
1.1140 raeburn 8516: return;
1.996 www 8517: }
1.1140 raeburn 8518: ';
8519: }
8520: if ($needjsready) {
8521: $nicescroll_js = '
8522: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8523: } else {
8524: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8525: }
8526: return $nicescroll_js;
1.996 www 8527: }
8528:
1.318 albertel 8529: sub simple_error_page {
1.1150 bisitz 8530: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8531: if (ref($args) eq 'HASH') {
8532: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8533: } else {
8534: $msg = &mt($msg);
8535: }
1.1150 bisitz 8536:
1.318 albertel 8537: my $page =
8538: &Apache::loncommon::start_page($title).
1.1150 bisitz 8539: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8540: &Apache::loncommon::end_page();
8541: if (ref($r)) {
8542: $r->print($page);
1.327 albertel 8543: return;
1.318 albertel 8544: }
8545: return $page;
8546: }
1.347 albertel 8547:
8548: {
1.610 albertel 8549: my @row_count;
1.961 onken 8550:
8551: sub start_data_table_count {
8552: unshift(@row_count, 0);
8553: return;
8554: }
8555:
8556: sub end_data_table_count {
8557: shift(@row_count);
8558: return;
8559: }
8560:
1.347 albertel 8561: sub start_data_table {
1.1018 raeburn 8562: my ($add_class,$id) = @_;
1.422 albertel 8563: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8564: my $table_id;
8565: if (defined($id)) {
8566: $table_id = ' id="'.$id.'"';
8567: }
1.961 onken 8568: &start_data_table_count();
1.1018 raeburn 8569: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8570: }
8571:
8572: sub end_data_table {
1.961 onken 8573: &end_data_table_count();
1.389 albertel 8574: return '</table>'."\n";;
1.347 albertel 8575: }
8576:
8577: sub start_data_table_row {
1.974 wenzelju 8578: my ($add_class, $id) = @_;
1.610 albertel 8579: $row_count[0]++;
8580: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8581: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8582: $id = (' id="'.$id.'"') unless ($id eq '');
8583: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8584: }
1.471 banghart 8585:
8586: sub continue_data_table_row {
1.974 wenzelju 8587: my ($add_class, $id) = @_;
1.610 albertel 8588: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8589: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8590: $id = (' id="'.$id.'"') unless ($id eq '');
8591: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8592: }
1.347 albertel 8593:
8594: sub end_data_table_row {
1.389 albertel 8595: return '</tr>'."\n";;
1.347 albertel 8596: }
1.367 www 8597:
1.421 albertel 8598: sub start_data_table_empty_row {
1.707 bisitz 8599: # $row_count[0]++;
1.421 albertel 8600: return '<tr class="LC_empty_row" >'."\n";;
8601: }
8602:
8603: sub end_data_table_empty_row {
8604: return '</tr>'."\n";;
8605: }
8606:
1.367 www 8607: sub start_data_table_header_row {
1.389 albertel 8608: return '<tr class="LC_header_row">'."\n";;
1.367 www 8609: }
8610:
8611: sub end_data_table_header_row {
1.389 albertel 8612: return '</tr>'."\n";;
1.367 www 8613: }
1.890 droeschl 8614:
8615: sub data_table_caption {
8616: my $caption = shift;
8617: return "<caption class=\"LC_caption\">$caption</caption>";
8618: }
1.347 albertel 8619: }
8620:
1.548 albertel 8621: =pod
8622:
8623: =item * &inhibit_menu_check($arg)
8624:
8625: Checks for a inhibitmenu state and generates output to preserve it
8626:
8627: Inputs: $arg - can be any of
8628: - undef - in which case the return value is a string
8629: to add into arguments list of a uri
8630: - 'input' - in which case the return value is a HTML
8631: <form> <input> field of type hidden to
8632: preserve the value
8633: - a url - in which case the return value is the url with
8634: the neccesary cgi args added to preserve the
8635: inhibitmenu state
8636: - a ref to a url - no return value, but the string is
8637: updated to include the neccessary cgi
8638: args to preserve the inhibitmenu state
8639:
8640: =cut
8641:
8642: sub inhibit_menu_check {
8643: my ($arg) = @_;
8644: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8645: if ($arg eq 'input') {
8646: if ($env{'form.inhibitmenu'}) {
8647: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8648: } else {
8649: return
8650: }
8651: }
8652: if ($env{'form.inhibitmenu'}) {
8653: if (ref($arg)) {
8654: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8655: } elsif ($arg eq '') {
8656: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8657: } else {
8658: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8659: }
8660: }
8661: if (!ref($arg)) {
8662: return $arg;
8663: }
8664: }
8665:
1.251 albertel 8666: ###############################################
1.182 matthew 8667:
8668: =pod
8669:
1.549 albertel 8670: =back
8671:
8672: =head1 User Information Routines
8673:
8674: =over 4
8675:
1.405 albertel 8676: =item * &get_users_function()
1.182 matthew 8677:
8678: Used by &bodytag to determine the current users primary role.
8679: Returns either 'student','coordinator','admin', or 'author'.
8680:
8681: =cut
8682:
8683: ###############################################
8684: sub get_users_function {
1.815 tempelho 8685: my $function = 'norole';
1.818 tempelho 8686: if ($env{'request.role'}=~/^(st)/) {
8687: $function='student';
8688: }
1.907 raeburn 8689: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8690: $function='coordinator';
8691: }
1.258 albertel 8692: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8693: $function='admin';
8694: }
1.826 bisitz 8695: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8696: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8697: $function='author';
8698: }
8699: return $function;
1.54 www 8700: }
1.99 www 8701:
8702: ###############################################
8703:
1.233 raeburn 8704: =pod
8705:
1.821 raeburn 8706: =item * &show_course()
8707:
8708: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8709: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8710:
8711: Inputs:
8712: None
8713:
8714: Outputs:
8715: Scalar: 1 if 'Course' to be used, 0 otherwise.
8716:
8717: =cut
8718:
8719: ###############################################
8720: sub show_course {
8721: my $course = !$env{'user.adv'};
8722: if (!$env{'user.adv'}) {
8723: foreach my $env (keys(%env)) {
8724: next if ($env !~ m/^user\.priv\./);
8725: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8726: $course = 0;
8727: last;
8728: }
8729: }
8730: }
8731: return $course;
8732: }
8733:
8734: ###############################################
8735:
8736: =pod
8737:
1.542 raeburn 8738: =item * &check_user_status()
1.274 raeburn 8739:
8740: Determines current status of supplied role for a
8741: specific user. Roles can be active, previous or future.
8742:
8743: Inputs:
8744: user's domain, user's username, course's domain,
1.375 raeburn 8745: course's number, optional section ID.
1.274 raeburn 8746:
8747: Outputs:
8748: role status: active, previous or future.
8749:
8750: =cut
8751:
8752: sub check_user_status {
1.412 raeburn 8753: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8754: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 8755: my @uroles = keys(%userinfo);
1.274 raeburn 8756: my $srchstr;
8757: my $active_chk = 'none';
1.412 raeburn 8758: my $now = time;
1.274 raeburn 8759: if (@uroles > 0) {
1.908 raeburn 8760: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8761: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8762: } else {
1.412 raeburn 8763: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8764: }
8765: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8766: my $role_end = 0;
8767: my $role_start = 0;
8768: $active_chk = 'active';
1.412 raeburn 8769: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8770: $role_end = $1;
8771: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8772: $role_start = $1;
1.274 raeburn 8773: }
8774: }
8775: if ($role_start > 0) {
1.412 raeburn 8776: if ($now < $role_start) {
1.274 raeburn 8777: $active_chk = 'future';
8778: }
8779: }
8780: if ($role_end > 0) {
1.412 raeburn 8781: if ($now > $role_end) {
1.274 raeburn 8782: $active_chk = 'previous';
8783: }
8784: }
8785: }
8786: }
8787: return $active_chk;
8788: }
8789:
8790: ###############################################
8791:
8792: =pod
8793:
1.405 albertel 8794: =item * &get_sections()
1.233 raeburn 8795:
8796: Determines all the sections for a course including
8797: sections with students and sections containing other roles.
1.419 raeburn 8798: Incoming parameters:
8799:
8800: 1. domain
8801: 2. course number
8802: 3. reference to array containing roles for which sections should
8803: be gathered (optional).
8804: 4. reference to array containing status types for which sections
8805: should be gathered (optional).
8806:
8807: If the third argument is undefined, sections are gathered for any role.
8808: If the fourth argument is undefined, sections are gathered for any status.
8809: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8810:
1.374 raeburn 8811: Returns section hash (keys are section IDs, values are
8812: number of users in each section), subject to the
1.419 raeburn 8813: optional roles filter, optional status filter
1.233 raeburn 8814:
8815: =cut
8816:
8817: ###############################################
8818: sub get_sections {
1.419 raeburn 8819: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8820: if (!defined($cdom) || !defined($cnum)) {
8821: my $cid = $env{'request.course.id'};
8822:
8823: return if (!defined($cid));
8824:
8825: $cdom = $env{'course.'.$cid.'.domain'};
8826: $cnum = $env{'course.'.$cid.'.num'};
8827: }
8828:
8829: my %sectioncount;
1.419 raeburn 8830: my $now = time;
1.240 albertel 8831:
1.1118 raeburn 8832: my $check_students = 1;
8833: my $only_students = 0;
8834: if (ref($possible_roles) eq 'ARRAY') {
8835: if (grep(/^st$/,@{$possible_roles})) {
8836: if (@{$possible_roles} == 1) {
8837: $only_students = 1;
8838: }
8839: } else {
8840: $check_students = 0;
8841: }
8842: }
8843:
8844: if ($check_students) {
1.276 albertel 8845: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8846: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8847: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8848: my $start_index = &Apache::loncoursedata::CL_START();
8849: my $end_index = &Apache::loncoursedata::CL_END();
8850: my $status;
1.366 albertel 8851: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8852: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8853: $data->[$status_index],
8854: $data->[$start_index],
8855: $data->[$end_index]);
8856: if ($stu_status eq 'Active') {
8857: $status = 'active';
8858: } elsif ($end < $now) {
8859: $status = 'previous';
8860: } elsif ($start > $now) {
8861: $status = 'future';
8862: }
8863: if ($section ne '-1' && $section !~ /^\s*$/) {
8864: if ((!defined($possible_status)) || (($status ne '') &&
8865: (grep/^\Q$status\E$/,@{$possible_status}))) {
8866: $sectioncount{$section}++;
8867: }
1.240 albertel 8868: }
8869: }
8870: }
1.1118 raeburn 8871: if ($only_students) {
8872: return %sectioncount;
8873: }
1.240 albertel 8874: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8875: foreach my $user (sort(keys(%courseroles))) {
8876: if ($user !~ /^(\w{2})/) { next; }
8877: my ($role) = ($user =~ /^(\w{2})/);
8878: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8879: my ($section,$status);
1.240 albertel 8880: if ($role eq 'cr' &&
8881: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8882: $section=$1;
8883: }
8884: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8885: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8886: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8887: if ($end == -1 && $start == -1) {
8888: next; #deleted role
8889: }
8890: if (!defined($possible_status)) {
8891: $sectioncount{$section}++;
8892: } else {
8893: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8894: $status = 'active';
8895: } elsif ($end < $now) {
8896: $status = 'future';
8897: } elsif ($start > $now) {
8898: $status = 'previous';
8899: }
8900: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8901: $sectioncount{$section}++;
8902: }
8903: }
1.233 raeburn 8904: }
1.366 albertel 8905: return %sectioncount;
1.233 raeburn 8906: }
8907:
1.274 raeburn 8908: ###############################################
1.294 raeburn 8909:
8910: =pod
1.405 albertel 8911:
8912: =item * &get_course_users()
8913:
1.275 raeburn 8914: Retrieves usernames:domains for users in the specified course
8915: with specific role(s), and access status.
8916:
8917: Incoming parameters:
1.277 albertel 8918: 1. course domain
8919: 2. course number
8920: 3. access status: users must have - either active,
1.275 raeburn 8921: previous, future, or all.
1.277 albertel 8922: 4. reference to array of permissible roles
1.288 raeburn 8923: 5. reference to array of section restrictions (optional)
8924: 6. reference to results object (hash of hashes).
8925: 7. reference to optional userdata hash
1.609 raeburn 8926: 8. reference to optional statushash
1.630 raeburn 8927: 9. flag if privileged users (except those set to unhide in
8928: course settings) should be excluded
1.609 raeburn 8929: Keys of top level results hash are roles.
1.275 raeburn 8930: Keys of inner hashes are username:domain, with
8931: values set to access type.
1.288 raeburn 8932: Optional userdata hash returns an array with arguments in the
8933: same order as loncoursedata::get_classlist() for student data.
8934:
1.609 raeburn 8935: Optional statushash returns
8936:
1.288 raeburn 8937: Entries for end, start, section and status are blank because
8938: of the possibility of multiple values for non-student roles.
8939:
1.275 raeburn 8940: =cut
1.405 albertel 8941:
1.275 raeburn 8942: ###############################################
1.405 albertel 8943:
1.275 raeburn 8944: sub get_course_users {
1.630 raeburn 8945: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8946: my %idx = ();
1.419 raeburn 8947: my %seclists;
1.288 raeburn 8948:
8949: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8950: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8951: $idx{end} = &Apache::loncoursedata::CL_END();
8952: $idx{start} = &Apache::loncoursedata::CL_START();
8953: $idx{id} = &Apache::loncoursedata::CL_ID();
8954: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8955: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8956: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8957:
1.290 albertel 8958: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8959: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8960: my $now = time;
1.277 albertel 8961: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8962: my $match = 0;
1.412 raeburn 8963: my $secmatch = 0;
1.419 raeburn 8964: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8965: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8966: if ($section eq '') {
8967: $section = 'none';
8968: }
1.291 albertel 8969: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8970: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8971: $secmatch = 1;
8972: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8973: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8974: $secmatch = 1;
8975: }
8976: } else {
1.419 raeburn 8977: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8978: $secmatch = 1;
8979: }
1.290 albertel 8980: }
1.412 raeburn 8981: if (!$secmatch) {
8982: next;
8983: }
1.419 raeburn 8984: }
1.275 raeburn 8985: if (defined($$types{'active'})) {
1.288 raeburn 8986: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8987: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8988: $match = 1;
1.275 raeburn 8989: }
8990: }
8991: if (defined($$types{'previous'})) {
1.609 raeburn 8992: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8993: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8994: $match = 1;
1.275 raeburn 8995: }
8996: }
8997: if (defined($$types{'future'})) {
1.609 raeburn 8998: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8999: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9000: $match = 1;
1.275 raeburn 9001: }
9002: }
1.609 raeburn 9003: if ($match) {
9004: push(@{$seclists{$student}},$section);
9005: if (ref($userdata) eq 'HASH') {
9006: $$userdata{$student} = $$classlist{$student};
9007: }
9008: if (ref($statushash) eq 'HASH') {
9009: $statushash->{$student}{'st'}{$section} = $status;
9010: }
1.288 raeburn 9011: }
1.275 raeburn 9012: }
9013: }
1.412 raeburn 9014: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9015: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9016: my $now = time;
1.609 raeburn 9017: my %displaystatus = ( previous => 'Expired',
9018: active => 'Active',
9019: future => 'Future',
9020: );
1.1121 raeburn 9021: my (%nothide,@possdoms);
1.630 raeburn 9022: if ($hidepriv) {
9023: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9024: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9025: if ($user !~ /:/) {
9026: $nothide{join(':',split(/[\@]/,$user))}=1;
9027: } else {
9028: $nothide{$user} = 1;
9029: }
9030: }
1.1121 raeburn 9031: my @possdoms = ($cdom);
9032: if ($coursehash{'checkforpriv'}) {
9033: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9034: }
1.630 raeburn 9035: }
1.439 raeburn 9036: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9037: my $match = 0;
1.412 raeburn 9038: my $secmatch = 0;
1.439 raeburn 9039: my $status;
1.412 raeburn 9040: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9041: $user =~ s/:$//;
1.439 raeburn 9042: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9043: if ($end == -1 || $start == -1) {
9044: next;
9045: }
9046: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9047: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9048: my ($uname,$udom) = split(/:/,$user);
9049: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9050: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9051: $secmatch = 1;
9052: } elsif ($usec eq '') {
1.420 albertel 9053: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9054: $secmatch = 1;
9055: }
9056: } else {
9057: if (grep(/^\Q$usec\E$/,@{$sections})) {
9058: $secmatch = 1;
9059: }
9060: }
9061: if (!$secmatch) {
9062: next;
9063: }
1.288 raeburn 9064: }
1.419 raeburn 9065: if ($usec eq '') {
9066: $usec = 'none';
9067: }
1.275 raeburn 9068: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9069: if ($hidepriv) {
1.1121 raeburn 9070: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9071: (!$nothide{$uname.':'.$udom})) {
9072: next;
9073: }
9074: }
1.503 raeburn 9075: if ($end > 0 && $end < $now) {
1.439 raeburn 9076: $status = 'previous';
9077: } elsif ($start > $now) {
9078: $status = 'future';
9079: } else {
9080: $status = 'active';
9081: }
1.277 albertel 9082: foreach my $type (keys(%{$types})) {
1.275 raeburn 9083: if ($status eq $type) {
1.420 albertel 9084: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9085: push(@{$$users{$role}{$user}},$type);
9086: }
1.288 raeburn 9087: $match = 1;
9088: }
9089: }
1.419 raeburn 9090: if (($match) && (ref($userdata) eq 'HASH')) {
9091: if (!exists($$userdata{$uname.':'.$udom})) {
9092: &get_user_info($udom,$uname,\%idx,$userdata);
9093: }
1.420 albertel 9094: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9095: push(@{$seclists{$uname.':'.$udom}},$usec);
9096: }
1.609 raeburn 9097: if (ref($statushash) eq 'HASH') {
9098: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9099: }
1.275 raeburn 9100: }
9101: }
9102: }
9103: }
1.290 albertel 9104: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9105: if ((defined($cdom)) && (defined($cnum))) {
9106: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9107: if ( defined($csettings{'internal.courseowner'}) ) {
9108: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9109: next if ($owner eq '');
9110: my ($ownername,$ownerdom);
9111: if ($owner =~ /^([^:]+):([^:]+)$/) {
9112: $ownername = $1;
9113: $ownerdom = $2;
9114: } else {
9115: $ownername = $owner;
9116: $ownerdom = $cdom;
9117: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9118: }
9119: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9120: if (defined($userdata) &&
1.609 raeburn 9121: !exists($$userdata{$owner})) {
9122: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9123: if (!grep(/^none$/,@{$seclists{$owner}})) {
9124: push(@{$seclists{$owner}},'none');
9125: }
9126: if (ref($statushash) eq 'HASH') {
9127: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9128: }
1.290 albertel 9129: }
1.279 raeburn 9130: }
9131: }
9132: }
1.419 raeburn 9133: foreach my $user (keys(%seclists)) {
9134: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9135: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9136: }
1.275 raeburn 9137: }
9138: return;
9139: }
9140:
1.288 raeburn 9141: sub get_user_info {
9142: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9143: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9144: &plainname($uname,$udom,'lastname');
1.291 albertel 9145: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9146: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9147: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9148: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9149: return;
9150: }
1.275 raeburn 9151:
1.472 raeburn 9152: ###############################################
9153:
9154: =pod
9155:
9156: =item * &get_user_quota()
9157:
1.1134 raeburn 9158: Retrieves quota assigned for storage of user files.
9159: Default is to report quota for portfolio files.
1.472 raeburn 9160:
9161: Incoming parameters:
9162: 1. user's username
9163: 2. user's domain
1.1134 raeburn 9164: 3. quota name - portfolio, author, or course
1.1136 raeburn 9165: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 9166: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 9167: course
1.472 raeburn 9168:
9169: Returns:
1.1163 raeburn 9170: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9171: 2. (Optional) Type of setting: custom or default
9172: (individually assigned or default for user's
9173: institutional status).
9174: 3. (Optional) - User's institutional status (e.g., faculty, staff
9175: or student - types as defined in localenroll::inst_usertypes
9176: for user's domain, which determines default quota for user.
9177: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9178:
9179: If a value has been stored in the user's environment,
1.536 raeburn 9180: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9181: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9182:
9183: =cut
9184:
9185: ###############################################
9186:
9187:
9188: sub get_user_quota {
1.1136 raeburn 9189: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9190: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9191: if (!defined($udom)) {
9192: $udom = $env{'user.domain'};
9193: }
9194: if (!defined($uname)) {
9195: $uname = $env{'user.name'};
9196: }
9197: if (($udom eq '' || $uname eq '') ||
9198: ($udom eq 'public') && ($uname eq 'public')) {
9199: $quota = 0;
1.536 raeburn 9200: $quotatype = 'default';
9201: $defquota = 0;
1.472 raeburn 9202: } else {
1.536 raeburn 9203: my $inststatus;
1.1134 raeburn 9204: if ($quotaname eq 'course') {
9205: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9206: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9207: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9208: } else {
9209: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9210: $quota = $cenv{'internal.uploadquota'};
9211: }
1.536 raeburn 9212: } else {
1.1134 raeburn 9213: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9214: if ($quotaname eq 'author') {
9215: $quota = $env{'environment.authorquota'};
9216: } else {
9217: $quota = $env{'environment.portfolioquota'};
9218: }
9219: $inststatus = $env{'environment.inststatus'};
9220: } else {
9221: my %userenv =
9222: &Apache::lonnet::get('environment',['portfolioquota',
9223: 'authorquota','inststatus'],$udom,$uname);
9224: my ($tmp) = keys(%userenv);
9225: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9226: if ($quotaname eq 'author') {
9227: $quota = $userenv{'authorquota'};
9228: } else {
9229: $quota = $userenv{'portfolioquota'};
9230: }
9231: $inststatus = $userenv{'inststatus'};
9232: } else {
9233: undef(%userenv);
9234: }
9235: }
9236: }
9237: if ($quota eq '' || wantarray) {
9238: if ($quotaname eq 'course') {
9239: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9240: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9241: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 9242: $defquota = $domdefs{$crstype.'quota'};
9243: }
9244: if ($defquota eq '') {
9245: $defquota = 500;
9246: }
1.1134 raeburn 9247: } else {
9248: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9249: }
9250: if ($quota eq '') {
9251: $quota = $defquota;
9252: $quotatype = 'default';
9253: } else {
9254: $quotatype = 'custom';
9255: }
1.472 raeburn 9256: }
9257: }
1.536 raeburn 9258: if (wantarray) {
9259: return ($quota,$quotatype,$settingstatus,$defquota);
9260: } else {
9261: return $quota;
9262: }
1.472 raeburn 9263: }
9264:
9265: ###############################################
9266:
9267: =pod
9268:
9269: =item * &default_quota()
9270:
1.536 raeburn 9271: Retrieves default quota assigned for storage of user portfolio files,
9272: given an (optional) user's institutional status.
1.472 raeburn 9273:
9274: Incoming parameters:
1.1142 raeburn 9275:
1.472 raeburn 9276: 1. domain
1.536 raeburn 9277: 2. (Optional) institutional status(es). This is a : separated list of
9278: status types (e.g., faculty, staff, student etc.)
9279: which apply to the user for whom the default is being retrieved.
9280: If the institutional status string in undefined, the domain
1.1134 raeburn 9281: default quota will be returned.
9282: 3. quota name - portfolio, author, or course
9283: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9284:
9285: Returns:
1.1142 raeburn 9286:
1.1163 raeburn 9287: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9288: 2. (Optional) institutional type which determined the value of the
9289: default quota.
1.472 raeburn 9290:
9291: If a value has been stored in the domain's configuration db,
9292: it will return that, otherwise it returns 20 (for backwards
9293: compatibility with domains which have not set up a configuration
1.1163 raeburn 9294: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9295:
1.536 raeburn 9296: If the user's status includes multiple types (e.g., staff and student),
9297: the largest default quota which applies to the user determines the
9298: default quota returned.
9299:
1.472 raeburn 9300: =cut
9301:
9302: ###############################################
9303:
9304:
9305: sub default_quota {
1.1134 raeburn 9306: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9307: my ($defquota,$settingstatus);
9308: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9309: ['quotas'],$udom);
1.1134 raeburn 9310: my $key = 'defaultquota';
9311: if ($quotaname eq 'author') {
9312: $key = 'authorquota';
9313: }
1.622 raeburn 9314: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9315: if ($inststatus ne '') {
1.765 raeburn 9316: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9317: foreach my $item (@statuses) {
1.1134 raeburn 9318: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9319: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9320: if ($defquota eq '') {
1.1134 raeburn 9321: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9322: $settingstatus = $item;
1.1134 raeburn 9323: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9324: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9325: $settingstatus = $item;
9326: }
9327: }
1.1134 raeburn 9328: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9329: if ($quotahash{'quotas'}{$item} ne '') {
9330: if ($defquota eq '') {
9331: $defquota = $quotahash{'quotas'}{$item};
9332: $settingstatus = $item;
9333: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9334: $defquota = $quotahash{'quotas'}{$item};
9335: $settingstatus = $item;
9336: }
1.536 raeburn 9337: }
9338: }
9339: }
9340: }
9341: if ($defquota eq '') {
1.1134 raeburn 9342: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9343: $defquota = $quotahash{'quotas'}{$key}{'default'};
9344: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9345: $defquota = $quotahash{'quotas'}{'default'};
9346: }
1.536 raeburn 9347: $settingstatus = 'default';
1.1139 raeburn 9348: if ($defquota eq '') {
9349: if ($quotaname eq 'author') {
9350: $defquota = 500;
9351: }
9352: }
1.536 raeburn 9353: }
9354: } else {
9355: $settingstatus = 'default';
1.1134 raeburn 9356: if ($quotaname eq 'author') {
9357: $defquota = 500;
9358: } else {
9359: $defquota = 20;
9360: }
1.536 raeburn 9361: }
9362: if (wantarray) {
9363: return ($defquota,$settingstatus);
1.472 raeburn 9364: } else {
1.536 raeburn 9365: return $defquota;
1.472 raeburn 9366: }
9367: }
9368:
1.1135 raeburn 9369: ###############################################
9370:
9371: =pod
9372:
1.1136 raeburn 9373: =item * &excess_filesize_warning()
1.1135 raeburn 9374:
9375: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9376: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9377: space to be exceeded.
1.1136 raeburn 9378:
9379: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9380: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9381:
1.1165 raeburn 9382: Inputs: 7
1.1136 raeburn 9383: 1. username or coursenum
1.1135 raeburn 9384: 2. domain
1.1136 raeburn 9385: 3. context ('author' or 'course')
1.1135 raeburn 9386: 4. filename of file for which action is being requested
9387: 5. filesize (kB) of file
9388: 6. action being taken: copy or upload.
1.1165 raeburn 9389: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 9390:
9391: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9392: otherwise return null.
9393:
9394: =back
1.1135 raeburn 9395:
9396: =cut
9397:
1.1136 raeburn 9398: sub excess_filesize_warning {
1.1165 raeburn 9399: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9400: my $current_disk_usage = 0;
1.1165 raeburn 9401: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9402: if ($context eq 'author') {
9403: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9404: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9405: } else {
9406: foreach my $subdir ('docs','supplemental') {
9407: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9408: }
9409: }
1.1135 raeburn 9410: $disk_quota = int($disk_quota * 1000);
9411: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9412: return '<p class="LC_warning">'.
1.1135 raeburn 9413: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9414: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9415: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9416: $disk_quota,$current_disk_usage).
9417: '</p>';
9418: }
9419: return;
9420: }
9421:
9422: ###############################################
9423:
9424:
1.1136 raeburn 9425:
9426:
1.384 raeburn 9427: sub get_secgrprole_info {
9428: my ($cdom,$cnum,$needroles,$type) = @_;
9429: my %sections_count = &get_sections($cdom,$cnum);
9430: my @sections = (sort {$a <=> $b} keys(%sections_count));
9431: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9432: my @groups = sort(keys(%curr_groups));
9433: my $allroles = [];
9434: my $rolehash;
9435: my $accesshash = {
9436: active => 'Currently has access',
9437: future => 'Will have future access',
9438: previous => 'Previously had access',
9439: };
9440: if ($needroles) {
9441: $rolehash = {'all' => 'all'};
1.385 albertel 9442: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9443: if (&Apache::lonnet::error(%user_roles)) {
9444: undef(%user_roles);
9445: }
9446: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9447: my ($role)=split(/\:/,$item,2);
9448: if ($role eq 'cr') { next; }
9449: if ($role =~ /^cr/) {
9450: $$rolehash{$role} = (split('/',$role))[3];
9451: } else {
9452: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9453: }
9454: }
9455: foreach my $key (sort(keys(%{$rolehash}))) {
9456: push(@{$allroles},$key);
9457: }
9458: push (@{$allroles},'st');
9459: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9460: }
9461: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9462: }
9463:
1.555 raeburn 9464: sub user_picker {
1.994 raeburn 9465: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9466: my $currdom = $dom;
9467: my %curr_selected = (
9468: srchin => 'dom',
1.580 raeburn 9469: srchby => 'lastname',
1.555 raeburn 9470: );
9471: my $srchterm;
1.625 raeburn 9472: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9473: if ($srch->{'srchby'} ne '') {
9474: $curr_selected{'srchby'} = $srch->{'srchby'};
9475: }
9476: if ($srch->{'srchin'} ne '') {
9477: $curr_selected{'srchin'} = $srch->{'srchin'};
9478: }
9479: if ($srch->{'srchtype'} ne '') {
9480: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9481: }
9482: if ($srch->{'srchdomain'} ne '') {
9483: $currdom = $srch->{'srchdomain'};
9484: }
9485: $srchterm = $srch->{'srchterm'};
9486: }
9487: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9488: 'usr' => 'Search criteria',
1.563 raeburn 9489: 'doma' => 'Domain/institution to search',
1.558 albertel 9490: 'uname' => 'username',
9491: 'lastname' => 'last name',
1.555 raeburn 9492: 'lastfirst' => 'last name, first name',
1.558 albertel 9493: 'crs' => 'in this course',
1.576 raeburn 9494: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9495: 'alc' => 'all LON-CAPA',
1.573 raeburn 9496: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9497: 'exact' => 'is',
9498: 'contains' => 'contains',
1.569 raeburn 9499: 'begins' => 'begins with',
1.571 raeburn 9500: 'youm' => "You must include some text to search for.",
9501: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9502: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9503: 'yomc' => "You must choose a domain when using an institutional directory search.",
9504: 'ymcd' => "You must choose a domain when using a domain search.",
9505: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9506: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9507: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9508: );
1.563 raeburn 9509: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9510: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9511:
9512: my @srchins = ('crs','dom','alc','instd');
9513:
9514: foreach my $option (@srchins) {
9515: # FIXME 'alc' option unavailable until
9516: # loncreateuser::print_user_query_page()
9517: # has been completed.
9518: next if ($option eq 'alc');
1.880 raeburn 9519: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9520: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9521: if ($curr_selected{'srchin'} eq $option) {
9522: $srchinsel .= '
9523: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9524: } else {
9525: $srchinsel .= '
9526: <option value="'.$option.'">'.$lt{$option}.'</option>';
9527: }
1.555 raeburn 9528: }
1.563 raeburn 9529: $srchinsel .= "\n </select>\n";
1.555 raeburn 9530:
9531: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9532: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9533: if ($curr_selected{'srchby'} eq $option) {
9534: $srchbysel .= '
9535: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9536: } else {
9537: $srchbysel .= '
9538: <option value="'.$option.'">'.$lt{$option}.'</option>';
9539: }
9540: }
9541: $srchbysel .= "\n </select>\n";
9542:
9543: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9544: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9545: if ($curr_selected{'srchtype'} eq $option) {
9546: $srchtypesel .= '
9547: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9548: } else {
9549: $srchtypesel .= '
9550: <option value="'.$option.'">'.$lt{$option}.'</option>';
9551: }
9552: }
9553: $srchtypesel .= "\n </select>\n";
9554:
1.558 albertel 9555: my ($newuserscript,$new_user_create);
1.994 raeburn 9556: my $context_dom = $env{'request.role.domain'};
9557: if ($context eq 'requestcrs') {
9558: if ($env{'form.coursedom'} ne '') {
9559: $context_dom = $env{'form.coursedom'};
9560: }
9561: }
1.556 raeburn 9562: if ($forcenewuser) {
1.576 raeburn 9563: if (ref($srch) eq 'HASH') {
1.994 raeburn 9564: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9565: if ($cancreate) {
9566: $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>';
9567: } else {
1.799 bisitz 9568: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9569: my %usertypetext = (
9570: official => 'institutional',
9571: unofficial => 'non-institutional',
9572: );
1.799 bisitz 9573: $new_user_create = '<p class="LC_warning">'
9574: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9575: .' '
9576: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9577: ,'<a href="'.$helplink.'">','</a>')
9578: .'</p><br />';
1.627 raeburn 9579: }
1.576 raeburn 9580: }
9581: }
9582:
1.556 raeburn 9583: $newuserscript = <<"ENDSCRIPT";
9584:
1.570 raeburn 9585: function setSearch(createnew,callingForm) {
1.556 raeburn 9586: if (createnew == 1) {
1.570 raeburn 9587: for (var i=0; i<callingForm.srchby.length; i++) {
9588: if (callingForm.srchby.options[i].value == 'uname') {
9589: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9590: }
9591: }
1.570 raeburn 9592: for (var i=0; i<callingForm.srchin.length; i++) {
9593: if ( callingForm.srchin.options[i].value == 'dom') {
9594: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9595: }
9596: }
1.570 raeburn 9597: for (var i=0; i<callingForm.srchtype.length; i++) {
9598: if (callingForm.srchtype.options[i].value == 'exact') {
9599: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9600: }
9601: }
1.570 raeburn 9602: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9603: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9604: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9605: }
9606: }
9607: }
9608: }
9609: ENDSCRIPT
1.558 albertel 9610:
1.556 raeburn 9611: }
9612:
1.555 raeburn 9613: my $output = <<"END_BLOCK";
1.556 raeburn 9614: <script type="text/javascript">
1.824 bisitz 9615: // <![CDATA[
1.570 raeburn 9616: function validateEntry(callingForm) {
1.558 albertel 9617:
1.556 raeburn 9618: var checkok = 1;
1.558 albertel 9619: var srchin;
1.570 raeburn 9620: for (var i=0; i<callingForm.srchin.length; i++) {
9621: if ( callingForm.srchin[i].checked ) {
9622: srchin = callingForm.srchin[i].value;
1.558 albertel 9623: }
9624: }
9625:
1.570 raeburn 9626: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9627: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9628: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9629: var srchterm = callingForm.srchterm.value;
9630: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9631: var msg = "";
9632:
9633: if (srchterm == "") {
9634: checkok = 0;
1.571 raeburn 9635: msg += "$lt{'youm'}\\n";
1.556 raeburn 9636: }
9637:
1.569 raeburn 9638: if (srchtype== 'begins') {
9639: if (srchterm.length < 2) {
9640: checkok = 0;
1.571 raeburn 9641: msg += "$lt{'thte'}\\n";
1.569 raeburn 9642: }
9643: }
9644:
1.556 raeburn 9645: if (srchtype== 'contains') {
9646: if (srchterm.length < 3) {
9647: checkok = 0;
1.571 raeburn 9648: msg += "$lt{'thet'}\\n";
1.556 raeburn 9649: }
9650: }
9651: if (srchin == 'instd') {
9652: if (srchdomain == '') {
9653: checkok = 0;
1.571 raeburn 9654: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9655: }
9656: }
9657: if (srchin == 'dom') {
9658: if (srchdomain == '') {
9659: checkok = 0;
1.571 raeburn 9660: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9661: }
9662: }
9663: if (srchby == 'lastfirst') {
9664: if (srchterm.indexOf(",") == -1) {
9665: checkok = 0;
1.571 raeburn 9666: msg += "$lt{'whus'}\\n";
1.556 raeburn 9667: }
9668: if (srchterm.indexOf(",") == srchterm.length -1) {
9669: checkok = 0;
1.571 raeburn 9670: msg += "$lt{'whse'}\\n";
1.556 raeburn 9671: }
9672: }
9673: if (checkok == 0) {
1.571 raeburn 9674: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9675: return;
9676: }
9677: if (checkok == 1) {
1.570 raeburn 9678: callingForm.submit();
1.556 raeburn 9679: }
9680: }
9681:
9682: $newuserscript
9683:
1.824 bisitz 9684: // ]]>
1.556 raeburn 9685: </script>
1.558 albertel 9686:
9687: $new_user_create
9688:
1.555 raeburn 9689: END_BLOCK
1.558 albertel 9690:
1.876 raeburn 9691: $output .= &Apache::lonhtmlcommon::start_pick_box().
9692: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9693: $domform.
9694: &Apache::lonhtmlcommon::row_closure().
9695: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9696: $srchbysel.
9697: $srchtypesel.
9698: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9699: $srchinsel.
9700: &Apache::lonhtmlcommon::row_closure(1).
9701: &Apache::lonhtmlcommon::end_pick_box().
9702: '<br />';
1.555 raeburn 9703: return $output;
9704: }
9705:
1.612 raeburn 9706: sub user_rule_check {
1.615 raeburn 9707: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9708: my $response;
9709: if (ref($usershash) eq 'HASH') {
9710: foreach my $user (keys(%{$usershash})) {
9711: my ($uname,$udom) = split(/:/,$user);
9712: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9713: my ($id,$newuser);
1.612 raeburn 9714: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9715: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9716: $id = $usershash->{$user}->{'id'};
9717: }
9718: my $inst_response;
9719: if (ref($checks) eq 'HASH') {
9720: if (defined($checks->{'username'})) {
1.615 raeburn 9721: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9722: &Apache::lonnet::get_instuser($udom,$uname);
9723: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9724: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9725: &Apache::lonnet::get_instuser($udom,undef,$id);
9726: }
1.615 raeburn 9727: } else {
9728: ($inst_response,%{$inst_results->{$user}}) =
9729: &Apache::lonnet::get_instuser($udom,$uname);
9730: return;
1.612 raeburn 9731: }
1.615 raeburn 9732: if (!$got_rules->{$udom}) {
1.612 raeburn 9733: my %domconfig = &Apache::lonnet::get_dom('configuration',
9734: ['usercreation'],$udom);
9735: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9736: foreach my $item ('username','id') {
1.612 raeburn 9737: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9738: $$curr_rules{$udom}{$item} =
9739: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9740: }
9741: }
9742: }
1.615 raeburn 9743: $got_rules->{$udom} = 1;
1.585 raeburn 9744: }
1.612 raeburn 9745: foreach my $item (keys(%{$checks})) {
9746: if (ref($$curr_rules{$udom}) eq 'HASH') {
9747: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9748: if (@{$$curr_rules{$udom}{$item}} > 0) {
9749: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9750: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9751: if ($rule_check{$rule}) {
9752: $$rulematch{$user}{$item} = $rule;
9753: if ($inst_response eq 'ok') {
1.615 raeburn 9754: if (ref($inst_results) eq 'HASH') {
9755: if (ref($inst_results->{$user}) eq 'HASH') {
9756: if (keys(%{$inst_results->{$user}}) == 0) {
9757: $$alerts{$item}{$udom}{$uname} = 1;
9758: }
1.612 raeburn 9759: }
9760: }
1.615 raeburn 9761: }
9762: last;
1.585 raeburn 9763: }
9764: }
9765: }
9766: }
9767: }
9768: }
9769: }
9770: }
1.612 raeburn 9771: return;
9772: }
9773:
9774: sub user_rule_formats {
9775: my ($domain,$domdesc,$curr_rules,$check) = @_;
9776: my %text = (
9777: 'username' => 'Usernames',
9778: 'id' => 'IDs',
9779: );
9780: my $output;
9781: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9782: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9783: if (@{$ruleorder} > 0) {
1.1102 raeburn 9784: $output = '<br />'.
9785: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9786: '<span class="LC_cusr_emph">','</span>',$domdesc).
9787: ' <ul>';
1.612 raeburn 9788: foreach my $rule (@{$ruleorder}) {
9789: if (ref($curr_rules) eq 'ARRAY') {
9790: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9791: if (ref($rules->{$rule}) eq 'HASH') {
9792: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9793: $rules->{$rule}{'desc'}.'</li>';
9794: }
9795: }
9796: }
9797: }
9798: $output .= '</ul>';
9799: }
9800: }
9801: return $output;
9802: }
9803:
9804: sub instrule_disallow_msg {
1.615 raeburn 9805: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9806: my $response;
9807: my %text = (
9808: item => 'username',
9809: items => 'usernames',
9810: match => 'matches',
9811: do => 'does',
9812: action => 'a username',
9813: one => 'one',
9814: );
9815: if ($count > 1) {
9816: $text{'item'} = 'usernames';
9817: $text{'match'} ='match';
9818: $text{'do'} = 'do';
9819: $text{'action'} = 'usernames',
9820: $text{'one'} = 'ones';
9821: }
9822: if ($checkitem eq 'id') {
9823: $text{'items'} = 'IDs';
9824: $text{'item'} = 'ID';
9825: $text{'action'} = 'an ID';
1.615 raeburn 9826: if ($count > 1) {
9827: $text{'item'} = 'IDs';
9828: $text{'action'} = 'IDs';
9829: }
1.612 raeburn 9830: }
1.674 bisitz 9831: $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 9832: if ($mode eq 'upload') {
9833: if ($checkitem eq 'username') {
9834: $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'}.");
9835: } elsif ($checkitem eq 'id') {
1.674 bisitz 9836: $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 9837: }
1.669 raeburn 9838: } elsif ($mode eq 'selfcreate') {
9839: if ($checkitem eq 'id') {
9840: $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.");
9841: }
1.615 raeburn 9842: } else {
9843: if ($checkitem eq 'username') {
9844: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9845: } elsif ($checkitem eq 'id') {
9846: $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.");
9847: }
1.612 raeburn 9848: }
9849: return $response;
1.585 raeburn 9850: }
9851:
1.624 raeburn 9852: sub personal_data_fieldtitles {
9853: my %fieldtitles = &Apache::lonlocal::texthash (
9854: id => 'Student/Employee ID',
9855: permanentemail => 'E-mail address',
9856: lastname => 'Last Name',
9857: firstname => 'First Name',
9858: middlename => 'Middle Name',
9859: generation => 'Generation',
9860: gen => 'Generation',
1.765 raeburn 9861: inststatus => 'Affiliation',
1.624 raeburn 9862: );
9863: return %fieldtitles;
9864: }
9865:
1.642 raeburn 9866: sub sorted_inst_types {
9867: my ($dom) = @_;
1.1185 raeburn 9868: my ($usertypes,$order);
9869: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9870: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9871: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9872: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9873: } else {
9874: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9875: }
1.642 raeburn 9876: my $othertitle = &mt('All users');
9877: if ($env{'request.course.id'}) {
1.668 raeburn 9878: $othertitle = &mt('Any users');
1.642 raeburn 9879: }
9880: my @types;
9881: if (ref($order) eq 'ARRAY') {
9882: @types = @{$order};
9883: }
9884: if (@types == 0) {
9885: if (ref($usertypes) eq 'HASH') {
9886: @types = sort(keys(%{$usertypes}));
9887: }
9888: }
9889: if (keys(%{$usertypes}) > 0) {
9890: $othertitle = &mt('Other users');
9891: }
9892: return ($othertitle,$usertypes,\@types);
9893: }
9894:
1.645 raeburn 9895: sub get_institutional_codes {
9896: my ($settings,$allcourses,$LC_code) = @_;
9897: # Get complete list of course sections to update
9898: my @currsections = ();
9899: my @currxlists = ();
9900: my $coursecode = $$settings{'internal.coursecode'};
9901:
9902: if ($$settings{'internal.sectionnums'} ne '') {
9903: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9904: }
9905:
9906: if ($$settings{'internal.crosslistings'} ne '') {
9907: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9908: }
9909:
9910: if (@currxlists > 0) {
9911: foreach (@currxlists) {
9912: if (m/^([^:]+):(\w*)$/) {
9913: unless (grep/^$1$/,@{$allcourses}) {
9914: push @{$allcourses},$1;
9915: $$LC_code{$1} = $2;
9916: }
9917: }
9918: }
9919: }
9920:
9921: if (@currsections > 0) {
9922: foreach (@currsections) {
9923: if (m/^(\w+):(\w*)$/) {
9924: my $sec = $coursecode.$1;
9925: my $lc_sec = $2;
9926: unless (grep/^$sec$/,@{$allcourses}) {
9927: push @{$allcourses},$sec;
9928: $$LC_code{$sec} = $lc_sec;
9929: }
9930: }
9931: }
9932: }
9933: return;
9934: }
9935:
1.971 raeburn 9936: sub get_standard_codeitems {
9937: return ('Year','Semester','Department','Number','Section');
9938: }
9939:
1.112 bowersj2 9940: =pod
9941:
1.780 raeburn 9942: =head1 Slot Helpers
9943:
9944: =over 4
9945:
9946: =item * sorted_slots()
9947:
1.1040 raeburn 9948: Sorts an array of slot names in order of an optional sort key,
9949: default sort is by slot start time (earliest first).
1.780 raeburn 9950:
9951: Inputs:
9952:
9953: =over 4
9954:
9955: slotsarr - Reference to array of unsorted slot names.
9956:
9957: slots - Reference to hash of hash, where outer hash keys are slot names.
9958:
1.1040 raeburn 9959: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9960:
1.549 albertel 9961: =back
9962:
1.780 raeburn 9963: Returns:
9964:
9965: =over 4
9966:
1.1040 raeburn 9967: sorted - An array of slot names sorted by a specified sort key
9968: (default sort key is start time of the slot).
1.780 raeburn 9969:
9970: =back
9971:
9972: =cut
9973:
9974:
9975: sub sorted_slots {
1.1040 raeburn 9976: my ($slotsarr,$slots,$sortkey) = @_;
9977: if ($sortkey eq '') {
9978: $sortkey = 'starttime';
9979: }
1.780 raeburn 9980: my @sorted;
9981: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9982: @sorted =
9983: sort {
9984: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9985: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9986: }
9987: if (ref($slots->{$a})) { return -1;}
9988: if (ref($slots->{$b})) { return 1;}
9989: return 0;
9990: } @{$slotsarr};
9991: }
9992: return @sorted;
9993: }
9994:
1.1040 raeburn 9995: =pod
9996:
9997: =item * get_future_slots()
9998:
9999: Inputs:
10000:
10001: =over 4
10002:
10003: cnum - course number
10004:
10005: cdom - course domain
10006:
10007: now - current UNIX time
10008:
10009: symb - optional symb
10010:
10011: =back
10012:
10013: Returns:
10014:
10015: =over 4
10016:
10017: sorted_reservable - ref to array of student_schedulable slots currently
10018: reservable, ordered by end date of reservation period.
10019:
10020: reservable_now - ref to hash of student_schedulable slots currently
10021: reservable.
10022:
10023: Keys in inner hash are:
10024: (a) symb: either blank or symb to which slot use is restricted.
10025: (b) endreserve: end date of reservation period.
10026:
10027: sorted_future - ref to array of student_schedulable slots reservable in
10028: the future, ordered by start date of reservation period.
10029:
10030: future_reservable - ref to hash of student_schedulable slots reservable
10031: in the future.
10032:
10033: Keys in inner hash are:
10034: (a) symb: either blank or symb to which slot use is restricted.
10035: (b) startreserve: start date of reservation period.
10036:
10037: =back
10038:
10039: =cut
10040:
10041: sub get_future_slots {
10042: my ($cnum,$cdom,$now,$symb) = @_;
10043: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10044: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10045: foreach my $slot (keys(%slots)) {
10046: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10047: if ($symb) {
10048: next if (($slots{$slot}->{'symb'} ne '') &&
10049: ($slots{$slot}->{'symb'} ne $symb));
10050: }
10051: if (($slots{$slot}->{'starttime'} > $now) &&
10052: ($slots{$slot}->{'endtime'} > $now)) {
10053: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10054: my $userallowed = 0;
10055: if ($slots{$slot}->{'allowedsections'}) {
10056: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10057: if (!defined($env{'request.role.sec'})
10058: && grep(/^No section assigned$/,@allowed_sec)) {
10059: $userallowed=1;
10060: } else {
10061: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10062: $userallowed=1;
10063: }
10064: }
10065: unless ($userallowed) {
10066: if (defined($env{'request.course.groups'})) {
10067: my @groups = split(/:/,$env{'request.course.groups'});
10068: foreach my $group (@groups) {
10069: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10070: $userallowed=1;
10071: last;
10072: }
10073: }
10074: }
10075: }
10076: }
10077: if ($slots{$slot}->{'allowedusers'}) {
10078: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10079: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10080: if (grep(/^\Q$user\E$/,@allowed_users)) {
10081: $userallowed = 1;
10082: }
10083: }
10084: next unless($userallowed);
10085: }
10086: my $startreserve = $slots{$slot}->{'startreserve'};
10087: my $endreserve = $slots{$slot}->{'endreserve'};
10088: my $symb = $slots{$slot}->{'symb'};
10089: if (($startreserve < $now) &&
10090: (!$endreserve || $endreserve > $now)) {
10091: my $lastres = $endreserve;
10092: if (!$lastres) {
10093: $lastres = $slots{$slot}->{'starttime'};
10094: }
10095: $reservable_now{$slot} = {
10096: symb => $symb,
10097: endreserve => $lastres
10098: };
10099: } elsif (($startreserve > $now) &&
10100: (!$endreserve || $endreserve > $startreserve)) {
10101: $future_reservable{$slot} = {
10102: symb => $symb,
10103: startreserve => $startreserve
10104: };
10105: }
10106: }
10107: }
10108: my @unsorted_reservable = keys(%reservable_now);
10109: if (@unsorted_reservable > 0) {
10110: @sorted_reservable =
10111: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10112: }
10113: my @unsorted_future = keys(%future_reservable);
10114: if (@unsorted_future > 0) {
10115: @sorted_future =
10116: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10117: }
10118: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10119: }
1.780 raeburn 10120:
10121: =pod
10122:
1.1057 foxr 10123: =back
10124:
1.549 albertel 10125: =head1 HTTP Helpers
10126:
10127: =over 4
10128:
1.648 raeburn 10129: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10130:
1.258 albertel 10131: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10132: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10133: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10134:
10135: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10136: $possible_names is an ref to an array of form element names. As an example:
10137: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10138: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10139:
10140: =cut
1.1 albertel 10141:
1.6 albertel 10142: sub get_unprocessed_cgi {
1.25 albertel 10143: my ($query,$possible_names)= @_;
1.26 matthew 10144: # $Apache::lonxml::debug=1;
1.356 albertel 10145: foreach my $pair (split(/&/,$query)) {
10146: my ($name, $value) = split(/=/,$pair);
1.369 www 10147: $name = &unescape($name);
1.25 albertel 10148: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10149: $value =~ tr/+/ /;
10150: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10151: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10152: }
1.16 harris41 10153: }
1.6 albertel 10154: }
10155:
1.112 bowersj2 10156: =pod
10157:
1.648 raeburn 10158: =item * &cacheheader()
1.112 bowersj2 10159:
10160: returns cache-controlling header code
10161:
10162: =cut
10163:
1.7 albertel 10164: sub cacheheader {
1.258 albertel 10165: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10166: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10167: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10168: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10169: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10170: return $output;
1.7 albertel 10171: }
10172:
1.112 bowersj2 10173: =pod
10174:
1.648 raeburn 10175: =item * &no_cache($r)
1.112 bowersj2 10176:
10177: specifies header code to not have cache
10178:
10179: =cut
10180:
1.9 albertel 10181: sub no_cache {
1.216 albertel 10182: my ($r) = @_;
10183: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10184: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10185: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10186: $r->no_cache(1);
10187: $r->header_out("Expires" => $date);
10188: $r->header_out("Pragma" => "no-cache");
1.123 www 10189: }
10190:
10191: sub content_type {
1.181 albertel 10192: my ($r,$type,$charset) = @_;
1.299 foxr 10193: if ($r) {
10194: # Note that printout.pl calls this with undef for $r.
10195: &no_cache($r);
10196: }
1.258 albertel 10197: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10198: unless ($charset) {
10199: $charset=&Apache::lonlocal::current_encoding;
10200: }
10201: if ($charset) { $type.='; charset='.$charset; }
10202: if ($r) {
10203: $r->content_type($type);
10204: } else {
10205: print("Content-type: $type\n\n");
10206: }
1.9 albertel 10207: }
1.25 albertel 10208:
1.112 bowersj2 10209: =pod
10210:
1.648 raeburn 10211: =item * &add_to_env($name,$value)
1.112 bowersj2 10212:
1.258 albertel 10213: adds $name to the %env hash with value
1.112 bowersj2 10214: $value, if $name already exists, the entry is converted to an array
10215: reference and $value is added to the array.
10216:
10217: =cut
10218:
1.25 albertel 10219: sub add_to_env {
10220: my ($name,$value)=@_;
1.258 albertel 10221: if (defined($env{$name})) {
10222: if (ref($env{$name})) {
1.25 albertel 10223: #already have multiple values
1.258 albertel 10224: push(@{ $env{$name} },$value);
1.25 albertel 10225: } else {
10226: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10227: my $first=$env{$name};
10228: undef($env{$name});
10229: push(@{ $env{$name} },$first,$value);
1.25 albertel 10230: }
10231: } else {
1.258 albertel 10232: $env{$name}=$value;
1.25 albertel 10233: }
1.31 albertel 10234: }
1.149 albertel 10235:
10236: =pod
10237:
1.648 raeburn 10238: =item * &get_env_multiple($name)
1.149 albertel 10239:
1.258 albertel 10240: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10241: values may be defined and end up as an array ref.
10242:
10243: returns an array of values
10244:
10245: =cut
10246:
10247: sub get_env_multiple {
10248: my ($name) = @_;
10249: my @values;
1.258 albertel 10250: if (defined($env{$name})) {
1.149 albertel 10251: # exists is it an array
1.258 albertel 10252: if (ref($env{$name})) {
10253: @values=@{ $env{$name} };
1.149 albertel 10254: } else {
1.258 albertel 10255: $values[0]=$env{$name};
1.149 albertel 10256: }
10257: }
10258: return(@values);
10259: }
10260:
1.660 raeburn 10261: sub ask_for_embedded_content {
10262: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10263: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10264: %currsubfile,%unused,$rem);
1.1071 raeburn 10265: my $counter = 0;
10266: my $numnew = 0;
1.987 raeburn 10267: my $numremref = 0;
10268: my $numinvalid = 0;
10269: my $numpathchg = 0;
10270: my $numexisting = 0;
1.1071 raeburn 10271: my $numunused = 0;
10272: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10273: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10274: my $heading = &mt('Upload embedded files');
10275: my $buttontext = &mt('Upload');
10276:
1.1085 raeburn 10277: if ($env{'request.course.id'}) {
1.1123 raeburn 10278: if ($actionurl eq '/adm/dependencies') {
10279: $navmap = Apache::lonnavmaps::navmap->new();
10280: }
10281: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10282: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10283: }
1.1123 raeburn 10284: if (($actionurl eq '/adm/portfolio') ||
10285: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10286: my $current_path='/';
10287: if ($env{'form.currentpath'}) {
10288: $current_path = $env{'form.currentpath'};
10289: }
10290: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10291: $udom = $cdom;
10292: $uname = $cnum;
1.984 raeburn 10293: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10294: } else {
10295: $udom = $env{'user.domain'};
10296: $uname = $env{'user.name'};
10297: $url = '/userfiles/portfolio';
10298: }
1.987 raeburn 10299: $toplevel = $url.'/';
1.984 raeburn 10300: $url .= $current_path;
10301: $getpropath = 1;
1.987 raeburn 10302: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10303: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10304: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10305: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10306: $toplevel = $url;
1.984 raeburn 10307: if ($rest ne '') {
1.987 raeburn 10308: $url .= $rest;
10309: }
10310: } elsif ($actionurl eq '/adm/coursedocs') {
10311: if (ref($args) eq 'HASH') {
1.1071 raeburn 10312: $url = $args->{'docs_url'};
10313: $toplevel = $url;
1.1084 raeburn 10314: if ($args->{'context'} eq 'paste') {
10315: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10316: ($path) =
10317: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10318: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10319: $fileloc =~ s{^/}{};
10320: }
1.1071 raeburn 10321: }
1.1084 raeburn 10322: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 10323: if ($env{'request.course.id'} ne '') {
10324: if (ref($args) eq 'HASH') {
10325: $url = $args->{'docs_url'};
10326: $title = $args->{'docs_title'};
1.1126 raeburn 10327: $toplevel = $url;
10328: unless ($toplevel =~ m{^/}) {
10329: $toplevel = "/$url";
10330: }
1.1085 raeburn 10331: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 10332: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10333: $path = $1;
10334: } else {
10335: ($path) =
10336: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10337: }
1.1195 raeburn 10338: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10339: $fileloc = $toplevel;
10340: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10341: my ($udom,$uname,$fname) =
10342: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10343: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10344: } else {
10345: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10346: }
1.1071 raeburn 10347: $fileloc =~ s{^/}{};
10348: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10349: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10350: }
1.987 raeburn 10351: }
1.1123 raeburn 10352: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10353: $udom = $cdom;
10354: $uname = $cnum;
10355: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10356: $toplevel = $url;
10357: $path = $url;
10358: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10359: $fileloc =~ s{^/}{};
1.987 raeburn 10360: }
1.1126 raeburn 10361: foreach my $file (keys(%{$allfiles})) {
10362: my $embed_file;
10363: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10364: $embed_file = $1;
10365: } else {
10366: $embed_file = $file;
10367: }
1.1158 raeburn 10368: my ($absolutepath,$cleaned_file);
10369: if ($embed_file =~ m{^\w+://}) {
10370: $cleaned_file = $embed_file;
1.1147 raeburn 10371: $newfiles{$cleaned_file} = 1;
10372: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10373: } else {
1.1158 raeburn 10374: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10375: if ($embed_file =~ m{^/}) {
10376: $absolutepath = $embed_file;
10377: }
1.1147 raeburn 10378: if ($cleaned_file =~ m{/}) {
10379: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10380: $path = &check_for_traversal($path,$url,$toplevel);
10381: my $item = $fname;
10382: if ($path ne '') {
10383: $item = $path.'/'.$fname;
10384: $subdependencies{$path}{$fname} = 1;
10385: } else {
10386: $dependencies{$item} = 1;
10387: }
10388: if ($absolutepath) {
10389: $mapping{$item} = $absolutepath;
10390: } else {
10391: $mapping{$item} = $embed_file;
10392: }
10393: } else {
10394: $dependencies{$embed_file} = 1;
10395: if ($absolutepath) {
1.1147 raeburn 10396: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10397: } else {
1.1147 raeburn 10398: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10399: }
10400: }
1.984 raeburn 10401: }
10402: }
1.1071 raeburn 10403: my $dirptr = 16384;
1.984 raeburn 10404: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10405: $currsubfile{$path} = {};
1.1123 raeburn 10406: if (($actionurl eq '/adm/portfolio') ||
10407: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10408: my ($sublistref,$listerror) =
10409: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10410: if (ref($sublistref) eq 'ARRAY') {
10411: foreach my $line (@{$sublistref}) {
10412: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10413: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10414: }
1.984 raeburn 10415: }
1.987 raeburn 10416: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10417: if (opendir(my $dir,$url.'/'.$path)) {
10418: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10419: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10420: }
1.1084 raeburn 10421: } elsif (($actionurl eq '/adm/dependencies') ||
10422: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10423: ($args->{'context'} eq 'paste')) ||
10424: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10425: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 10426: my $dir;
10427: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10428: $dir = $fileloc;
10429: } else {
10430: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10431: }
1.1071 raeburn 10432: if ($dir ne '') {
10433: my ($sublistref,$listerror) =
10434: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10435: if (ref($sublistref) eq 'ARRAY') {
10436: foreach my $line (@{$sublistref}) {
10437: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10438: undef,$mtime)=split(/\&/,$line,12);
10439: unless (($testdir&$dirptr) ||
10440: ($file_name =~ /^\.\.?$/)) {
10441: $currsubfile{$path}{$file_name} = [$size,$mtime];
10442: }
10443: }
10444: }
10445: }
1.984 raeburn 10446: }
10447: }
10448: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10449: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10450: my $item = $path.'/'.$file;
10451: unless ($mapping{$item} eq $item) {
10452: $pathchanges{$item} = 1;
10453: }
10454: $existing{$item} = 1;
10455: $numexisting ++;
10456: } else {
10457: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10458: }
10459: }
1.1071 raeburn 10460: if ($actionurl eq '/adm/dependencies') {
10461: foreach my $path (keys(%currsubfile)) {
10462: if (ref($currsubfile{$path}) eq 'HASH') {
10463: foreach my $file (keys(%{$currsubfile{$path}})) {
10464: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10465: next if (($rem ne '') &&
10466: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10467: (ref($navmap) &&
10468: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10469: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10470: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10471: $unused{$path.'/'.$file} = 1;
10472: }
10473: }
10474: }
10475: }
10476: }
1.984 raeburn 10477: }
1.987 raeburn 10478: my %currfile;
1.1123 raeburn 10479: if (($actionurl eq '/adm/portfolio') ||
10480: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10481: my ($dirlistref,$listerror) =
10482: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10483: if (ref($dirlistref) eq 'ARRAY') {
10484: foreach my $line (@{$dirlistref}) {
10485: my ($file_name,$rest) = split(/\&/,$line,2);
10486: $currfile{$file_name} = 1;
10487: }
1.984 raeburn 10488: }
1.987 raeburn 10489: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10490: if (opendir(my $dir,$url)) {
1.987 raeburn 10491: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10492: map {$currfile{$_} = 1;} @dir_list;
10493: }
1.1084 raeburn 10494: } elsif (($actionurl eq '/adm/dependencies') ||
10495: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10496: ($args->{'context'} eq 'paste')) ||
10497: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10498: if ($env{'request.course.id'} ne '') {
10499: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10500: if ($dir ne '') {
10501: my ($dirlistref,$listerror) =
10502: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10503: if (ref($dirlistref) eq 'ARRAY') {
10504: foreach my $line (@{$dirlistref}) {
10505: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10506: $size,undef,$mtime)=split(/\&/,$line,12);
10507: unless (($testdir&$dirptr) ||
10508: ($file_name =~ /^\.\.?$/)) {
10509: $currfile{$file_name} = [$size,$mtime];
10510: }
10511: }
10512: }
10513: }
10514: }
1.984 raeburn 10515: }
10516: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10517: if (exists($currfile{$file})) {
1.987 raeburn 10518: unless ($mapping{$file} eq $file) {
10519: $pathchanges{$file} = 1;
10520: }
10521: $existing{$file} = 1;
10522: $numexisting ++;
10523: } else {
1.984 raeburn 10524: $newfiles{$file} = 1;
10525: }
10526: }
1.1071 raeburn 10527: foreach my $file (keys(%currfile)) {
10528: unless (($file eq $filename) ||
10529: ($file eq $filename.'.bak') ||
10530: ($dependencies{$file})) {
1.1085 raeburn 10531: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10532: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10533: next if (($rem ne '') &&
10534: (($env{"httpref.$rem".$file} ne '') ||
10535: (ref($navmap) &&
10536: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10537: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10538: ($navmap->getResourceByUrl($rem.$1)))))));
10539: }
1.1085 raeburn 10540: }
1.1071 raeburn 10541: $unused{$file} = 1;
10542: }
10543: }
1.1084 raeburn 10544: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10545: ($args->{'context'} eq 'paste')) {
10546: $counter = scalar(keys(%existing));
10547: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10548: return ($output,$counter,$numpathchg,\%existing);
10549: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10550: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10551: $counter = scalar(keys(%existing));
10552: $numpathchg = scalar(keys(%pathchanges));
10553: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10554: }
1.984 raeburn 10555: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10556: if ($actionurl eq '/adm/dependencies') {
10557: next if ($embed_file =~ m{^\w+://});
10558: }
1.660 raeburn 10559: $upload_output .= &start_data_table_row().
1.1123 raeburn 10560: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10561: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10562: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10563: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10564: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10565: }
1.1123 raeburn 10566: $upload_output .= '</td>';
1.1071 raeburn 10567: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10568: $upload_output.='<td align="right">'.
10569: '<span class="LC_info LC_fontsize_medium">'.
10570: &mt("URL points to web address").'</span>';
1.987 raeburn 10571: $numremref++;
1.660 raeburn 10572: } elsif ($args->{'error_on_invalid_names'}
10573: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10574: $upload_output.='<td align="right"><span class="LC_warning">'.
10575: &mt('Invalid characters').'</span>';
1.987 raeburn 10576: $numinvalid++;
1.660 raeburn 10577: } else {
1.1123 raeburn 10578: $upload_output .= '<td>'.
10579: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10580: $embed_file,\%mapping,
1.1071 raeburn 10581: $allfiles,$codebase,'upload');
10582: $counter ++;
10583: $numnew ++;
1.987 raeburn 10584: }
10585: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10586: }
10587: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10588: if ($actionurl eq '/adm/dependencies') {
10589: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10590: $modify_output .= &start_data_table_row().
10591: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10592: '<img src="'.&icon($embed_file).'" border="0" />'.
10593: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10594: '<td>'.$size.'</td>'.
10595: '<td>'.$mtime.'</td>'.
10596: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10597: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10598: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10599: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10600: &embedded_file_element('upload_embedded',$counter,
10601: $embed_file,\%mapping,
10602: $allfiles,$codebase,'modify').
10603: '</div></td>'.
10604: &end_data_table_row()."\n";
10605: $counter ++;
10606: } else {
10607: $upload_output .= &start_data_table_row().
1.1123 raeburn 10608: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10609: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10610: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10611: &Apache::loncommon::end_data_table_row()."\n";
10612: }
10613: }
10614: my $delidx = $counter;
10615: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10616: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10617: $delete_output .= &start_data_table_row().
10618: '<td><img src="'.&icon($oldfile).'" />'.
10619: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10620: '<td>'.$size.'</td>'.
10621: '<td>'.$mtime.'</td>'.
10622: '<td><label><input type="checkbox" name="del_upload_dep" '.
10623: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10624: &embedded_file_element('upload_embedded',$delidx,
10625: $oldfile,\%mapping,$allfiles,
10626: $codebase,'delete').'</td>'.
10627: &end_data_table_row()."\n";
10628: $numunused ++;
10629: $delidx ++;
1.987 raeburn 10630: }
10631: if ($upload_output) {
10632: $upload_output = &start_data_table().
10633: $upload_output.
10634: &end_data_table()."\n";
10635: }
1.1071 raeburn 10636: if ($modify_output) {
10637: $modify_output = &start_data_table().
10638: &start_data_table_header_row().
10639: '<th>'.&mt('File').'</th>'.
10640: '<th>'.&mt('Size (KB)').'</th>'.
10641: '<th>'.&mt('Modified').'</th>'.
10642: '<th>'.&mt('Upload replacement?').'</th>'.
10643: &end_data_table_header_row().
10644: $modify_output.
10645: &end_data_table()."\n";
10646: }
10647: if ($delete_output) {
10648: $delete_output = &start_data_table().
10649: &start_data_table_header_row().
10650: '<th>'.&mt('File').'</th>'.
10651: '<th>'.&mt('Size (KB)').'</th>'.
10652: '<th>'.&mt('Modified').'</th>'.
10653: '<th>'.&mt('Delete?').'</th>'.
10654: &end_data_table_header_row().
10655: $delete_output.
10656: &end_data_table()."\n";
10657: }
1.987 raeburn 10658: my $applies = 0;
10659: if ($numremref) {
10660: $applies ++;
10661: }
10662: if ($numinvalid) {
10663: $applies ++;
10664: }
10665: if ($numexisting) {
10666: $applies ++;
10667: }
1.1071 raeburn 10668: if ($counter || $numunused) {
1.987 raeburn 10669: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10670: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10671: $state.'<h3>'.$heading.'</h3>';
10672: if ($actionurl eq '/adm/dependencies') {
10673: if ($numnew) {
10674: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10675: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10676: $upload_output.'<br />'."\n";
10677: }
10678: if ($numexisting) {
10679: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10680: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10681: $modify_output.'<br />'."\n";
10682: $buttontext = &mt('Save changes');
10683: }
10684: if ($numunused) {
10685: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10686: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10687: $delete_output.'<br />'."\n";
10688: $buttontext = &mt('Save changes');
10689: }
10690: } else {
10691: $output .= $upload_output.'<br />'."\n";
10692: }
10693: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10694: $counter.'" />'."\n";
10695: if ($actionurl eq '/adm/dependencies') {
10696: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10697: $numnew.'" />'."\n";
10698: } elsif ($actionurl eq '') {
1.987 raeburn 10699: $output .= '<input type="hidden" name="phase" value="three" />';
10700: }
10701: } elsif ($applies) {
10702: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10703: if ($applies > 1) {
10704: $output .=
1.1123 raeburn 10705: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10706: if ($numremref) {
10707: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10708: }
10709: if ($numinvalid) {
10710: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10711: }
10712: if ($numexisting) {
10713: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10714: }
10715: $output .= '</ul><br />';
10716: } elsif ($numremref) {
10717: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10718: } elsif ($numinvalid) {
10719: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10720: } elsif ($numexisting) {
10721: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10722: }
10723: $output .= $upload_output.'<br />';
10724: }
10725: my ($pathchange_output,$chgcount);
1.1071 raeburn 10726: $chgcount = $counter;
1.987 raeburn 10727: if (keys(%pathchanges) > 0) {
10728: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10729: if ($counter) {
1.987 raeburn 10730: $output .= &embedded_file_element('pathchange',$chgcount,
10731: $embed_file,\%mapping,
1.1071 raeburn 10732: $allfiles,$codebase,'change');
1.987 raeburn 10733: } else {
10734: $pathchange_output .=
10735: &start_data_table_row().
10736: '<td><input type ="checkbox" name="namechange" value="'.
10737: $chgcount.'" checked="checked" /></td>'.
10738: '<td>'.$mapping{$embed_file}.'</td>'.
10739: '<td>'.$embed_file.
10740: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10741: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10742: '</td>'.&end_data_table_row();
1.660 raeburn 10743: }
1.987 raeburn 10744: $numpathchg ++;
10745: $chgcount ++;
1.660 raeburn 10746: }
10747: }
1.1127 raeburn 10748: if (($counter) || ($numunused)) {
1.987 raeburn 10749: if ($numpathchg) {
10750: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10751: $numpathchg.'" />'."\n";
10752: }
10753: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10754: ($actionurl eq '/adm/imsimport')) {
10755: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10756: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10757: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10758: } elsif ($actionurl eq '/adm/dependencies') {
10759: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10760: }
1.1123 raeburn 10761: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10762: } elsif ($numpathchg) {
10763: my %pathchange = ();
10764: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10765: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10766: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10767: }
1.987 raeburn 10768: }
1.1071 raeburn 10769: return ($output,$counter,$numpathchg);
1.987 raeburn 10770: }
10771:
1.1147 raeburn 10772: =pod
10773:
10774: =item * clean_path($name)
10775:
10776: Performs clean-up of directories, subdirectories and filename in an
10777: embedded object, referenced in an HTML file which is being uploaded
10778: to a course or portfolio, where
10779: "Upload embedded images/multimedia files if HTML file" checkbox was
10780: checked.
10781:
10782: Clean-up is similar to replacements in lonnet::clean_filename()
10783: except each / between sub-directory and next level is preserved.
10784:
10785: =cut
10786:
10787: sub clean_path {
10788: my ($embed_file) = @_;
10789: $embed_file =~s{^/+}{};
10790: my @contents;
10791: if ($embed_file =~ m{/}) {
10792: @contents = split(/\//,$embed_file);
10793: } else {
10794: @contents = ($embed_file);
10795: }
10796: my $lastidx = scalar(@contents)-1;
10797: for (my $i=0; $i<=$lastidx; $i++) {
10798: $contents[$i]=~s{\\}{/}g;
10799: $contents[$i]=~s/\s+/\_/g;
10800: $contents[$i]=~s{[^/\w\.\-]}{}g;
10801: if ($i == $lastidx) {
10802: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10803: }
10804: }
10805: if ($lastidx > 0) {
10806: return join('/',@contents);
10807: } else {
10808: return $contents[0];
10809: }
10810: }
10811:
1.987 raeburn 10812: sub embedded_file_element {
1.1071 raeburn 10813: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10814: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10815: (ref($codebase) eq 'HASH'));
10816: my $output;
1.1071 raeburn 10817: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10818: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10819: }
10820: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10821: &escape($embed_file).'" />';
10822: unless (($context eq 'upload_embedded') &&
10823: ($mapping->{$embed_file} eq $embed_file)) {
10824: $output .='
10825: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10826: }
10827: my $attrib;
10828: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10829: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10830: }
10831: $output .=
10832: "\n\t\t".
10833: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10834: $attrib.'" />';
10835: if (exists($codebase->{$mapping->{$embed_file}})) {
10836: $output .=
10837: "\n\t\t".
10838: '<input name="codebase_'.$num.'" type="hidden" value="'.
10839: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10840: }
1.987 raeburn 10841: return $output;
1.660 raeburn 10842: }
10843:
1.1071 raeburn 10844: sub get_dependency_details {
10845: my ($currfile,$currsubfile,$embed_file) = @_;
10846: my ($size,$mtime,$showsize,$showmtime);
10847: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10848: if ($embed_file =~ m{/}) {
10849: my ($path,$fname) = split(/\//,$embed_file);
10850: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10851: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10852: }
10853: } else {
10854: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10855: ($size,$mtime) = @{$currfile->{$embed_file}};
10856: }
10857: }
10858: $showsize = $size/1024.0;
10859: $showsize = sprintf("%.1f",$showsize);
10860: if ($mtime > 0) {
10861: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10862: }
10863: }
10864: return ($showsize,$showmtime);
10865: }
10866:
10867: sub ask_embedded_js {
10868: return <<"END";
10869: <script type="text/javascript"">
10870: // <![CDATA[
10871: function toggleBrowse(counter) {
10872: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10873: var fileid = document.getElementById('embedded_item_'+counter);
10874: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10875: if (chkboxid.checked == true) {
10876: uploaddivid.style.display='block';
10877: } else {
10878: uploaddivid.style.display='none';
10879: fileid.value = '';
10880: }
10881: }
10882: // ]]>
10883: </script>
10884:
10885: END
10886: }
10887:
1.661 raeburn 10888: sub upload_embedded {
10889: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10890: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10891: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10892: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10893: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10894: my $orig_uploaded_filename =
10895: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10896: foreach my $type ('orig','ref','attrib','codebase') {
10897: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10898: $env{'form.embedded_'.$type.'_'.$i} =
10899: &unescape($env{'form.embedded_'.$type.'_'.$i});
10900: }
10901: }
1.661 raeburn 10902: my ($path,$fname) =
10903: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10904: # no path, whole string is fname
10905: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10906: $fname = &Apache::lonnet::clean_filename($fname);
10907: # See if there is anything left
10908: next if ($fname eq '');
10909:
10910: # Check if file already exists as a file or directory.
10911: my ($state,$msg);
10912: if ($context eq 'portfolio') {
10913: my $port_path = $dirpath;
10914: if ($group ne '') {
10915: $port_path = "groups/$group/$port_path";
10916: }
1.987 raeburn 10917: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10918: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10919: $dir_root,$port_path,$disk_quota,
10920: $current_disk_usage,$uname,$udom);
10921: if ($state eq 'will_exceed_quota'
1.984 raeburn 10922: || $state eq 'file_locked') {
1.661 raeburn 10923: $output .= $msg;
10924: next;
10925: }
10926: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10927: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10928: if ($state eq 'exists') {
10929: $output .= $msg;
10930: next;
10931: }
10932: }
10933: # Check if extension is valid
10934: if (($fname =~ /\.(\w+)$/) &&
10935: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 10936: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10937: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10938: next;
10939: } elsif (($fname =~ /\.(\w+)$/) &&
10940: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10941: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10942: next;
10943: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10944: $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 10945: next;
10946: }
10947: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10948: my $subdir = $path;
10949: $subdir =~ s{/+$}{};
1.661 raeburn 10950: if ($context eq 'portfolio') {
1.984 raeburn 10951: my $result;
10952: if ($state eq 'existingfile') {
10953: $result=
10954: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10955: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10956: } else {
1.984 raeburn 10957: $result=
10958: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10959: $dirpath.
1.1123 raeburn 10960: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10961: if ($result !~ m|^/uploaded/|) {
10962: $output .= '<span class="LC_error">'
10963: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10964: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10965: .'</span><br />';
10966: next;
10967: } else {
1.987 raeburn 10968: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10969: $path.$fname.'</span>').'<br />';
1.984 raeburn 10970: }
1.661 raeburn 10971: }
1.1123 raeburn 10972: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10973: my $extendedsubdir = $dirpath.'/'.$subdir;
10974: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10975: my $result =
1.1126 raeburn 10976: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10977: if ($result !~ m|^/uploaded/|) {
10978: $output .= '<span class="LC_error">'
10979: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10980: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10981: .'</span><br />';
10982: next;
10983: } else {
10984: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10985: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10986: if ($context eq 'syllabus') {
10987: &Apache::lonnet::make_public_indefinitely($result);
10988: }
1.987 raeburn 10989: }
1.661 raeburn 10990: } else {
10991: # Save the file
10992: my $target = $env{'form.embedded_item_'.$i};
10993: my $fullpath = $dir_root.$dirpath.'/'.$path;
10994: my $dest = $fullpath.$fname;
10995: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10996: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10997: my $count;
10998: my $filepath = $dir_root;
1.1027 raeburn 10999: foreach my $subdir (@parts) {
11000: $filepath .= "/$subdir";
11001: if (!-e $filepath) {
1.661 raeburn 11002: mkdir($filepath,0770);
11003: }
11004: }
11005: my $fh;
11006: if (!open($fh,'>'.$dest)) {
11007: &Apache::lonnet::logthis('Failed to create '.$dest);
11008: $output .= '<span class="LC_error">'.
1.1071 raeburn 11009: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11010: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11011: '</span><br />';
11012: } else {
11013: if (!print $fh $env{'form.embedded_item_'.$i}) {
11014: &Apache::lonnet::logthis('Failed to write to '.$dest);
11015: $output .= '<span class="LC_error">'.
1.1071 raeburn 11016: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11017: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11018: '</span><br />';
11019: } else {
1.987 raeburn 11020: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11021: $url.'</span>').'<br />';
11022: unless ($context eq 'testbank') {
11023: $footer .= &mt('View embedded file: [_1]',
11024: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11025: }
11026: }
11027: close($fh);
11028: }
11029: }
11030: if ($env{'form.embedded_ref_'.$i}) {
11031: $pathchange{$i} = 1;
11032: }
11033: }
11034: if ($output) {
11035: $output = '<p>'.$output.'</p>';
11036: }
11037: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11038: $returnflag = 'ok';
1.1071 raeburn 11039: my $numpathchgs = scalar(keys(%pathchange));
11040: if ($numpathchgs > 0) {
1.987 raeburn 11041: if ($context eq 'portfolio') {
11042: $output .= '<p>'.&mt('or').'</p>';
11043: } elsif ($context eq 'testbank') {
1.1071 raeburn 11044: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11045: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11046: $returnflag = 'modify_orightml';
11047: }
11048: }
1.1071 raeburn 11049: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11050: }
11051:
11052: sub modify_html_form {
11053: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11054: my $end = 0;
11055: my $modifyform;
11056: if ($context eq 'upload_embedded') {
11057: return unless (ref($pathchange) eq 'HASH');
11058: if ($env{'form.number_embedded_items'}) {
11059: $end += $env{'form.number_embedded_items'};
11060: }
11061: if ($env{'form.number_pathchange_items'}) {
11062: $end += $env{'form.number_pathchange_items'};
11063: }
11064: if ($end) {
11065: for (my $i=0; $i<$end; $i++) {
11066: if ($i < $env{'form.number_embedded_items'}) {
11067: next unless($pathchange->{$i});
11068: }
11069: $modifyform .=
11070: &start_data_table_row().
11071: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11072: 'checked="checked" /></td>'.
11073: '<td>'.$env{'form.embedded_ref_'.$i}.
11074: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11075: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11076: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11077: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11078: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11079: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11080: '<td>'.$env{'form.embedded_orig_'.$i}.
11081: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11082: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11083: &end_data_table_row();
1.1071 raeburn 11084: }
1.987 raeburn 11085: }
11086: } else {
11087: $modifyform = $pathchgtable;
11088: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11089: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11090: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11091: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11092: }
11093: }
11094: if ($modifyform) {
1.1071 raeburn 11095: if ($actionurl eq '/adm/dependencies') {
11096: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11097: }
1.987 raeburn 11098: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11099: '<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".
11100: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11101: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11102: '</ol></p>'."\n".'<p>'.
11103: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11104: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11105: &start_data_table()."\n".
11106: &start_data_table_header_row().
11107: '<th>'.&mt('Change?').'</th>'.
11108: '<th>'.&mt('Current reference').'</th>'.
11109: '<th>'.&mt('Required reference').'</th>'.
11110: &end_data_table_header_row()."\n".
11111: $modifyform.
11112: &end_data_table().'<br />'."\n".$hiddenstate.
11113: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11114: '</form>'."\n";
11115: }
11116: return;
11117: }
11118:
11119: sub modify_html_refs {
1.1123 raeburn 11120: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11121: my $container;
11122: if ($context eq 'portfolio') {
11123: $container = $env{'form.container'};
11124: } elsif ($context eq 'coursedoc') {
11125: $container = $env{'form.primaryurl'};
1.1071 raeburn 11126: } elsif ($context eq 'manage_dependencies') {
11127: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11128: $container = "/$container";
1.1123 raeburn 11129: } elsif ($context eq 'syllabus') {
11130: $container = $url;
1.987 raeburn 11131: } else {
1.1027 raeburn 11132: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11133: }
11134: my (%allfiles,%codebase,$output,$content);
11135: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11136: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11137: if (wantarray) {
11138: return ('',0,0);
11139: } else {
11140: return;
11141: }
11142: }
11143: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11144: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11145: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11146: if (wantarray) {
11147: return ('',0,0);
11148: } else {
11149: return;
11150: }
11151: }
1.987 raeburn 11152: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11153: if ($content eq '-1') {
11154: if (wantarray) {
11155: return ('',0,0);
11156: } else {
11157: return;
11158: }
11159: }
1.987 raeburn 11160: } else {
1.1071 raeburn 11161: unless ($container =~ /^\Q$dir_root\E/) {
11162: if (wantarray) {
11163: return ('',0,0);
11164: } else {
11165: return;
11166: }
11167: }
1.987 raeburn 11168: if (open(my $fh,"<$container")) {
11169: $content = join('', <$fh>);
11170: close($fh);
11171: } else {
1.1071 raeburn 11172: if (wantarray) {
11173: return ('',0,0);
11174: } else {
11175: return;
11176: }
1.987 raeburn 11177: }
11178: }
11179: my ($count,$codebasecount) = (0,0);
11180: my $mm = new File::MMagic;
11181: my $mime_type = $mm->checktype_contents($content);
11182: if ($mime_type eq 'text/html') {
11183: my $parse_result =
11184: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11185: \%codebase,\$content);
11186: if ($parse_result eq 'ok') {
11187: foreach my $i (@changes) {
11188: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11189: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11190: if ($allfiles{$ref}) {
11191: my $newname = $orig;
11192: my ($attrib_regexp,$codebase);
1.1006 raeburn 11193: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11194: if ($attrib_regexp =~ /:/) {
11195: $attrib_regexp =~ s/\:/|/g;
11196: }
11197: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11198: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11199: $count += $numchg;
1.1123 raeburn 11200: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11201: delete($allfiles{$ref});
1.987 raeburn 11202: }
11203: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11204: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11205: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11206: $codebasecount ++;
11207: }
11208: }
11209: }
1.1123 raeburn 11210: my $skiprewrites;
1.987 raeburn 11211: if ($count || $codebasecount) {
11212: my $saveresult;
1.1071 raeburn 11213: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11214: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11215: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11216: if ($url eq $container) {
11217: my ($fname) = ($container =~ m{/([^/]+)$});
11218: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11219: $count,'<span class="LC_filename">'.
1.1071 raeburn 11220: $fname.'</span>').'</p>';
1.987 raeburn 11221: } else {
11222: $output = '<p class="LC_error">'.
11223: &mt('Error: update failed for: [_1].',
11224: '<span class="LC_filename">'.
11225: $container.'</span>').'</p>';
11226: }
1.1123 raeburn 11227: if ($context eq 'syllabus') {
11228: unless ($saveresult eq 'ok') {
11229: $skiprewrites = 1;
11230: }
11231: }
1.987 raeburn 11232: } else {
11233: if (open(my $fh,">$container")) {
11234: print $fh $content;
11235: close($fh);
11236: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11237: $count,'<span class="LC_filename">'.
11238: $container.'</span>').'</p>';
1.661 raeburn 11239: } else {
1.987 raeburn 11240: $output = '<p class="LC_error">'.
11241: &mt('Error: could not update [_1].',
11242: '<span class="LC_filename">'.
11243: $container.'</span>').'</p>';
1.661 raeburn 11244: }
11245: }
11246: }
1.1123 raeburn 11247: if (($context eq 'syllabus') && (!$skiprewrites)) {
11248: my ($actionurl,$state);
11249: $actionurl = "/public/$udom/$uname/syllabus";
11250: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11251: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11252: \%codebase,
11253: {'context' => 'rewrites',
11254: 'ignore_remote_references' => 1,});
11255: if (ref($mapping) eq 'HASH') {
11256: my $rewrites = 0;
11257: foreach my $key (keys(%{$mapping})) {
11258: next if ($key =~ m{^https?://});
11259: my $ref = $mapping->{$key};
11260: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11261: my $attrib;
11262: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11263: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11264: }
11265: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11266: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11267: $rewrites += $numchg;
11268: }
11269: }
11270: if ($rewrites) {
11271: my $saveresult;
11272: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11273: if ($url eq $container) {
11274: my ($fname) = ($container =~ m{/([^/]+)$});
11275: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11276: $count,'<span class="LC_filename">'.
11277: $fname.'</span>').'</p>';
11278: } else {
11279: $output .= '<p class="LC_error">'.
11280: &mt('Error: could not update links in [_1].',
11281: '<span class="LC_filename">'.
11282: $container.'</span>').'</p>';
11283:
11284: }
11285: }
11286: }
11287: }
1.987 raeburn 11288: } else {
11289: &logthis('Failed to parse '.$container.
11290: ' to modify references: '.$parse_result);
1.661 raeburn 11291: }
11292: }
1.1071 raeburn 11293: if (wantarray) {
11294: return ($output,$count,$codebasecount);
11295: } else {
11296: return $output;
11297: }
1.661 raeburn 11298: }
11299:
11300: sub check_for_existing {
11301: my ($path,$fname,$element) = @_;
11302: my ($state,$msg);
11303: if (-d $path.'/'.$fname) {
11304: $state = 'exists';
11305: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11306: } elsif (-e $path.'/'.$fname) {
11307: $state = 'exists';
11308: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11309: }
11310: if ($state eq 'exists') {
11311: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11312: }
11313: return ($state,$msg);
11314: }
11315:
11316: sub check_for_upload {
11317: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11318: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11319: my $filesize = length($env{'form.'.$element});
11320: if (!$filesize) {
11321: my $msg = '<span class="LC_error">'.
11322: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11323: '<span class="LC_filename">'.$fname.'</span>',
11324: $filesize).'<br />'.
1.1007 raeburn 11325: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11326: '</span>';
11327: return ('zero_bytes',$msg);
11328: }
11329: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11330: my $getpropath = 1;
1.1021 raeburn 11331: my ($dirlistref,$listerror) =
11332: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11333: my $found_file = 0;
11334: my $locked_file = 0;
1.991 raeburn 11335: my @lockers;
11336: my $navmap;
11337: if ($env{'request.course.id'}) {
11338: $navmap = Apache::lonnavmaps::navmap->new();
11339: }
1.1021 raeburn 11340: if (ref($dirlistref) eq 'ARRAY') {
11341: foreach my $line (@{$dirlistref}) {
11342: my ($file_name,$rest)=split(/\&/,$line,2);
11343: if ($file_name eq $fname){
11344: $file_name = $path.$file_name;
11345: if ($group ne '') {
11346: $file_name = $group.$file_name;
11347: }
11348: $found_file = 1;
11349: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11350: foreach my $lock (@lockers) {
11351: if (ref($lock) eq 'ARRAY') {
11352: my ($symb,$crsid) = @{$lock};
11353: if ($crsid eq $env{'request.course.id'}) {
11354: if (ref($navmap)) {
11355: my $res = $navmap->getBySymb($symb);
11356: foreach my $part (@{$res->parts()}) {
11357: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11358: unless (($slot_status == $res->RESERVED) ||
11359: ($slot_status == $res->RESERVED_LOCATION)) {
11360: $locked_file = 1;
11361: }
1.991 raeburn 11362: }
1.1021 raeburn 11363: } else {
11364: $locked_file = 1;
1.991 raeburn 11365: }
11366: } else {
11367: $locked_file = 1;
11368: }
11369: }
1.1021 raeburn 11370: }
11371: } else {
11372: my @info = split(/\&/,$rest);
11373: my $currsize = $info[6]/1000;
11374: if ($currsize < $filesize) {
11375: my $extra = $filesize - $currsize;
11376: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 11377: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11378: &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 11379: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11380: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11381: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11382: return ('will_exceed_quota',$msg);
11383: }
1.984 raeburn 11384: }
11385: }
1.661 raeburn 11386: }
11387: }
11388: }
11389: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 11390: my $msg = '<p class="LC_warning">'.
11391: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 11392: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11393: return ('will_exceed_quota',$msg);
11394: } elsif ($found_file) {
11395: if ($locked_file) {
1.1179 bisitz 11396: my $msg = '<p class="LC_warning">';
1.661 raeburn 11397: $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 11398: $msg .= '</p>';
1.661 raeburn 11399: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11400: return ('file_locked',$msg);
11401: } else {
1.1179 bisitz 11402: my $msg = '<p class="LC_error">';
1.984 raeburn 11403: $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 11404: $msg .= '</p>';
1.984 raeburn 11405: return ('existingfile',$msg);
1.661 raeburn 11406: }
11407: }
11408: }
11409:
1.987 raeburn 11410: sub check_for_traversal {
11411: my ($path,$url,$toplevel) = @_;
11412: my @parts=split(/\//,$path);
11413: my $cleanpath;
11414: my $fullpath = $url;
11415: for (my $i=0;$i<@parts;$i++) {
11416: next if ($parts[$i] eq '.');
11417: if ($parts[$i] eq '..') {
11418: $fullpath =~ s{([^/]+/)$}{};
11419: } else {
11420: $fullpath .= $parts[$i].'/';
11421: }
11422: }
11423: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11424: $cleanpath = $1;
11425: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11426: my $curr_toprel = $1;
11427: my @parts = split(/\//,$curr_toprel);
11428: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11429: my @urlparts = split(/\//,$url_toprel);
11430: my $doubledots;
11431: my $startdiff = -1;
11432: for (my $i=0; $i<@urlparts; $i++) {
11433: if ($startdiff == -1) {
11434: unless ($urlparts[$i] eq $parts[$i]) {
11435: $startdiff = $i;
11436: $doubledots .= '../';
11437: }
11438: } else {
11439: $doubledots .= '../';
11440: }
11441: }
11442: if ($startdiff > -1) {
11443: $cleanpath = $doubledots;
11444: for (my $i=$startdiff; $i<@parts; $i++) {
11445: $cleanpath .= $parts[$i].'/';
11446: }
11447: }
11448: }
11449: $cleanpath =~ s{(/)$}{};
11450: return $cleanpath;
11451: }
1.31 albertel 11452:
1.1053 raeburn 11453: sub is_archive_file {
11454: my ($mimetype) = @_;
11455: if (($mimetype eq 'application/octet-stream') ||
11456: ($mimetype eq 'application/x-stuffit') ||
11457: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11458: return 1;
11459: }
11460: return;
11461: }
11462:
11463: sub decompress_form {
1.1065 raeburn 11464: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11465: my %lt = &Apache::lonlocal::texthash (
11466: this => 'This file is an archive file.',
1.1067 raeburn 11467: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11468: itsc => 'Its contents are as follows:',
1.1053 raeburn 11469: youm => 'You may wish to extract its contents.',
11470: extr => 'Extract contents',
1.1067 raeburn 11471: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11472: proa => 'Process automatically?',
1.1053 raeburn 11473: yes => 'Yes',
11474: no => 'No',
1.1067 raeburn 11475: fold => 'Title for folder containing movie',
11476: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11477: );
1.1065 raeburn 11478: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11479: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11480: my $info = &list_archive_contents($fileloc,\@paths);
11481: if (@paths) {
11482: foreach my $path (@paths) {
11483: $path =~ s{^/}{};
1.1067 raeburn 11484: if ($path =~ m{^([^/]+)/$}) {
11485: $topdir = $1;
11486: }
1.1065 raeburn 11487: if ($path =~ m{^([^/]+)/}) {
11488: $toplevel{$1} = $path;
11489: } else {
11490: $toplevel{$path} = $path;
11491: }
11492: }
11493: }
1.1067 raeburn 11494: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11495: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11496: "$topdir/media/",
11497: "$topdir/media/$topdir.mp4",
11498: "$topdir/media/FirstFrame.png",
11499: "$topdir/media/player.swf",
11500: "$topdir/media/swfobject.js",
11501: "$topdir/media/expressInstall.swf");
1.1197 raeburn 11502: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 11503: "$topdir/$topdir.mp4",
11504: "$topdir/$topdir\_config.xml",
11505: "$topdir/$topdir\_controller.swf",
11506: "$topdir/$topdir\_embed.css",
11507: "$topdir/$topdir\_First_Frame.png",
11508: "$topdir/$topdir\_player.html",
11509: "$topdir/$topdir\_Thumbnails.png",
11510: "$topdir/playerProductInstall.swf",
11511: "$topdir/scripts/",
11512: "$topdir/scripts/config_xml.js",
11513: "$topdir/scripts/handlebars.js",
11514: "$topdir/scripts/jquery-1.7.1.min.js",
11515: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11516: "$topdir/scripts/modernizr.js",
11517: "$topdir/scripts/player-min.js",
11518: "$topdir/scripts/swfobject.js",
11519: "$topdir/skins/",
11520: "$topdir/skins/configuration_express.xml",
11521: "$topdir/skins/express_show/",
11522: "$topdir/skins/express_show/player-min.css",
11523: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 11524: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11525: "$topdir/$topdir.mp4",
11526: "$topdir/$topdir\_config.xml",
11527: "$topdir/$topdir\_controller.swf",
11528: "$topdir/$topdir\_embed.css",
11529: "$topdir/$topdir\_First_Frame.png",
11530: "$topdir/$topdir\_player.html",
11531: "$topdir/$topdir\_Thumbnails.png",
11532: "$topdir/playerProductInstall.swf",
11533: "$topdir/scripts/",
11534: "$topdir/scripts/config_xml.js",
11535: "$topdir/scripts/techsmith-smart-player.min.js",
11536: "$topdir/skins/",
11537: "$topdir/skins/configuration_express.xml",
11538: "$topdir/skins/express_show/",
11539: "$topdir/skins/express_show/spritesheet.min.css",
11540: "$topdir/skins/express_show/spritesheet.png",
11541: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 11542: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11543: if (@diffs == 0) {
1.1164 raeburn 11544: $is_camtasia = 6;
11545: } else {
1.1197 raeburn 11546: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 11547: if (@diffs == 0) {
11548: $is_camtasia = 8;
1.1197 raeburn 11549: } else {
11550: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11551: if (@diffs == 0) {
11552: $is_camtasia = 8;
11553: }
1.1164 raeburn 11554: }
1.1067 raeburn 11555: }
11556: }
11557: my $output;
11558: if ($is_camtasia) {
11559: $output = <<"ENDCAM";
11560: <script type="text/javascript" language="Javascript">
11561: // <![CDATA[
11562:
11563: function camtasiaToggle() {
11564: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11565: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11566: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11567: document.getElementById('camtasia_titles').style.display='block';
11568: } else {
11569: document.getElementById('camtasia_titles').style.display='none';
11570: }
11571: }
11572: }
11573: return;
11574: }
11575:
11576: // ]]>
11577: </script>
11578: <p>$lt{'camt'}</p>
11579: ENDCAM
1.1065 raeburn 11580: } else {
1.1067 raeburn 11581: $output = '<p>'.$lt{'this'};
11582: if ($info eq '') {
11583: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11584: } else {
11585: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11586: '<div><pre>'.$info.'</pre></div>';
11587: }
1.1065 raeburn 11588: }
1.1067 raeburn 11589: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11590: my $duplicates;
11591: my $num = 0;
11592: if (ref($dirlist) eq 'ARRAY') {
11593: foreach my $item (@{$dirlist}) {
11594: if (ref($item) eq 'ARRAY') {
11595: if (exists($toplevel{$item->[0]})) {
11596: $duplicates .=
11597: &start_data_table_row().
11598: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11599: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11600: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11601: 'value="1" />'.&mt('Yes').'</label>'.
11602: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11603: '<td>'.$item->[0].'</td>';
11604: if ($item->[2]) {
11605: $duplicates .= '<td>'.&mt('Directory').'</td>';
11606: } else {
11607: $duplicates .= '<td>'.&mt('File').'</td>';
11608: }
11609: $duplicates .= '<td>'.$item->[3].'</td>'.
11610: '<td>'.
11611: &Apache::lonlocal::locallocaltime($item->[4]).
11612: '</td>'.
11613: &end_data_table_row();
11614: $num ++;
11615: }
11616: }
11617: }
11618: }
11619: my $itemcount;
11620: if (@paths > 0) {
11621: $itemcount = scalar(@paths);
11622: } else {
11623: $itemcount = 1;
11624: }
1.1067 raeburn 11625: if ($is_camtasia) {
11626: $output .= $lt{'auto'}.'<br />'.
11627: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11628: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11629: $lt{'yes'}.'</label> <label>'.
11630: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11631: $lt{'no'}.'</label></span><br />'.
11632: '<div id="camtasia_titles" style="display:block">'.
11633: &Apache::lonhtmlcommon::start_pick_box().
11634: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11635: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11636: &Apache::lonhtmlcommon::row_closure().
11637: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11638: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11639: &Apache::lonhtmlcommon::row_closure(1).
11640: &Apache::lonhtmlcommon::end_pick_box().
11641: '</div>';
11642: }
1.1065 raeburn 11643: $output .=
11644: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11645: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11646: "\n";
1.1065 raeburn 11647: if ($duplicates ne '') {
11648: $output .= '<p><span class="LC_warning">'.
11649: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11650: &start_data_table().
11651: &start_data_table_header_row().
11652: '<th>'.&mt('Overwrite?').'</th>'.
11653: '<th>'.&mt('Name').'</th>'.
11654: '<th>'.&mt('Type').'</th>'.
11655: '<th>'.&mt('Size').'</th>'.
11656: '<th>'.&mt('Last modified').'</th>'.
11657: &end_data_table_header_row().
11658: $duplicates.
11659: &end_data_table().
11660: '</p>';
11661: }
1.1067 raeburn 11662: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11663: if (ref($hiddenelements) eq 'HASH') {
11664: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11665: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11666: }
11667: }
11668: $output .= <<"END";
1.1067 raeburn 11669: <br />
1.1053 raeburn 11670: <input type="submit" name="decompress" value="$lt{'extr'}" />
11671: </form>
11672: $noextract
11673: END
11674: return $output;
11675: }
11676:
1.1065 raeburn 11677: sub decompression_utility {
11678: my ($program) = @_;
11679: my @utilities = ('tar','gunzip','bunzip2','unzip');
11680: my $location;
11681: if (grep(/^\Q$program\E$/,@utilities)) {
11682: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11683: '/usr/sbin/') {
11684: if (-x $dir.$program) {
11685: $location = $dir.$program;
11686: last;
11687: }
11688: }
11689: }
11690: return $location;
11691: }
11692:
11693: sub list_archive_contents {
11694: my ($file,$pathsref) = @_;
11695: my (@cmd,$output);
11696: my $needsregexp;
11697: if ($file =~ /\.zip$/) {
11698: @cmd = (&decompression_utility('unzip'),"-l");
11699: $needsregexp = 1;
11700: } elsif (($file =~ m/\.tar\.gz$/) ||
11701: ($file =~ /\.tgz$/)) {
11702: @cmd = (&decompression_utility('tar'),"-ztf");
11703: } elsif ($file =~ /\.tar\.bz2$/) {
11704: @cmd = (&decompression_utility('tar'),"-jtf");
11705: } elsif ($file =~ m|\.tar$|) {
11706: @cmd = (&decompression_utility('tar'),"-tf");
11707: }
11708: if (@cmd) {
11709: undef($!);
11710: undef($@);
11711: if (open(my $fh,"-|", @cmd, $file)) {
11712: while (my $line = <$fh>) {
11713: $output .= $line;
11714: chomp($line);
11715: my $item;
11716: if ($needsregexp) {
11717: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11718: } else {
11719: $item = $line;
11720: }
11721: if ($item ne '') {
11722: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11723: push(@{$pathsref},$item);
11724: }
11725: }
11726: }
11727: close($fh);
11728: }
11729: }
11730: return $output;
11731: }
11732:
1.1053 raeburn 11733: sub decompress_uploaded_file {
11734: my ($file,$dir) = @_;
11735: &Apache::lonnet::appenv({'cgi.file' => $file});
11736: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11737: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11738: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11739: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11740: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11741: my $decompressed = $env{'cgi.decompressed'};
11742: &Apache::lonnet::delenv('cgi.file');
11743: &Apache::lonnet::delenv('cgi.dir');
11744: &Apache::lonnet::delenv('cgi.decompressed');
11745: return ($decompressed,$result);
11746: }
11747:
1.1055 raeburn 11748: sub process_decompression {
11749: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11750: my ($dir,$error,$warning,$output);
1.1180 raeburn 11751: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 11752: $error = &mt('Filename not a supported archive file type.').
11753: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11754: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11755: } else {
11756: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11757: if ($docuhome eq 'no_host') {
11758: $error = &mt('Could not determine home server for course.');
11759: } else {
11760: my @ids=&Apache::lonnet::current_machine_ids();
11761: my $currdir = "$dir_root/$destination";
11762: if (grep(/^\Q$docuhome\E$/,@ids)) {
11763: $dir = &LONCAPA::propath($docudom,$docuname).
11764: "$dir_root/$destination";
11765: } else {
11766: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11767: "$dir_root/$docudom/$docuname/$destination";
11768: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11769: $error = &mt('Archive file not found.');
11770: }
11771: }
1.1065 raeburn 11772: my (@to_overwrite,@to_skip);
11773: if ($env{'form.archive_overwrite_total'} > 0) {
11774: my $total = $env{'form.archive_overwrite_total'};
11775: for (my $i=0; $i<$total; $i++) {
11776: if ($env{'form.archive_overwrite_'.$i} == 1) {
11777: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11778: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11779: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11780: }
11781: }
11782: }
11783: my $numskip = scalar(@to_skip);
11784: if (($numskip > 0) &&
11785: ($numskip == $env{'form.archive_itemcount'})) {
11786: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11787: } elsif ($dir eq '') {
1.1055 raeburn 11788: $error = &mt('Directory containing archive file unavailable.');
11789: } elsif (!$error) {
1.1065 raeburn 11790: my ($decompressed,$display);
11791: if ($numskip > 0) {
11792: my $tempdir = time.'_'.$$.int(rand(10000));
11793: mkdir("$dir/$tempdir",0755);
11794: system("mv $dir/$file $dir/$tempdir/$file");
11795: ($decompressed,$display) =
11796: &decompress_uploaded_file($file,"$dir/$tempdir");
11797: foreach my $item (@to_skip) {
11798: if (($item ne '') && ($item !~ /\.\./)) {
11799: if (-f "$dir/$tempdir/$item") {
11800: unlink("$dir/$tempdir/$item");
11801: } elsif (-d "$dir/$tempdir/$item") {
11802: system("rm -rf $dir/$tempdir/$item");
11803: }
11804: }
11805: }
11806: system("mv $dir/$tempdir/* $dir");
11807: rmdir("$dir/$tempdir");
11808: } else {
11809: ($decompressed,$display) =
11810: &decompress_uploaded_file($file,$dir);
11811: }
1.1055 raeburn 11812: if ($decompressed eq 'ok') {
1.1065 raeburn 11813: $output = '<p class="LC_info">'.
11814: &mt('Files extracted successfully from archive.').
11815: '</p>'."\n";
1.1055 raeburn 11816: my ($warning,$result,@contents);
11817: my ($newdirlistref,$newlisterror) =
11818: &Apache::lonnet::dirlist($currdir,$docudom,
11819: $docuname,1);
11820: my (%is_dir,%changes,@newitems);
11821: my $dirptr = 16384;
1.1065 raeburn 11822: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11823: foreach my $dir_line (@{$newdirlistref}) {
11824: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11825: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11826: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11827: push(@newitems,$item);
11828: if ($dirptr&$testdir) {
11829: $is_dir{$item} = 1;
11830: }
11831: $changes{$item} = 1;
11832: }
11833: }
11834: }
11835: if (keys(%changes) > 0) {
11836: foreach my $item (sort(@newitems)) {
11837: if ($changes{$item}) {
11838: push(@contents,$item);
11839: }
11840: }
11841: }
11842: if (@contents > 0) {
1.1067 raeburn 11843: my $wantform;
11844: unless ($env{'form.autoextract_camtasia'}) {
11845: $wantform = 1;
11846: }
1.1056 raeburn 11847: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11848: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11849: $currdir,\%is_dir,
11850: \%children,\%parent,
1.1056 raeburn 11851: \@contents,\%dirorder,
11852: \%titles,$wantform);
1.1055 raeburn 11853: if ($datatable ne '') {
11854: $output .= &archive_options_form('decompressed',$datatable,
11855: $count,$hiddenelem);
1.1065 raeburn 11856: my $startcount = 6;
1.1055 raeburn 11857: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11858: \%titles,\%children);
1.1055 raeburn 11859: }
1.1067 raeburn 11860: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 11861: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11862: my %displayed;
11863: my $total = 1;
11864: $env{'form.archive_directory'} = [];
11865: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11866: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11867: $path =~ s{/$}{};
11868: my $item;
11869: if ($path ne '') {
11870: $item = "$path/$titles{$i}";
11871: } else {
11872: $item = $titles{$i};
11873: }
11874: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11875: if ($item eq $contents[0]) {
11876: push(@{$env{'form.archive_directory'}},$i);
11877: $env{'form.archive_'.$i} = 'display';
11878: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11879: $displayed{'folder'} = $i;
1.1164 raeburn 11880: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11881: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11882: $env{'form.archive_'.$i} = 'display';
11883: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11884: $displayed{'web'} = $i;
11885: } else {
1.1164 raeburn 11886: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11887: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11888: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11889: push(@{$env{'form.archive_directory'}},$i);
11890: }
11891: $env{'form.archive_'.$i} = 'dependency';
11892: }
11893: $total ++;
11894: }
11895: for (my $i=1; $i<$total; $i++) {
11896: next if ($i == $displayed{'web'});
11897: next if ($i == $displayed{'folder'});
11898: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11899: }
11900: $env{'form.phase'} = 'decompress_cleanup';
11901: $env{'form.archivedelete'} = 1;
11902: $env{'form.archive_count'} = $total-1;
11903: $output .=
11904: &process_extracted_files('coursedocs',$docudom,
11905: $docuname,$destination,
11906: $dir_root,$hiddenelem);
11907: }
1.1055 raeburn 11908: } else {
11909: $warning = &mt('No new items extracted from archive file.');
11910: }
11911: } else {
11912: $output = $display;
11913: $error = &mt('An error occurred during extraction from the archive file.');
11914: }
11915: }
11916: }
11917: }
11918: if ($error) {
11919: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11920: $error.'</p>'."\n";
11921: }
11922: if ($warning) {
11923: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11924: }
11925: return $output;
11926: }
11927:
11928: sub get_extracted {
1.1056 raeburn 11929: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11930: $titles,$wantform) = @_;
1.1055 raeburn 11931: my $count = 0;
11932: my $depth = 0;
11933: my $datatable;
1.1056 raeburn 11934: my @hierarchy;
1.1055 raeburn 11935: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11936: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11937: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11938: foreach my $item (@{$contents}) {
11939: $count ++;
1.1056 raeburn 11940: @{$dirorder->{$count}} = @hierarchy;
11941: $titles->{$count} = $item;
1.1055 raeburn 11942: &archive_hierarchy($depth,$count,$parent,$children);
11943: if ($wantform) {
11944: $datatable .= &archive_row($is_dir->{$item},$item,
11945: $currdir,$depth,$count);
11946: }
11947: if ($is_dir->{$item}) {
11948: $depth ++;
1.1056 raeburn 11949: push(@hierarchy,$count);
11950: $parent->{$depth} = $count;
1.1055 raeburn 11951: $datatable .=
11952: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11953: \$depth,\$count,\@hierarchy,$dirorder,
11954: $children,$parent,$titles,$wantform);
1.1055 raeburn 11955: $depth --;
1.1056 raeburn 11956: pop(@hierarchy);
1.1055 raeburn 11957: }
11958: }
11959: return ($count,$datatable);
11960: }
11961:
11962: sub recurse_extracted_archive {
1.1056 raeburn 11963: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11964: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11965: my $result='';
1.1056 raeburn 11966: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11967: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11968: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11969: return $result;
11970: }
11971: my $dirptr = 16384;
11972: my ($newdirlistref,$newlisterror) =
11973: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11974: if (ref($newdirlistref) eq 'ARRAY') {
11975: foreach my $dir_line (@{$newdirlistref}) {
11976: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11977: unless ($item =~ /^\.+$/) {
11978: $$count ++;
1.1056 raeburn 11979: @{$dirorder->{$$count}} = @{$hierarchy};
11980: $titles->{$$count} = $item;
1.1055 raeburn 11981: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11982:
1.1055 raeburn 11983: my $is_dir;
11984: if ($dirptr&$testdir) {
11985: $is_dir = 1;
11986: }
11987: if ($wantform) {
11988: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11989: }
11990: if ($is_dir) {
11991: $$depth ++;
1.1056 raeburn 11992: push(@{$hierarchy},$$count);
11993: $parent->{$$depth} = $$count;
1.1055 raeburn 11994: $result .=
11995: &recurse_extracted_archive("$currdir/$item",$docudom,
11996: $docuname,$depth,$count,
1.1056 raeburn 11997: $hierarchy,$dirorder,$children,
11998: $parent,$titles,$wantform);
1.1055 raeburn 11999: $$depth --;
1.1056 raeburn 12000: pop(@{$hierarchy});
1.1055 raeburn 12001: }
12002: }
12003: }
12004: }
12005: return $result;
12006: }
12007:
12008: sub archive_hierarchy {
12009: my ($depth,$count,$parent,$children) =@_;
12010: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12011: if (exists($parent->{$depth})) {
12012: $children->{$parent->{$depth}} .= $count.':';
12013: }
12014: }
12015: return;
12016: }
12017:
12018: sub archive_row {
12019: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12020: my ($name) = ($item =~ m{([^/]+)$});
12021: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12022: 'display' => 'Add as file',
1.1055 raeburn 12023: 'dependency' => 'Include as dependency',
12024: 'discard' => 'Discard',
12025: );
12026: if ($is_dir) {
1.1059 raeburn 12027: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12028: }
1.1056 raeburn 12029: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12030: my $offset = 0;
1.1055 raeburn 12031: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12032: $offset ++;
1.1065 raeburn 12033: if ($action ne 'display') {
12034: $offset ++;
12035: }
1.1055 raeburn 12036: $output .= '<td><span class="LC_nobreak">'.
12037: '<label><input type="radio" name="archive_'.$count.
12038: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12039: my $text = $choices{$action};
12040: if ($is_dir) {
12041: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12042: if ($action eq 'display') {
1.1059 raeburn 12043: $text = &mt('Add as folder');
1.1055 raeburn 12044: }
1.1056 raeburn 12045: } else {
12046: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12047:
12048: }
12049: $output .= ' /> '.$choices{$action}.'</label></span>';
12050: if ($action eq 'dependency') {
12051: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12052: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12053: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12054: '<option value=""></option>'."\n".
12055: '</select>'."\n".
12056: '</div>';
1.1059 raeburn 12057: } elsif ($action eq 'display') {
12058: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12059: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12060: '</div>';
1.1055 raeburn 12061: }
1.1056 raeburn 12062: $output .= '</td>';
1.1055 raeburn 12063: }
12064: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12065: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12066: for (my $i=0; $i<$depth; $i++) {
12067: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12068: }
12069: if ($is_dir) {
12070: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12071: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12072: } else {
12073: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12074: }
12075: $output .= ' '.$name.'</td>'."\n".
12076: &end_data_table_row();
12077: return $output;
12078: }
12079:
12080: sub archive_options_form {
1.1065 raeburn 12081: my ($form,$display,$count,$hiddenelem) = @_;
12082: my %lt = &Apache::lonlocal::texthash(
12083: perm => 'Permanently remove archive file?',
12084: hows => 'How should each extracted item be incorporated in the course?',
12085: cont => 'Content actions for all',
12086: addf => 'Add as folder/file',
12087: incd => 'Include as dependency for a displayed file',
12088: disc => 'Discard',
12089: no => 'No',
12090: yes => 'Yes',
12091: save => 'Save',
12092: );
12093: my $output = <<"END";
12094: <form name="$form" method="post" action="">
12095: <p><span class="LC_nobreak">$lt{'perm'}
12096: <label>
12097: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12098: </label>
12099:
12100: <label>
12101: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12102: </span>
12103: </p>
12104: <input type="hidden" name="phase" value="decompress_cleanup" />
12105: <br />$lt{'hows'}
12106: <div class="LC_columnSection">
12107: <fieldset>
12108: <legend>$lt{'cont'}</legend>
12109: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12110: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12111: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12112: </fieldset>
12113: </div>
12114: END
12115: return $output.
1.1055 raeburn 12116: &start_data_table()."\n".
1.1065 raeburn 12117: $display."\n".
1.1055 raeburn 12118: &end_data_table()."\n".
12119: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12120: $hiddenelem.
1.1065 raeburn 12121: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12122: '</form>';
12123: }
12124:
12125: sub archive_javascript {
1.1056 raeburn 12126: my ($startcount,$numitems,$titles,$children) = @_;
12127: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12128: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12129: my $scripttag = <<START;
12130: <script type="text/javascript">
12131: // <![CDATA[
12132:
12133: function checkAll(form,prefix) {
12134: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12135: for (var i=0; i < form.elements.length; i++) {
12136: var id = form.elements[i].id;
12137: if ((id != '') && (id != undefined)) {
12138: if (idstr.test(id)) {
12139: if (form.elements[i].type == 'radio') {
12140: form.elements[i].checked = true;
1.1056 raeburn 12141: var nostart = i-$startcount;
1.1059 raeburn 12142: var offset = nostart%7;
12143: var count = (nostart-offset)/7;
1.1056 raeburn 12144: dependencyCheck(form,count,offset);
1.1055 raeburn 12145: }
12146: }
12147: }
12148: }
12149: }
12150:
12151: function propagateCheck(form,count) {
12152: if (count > 0) {
1.1059 raeburn 12153: var startelement = $startcount + ((count-1) * 7);
12154: for (var j=1; j<6; j++) {
12155: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12156: var item = startelement + j;
12157: if (form.elements[item].type == 'radio') {
12158: if (form.elements[item].checked) {
12159: containerCheck(form,count,j);
12160: break;
12161: }
1.1055 raeburn 12162: }
12163: }
12164: }
12165: }
12166: }
12167:
12168: numitems = $numitems
1.1056 raeburn 12169: var titles = new Array(numitems);
12170: var parents = new Array(numitems);
1.1055 raeburn 12171: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12172: parents[i] = new Array;
1.1055 raeburn 12173: }
1.1059 raeburn 12174: var maintitle = '$maintitle';
1.1055 raeburn 12175:
12176: START
12177:
1.1056 raeburn 12178: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12179: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12180: for (my $i=0; $i<@contents; $i ++) {
12181: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12182: }
12183: }
12184:
1.1056 raeburn 12185: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12186: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12187: }
12188:
1.1055 raeburn 12189: $scripttag .= <<END;
12190:
12191: function containerCheck(form,count,offset) {
12192: if (count > 0) {
1.1056 raeburn 12193: dependencyCheck(form,count,offset);
1.1059 raeburn 12194: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12195: form.elements[item].checked = true;
12196: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12197: if (parents[count].length > 0) {
12198: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12199: containerCheck(form,parents[count][j],offset);
12200: }
12201: }
12202: }
12203: }
12204: }
12205:
12206: function dependencyCheck(form,count,offset) {
12207: if (count > 0) {
1.1059 raeburn 12208: var chosen = (offset+$startcount)+7*(count-1);
12209: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12210: var currtype = form.elements[depitem].type;
12211: if (form.elements[chosen].value == 'dependency') {
12212: document.getElementById('arc_depon_'+count).style.display='block';
12213: form.elements[depitem].options.length = 0;
12214: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12215: for (var i=1; i<=numitems; i++) {
12216: if (i == count) {
12217: continue;
12218: }
1.1059 raeburn 12219: var startelement = $startcount + (i-1) * 7;
12220: for (var j=1; j<6; j++) {
12221: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12222: var item = startelement + j;
12223: if (form.elements[item].type == 'radio') {
12224: if (form.elements[item].checked) {
12225: if (form.elements[item].value == 'display') {
12226: var n = form.elements[depitem].options.length;
12227: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12228: }
12229: }
12230: }
12231: }
12232: }
12233: }
12234: } else {
12235: document.getElementById('arc_depon_'+count).style.display='none';
12236: form.elements[depitem].options.length = 0;
12237: form.elements[depitem].options[0] = new Option('Select','',true,true);
12238: }
1.1059 raeburn 12239: titleCheck(form,count,offset);
1.1056 raeburn 12240: }
12241: }
12242:
12243: function propagateSelect(form,count,offset) {
12244: if (count > 0) {
1.1065 raeburn 12245: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12246: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12247: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12248: if (parents[count].length > 0) {
12249: for (var j=0; j<parents[count].length; j++) {
12250: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12251: }
12252: }
12253: }
12254: }
12255: }
1.1056 raeburn 12256:
12257: function containerSelect(form,count,offset,picked) {
12258: if (count > 0) {
1.1065 raeburn 12259: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12260: if (form.elements[item].type == 'radio') {
12261: if (form.elements[item].value == 'dependency') {
12262: if (form.elements[item+1].type == 'select-one') {
12263: for (var i=0; i<form.elements[item+1].options.length; i++) {
12264: if (form.elements[item+1].options[i].value == picked) {
12265: form.elements[item+1].selectedIndex = i;
12266: break;
12267: }
12268: }
12269: }
12270: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12271: if (parents[count].length > 0) {
12272: for (var j=0; j<parents[count].length; j++) {
12273: containerSelect(form,parents[count][j],offset,picked);
12274: }
12275: }
12276: }
12277: }
12278: }
12279: }
12280: }
12281:
1.1059 raeburn 12282: function titleCheck(form,count,offset) {
12283: if (count > 0) {
12284: var chosen = (offset+$startcount)+7*(count-1);
12285: var depitem = $startcount + ((count-1) * 7) + 2;
12286: var currtype = form.elements[depitem].type;
12287: if (form.elements[chosen].value == 'display') {
12288: document.getElementById('arc_title_'+count).style.display='block';
12289: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12290: document.getElementById('archive_title_'+count).value=maintitle;
12291: }
12292: } else {
12293: document.getElementById('arc_title_'+count).style.display='none';
12294: if (currtype == 'text') {
12295: document.getElementById('archive_title_'+count).value='';
12296: }
12297: }
12298: }
12299: return;
12300: }
12301:
1.1055 raeburn 12302: // ]]>
12303: </script>
12304: END
12305: return $scripttag;
12306: }
12307:
12308: sub process_extracted_files {
1.1067 raeburn 12309: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12310: my $numitems = $env{'form.archive_count'};
12311: return unless ($numitems);
12312: my @ids=&Apache::lonnet::current_machine_ids();
12313: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12314: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12315: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12316: if (grep(/^\Q$docuhome\E$/,@ids)) {
12317: $prefix = &LONCAPA::propath($docudom,$docuname);
12318: $pathtocheck = "$dir_root/$destination";
12319: $dir = $dir_root;
12320: $ishome = 1;
12321: } else {
12322: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12323: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12324: $dir = "$dir_root/$docudom/$docuname";
12325: }
12326: my $currdir = "$dir_root/$destination";
12327: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12328: if ($env{'form.folderpath'}) {
12329: my @items = split('&',$env{'form.folderpath'});
12330: $folders{'0'} = $items[-2];
1.1099 raeburn 12331: if ($env{'form.folderpath'} =~ /\:1$/) {
12332: $containers{'0'}='page';
12333: } else {
12334: $containers{'0'}='sequence';
12335: }
1.1055 raeburn 12336: }
12337: my @archdirs = &get_env_multiple('form.archive_directory');
12338: if ($numitems) {
12339: for (my $i=1; $i<=$numitems; $i++) {
12340: my $path = $env{'form.archive_content_'.$i};
12341: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12342: my $item = $1;
12343: $toplevelitems{$item} = $i;
12344: if (grep(/^\Q$i\E$/,@archdirs)) {
12345: $is_dir{$item} = 1;
12346: }
12347: }
12348: }
12349: }
1.1067 raeburn 12350: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12351: if (keys(%toplevelitems) > 0) {
12352: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12353: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12354: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12355: }
1.1066 raeburn 12356: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12357: if ($numitems) {
12358: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 12359: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12360: my $path = $env{'form.archive_content_'.$i};
12361: if ($path =~ /^\Q$pathtocheck\E/) {
12362: if ($env{'form.archive_'.$i} eq 'discard') {
12363: if ($prefix ne '' && $path ne '') {
12364: if (-e $prefix.$path) {
1.1066 raeburn 12365: if ((@archdirs > 0) &&
12366: (grep(/^\Q$i\E$/,@archdirs))) {
12367: $todeletedir{$prefix.$path} = 1;
12368: } else {
12369: $todelete{$prefix.$path} = 1;
12370: }
1.1055 raeburn 12371: }
12372: }
12373: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12374: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12375: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12376: $docstitle = $env{'form.archive_title_'.$i};
12377: if ($docstitle eq '') {
12378: $docstitle = $title;
12379: }
1.1055 raeburn 12380: $outer = 0;
1.1056 raeburn 12381: if (ref($dirorder{$i}) eq 'ARRAY') {
12382: if (@{$dirorder{$i}} > 0) {
12383: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12384: if ($env{'form.archive_'.$item} eq 'display') {
12385: $outer = $item;
12386: last;
12387: }
12388: }
12389: }
12390: }
12391: my ($errtext,$fatal) =
12392: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12393: '/'.$folders{$outer}.'.'.
12394: $containers{$outer});
12395: next if ($fatal);
12396: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12397: if ($context eq 'coursedocs') {
1.1056 raeburn 12398: $mapinner{$i} = time;
1.1055 raeburn 12399: $folders{$i} = 'default_'.$mapinner{$i};
12400: $containers{$i} = 'sequence';
12401: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12402: $folders{$i}.'.'.$containers{$i};
12403: my $newidx = &LONCAPA::map::getresidx();
12404: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12405: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12406: push(@LONCAPA::map::order,$newidx);
12407: my ($outtext,$errtext) =
12408: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12409: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12410: '.'.$containers{$outer},1,1);
1.1056 raeburn 12411: $newseqid{$i} = $newidx;
1.1067 raeburn 12412: unless ($errtext) {
12413: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12414: }
1.1055 raeburn 12415: }
12416: } else {
12417: if ($context eq 'coursedocs') {
12418: my $newidx=&LONCAPA::map::getresidx();
12419: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12420: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12421: $title;
12422: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12423: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12424: }
12425: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12426: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12427: }
12428: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12429: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12430: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12431: unless ($ishome) {
12432: my $fetch = "$newdest{$i}/$title";
12433: $fetch =~ s/^\Q$prefix$dir\E//;
12434: $prompttofetch{$fetch} = 1;
12435: }
1.1055 raeburn 12436: }
12437: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12438: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12439: push(@LONCAPA::map::order, $newidx);
12440: my ($outtext,$errtext)=
12441: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12442: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12443: '.'.$containers{$outer},1,1);
1.1067 raeburn 12444: unless ($errtext) {
12445: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12446: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12447: }
12448: }
1.1055 raeburn 12449: }
12450: }
1.1086 raeburn 12451: }
12452: } else {
12453: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12454: }
12455: }
12456: for (my $i=1; $i<=$numitems; $i++) {
12457: next unless ($env{'form.archive_'.$i} eq 'dependency');
12458: my $path = $env{'form.archive_content_'.$i};
12459: if ($path =~ /^\Q$pathtocheck\E/) {
12460: my ($title) = ($path =~ m{/([^/]+)$});
12461: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12462: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12463: if (ref($dirorder{$i}) eq 'ARRAY') {
12464: my ($itemidx,$fullpath,$relpath);
12465: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12466: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12467: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12468: if ($dirorder{$i}->[$j] eq $container) {
12469: $itemidx = $j;
1.1056 raeburn 12470: }
12471: }
1.1086 raeburn 12472: }
12473: if ($itemidx eq '') {
12474: $itemidx = 0;
12475: }
12476: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12477: if ($mapinner{$referrer{$i}}) {
12478: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12479: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12480: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12481: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12482: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12483: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12484: if (!-e $fullpath) {
12485: mkdir($fullpath,0755);
1.1056 raeburn 12486: }
12487: }
1.1086 raeburn 12488: } else {
12489: last;
1.1056 raeburn 12490: }
1.1086 raeburn 12491: }
12492: }
12493: } elsif ($newdest{$referrer{$i}}) {
12494: $fullpath = $newdest{$referrer{$i}};
12495: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12496: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12497: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12498: last;
12499: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12500: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12501: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12502: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12503: if (!-e $fullpath) {
12504: mkdir($fullpath,0755);
1.1056 raeburn 12505: }
12506: }
1.1086 raeburn 12507: } else {
12508: last;
1.1056 raeburn 12509: }
1.1055 raeburn 12510: }
12511: }
1.1086 raeburn 12512: if ($fullpath ne '') {
12513: if (-e "$prefix$path") {
12514: system("mv $prefix$path $fullpath/$title");
12515: }
12516: if (-e "$fullpath/$title") {
12517: my $showpath;
12518: if ($relpath ne '') {
12519: $showpath = "$relpath/$title";
12520: } else {
12521: $showpath = "/$title";
12522: }
12523: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12524: }
12525: unless ($ishome) {
12526: my $fetch = "$fullpath/$title";
12527: $fetch =~ s/^\Q$prefix$dir\E//;
12528: $prompttofetch{$fetch} = 1;
12529: }
12530: }
1.1055 raeburn 12531: }
1.1086 raeburn 12532: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12533: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12534: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12535: }
12536: } else {
12537: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12538: }
12539: }
12540: if (keys(%todelete)) {
12541: foreach my $key (keys(%todelete)) {
12542: unlink($key);
1.1066 raeburn 12543: }
12544: }
12545: if (keys(%todeletedir)) {
12546: foreach my $key (keys(%todeletedir)) {
12547: rmdir($key);
12548: }
12549: }
12550: foreach my $dir (sort(keys(%is_dir))) {
12551: if (($pathtocheck ne '') && ($dir ne '')) {
12552: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12553: }
12554: }
1.1067 raeburn 12555: if ($result ne '') {
12556: $output .= '<ul>'."\n".
12557: $result."\n".
12558: '</ul>';
12559: }
12560: unless ($ishome) {
12561: my $replicationfail;
12562: foreach my $item (keys(%prompttofetch)) {
12563: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12564: unless ($fetchresult eq 'ok') {
12565: $replicationfail .= '<li>'.$item.'</li>'."\n";
12566: }
12567: }
12568: if ($replicationfail) {
12569: $output .= '<p class="LC_error">'.
12570: &mt('Course home server failed to retrieve:').'<ul>'.
12571: $replicationfail.
12572: '</ul></p>';
12573: }
12574: }
1.1055 raeburn 12575: } else {
12576: $warning = &mt('No items found in archive.');
12577: }
12578: if ($error) {
12579: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12580: $error.'</p>'."\n";
12581: }
12582: if ($warning) {
12583: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12584: }
12585: return $output;
12586: }
12587:
1.1066 raeburn 12588: sub cleanup_empty_dirs {
12589: my ($path) = @_;
12590: if (($path ne '') && (-d $path)) {
12591: if (opendir(my $dirh,$path)) {
12592: my @dircontents = grep(!/^\./,readdir($dirh));
12593: my $numitems = 0;
12594: foreach my $item (@dircontents) {
12595: if (-d "$path/$item") {
1.1111 raeburn 12596: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12597: if (-e "$path/$item") {
12598: $numitems ++;
12599: }
12600: } else {
12601: $numitems ++;
12602: }
12603: }
12604: if ($numitems == 0) {
12605: rmdir($path);
12606: }
12607: closedir($dirh);
12608: }
12609: }
12610: return;
12611: }
12612:
1.41 ng 12613: =pod
1.45 matthew 12614:
1.1162 raeburn 12615: =item * &get_folder_hierarchy()
1.1068 raeburn 12616:
12617: Provides hierarchy of names of folders/sub-folders containing the current
12618: item,
12619:
12620: Inputs: 3
12621: - $navmap - navmaps object
12622:
12623: - $map - url for map (either the trigger itself, or map containing
12624: the resource, which is the trigger).
12625:
12626: - $showitem - 1 => show title for map itself; 0 => do not show.
12627:
12628: Outputs: 1 @pathitems - array of folder/subfolder names.
12629:
12630: =cut
12631:
12632: sub get_folder_hierarchy {
12633: my ($navmap,$map,$showitem) = @_;
12634: my @pathitems;
12635: if (ref($navmap)) {
12636: my $mapres = $navmap->getResourceByUrl($map);
12637: if (ref($mapres)) {
12638: my $pcslist = $mapres->map_hierarchy();
12639: if ($pcslist ne '') {
12640: my @pcs = split(/,/,$pcslist);
12641: foreach my $pc (@pcs) {
12642: if ($pc == 1) {
1.1129 raeburn 12643: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12644: } else {
12645: my $res = $navmap->getByMapPc($pc);
12646: if (ref($res)) {
12647: my $title = $res->compTitle();
12648: $title =~ s/\W+/_/g;
12649: if ($title ne '') {
12650: push(@pathitems,$title);
12651: }
12652: }
12653: }
12654: }
12655: }
1.1071 raeburn 12656: if ($showitem) {
12657: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12658: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12659: } else {
12660: my $maptitle = $mapres->compTitle();
12661: $maptitle =~ s/\W+/_/g;
12662: if ($maptitle ne '') {
12663: push(@pathitems,$maptitle);
12664: }
1.1068 raeburn 12665: }
12666: }
12667: }
12668: }
12669: return @pathitems;
12670: }
12671:
12672: =pod
12673:
1.1015 raeburn 12674: =item * &get_turnedin_filepath()
12675:
12676: Determines path in a user's portfolio file for storage of files uploaded
12677: to a specific essayresponse or dropbox item.
12678:
12679: Inputs: 3 required + 1 optional.
12680: $symb is symb for resource, $uname and $udom are for current user (required).
12681: $caller is optional (can be "submission", if routine is called when storing
12682: an upoaded file when "Submit Answer" button was pressed).
12683:
12684: Returns array containing $path and $multiresp.
12685: $path is path in portfolio. $multiresp is 1 if this resource contains more
12686: than one file upload item. Callers of routine should append partid as a
12687: subdirectory to $path in cases where $multiresp is 1.
12688:
12689: Called by: homework/essayresponse.pm and homework/structuretags.pm
12690:
12691: =cut
12692:
12693: sub get_turnedin_filepath {
12694: my ($symb,$uname,$udom,$caller) = @_;
12695: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12696: my $turnindir;
12697: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12698: $turnindir = $userhash{'turnindir'};
12699: my ($path,$multiresp);
12700: if ($turnindir eq '') {
12701: if ($caller eq 'submission') {
12702: $turnindir = &mt('turned in');
12703: $turnindir =~ s/\W+/_/g;
12704: my %newhash = (
12705: 'turnindir' => $turnindir,
12706: );
12707: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12708: }
12709: }
12710: if ($turnindir ne '') {
12711: $path = '/'.$turnindir.'/';
12712: my ($multipart,$turnin,@pathitems);
12713: my $navmap = Apache::lonnavmaps::navmap->new();
12714: if (defined($navmap)) {
12715: my $mapres = $navmap->getResourceByUrl($map);
12716: if (ref($mapres)) {
12717: my $pcslist = $mapres->map_hierarchy();
12718: if ($pcslist ne '') {
12719: foreach my $pc (split(/,/,$pcslist)) {
12720: my $res = $navmap->getByMapPc($pc);
12721: if (ref($res)) {
12722: my $title = $res->compTitle();
12723: $title =~ s/\W+/_/g;
12724: if ($title ne '') {
1.1149 raeburn 12725: if (($pc > 1) && (length($title) > 12)) {
12726: $title = substr($title,0,12);
12727: }
1.1015 raeburn 12728: push(@pathitems,$title);
12729: }
12730: }
12731: }
12732: }
12733: my $maptitle = $mapres->compTitle();
12734: $maptitle =~ s/\W+/_/g;
12735: if ($maptitle ne '') {
1.1149 raeburn 12736: if (length($maptitle) > 12) {
12737: $maptitle = substr($maptitle,0,12);
12738: }
1.1015 raeburn 12739: push(@pathitems,$maptitle);
12740: }
12741: unless ($env{'request.state'} eq 'construct') {
12742: my $res = $navmap->getBySymb($symb);
12743: if (ref($res)) {
12744: my $partlist = $res->parts();
12745: my $totaluploads = 0;
12746: if (ref($partlist) eq 'ARRAY') {
12747: foreach my $part (@{$partlist}) {
12748: my @types = $res->responseType($part);
12749: my @ids = $res->responseIds($part);
12750: for (my $i=0; $i < scalar(@ids); $i++) {
12751: if ($types[$i] eq 'essay') {
12752: my $partid = $part.'_'.$ids[$i];
12753: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12754: $totaluploads ++;
12755: }
12756: }
12757: }
12758: }
12759: if ($totaluploads > 1) {
12760: $multiresp = 1;
12761: }
12762: }
12763: }
12764: }
12765: } else {
12766: return;
12767: }
12768: } else {
12769: return;
12770: }
12771: my $restitle=&Apache::lonnet::gettitle($symb);
12772: $restitle =~ s/\W+/_/g;
12773: if ($restitle eq '') {
12774: $restitle = ($resurl =~ m{/[^/]+$});
12775: if ($restitle eq '') {
12776: $restitle = time;
12777: }
12778: }
1.1149 raeburn 12779: if (length($restitle) > 12) {
12780: $restitle = substr($restitle,0,12);
12781: }
1.1015 raeburn 12782: push(@pathitems,$restitle);
12783: $path .= join('/',@pathitems);
12784: }
12785: return ($path,$multiresp);
12786: }
12787:
12788: =pod
12789:
1.464 albertel 12790: =back
1.41 ng 12791:
1.112 bowersj2 12792: =head1 CSV Upload/Handling functions
1.38 albertel 12793:
1.41 ng 12794: =over 4
12795:
1.648 raeburn 12796: =item * &upfile_store($r)
1.41 ng 12797:
12798: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12799: needs $env{'form.upfile'}
1.41 ng 12800: returns $datatoken to be put into hidden field
12801:
12802: =cut
1.31 albertel 12803:
12804: sub upfile_store {
12805: my $r=shift;
1.258 albertel 12806: $env{'form.upfile'}=~s/\r/\n/gs;
12807: $env{'form.upfile'}=~s/\f/\n/gs;
12808: $env{'form.upfile'}=~s/\n+/\n/gs;
12809: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12810:
1.258 albertel 12811: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12812: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12813: {
1.158 raeburn 12814: my $datafile = $r->dir_config('lonDaemons').
12815: '/tmp/'.$datatoken.'.tmp';
12816: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12817: print $fh $env{'form.upfile'};
1.158 raeburn 12818: close($fh);
12819: }
1.31 albertel 12820: }
12821: return $datatoken;
12822: }
12823:
1.56 matthew 12824: =pod
12825:
1.648 raeburn 12826: =item * &load_tmp_file($r)
1.41 ng 12827:
12828: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12829: needs $env{'form.datatoken'},
12830: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12831:
12832: =cut
1.31 albertel 12833:
12834: sub load_tmp_file {
12835: my $r=shift;
12836: my @studentdata=();
12837: {
1.158 raeburn 12838: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12839: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12840: if ( open(my $fh,"<$studentfile") ) {
12841: @studentdata=<$fh>;
12842: close($fh);
12843: }
1.31 albertel 12844: }
1.258 albertel 12845: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12846: }
12847:
1.56 matthew 12848: =pod
12849:
1.648 raeburn 12850: =item * &upfile_record_sep()
1.41 ng 12851:
12852: Separate uploaded file into records
12853: returns array of records,
1.258 albertel 12854: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12855:
12856: =cut
1.31 albertel 12857:
12858: sub upfile_record_sep {
1.258 albertel 12859: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12860: } else {
1.248 albertel 12861: my @records;
1.258 albertel 12862: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12863: if ($line=~/^\s*$/) { next; }
12864: push(@records,$line);
12865: }
12866: return @records;
1.31 albertel 12867: }
12868: }
12869:
1.56 matthew 12870: =pod
12871:
1.648 raeburn 12872: =item * &record_sep($record)
1.41 ng 12873:
1.258 albertel 12874: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12875:
12876: =cut
12877:
1.263 www 12878: sub takeleft {
12879: my $index=shift;
12880: return substr('0000'.$index,-4,4);
12881: }
12882:
1.31 albertel 12883: sub record_sep {
12884: my $record=shift;
12885: my %components=();
1.258 albertel 12886: if ($env{'form.upfiletype'} eq 'xml') {
12887: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12888: my $i=0;
1.356 albertel 12889: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12890: $field=~s/^(\"|\')//;
12891: $field=~s/(\"|\')$//;
1.263 www 12892: $components{&takeleft($i)}=$field;
1.31 albertel 12893: $i++;
12894: }
1.258 albertel 12895: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12896: my $i=0;
1.356 albertel 12897: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12898: $field=~s/^(\"|\')//;
12899: $field=~s/(\"|\')$//;
1.263 www 12900: $components{&takeleft($i)}=$field;
1.31 albertel 12901: $i++;
12902: }
12903: } else {
1.561 www 12904: my $separator=',';
1.480 banghart 12905: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12906: $separator=';';
1.480 banghart 12907: }
1.31 albertel 12908: my $i=0;
1.561 www 12909: # the character we are looking for to indicate the end of a quote or a record
12910: my $looking_for=$separator;
12911: # do not add the characters to the fields
12912: my $ignore=0;
12913: # we just encountered a separator (or the beginning of the record)
12914: my $just_found_separator=1;
12915: # store the field we are working on here
12916: my $field='';
12917: # work our way through all characters in record
12918: foreach my $character ($record=~/(.)/g) {
12919: if ($character eq $looking_for) {
12920: if ($character ne $separator) {
12921: # Found the end of a quote, again looking for separator
12922: $looking_for=$separator;
12923: $ignore=1;
12924: } else {
12925: # Found a separator, store away what we got
12926: $components{&takeleft($i)}=$field;
12927: $i++;
12928: $just_found_separator=1;
12929: $ignore=0;
12930: $field='';
12931: }
12932: next;
12933: }
12934: # single or double quotation marks after a separator indicate beginning of a quote
12935: # we are now looking for the end of the quote and need to ignore separators
12936: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12937: $looking_for=$character;
12938: next;
12939: }
12940: # ignore would be true after we reached the end of a quote
12941: if ($ignore) { next; }
12942: if (($just_found_separator) && ($character=~/\s/)) { next; }
12943: $field.=$character;
12944: $just_found_separator=0;
1.31 albertel 12945: }
1.561 www 12946: # catch the very last entry, since we never encountered the separator
12947: $components{&takeleft($i)}=$field;
1.31 albertel 12948: }
12949: return %components;
12950: }
12951:
1.144 matthew 12952: ######################################################
12953: ######################################################
12954:
1.56 matthew 12955: =pod
12956:
1.648 raeburn 12957: =item * &upfile_select_html()
1.41 ng 12958:
1.144 matthew 12959: Return HTML code to select a file from the users machine and specify
12960: the file type.
1.41 ng 12961:
12962: =cut
12963:
1.144 matthew 12964: ######################################################
12965: ######################################################
1.31 albertel 12966: sub upfile_select_html {
1.144 matthew 12967: my %Types = (
12968: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12969: semisv => &mt('Semicolon separated values'),
1.144 matthew 12970: space => &mt('Space separated'),
12971: tab => &mt('Tabulator separated'),
12972: # xml => &mt('HTML/XML'),
12973: );
12974: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12975: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12976: foreach my $type (sort(keys(%Types))) {
12977: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12978: }
12979: $Str .= "</select>\n";
12980: return $Str;
1.31 albertel 12981: }
12982:
1.301 albertel 12983: sub get_samples {
12984: my ($records,$toget) = @_;
12985: my @samples=({});
12986: my $got=0;
12987: foreach my $rec (@$records) {
12988: my %temp = &record_sep($rec);
12989: if (! grep(/\S/, values(%temp))) { next; }
12990: if (%temp) {
12991: $samples[$got]=\%temp;
12992: $got++;
12993: if ($got == $toget) { last; }
12994: }
12995: }
12996: return \@samples;
12997: }
12998:
1.144 matthew 12999: ######################################################
13000: ######################################################
13001:
1.56 matthew 13002: =pod
13003:
1.648 raeburn 13004: =item * &csv_print_samples($r,$records)
1.41 ng 13005:
13006: Prints a table of sample values from each column uploaded $r is an
13007: Apache Request ref, $records is an arrayref from
13008: &Apache::loncommon::upfile_record_sep
13009:
13010: =cut
13011:
1.144 matthew 13012: ######################################################
13013: ######################################################
1.31 albertel 13014: sub csv_print_samples {
13015: my ($r,$records) = @_;
1.662 bisitz 13016: my $samples = &get_samples($records,5);
1.301 albertel 13017:
1.594 raeburn 13018: $r->print(&mt('Samples').'<br />'.&start_data_table().
13019: &start_data_table_header_row());
1.356 albertel 13020: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13021: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13022: $r->print(&end_data_table_header_row());
1.301 albertel 13023: foreach my $hash (@$samples) {
1.594 raeburn 13024: $r->print(&start_data_table_row());
1.356 albertel 13025: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13026: $r->print('<td>');
1.356 albertel 13027: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13028: $r->print('</td>');
13029: }
1.594 raeburn 13030: $r->print(&end_data_table_row());
1.31 albertel 13031: }
1.594 raeburn 13032: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13033: }
13034:
1.144 matthew 13035: ######################################################
13036: ######################################################
13037:
1.56 matthew 13038: =pod
13039:
1.648 raeburn 13040: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13041:
13042: Prints a table to create associations between values and table columns.
1.144 matthew 13043:
1.41 ng 13044: $r is an Apache Request ref,
13045: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13046: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13047:
13048: =cut
13049:
1.144 matthew 13050: ######################################################
13051: ######################################################
1.31 albertel 13052: sub csv_print_select_table {
13053: my ($r,$records,$d) = @_;
1.301 albertel 13054: my $i=0;
13055: my $samples = &get_samples($records,1);
1.144 matthew 13056: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13057: &start_data_table().&start_data_table_header_row().
1.144 matthew 13058: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13059: '<th>'.&mt('Column').'</th>'.
13060: &end_data_table_header_row()."\n");
1.356 albertel 13061: foreach my $array_ref (@$d) {
13062: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13063: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13064:
1.875 bisitz 13065: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13066: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13067: $r->print('<option value="none"></option>');
1.356 albertel 13068: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13069: $r->print('<option value="'.$sample.'"'.
13070: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13071: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13072: }
1.594 raeburn 13073: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13074: $i++;
13075: }
1.594 raeburn 13076: $r->print(&end_data_table());
1.31 albertel 13077: $i--;
13078: return $i;
13079: }
1.56 matthew 13080:
1.144 matthew 13081: ######################################################
13082: ######################################################
13083:
1.56 matthew 13084: =pod
1.31 albertel 13085:
1.648 raeburn 13086: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13087:
13088: Prints a table of sample values from the upload and can make associate samples to internal names.
13089:
13090: $r is an Apache Request ref,
13091: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13092: $d is an array of 2 element arrays (internal name, displayed name)
13093:
13094: =cut
13095:
1.144 matthew 13096: ######################################################
13097: ######################################################
1.31 albertel 13098: sub csv_samples_select_table {
13099: my ($r,$records,$d) = @_;
13100: my $i=0;
1.144 matthew 13101: #
1.662 bisitz 13102: my $max_samples = 5;
13103: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13104: $r->print(&start_data_table().
13105: &start_data_table_header_row().'<th>'.
13106: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13107: &end_data_table_header_row());
1.301 albertel 13108:
13109: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13110: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13111: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13112: foreach my $option (@$d) {
13113: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13114: $r->print('<option value="'.$value.'"'.
1.253 albertel 13115: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13116: $display.'</option>');
1.31 albertel 13117: }
13118: $r->print('</select></td><td>');
1.662 bisitz 13119: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13120: if (defined($samples->[$line]{$key})) {
13121: $r->print($samples->[$line]{$key}."<br />\n");
13122: }
13123: }
1.594 raeburn 13124: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13125: $i++;
13126: }
1.594 raeburn 13127: $r->print(&end_data_table());
1.31 albertel 13128: $i--;
13129: return($i);
1.115 matthew 13130: }
13131:
1.144 matthew 13132: ######################################################
13133: ######################################################
13134:
1.115 matthew 13135: =pod
13136:
1.648 raeburn 13137: =item * &clean_excel_name($name)
1.115 matthew 13138:
13139: Returns a replacement for $name which does not contain any illegal characters.
13140:
13141: =cut
13142:
1.144 matthew 13143: ######################################################
13144: ######################################################
1.115 matthew 13145: sub clean_excel_name {
13146: my ($name) = @_;
13147: $name =~ s/[:\*\?\/\\]//g;
13148: if (length($name) > 31) {
13149: $name = substr($name,0,31);
13150: }
13151: return $name;
1.25 albertel 13152: }
1.84 albertel 13153:
1.85 albertel 13154: =pod
13155:
1.648 raeburn 13156: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13157:
13158: Returns either 1 or undef
13159:
13160: 1 if the part is to be hidden, undef if it is to be shown
13161:
13162: Arguments are:
13163:
13164: $id the id of the part to be checked
13165: $symb, optional the symb of the resource to check
13166: $udom, optional the domain of the user to check for
13167: $uname, optional the username of the user to check for
13168:
13169: =cut
1.84 albertel 13170:
13171: sub check_if_partid_hidden {
13172: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13173: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13174: $symb,$udom,$uname);
1.141 albertel 13175: my $truth=1;
13176: #if the string starts with !, then the list is the list to show not hide
13177: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13178: my @hiddenlist=split(/,/,$hiddenparts);
13179: foreach my $checkid (@hiddenlist) {
1.141 albertel 13180: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13181: }
1.141 albertel 13182: return !$truth;
1.84 albertel 13183: }
1.127 matthew 13184:
1.138 matthew 13185:
13186: ############################################################
13187: ############################################################
13188:
13189: =pod
13190:
1.157 matthew 13191: =back
13192:
1.138 matthew 13193: =head1 cgi-bin script and graphing routines
13194:
1.157 matthew 13195: =over 4
13196:
1.648 raeburn 13197: =item * &get_cgi_id()
1.138 matthew 13198:
13199: Inputs: none
13200:
13201: Returns an id which can be used to pass environment variables
13202: to various cgi-bin scripts. These environment variables will
13203: be removed from the users environment after a given time by
13204: the routine &Apache::lonnet::transfer_profile_to_env.
13205:
13206: =cut
13207:
13208: ############################################################
13209: ############################################################
1.152 albertel 13210: my $uniq=0;
1.136 matthew 13211: sub get_cgi_id {
1.154 albertel 13212: $uniq=($uniq+1)%100000;
1.280 albertel 13213: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13214: }
13215:
1.127 matthew 13216: ############################################################
13217: ############################################################
13218:
13219: =pod
13220:
1.648 raeburn 13221: =item * &DrawBarGraph()
1.127 matthew 13222:
1.138 matthew 13223: Facilitates the plotting of data in a (stacked) bar graph.
13224: Puts plot definition data into the users environment in order for
13225: graph.png to plot it. Returns an <img> tag for the plot.
13226: The bars on the plot are labeled '1','2',...,'n'.
13227:
13228: Inputs:
13229:
13230: =over 4
13231:
13232: =item $Title: string, the title of the plot
13233:
13234: =item $xlabel: string, text describing the X-axis of the plot
13235:
13236: =item $ylabel: string, text describing the Y-axis of the plot
13237:
13238: =item $Max: scalar, the maximum Y value to use in the plot
13239: If $Max is < any data point, the graph will not be rendered.
13240:
1.140 matthew 13241: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13242: they are plotted. If undefined, default values will be used.
13243:
1.178 matthew 13244: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13245:
1.138 matthew 13246: =item @Values: An array of array references. Each array reference holds data
13247: to be plotted in a stacked bar chart.
13248:
1.239 matthew 13249: =item If the final element of @Values is a hash reference the key/value
13250: pairs will be added to the graph definition.
13251:
1.138 matthew 13252: =back
13253:
13254: Returns:
13255:
13256: An <img> tag which references graph.png and the appropriate identifying
13257: information for the plot.
13258:
1.127 matthew 13259: =cut
13260:
13261: ############################################################
13262: ############################################################
1.134 matthew 13263: sub DrawBarGraph {
1.178 matthew 13264: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13265: #
13266: if (! defined($colors)) {
13267: $colors = ['#33ff00',
13268: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13269: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13270: ];
13271: }
1.228 matthew 13272: my $extra_settings = {};
13273: if (ref($Values[-1]) eq 'HASH') {
13274: $extra_settings = pop(@Values);
13275: }
1.127 matthew 13276: #
1.136 matthew 13277: my $identifier = &get_cgi_id();
13278: my $id = 'cgi.'.$identifier;
1.129 matthew 13279: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13280: return '';
13281: }
1.225 matthew 13282: #
13283: my @Labels;
13284: if (defined($labels)) {
13285: @Labels = @$labels;
13286: } else {
13287: for (my $i=0;$i<@{$Values[0]};$i++) {
13288: push (@Labels,$i+1);
13289: }
13290: }
13291: #
1.129 matthew 13292: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13293: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13294: my %ValuesHash;
13295: my $NumSets=1;
13296: foreach my $array (@Values) {
13297: next if (! ref($array));
1.136 matthew 13298: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13299: join(',',@$array);
1.129 matthew 13300: }
1.127 matthew 13301: #
1.136 matthew 13302: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13303: if ($NumBars < 3) {
13304: $width = 120+$NumBars*32;
1.220 matthew 13305: $xskip = 1;
1.225 matthew 13306: $bar_width = 30;
13307: } elsif ($NumBars < 5) {
13308: $width = 120+$NumBars*20;
13309: $xskip = 1;
13310: $bar_width = 20;
1.220 matthew 13311: } elsif ($NumBars < 10) {
1.136 matthew 13312: $width = 120+$NumBars*15;
13313: $xskip = 1;
13314: $bar_width = 15;
13315: } elsif ($NumBars <= 25) {
13316: $width = 120+$NumBars*11;
13317: $xskip = 5;
13318: $bar_width = 8;
13319: } elsif ($NumBars <= 50) {
13320: $width = 120+$NumBars*8;
13321: $xskip = 5;
13322: $bar_width = 4;
13323: } else {
13324: $width = 120+$NumBars*8;
13325: $xskip = 5;
13326: $bar_width = 4;
13327: }
13328: #
1.137 matthew 13329: $Max = 1 if ($Max < 1);
13330: if ( int($Max) < $Max ) {
13331: $Max++;
13332: $Max = int($Max);
13333: }
1.127 matthew 13334: $Title = '' if (! defined($Title));
13335: $xlabel = '' if (! defined($xlabel));
13336: $ylabel = '' if (! defined($ylabel));
1.369 www 13337: $ValuesHash{$id.'.title'} = &escape($Title);
13338: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13339: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13340: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13341: $ValuesHash{$id.'.NumBars'} = $NumBars;
13342: $ValuesHash{$id.'.NumSets'} = $NumSets;
13343: $ValuesHash{$id.'.PlotType'} = 'bar';
13344: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13345: $ValuesHash{$id.'.height'} = $height;
13346: $ValuesHash{$id.'.width'} = $width;
13347: $ValuesHash{$id.'.xskip'} = $xskip;
13348: $ValuesHash{$id.'.bar_width'} = $bar_width;
13349: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13350: #
1.228 matthew 13351: # Deal with other parameters
13352: while (my ($key,$value) = each(%$extra_settings)) {
13353: $ValuesHash{$id.'.'.$key} = $value;
13354: }
13355: #
1.646 raeburn 13356: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13357: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13358: }
13359:
13360: ############################################################
13361: ############################################################
13362:
13363: =pod
13364:
1.648 raeburn 13365: =item * &DrawXYGraph()
1.137 matthew 13366:
1.138 matthew 13367: Facilitates the plotting of data in an XY graph.
13368: Puts plot definition data into the users environment in order for
13369: graph.png to plot it. Returns an <img> tag for the plot.
13370:
13371: Inputs:
13372:
13373: =over 4
13374:
13375: =item $Title: string, the title of the plot
13376:
13377: =item $xlabel: string, text describing the X-axis of the plot
13378:
13379: =item $ylabel: string, text describing the Y-axis of the plot
13380:
13381: =item $Max: scalar, the maximum Y value to use in the plot
13382: If $Max is < any data point, the graph will not be rendered.
13383:
13384: =item $colors: Array ref containing the hex color codes for the data to be
13385: plotted in. If undefined, default values will be used.
13386:
13387: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13388:
13389: =item $Ydata: Array ref containing Array refs.
1.185 www 13390: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13391:
13392: =item %Values: hash indicating or overriding any default values which are
13393: passed to graph.png.
13394: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13395:
13396: =back
13397:
13398: Returns:
13399:
13400: An <img> tag which references graph.png and the appropriate identifying
13401: information for the plot.
13402:
1.137 matthew 13403: =cut
13404:
13405: ############################################################
13406: ############################################################
13407: sub DrawXYGraph {
13408: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13409: #
13410: # Create the identifier for the graph
13411: my $identifier = &get_cgi_id();
13412: my $id = 'cgi.'.$identifier;
13413: #
13414: $Title = '' if (! defined($Title));
13415: $xlabel = '' if (! defined($xlabel));
13416: $ylabel = '' if (! defined($ylabel));
13417: my %ValuesHash =
13418: (
1.369 www 13419: $id.'.title' => &escape($Title),
13420: $id.'.xlabel' => &escape($xlabel),
13421: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13422: $id.'.y_max_value'=> $Max,
13423: $id.'.labels' => join(',',@$Xlabels),
13424: $id.'.PlotType' => 'XY',
13425: );
13426: #
13427: if (defined($colors) && ref($colors) eq 'ARRAY') {
13428: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13429: }
13430: #
13431: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13432: return '';
13433: }
13434: my $NumSets=1;
1.138 matthew 13435: foreach my $array (@{$Ydata}){
1.137 matthew 13436: next if (! ref($array));
13437: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13438: }
1.138 matthew 13439: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13440: #
13441: # Deal with other parameters
13442: while (my ($key,$value) = each(%Values)) {
13443: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13444: }
13445: #
1.646 raeburn 13446: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13447: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13448: }
13449:
13450: ############################################################
13451: ############################################################
13452:
13453: =pod
13454:
1.648 raeburn 13455: =item * &DrawXYYGraph()
1.138 matthew 13456:
13457: Facilitates the plotting of data in an XY graph with two Y axes.
13458: Puts plot definition data into the users environment in order for
13459: graph.png to plot it. Returns an <img> tag for the plot.
13460:
13461: Inputs:
13462:
13463: =over 4
13464:
13465: =item $Title: string, the title of the plot
13466:
13467: =item $xlabel: string, text describing the X-axis of the plot
13468:
13469: =item $ylabel: string, text describing the Y-axis of the plot
13470:
13471: =item $colors: Array ref containing the hex color codes for the data to be
13472: plotted in. If undefined, default values will be used.
13473:
13474: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13475:
13476: =item $Ydata1: The first data set
13477:
13478: =item $Min1: The minimum value of the left Y-axis
13479:
13480: =item $Max1: The maximum value of the left Y-axis
13481:
13482: =item $Ydata2: The second data set
13483:
13484: =item $Min2: The minimum value of the right Y-axis
13485:
13486: =item $Max2: The maximum value of the left Y-axis
13487:
13488: =item %Values: hash indicating or overriding any default values which are
13489: passed to graph.png.
13490: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13491:
13492: =back
13493:
13494: Returns:
13495:
13496: An <img> tag which references graph.png and the appropriate identifying
13497: information for the plot.
1.136 matthew 13498:
13499: =cut
13500:
13501: ############################################################
13502: ############################################################
1.137 matthew 13503: sub DrawXYYGraph {
13504: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13505: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13506: #
13507: # Create the identifier for the graph
13508: my $identifier = &get_cgi_id();
13509: my $id = 'cgi.'.$identifier;
13510: #
13511: $Title = '' if (! defined($Title));
13512: $xlabel = '' if (! defined($xlabel));
13513: $ylabel = '' if (! defined($ylabel));
13514: my %ValuesHash =
13515: (
1.369 www 13516: $id.'.title' => &escape($Title),
13517: $id.'.xlabel' => &escape($xlabel),
13518: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13519: $id.'.labels' => join(',',@$Xlabels),
13520: $id.'.PlotType' => 'XY',
13521: $id.'.NumSets' => 2,
1.137 matthew 13522: $id.'.two_axes' => 1,
13523: $id.'.y1_max_value' => $Max1,
13524: $id.'.y1_min_value' => $Min1,
13525: $id.'.y2_max_value' => $Max2,
13526: $id.'.y2_min_value' => $Min2,
1.136 matthew 13527: );
13528: #
1.137 matthew 13529: if (defined($colors) && ref($colors) eq 'ARRAY') {
13530: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13531: }
13532: #
13533: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13534: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13535: return '';
13536: }
13537: my $NumSets=1;
1.137 matthew 13538: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13539: next if (! ref($array));
13540: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13541: }
13542: #
13543: # Deal with other parameters
13544: while (my ($key,$value) = each(%Values)) {
13545: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13546: }
13547: #
1.646 raeburn 13548: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13549: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13550: }
13551:
13552: ############################################################
13553: ############################################################
13554:
13555: =pod
13556:
1.157 matthew 13557: =back
13558:
1.139 matthew 13559: =head1 Statistics helper routines?
13560:
13561: Bad place for them but what the hell.
13562:
1.157 matthew 13563: =over 4
13564:
1.648 raeburn 13565: =item * &chartlink()
1.139 matthew 13566:
13567: Returns a link to the chart for a specific student.
13568:
13569: Inputs:
13570:
13571: =over 4
13572:
13573: =item $linktext: The text of the link
13574:
13575: =item $sname: The students username
13576:
13577: =item $sdomain: The students domain
13578:
13579: =back
13580:
1.157 matthew 13581: =back
13582:
1.139 matthew 13583: =cut
13584:
13585: ############################################################
13586: ############################################################
13587: sub chartlink {
13588: my ($linktext, $sname, $sdomain) = @_;
13589: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13590: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13591: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13592: '">'.$linktext.'</a>';
1.153 matthew 13593: }
13594:
13595: #######################################################
13596: #######################################################
13597:
13598: =pod
13599:
13600: =head1 Course Environment Routines
1.157 matthew 13601:
13602: =over 4
1.153 matthew 13603:
1.648 raeburn 13604: =item * &restore_course_settings()
1.153 matthew 13605:
1.648 raeburn 13606: =item * &store_course_settings()
1.153 matthew 13607:
13608: Restores/Store indicated form parameters from the course environment.
13609: Will not overwrite existing values of the form parameters.
13610:
13611: Inputs:
13612: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13613:
13614: a hash ref describing the data to be stored. For example:
13615:
13616: %Save_Parameters = ('Status' => 'scalar',
13617: 'chartoutputmode' => 'scalar',
13618: 'chartoutputdata' => 'scalar',
13619: 'Section' => 'array',
1.373 raeburn 13620: 'Group' => 'array',
1.153 matthew 13621: 'StudentData' => 'array',
13622: 'Maps' => 'array');
13623:
13624: Returns: both routines return nothing
13625:
1.631 raeburn 13626: =back
13627:
1.153 matthew 13628: =cut
13629:
13630: #######################################################
13631: #######################################################
13632: sub store_course_settings {
1.496 albertel 13633: return &store_settings($env{'request.course.id'},@_);
13634: }
13635:
13636: sub store_settings {
1.153 matthew 13637: # save to the environment
13638: # appenv the same items, just to be safe
1.300 albertel 13639: my $udom = $env{'user.domain'};
13640: my $uname = $env{'user.name'};
1.496 albertel 13641: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13642: my %SaveHash;
13643: my %AppHash;
13644: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13645: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13646: my $envname = 'environment.'.$basename;
1.258 albertel 13647: if (exists($env{'form.'.$setting})) {
1.153 matthew 13648: # Save this value away
13649: if ($type eq 'scalar' &&
1.258 albertel 13650: (! exists($env{$envname}) ||
13651: $env{$envname} ne $env{'form.'.$setting})) {
13652: $SaveHash{$basename} = $env{'form.'.$setting};
13653: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13654: } elsif ($type eq 'array') {
13655: my $stored_form;
1.258 albertel 13656: if (ref($env{'form.'.$setting})) {
1.153 matthew 13657: $stored_form = join(',',
13658: map {
1.369 www 13659: &escape($_);
1.258 albertel 13660: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13661: } else {
13662: $stored_form =
1.369 www 13663: &escape($env{'form.'.$setting});
1.153 matthew 13664: }
13665: # Determine if the array contents are the same.
1.258 albertel 13666: if ($stored_form ne $env{$envname}) {
1.153 matthew 13667: $SaveHash{$basename} = $stored_form;
13668: $AppHash{$envname} = $stored_form;
13669: }
13670: }
13671: }
13672: }
13673: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13674: $udom,$uname);
1.153 matthew 13675: if ($put_result !~ /^(ok|delayed)/) {
13676: &Apache::lonnet::logthis('unable to save form parameters, '.
13677: 'got error:'.$put_result);
13678: }
13679: # Make sure these settings stick around in this session, too
1.646 raeburn 13680: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13681: return;
13682: }
13683:
13684: sub restore_course_settings {
1.499 albertel 13685: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13686: }
13687:
13688: sub restore_settings {
13689: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13690: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13691: next if (exists($env{'form.'.$setting}));
1.496 albertel 13692: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13693: '.'.$setting;
1.258 albertel 13694: if (exists($env{$envname})) {
1.153 matthew 13695: if ($type eq 'scalar') {
1.258 albertel 13696: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13697: } elsif ($type eq 'array') {
1.258 albertel 13698: $env{'form.'.$setting} = [
1.153 matthew 13699: map {
1.369 www 13700: &unescape($_);
1.258 albertel 13701: } split(',',$env{$envname})
1.153 matthew 13702: ];
13703: }
13704: }
13705: }
1.127 matthew 13706: }
13707:
1.618 raeburn 13708: #######################################################
13709: #######################################################
13710:
13711: =pod
13712:
13713: =head1 Domain E-mail Routines
13714:
13715: =over 4
13716:
1.648 raeburn 13717: =item * &build_recipient_list()
1.618 raeburn 13718:
1.1144 raeburn 13719: Build recipient lists for following types of e-mail:
1.766 raeburn 13720: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13721: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13722: module change checking, student/employee ID conflict checks, as
13723: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13724: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13725:
13726: Inputs:
1.619 raeburn 13727: defmail (scalar - email address of default recipient),
1.1144 raeburn 13728: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13729: requestsmail, updatesmail, or idconflictsmail).
13730:
1.619 raeburn 13731: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13732:
1.619 raeburn 13733: origmail (scalar - email address of recipient from loncapa.conf,
13734: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13735:
1.655 raeburn 13736: Returns: comma separated list of addresses to which to send e-mail.
13737:
13738: =back
1.618 raeburn 13739:
13740: =cut
13741:
13742: ############################################################
13743: ############################################################
13744: sub build_recipient_list {
1.619 raeburn 13745: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13746: my @recipients;
13747: my $otheremails;
13748: my %domconfig =
13749: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13750: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13751: if (exists($domconfig{'contacts'}{$mailing})) {
13752: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13753: my @contacts = ('adminemail','supportemail');
13754: foreach my $item (@contacts) {
13755: if ($domconfig{'contacts'}{$mailing}{$item}) {
13756: my $addr = $domconfig{'contacts'}{$item};
13757: if (!grep(/^\Q$addr\E$/,@recipients)) {
13758: push(@recipients,$addr);
13759: }
1.619 raeburn 13760: }
1.766 raeburn 13761: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13762: }
13763: }
1.766 raeburn 13764: } elsif ($origmail ne '') {
13765: push(@recipients,$origmail);
1.618 raeburn 13766: }
1.619 raeburn 13767: } elsif ($origmail ne '') {
13768: push(@recipients,$origmail);
1.618 raeburn 13769: }
1.688 raeburn 13770: if (defined($defmail)) {
13771: if ($defmail ne '') {
13772: push(@recipients,$defmail);
13773: }
1.618 raeburn 13774: }
13775: if ($otheremails) {
1.619 raeburn 13776: my @others;
13777: if ($otheremails =~ /,/) {
13778: @others = split(/,/,$otheremails);
1.618 raeburn 13779: } else {
1.619 raeburn 13780: push(@others,$otheremails);
13781: }
13782: foreach my $addr (@others) {
13783: if (!grep(/^\Q$addr\E$/,@recipients)) {
13784: push(@recipients,$addr);
13785: }
1.618 raeburn 13786: }
13787: }
1.619 raeburn 13788: my $recipientlist = join(',',@recipients);
1.618 raeburn 13789: return $recipientlist;
13790: }
13791:
1.127 matthew 13792: ############################################################
13793: ############################################################
1.154 albertel 13794:
1.655 raeburn 13795: =pod
13796:
13797: =head1 Course Catalog Routines
13798:
13799: =over 4
13800:
13801: =item * &gather_categories()
13802:
13803: Converts category definitions - keys of categories hash stored in
13804: coursecategories in configuration.db on the primary library server in a
13805: domain - to an array. Also generates javascript and idx hash used to
13806: generate Domain Coordinator interface for editing Course Categories.
13807:
13808: Inputs:
1.663 raeburn 13809:
1.655 raeburn 13810: categories (reference to hash of category definitions).
1.663 raeburn 13811:
1.655 raeburn 13812: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13813: categories and subcategories).
1.663 raeburn 13814:
1.655 raeburn 13815: idx (reference to hash of counters used in Domain Coordinator interface for
13816: editing Course Categories).
1.663 raeburn 13817:
1.655 raeburn 13818: jsarray (reference to array of categories used to create Javascript arrays for
13819: Domain Coordinator interface for editing Course Categories).
13820:
13821: Returns: nothing
13822:
13823: Side effects: populates cats, idx and jsarray.
13824:
13825: =cut
13826:
13827: sub gather_categories {
13828: my ($categories,$cats,$idx,$jsarray) = @_;
13829: my %counters;
13830: my $num = 0;
13831: foreach my $item (keys(%{$categories})) {
13832: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13833: if ($container eq '' && $depth == 0) {
13834: $cats->[$depth][$categories->{$item}] = $cat;
13835: } else {
13836: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13837: }
13838: my ($escitem,$tail) = split(/:/,$item,2);
13839: if ($counters{$tail} eq '') {
13840: $counters{$tail} = $num;
13841: $num ++;
13842: }
13843: if (ref($idx) eq 'HASH') {
13844: $idx->{$item} = $counters{$tail};
13845: }
13846: if (ref($jsarray) eq 'ARRAY') {
13847: push(@{$jsarray->[$counters{$tail}]},$item);
13848: }
13849: }
13850: return;
13851: }
13852:
13853: =pod
13854:
13855: =item * &extract_categories()
13856:
13857: Used to generate breadcrumb trails for course categories.
13858:
13859: Inputs:
1.663 raeburn 13860:
1.655 raeburn 13861: categories (reference to hash of category definitions).
1.663 raeburn 13862:
1.655 raeburn 13863: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13864: categories and subcategories).
1.663 raeburn 13865:
1.655 raeburn 13866: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13867:
1.655 raeburn 13868: allitems (reference to hash - key is category key
13869: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13870:
1.655 raeburn 13871: idx (reference to hash of counters used in Domain Coordinator interface for
13872: editing Course Categories).
1.663 raeburn 13873:
1.655 raeburn 13874: jsarray (reference to array of categories used to create Javascript arrays for
13875: Domain Coordinator interface for editing Course Categories).
13876:
1.665 raeburn 13877: subcats (reference to hash of arrays containing all subcategories within each
13878: category, -recursive)
13879:
1.655 raeburn 13880: Returns: nothing
13881:
13882: Side effects: populates trails and allitems hash references.
13883:
13884: =cut
13885:
13886: sub extract_categories {
1.665 raeburn 13887: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13888: if (ref($categories) eq 'HASH') {
13889: &gather_categories($categories,$cats,$idx,$jsarray);
13890: if (ref($cats->[0]) eq 'ARRAY') {
13891: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13892: my $name = $cats->[0][$i];
13893: my $item = &escape($name).'::0';
13894: my $trailstr;
13895: if ($name eq 'instcode') {
13896: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13897: } elsif ($name eq 'communities') {
13898: $trailstr = &mt('Communities');
1.655 raeburn 13899: } else {
13900: $trailstr = $name;
13901: }
13902: if ($allitems->{$item} eq '') {
13903: push(@{$trails},$trailstr);
13904: $allitems->{$item} = scalar(@{$trails})-1;
13905: }
13906: my @parents = ($name);
13907: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13908: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13909: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13910: if (ref($subcats) eq 'HASH') {
13911: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13912: }
13913: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13914: }
13915: } else {
13916: if (ref($subcats) eq 'HASH') {
13917: $subcats->{$item} = [];
1.655 raeburn 13918: }
13919: }
13920: }
13921: }
13922: }
13923: return;
13924: }
13925:
13926: =pod
13927:
1.1162 raeburn 13928: =item * &recurse_categories()
1.655 raeburn 13929:
13930: Recursively used to generate breadcrumb trails for course categories.
13931:
13932: Inputs:
1.663 raeburn 13933:
1.655 raeburn 13934: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13935: categories and subcategories).
1.663 raeburn 13936:
1.655 raeburn 13937: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13938:
13939: category (current course category, for which breadcrumb trail is being generated).
13940:
13941: trails (reference to array of breadcrumb trails for each category).
13942:
1.655 raeburn 13943: allitems (reference to hash - key is category key
13944: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13945:
1.655 raeburn 13946: parents (array containing containers directories for current category,
13947: back to top level).
13948:
13949: Returns: nothing
13950:
13951: Side effects: populates trails and allitems hash references
13952:
13953: =cut
13954:
13955: sub recurse_categories {
1.665 raeburn 13956: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13957: my $shallower = $depth - 1;
13958: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13959: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13960: my $name = $cats->[$depth]{$category}[$k];
13961: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13962: my $trailstr = join(' -> ',(@{$parents},$category));
13963: if ($allitems->{$item} eq '') {
13964: push(@{$trails},$trailstr);
13965: $allitems->{$item} = scalar(@{$trails})-1;
13966: }
13967: my $deeper = $depth+1;
13968: push(@{$parents},$category);
1.665 raeburn 13969: if (ref($subcats) eq 'HASH') {
13970: my $subcat = &escape($name).':'.$category.':'.$depth;
13971: for (my $j=@{$parents}; $j>=0; $j--) {
13972: my $higher;
13973: if ($j > 0) {
13974: $higher = &escape($parents->[$j]).':'.
13975: &escape($parents->[$j-1]).':'.$j;
13976: } else {
13977: $higher = &escape($parents->[$j]).'::'.$j;
13978: }
13979: push(@{$subcats->{$higher}},$subcat);
13980: }
13981: }
13982: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13983: $subcats);
1.655 raeburn 13984: pop(@{$parents});
13985: }
13986: } else {
13987: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13988: my $trailstr = join(' -> ',(@{$parents},$category));
13989: if ($allitems->{$item} eq '') {
13990: push(@{$trails},$trailstr);
13991: $allitems->{$item} = scalar(@{$trails})-1;
13992: }
13993: }
13994: return;
13995: }
13996:
1.663 raeburn 13997: =pod
13998:
1.1162 raeburn 13999: =item * &assign_categories_table()
1.663 raeburn 14000:
14001: Create a datatable for display of hierarchical categories in a domain,
14002: with checkboxes to allow a course to be categorized.
14003:
14004: Inputs:
14005:
14006: cathash - reference to hash of categories defined for the domain (from
14007: configuration.db)
14008:
14009: currcat - scalar with an & separated list of categories assigned to a course.
14010:
1.919 raeburn 14011: type - scalar contains course type (Course or Community).
14012:
1.663 raeburn 14013: Returns: $output (markup to be displayed)
14014:
14015: =cut
14016:
14017: sub assign_categories_table {
1.919 raeburn 14018: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14019: my $output;
14020: if (ref($cathash) eq 'HASH') {
14021: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14022: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14023: $maxdepth = scalar(@cats);
14024: if (@cats > 0) {
14025: my $itemcount = 0;
14026: if (ref($cats[0]) eq 'ARRAY') {
14027: my @currcategories;
14028: if ($currcat ne '') {
14029: @currcategories = split('&',$currcat);
14030: }
1.919 raeburn 14031: my $table;
1.663 raeburn 14032: for (my $i=0; $i<@{$cats[0]}; $i++) {
14033: my $parent = $cats[0][$i];
1.919 raeburn 14034: next if ($parent eq 'instcode');
14035: if ($type eq 'Community') {
14036: next unless ($parent eq 'communities');
14037: } else {
14038: next if ($parent eq 'communities');
14039: }
1.663 raeburn 14040: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14041: my $item = &escape($parent).'::0';
14042: my $checked = '';
14043: if (@currcategories > 0) {
14044: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14045: $checked = ' checked="checked"';
1.663 raeburn 14046: }
14047: }
1.919 raeburn 14048: my $parent_title = $parent;
14049: if ($parent eq 'communities') {
14050: $parent_title = &mt('Communities');
14051: }
14052: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14053: '<input type="checkbox" name="usecategory" value="'.
14054: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14055: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14056: my $depth = 1;
14057: push(@path,$parent);
1.919 raeburn 14058: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14059: pop(@path);
1.919 raeburn 14060: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14061: $itemcount ++;
14062: }
1.919 raeburn 14063: if ($itemcount) {
14064: $output = &Apache::loncommon::start_data_table().
14065: $table.
14066: &Apache::loncommon::end_data_table();
14067: }
1.663 raeburn 14068: }
14069: }
14070: }
14071: return $output;
14072: }
14073:
14074: =pod
14075:
1.1162 raeburn 14076: =item * &assign_category_rows()
1.663 raeburn 14077:
14078: Create a datatable row for display of nested categories in a domain,
14079: with checkboxes to allow a course to be categorized,called recursively.
14080:
14081: Inputs:
14082:
14083: itemcount - track row number for alternating colors
14084:
14085: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14086: categories and subcategories.
14087:
14088: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14089:
14090: parent - parent of current category item
14091:
14092: path - Array containing all categories back up through the hierarchy from the
14093: current category to the top level.
14094:
14095: currcategories - reference to array of current categories assigned to the course
14096:
14097: Returns: $output (markup to be displayed).
14098:
14099: =cut
14100:
14101: sub assign_category_rows {
14102: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14103: my ($text,$name,$item,$chgstr);
14104: if (ref($cats) eq 'ARRAY') {
14105: my $maxdepth = scalar(@{$cats});
14106: if (ref($cats->[$depth]) eq 'HASH') {
14107: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14108: my $numchildren = @{$cats->[$depth]{$parent}};
14109: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14110: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14111: for (my $j=0; $j<$numchildren; $j++) {
14112: $name = $cats->[$depth]{$parent}[$j];
14113: $item = &escape($name).':'.&escape($parent).':'.$depth;
14114: my $deeper = $depth+1;
14115: my $checked = '';
14116: if (ref($currcategories) eq 'ARRAY') {
14117: if (@{$currcategories} > 0) {
14118: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14119: $checked = ' checked="checked"';
1.663 raeburn 14120: }
14121: }
14122: }
1.664 raeburn 14123: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14124: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14125: $item.'"'.$checked.' />'.$name.'</label></span>'.
14126: '<input type="hidden" name="catname" value="'.$name.'" />'.
14127: '</td><td>';
1.663 raeburn 14128: if (ref($path) eq 'ARRAY') {
14129: push(@{$path},$name);
14130: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14131: pop(@{$path});
14132: }
14133: $text .= '</td></tr>';
14134: }
14135: $text .= '</table></td>';
14136: }
14137: }
14138: }
14139: return $text;
14140: }
14141:
1.1181 raeburn 14142: =pod
14143:
14144: =back
14145:
14146: =cut
14147:
1.655 raeburn 14148: ############################################################
14149: ############################################################
14150:
14151:
1.443 albertel 14152: sub commit_customrole {
1.664 raeburn 14153: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14154: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14155: ($start?', '.&mt('starting').' '.localtime($start):'').
14156: ($end?', ending '.localtime($end):'').': <b>'.
14157: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14158: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14159: '</b><br />';
14160: return $output;
14161: }
14162:
14163: sub commit_standardrole {
1.1116 raeburn 14164: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14165: my ($output,$logmsg,$linefeed);
14166: if ($context eq 'auto') {
14167: $linefeed = "\n";
14168: } else {
14169: $linefeed = "<br />\n";
14170: }
1.443 albertel 14171: if ($three eq 'st') {
1.541 raeburn 14172: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14173: $one,$two,$sec,$context,$credits);
1.541 raeburn 14174: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14175: ($result eq 'unknown_course') || ($result eq 'refused')) {
14176: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14177: } else {
1.541 raeburn 14178: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14179: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14180: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14181: if ($context eq 'auto') {
14182: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14183: } else {
14184: $output .= '<b>'.$result.'</b>'.$linefeed.
14185: &mt('Add to classlist').': <b>ok</b>';
14186: }
14187: $output .= $linefeed;
1.443 albertel 14188: }
14189: } else {
14190: $output = &mt('Assigning').' '.$three.' in '.$url.
14191: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14192: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14193: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14194: if ($context eq 'auto') {
14195: $output .= $result.$linefeed;
14196: } else {
14197: $output .= '<b>'.$result.'</b>'.$linefeed;
14198: }
1.443 albertel 14199: }
14200: return $output;
14201: }
14202:
14203: sub commit_studentrole {
1.1116 raeburn 14204: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14205: $credits) = @_;
1.626 raeburn 14206: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14207: if ($context eq 'auto') {
14208: $linefeed = "\n";
14209: } else {
14210: $linefeed = '<br />'."\n";
14211: }
1.443 albertel 14212: if (defined($one) && defined($two)) {
14213: my $cid=$one.'_'.$two;
14214: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14215: my $secchange = 0;
14216: my $expire_role_result;
14217: my $modify_section_result;
1.628 raeburn 14218: if ($oldsec ne '-1') {
14219: if ($oldsec ne $sec) {
1.443 albertel 14220: $secchange = 1;
1.628 raeburn 14221: my $now = time;
1.443 albertel 14222: my $uurl='/'.$cid;
14223: $uurl=~s/\_/\//g;
14224: if ($oldsec) {
14225: $uurl.='/'.$oldsec;
14226: }
1.626 raeburn 14227: $oldsecurl = $uurl;
1.628 raeburn 14228: $expire_role_result =
1.652 raeburn 14229: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14230: if ($env{'request.course.sec'} ne '') {
14231: if ($expire_role_result eq 'refused') {
14232: my @roles = ('st');
14233: my @statuses = ('previous');
14234: my @roledoms = ($one);
14235: my $withsec = 1;
14236: my %roleshash =
14237: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14238: \@statuses,\@roles,\@roledoms,$withsec);
14239: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14240: my ($oldstart,$oldend) =
14241: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14242: if ($oldend > 0 && $oldend <= $now) {
14243: $expire_role_result = 'ok';
14244: }
14245: }
14246: }
14247: }
1.443 albertel 14248: $result = $expire_role_result;
14249: }
14250: }
14251: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 14252: $modify_section_result =
14253: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14254: undef,undef,undef,$sec,
14255: $end,$start,'','',$cid,
14256: '',$context,$credits);
1.443 albertel 14257: if ($modify_section_result =~ /^ok/) {
14258: if ($secchange == 1) {
1.628 raeburn 14259: if ($sec eq '') {
14260: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14261: } else {
14262: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14263: }
1.443 albertel 14264: } elsif ($oldsec eq '-1') {
1.628 raeburn 14265: if ($sec eq '') {
14266: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14267: } else {
14268: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14269: }
1.443 albertel 14270: } else {
1.628 raeburn 14271: if ($sec eq '') {
14272: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14273: } else {
14274: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14275: }
1.443 albertel 14276: }
14277: } else {
1.1115 raeburn 14278: if ($secchange) {
1.628 raeburn 14279: $$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;
14280: } else {
14281: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14282: }
1.443 albertel 14283: }
14284: $result = $modify_section_result;
14285: } elsif ($secchange == 1) {
1.628 raeburn 14286: if ($oldsec eq '') {
1.1103 raeburn 14287: $$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 14288: } else {
14289: $$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;
14290: }
1.626 raeburn 14291: if ($expire_role_result eq 'refused') {
14292: my $newsecurl = '/'.$cid;
14293: $newsecurl =~ s/\_/\//g;
14294: if ($sec ne '') {
14295: $newsecurl.='/'.$sec;
14296: }
14297: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14298: if ($sec eq '') {
14299: $$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;
14300: } else {
14301: $$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;
14302: }
14303: }
14304: }
1.443 albertel 14305: }
14306: } else {
1.626 raeburn 14307: $$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 14308: $result = "error: incomplete course id\n";
14309: }
14310: return $result;
14311: }
14312:
1.1108 raeburn 14313: sub show_role_extent {
14314: my ($scope,$context,$role) = @_;
14315: $scope =~ s{^/}{};
14316: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14317: push(@courseroles,'co');
14318: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14319: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14320: $scope =~ s{/}{_};
14321: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14322: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14323: my ($audom,$auname) = split(/\//,$scope);
14324: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14325: &Apache::loncommon::plainname($auname,$audom).'</span>');
14326: } else {
14327: $scope =~ s{/$}{};
14328: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14329: &Apache::lonnet::domain($scope,'description').'</span>');
14330: }
14331: }
14332:
1.443 albertel 14333: ############################################################
14334: ############################################################
14335:
1.566 albertel 14336: sub check_clone {
1.578 raeburn 14337: my ($args,$linefeed) = @_;
1.566 albertel 14338: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14339: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14340: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14341: my $clonemsg;
14342: my $can_clone = 0;
1.944 raeburn 14343: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14344: if ($lctype ne 'community') {
14345: $lctype = 'course';
14346: }
1.566 albertel 14347: if ($clonehome eq 'no_host') {
1.944 raeburn 14348: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14349: $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'});
14350: } else {
14351: $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'});
14352: }
1.566 albertel 14353: } else {
14354: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14355: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14356: if ($clonedesc{'type'} ne 'Community') {
14357: $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'});
14358: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14359: }
14360: }
1.882 raeburn 14361: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14362: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14363: $can_clone = 1;
14364: } else {
14365: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
14366: $args->{'clonedomain'},$args->{'clonecourse'});
14367: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 14368: if (grep(/^\*$/,@cloners)) {
14369: $can_clone = 1;
14370: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14371: $can_clone = 1;
14372: } else {
1.908 raeburn 14373: my $ccrole = 'cc';
1.944 raeburn 14374: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14375: $ccrole = 'co';
14376: }
1.578 raeburn 14377: my %roleshash =
14378: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14379: $args->{'ccdomain'},
1.908 raeburn 14380: 'userroles',['active'],[$ccrole],
1.578 raeburn 14381: [$args->{'clonedomain'}]);
1.908 raeburn 14382: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 14383: $can_clone = 1;
14384: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
14385: $can_clone = 1;
14386: } else {
1.944 raeburn 14387: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14388: $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'});
14389: } else {
14390: $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'});
14391: }
1.578 raeburn 14392: }
1.566 albertel 14393: }
1.578 raeburn 14394: }
1.566 albertel 14395: }
14396: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14397: }
14398:
1.444 albertel 14399: sub construct_course {
1.1166 raeburn 14400: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14401: my $outcome;
1.541 raeburn 14402: my $linefeed = '<br />'."\n";
14403: if ($context eq 'auto') {
14404: $linefeed = "\n";
14405: }
1.566 albertel 14406:
14407: #
14408: # Are we cloning?
14409: #
14410: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14411: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14412: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14413: if ($context ne 'auto') {
1.578 raeburn 14414: if ($clonemsg ne '') {
14415: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14416: }
1.566 albertel 14417: }
14418: $outcome .= $clonemsg.$linefeed;
14419:
14420: if (!$can_clone) {
14421: return (0,$outcome);
14422: }
14423: }
14424:
1.444 albertel 14425: #
14426: # Open course
14427: #
14428: my $crstype = lc($args->{'crstype'});
14429: my %cenv=();
14430: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14431: $args->{'cdescr'},
14432: $args->{'curl'},
14433: $args->{'course_home'},
14434: $args->{'nonstandard'},
14435: $args->{'crscode'},
14436: $args->{'ccuname'}.':'.
14437: $args->{'ccdomain'},
1.882 raeburn 14438: $args->{'crstype'},
1.885 raeburn 14439: $cnum,$context,$category);
1.444 albertel 14440:
14441: # Note: The testing routines depend on this being output; see
14442: # Utils::Course. This needs to at least be output as a comment
14443: # if anyone ever decides to not show this, and Utils::Course::new
14444: # will need to be suitably modified.
1.541 raeburn 14445: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14446: if ($$courseid =~ /^error:/) {
14447: return (0,$outcome);
14448: }
14449:
1.444 albertel 14450: #
14451: # Check if created correctly
14452: #
1.479 albertel 14453: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14454: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14455: if ($crsuhome eq 'no_host') {
14456: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14457: return (0,$outcome);
14458: }
1.541 raeburn 14459: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14460:
1.444 albertel 14461: #
1.566 albertel 14462: # Do the cloning
14463: #
14464: if ($can_clone && $cloneid) {
14465: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14466: if ($context ne 'auto') {
14467: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14468: }
14469: $outcome .= $clonemsg.$linefeed;
14470: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14471: # Copy all files
1.637 www 14472: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14473: # Restore URL
1.566 albertel 14474: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14475: # Restore title
1.566 albertel 14476: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14477: # Restore creation date, creator and creation context.
14478: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14479: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14480: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14481: # Mark as cloned
1.566 albertel 14482: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14483: # Need to clone grading mode
14484: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14485: $cenv{'grading'}=$newenv{'grading'};
14486: # Do not clone these environment entries
14487: &Apache::lonnet::del('environment',
14488: ['default_enrollment_start_date',
14489: 'default_enrollment_end_date',
14490: 'question.email',
14491: 'policy.email',
14492: 'comment.email',
14493: 'pch.users.denied',
1.725 raeburn 14494: 'plc.users.denied',
14495: 'hidefromcat',
1.1121 raeburn 14496: 'checkforpriv',
1.1166 raeburn 14497: 'categories',
14498: 'internal.uniquecode'],
1.638 www 14499: $$crsudom,$$crsunum);
1.1170 raeburn 14500: if ($args->{'textbook'}) {
14501: $cenv{'internal.textbook'} = $args->{'textbook'};
14502: }
1.444 albertel 14503: }
1.566 albertel 14504:
1.444 albertel 14505: #
14506: # Set environment (will override cloned, if existing)
14507: #
14508: my @sections = ();
14509: my @xlists = ();
14510: if ($args->{'crstype'}) {
14511: $cenv{'type'}=$args->{'crstype'};
14512: }
14513: if ($args->{'crsid'}) {
14514: $cenv{'courseid'}=$args->{'crsid'};
14515: }
14516: if ($args->{'crscode'}) {
14517: $cenv{'internal.coursecode'}=$args->{'crscode'};
14518: }
14519: if ($args->{'crsquota'} ne '') {
14520: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14521: } else {
14522: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14523: }
14524: if ($args->{'ccuname'}) {
14525: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14526: ':'.$args->{'ccdomain'};
14527: } else {
14528: $cenv{'internal.courseowner'} = $args->{'curruser'};
14529: }
1.1116 raeburn 14530: if ($args->{'defaultcredits'}) {
14531: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14532: }
1.444 albertel 14533: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14534: if ($args->{'crssections'}) {
14535: $cenv{'internal.sectionnums'} = '';
14536: if ($args->{'crssections'} =~ m/,/) {
14537: @sections = split/,/,$args->{'crssections'};
14538: } else {
14539: $sections[0] = $args->{'crssections'};
14540: }
14541: if (@sections > 0) {
14542: foreach my $item (@sections) {
14543: my ($sec,$gp) = split/:/,$item;
14544: my $class = $args->{'crscode'}.$sec;
14545: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14546: $cenv{'internal.sectionnums'} .= $item.',';
14547: unless ($addcheck eq 'ok') {
14548: push @badclasses, $class;
14549: }
14550: }
14551: $cenv{'internal.sectionnums'} =~ s/,$//;
14552: }
14553: }
14554: # do not hide course coordinator from staff listing,
14555: # even if privileged
14556: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14557: # add course coordinator's domain to domains to check for privileged users
14558: # if different to course domain
14559: if ($$crsudom ne $args->{'ccdomain'}) {
14560: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14561: }
1.444 albertel 14562: # add crosslistings
14563: if ($args->{'crsxlist'}) {
14564: $cenv{'internal.crosslistings'}='';
14565: if ($args->{'crsxlist'} =~ m/,/) {
14566: @xlists = split/,/,$args->{'crsxlist'};
14567: } else {
14568: $xlists[0] = $args->{'crsxlist'};
14569: }
14570: if (@xlists > 0) {
14571: foreach my $item (@xlists) {
14572: my ($xl,$gp) = split/:/,$item;
14573: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14574: $cenv{'internal.crosslistings'} .= $item.',';
14575: unless ($addcheck eq 'ok') {
14576: push @badclasses, $xl;
14577: }
14578: }
14579: $cenv{'internal.crosslistings'} =~ s/,$//;
14580: }
14581: }
14582: if ($args->{'autoadds'}) {
14583: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14584: }
14585: if ($args->{'autodrops'}) {
14586: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14587: }
14588: # check for notification of enrollment changes
14589: my @notified = ();
14590: if ($args->{'notify_owner'}) {
14591: if ($args->{'ccuname'} ne '') {
14592: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14593: }
14594: }
14595: if ($args->{'notify_dc'}) {
14596: if ($uname ne '') {
1.630 raeburn 14597: push(@notified,$uname.':'.$udom);
1.444 albertel 14598: }
14599: }
14600: if (@notified > 0) {
14601: my $notifylist;
14602: if (@notified > 1) {
14603: $notifylist = join(',',@notified);
14604: } else {
14605: $notifylist = $notified[0];
14606: }
14607: $cenv{'internal.notifylist'} = $notifylist;
14608: }
14609: if (@badclasses > 0) {
14610: my %lt=&Apache::lonlocal::texthash(
14611: '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',
14612: 'dnhr' => 'does not have rights to access enrollment in these classes',
14613: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14614: );
1.541 raeburn 14615: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14616: ' ('.$lt{'adby'}.')';
14617: if ($context eq 'auto') {
14618: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14619: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14620: foreach my $item (@badclasses) {
14621: if ($context eq 'auto') {
14622: $outcome .= " - $item\n";
14623: } else {
14624: $outcome .= "<li>$item</li>\n";
14625: }
14626: }
14627: if ($context eq 'auto') {
14628: $outcome .= $linefeed;
14629: } else {
1.566 albertel 14630: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14631: }
14632: }
1.444 albertel 14633: }
14634: if ($args->{'no_end_date'}) {
14635: $args->{'endaccess'} = 0;
14636: }
14637: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14638: $cenv{'internal.autoend'}=$args->{'enrollend'};
14639: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14640: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14641: if ($args->{'showphotos'}) {
14642: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14643: }
14644: $cenv{'internal.authtype'} = $args->{'authtype'};
14645: $cenv{'internal.autharg'} = $args->{'autharg'};
14646: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14647: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14648: 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');
14649: if ($context eq 'auto') {
14650: $outcome .= $krb_msg;
14651: } else {
1.566 albertel 14652: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14653: }
14654: $outcome .= $linefeed;
1.444 albertel 14655: }
14656: }
14657: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14658: if ($args->{'setpolicy'}) {
14659: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14660: }
14661: if ($args->{'setcontent'}) {
14662: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14663: }
14664: }
14665: if ($args->{'reshome'}) {
14666: $cenv{'reshome'}=$args->{'reshome'}.'/';
14667: $cenv{'reshome'}=~s/\/+$/\//;
14668: }
14669: #
14670: # course has keyed access
14671: #
14672: if ($args->{'setkeys'}) {
14673: $cenv{'keyaccess'}='yes';
14674: }
14675: # if specified, key authority is not course, but user
14676: # only active if keyaccess is yes
14677: if ($args->{'keyauth'}) {
1.487 albertel 14678: my ($user,$domain) = split(':',$args->{'keyauth'});
14679: $user = &LONCAPA::clean_username($user);
14680: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14681: if ($user ne '' && $domain ne '') {
1.487 albertel 14682: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14683: }
14684: }
14685:
1.1166 raeburn 14686: #
1.1167 raeburn 14687: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 14688: #
14689: if ($args->{'uniquecode'}) {
14690: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14691: if ($code) {
14692: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 14693: my %crsinfo =
14694: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14695: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14696: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14697: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14698: }
1.1166 raeburn 14699: if (ref($coderef)) {
14700: $$coderef = $code;
14701: }
14702: }
14703: }
14704:
1.444 albertel 14705: if ($args->{'disresdis'}) {
14706: $cenv{'pch.roles.denied'}='st';
14707: }
14708: if ($args->{'disablechat'}) {
14709: $cenv{'plc.roles.denied'}='st';
14710: }
14711:
14712: # Record we've not yet viewed the Course Initialization Helper for this
14713: # course
14714: $cenv{'course.helper.not.run'} = 1;
14715: #
14716: # Use new Randomseed
14717: #
14718: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14719: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14720: #
14721: # The encryption code and receipt prefix for this course
14722: #
14723: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14724: $cenv{'internal.encpref'}=100+int(9*rand(99));
14725: #
14726: # By default, use standard grading
14727: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14728:
1.541 raeburn 14729: $outcome .= $linefeed.&mt('Setting environment').': '.
14730: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14731: #
14732: # Open all assignments
14733: #
14734: if ($args->{'openall'}) {
14735: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14736: my %storecontent = ($storeunder => time,
14737: $storeunder.'.type' => 'date_start');
14738:
14739: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14740: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14741: }
14742: #
14743: # Set first page
14744: #
14745: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14746: || ($cloneid)) {
1.445 albertel 14747: use LONCAPA::map;
1.444 albertel 14748: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14749:
14750: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14751: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14752:
1.444 albertel 14753: $outcome .= ($fatal?$errtext:'read ok').' - ';
14754: my $title; my $url;
14755: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14756: $title=&mt('Syllabus');
1.444 albertel 14757: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14758: } else {
1.963 raeburn 14759: $title=&mt('Table of Contents');
1.444 albertel 14760: $url='/adm/navmaps';
14761: }
1.445 albertel 14762:
14763: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14764: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14765:
14766: if ($errtext) { $fatal=2; }
1.541 raeburn 14767: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14768: }
1.566 albertel 14769:
14770: return (1,$outcome);
1.444 albertel 14771: }
14772:
1.1166 raeburn 14773: sub make_unique_code {
14774: my ($cdom,$cnum) = @_;
14775: # get lock on uniquecodes db
14776: my $lockhash = {
14777: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14778: ':'.$env{'user.domain'},
14779: };
14780: my $tries = 0;
14781: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14782: my ($code,$error);
14783:
14784: while (($gotlock ne 'ok') && ($tries<3)) {
14785: $tries ++;
14786: sleep 1;
14787: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14788: }
14789: if ($gotlock eq 'ok') {
14790: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14791: my $gotcode;
14792: my $attempts = 0;
14793: while ((!$gotcode) && ($attempts < 100)) {
14794: $code = &generate_code();
14795: if (!exists($currcodes{$code})) {
14796: $gotcode = 1;
14797: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14798: $error = 'nostore';
14799: }
14800: }
14801: $attempts ++;
14802: }
14803: my @del_lock = ($cnum."\0".'uniquecodes');
14804: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14805: } else {
14806: $error = 'nolock';
14807: }
14808: return ($code,$error);
14809: }
14810:
14811: sub generate_code {
14812: my $code;
14813: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14814: for (my $i=0; $i<6; $i++) {
14815: my $lettnum = int (rand 2);
14816: my $item = '';
14817: if ($lettnum) {
14818: $item = $letts[int( rand(18) )];
14819: } else {
14820: $item = 1+int( rand(8) );
14821: }
14822: $code .= $item;
14823: }
14824: return $code;
14825: }
14826:
1.444 albertel 14827: ############################################################
14828: ############################################################
14829:
1.953 droeschl 14830: #SD
14831: # only Community and Course, or anything else?
1.378 raeburn 14832: sub course_type {
14833: my ($cid) = @_;
14834: if (!defined($cid)) {
14835: $cid = $env{'request.course.id'};
14836: }
1.404 albertel 14837: if (defined($env{'course.'.$cid.'.type'})) {
14838: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14839: } else {
14840: return 'Course';
1.377 raeburn 14841: }
14842: }
1.156 albertel 14843:
1.406 raeburn 14844: sub group_term {
14845: my $crstype = &course_type();
14846: my %names = (
14847: 'Course' => 'group',
1.865 raeburn 14848: 'Community' => 'group',
1.406 raeburn 14849: );
14850: return $names{$crstype};
14851: }
14852:
1.902 raeburn 14853: sub course_types {
1.1165 raeburn 14854: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14855: my %typename = (
14856: official => 'Official course',
14857: unofficial => 'Unofficial course',
14858: community => 'Community',
1.1165 raeburn 14859: textbook => 'Textbook course',
1.902 raeburn 14860: );
14861: return (\@types,\%typename);
14862: }
14863:
1.156 albertel 14864: sub icon {
14865: my ($file)=@_;
1.505 albertel 14866: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14867: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14868: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14869: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14870: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14871: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14872: $curfext.".gif") {
14873: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14874: $curfext.".gif";
14875: }
14876: }
1.249 albertel 14877: return &lonhttpdurl($iconname);
1.154 albertel 14878: }
1.84 albertel 14879:
1.575 albertel 14880: sub lonhttpdurl {
1.692 www 14881: #
14882: # Had been used for "small fry" static images on separate port 8080.
14883: # Modify here if lightweight http functionality desired again.
14884: # Currently eliminated due to increasing firewall issues.
14885: #
1.575 albertel 14886: my ($url)=@_;
1.692 www 14887: return $url;
1.215 albertel 14888: }
14889:
1.213 albertel 14890: sub connection_aborted {
14891: my ($r)=@_;
14892: $r->print(" ");$r->rflush();
14893: my $c = $r->connection;
14894: return $c->aborted();
14895: }
14896:
1.221 foxr 14897: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14898: # strings as 'strings'.
14899: sub escape_single {
1.221 foxr 14900: my ($input) = @_;
1.223 albertel 14901: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14902: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14903: return $input;
14904: }
1.223 albertel 14905:
1.222 foxr 14906: # Same as escape_single, but escape's "'s This
14907: # can be used for "strings"
14908: sub escape_double {
14909: my ($input) = @_;
14910: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14911: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14912: return $input;
14913: }
1.223 albertel 14914:
1.222 foxr 14915: # Escapes the last element of a full URL.
14916: sub escape_url {
14917: my ($url) = @_;
1.238 raeburn 14918: my @urlslices = split(/\//, $url,-1);
1.369 www 14919: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 14920: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 14921: }
1.462 albertel 14922:
1.820 raeburn 14923: sub compare_arrays {
14924: my ($arrayref1,$arrayref2) = @_;
14925: my (@difference,%count);
14926: @difference = ();
14927: %count = ();
14928: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14929: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14930: foreach my $element (keys(%count)) {
14931: if ($count{$element} == 1) {
14932: push(@difference,$element);
14933: }
14934: }
14935: }
14936: return @difference;
14937: }
14938:
1.817 bisitz 14939: # -------------------------------------------------------- Initialize user login
1.462 albertel 14940: sub init_user_environment {
1.463 albertel 14941: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14942: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14943:
14944: my $public=($username eq 'public' && $domain eq 'public');
14945:
14946: # See if old ID present, if so, remove
14947:
1.1062 raeburn 14948: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14949: my $now=time;
14950:
14951: if ($public) {
14952: my $max_public=100;
14953: my $oldest;
14954: my $oldest_time=0;
14955: for(my $next=1;$next<=$max_public;$next++) {
14956: if (-e $lonids."/publicuser_$next.id") {
14957: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14958: if ($mtime<$oldest_time || !$oldest_time) {
14959: $oldest_time=$mtime;
14960: $oldest=$next;
14961: }
14962: } else {
14963: $cookie="publicuser_$next";
14964: last;
14965: }
14966: }
14967: if (!$cookie) { $cookie="publicuser_$oldest"; }
14968: } else {
1.463 albertel 14969: # if this isn't a robot, kill any existing non-robot sessions
14970: if (!$args->{'robot'}) {
14971: opendir(DIR,$lonids);
14972: while ($filename=readdir(DIR)) {
14973: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14974: unlink($lonids.'/'.$filename);
14975: }
1.462 albertel 14976: }
1.463 albertel 14977: closedir(DIR);
1.1204 raeburn 14978: # If there is a undeleted lockfile for the user's paste buffer remove it.
14979: my $namespace = 'nohist_courseeditor';
14980: my $lockingkey = 'paste'."\0".'locked_num';
14981: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
14982: $domain,$username);
14983: if (exists($lockhash{$lockingkey})) {
14984: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
14985: unless ($delresult eq 'ok') {
14986: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
14987: }
14988: }
1.462 albertel 14989: }
14990: # Give them a new cookie
1.463 albertel 14991: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14992: : $now.$$.int(rand(10000)));
1.463 albertel 14993: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14994:
14995: # Initialize roles
14996:
1.1062 raeburn 14997: ($userroles,$firstaccenv,$timerintenv) =
14998: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14999: }
15000: # ------------------------------------ Check browser type and MathML capability
15001:
1.1194 raeburn 15002: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15003: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15004:
15005: # ------------------------------------------------------------- Get environment
15006:
15007: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15008: my ($tmp) = keys(%userenv);
15009: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15010: } else {
15011: undef(%userenv);
15012: }
15013: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15014: $form->{'interface'}=$userenv{'interface'};
15015: }
15016: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15017:
15018: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15019: foreach my $option ('interface','localpath','localres') {
15020: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15021: }
15022: # --------------------------------------------------------- Write first profile
15023:
15024: {
15025: my %initial_env =
15026: ("user.name" => $username,
15027: "user.domain" => $domain,
15028: "user.home" => $authhost,
15029: "browser.type" => $clientbrowser,
15030: "browser.version" => $clientversion,
15031: "browser.mathml" => $clientmathml,
15032: "browser.unicode" => $clientunicode,
15033: "browser.os" => $clientos,
1.1137 raeburn 15034: "browser.mobile" => $clientmobile,
1.1141 raeburn 15035: "browser.info" => $clientinfo,
1.1194 raeburn 15036: "browser.osversion" => $clientosversion,
1.462 albertel 15037: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15038: "request.course.fn" => '',
15039: "request.course.uri" => '',
15040: "request.course.sec" => '',
15041: "request.role" => 'cm',
15042: "request.role.adv" => $env{'user.adv'},
15043: "request.host" => $ENV{'REMOTE_ADDR'},);
15044:
15045: if ($form->{'localpath'}) {
15046: $initial_env{"browser.localpath"} = $form->{'localpath'};
15047: $initial_env{"browser.localres"} = $form->{'localres'};
15048: }
15049:
15050: if ($form->{'interface'}) {
15051: $form->{'interface'}=~s/\W//gs;
15052: $initial_env{"browser.interface"} = $form->{'interface'};
15053: $env{'browser.interface'}=$form->{'interface'};
15054: }
15055:
1.1157 raeburn 15056: if ($form->{'iptoken'}) {
15057: my $lonhost = $r->dir_config('lonHostID');
15058: $initial_env{"user.noloadbalance"} = $lonhost;
15059: $env{'user.noloadbalance'} = $lonhost;
15060: }
15061:
1.981 raeburn 15062: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15063: my %domdef;
15064: unless ($domain eq 'public') {
15065: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15066: }
1.980 raeburn 15067:
1.1081 raeburn 15068: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15069: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15070: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15071: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15072: }
15073:
1.1165 raeburn 15074: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 15075: $userenv{'canrequest.'.$crstype} =
15076: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15077: 'reload','requestcourses',
15078: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15079: }
15080:
1.1092 raeburn 15081: $userenv{'canrequest.author'} =
15082: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15083: 'reload','requestauthor',
15084: \%userenv,\%domdef,\%is_adv);
15085: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15086: $domain,$username);
15087: my $reqstatus = $reqauthor{'author_status'};
15088: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15089: if (ref($reqauthor{'author'}) eq 'HASH') {
15090: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15091: $reqauthor{'author'}{'timestamp'};
15092: }
15093: }
15094:
1.462 albertel 15095: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15096:
1.462 albertel 15097: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15098: &GDBM_WRCREAT(),0640)) {
15099: &_add_to_env(\%disk_env,\%initial_env);
15100: &_add_to_env(\%disk_env,\%userenv,'environment.');
15101: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15102: if (ref($firstaccenv) eq 'HASH') {
15103: &_add_to_env(\%disk_env,$firstaccenv);
15104: }
15105: if (ref($timerintenv) eq 'HASH') {
15106: &_add_to_env(\%disk_env,$timerintenv);
15107: }
1.463 albertel 15108: if (ref($args->{'extra_env'})) {
15109: &_add_to_env(\%disk_env,$args->{'extra_env'});
15110: }
1.462 albertel 15111: untie(%disk_env);
15112: } else {
1.705 tempelho 15113: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15114: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15115: return 'error: '.$!;
15116: }
15117: }
15118: $env{'request.role'}='cm';
15119: $env{'request.role.adv'}=$env{'user.adv'};
15120: $env{'browser.type'}=$clientbrowser;
15121:
15122: return $cookie;
15123:
15124: }
15125:
15126: sub _add_to_env {
15127: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15128: if (ref($env_data) eq 'HASH') {
15129: while (my ($key,$value) = each(%$env_data)) {
15130: $idf->{$prefix.$key} = $value;
15131: $env{$prefix.$key} = $value;
15132: }
1.462 albertel 15133: }
15134: }
15135:
1.685 tempelho 15136: # --- Get the symbolic name of a problem and the url
15137: sub get_symb {
15138: my ($request,$silent) = @_;
1.726 raeburn 15139: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15140: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15141: if ($symb eq '') {
15142: if (!$silent) {
1.1071 raeburn 15143: if (ref($request)) {
15144: $request->print("Unable to handle ambiguous references:$url:.");
15145: }
1.685 tempelho 15146: return ();
15147: }
15148: }
15149: &Apache::lonenc::check_decrypt(\$symb);
15150: return ($symb);
15151: }
15152:
15153: # --------------------------------------------------------------Get annotation
15154:
15155: sub get_annotation {
15156: my ($symb,$enc) = @_;
15157:
15158: my $key = $symb;
15159: if (!$enc) {
15160: $key =
15161: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15162: }
15163: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15164: return $annotation{$key};
15165: }
15166:
15167: sub clean_symb {
1.731 raeburn 15168: my ($symb,$delete_enc) = @_;
1.685 tempelho 15169:
15170: &Apache::lonenc::check_decrypt(\$symb);
15171: my $enc = $env{'request.enc'};
1.731 raeburn 15172: if ($delete_enc) {
1.730 raeburn 15173: delete($env{'request.enc'});
15174: }
1.685 tempelho 15175:
15176: return ($symb,$enc);
15177: }
1.462 albertel 15178:
1.1181 raeburn 15179: ############################################################
15180: ############################################################
15181:
15182: =pod
15183:
15184: =head1 Routines for building display used to search for courses
15185:
15186:
15187: =over 4
15188:
15189: =item * &build_filters()
15190:
15191: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 15192: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15193: and quotacheck.pl
15194:
1.1181 raeburn 15195:
15196: Inputs:
15197:
15198: filterlist - anonymous array of fields to include as potential filters
15199:
15200: crstype - course type
15201:
15202: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15203: to pop-open a course selector (will contain "extra element").
15204:
15205: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15206:
15207: filter - anonymous hash of criteria and their values
15208:
15209: action - form action
15210:
15211: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15212:
1.1182 raeburn 15213: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 15214:
15215: cloneruname - username of owner of new course who wants to clone
15216:
15217: clonerudom - domain of owner of new course who wants to clone
15218:
15219: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15220:
15221: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15222:
15223: codedom - domain
15224:
15225: formname - value of form element named "form".
15226:
15227: fixeddom - domain, if fixed.
15228:
15229: prevphase - value to assign to form element named "phase" when going back to the previous screen
15230:
15231: cnameelement - name of form element in form on opener page which will receive title of selected course
15232:
15233: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15234:
15235: cdomelement - name of form element in form on opener page which will receive domain of selected course
15236:
15237: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15238:
15239: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15240:
15241: clonewarning - warning message about missing information for intended course owner when DC creates a course
15242:
1.1182 raeburn 15243:
1.1181 raeburn 15244: Returns: $output - HTML for display of search criteria, and hidden form elements.
15245:
1.1182 raeburn 15246:
1.1181 raeburn 15247: Side Effects: None
15248:
15249: =cut
15250:
15251: # ---------------------------------------------- search for courses based on last activity etc.
15252:
15253: sub build_filters {
15254: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15255: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15256: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15257: $cnameelement,$cnumelement,$cdomelement,$setroles,
15258: $clonetext,$clonewarning) = @_;
1.1182 raeburn 15259: my ($list,$jscript);
1.1181 raeburn 15260: my $onchange = 'javascript:updateFilters(this)';
15261: my ($domainselectform,$sincefilterform,$createdfilterform,
15262: $ownerdomselectform,$persondomselectform,$instcodeform,
15263: $typeselectform,$instcodetitle);
15264: if ($formname eq '') {
15265: $formname = $caller;
15266: }
15267: foreach my $item (@{$filterlist}) {
15268: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15269: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15270: if ($item eq 'domainfilter') {
15271: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15272: } elsif ($item eq 'coursefilter') {
15273: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15274: } elsif ($item eq 'ownerfilter') {
15275: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15276: } elsif ($item eq 'ownerdomfilter') {
15277: $filter->{'ownerdomfilter'} =
15278: &LONCAPA::clean_domain($filter->{$item});
15279: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15280: 'ownerdomfilter',1);
15281: } elsif ($item eq 'personfilter') {
15282: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15283: } elsif ($item eq 'persondomfilter') {
15284: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15285: 'persondomfilter',1);
15286: } else {
15287: $filter->{$item} =~ s/\W//g;
15288: }
15289: if (!$filter->{$item}) {
15290: $filter->{$item} = '';
15291: }
15292: }
15293: if ($item eq 'domainfilter') {
15294: my $allow_blank = 1;
15295: if ($formname eq 'portform') {
15296: $allow_blank=0;
15297: } elsif ($formname eq 'studentform') {
15298: $allow_blank=0;
15299: }
15300: if ($fixeddom) {
15301: $domainselectform = '<input type="hidden" name="domainfilter"'.
15302: ' value="'.$codedom.'" />'.
15303: &Apache::lonnet::domain($codedom,'description');
15304: } else {
15305: $domainselectform = &select_dom_form($filter->{$item},
15306: 'domainfilter',
15307: $allow_blank,'',$onchange);
15308: }
15309: } else {
15310: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15311: }
15312: }
15313:
15314: # last course activity filter and selection
15315: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15316:
15317: # course created filter and selection
15318: if (exists($filter->{'createdfilter'})) {
15319: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15320: }
15321:
15322: my %lt = &Apache::lonlocal::texthash(
15323: 'cac' => "$crstype Activity",
15324: 'ccr' => "$crstype Created",
15325: 'cde' => "$crstype Title",
15326: 'cdo' => "$crstype Domain",
15327: 'ins' => 'Institutional Code',
15328: 'inc' => 'Institutional Categorization',
15329: 'cow' => "$crstype Owner/Co-owner",
15330: 'cop' => "$crstype Personnel Includes",
15331: 'cog' => 'Type',
15332: );
15333:
15334: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15335: my $typeval = 'Course';
15336: if ($crstype eq 'Community') {
15337: $typeval = 'Community';
15338: }
15339: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15340: } else {
15341: $typeselectform = '<select name="type" size="1"';
15342: if ($onchange) {
15343: $typeselectform .= ' onchange="'.$onchange.'"';
15344: }
15345: $typeselectform .= '>'."\n";
15346: foreach my $posstype ('Course','Community') {
15347: $typeselectform.='<option value="'.$posstype.'"'.
15348: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15349: }
15350: $typeselectform.="</select>";
15351: }
15352:
15353: my ($cloneableonlyform,$cloneabletitle);
15354: if (exists($filter->{'cloneableonly'})) {
15355: my $cloneableon = '';
15356: my $cloneableoff = ' checked="checked"';
15357: if ($filter->{'cloneableonly'}) {
15358: $cloneableon = $cloneableoff;
15359: $cloneableoff = '';
15360: }
15361: $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>';
15362: if ($formname eq 'ccrs') {
1.1187 bisitz 15363: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 15364: } else {
15365: $cloneabletitle = &mt('Cloneable by you');
15366: }
15367: }
15368: my $officialjs;
15369: if ($crstype eq 'Course') {
15370: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 15371: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15372: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15373: if ($codedom) {
1.1181 raeburn 15374: $officialjs = 1;
15375: ($instcodeform,$jscript,$$numtitlesref) =
15376: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15377: $officialjs,$codetitlesref);
15378: if ($jscript) {
1.1182 raeburn 15379: $jscript = '<script type="text/javascript">'."\n".
15380: '// <![CDATA['."\n".
15381: $jscript."\n".
15382: '// ]]>'."\n".
15383: '</script>'."\n";
1.1181 raeburn 15384: }
15385: }
15386: if ($instcodeform eq '') {
15387: $instcodeform =
15388: '<input type="text" name="instcodefilter" size="10" value="'.
15389: $list->{'instcodefilter'}.'" />';
15390: $instcodetitle = $lt{'ins'};
15391: } else {
15392: $instcodetitle = $lt{'inc'};
15393: }
15394: if ($fixeddom) {
15395: $instcodetitle .= '<br />('.$codedom.')';
15396: }
15397: }
15398: }
15399: my $output = qq|
15400: <form method="post" name="filterpicker" action="$action">
15401: <input type="hidden" name="form" value="$formname" />
15402: |;
15403: if ($formname eq 'modifycourse') {
15404: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15405: '<input type="hidden" name="prevphase" value="'.
15406: $prevphase.'" />'."\n";
1.1198 musolffc 15407: } elsif ($formname eq 'quotacheck') {
15408: $output .= qq|
15409: <input type="hidden" name="sortby" value="" />
15410: <input type="hidden" name="sortorder" value="" />
15411: |;
15412: } else {
1.1181 raeburn 15413: my $name_input;
15414: if ($cnameelement ne '') {
15415: $name_input = '<input type="hidden" name="cnameelement" value="'.
15416: $cnameelement.'" />';
15417: }
15418: $output .= qq|
1.1182 raeburn 15419: <input type="hidden" name="cnumelement" value="$cnumelement" />
15420: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 15421: $name_input
15422: $roleelement
15423: $multelement
15424: $typeelement
15425: |;
15426: if ($formname eq 'portform') {
15427: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15428: }
15429: }
15430: if ($fixeddom) {
15431: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15432: }
15433: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15434: if ($sincefilterform) {
15435: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15436: .$sincefilterform
15437: .&Apache::lonhtmlcommon::row_closure();
15438: }
15439: if ($createdfilterform) {
15440: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15441: .$createdfilterform
15442: .&Apache::lonhtmlcommon::row_closure();
15443: }
15444: if ($domainselectform) {
15445: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15446: .$domainselectform
15447: .&Apache::lonhtmlcommon::row_closure();
15448: }
15449: if ($typeselectform) {
15450: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15451: $output .= $typeselectform;
15452: } else {
15453: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15454: .$typeselectform
15455: .&Apache::lonhtmlcommon::row_closure();
15456: }
15457: }
15458: if ($instcodeform) {
15459: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15460: .$instcodeform
15461: .&Apache::lonhtmlcommon::row_closure();
15462: }
15463: if (exists($filter->{'ownerfilter'})) {
15464: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15465: '<table><tr><td>'.&mt('Username').'<br />'.
15466: '<input type="text" name="ownerfilter" size="20" value="'.
15467: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15468: $ownerdomselectform.'</td></tr></table>'.
15469: &Apache::lonhtmlcommon::row_closure();
15470: }
15471: if (exists($filter->{'personfilter'})) {
15472: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15473: '<table><tr><td>'.&mt('Username').'<br />'.
15474: '<input type="text" name="personfilter" size="20" value="'.
15475: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15476: $persondomselectform.'</td></tr></table>'.
15477: &Apache::lonhtmlcommon::row_closure();
15478: }
15479: if (exists($filter->{'coursefilter'})) {
15480: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15481: .'<input type="text" name="coursefilter" size="25" value="'
15482: .$list->{'coursefilter'}.'" />'
15483: .&Apache::lonhtmlcommon::row_closure();
15484: }
15485: if ($cloneableonlyform) {
15486: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15487: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15488: }
15489: if (exists($filter->{'descriptfilter'})) {
15490: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15491: .'<input type="text" name="descriptfilter" size="40" value="'
15492: .$list->{'descriptfilter'}.'" />'
15493: .&Apache::lonhtmlcommon::row_closure(1);
15494: }
15495: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15496: '<input type="hidden" name="updater" value="" />'."\n".
15497: '<input type="submit" name="gosearch" value="'.
15498: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15499: return $jscript.$clonewarning.$output;
15500: }
15501:
15502: =pod
15503:
15504: =item * &timebased_select_form()
15505:
1.1182 raeburn 15506: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 15507: filter e.g., Course Activity, Course Created, when searching for courses
15508: or communities
15509:
15510: Inputs:
15511:
15512: item - name of form element (sincefilter or createdfilter)
15513:
15514: filter - anonymous hash of criteria and their values
15515:
15516: Returns: HTML for a select box contained a blank, then six time selections,
15517: with value set in incoming form variables currently selected.
15518:
15519: Side Effects: None
15520:
15521: =cut
15522:
15523: sub timebased_select_form {
15524: my ($item,$filter) = @_;
15525: if (ref($filter) eq 'HASH') {
15526: $filter->{$item} =~ s/[^\d-]//g;
15527: if (!$filter->{$item}) { $filter->{$item}=-1; }
15528: return &select_form(
15529: $filter->{$item},
15530: $item,
15531: { '-1' => '',
15532: '86400' => &mt('today'),
15533: '604800' => &mt('last week'),
15534: '2592000' => &mt('last month'),
15535: '7776000' => &mt('last three months'),
15536: '15552000' => &mt('last six months'),
15537: '31104000' => &mt('last year'),
15538: 'select_form_order' =>
15539: ['-1','86400','604800','2592000','7776000',
15540: '15552000','31104000']});
15541: }
15542: }
15543:
15544: =pod
15545:
15546: =item * &js_changer()
15547:
15548: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 15549: when course type or domain is changed, and also to hide 'Searching ...' on
15550: page load completion for page showing search result.
1.1181 raeburn 15551:
15552: Inputs: None
15553:
1.1183 raeburn 15554: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 15555:
15556: Side Effects: None
15557:
15558: =cut
15559:
15560: sub js_changer {
15561: return <<ENDJS;
15562: <script type="text/javascript">
15563: // <![CDATA[
15564: function updateFilters(caller) {
15565: if (typeof(caller) != "undefined") {
15566: document.filterpicker.updater.value = caller.name;
15567: }
15568: document.filterpicker.submit();
15569: }
1.1183 raeburn 15570:
15571: function hideSearching() {
15572: if (document.getElementById('searching')) {
15573: document.getElementById('searching').style.display = 'none';
15574: }
15575: return;
15576: }
15577:
1.1181 raeburn 15578: // ]]>
15579: </script>
15580:
15581: ENDJS
15582: }
15583:
15584: =pod
15585:
1.1182 raeburn 15586: =item * &search_courses()
15587:
15588: Process selected filters form course search form and pass to lonnet::courseiddump
15589: to retrieve a hash for which keys are courseIDs which match the selected filters.
15590:
15591: Inputs:
15592:
15593: dom - domain being searched
15594:
15595: type - course type ('Course' or 'Community' or '.' if any).
15596:
15597: filter - anonymous hash of criteria and their values
15598:
15599: numtitles - for institutional codes - number of categories
15600:
15601: cloneruname - optional username of new course owner
15602:
15603: clonerudom - optional domain of new course owner
15604:
15605: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15606: (used when DC is using course creation form)
15607:
15608: codetitles - reference to array of titles of components in institutional codes (official courses).
15609:
15610:
15611: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15612:
15613:
15614: Side Effects: None
15615:
15616: =cut
15617:
15618:
15619: sub search_courses {
15620: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15621: my (%courses,%showcourses,$cloner);
15622: if (($filter->{'ownerfilter'} ne '') ||
15623: ($filter->{'ownerdomfilter'} ne '')) {
15624: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15625: $filter->{'ownerdomfilter'};
15626: }
15627: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15628: if (!$filter->{$item}) {
15629: $filter->{$item}='.';
15630: }
15631: }
15632: my $now = time;
15633: my $timefilter =
15634: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15635: my ($createdbefore,$createdafter);
15636: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15637: $createdbefore = $now;
15638: $createdafter = $now-$filter->{'createdfilter'};
15639: }
15640: my ($instcodefilter,$regexpok);
15641: if ($numtitles) {
15642: if ($env{'form.official'} eq 'on') {
15643: $instcodefilter =
15644: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15645: $regexpok = 1;
15646: } elsif ($env{'form.official'} eq 'off') {
15647: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15648: unless ($instcodefilter eq '') {
15649: $regexpok = -1;
15650: }
15651: }
15652: } else {
15653: $instcodefilter = $filter->{'instcodefilter'};
15654: }
15655: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15656: if ($type eq '') { $type = '.'; }
15657:
15658: if (($clonerudom ne '') && ($cloneruname ne '')) {
15659: $cloner = $cloneruname.':'.$clonerudom;
15660: }
15661: %courses = &Apache::lonnet::courseiddump($dom,
15662: $filter->{'descriptfilter'},
15663: $timefilter,
15664: $instcodefilter,
15665: $filter->{'combownerfilter'},
15666: $filter->{'coursefilter'},
15667: undef,undef,$type,$regexpok,undef,undef,
15668: undef,undef,$cloner,$env{'form.cc_clone'},
15669: $filter->{'cloneableonly'},
15670: $createdbefore,$createdafter,undef,
15671: $domcloner);
15672: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15673: my $ccrole;
15674: if ($type eq 'Community') {
15675: $ccrole = 'co';
15676: } else {
15677: $ccrole = 'cc';
15678: }
15679: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15680: $filter->{'persondomfilter'},
15681: 'userroles',undef,
15682: [$ccrole,'in','ad','ep','ta','cr'],
15683: $dom);
15684: foreach my $role (keys(%rolehash)) {
15685: my ($cnum,$cdom,$courserole) = split(':',$role);
15686: my $cid = $cdom.'_'.$cnum;
15687: if (exists($courses{$cid})) {
15688: if (ref($courses{$cid}) eq 'HASH') {
15689: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15690: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15691: push (@{$courses{$cid}{roles}},$courserole);
15692: }
15693: } else {
15694: $courses{$cid}{roles} = [$courserole];
15695: }
15696: $showcourses{$cid} = $courses{$cid};
15697: }
15698: }
15699: }
15700: %courses = %showcourses;
15701: }
15702: return %courses;
15703: }
15704:
15705: =pod
15706:
1.1181 raeburn 15707: =back
15708:
1.1207 raeburn 15709: =head1 Routines for version requirements for current course.
15710:
15711: =over 4
15712:
15713: =item * &check_release_required()
15714:
15715: Compares required LON-CAPA version with version on server, and
15716: if required version is newer looks for a server with the required version.
15717:
15718: Looks first at servers in user's owen domain; if none suitable, looks at
15719: servers in course's domain are permitted to host sessions for user's domain.
15720:
15721: Inputs:
15722:
15723: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15724:
15725: $courseid - Course ID of current course
15726:
15727: $rolecode - User's current role in course (for switchserver query string).
15728:
15729: $required - LON-CAPA version needed by course (format: Major.Minor).
15730:
15731:
15732: Returns:
15733:
15734: $switchserver - query string tp append to /adm/switchserver call (if
15735: current server's LON-CAPA version is too old.
15736:
15737: $warning - Message is displayed if no suitable server could be found.
15738:
15739: =cut
15740:
15741: sub check_release_required {
15742: my ($loncaparev,$courseid,$rolecode,$required) = @_;
15743: my ($switchserver,$warning);
15744: if ($required ne '') {
15745: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
15746: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15747: if ($reqdmajor ne '' && $reqdminor ne '') {
15748: my $otherserver;
15749: if (($major eq '' && $minor eq '') ||
15750: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
15751: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
15752: my $switchlcrev =
15753: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
15754: $userdomserver);
15755: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15756: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
15757: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
15758: my $cdom = $env{'course.'.$courseid.'.domain'};
15759: if ($cdom ne $env{'user.domain'}) {
15760: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
15761: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
15762: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15763: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
15764: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
15765: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
15766: my $canhost =
15767: &Apache::lonnet::can_host_session($env{'user.domain'},
15768: $coursedomserver,
15769: $remoterev,
15770: $udomdefaults{'remotesessions'},
15771: $defdomdefaults{'hostedsessions'});
15772:
15773: if ($canhost) {
15774: $otherserver = $coursedomserver;
15775: } else {
15776: $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.");
15777: }
15778: } else {
15779: $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).");
15780: }
15781: } else {
15782: $otherserver = $userdomserver;
15783: }
15784: }
15785: if ($otherserver ne '') {
15786: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
15787: }
15788: }
15789: }
15790: return ($switchserver,$warning);
15791: }
15792:
15793: =pod
15794:
15795: =item * &check_release_result()
15796:
15797: Inputs:
15798:
15799: $switchwarning - Warning message if no suitable server found to host session.
15800:
15801: $switchserver - query string to append to /adm/switchserver containing lonHostID
15802: and current role.
15803:
15804: Returns: HTML to display with information about requirement to switch server.
15805: Either displaying warning with link to Roles/Courses screen or
15806: display link to switchserver.
15807:
1.1181 raeburn 15808: =cut
15809:
1.1207 raeburn 15810: sub check_release_result {
15811: my ($switchwarning,$switchserver) = @_;
15812: my $output = &start_page('Selected course unavailable on this server').
15813: '<p class="LC_warning">';
15814: if ($switchwarning) {
15815: $output .= $switchwarning.'<br /><a href="/adm/roles">';
15816: if (&show_course()) {
15817: $output .= &mt('Display courses');
15818: } else {
15819: $output .= &mt('Display roles');
15820: }
15821: $output .= '</a>';
15822: } elsif ($switchserver) {
15823: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
15824: '<br />'.
15825: '<a href="/adm/switchserver?'.$switchserver.'">'.
15826: &mt('Switch Server').
15827: '</a>';
15828: }
15829: $output .= '</p>'.&end_page();
15830: return $output;
15831: }
15832:
15833: =pod
15834:
15835: =item * &needs_coursereinit()
15836:
15837: Determine if course contents stored for user's session needs to be
15838: refreshed, because content has changed since "Big Hash" last tied.
15839:
15840: Check for change is made if time last checked is more than 10 minutes ago
15841: (by default).
15842:
15843: Inputs:
15844:
15845: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15846:
15847: $interval (optional) - Time which may elapse (in s) between last check for content
15848: change in current course. (default: 600 s).
15849:
15850: Returns: an array; first element is:
15851:
15852: =over 4
15853:
15854: 'switch' - if content updates mean user's session
15855: needs to be switched to a server running a newer LON-CAPA version
15856:
15857: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
15858: on current server hosting user's session
15859:
15860: '' - if no action required.
15861:
15862: =back
15863:
15864: If first item element is 'switch':
15865:
15866: second item is $switchwarning - Warning message if no suitable server found to host session.
15867:
15868: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
15869: and current role.
15870:
15871: otherwise: no other elements returned.
15872:
15873: =back
15874:
15875: =cut
15876:
15877: sub needs_coursereinit {
15878: my ($loncaparev,$interval) = @_;
15879: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
15880: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
15881: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
15882: my $now = time;
15883: if ($interval eq '') {
15884: $interval = 600;
15885: }
15886: if (($now-$env{'request.course.timechecked'})>$interval) {
15887: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
15888: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
15889: if ($lastchange > $env{'request.course.tied'}) {
15890: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15891: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
15892: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
15893: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
15894: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
15895: $curr_reqd_hash{'internal.releaserequired'}});
15896: my ($switchserver,$switchwarning) =
15897: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
15898: $curr_reqd_hash{'internal.releaserequired'});
15899: if ($switchwarning ne '' || $switchserver ne '') {
15900: return ('switch',$switchwarning,$switchserver);
15901: }
15902: }
15903: }
15904: return ('update');
15905: }
15906: }
15907: return ();
15908: }
1.1181 raeburn 15909:
1.1083 raeburn 15910: sub update_content_constraints {
15911: my ($cdom,$cnum,$chome,$cid) = @_;
15912: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15913: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15914: my %checkresponsetypes;
15915: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15916: my ($item,$name,$value) = split(/:/,$key);
15917: if ($item eq 'resourcetag') {
15918: if ($name eq 'responsetype') {
15919: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15920: }
15921: }
15922: }
15923: my $navmap = Apache::lonnavmaps::navmap->new();
15924: if (defined($navmap)) {
15925: my %allresponses;
15926: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15927: my %responses = $res->responseTypes();
15928: foreach my $key (keys(%responses)) {
15929: next unless(exists($checkresponsetypes{$key}));
15930: $allresponses{$key} += $responses{$key};
15931: }
15932: }
15933: foreach my $key (keys(%allresponses)) {
15934: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15935: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15936: ($reqdmajor,$reqdminor) = ($major,$minor);
15937: }
15938: }
15939: undef($navmap);
15940: }
15941: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15942: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15943: }
15944: return;
15945: }
15946:
1.1110 raeburn 15947: sub allmaps_incourse {
15948: my ($cdom,$cnum,$chome,$cid) = @_;
15949: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15950: $cid = $env{'request.course.id'};
15951: $cdom = $env{'course.'.$cid.'.domain'};
15952: $cnum = $env{'course.'.$cid.'.num'};
15953: $chome = $env{'course.'.$cid.'.home'};
15954: }
15955: my %allmaps = ();
15956: my $lastchange =
15957: &Apache::lonnet::get_coursechange($cdom,$cnum);
15958: if ($lastchange > $env{'request.course.tied'}) {
15959: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15960: unless ($ferr) {
15961: &update_content_constraints($cdom,$cnum,$chome,$cid);
15962: }
15963: }
15964: my $navmap = Apache::lonnavmaps::navmap->new();
15965: if (defined($navmap)) {
15966: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15967: $allmaps{$res->src()} = 1;
15968: }
15969: }
15970: return \%allmaps;
15971: }
15972:
1.1083 raeburn 15973: sub parse_supplemental_title {
15974: my ($title) = @_;
15975:
15976: my ($foldertitle,$renametitle);
15977: if ($title =~ /&&&/) {
15978: $title = &HTML::Entites::decode($title);
15979: }
15980: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15981: $renametitle=$4;
15982: my ($time,$uname,$udom) = ($1,$2,$3);
15983: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15984: my $name = &plainname($uname,$udom);
15985: $name = &HTML::Entities::encode($name,'"<>&\'');
15986: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15987: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15988: $name.': <br />'.$foldertitle;
15989: }
15990: if (wantarray) {
15991: return ($title,$foldertitle,$renametitle);
15992: }
15993: return $title;
15994: }
15995:
1.1143 raeburn 15996: sub recurse_supplemental {
15997: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15998: if ($suppmap) {
15999: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16000: if ($fatal) {
16001: $errors ++;
16002: } else {
16003: if ($#LONCAPA::map::resources > 0) {
16004: foreach my $res (@LONCAPA::map::resources) {
16005: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16006: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16007: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16008: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16009: } else {
16010: $numfiles ++;
16011: }
16012: }
16013: }
16014: }
16015: }
16016: }
16017: return ($numfiles,$errors);
16018: }
16019:
1.1101 raeburn 16020: sub symb_to_docspath {
16021: my ($symb) = @_;
16022: return unless ($symb);
16023: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16024: if ($resurl=~/\.(sequence|page)$/) {
16025: $mapurl=$resurl;
16026: } elsif ($resurl eq 'adm/navmaps') {
16027: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16028: }
16029: my $mapresobj;
16030: my $navmap = Apache::lonnavmaps::navmap->new();
16031: if (ref($navmap)) {
16032: $mapresobj = $navmap->getResourceByUrl($mapurl);
16033: }
16034: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16035: my $type=$2;
16036: my $path;
16037: if (ref($mapresobj)) {
16038: my $pcslist = $mapresobj->map_hierarchy();
16039: if ($pcslist ne '') {
16040: foreach my $pc (split(/,/,$pcslist)) {
16041: next if ($pc <= 1);
16042: my $res = $navmap->getByMapPc($pc);
16043: if (ref($res)) {
16044: my $thisurl = $res->src();
16045: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16046: my $thistitle = $res->title();
16047: $path .= '&'.
16048: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16049: &escape($thistitle).
1.1101 raeburn 16050: ':'.$res->randompick().
16051: ':'.$res->randomout().
16052: ':'.$res->encrypted().
16053: ':'.$res->randomorder().
16054: ':'.$res->is_page();
16055: }
16056: }
16057: }
16058: $path =~ s/^\&//;
16059: my $maptitle = $mapresobj->title();
16060: if ($mapurl eq 'default') {
1.1129 raeburn 16061: $maptitle = 'Main Content';
1.1101 raeburn 16062: }
16063: $path .= (($path ne '')? '&' : '').
16064: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16065: &escape($maptitle).
1.1101 raeburn 16066: ':'.$mapresobj->randompick().
16067: ':'.$mapresobj->randomout().
16068: ':'.$mapresobj->encrypted().
16069: ':'.$mapresobj->randomorder().
16070: ':'.$mapresobj->is_page();
16071: } else {
16072: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16073: my $ispage = (($type eq 'page')? 1 : '');
16074: if ($mapurl eq 'default') {
1.1129 raeburn 16075: $maptitle = 'Main Content';
1.1101 raeburn 16076: }
16077: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16078: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 16079: }
16080: unless ($mapurl eq 'default') {
16081: $path = 'default&'.
1.1146 raeburn 16082: &escape('Main Content').
1.1101 raeburn 16083: ':::::&'.$path;
16084: }
16085: return $path;
16086: }
16087:
1.1094 raeburn 16088: sub captcha_display {
16089: my ($context,$lonhost) = @_;
16090: my ($output,$error);
16091: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16092: if ($captcha eq 'original') {
1.1094 raeburn 16093: $output = &create_captcha();
16094: unless ($output) {
1.1172 raeburn 16095: $error = 'captcha';
1.1094 raeburn 16096: }
16097: } elsif ($captcha eq 'recaptcha') {
16098: $output = &create_recaptcha($pubkey);
16099: unless ($output) {
1.1172 raeburn 16100: $error = 'recaptcha';
1.1094 raeburn 16101: }
16102: }
1.1176 raeburn 16103: return ($output,$error,$captcha);
1.1094 raeburn 16104: }
16105:
16106: sub captcha_response {
16107: my ($context,$lonhost) = @_;
16108: my ($captcha_chk,$captcha_error);
16109: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16110: if ($captcha eq 'original') {
1.1094 raeburn 16111: ($captcha_chk,$captcha_error) = &check_captcha();
16112: } elsif ($captcha eq 'recaptcha') {
16113: $captcha_chk = &check_recaptcha($privkey);
16114: } else {
16115: $captcha_chk = 1;
16116: }
16117: return ($captcha_chk,$captcha_error);
16118: }
16119:
16120: sub get_captcha_config {
16121: my ($context,$lonhost) = @_;
1.1095 raeburn 16122: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 16123: my $hostname = &Apache::lonnet::hostname($lonhost);
16124: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16125: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 16126: if ($context eq 'usercreation') {
16127: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16128: if (ref($domconfig{$context}) eq 'HASH') {
16129: $hashtocheck = $domconfig{$context}{'cancreate'};
16130: if (ref($hashtocheck) eq 'HASH') {
16131: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16132: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16133: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16134: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16135: }
16136: if ($privkey && $pubkey) {
16137: $captcha = 'recaptcha';
16138: } else {
16139: $captcha = 'original';
16140: }
16141: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16142: $captcha = 'original';
16143: }
1.1094 raeburn 16144: }
1.1095 raeburn 16145: } else {
16146: $captcha = 'captcha';
16147: }
16148: } elsif ($context eq 'login') {
16149: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16150: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16151: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16152: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 16153: if ($privkey && $pubkey) {
16154: $captcha = 'recaptcha';
1.1095 raeburn 16155: } else {
16156: $captcha = 'original';
1.1094 raeburn 16157: }
1.1095 raeburn 16158: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16159: $captcha = 'original';
1.1094 raeburn 16160: }
16161: }
16162: return ($captcha,$pubkey,$privkey);
16163: }
16164:
16165: sub create_captcha {
16166: my %captcha_params = &captcha_settings();
16167: my ($output,$maxtries,$tries) = ('',10,0);
16168: while ($tries < $maxtries) {
16169: $tries ++;
16170: my $captcha = Authen::Captcha->new (
16171: output_folder => $captcha_params{'output_dir'},
16172: data_folder => $captcha_params{'db_dir'},
16173: );
16174: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16175:
16176: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16177: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16178: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 16179: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16180: '<br />'.
16181: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 16182: last;
16183: }
16184: }
16185: return $output;
16186: }
16187:
16188: sub captcha_settings {
16189: my %captcha_params = (
16190: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16191: www_output_dir => "/captchaspool",
16192: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16193: numchars => '5',
16194: );
16195: return %captcha_params;
16196: }
16197:
16198: sub check_captcha {
16199: my ($captcha_chk,$captcha_error);
16200: my $code = $env{'form.code'};
16201: my $md5sum = $env{'form.crypt'};
16202: my %captcha_params = &captcha_settings();
16203: my $captcha = Authen::Captcha->new(
16204: output_folder => $captcha_params{'output_dir'},
16205: data_folder => $captcha_params{'db_dir'},
16206: );
1.1109 raeburn 16207: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 16208: my %captcha_hash = (
16209: 0 => 'Code not checked (file error)',
16210: -1 => 'Failed: code expired',
16211: -2 => 'Failed: invalid code (not in database)',
16212: -3 => 'Failed: invalid code (code does not match crypt)',
16213: );
16214: if ($captcha_chk != 1) {
16215: $captcha_error = $captcha_hash{$captcha_chk}
16216: }
16217: return ($captcha_chk,$captcha_error);
16218: }
16219:
16220: sub create_recaptcha {
16221: my ($pubkey) = @_;
1.1153 raeburn 16222: my $use_ssl;
16223: if ($ENV{'SERVER_PORT'} == 443) {
16224: $use_ssl = 1;
16225: }
1.1094 raeburn 16226: my $captcha = Captcha::reCAPTCHA->new;
16227: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 16228: $captcha->get_html($pubkey,undef,$use_ssl).
1.1094 raeburn 16229: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 16230: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 16231: '<br /><br />';
16232: }
16233:
16234: sub check_recaptcha {
16235: my ($privkey) = @_;
16236: my $captcha_chk;
16237: my $captcha = Captcha::reCAPTCHA->new;
16238: my $captcha_result =
16239: $captcha->check_answer(
16240: $privkey,
16241: $ENV{'REMOTE_ADDR'},
16242: $env{'form.recaptcha_challenge_field'},
16243: $env{'form.recaptcha_response_field'},
16244: );
16245: if ($captcha_result->{is_valid}) {
16246: $captcha_chk = 1;
16247: }
16248: return $captcha_chk;
16249: }
16250:
1.1174 raeburn 16251: sub emailusername_info {
1.1177 raeburn 16252: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 16253: my %titles = &Apache::lonlocal::texthash (
16254: lastname => 'Last Name',
16255: firstname => 'First Name',
16256: institution => 'School/college/university',
16257: location => "School's city, state/province, country",
16258: web => "School's web address",
16259: officialemail => 'E-mail address at institution (if different)',
16260: );
16261: return (\@fields,\%titles);
16262: }
16263:
1.1161 raeburn 16264: sub cleanup_html {
16265: my ($incoming) = @_;
16266: my $outgoing;
16267: if ($incoming ne '') {
16268: $outgoing = $incoming;
16269: $outgoing =~ s/;/;/g;
16270: $outgoing =~ s/\#/#/g;
16271: $outgoing =~ s/\&/&/g;
16272: $outgoing =~ s/</</g;
16273: $outgoing =~ s/>/>/g;
16274: $outgoing =~ s/\(/(/g;
16275: $outgoing =~ s/\)/)/g;
16276: $outgoing =~ s/"/"/g;
16277: $outgoing =~ s/'/'/g;
16278: $outgoing =~ s/\$/$/g;
16279: $outgoing =~ s{/}{/}g;
16280: $outgoing =~ s/=/=/g;
16281: $outgoing =~ s/\\/\/g
16282: }
16283: return $outgoing;
16284: }
16285:
1.1190 musolffc 16286: # Checks for critical messages and returns a redirect url if one exists.
16287: # $interval indicates how often to check for messages.
16288: sub critical_redirect {
16289: my ($interval) = @_;
16290: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16291: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16292: $env{'user.name'});
16293: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 16294: my $redirecturl;
1.1190 musolffc 16295: if ($what[0]) {
16296: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16297: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 16298: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16299: return (1, $url);
1.1190 musolffc 16300: }
1.1191 raeburn 16301: }
16302: }
16303: return ();
1.1190 musolffc 16304: }
16305:
1.1174 raeburn 16306: # Use:
16307: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16308: #
16309: ##################################################
16310: # password associated functions #
16311: ##################################################
16312: sub des_keys {
16313: # Make a new key for DES encryption.
16314: # Each key has two parts which are returned separately.
16315: # Please note: Each key must be passed through the &hex function
16316: # before it is output to the web browser. The hex versions cannot
16317: # be used to decrypt.
16318: my @hexstr=('0','1','2','3','4','5','6','7',
16319: '8','9','a','b','c','d','e','f');
16320: my $lkey='';
16321: for (0..7) {
16322: $lkey.=$hexstr[rand(15)];
16323: }
16324: my $ukey='';
16325: for (0..7) {
16326: $ukey.=$hexstr[rand(15)];
16327: }
16328: return ($lkey,$ukey);
16329: }
16330:
16331: sub des_decrypt {
16332: my ($key,$cyphertext) = @_;
16333: my $keybin=pack("H16",$key);
16334: my $cypher;
16335: if ($Crypt::DES::VERSION>=2.03) {
16336: $cypher=new Crypt::DES $keybin;
16337: } else {
16338: $cypher=new DES $keybin;
16339: }
16340: my $plaintext=
16341: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
16342: $plaintext.=
16343: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
16344: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
16345: return $plaintext;
16346: }
16347:
1.112 bowersj2 16348: 1;
16349: __END__;
1.41 ng 16350:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>