Annotation of loncom/interface/loncommon.pm, revision 1.1315
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1315 ! raeburn 4: # $Id: loncommon.pm,v 1.1314 2018/04/24 13:40:32 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1280 raeburn 74: use LONCAPA::LWPReq;
1.657 raeburn 75: use DateTime::TimeZone;
1.1241 raeburn 76: use DateTime::Locale;
1.1220 raeburn 77: use Encode();
1.1091 foxr 78: use Text::Aspell;
1.1094 raeburn 79: use Authen::Captcha;
80: use Captcha::reCAPTCHA;
1.1234 raeburn 81: use JSON::DWIW;
82: use LWP::UserAgent;
1.1174 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 85: use MIME::Lite;
86: use MIME::Types;
1.1292 raeburn 87: use File::Copy();
1.1300 raeburn 88: use File::Path();
1.1309 raeburn 89: use String::CRC32();
90: use Short::URL();
1.117 www 91:
1.517 raeburn 92: # ---------------------------------------------- Designs
93: use vars qw(%defaultdesign);
94:
1.22 www 95: my $readit;
96:
1.517 raeburn 97:
1.157 matthew 98: ##
99: ## Global Variables
100: ##
1.46 matthew 101:
1.643 foxr 102:
103: # ----------------------------------------------- SSI with retries:
104: #
105:
106: =pod
107:
1.648 raeburn 108: =head1 Server Side include with retries:
1.643 foxr 109:
110: =over 4
111:
1.648 raeburn 112: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 113:
114: Performs an ssi with some number of retries. Retries continue either
115: until the result is ok or until the retry count supplied by the
116: caller is exhausted.
117:
118: Inputs:
1.648 raeburn 119:
120: =over 4
121:
1.643 foxr 122: resource - Identifies the resource to insert.
1.648 raeburn 123:
1.643 foxr 124: retries - Count of the number of retries allowed.
1.648 raeburn 125:
1.643 foxr 126: form - Hash that identifies the rendering options.
127:
1.648 raeburn 128: =back
129:
130: Returns:
131:
132: =over 4
133:
1.643 foxr 134: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 135:
1.643 foxr 136: response - The response from the last attempt (which may or may not have been successful.
137:
1.648 raeburn 138: =back
139:
140: =back
141:
1.643 foxr 142: =cut
143:
144: sub ssi_with_retries {
145: my ($resource, $retries, %form) = @_;
146:
147:
148: my $ok = 0; # True if we got a good response.
149: my $content;
150: my $response;
151:
152: # Try to get the ssi done. within the retries count:
153:
154: do {
155: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
156: $ok = $response->is_success;
1.650 www 157: if (!$ok) {
158: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
159: }
1.643 foxr 160: $retries--;
161: } while (!$ok && ($retries > 0));
162:
163: if (!$ok) {
164: $content = ''; # On error return an empty content.
165: }
166: return ($content, $response);
167:
168: }
169:
170:
171:
1.20 www 172: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 173: my %language;
1.124 www 174: my %supported_language;
1.1088 foxr 175: my %supported_codes;
1.1048 foxr 176: my %latex_language; # For choosing hyphenation in <transl..>
177: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 178: my %cprtag;
1.192 taceyjo1 179: my %scprtag;
1.351 www 180: my %fe; my %fd; my %fm;
1.41 ng 181: my %category_extensions;
1.12 harris41 182:
1.46 matthew 183: # ---------------------------------------------- Thesaurus variables
1.144 matthew 184: #
185: # %Keywords:
186: # A hash used by &keyword to determine if a word is considered a keyword.
187: # $thesaurus_db_file
188: # Scalar containing the full path to the thesaurus database.
1.46 matthew 189:
190: my %Keywords;
191: my $thesaurus_db_file;
192:
1.144 matthew 193: #
194: # Initialize values from language.tab, copyright.tab, filetypes.tab,
195: # thesaurus.tab, and filecategories.tab.
196: #
1.18 www 197: BEGIN {
1.46 matthew 198: # Variable initialization
199: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
200: #
1.22 www 201: unless ($readit) {
1.12 harris41 202: # ------------------------------------------------------------------- languages
203: {
1.158 raeburn 204: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
205: '/language.tab';
206: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 207: while (my $line = <$fh>) {
208: next if ($line=~/^\#/);
209: chomp($line);
1.1088 foxr 210: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 211: $language{$key}=$val.' - '.$enc;
212: if ($sup) {
213: $supported_language{$key}=$sup;
1.1088 foxr 214: $supported_codes{$key} = $code;
1.158 raeburn 215: }
1.1048 foxr 216: if ($latex) {
217: $latex_language_bykey{$key} = $latex;
1.1088 foxr 218: $latex_language{$code} = $latex;
1.1048 foxr 219: }
1.158 raeburn 220: }
221: close($fh);
222: }
1.12 harris41 223: }
224: # ------------------------------------------------------------------ copyrights
225: {
1.158 raeburn 226: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
227: '/copyright.tab';
228: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 229: while (my $line = <$fh>) {
230: next if ($line=~/^\#/);
231: chomp($line);
232: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 233: $cprtag{$key}=$val;
234: }
235: close($fh);
236: }
1.12 harris41 237: }
1.351 www 238: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 239: {
240: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
241: '/source_copyright.tab';
242: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 243: while (my $line = <$fh>) {
244: next if ($line =~ /^\#/);
245: chomp($line);
246: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 247: $scprtag{$key}=$val;
248: }
249: close($fh);
250: }
251: }
1.63 www 252:
1.517 raeburn 253: # -------------------------------------------------------------- default domain designs
1.63 www 254: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 255: my $designfile = $designdir.'/default.tab';
256: if ( open (my $fh,"<$designfile") ) {
257: while (my $line = <$fh>) {
258: next if ($line =~ /^\#/);
259: chomp($line);
260: my ($key,$val)=(split(/\=/,$line));
261: if ($val) { $defaultdesign{$key}=$val; }
262: }
263: close($fh);
1.63 www 264: }
265:
1.15 harris41 266: # ------------------------------------------------------------- file categories
267: {
1.158 raeburn 268: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
269: '/filecategories.tab';
270: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 271: while (my $line = <$fh>) {
272: next if ($line =~ /^\#/);
273: chomp($line);
274: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 275: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 276: }
277: close($fh);
278: }
279:
1.15 harris41 280: }
1.12 harris41 281: # ------------------------------------------------------------------ file types
282: {
1.158 raeburn 283: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
284: '/filetypes.tab';
285: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 286: while (my $line = <$fh>) {
287: next if ($line =~ /^\#/);
288: chomp($line);
289: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 290: if ($descr ne '') {
291: $fe{$ending}=lc($emb);
292: $fd{$ending}=$descr;
1.351 www 293: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 294: }
295: }
296: close($fh);
297: }
1.12 harris41 298: }
1.22 www 299: &Apache::lonnet::logthis(
1.705 tempelho 300: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 301: $readit=1;
1.46 matthew 302: } # end of unless($readit)
1.32 matthew 303:
304: }
1.112 bowersj2 305:
1.42 matthew 306: ###############################################################
307: ## HTML and Javascript Helper Functions ##
308: ###############################################################
309:
310: =pod
311:
1.112 bowersj2 312: =head1 HTML and Javascript Functions
1.42 matthew 313:
1.112 bowersj2 314: =over 4
315:
1.648 raeburn 316: =item * &browser_and_searcher_javascript()
1.112 bowersj2 317:
318: X<browsing, javascript>X<searching, javascript>Returns a string
319: containing javascript with two functions, C<openbrowser> and
320: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
321: tags.
1.42 matthew 322:
1.648 raeburn 323: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 324:
325: inputs: formname, elementname, only, omit
326:
327: formname and elementname indicate the name of the html form and name of
328: the element that the results of the browsing selection are to be placed in.
329:
330: Specifying 'only' will restrict the browser to displaying only files
1.185 www 331: with the given extension. Can be a comma separated list.
1.42 matthew 332:
333: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 334: with the given extension. Can be a comma separated list.
1.42 matthew 335:
1.648 raeburn 336: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 337:
338: Inputs: formname, elementname
339:
340: formname and elementname specify the name of the html form and the name
341: of the element the selection from the search results will be placed in.
1.542 raeburn 342:
1.42 matthew 343: =cut
344:
345: sub browser_and_searcher_javascript {
1.199 albertel 346: my ($mode)=@_;
347: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 348: my $resurl=&escape_single(&lastresurl());
1.42 matthew 349: return <<END;
1.219 albertel 350: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 351: var editbrowser = null;
1.135 albertel 352: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 353: var url = '$resurl/?';
1.42 matthew 354: if (editbrowser == null) {
355: url += 'launch=1&';
356: }
357: url += 'catalogmode=interactive&';
1.199 albertel 358: url += 'mode=$mode&';
1.611 albertel 359: url += 'inhibitmenu=yes&';
1.42 matthew 360: url += 'form=' + formname + '&';
361: if (only != null) {
362: url += 'only=' + only + '&';
1.217 albertel 363: } else {
364: url += 'only=&';
365: }
1.42 matthew 366: if (omit != null) {
367: url += 'omit=' + omit + '&';
1.217 albertel 368: } else {
369: url += 'omit=&';
370: }
1.135 albertel 371: if (titleelement != null) {
372: url += 'titleelement=' + titleelement + '&';
1.217 albertel 373: } else {
374: url += 'titleelement=&';
375: }
1.42 matthew 376: url += 'element=' + elementname + '';
377: var title = 'Browser';
1.435 albertel 378: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 379: options += ',width=700,height=600';
380: editbrowser = open(url,title,options,'1');
381: editbrowser.focus();
382: }
383: var editsearcher;
1.135 albertel 384: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 385: var url = '/adm/searchcat?';
386: if (editsearcher == null) {
387: url += 'launch=1&';
388: }
389: url += 'catalogmode=interactive&';
1.199 albertel 390: url += 'mode=$mode&';
1.42 matthew 391: url += 'form=' + formname + '&';
1.135 albertel 392: if (titleelement != null) {
393: url += 'titleelement=' + titleelement + '&';
1.217 albertel 394: } else {
395: url += 'titleelement=&';
396: }
1.42 matthew 397: url += 'element=' + elementname + '';
398: var title = 'Search';
1.435 albertel 399: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 400: options += ',width=700,height=600';
401: editsearcher = open(url,title,options,'1');
402: editsearcher.focus();
403: }
1.219 albertel 404: // END LON-CAPA Internal -->
1.42 matthew 405: END
1.170 www 406: }
407:
408: sub lastresurl {
1.258 albertel 409: if ($env{'environment.lastresurl'}) {
410: return $env{'environment.lastresurl'}
1.170 www 411: } else {
412: return '/res';
413: }
414: }
415:
416: sub storeresurl {
417: my $resurl=&Apache::lonnet::clutter(shift);
418: unless ($resurl=~/^\/res/) { return 0; }
419: $resurl=~s/\/$//;
420: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 421: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 422: return 1;
1.42 matthew 423: }
424:
1.74 www 425: sub studentbrowser_javascript {
1.111 www 426: unless (
1.258 albertel 427: (($env{'request.course.id'}) &&
1.302 albertel 428: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
429: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
430: '/'.$env{'request.course.sec'})
431: ))
1.258 albertel 432: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 433: ) { return ''; }
1.74 www 434: return (<<'ENDSTDBRW');
1.776 bisitz 435: <script type="text/javascript" language="Javascript">
1.824 bisitz 436: // <![CDATA[
1.74 www 437: var stdeditbrowser;
1.999 www 438: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 439: var url = '/adm/pickstudent?';
440: var filter;
1.558 albertel 441: if (!ignorefilter) {
442: eval('filter=document.'+formname+'.'+uname+'.value;');
443: }
1.74 www 444: if (filter != null) {
445: if (filter != '') {
446: url += 'filter='+filter+'&';
447: }
448: }
449: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 450: '&udomelement='+udom+
451: '&clicker='+clicker;
1.111 www 452: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 453: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 454: var title = 'Student_Browser';
1.74 www 455: var options = 'scrollbars=1,resizable=1,menubar=0';
456: options += ',width=700,height=600';
457: stdeditbrowser = open(url,title,options,'1');
458: stdeditbrowser.focus();
459: }
1.824 bisitz 460: // ]]>
1.74 www 461: </script>
462: ENDSTDBRW
463: }
1.42 matthew 464:
1.1003 www 465: sub resourcebrowser_javascript {
466: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 467: return (<<'ENDRESBRW');
1.1003 www 468: <script type="text/javascript" language="Javascript">
469: // <![CDATA[
470: var reseditbrowser;
1.1004 www 471: function openresbrowser(formname,reslink) {
1.1005 www 472: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 473: var title = 'Resource_Browser';
474: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 475: options += ',width=700,height=500';
1.1004 www 476: reseditbrowser = open(url,title,options,'1');
477: reseditbrowser.focus();
1.1003 www 478: }
479: // ]]>
480: </script>
1.1004 www 481: ENDRESBRW
1.1003 www 482: }
483:
1.74 www 484: sub selectstudent_link {
1.999 www 485: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
486: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
487: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
488: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 489: if ($env{'request.course.id'}) {
1.302 albertel 490: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
491: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
492: '/'.$env{'request.course.sec'})) {
1.111 www 493: return '';
494: }
1.999 www 495: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 496: if ($courseadvonly) {
497: $callargs .= ",'',1,1";
498: }
499: return '<span class="LC_nobreak">'.
500: '<a href="javascript:openstdbrowser('.$callargs.');">'.
501: &mt('Select User').'</a></span>';
1.74 www 502: }
1.258 albertel 503: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 504: $callargs .= ",'',1";
1.793 raeburn 505: return '<span class="LC_nobreak">'.
506: '<a href="javascript:openstdbrowser('.$callargs.');">'.
507: &mt('Select User').'</a></span>';
1.111 www 508: }
509: return '';
1.91 www 510: }
511:
1.1004 www 512: sub selectresource_link {
513: my ($form,$reslink,$arg)=@_;
514:
515: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
516: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
517: unless ($env{'request.course.id'}) { return $arg; }
518: return '<span class="LC_nobreak">'.
519: '<a href="javascript:openresbrowser('.$callargs.');">'.
520: $arg.'</a></span>';
521: }
522:
523:
524:
1.653 raeburn 525: sub authorbrowser_javascript {
526: return <<"ENDAUTHORBRW";
1.776 bisitz 527: <script type="text/javascript" language="JavaScript">
1.824 bisitz 528: // <![CDATA[
1.653 raeburn 529: var stdeditbrowser;
530:
531: function openauthorbrowser(formname,udom) {
532: var url = '/adm/pickauthor?';
533: url += 'form='+formname+'&roledom='+udom;
534: var title = 'Author_Browser';
535: var options = 'scrollbars=1,resizable=1,menubar=0';
536: options += ',width=700,height=600';
537: stdeditbrowser = open(url,title,options,'1');
538: stdeditbrowser.focus();
539: }
540:
1.824 bisitz 541: // ]]>
1.653 raeburn 542: </script>
543: ENDAUTHORBRW
544: }
545:
1.91 www 546: sub coursebrowser_javascript {
1.1116 raeburn 547: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 548: $credits_element,$instcode) = @_;
1.932 raeburn 549: my $wintitle = 'Course_Browser';
1.931 raeburn 550: if ($crstype eq 'Community') {
1.932 raeburn 551: $wintitle = 'Community_Browser';
1.909 raeburn 552: }
1.876 raeburn 553: my $id_functions = &javascript_index_functions();
554: my $output = '
1.776 bisitz 555: <script type="text/javascript" language="JavaScript">
1.824 bisitz 556: // <![CDATA[
1.468 raeburn 557: var stdeditbrowser;'."\n";
1.876 raeburn 558:
559: $output .= <<"ENDSTDBRW";
1.909 raeburn 560: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 561: var url = '/adm/pickcourse?';
1.895 raeburn 562: var formid = getFormIdByName(formname);
1.876 raeburn 563: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 564: if (domainfilter != null) {
565: if (domainfilter != '') {
566: url += 'domainfilter='+domainfilter+'&';
567: }
568: }
1.91 www 569: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 570: '&cdomelement='+udom+
571: '&cnameelement='+desc;
1.468 raeburn 572: if (extra_element !=null && extra_element != '') {
1.594 raeburn 573: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 574: url += '&roleelement='+extra_element;
575: if (domainfilter == null || domainfilter == '') {
576: url += '&domainfilter='+extra_element;
577: }
1.234 raeburn 578: }
1.468 raeburn 579: else {
580: if (formname == 'portform') {
581: url += '&setroles='+extra_element;
1.800 raeburn 582: } else {
583: if (formname == 'rules') {
584: url += '&fixeddom='+extra_element;
585: }
1.468 raeburn 586: }
587: }
1.230 raeburn 588: }
1.909 raeburn 589: if (type != null && type != '') {
590: url += '&type='+type;
591: }
592: if (type_elem != null && type_elem != '') {
593: url += '&typeelement='+type_elem;
594: }
1.872 raeburn 595: if (formname == 'ccrs') {
596: var ownername = document.forms[formid].ccuname.value;
597: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 598: url += '&cloner='+ownername+':'+ownerdom;
599: if (type == 'Course') {
600: url += '&crscode='+document.forms[formid].crscode.value;
601: }
1.1221 raeburn 602: }
603: if (formname == 'requestcrs') {
604: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 605: }
1.293 raeburn 606: if (multflag !=null && multflag != '') {
607: url += '&multiple='+multflag;
608: }
1.909 raeburn 609: var title = '$wintitle';
1.91 www 610: var options = 'scrollbars=1,resizable=1,menubar=0';
611: options += ',width=700,height=600';
612: stdeditbrowser = open(url,title,options,'1');
613: stdeditbrowser.focus();
614: }
1.876 raeburn 615: $id_functions
616: ENDSTDBRW
1.1116 raeburn 617: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
618: $output .= &setsec_javascript($sec_element,$formname,$role_element,
619: $credits_element);
1.876 raeburn 620: }
621: $output .= '
622: // ]]>
623: </script>';
624: return $output;
625: }
626:
627: sub javascript_index_functions {
628: return <<"ENDJS";
629:
630: function getFormIdByName(formname) {
631: for (var i=0;i<document.forms.length;i++) {
632: if (document.forms[i].name == formname) {
633: return i;
634: }
635: }
636: return -1;
637: }
638:
639: function getIndexByName(formid,item) {
640: for (var i=0;i<document.forms[formid].elements.length;i++) {
641: if (document.forms[formid].elements[i].name == item) {
642: return i;
643: }
644: }
645: return -1;
646: }
1.468 raeburn 647:
1.876 raeburn 648: function getDomainFromSelectbox(formname,udom) {
649: var userdom;
650: var formid = getFormIdByName(formname);
651: if (formid > -1) {
652: var domid = getIndexByName(formid,udom);
653: if (domid > -1) {
654: if (document.forms[formid].elements[domid].type == 'select-one') {
655: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
656: }
657: if (document.forms[formid].elements[domid].type == 'hidden') {
658: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 659: }
660: }
661: }
1.876 raeburn 662: return userdom;
663: }
664:
665: ENDJS
1.468 raeburn 666:
1.876 raeburn 667: }
668:
1.1017 raeburn 669: sub javascript_array_indexof {
1.1018 raeburn 670: return <<ENDJS;
1.1017 raeburn 671: <script type="text/javascript" language="JavaScript">
672: // <![CDATA[
673:
674: if (!Array.prototype.indexOf) {
675: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
676: "use strict";
677: if (this === void 0 || this === null) {
678: throw new TypeError();
679: }
680: var t = Object(this);
681: var len = t.length >>> 0;
682: if (len === 0) {
683: return -1;
684: }
685: var n = 0;
686: if (arguments.length > 0) {
687: n = Number(arguments[1]);
1.1088 foxr 688: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 689: n = 0;
690: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
691: n = (n > 0 || -1) * Math.floor(Math.abs(n));
692: }
693: }
694: if (n >= len) {
695: return -1;
696: }
697: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
698: for (; k < len; k++) {
699: if (k in t && t[k] === searchElement) {
700: return k;
701: }
702: }
703: return -1;
704: }
705: }
706:
707: // ]]>
708: </script>
709:
710: ENDJS
711:
712: }
713:
1.876 raeburn 714: sub userbrowser_javascript {
715: my $id_functions = &javascript_index_functions();
716: return <<"ENDUSERBRW";
717:
1.888 raeburn 718: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 719: var url = '/adm/pickuser?';
720: var userdom = getDomainFromSelectbox(formname,udom);
721: if (userdom != null) {
722: if (userdom != '') {
723: url += 'srchdom='+userdom+'&';
724: }
725: }
726: url += 'form=' + formname + '&unameelement='+uname+
727: '&udomelement='+udom+
728: '&ulastelement='+ulast+
729: '&ufirstelement='+ufirst+
730: '&uemailelement='+uemail+
1.881 raeburn 731: '&hideudomelement='+hideudom+
732: '&coursedom='+crsdom;
1.888 raeburn 733: if ((caller != null) && (caller != undefined)) {
734: url += '&caller='+caller;
735: }
1.876 raeburn 736: var title = 'User_Browser';
737: var options = 'scrollbars=1,resizable=1,menubar=0';
738: options += ',width=700,height=600';
739: var stdeditbrowser = open(url,title,options,'1');
740: stdeditbrowser.focus();
741: }
742:
1.888 raeburn 743: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 744: var formid = getFormIdByName(formname);
745: if (formid > -1) {
1.888 raeburn 746: var unameid = getIndexByName(formid,uname);
1.876 raeburn 747: var domid = getIndexByName(formid,udom);
748: var hidedomid = getIndexByName(formid,origdom);
749: if (hidedomid > -1) {
750: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 751: var unameval = document.forms[formid].elements[unameid].value;
752: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
753: if (domid > -1) {
754: var slct = document.forms[formid].elements[domid];
755: if (slct.type == 'select-one') {
756: var i;
757: for (i=0;i<slct.length;i++) {
758: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
759: }
760: }
761: if (slct.type == 'hidden') {
762: slct.value = fixeddom;
1.876 raeburn 763: }
764: }
1.468 raeburn 765: }
766: }
767: }
1.876 raeburn 768: return;
769: }
770:
771: $id_functions
772: ENDUSERBRW
1.468 raeburn 773: }
774:
775: sub setsec_javascript {
1.1116 raeburn 776: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 777: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
778: $communityrolestr);
779: if ($role_element ne '') {
780: my @allroles = ('st','ta','ep','in','ad');
781: foreach my $crstype ('Course','Community') {
782: if ($crstype eq 'Community') {
783: foreach my $role (@allroles) {
784: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
785: }
786: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
787: } else {
788: foreach my $role (@allroles) {
789: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
790: }
791: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
792: }
793: }
794: $rolestr = '"'.join('","',@allroles).'"';
795: $courserolestr = '"'.join('","',@courserolenames).'"';
796: $communityrolestr = '"'.join('","',@communityrolenames).'"';
797: }
1.468 raeburn 798: my $setsections = qq|
799: function setSect(sectionlist) {
1.629 raeburn 800: var sectionsArray = new Array();
801: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
802: sectionsArray = sectionlist.split(",");
803: }
1.468 raeburn 804: var numSections = sectionsArray.length;
805: document.$formname.$sec_element.length = 0;
806: if (numSections == 0) {
807: document.$formname.$sec_element.multiple=false;
808: document.$formname.$sec_element.size=1;
809: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
810: } else {
811: if (numSections == 1) {
812: document.$formname.$sec_element.multiple=false;
813: document.$formname.$sec_element.size=1;
814: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
815: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
816: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
817: } else {
818: for (var i=0; i<numSections; i++) {
819: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
820: }
821: document.$formname.$sec_element.multiple=true
822: if (numSections < 3) {
823: document.$formname.$sec_element.size=numSections;
824: } else {
825: document.$formname.$sec_element.size=3;
826: }
827: document.$formname.$sec_element.options[0].selected = false
828: }
829: }
1.91 www 830: }
1.905 raeburn 831:
832: function setRole(crstype) {
1.468 raeburn 833: |;
1.905 raeburn 834: if ($role_element eq '') {
835: $setsections .= ' return;
836: }
837: ';
838: } else {
839: $setsections .= qq|
840: var elementLength = document.$formname.$role_element.length;
841: var allroles = Array($rolestr);
842: var courserolenames = Array($courserolestr);
843: var communityrolenames = Array($communityrolestr);
844: if (elementLength != undefined) {
845: if (document.$formname.$role_element.options[5].value == 'cc') {
846: if (crstype == 'Course') {
847: return;
848: } else {
849: allroles[5] = 'co';
850: for (var i=0; i<6; i++) {
851: document.$formname.$role_element.options[i].value = allroles[i];
852: document.$formname.$role_element.options[i].text = communityrolenames[i];
853: }
854: }
855: } else {
856: if (crstype == 'Community') {
857: return;
858: } else {
859: allroles[5] = 'cc';
860: for (var i=0; i<6; i++) {
861: document.$formname.$role_element.options[i].value = allroles[i];
862: document.$formname.$role_element.options[i].text = courserolenames[i];
863: }
864: }
865: }
866: }
867: return;
868: }
869: |;
870: }
1.1116 raeburn 871: if ($credits_element) {
872: $setsections .= qq|
873: function setCredits(defaultcredits) {
874: document.$formname.$credits_element.value = defaultcredits;
875: return;
876: }
877: |;
878: }
1.468 raeburn 879: return $setsections;
880: }
881:
1.91 www 882: sub selectcourse_link {
1.909 raeburn 883: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
884: $typeelement) = @_;
885: my $type = $selecttype;
1.871 raeburn 886: my $linktext = &mt('Select Course');
887: if ($selecttype eq 'Community') {
1.909 raeburn 888: $linktext = &mt('Select Community');
1.1239 raeburn 889: } elsif ($selecttype eq 'Placement') {
890: $linktext = &mt('Select Placement Test');
1.906 raeburn 891: } elsif ($selecttype eq 'Course/Community') {
892: $linktext = &mt('Select Course/Community');
1.909 raeburn 893: $type = '';
1.1019 raeburn 894: } elsif ($selecttype eq 'Select') {
895: $linktext = &mt('Select');
896: $type = '';
1.871 raeburn 897: }
1.787 bisitz 898: return '<span class="LC_nobreak">'
899: ."<a href='"
900: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
901: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 902: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 903: ."'>".$linktext.'</a>'
1.787 bisitz 904: .'</span>';
1.74 www 905: }
1.42 matthew 906:
1.653 raeburn 907: sub selectauthor_link {
908: my ($form,$udom)=@_;
909: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
910: &mt('Select Author').'</a>';
911: }
912:
1.876 raeburn 913: sub selectuser_link {
1.881 raeburn 914: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 915: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 916: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 917: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 918: ');">'.$linktext.'</a>';
1.876 raeburn 919: }
920:
1.273 raeburn 921: sub check_uncheck_jscript {
922: my $jscript = <<"ENDSCRT";
923: function checkAll(field) {
924: if (field.length > 0) {
925: for (i = 0; i < field.length; i++) {
1.1093 raeburn 926: if (!field[i].disabled) {
927: field[i].checked = true;
928: }
1.273 raeburn 929: }
930: } else {
1.1093 raeburn 931: if (!field.disabled) {
932: field.checked = true;
933: }
1.273 raeburn 934: }
935: }
936:
937: function uncheckAll(field) {
938: if (field.length > 0) {
939: for (i = 0; i < field.length; i++) {
940: field[i].checked = false ;
1.543 albertel 941: }
942: } else {
1.273 raeburn 943: field.checked = false ;
944: }
945: }
946: ENDSCRT
947: return $jscript;
948: }
949:
1.656 www 950: sub select_timezone {
1.1256 raeburn 951: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
952: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 953: if ($includeempty) {
954: $output .= '<option value=""';
955: if (($selected eq '') || ($selected eq 'local')) {
956: $output .= ' selected="selected" ';
957: }
958: $output .= '> </option>';
959: }
1.657 raeburn 960: my @timezones = DateTime::TimeZone->all_names;
961: foreach my $tzone (@timezones) {
962: $output.= '<option value="'.$tzone.'"';
963: if ($tzone eq $selected) {
964: $output.=' selected="selected"';
965: }
966: $output.=">$tzone</option>\n";
1.656 www 967: }
968: $output.="</select>";
969: return $output;
970: }
1.273 raeburn 971:
1.687 raeburn 972: sub select_datelocale {
1.1256 raeburn 973: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
974: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 975: if ($includeempty) {
976: $output .= '<option value=""';
977: if ($selected eq '') {
978: $output .= ' selected="selected" ';
979: }
980: $output .= '> </option>';
981: }
1.1241 raeburn 982: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 983: my (@possibles,%locale_names);
1.1241 raeburn 984: my @locales = DateTime::Locale->ids();
985: foreach my $id (@locales) {
986: if ($id ne '') {
987: my ($en_terr,$native_terr);
988: my $loc = DateTime::Locale->load($id);
989: if (ref($loc)) {
990: $en_terr = $loc->name();
991: $native_terr = $loc->native_name();
1.687 raeburn 992: if (grep(/^en$/,@languages) || !@languages) {
993: if ($en_terr ne '') {
994: $locale_names{$id} = '('.$en_terr.')';
995: } elsif ($native_terr ne '') {
996: $locale_names{$id} = $native_terr;
997: }
998: } else {
999: if ($native_terr ne '') {
1000: $locale_names{$id} = $native_terr.' ';
1001: } elsif ($en_terr ne '') {
1002: $locale_names{$id} = '('.$en_terr.')';
1003: }
1004: }
1.1220 raeburn 1005: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1006: push(@possibles,$id);
1007: }
1.687 raeburn 1008: }
1009: }
1010: foreach my $item (sort(@possibles)) {
1011: $output.= '<option value="'.$item.'"';
1012: if ($item eq $selected) {
1013: $output.=' selected="selected"';
1014: }
1015: $output.=">$item";
1016: if ($locale_names{$item} ne '') {
1.1220 raeburn 1017: $output.=' '.$locale_names{$item};
1.687 raeburn 1018: }
1019: $output.="</option>\n";
1020: }
1021: $output.="</select>";
1022: return $output;
1023: }
1024:
1.792 raeburn 1025: sub select_language {
1.1256 raeburn 1026: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1027: my %langchoices;
1028: if ($includeempty) {
1.1117 raeburn 1029: %langchoices = ('' => 'No language preference');
1.792 raeburn 1030: }
1031: foreach my $id (&languageids()) {
1032: my $code = &supportedlanguagecode($id);
1033: if ($code) {
1034: $langchoices{$code} = &plainlanguagedescription($id);
1035: }
1036: }
1.1117 raeburn 1037: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1038: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1039: }
1040:
1.42 matthew 1041: =pod
1.36 matthew 1042:
1.1088 foxr 1043:
1044: =item * &list_languages()
1045:
1046: Returns an array reference that is suitable for use in language prompters.
1047: Each array element is itself a two element array. The first element
1048: is the language code. The second element a descsriptiuon of the
1049: language itself. This is suitable for use in e.g.
1050: &Apache::edit::select_arg (once dereferenced that is).
1051:
1052: =cut
1053:
1054: sub list_languages {
1055: my @lang_choices;
1056:
1057: foreach my $id (&languageids()) {
1058: my $code = &supportedlanguagecode($id);
1059: if ($code) {
1060: my $selector = $supported_codes{$id};
1061: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1062: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1063: }
1064: }
1065: return \@lang_choices;
1066: }
1067:
1068: =pod
1069:
1.648 raeburn 1070: =item * &linked_select_forms(...)
1.36 matthew 1071:
1072: linked_select_forms returns a string containing a <script></script> block
1073: and html for two <select> menus. The select menus will be linked in that
1074: changing the value of the first menu will result in new values being placed
1075: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1076: order unless a defined order is provided.
1.36 matthew 1077:
1078: linked_select_forms takes the following ordered inputs:
1079:
1080: =over 4
1081:
1.112 bowersj2 1082: =item * $formname, the name of the <form> tag
1.36 matthew 1083:
1.112 bowersj2 1084: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1085:
1.112 bowersj2 1086: =item * $firstdefault, the default value for the first menu
1.36 matthew 1087:
1.112 bowersj2 1088: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1089:
1.112 bowersj2 1090: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1091:
1.112 bowersj2 1092: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1093:
1.609 raeburn 1094: =item * $menuorder, the order of values in the first menu
1095:
1.1115 raeburn 1096: =item * $onchangefirst, additional javascript call to execute for an onchange
1097: event for the first <select> tag
1098:
1099: =item * $onchangesecond, additional javascript call to execute for an onchange
1100: event for the second <select> tag
1101:
1.1245 raeburn 1102: =item * $suffix, to differentiate separate uses of select2data javascript
1103: objects in a page.
1104:
1.41 ng 1105: =back
1106:
1.36 matthew 1107: Below is an example of such a hash. Only the 'text', 'default', and
1108: 'select2' keys must appear as stated. keys(%menu) are the possible
1109: values for the first select menu. The text that coincides with the
1.41 ng 1110: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1111: and text for the second menu are given in the hash pointed to by
1112: $menu{$choice1}->{'select2'}.
1113:
1.112 bowersj2 1114: my %menu = ( A1 => { text =>"Choice A1" ,
1115: default => "B3",
1116: select2 => {
1117: B1 => "Choice B1",
1118: B2 => "Choice B2",
1119: B3 => "Choice B3",
1120: B4 => "Choice B4"
1.609 raeburn 1121: },
1122: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1123: },
1124: A2 => { text =>"Choice A2" ,
1125: default => "C2",
1126: select2 => {
1127: C1 => "Choice C1",
1128: C2 => "Choice C2",
1129: C3 => "Choice C3"
1.609 raeburn 1130: },
1131: order => ['C2','C1','C3'],
1.112 bowersj2 1132: },
1133: A3 => { text =>"Choice A3" ,
1134: default => "D6",
1135: select2 => {
1136: D1 => "Choice D1",
1137: D2 => "Choice D2",
1138: D3 => "Choice D3",
1139: D4 => "Choice D4",
1140: D5 => "Choice D5",
1141: D6 => "Choice D6",
1142: D7 => "Choice D7"
1.609 raeburn 1143: },
1144: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1145: }
1146: );
1.36 matthew 1147:
1148: =cut
1149:
1150: sub linked_select_forms {
1151: my ($formname,
1152: $middletext,
1153: $firstdefault,
1154: $firstselectname,
1155: $secondselectname,
1.609 raeburn 1156: $hashref,
1157: $menuorder,
1.1115 raeburn 1158: $onchangefirst,
1.1245 raeburn 1159: $onchangesecond,
1160: $suffix
1.36 matthew 1161: ) = @_;
1162: my $second = "document.$formname.$secondselectname";
1163: my $first = "document.$formname.$firstselectname";
1164: # output the javascript to do the changing
1165: my $result = '';
1.776 bisitz 1166: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1167: $result.="// <![CDATA[\n";
1.1245 raeburn 1168: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1169: $" = '","';
1170: my $debug = '';
1171: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1172: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1173: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1174: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1175: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1176: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1177: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1178: @s2values = @{$hashref->{$s1}->{'order'}};
1179: }
1.36 matthew 1180: $result.="\"@s2values\");\n";
1.1245 raeburn 1181: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1182: my @s2texts;
1183: foreach my $value (@s2values) {
1.1263 raeburn 1184: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1185: }
1186: $result.="\"@s2texts\");\n";
1187: }
1188: $"=' ';
1189: $result.= <<"END";
1190:
1.1245 raeburn 1191: function select1${suffix}_changed() {
1.36 matthew 1192: // Determine new choice
1.1245 raeburn 1193: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1194: // update select2
1.1245 raeburn 1195: var values = select2data${suffix}[newvalue].values;
1196: var texts = select2data${suffix}[newvalue].texts;
1197: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1198: var i;
1199: // out with the old
1.1245 raeburn 1200: $second.options.length = 0;
1201: // in with the new
1.36 matthew 1202: for (i=0;i<values.length; i++) {
1203: $second.options[i] = new Option(values[i]);
1.143 matthew 1204: $second.options[i].value = values[i];
1.36 matthew 1205: $second.options[i].text = texts[i];
1206: if (values[i] == select2def) {
1207: $second.options[i].selected = true;
1208: }
1209: }
1210: }
1.824 bisitz 1211: // ]]>
1.36 matthew 1212: </script>
1213: END
1214: # output the initial values for the selection lists
1.1245 raeburn 1215: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1216: my @order = sort(keys(%{$hashref}));
1217: if (ref($menuorder) eq 'ARRAY') {
1218: @order = @{$menuorder};
1219: }
1220: foreach my $value (@order) {
1.36 matthew 1221: $result.=" <option value=\"$value\" ";
1.253 albertel 1222: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1223: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1224: }
1225: $result .= "</select>\n";
1226: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1227: $result .= $middletext;
1.1115 raeburn 1228: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1229: if ($onchangesecond) {
1230: $result .= ' onchange="'.$onchangesecond.'"';
1231: }
1232: $result .= ">\n";
1.36 matthew 1233: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1234:
1235: my @secondorder = sort(keys(%select2));
1236: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1237: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1238: }
1239: foreach my $value (@secondorder) {
1.36 matthew 1240: $result.=" <option value=\"$value\" ";
1.253 albertel 1241: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1242: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1243: }
1244: $result .= "</select>\n";
1245: # return $debug;
1246: return $result;
1247: } # end of sub linked_select_forms {
1248:
1.45 matthew 1249: =pod
1.44 bowersj2 1250:
1.973 raeburn 1251: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1252:
1.112 bowersj2 1253: Returns a string corresponding to an HTML link to the given help
1254: $topic, where $topic corresponds to the name of a .tex file in
1255: /home/httpd/html/adm/help/tex, with underscores replaced by
1256: spaces.
1257:
1258: $text will optionally be linked to the same topic, allowing you to
1259: link text in addition to the graphic. If you do not want to link
1260: text, but wish to specify one of the later parameters, pass an
1261: empty string.
1262:
1263: $stayOnPage is a value that will be interpreted as a boolean. If true,
1264: the link will not open a new window. If false, the link will open
1265: a new window using Javascript. (Default is false.)
1266:
1267: $width and $height are optional numerical parameters that will
1268: override the width and height of the popped up window, which may
1.973 raeburn 1269: be useful for certain help topics with big pictures included.
1270:
1271: $imgid is the id of the img tag used for the help icon. This may be
1272: used in a javascript call to switch the image src. See
1273: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1274:
1275: =cut
1276:
1277: sub help_open_topic {
1.973 raeburn 1278: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1279: $text = "" if (not defined $text);
1.44 bowersj2 1280: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1281: $width = 500 if (not defined $width);
1.44 bowersj2 1282: $height = 400 if (not defined $height);
1283: my $filename = $topic;
1284: $filename =~ s/ /_/g;
1285:
1.48 bowersj2 1286: my $template = "";
1287: my $link;
1.572 banghart 1288:
1.159 www 1289: $topic=~s/\W/\_/g;
1.44 bowersj2 1290:
1.572 banghart 1291: if (!$stayOnPage) {
1.1033 www 1292: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1293: } elsif ($stayOnPage eq 'popup') {
1294: $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 1295: } else {
1.48 bowersj2 1296: $link = "/adm/help/${filename}.hlp";
1297: }
1298:
1299: # Add the text
1.1314 raeburn 1300: my $target = ' target="_top"';
1301: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1302: $target = '';
1303: }
1.755 neumanie 1304: if ($text ne "") {
1.763 bisitz 1305: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1306: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1307: .$text.'</a>';
1.48 bowersj2 1308: }
1309:
1.763 bisitz 1310: # (Always) Add the graphic
1.179 matthew 1311: my $title = &mt('Online Help');
1.667 raeburn 1312: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1313: if ($imgid ne '') {
1314: $imgid = ' id="'.$imgid.'"';
1315: }
1.1314 raeburn 1316: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1317: .'<img src="'.$helpicon.'" border="0"'
1318: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1319: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1320: .' /></a>';
1321: if ($text ne "") {
1322: $template.='</span>';
1323: }
1.44 bowersj2 1324: return $template;
1325:
1.106 bowersj2 1326: }
1327:
1328: # This is a quicky function for Latex cheatsheet editing, since it
1329: # appears in at least four places
1330: sub helpLatexCheatsheet {
1.1037 www 1331: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1332: my $out;
1.106 bowersj2 1333: my $addOther = '';
1.732 raeburn 1334: if ($topic) {
1.1037 www 1335: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1336: }
1337: $out = '<span>' # Start cheatsheet
1338: .$addOther
1339: .'<span>'
1.1037 www 1340: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1341: .'</span> <span>'
1.1037 www 1342: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1343: .'</span>';
1.732 raeburn 1344: unless ($not_author) {
1.1186 kruse 1345: $out .= '<span>'
1346: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1347: .'</span> <span>'
1348: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1349: .'</span>';
1.732 raeburn 1350: }
1.763 bisitz 1351: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1352: return $out;
1.172 www 1353: }
1354:
1.430 albertel 1355: sub general_help {
1356: my $helptopic='Student_Intro';
1357: if ($env{'request.role'}=~/^(ca|au)/) {
1358: $helptopic='Authoring_Intro';
1.907 raeburn 1359: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1360: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1361: } elsif ($env{'request.role'}=~/^dc/) {
1362: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1363: }
1364: return $helptopic;
1365: }
1366:
1367: sub update_help_link {
1368: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1369: my $origurl = $ENV{'REQUEST_URI'};
1370: $origurl=~s|^/~|/priv/|;
1371: my $timestamp = time;
1372: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1373: $$datum = &escape($$datum);
1374: }
1375:
1376: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1377: my $output .= <<"ENDOUTPUT";
1378: <script type="text/javascript">
1.824 bisitz 1379: // <![CDATA[
1.430 albertel 1380: banner_link = '$banner_link';
1.824 bisitz 1381: // ]]>
1.430 albertel 1382: </script>
1383: ENDOUTPUT
1384: return $output;
1385: }
1386:
1387: # now just updates the help link and generates a blue icon
1.193 raeburn 1388: sub help_open_menu {
1.430 albertel 1389: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1390: = @_;
1.949 droeschl 1391: $stayOnPage = 1;
1.430 albertel 1392: my $output;
1393: if ($component_help) {
1394: if (!$text) {
1395: $output=&help_open_topic($component_help,undef,$stayOnPage,
1396: $width,$height);
1397: } else {
1398: my $help_text;
1399: $help_text=&unescape($topic);
1400: $output='<table><tr><td>'.
1401: &help_open_topic($component_help,$help_text,$stayOnPage,
1402: $width,$height).'</td></tr></table>';
1403: }
1404: }
1405: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1406: return $output.$banner_link;
1407: }
1408:
1409: sub top_nav_help {
1410: my ($text) = @_;
1.436 albertel 1411: $text = &mt($text);
1.949 droeschl 1412: my $stay_on_page = 1;
1413:
1.1168 raeburn 1414: my ($link,$banner_link);
1415: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1416: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1417: : "javascript:helpMenu('open')";
1418: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1419: }
1.201 raeburn 1420: my $title = &mt('Get help');
1.1168 raeburn 1421: if ($link) {
1422: return <<"END";
1.436 albertel 1423: $banner_link
1.1159 raeburn 1424: <a href="$link" title="$title">$text</a>
1.436 albertel 1425: END
1.1168 raeburn 1426: } else {
1427: return ' '.$text.' ';
1428: }
1.436 albertel 1429: }
1430:
1431: sub help_menu_js {
1.1154 raeburn 1432: my ($httphost) = @_;
1.949 droeschl 1433: my $stayOnPage = 1;
1.436 albertel 1434: my $width = 620;
1435: my $height = 600;
1.430 albertel 1436: my $helptopic=&general_help();
1.1154 raeburn 1437: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1438: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1439: my $start_page =
1440: &Apache::loncommon::start_page('Help Menu', undef,
1441: {'frameset' => 1,
1442: 'js_ready' => 1,
1.1154 raeburn 1443: 'use_absolute' => $httphost,
1.331 albertel 1444: 'add_entries' => {
1.1168 raeburn 1445: 'border' => '0',
1.579 raeburn 1446: 'rows' => "110,*",},});
1.331 albertel 1447: my $end_page =
1448: &Apache::loncommon::end_page({'frameset' => 1,
1449: 'js_ready' => 1,});
1450:
1.436 albertel 1451: my $template .= <<"ENDTEMPLATE";
1452: <script type="text/javascript">
1.877 bisitz 1453: // <![CDATA[
1.253 albertel 1454: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1455: var banner_link = '';
1.243 raeburn 1456: function helpMenu(target) {
1457: var caller = this;
1458: if (target == 'open') {
1459: var newWindow = null;
1460: try {
1.262 albertel 1461: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1462: }
1463: catch(error) {
1464: writeHelp(caller);
1465: return;
1466: }
1467: if (newWindow) {
1468: caller = newWindow;
1469: }
1.193 raeburn 1470: }
1.243 raeburn 1471: writeHelp(caller);
1472: return;
1473: }
1474: function writeHelp(caller) {
1.1168 raeburn 1475: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1476: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1477: caller.document.close();
1478: caller.focus();
1.193 raeburn 1479: }
1.877 bisitz 1480: // END LON-CAPA Internal -->
1.253 albertel 1481: // ]]>
1.436 albertel 1482: </script>
1.193 raeburn 1483: ENDTEMPLATE
1484: return $template;
1485: }
1486:
1.172 www 1487: sub help_open_bug {
1488: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1489: unless ($env{'user.adv'}) { return ''; }
1.172 www 1490: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1491: $text = "" if (not defined $text);
1492: $stayOnPage=1;
1.184 albertel 1493: $width = 600 if (not defined $width);
1494: $height = 600 if (not defined $height);
1.172 www 1495:
1496: $topic=~s/\W+/\+/g;
1497: my $link='';
1498: my $template='';
1.379 albertel 1499: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1500: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1501: if (!$stayOnPage)
1502: {
1503: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1504: }
1505: else
1506: {
1507: $link = $url;
1508: }
1.1314 raeburn 1509:
1510: my $target = ' target="_top"';
1511: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1512: $target = '';
1513: }
1.172 www 1514: # Add the text
1515: if ($text ne "")
1516: {
1517: $template .=
1518: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1519: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1520: }
1521:
1522: # Add the graphic
1.179 matthew 1523: my $title = &mt('Report a Bug');
1.215 albertel 1524: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1525: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1526: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1527: ENDTEMPLATE
1528: if ($text ne '') { $template.='</td></tr></table>' };
1529: return $template;
1530:
1531: }
1532:
1533: sub help_open_faq {
1534: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1535: unless ($env{'user.adv'}) { return ''; }
1.172 www 1536: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1537: $text = "" if (not defined $text);
1538: $stayOnPage=1;
1539: $width = 350 if (not defined $width);
1540: $height = 400 if (not defined $height);
1541:
1542: $topic=~s/\W+/\+/g;
1543: my $link='';
1544: my $template='';
1545: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1546: if (!$stayOnPage)
1547: {
1548: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1549: }
1550: else
1551: {
1552: $link = $url;
1553: }
1554:
1555: # Add the text
1556: if ($text ne "")
1557: {
1558: $template .=
1.173 www 1559: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1560: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1561: }
1562:
1563: # Add the graphic
1.179 matthew 1564: my $title = &mt('View the FAQ');
1.215 albertel 1565: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1566: $template .= <<"ENDTEMPLATE";
1.436 albertel 1567: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1568: ENDTEMPLATE
1569: if ($text ne '') { $template.='</td></tr></table>' };
1570: return $template;
1571:
1.44 bowersj2 1572: }
1.37 matthew 1573:
1.180 matthew 1574: ###############################################################
1575: ###############################################################
1576:
1.45 matthew 1577: =pod
1578:
1.648 raeburn 1579: =item * &change_content_javascript():
1.256 matthew 1580:
1581: This and the next function allow you to create small sections of an
1582: otherwise static HTML page that you can update on the fly with
1583: Javascript, even in Netscape 4.
1584:
1585: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1586: must be written to the HTML page once. It will prove the Javascript
1587: function "change(name, content)". Calling the change function with the
1588: name of the section
1589: you want to update, matching the name passed to C<changable_area>, and
1590: the new content you want to put in there, will put the content into
1591: that area.
1592:
1593: B<Note>: Netscape 4 only reserves enough space for the changable area
1594: to contain room for the original contents. You need to "make space"
1595: for whatever changes you wish to make, and be B<sure> to check your
1596: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1597: it's adequate for updating a one-line status display, but little more.
1598: This script will set the space to 100% width, so you only need to
1599: worry about height in Netscape 4.
1600:
1601: Modern browsers are much less limiting, and if you can commit to the
1602: user not using Netscape 4, this feature may be used freely with
1603: pretty much any HTML.
1604:
1605: =cut
1606:
1607: sub change_content_javascript {
1608: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1609: if ($env{'browser.type'} eq 'netscape' &&
1610: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1611: return (<<NETSCAPE4);
1612: function change(name, content) {
1613: doc = document.layers[name+"___escape"].layers[0].document;
1614: doc.open();
1615: doc.write(content);
1616: doc.close();
1617: }
1618: NETSCAPE4
1619: } else {
1620: # Otherwise, we need to use semi-standards-compliant code
1621: # (technically, "innerHTML" isn't standard but the equivalent
1622: # is really scary, and every useful browser supports it
1623: return (<<DOMBASED);
1624: function change(name, content) {
1625: element = document.getElementById(name);
1626: element.innerHTML = content;
1627: }
1628: DOMBASED
1629: }
1630: }
1631:
1632: =pod
1633:
1.648 raeburn 1634: =item * &changable_area($name,$origContent):
1.256 matthew 1635:
1636: This provides a "changable area" that can be modified on the fly via
1637: the Javascript code provided in C<change_content_javascript>. $name is
1638: the name you will use to reference the area later; do not repeat the
1639: same name on a given HTML page more then once. $origContent is what
1640: the area will originally contain, which can be left blank.
1641:
1642: =cut
1643:
1644: sub changable_area {
1645: my ($name, $origContent) = @_;
1646:
1.258 albertel 1647: if ($env{'browser.type'} eq 'netscape' &&
1648: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1649: # If this is netscape 4, we need to use the Layer tag
1650: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1651: } else {
1652: return "<span id='$name'>$origContent</span>";
1653: }
1654: }
1655:
1656: =pod
1657:
1.648 raeburn 1658: =item * &viewport_geometry_js
1.590 raeburn 1659:
1660: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1661:
1662: =cut
1663:
1664:
1665: sub viewport_geometry_js {
1666: return <<"GEOMETRY";
1667: var Geometry = {};
1668: function init_geometry() {
1669: if (Geometry.init) { return };
1670: Geometry.init=1;
1671: if (window.innerHeight) {
1672: Geometry.getViewportHeight = function() { return window.innerHeight; };
1673: Geometry.getViewportWidth = function() { return window.innerWidth; };
1674: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1675: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1676: }
1677: else if (document.documentElement && document.documentElement.clientHeight) {
1678: Geometry.getViewportHeight =
1679: function() { return document.documentElement.clientHeight; };
1680: Geometry.getViewportWidth =
1681: function() { return document.documentElement.clientWidth; };
1682:
1683: Geometry.getHorizontalScroll =
1684: function() { return document.documentElement.scrollLeft; };
1685: Geometry.getVerticalScroll =
1686: function() { return document.documentElement.scrollTop; };
1687: }
1688: else if (document.body.clientHeight) {
1689: Geometry.getViewportHeight =
1690: function() { return document.body.clientHeight; };
1691: Geometry.getViewportWidth =
1692: function() { return document.body.clientWidth; };
1693: Geometry.getHorizontalScroll =
1694: function() { return document.body.scrollLeft; };
1695: Geometry.getVerticalScroll =
1696: function() { return document.body.scrollTop; };
1697: }
1698: }
1699:
1700: GEOMETRY
1701: }
1702:
1703: =pod
1704:
1.648 raeburn 1705: =item * &viewport_size_js()
1.590 raeburn 1706:
1707: 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.
1708:
1709: =cut
1710:
1711: sub viewport_size_js {
1712: my $geometry = &viewport_geometry_js();
1713: return <<"DIMS";
1714:
1715: $geometry
1716:
1717: function getViewportDims(width,height) {
1718: init_geometry();
1719: width.value = Geometry.getViewportWidth();
1720: height.value = Geometry.getViewportHeight();
1721: return;
1722: }
1723:
1724: DIMS
1725: }
1726:
1727: =pod
1728:
1.648 raeburn 1729: =item * &resize_textarea_js()
1.565 albertel 1730:
1731: emits the needed javascript to resize a textarea to be as big as possible
1732:
1733: creates a function resize_textrea that takes two IDs first should be
1734: the id of the element to resize, second should be the id of a div that
1735: surrounds everything that comes after the textarea, this routine needs
1736: to be attached to the <body> for the onload and onresize events.
1737:
1.648 raeburn 1738: =back
1.565 albertel 1739:
1740: =cut
1741:
1742: sub resize_textarea_js {
1.590 raeburn 1743: my $geometry = &viewport_geometry_js();
1.565 albertel 1744: return <<"RESIZE";
1745: <script type="text/javascript">
1.824 bisitz 1746: // <![CDATA[
1.590 raeburn 1747: $geometry
1.565 albertel 1748:
1.588 albertel 1749: function getX(element) {
1750: var x = 0;
1751: while (element) {
1752: x += element.offsetLeft;
1753: element = element.offsetParent;
1754: }
1755: return x;
1756: }
1757: function getY(element) {
1758: var y = 0;
1759: while (element) {
1760: y += element.offsetTop;
1761: element = element.offsetParent;
1762: }
1763: return y;
1764: }
1765:
1766:
1.565 albertel 1767: function resize_textarea(textarea_id,bottom_id) {
1768: init_geometry();
1769: var textarea = document.getElementById(textarea_id);
1770: //alert(textarea);
1771:
1.588 albertel 1772: var textarea_top = getY(textarea);
1.565 albertel 1773: var textarea_height = textarea.offsetHeight;
1774: var bottom = document.getElementById(bottom_id);
1.588 albertel 1775: var bottom_top = getY(bottom);
1.565 albertel 1776: var bottom_height = bottom.offsetHeight;
1777: var window_height = Geometry.getViewportHeight();
1.588 albertel 1778: var fudge = 23;
1.565 albertel 1779: var new_height = window_height-fudge-textarea_top-bottom_height;
1780: if (new_height < 300) {
1781: new_height = 300;
1782: }
1783: textarea.style.height=new_height+'px';
1784: }
1.824 bisitz 1785: // ]]>
1.565 albertel 1786: </script>
1787: RESIZE
1788:
1789: }
1790:
1.1205 golterma 1791: sub colorfuleditor_js {
1.1248 raeburn 1792: my $browse_or_search;
1793: my $respath;
1794: my ($cnum,$cdom) = &crsauthor_url();
1795: if ($cnum) {
1796: $respath = "/res/$cdom/$cnum/";
1797: my %js_lt = &Apache::lonlocal::texthash(
1798: sunm => 'Sub-directory name',
1799: save => 'Save page to make this permanent',
1800: );
1801: &js_escape(\%js_lt);
1802: $browse_or_search = <<"END";
1803:
1804: function toggleChooser(form,element,titleid,only,search) {
1805: var disp = 'none';
1806: if (document.getElementById('chooser_'+element)) {
1807: var curr = document.getElementById('chooser_'+element).style.display;
1808: if (curr == 'none') {
1809: disp='inline';
1810: if (form.elements['chooser_'+element].length) {
1811: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1812: form.elements['chooser_'+element][i].checked = false;
1813: }
1814: }
1815: toggleResImport(form,element);
1816: }
1817: document.getElementById('chooser_'+element).style.display = disp;
1818: }
1819: }
1820:
1821: function toggleCrsFile(form,element,numdirs) {
1822: if (document.getElementById('chooser_'+element+'_crsres')) {
1823: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1824: if (curr == 'none') {
1825: if (numdirs) {
1826: form.elements['coursepath_'+element].selectedIndex = 0;
1827: if (numdirs > 1) {
1828: window['select1'+element+'_changed']();
1829: }
1830: }
1831: }
1832: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1833:
1834: }
1835: if (document.getElementById('chooser_'+element+'_upload')) {
1836: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1837: if (document.getElementById('uploadcrsres_'+element)) {
1838: document.getElementById('uploadcrsres_'+element).value = '';
1839: }
1840: }
1841: return;
1842: }
1843:
1844: function toggleCrsUpload(form,element,numcrsdirs) {
1845: if (document.getElementById('chooser_'+element+'_crsres')) {
1846: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1847: }
1848: if (document.getElementById('chooser_'+element+'_upload')) {
1849: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1850: if (curr == 'none') {
1851: if (numcrsdirs) {
1852: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1853: form.elements['newsubdir_'+element][0].checked = true;
1854: toggleNewsubdir(form,element);
1855: }
1856: }
1857: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1858: }
1859: return;
1860: }
1861:
1862: function toggleResImport(form,element) {
1863: var choices = new Array('crsres','upload');
1864: for (var i=0; i<choices.length; i++) {
1865: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1866: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1867: }
1868: }
1869: }
1870:
1871: function toggleNewsubdir(form,element) {
1872: var newsub = form.elements['newsubdir_'+element];
1873: if (newsub) {
1874: if (newsub.length) {
1875: for (var j=0; j<newsub.length; j++) {
1876: if (newsub[j].checked) {
1877: if (document.getElementById('newsubdirname_'+element)) {
1878: if (newsub[j].value == '1') {
1879: document.getElementById('newsubdirname_'+element).type = "text";
1880: if (document.getElementById('newsubdir_'+element)) {
1881: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1882: }
1883: } else {
1884: document.getElementById('newsubdirname_'+element).type = "hidden";
1885: document.getElementById('newsubdirname_'+element).value = "";
1886: document.getElementById('newsubdir_'+element).innerHTML = "";
1887: }
1888: }
1889: break;
1890: }
1891: }
1892: }
1893: }
1894: }
1895:
1896: function updateCrsFile(form,element) {
1897: var directory = form.elements['coursepath_'+element];
1898: var filename = form.elements['coursefile_'+element];
1899: var path = directory.options[directory.selectedIndex].value;
1900: var file = filename.options[filename.selectedIndex].value;
1901: form.elements[element].value = '$respath';
1902: if (path == '/') {
1903: form.elements[element].value += file;
1904: } else {
1905: form.elements[element].value += path+'/'+file;
1906: }
1907: unClean();
1908: if (document.getElementById('previewimg_'+element)) {
1909: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1910: var newsrc = document.getElementById('previewimg_'+element).src;
1911: }
1912: if (document.getElementById('showimg_'+element)) {
1913: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1914: }
1915: toggleChooser(form,element);
1916: return;
1917: }
1918:
1919: function uploadDone(suffix,name) {
1920: if (name) {
1921: document.forms["lonhomework"].elements[suffix].value = name;
1922: unClean();
1923: toggleChooser(document.forms["lonhomework"],suffix);
1924: }
1925: }
1926:
1927: \$(document).ready(function(){
1928:
1929: \$(document).delegate('form :submit', 'click', function( event ) {
1930: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1931: var buttonId = this.id;
1932: var suffix = buttonId.toString();
1933: suffix = suffix.replace(/^crsupload_/,'');
1934: event.preventDefault();
1935: document.lonhomework.target = 'crsupload_target_'+suffix;
1936: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1937: \$(this.form).submit();
1938: document.lonhomework.target = '';
1939: if (document.getElementById('crsuploadto_'+suffix)) {
1940: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1941: }
1942: return false;
1943: }
1944: });
1945: });
1946: END
1947: }
1.1205 golterma 1948: return <<"COLORFULEDIT"
1949: <script type="text/javascript">
1950: // <![CDATA[>
1951: function fold_box(curDepth, lastresource){
1952:
1953: // we need a list because there can be several blocks you need to fold in one tag
1954: var block = document.getElementsByName('foldblock_'+curDepth);
1955: // but there is only one folding button per tag
1956: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1957:
1958: if(block.item(0).style.display == 'none'){
1959:
1960: foldbutton.value = '@{[&mt("Hide")]}';
1961: for (i = 0; i < block.length; i++){
1962: block.item(i).style.display = '';
1963: }
1964: }else{
1965:
1966: foldbutton.value = '@{[&mt("Show")]}';
1967: for (i = 0; i < block.length; i++){
1968: // block.item(i).style.visibility = 'collapse';
1969: block.item(i).style.display = 'none';
1970: }
1971: };
1972: saveState(lastresource);
1973: }
1974:
1975: function saveState (lastresource) {
1976:
1977: var tag_list = getTagList();
1978: if(tag_list != null){
1979: var timestamp = new Date().getTime();
1980: var key = lastresource;
1981:
1982: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1983: // starting with timestamp
1984: var value = timestamp+';';
1985:
1986: // building the list of key-value pairs
1987: for(var i = 0; i < tag_list.length; i++){
1988: value += tag_list[i]+',';
1989: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1990: }
1991:
1992: // only iterate whole storage if nothing to override
1993: if(localStorage.getItem(key) == null){
1994:
1995: // prevent storage from growing large
1996: if(localStorage.length > 50){
1997: var regex_getTimestamp = /^(?:\d)+;/;
1998: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1999: var oldest_key;
2000:
2001: for(var i = 1; i < localStorage.length; i++){
2002: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2003: oldest_key = localStorage.key(i);
2004: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2005: }
2006: }
2007: localStorage.removeItem(oldest_key);
2008: }
2009: }
2010: localStorage.setItem(key,value);
2011: }
2012: }
2013:
2014: // restore folding status of blocks (on page load)
2015: function restoreState (lastresource) {
2016: if(localStorage.getItem(lastresource) != null){
2017: var key = lastresource;
2018: var value = localStorage.getItem(key);
2019: var regex_delTimestamp = /^\d+;/;
2020:
2021: value.replace(regex_delTimestamp, '');
2022:
2023: var valueArr = value.split(';');
2024: var pairs;
2025: var elements;
2026: for (var i = 0; i < valueArr.length; i++){
2027: pairs = valueArr[i].split(',');
2028: elements = document.getElementsByName(pairs[0]);
2029:
2030: for (var j = 0; j < elements.length; j++){
2031: elements[j].style.display = pairs[1];
2032: if (pairs[1] == "none"){
2033: var regex_id = /([_\\d]+)\$/;
2034: regex_id.exec(pairs[0]);
2035: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2036: }
2037: }
2038: }
2039: }
2040: }
2041:
2042: function getTagList () {
2043:
2044: var stringToSearch = document.lonhomework.innerHTML;
2045:
2046: var ret = new Array();
2047: var regex_findBlock = /(foldblock_.*?)"/g;
2048: var tag_list = stringToSearch.match(regex_findBlock);
2049:
2050: if(tag_list != null){
2051: for(var i = 0; i < tag_list.length; i++){
2052: ret.push(tag_list[i].replace(/"/, ''));
2053: }
2054: }
2055: return ret;
2056: }
2057:
2058: function saveScrollPosition (resource) {
2059: var tag_list = getTagList();
2060:
2061: // we dont always want to jump to the first block
2062: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2063: if(\$(window).scrollTop() > 170){
2064: if(tag_list != null){
2065: var result;
2066: for(var i = 0; i < tag_list.length; i++){
2067: if(isElementInViewport(tag_list[i])){
2068: result += tag_list[i]+';';
2069: }
2070: }
2071: sessionStorage.setItem('anchor_'+resource, result);
2072: }
2073: } else {
2074: // we dont need to save zero, just delete the item to leave everything tidy
2075: sessionStorage.removeItem('anchor_'+resource);
2076: }
2077: }
2078:
2079: function restoreScrollPosition(resource){
2080:
2081: var elem = sessionStorage.getItem('anchor_'+resource);
2082: if(elem != null){
2083: var tag_list = elem.split(';');
2084: var elem_list;
2085:
2086: for(var i = 0; i < tag_list.length; i++){
2087: elem_list = document.getElementsByName(tag_list[i]);
2088:
2089: if(elem_list.length > 0){
2090: elem = elem_list[0];
2091: break;
2092: }
2093: }
2094: elem.scrollIntoView();
2095: }
2096: }
2097:
2098: function isElementInViewport(el) {
2099:
2100: // change to last element instead of first
2101: var elem = document.getElementsByName(el);
2102: var rect = elem[0].getBoundingClientRect();
2103:
2104: return (
2105: rect.top >= 0 &&
2106: rect.left >= 0 &&
2107: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2108: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2109: );
2110: }
2111:
2112: function autosize(depth){
2113: var cmInst = window['cm'+depth];
2114: var fitsizeButton = document.getElementById('fitsize'+depth);
2115:
2116: // is fixed size, switching to dynamic
2117: if (sessionStorage.getItem("autosized_"+depth) == null) {
2118: cmInst.setSize("","auto");
2119: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2120: sessionStorage.setItem("autosized_"+depth, "yes");
2121:
2122: // is dynamic size, switching to fixed
2123: } else {
2124: cmInst.setSize("","300px");
2125: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2126: sessionStorage.removeItem("autosized_"+depth);
2127: }
2128: }
2129:
1.1248 raeburn 2130: $browse_or_search
1.1205 golterma 2131:
2132: // ]]>
2133: </script>
2134: COLORFULEDIT
2135: }
2136:
2137: sub xmleditor_js {
2138: return <<XMLEDIT
2139: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2140: <script type="text/javascript">
2141: // <![CDATA[>
2142:
2143: function saveScrollPosition (resource) {
2144:
2145: var scrollPos = \$(window).scrollTop();
2146: sessionStorage.setItem(resource,scrollPos);
2147: }
2148:
2149: function restoreScrollPosition(resource){
2150:
2151: var scrollPos = sessionStorage.getItem(resource);
2152: \$(window).scrollTop(scrollPos);
2153: }
2154:
2155: // unless internet explorer
2156: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2157:
2158: \$(document).ready(function() {
2159: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2160: });
2161: }
2162:
2163: // inserts text at cursor position into codemirror (xml editor only)
2164: function insertText(text){
2165: cm.focus();
2166: var curPos = cm.getCursor();
2167: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2168: }
2169: // ]]>
2170: </script>
2171: XMLEDIT
2172: }
2173:
2174: sub insert_folding_button {
2175: my $curDepth = $Apache::lonxml::curdepth;
2176: my $lastresource = $env{'request.ambiguous'};
2177:
2178: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2179: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2180: }
2181:
1.1248 raeburn 2182: sub crsauthor_url {
2183: my ($url) = @_;
2184: if ($url eq '') {
2185: $url = $ENV{'REQUEST_URI'};
2186: }
2187: my ($cnum,$cdom);
2188: if ($env{'request.course.id'}) {
2189: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2190: if ($audom ne '' && $auname ne '') {
2191: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2192: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2193: $cnum = $auname;
2194: $cdom = $audom;
2195: }
2196: }
2197: }
2198: return ($cnum,$cdom);
2199: }
2200:
2201: sub import_crsauthor_form {
1.1265 raeburn 2202: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2203: return (0) unless ($env{'request.course.id'});
2204: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2205: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2206: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2207: return (0) unless (($cnum ne '') && ($cdom ne ''));
2208: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2209: my @ids=&Apache::lonnet::current_machine_ids();
2210: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2211:
2212: if (grep(/^\Q$crshome\E$/,@ids)) {
2213: $is_home = 1;
2214: }
2215: $relpath = "/priv/$cdom/$cnum";
2216: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2217: my %lt = &Apache::lonlocal::texthash (
2218: fnam => 'Filename',
2219: dire => 'Directory',
2220: );
2221: my $numdirs = scalar(keys(%files));
2222: my (%possexts,$singledir,@singledirfiles);
2223: if ($only) {
2224: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2225: }
2226: my (%nonemptydirs,$possdirs);
2227: if ($numdirs > 1) {
2228: my @order;
2229: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2230: if (ref($files{$key}) eq 'HASH') {
2231: my $shown = $key;
2232: if ($key eq '') {
2233: $shown = '/';
2234: }
2235: my @ordered = ();
2236: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 ! raeburn 2237: next if ($file =~ /\.rights$/);
1.1248 raeburn 2238: if ($only) {
2239: my ($ext) = ($file =~ /\.([^.]+)$/);
2240: unless ($possexts{lc($ext)}) {
2241: next;
2242: }
2243: }
2244: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2245: push(@ordered,$file);
2246: }
2247: if (@ordered) {
2248: push(@order,$key);
2249: $nonemptydirs{$key} = 1;
2250: $selimport_menus{$key}->{'text'} = $shown;
2251: $selimport_menus{$key}->{'default'} = '';
2252: $selimport_menus{$key}->{'select2'}->{''} = '';
2253: $selimport_menus{$key}->{'order'} = \@ordered;
2254: }
2255: }
2256: }
2257: $possdirs = scalar(keys(%nonemptydirs));
2258: if ($possdirs > 1) {
2259: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2260: $output = $lt{'dire'}.
2261: &linked_select_forms($form,'<br />'.
2262: $lt{'fnam'},'',
2263: $firstselectname,$secondselectname,
2264: \%selimport_menus,\@order,
2265: $onchangefirst,'',$suffix).'<br />';
2266: } elsif ($possdirs == 1) {
2267: $singledir = (keys(%nonemptydirs))[0];
2268: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2269: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2270: }
2271: delete($selimport_menus{$singledir});
2272: }
2273: } elsif ($numdirs == 1) {
2274: $singledir = (keys(%files))[0];
2275: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2276: if ($only) {
2277: my ($ext) = ($file =~ /\.([^.]+)$/);
2278: unless ($possexts{lc($ext)}) {
2279: next;
2280: }
1.1315 ! raeburn 2281: } else {
! 2282: next if ($file =~ /\.rights$/);
1.1248 raeburn 2283: }
2284: push(@singledirfiles,$file);
2285: }
2286: if (@singledirfiles) {
1.1315 ! raeburn 2287: $possdirs = 1;
1.1248 raeburn 2288: }
2289: }
2290: if (($possdirs == 1) && (@singledirfiles)) {
2291: my $showdir = $singledir;
2292: if ($singledir eq '') {
2293: $showdir = '/';
2294: }
2295: $output = $lt{'dire'}.
2296: '<select name="'.$firstselectname.'">'.
2297: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2298: '</select><br />'.
2299: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2300: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2301: foreach my $file (@singledirfiles) {
2302: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2303: }
2304: $output .= '</select><br />'."\n";
2305: }
2306: return ($possdirs,$output);
2307: }
2308:
1.565 albertel 2309: =pod
2310:
1.256 matthew 2311: =head1 Excel and CSV file utility routines
2312:
2313: =cut
2314:
2315: ###############################################################
2316: ###############################################################
2317:
2318: =pod
2319:
1.1162 raeburn 2320: =over 4
2321:
1.648 raeburn 2322: =item * &csv_translate($text)
1.37 matthew 2323:
1.185 www 2324: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2325: format.
2326:
2327: =cut
2328:
1.180 matthew 2329: ###############################################################
2330: ###############################################################
1.37 matthew 2331: sub csv_translate {
2332: my $text = shift;
2333: $text =~ s/\"/\"\"/g;
1.209 albertel 2334: $text =~ s/\n/ /g;
1.37 matthew 2335: return $text;
2336: }
1.180 matthew 2337:
2338: ###############################################################
2339: ###############################################################
2340:
2341: =pod
2342:
1.648 raeburn 2343: =item * &define_excel_formats()
1.180 matthew 2344:
2345: Define some commonly used Excel cell formats.
2346:
2347: Currently supported formats:
2348:
2349: =over 4
2350:
2351: =item header
2352:
2353: =item bold
2354:
2355: =item h1
2356:
2357: =item h2
2358:
2359: =item h3
2360:
1.256 matthew 2361: =item h4
2362:
2363: =item i
2364:
1.180 matthew 2365: =item date
2366:
2367: =back
2368:
2369: Inputs: $workbook
2370:
2371: Returns: $format, a hash reference.
2372:
1.1057 foxr 2373:
1.180 matthew 2374: =cut
2375:
2376: ###############################################################
2377: ###############################################################
2378: sub define_excel_formats {
2379: my ($workbook) = @_;
2380: my $format;
2381: $format->{'header'} = $workbook->add_format(bold => 1,
2382: bottom => 1,
2383: align => 'center');
2384: $format->{'bold'} = $workbook->add_format(bold=>1);
2385: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2386: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2387: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2388: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2389: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2390: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2391: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2392: return $format;
2393: }
2394:
2395: ###############################################################
2396: ###############################################################
1.113 bowersj2 2397:
2398: =pod
2399:
1.648 raeburn 2400: =item * &create_workbook()
1.255 matthew 2401:
2402: Create an Excel worksheet. If it fails, output message on the
2403: request object and return undefs.
2404:
2405: Inputs: Apache request object
2406:
2407: Returns (undef) on failure,
2408: Excel worksheet object, scalar with filename, and formats
2409: from &Apache::loncommon::define_excel_formats on success
2410:
2411: =cut
2412:
2413: ###############################################################
2414: ###############################################################
2415: sub create_workbook {
2416: my ($r) = @_;
2417: #
2418: # Create the excel spreadsheet
2419: my $filename = '/prtspool/'.
1.258 albertel 2420: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2421: time.'_'.rand(1000000000).'.xls';
2422: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2423: if (! defined($workbook)) {
2424: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2425: $r->print(
2426: '<p class="LC_error">'
2427: .&mt('Problems occurred in creating the new Excel file.')
2428: .' '.&mt('This error has been logged.')
2429: .' '.&mt('Please alert your LON-CAPA administrator.')
2430: .'</p>'
2431: );
1.255 matthew 2432: return (undef);
2433: }
2434: #
1.1014 foxr 2435: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2436: #
2437: my $format = &Apache::loncommon::define_excel_formats($workbook);
2438: return ($workbook,$filename,$format);
2439: }
2440:
2441: ###############################################################
2442: ###############################################################
2443:
2444: =pod
2445:
1.648 raeburn 2446: =item * &create_text_file()
1.113 bowersj2 2447:
1.542 raeburn 2448: Create a file to write to and eventually make available to the user.
1.256 matthew 2449: If file creation fails, outputs an error message on the request object and
2450: return undefs.
1.113 bowersj2 2451:
1.256 matthew 2452: Inputs: Apache request object, and file suffix
1.113 bowersj2 2453:
1.256 matthew 2454: Returns (undef) on failure,
2455: Filehandle and filename on success.
1.113 bowersj2 2456:
2457: =cut
2458:
1.256 matthew 2459: ###############################################################
2460: ###############################################################
2461: sub create_text_file {
2462: my ($r,$suffix) = @_;
2463: if (! defined($suffix)) { $suffix = 'txt'; };
2464: my $fh;
2465: my $filename = '/prtspool/'.
1.258 albertel 2466: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2467: time.'_'.rand(1000000000).'.'.$suffix;
2468: $fh = Apache::File->new('>/home/httpd'.$filename);
2469: if (! defined($fh)) {
2470: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2471: $r->print(
2472: '<p class="LC_error">'
2473: .&mt('Problems occurred in creating the output file.')
2474: .' '.&mt('This error has been logged.')
2475: .' '.&mt('Please alert your LON-CAPA administrator.')
2476: .'</p>'
2477: );
1.113 bowersj2 2478: }
1.256 matthew 2479: return ($fh,$filename)
1.113 bowersj2 2480: }
2481:
2482:
1.256 matthew 2483: =pod
1.113 bowersj2 2484:
2485: =back
2486:
2487: =cut
1.37 matthew 2488:
2489: ###############################################################
1.33 matthew 2490: ## Home server <option> list generating code ##
2491: ###############################################################
1.35 matthew 2492:
1.169 www 2493: # ------------------------------------------
2494:
2495: sub domain_select {
1.1289 raeburn 2496: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2497: my @possdoms;
2498: if (ref($incdoms) eq 'ARRAY') {
2499: @possdoms = @{$incdoms};
2500: } else {
2501: @possdoms = &Apache::lonnet::all_domains();
2502: }
2503:
1.169 www 2504: my %domains=map {
1.514 albertel 2505: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2506: } @possdoms;
2507:
2508: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2509: foreach my $dom (@{$excdoms}) {
2510: delete($domains{$dom});
2511: }
2512: }
2513:
1.169 www 2514: if ($multiple) {
2515: $domains{''}=&mt('Any domain');
1.550 albertel 2516: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2517: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2518: } else {
1.550 albertel 2519: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2520: return &select_form($name,$value,\%domains);
1.169 www 2521: }
2522: }
2523:
1.282 albertel 2524: #-------------------------------------------
2525:
2526: =pod
2527:
1.519 raeburn 2528: =head1 Routines for form select boxes
2529:
2530: =over 4
2531:
1.648 raeburn 2532: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2533:
2534: Returns a string containing a <select> element int multiple mode
2535:
2536:
2537: Args:
2538: $name - name of the <select> element
1.506 raeburn 2539: $value - scalar or array ref of values that should already be selected
1.282 albertel 2540: $size - number of rows long the select element is
1.283 albertel 2541: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2542: (shown text should already have been &mt())
1.506 raeburn 2543: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2544:
1.282 albertel 2545: =cut
2546:
2547: #-------------------------------------------
1.169 www 2548: sub multiple_select_form {
1.284 albertel 2549: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2550: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2551: my $output='';
1.191 matthew 2552: if (! defined($size)) {
2553: $size = 4;
1.283 albertel 2554: if (scalar(keys(%$hash))<4) {
2555: $size = scalar(keys(%$hash));
1.191 matthew 2556: }
2557: }
1.734 bisitz 2558: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2559: my @order;
1.506 raeburn 2560: if (ref($order) eq 'ARRAY') {
2561: @order = @{$order};
2562: } else {
2563: @order = sort(keys(%$hash));
1.501 banghart 2564: }
2565: if (exists($$hash{'select_form_order'})) {
2566: @order = @{$$hash{'select_form_order'}};
2567: }
2568:
1.284 albertel 2569: foreach my $key (@order) {
1.356 albertel 2570: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2571: $output.='selected="selected" ' if ($selected{$key});
2572: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2573: }
2574: $output.="</select>\n";
2575: return $output;
2576: }
2577:
1.88 www 2578: #-------------------------------------------
2579:
2580: =pod
2581:
1.1254 raeburn 2582: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2583:
2584: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2585: allow a user to select options from a ref to a hash containing:
2586: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2587: a javascript onchange item, e.g., onchange="this.form.submit();".
2588: An optional arg -- $readonly -- if true will cause the select form
2589: to be disabled, e.g., for the case where an instructor has a section-
2590: specific role, and is viewing/modifying parameters.
1.970 raeburn 2591:
1.88 www 2592: See lonrights.pm for an example invocation and use.
2593:
2594: =cut
2595:
2596: #-------------------------------------------
2597: sub select_form {
1.1228 raeburn 2598: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2599: return unless (ref($hashref) eq 'HASH');
2600: if ($onchange) {
2601: $onchange = ' onchange="'.$onchange.'"';
2602: }
1.1228 raeburn 2603: my $disabled;
2604: if ($readonly) {
2605: $disabled = ' disabled="disabled"';
2606: }
2607: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2608: my @keys;
1.970 raeburn 2609: if (exists($hashref->{'select_form_order'})) {
2610: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2611: } else {
1.970 raeburn 2612: @keys=sort(keys(%{$hashref}));
1.128 albertel 2613: }
1.356 albertel 2614: foreach my $key (@keys) {
2615: $selectform.=
2616: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2617: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2618: ">".$hashref->{$key}."</option>\n";
1.88 www 2619: }
2620: $selectform.="</select>";
2621: return $selectform;
2622: }
2623:
1.475 www 2624: # For display filters
2625:
2626: sub display_filter {
1.1074 raeburn 2627: my ($context) = @_;
1.475 www 2628: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2629: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2630: my $phraseinput = 'hidden';
2631: my $includeinput = 'hidden';
2632: my ($checked,$includetypestext);
2633: if ($env{'form.displayfilter'} eq 'containing') {
2634: $phraseinput = 'text';
2635: if ($context eq 'parmslog') {
2636: $includeinput = 'checkbox';
2637: if ($env{'form.includetypes'}) {
2638: $checked = ' checked="checked"';
2639: }
2640: $includetypestext = &mt('Include parameter types');
2641: }
2642: } else {
2643: $includetypestext = ' ';
2644: }
2645: my ($additional,$secondid,$thirdid);
2646: if ($context eq 'parmslog') {
2647: $additional =
2648: '<label><input type="'.$includeinput.'" name="includetypes"'.
2649: $checked.' name="includetypes" value="1" id="includetypes" />'.
2650: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2651: '</label>';
2652: $secondid = 'includetypes';
2653: $thirdid = 'includetypestext';
2654: }
2655: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2656: '$secondid','$thirdid')";
2657: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2658: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2659: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2660: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2661: &mt('Filter: [_1]',
1.477 www 2662: &select_form($env{'form.displayfilter'},
2663: 'displayfilter',
1.970 raeburn 2664: {'currentfolder' => 'Current folder/page',
1.477 www 2665: 'containing' => 'Containing phrase',
1.1074 raeburn 2666: 'none' => 'None'},$onchange)).' '.
2667: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2668: &HTML::Entities::encode($env{'form.containingphrase'}).
2669: '" />'.$additional;
2670: }
2671:
2672: sub display_filter_js {
2673: my $includetext = &mt('Include parameter types');
2674: return <<"ENDJS";
2675:
2676: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2677: var firstType = 'hidden';
2678: if (setter.options[setter.selectedIndex].value == 'containing') {
2679: firstType = 'text';
2680: }
2681: firstObject = document.getElementById(firstid);
2682: if (typeof(firstObject) == 'object') {
2683: if (firstObject.type != firstType) {
2684: changeInputType(firstObject,firstType);
2685: }
2686: }
2687: if (context == 'parmslog') {
2688: var secondType = 'hidden';
2689: if (firstType == 'text') {
2690: secondType = 'checkbox';
2691: }
2692: secondObject = document.getElementById(secondid);
2693: if (typeof(secondObject) == 'object') {
2694: if (secondObject.type != secondType) {
2695: changeInputType(secondObject,secondType);
2696: }
2697: }
2698: var textItem = document.getElementById(thirdid);
2699: var currtext = textItem.innerHTML;
2700: var newtext;
2701: if (firstType == 'text') {
2702: newtext = '$includetext';
2703: } else {
2704: newtext = ' ';
2705: }
2706: if (currtext != newtext) {
2707: textItem.innerHTML = newtext;
2708: }
2709: }
2710: return;
2711: }
2712:
2713: function changeInputType(oldObject,newType) {
2714: var newObject = document.createElement('input');
2715: newObject.type = newType;
2716: if (oldObject.size) {
2717: newObject.size = oldObject.size;
2718: }
2719: if (oldObject.value) {
2720: newObject.value = oldObject.value;
2721: }
2722: if (oldObject.name) {
2723: newObject.name = oldObject.name;
2724: }
2725: if (oldObject.id) {
2726: newObject.id = oldObject.id;
2727: }
2728: oldObject.parentNode.replaceChild(newObject,oldObject);
2729: return;
2730: }
2731:
2732: ENDJS
1.475 www 2733: }
2734:
1.167 www 2735: sub gradeleveldescription {
2736: my $gradelevel=shift;
2737: my %gradelevels=(0 => 'Not specified',
2738: 1 => 'Grade 1',
2739: 2 => 'Grade 2',
2740: 3 => 'Grade 3',
2741: 4 => 'Grade 4',
2742: 5 => 'Grade 5',
2743: 6 => 'Grade 6',
2744: 7 => 'Grade 7',
2745: 8 => 'Grade 8',
2746: 9 => 'Grade 9',
2747: 10 => 'Grade 10',
2748: 11 => 'Grade 11',
2749: 12 => 'Grade 12',
2750: 13 => 'Grade 13',
2751: 14 => '100 Level',
2752: 15 => '200 Level',
2753: 16 => '300 Level',
2754: 17 => '400 Level',
2755: 18 => 'Graduate Level');
2756: return &mt($gradelevels{$gradelevel});
2757: }
2758:
1.163 www 2759: sub select_level_form {
2760: my ($deflevel,$name)=@_;
2761: unless ($deflevel) { $deflevel=0; }
1.167 www 2762: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2763: for (my $i=0; $i<=18; $i++) {
2764: $selectform.="<option value=\"$i\" ".
1.253 albertel 2765: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2766: ">".&gradeleveldescription($i)."</option>\n";
2767: }
2768: $selectform.="</select>";
2769: return $selectform;
1.163 www 2770: }
1.167 www 2771:
1.35 matthew 2772: #-------------------------------------------
2773:
1.45 matthew 2774: =pod
2775:
1.1256 raeburn 2776: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2777:
2778: Returns a string containing a <select name='$name' size='1'> form to
2779: allow a user to select the domain to preform an operation in.
2780: See loncreateuser.pm for an example invocation and use.
2781:
1.90 www 2782: If the $includeempty flag is set, it also includes an empty choice ("no domain
2783: selected");
2784:
1.743 raeburn 2785: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2786:
1.910 raeburn 2787: 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.
2788:
1.1121 raeburn 2789: The optional $incdoms is a reference to an array of domains which will be the only available options.
2790:
2791: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2792:
1.1256 raeburn 2793: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2794:
1.35 matthew 2795: =cut
2796:
2797: #-------------------------------------------
1.34 matthew 2798: sub select_dom_form {
1.1256 raeburn 2799: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2800: if ($onchange) {
1.874 raeburn 2801: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2802: }
1.1256 raeburn 2803: if ($disabled) {
2804: $disabled = ' disabled="disabled"';
2805: }
1.1121 raeburn 2806: my (@domains,%exclude);
1.910 raeburn 2807: if (ref($incdoms) eq 'ARRAY') {
2808: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2809: } else {
2810: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2811: }
1.90 www 2812: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2813: if (ref($excdoms) eq 'ARRAY') {
2814: map { $exclude{$_} = 1; } @{$excdoms};
2815: }
1.1256 raeburn 2816: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2817: foreach my $dom (@domains) {
1.1121 raeburn 2818: next if ($exclude{$dom});
1.356 albertel 2819: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2820: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2821: if ($showdomdesc) {
2822: if ($dom ne '') {
2823: my $domdesc = &Apache::lonnet::domain($dom,'description');
2824: if ($domdesc ne '') {
2825: $selectdomain .= ' ('.$domdesc.')';
2826: }
2827: }
2828: }
2829: $selectdomain .= "</option>\n";
1.34 matthew 2830: }
2831: $selectdomain.="</select>";
2832: return $selectdomain;
2833: }
2834:
1.35 matthew 2835: #-------------------------------------------
2836:
1.45 matthew 2837: =pod
2838:
1.648 raeburn 2839: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2840:
1.586 raeburn 2841: input: 4 arguments (two required, two optional) -
2842: $domain - domain of new user
2843: $name - name of form element
2844: $default - Value of 'default' causes a default item to be first
2845: option, and selected by default.
2846: $hide - Value of 'hide' causes hiding of the name of the server,
2847: if 1 server found, or default, if 0 found.
1.594 raeburn 2848: output: returns 2 items:
1.586 raeburn 2849: (a) form element which contains either:
2850: (i) <select name="$name">
2851: <option value="$hostid1">$hostid $servers{$hostid}</option>
2852: <option value="$hostid2">$hostid $servers{$hostid}</option>
2853: </select>
2854: form item if there are multiple library servers in $domain, or
2855: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2856: if there is only one library server in $domain.
2857:
2858: (b) number of library servers found.
2859:
2860: See loncreateuser.pm for example of use.
1.35 matthew 2861:
2862: =cut
2863:
2864: #-------------------------------------------
1.586 raeburn 2865: sub home_server_form_item {
2866: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2867: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2868: my $result;
2869: my $numlib = keys(%servers);
2870: if ($numlib > 1) {
2871: $result .= '<select name="'.$name.'" />'."\n";
2872: if ($default) {
1.804 bisitz 2873: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2874: '</option>'."\n";
2875: }
2876: foreach my $hostid (sort(keys(%servers))) {
2877: $result.= '<option value="'.$hostid.'">'.
2878: $hostid.' '.$servers{$hostid}."</option>\n";
2879: }
2880: $result .= '</select>'."\n";
2881: } elsif ($numlib == 1) {
2882: my $hostid;
2883: foreach my $item (keys(%servers)) {
2884: $hostid = $item;
2885: }
2886: $result .= '<input type="hidden" name="'.$name.'" value="'.
2887: $hostid.'" />';
2888: if (!$hide) {
2889: $result .= $hostid.' '.$servers{$hostid};
2890: }
2891: $result .= "\n";
2892: } elsif ($default) {
2893: $result .= '<input type="hidden" name="'.$name.
2894: '" value="default" />';
2895: if (!$hide) {
2896: $result .= &mt('default');
2897: }
2898: $result .= "\n";
1.33 matthew 2899: }
1.586 raeburn 2900: return ($result,$numlib);
1.33 matthew 2901: }
1.112 bowersj2 2902:
2903: =pod
2904:
1.534 albertel 2905: =back
2906:
1.112 bowersj2 2907: =cut
1.87 matthew 2908:
2909: ###############################################################
1.112 bowersj2 2910: ## Decoding User Agent ##
1.87 matthew 2911: ###############################################################
2912:
2913: =pod
2914:
1.112 bowersj2 2915: =head1 Decoding the User Agent
2916:
2917: =over 4
2918:
2919: =item * &decode_user_agent()
1.87 matthew 2920:
2921: Inputs: $r
2922:
2923: Outputs:
2924:
2925: =over 4
2926:
1.112 bowersj2 2927: =item * $httpbrowser
1.87 matthew 2928:
1.112 bowersj2 2929: =item * $clientbrowser
1.87 matthew 2930:
1.112 bowersj2 2931: =item * $clientversion
1.87 matthew 2932:
1.112 bowersj2 2933: =item * $clientmathml
1.87 matthew 2934:
1.112 bowersj2 2935: =item * $clientunicode
1.87 matthew 2936:
1.112 bowersj2 2937: =item * $clientos
1.87 matthew 2938:
1.1137 raeburn 2939: =item * $clientmobile
2940:
1.1141 raeburn 2941: =item * $clientinfo
2942:
1.1194 raeburn 2943: =item * $clientosversion
2944:
1.87 matthew 2945: =back
2946:
1.157 matthew 2947: =back
2948:
1.87 matthew 2949: =cut
2950:
2951: ###############################################################
2952: ###############################################################
2953: sub decode_user_agent {
1.247 albertel 2954: my ($r)=@_;
1.87 matthew 2955: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2956: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2957: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2958: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2959: my $clientbrowser='unknown';
2960: my $clientversion='0';
2961: my $clientmathml='';
2962: my $clientunicode='0';
1.1137 raeburn 2963: my $clientmobile=0;
1.1194 raeburn 2964: my $clientosversion='';
1.87 matthew 2965: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2966: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2967: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2968: $clientbrowser=$bname;
2969: $httpbrowser=~/$vreg/i;
2970: $clientversion=$1;
2971: $clientmathml=($clientversion>=$minv);
2972: $clientunicode=($clientversion>=$univ);
2973: }
2974: }
2975: my $clientos='unknown';
1.1141 raeburn 2976: my $clientinfo;
1.87 matthew 2977: if (($httpbrowser=~/linux/i) ||
2978: ($httpbrowser=~/unix/i) ||
2979: ($httpbrowser=~/ux/i) ||
2980: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2981: if (($httpbrowser=~/vax/i) ||
2982: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2983: if ($httpbrowser=~/next/i) { $clientos='next'; }
2984: if (($httpbrowser=~/mac/i) ||
2985: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2986: if ($httpbrowser=~/win/i) {
2987: $clientos='win';
2988: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2989: $clientosversion = $1;
2990: }
2991: }
1.87 matthew 2992: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2993: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2994: $clientmobile=lc($1);
2995: }
1.1141 raeburn 2996: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2997: $clientinfo = 'firefox-'.$1;
2998: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2999: $clientinfo = 'chromeframe-'.$1;
3000: }
1.87 matthew 3001: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3002: $clientunicode,$clientos,$clientmobile,$clientinfo,
3003: $clientosversion);
1.87 matthew 3004: }
3005:
1.32 matthew 3006: ###############################################################
3007: ## Authentication changing form generation subroutines ##
3008: ###############################################################
3009: ##
3010: ## All of the authform_xxxxxxx subroutines take their inputs in a
3011: ## hash, and have reasonable default values.
3012: ##
3013: ## formname = the name given in the <form> tag.
1.35 matthew 3014: #-------------------------------------------
3015:
1.45 matthew 3016: =pod
3017:
1.112 bowersj2 3018: =head1 Authentication Routines
3019:
3020: =over 4
3021:
1.648 raeburn 3022: =item * &authform_xxxxxx()
1.35 matthew 3023:
3024: The authform_xxxxxx subroutines provide javascript and html forms which
3025: handle some of the conveniences required for authentication forms.
3026: This is not an optimal method, but it works.
3027:
3028: =over 4
3029:
1.112 bowersj2 3030: =item * authform_header
1.35 matthew 3031:
1.112 bowersj2 3032: =item * authform_authorwarning
1.35 matthew 3033:
1.112 bowersj2 3034: =item * authform_nochange
1.35 matthew 3035:
1.112 bowersj2 3036: =item * authform_kerberos
1.35 matthew 3037:
1.112 bowersj2 3038: =item * authform_internal
1.35 matthew 3039:
1.112 bowersj2 3040: =item * authform_filesystem
1.35 matthew 3041:
1.1310 raeburn 3042: =item * authform_lti
3043:
1.35 matthew 3044: =back
3045:
1.648 raeburn 3046: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3047:
1.35 matthew 3048: =cut
3049:
3050: #-------------------------------------------
1.32 matthew 3051: sub authform_header{
3052: my %in = (
3053: formname => 'cu',
1.80 albertel 3054: kerb_def_dom => '',
1.32 matthew 3055: @_,
3056: );
3057: $in{'formname'} = 'document.' . $in{'formname'};
3058: my $result='';
1.80 albertel 3059:
3060: #---------------------------------------------- Code for upper case translation
3061: my $Javascript_toUpperCase;
3062: unless ($in{kerb_def_dom}) {
3063: $Javascript_toUpperCase =<<"END";
3064: switch (choice) {
3065: case 'krb': currentform.elements[choicearg].value =
3066: currentform.elements[choicearg].value.toUpperCase();
3067: break;
3068: default:
3069: }
3070: END
3071: } else {
3072: $Javascript_toUpperCase = "";
3073: }
3074:
1.165 raeburn 3075: my $radioval = "'nochange'";
1.591 raeburn 3076: if (defined($in{'curr_authtype'})) {
3077: if ($in{'curr_authtype'} ne '') {
3078: $radioval = "'".$in{'curr_authtype'}."arg'";
3079: }
1.174 matthew 3080: }
1.165 raeburn 3081: my $argfield = 'null';
1.591 raeburn 3082: if (defined($in{'mode'})) {
1.165 raeburn 3083: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3084: if (defined($in{'curr_autharg'})) {
3085: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3086: $argfield = "'$in{'curr_autharg'}'";
3087: }
3088: }
3089: }
3090: }
3091:
1.32 matthew 3092: $result.=<<"END";
3093: var current = new Object();
1.165 raeburn 3094: current.radiovalue = $radioval;
3095: current.argfield = $argfield;
1.32 matthew 3096:
3097: function changed_radio(choice,currentform) {
3098: var choicearg = choice + 'arg';
3099: // If a radio button in changed, we need to change the argfield
3100: if (current.radiovalue != choice) {
3101: current.radiovalue = choice;
3102: if (current.argfield != null) {
3103: currentform.elements[current.argfield].value = '';
3104: }
3105: if (choice == 'nochange') {
3106: current.argfield = null;
3107: } else {
3108: current.argfield = choicearg;
3109: switch(choice) {
3110: case 'krb':
3111: currentform.elements[current.argfield].value =
3112: "$in{'kerb_def_dom'}";
3113: break;
3114: default:
3115: break;
3116: }
3117: }
3118: }
3119: return;
3120: }
1.22 www 3121:
1.32 matthew 3122: function changed_text(choice,currentform) {
3123: var choicearg = choice + 'arg';
3124: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3125: $Javascript_toUpperCase
1.32 matthew 3126: // clear old field
3127: if ((current.argfield != choicearg) && (current.argfield != null)) {
3128: currentform.elements[current.argfield].value = '';
3129: }
3130: current.argfield = choicearg;
3131: }
3132: set_auth_radio_buttons(choice,currentform);
3133: return;
1.20 www 3134: }
1.32 matthew 3135:
3136: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3137: var numauthchoices = currentform.login.length;
3138: if (typeof numauthchoices == "undefined") {
3139: return;
3140: }
1.32 matthew 3141: var i=0;
1.986 raeburn 3142: while (i < numauthchoices) {
1.32 matthew 3143: if (currentform.login[i].value == newvalue) { break; }
3144: i++;
3145: }
1.986 raeburn 3146: if (i == numauthchoices) {
1.32 matthew 3147: return;
3148: }
3149: current.radiovalue = newvalue;
3150: currentform.login[i].checked = true;
3151: return;
3152: }
3153: END
3154: return $result;
3155: }
3156:
1.1106 raeburn 3157: sub authform_authorwarning {
1.32 matthew 3158: my $result='';
1.144 matthew 3159: $result='<i>'.
3160: &mt('As a general rule, only authors or co-authors should be '.
3161: 'filesystem authenticated '.
3162: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3163: return $result;
3164: }
3165:
1.1106 raeburn 3166: sub authform_nochange {
1.32 matthew 3167: my %in = (
3168: formname => 'document.cu',
3169: kerb_def_dom => 'MSU.EDU',
3170: @_,
3171: );
1.1106 raeburn 3172: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3173: my $result;
1.1104 raeburn 3174: if (!$authnum) {
1.1105 raeburn 3175: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3176: } else {
3177: $result = '<label>'.&mt('[_1] Do not change login data',
3178: '<input type="radio" name="login" value="nochange" '.
3179: 'checked="checked" onclick="'.
1.281 albertel 3180: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3181: '</label>';
1.586 raeburn 3182: }
1.32 matthew 3183: return $result;
3184: }
3185:
1.591 raeburn 3186: sub authform_kerberos {
1.32 matthew 3187: my %in = (
3188: formname => 'document.cu',
3189: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3190: kerb_def_auth => 'krb4',
1.32 matthew 3191: @_,
3192: );
1.586 raeburn 3193: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3194: $autharg,$jscall,$disabled);
1.1106 raeburn 3195: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3196: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3197: $check5 = ' checked="checked"';
1.80 albertel 3198: } else {
1.772 bisitz 3199: $check4 = ' checked="checked"';
1.80 albertel 3200: }
1.1259 raeburn 3201: if ($in{'readonly'}) {
3202: $disabled = ' disabled="disabled"';
3203: }
1.165 raeburn 3204: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3205: if (defined($in{'curr_authtype'})) {
3206: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3207: $krbcheck = ' checked="checked"';
1.623 raeburn 3208: if (defined($in{'mode'})) {
3209: if ($in{'mode'} eq 'modifyuser') {
3210: $krbcheck = '';
3211: }
3212: }
1.591 raeburn 3213: if (defined($in{'curr_kerb_ver'})) {
3214: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3215: $check5 = ' checked="checked"';
1.591 raeburn 3216: $check4 = '';
3217: } else {
1.772 bisitz 3218: $check4 = ' checked="checked"';
1.591 raeburn 3219: $check5 = '';
3220: }
1.586 raeburn 3221: }
1.591 raeburn 3222: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3223: $krbarg = $in{'curr_autharg'};
3224: }
1.586 raeburn 3225: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3226: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3227: $result =
3228: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3229: $in{'curr_autharg'},$krbver);
3230: } else {
3231: $result =
3232: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3233: }
3234: return $result;
3235: }
3236: }
3237: } else {
3238: if ($authnum == 1) {
1.784 bisitz 3239: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3240: }
3241: }
1.586 raeburn 3242: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3243: return;
1.587 raeburn 3244: } elsif ($authtype eq '') {
1.591 raeburn 3245: if (defined($in{'mode'})) {
1.587 raeburn 3246: if ($in{'mode'} eq 'modifycourse') {
3247: if ($authnum == 1) {
1.1259 raeburn 3248: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3249: }
3250: }
3251: }
1.586 raeburn 3252: }
3253: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3254: if ($authtype eq '') {
3255: $authtype = '<input type="radio" name="login" value="krb" '.
3256: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3257: $krbcheck.$disabled.' />';
1.586 raeburn 3258: }
3259: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3260: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3261: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3262: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3263: $in{'curr_authtype'} eq 'krb4')) {
3264: $result .= &mt
1.144 matthew 3265: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3266: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3267: '<label>'.$authtype,
1.281 albertel 3268: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3269: 'value="'.$krbarg.'" '.
1.1259 raeburn 3270: 'onchange="'.$jscall.'"'.$disabled.' />',
3271: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3272: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3273: '</label>');
1.586 raeburn 3274: } elsif ($can_assign{'krb4'}) {
3275: $result .= &mt
3276: ('[_1] Kerberos authenticated with domain [_2] '.
3277: '[_3] Version 4 [_4]',
3278: '<label>'.$authtype,
3279: '</label><input type="text" size="10" name="krbarg" '.
3280: 'value="'.$krbarg.'" '.
1.1259 raeburn 3281: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3282: '<label><input type="hidden" name="krbver" value="4" />',
3283: '</label>');
3284: } elsif ($can_assign{'krb5'}) {
3285: $result .= &mt
3286: ('[_1] Kerberos authenticated with domain [_2] '.
3287: '[_3] Version 5 [_4]',
3288: '<label>'.$authtype,
3289: '</label><input type="text" size="10" name="krbarg" '.
3290: 'value="'.$krbarg.'" '.
1.1259 raeburn 3291: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3292: '<label><input type="hidden" name="krbver" value="5" />',
3293: '</label>');
3294: }
1.32 matthew 3295: return $result;
3296: }
3297:
1.1106 raeburn 3298: sub authform_internal {
1.586 raeburn 3299: my %in = (
1.32 matthew 3300: formname => 'document.cu',
3301: kerb_def_dom => 'MSU.EDU',
3302: @_,
3303: );
1.1259 raeburn 3304: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3305: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3306: if ($in{'readonly'}) {
3307: $disabled = ' disabled="disabled"';
3308: }
1.591 raeburn 3309: if (defined($in{'curr_authtype'})) {
3310: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3311: if ($can_assign{'int'}) {
1.772 bisitz 3312: $intcheck = 'checked="checked" ';
1.623 raeburn 3313: if (defined($in{'mode'})) {
3314: if ($in{'mode'} eq 'modifyuser') {
3315: $intcheck = '';
3316: }
3317: }
1.591 raeburn 3318: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3319: $intarg = $in{'curr_autharg'};
3320: }
3321: } else {
3322: $result = &mt('Currently internally authenticated.');
3323: return $result;
1.165 raeburn 3324: }
3325: }
1.586 raeburn 3326: } else {
3327: if ($authnum == 1) {
1.784 bisitz 3328: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3329: }
3330: }
3331: if (!$can_assign{'int'}) {
3332: return;
1.587 raeburn 3333: } elsif ($authtype eq '') {
1.591 raeburn 3334: if (defined($in{'mode'})) {
1.587 raeburn 3335: if ($in{'mode'} eq 'modifycourse') {
3336: if ($authnum == 1) {
1.1259 raeburn 3337: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3338: }
3339: }
3340: }
1.165 raeburn 3341: }
1.586 raeburn 3342: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3343: if ($authtype eq '') {
3344: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3345: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3346: }
1.605 bisitz 3347: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3348: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3349: $result = &mt
1.144 matthew 3350: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3351: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3352: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3353: return $result;
3354: }
3355:
1.1104 raeburn 3356: sub authform_local {
1.32 matthew 3357: my %in = (
3358: formname => 'document.cu',
3359: kerb_def_dom => 'MSU.EDU',
3360: @_,
3361: );
1.1259 raeburn 3362: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3363: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3364: if ($in{'readonly'}) {
3365: $disabled = ' disabled="disabled"';
3366: }
1.591 raeburn 3367: if (defined($in{'curr_authtype'})) {
3368: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3369: if ($can_assign{'loc'}) {
1.772 bisitz 3370: $loccheck = 'checked="checked" ';
1.623 raeburn 3371: if (defined($in{'mode'})) {
3372: if ($in{'mode'} eq 'modifyuser') {
3373: $loccheck = '';
3374: }
3375: }
1.591 raeburn 3376: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3377: $locarg = $in{'curr_autharg'};
3378: }
3379: } else {
3380: $result = &mt('Currently using local (institutional) authentication.');
3381: return $result;
1.165 raeburn 3382: }
3383: }
1.586 raeburn 3384: } else {
3385: if ($authnum == 1) {
1.784 bisitz 3386: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3387: }
3388: }
3389: if (!$can_assign{'loc'}) {
3390: return;
1.587 raeburn 3391: } elsif ($authtype eq '') {
1.591 raeburn 3392: if (defined($in{'mode'})) {
1.587 raeburn 3393: if ($in{'mode'} eq 'modifycourse') {
3394: if ($authnum == 1) {
1.1259 raeburn 3395: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3396: }
3397: }
3398: }
1.165 raeburn 3399: }
1.586 raeburn 3400: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3401: if ($authtype eq '') {
3402: $authtype = '<input type="radio" name="login" value="loc" '.
3403: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3404: $jscall.'"'.$disabled.' />';
1.586 raeburn 3405: }
3406: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3407: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3408: $result = &mt('[_1] Local Authentication with argument [_2]',
3409: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3410: return $result;
3411: }
3412:
1.1106 raeburn 3413: sub authform_filesystem {
1.32 matthew 3414: my %in = (
3415: formname => 'document.cu',
3416: kerb_def_dom => 'MSU.EDU',
3417: @_,
3418: );
1.1259 raeburn 3419: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3420: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3421: if ($in{'readonly'}) {
3422: $disabled = ' disabled="disabled"';
3423: }
1.591 raeburn 3424: if (defined($in{'curr_authtype'})) {
3425: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3426: if ($can_assign{'fsys'}) {
1.772 bisitz 3427: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3428: if (defined($in{'mode'})) {
3429: if ($in{'mode'} eq 'modifyuser') {
3430: $fsyscheck = '';
3431: }
3432: }
1.586 raeburn 3433: } else {
3434: $result = &mt('Currently Filesystem Authenticated.');
3435: return $result;
1.1259 raeburn 3436: }
1.586 raeburn 3437: }
3438: } else {
3439: if ($authnum == 1) {
1.784 bisitz 3440: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3441: }
3442: }
3443: if (!$can_assign{'fsys'}) {
3444: return;
1.587 raeburn 3445: } elsif ($authtype eq '') {
1.591 raeburn 3446: if (defined($in{'mode'})) {
1.587 raeburn 3447: if ($in{'mode'} eq 'modifycourse') {
3448: if ($authnum == 1) {
1.1259 raeburn 3449: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3450: }
3451: }
3452: }
1.586 raeburn 3453: }
3454: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3455: if ($authtype eq '') {
3456: $authtype = '<input type="radio" name="login" value="fsys" '.
3457: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3458: $jscall.'"'.$disabled.' />';
1.586 raeburn 3459: }
1.1310 raeburn 3460: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3461: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3462: $result = &mt
1.144 matthew 3463: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3464: '<label>'.$authtype,'</label>'.$autharg);
3465: return $result;
3466: }
3467:
3468: sub authform_lti {
3469: my %in = (
3470: formname => 'document.cu',
3471: kerb_def_dom => 'MSU.EDU',
3472: @_,
3473: );
3474: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3475: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3476: if ($in{'readonly'}) {
3477: $disabled = ' disabled="disabled"';
3478: }
3479: if (defined($in{'curr_authtype'})) {
3480: if ($in{'curr_authtype'} eq 'lti') {
3481: if ($can_assign{'lti'}) {
3482: $lticheck = 'checked="checked" ';
3483: if (defined($in{'mode'})) {
3484: if ($in{'mode'} eq 'modifyuser') {
3485: $lticheck = '';
3486: }
3487: }
3488: } else {
3489: $result = &mt('Currently LTI Authenticated.');
3490: return $result;
3491: }
3492: }
3493: } else {
3494: if ($authnum == 1) {
3495: $authtype = '<input type="hidden" name="login" value="lti" />';
3496: }
3497: }
3498: if (!$can_assign{'lti'}) {
3499: return;
3500: } elsif ($authtype eq '') {
3501: if (defined($in{'mode'})) {
3502: if ($in{'mode'} eq 'modifycourse') {
3503: if ($authnum == 1) {
3504: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3505: }
3506: }
3507: }
3508: }
3509: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3510: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3511: $authtype = '<input type="radio" name="login" value="lti" '.
3512: $lticheck.' onchange="'.$jscall.'" onclick="'.
3513: $jscall.'"'.$disabled.' />';
3514: }
3515: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3516: if ($authtype) {
3517: $result = &mt('[_1] LTI Authenticated',
3518: '<label>'.$authtype.'</label>'.$autharg);
3519: } else {
3520: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3521: $autharg;
3522: }
1.32 matthew 3523: return $result;
3524: }
3525:
1.586 raeburn 3526: sub get_assignable_auth {
3527: my ($dom) = @_;
3528: if ($dom eq '') {
3529: $dom = $env{'request.role.domain'};
3530: }
3531: my %can_assign = (
3532: krb4 => 1,
3533: krb5 => 1,
3534: int => 1,
3535: loc => 1,
1.1310 raeburn 3536: lti => 1,
1.586 raeburn 3537: );
3538: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3539: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3540: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3541: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3542: my $context;
3543: if ($env{'request.role'} =~ /^au/) {
3544: $context = 'author';
1.1259 raeburn 3545: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3546: $context = 'domain';
3547: } elsif ($env{'request.course.id'}) {
3548: $context = 'course';
3549: }
3550: if ($context) {
3551: if (ref($authhash->{$context}) eq 'HASH') {
3552: %can_assign = %{$authhash->{$context}};
3553: }
3554: }
3555: }
3556: }
3557: my $authnum = 0;
3558: foreach my $key (keys(%can_assign)) {
3559: if ($can_assign{$key}) {
3560: $authnum ++;
3561: }
3562: }
3563: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3564: $authnum --;
3565: }
3566: return ($authnum,%can_assign);
3567: }
3568:
1.80 albertel 3569: ###############################################################
3570: ## Get Kerberos Defaults for Domain ##
3571: ###############################################################
3572: ##
3573: ## Returns default kerberos version and an associated argument
3574: ## as listed in file domain.tab. If not listed, provides
3575: ## appropriate default domain and kerberos version.
3576: ##
3577: #-------------------------------------------
3578:
3579: =pod
3580:
1.648 raeburn 3581: =item * &get_kerberos_defaults()
1.80 albertel 3582:
3583: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3584: version and domain. If not found, it defaults to version 4 and the
3585: domain of the server.
1.80 albertel 3586:
1.648 raeburn 3587: =over 4
3588:
1.80 albertel 3589: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3590:
1.648 raeburn 3591: =back
3592:
3593: =back
3594:
1.80 albertel 3595: =cut
3596:
3597: #-------------------------------------------
3598: sub get_kerberos_defaults {
3599: my $domain=shift;
1.641 raeburn 3600: my ($krbdef,$krbdefdom);
3601: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3602: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3603: $krbdef = $domdefaults{'auth_def'};
3604: $krbdefdom = $domdefaults{'auth_arg_def'};
3605: } else {
1.80 albertel 3606: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3607: my $krbdefdom=$1;
3608: $krbdefdom=~tr/a-z/A-Z/;
3609: $krbdef = "krb4";
3610: }
3611: return ($krbdef,$krbdefdom);
3612: }
1.112 bowersj2 3613:
1.32 matthew 3614:
1.46 matthew 3615: ###############################################################
3616: ## Thesaurus Functions ##
3617: ###############################################################
1.20 www 3618:
1.46 matthew 3619: =pod
1.20 www 3620:
1.112 bowersj2 3621: =head1 Thesaurus Functions
3622:
3623: =over 4
3624:
1.648 raeburn 3625: =item * &initialize_keywords()
1.46 matthew 3626:
3627: Initializes the package variable %Keywords if it is empty. Uses the
3628: package variable $thesaurus_db_file.
3629:
3630: =cut
3631:
3632: ###################################################
3633:
3634: sub initialize_keywords {
3635: return 1 if (scalar keys(%Keywords));
3636: # If we are here, %Keywords is empty, so fill it up
3637: # Make sure the file we need exists...
3638: if (! -e $thesaurus_db_file) {
3639: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3640: " failed because it does not exist");
3641: return 0;
3642: }
3643: # Set up the hash as a database
3644: my %thesaurus_db;
3645: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3646: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3647: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3648: $thesaurus_db_file);
3649: return 0;
3650: }
3651: # Get the average number of appearances of a word.
3652: my $avecount = $thesaurus_db{'average.count'};
3653: # Put keywords (those that appear > average) into %Keywords
3654: while (my ($word,$data)=each (%thesaurus_db)) {
3655: my ($count,undef) = split /:/,$data;
3656: $Keywords{$word}++ if ($count > $avecount);
3657: }
3658: untie %thesaurus_db;
3659: # Remove special values from %Keywords.
1.356 albertel 3660: foreach my $value ('total.count','average.count') {
3661: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3662: }
1.46 matthew 3663: return 1;
3664: }
3665:
3666: ###################################################
3667:
3668: =pod
3669:
1.648 raeburn 3670: =item * &keyword($word)
1.46 matthew 3671:
3672: Returns true if $word is a keyword. A keyword is a word that appears more
3673: than the average number of times in the thesaurus database. Calls
3674: &initialize_keywords
3675:
3676: =cut
3677:
3678: ###################################################
1.20 www 3679:
3680: sub keyword {
1.46 matthew 3681: return if (!&initialize_keywords());
3682: my $word=lc(shift());
3683: $word=~s/\W//g;
3684: return exists($Keywords{$word});
1.20 www 3685: }
1.46 matthew 3686:
3687: ###############################################################
3688:
3689: =pod
1.20 www 3690:
1.648 raeburn 3691: =item * &get_related_words()
1.46 matthew 3692:
1.160 matthew 3693: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3694: an array of words. If the keyword is not in the thesaurus, an empty array
3695: will be returned. The order of the words returned is determined by the
3696: database which holds them.
3697:
3698: Uses global $thesaurus_db_file.
3699:
1.1057 foxr 3700:
1.46 matthew 3701: =cut
3702:
3703: ###############################################################
3704: sub get_related_words {
3705: my $keyword = shift;
3706: my %thesaurus_db;
3707: if (! -e $thesaurus_db_file) {
3708: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3709: "failed because the file does not exist");
3710: return ();
3711: }
3712: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3713: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3714: return ();
3715: }
3716: my @Words=();
1.429 www 3717: my $count=0;
1.46 matthew 3718: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3719: # The first element is the number of times
3720: # the word appears. We do not need it now.
1.429 www 3721: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3722: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3723: my $threshold=$mostfrequentcount/10;
3724: foreach my $possibleword (@RelatedWords) {
3725: my ($word,$wordcount)=split(/\,/,$possibleword);
3726: if ($wordcount>$threshold) {
3727: push(@Words,$word);
3728: $count++;
3729: if ($count>10) { last; }
3730: }
1.20 www 3731: }
3732: }
1.46 matthew 3733: untie %thesaurus_db;
3734: return @Words;
1.14 harris41 3735: }
1.1090 foxr 3736: ###############################################################
3737: #
3738: # Spell checking
3739: #
3740:
3741: =pod
3742:
1.1142 raeburn 3743: =back
3744:
1.1090 foxr 3745: =head1 Spell checking
3746:
3747: =over 4
3748:
3749: =item * &check_spelling($wordlist $language)
3750:
3751: Takes a string containing words and feeds it to an external
3752: spellcheck program via a pipeline. Returns a string containing
3753: them mis-spelled words.
3754:
3755: Parameters:
3756:
3757: =over 4
3758:
3759: =item - $wordlist
3760:
3761: String that will be fed into the spellcheck program.
3762:
3763: =item - $language
3764:
3765: Language string that specifies the language for which the spell
3766: check will be performed.
3767:
3768: =back
3769:
3770: =back
3771:
3772: Note: This sub assumes that aspell is installed.
3773:
3774:
3775: =cut
3776:
1.46 matthew 3777:
1.1090 foxr 3778: sub check_spelling {
3779: my ($wordlist, $language) = @_;
1.1091 foxr 3780: my @misspellings;
3781:
3782: # Generate the speller and set the langauge.
3783: # if explicitly selected:
1.1090 foxr 3784:
1.1091 foxr 3785: my $speller = Text::Aspell->new;
1.1090 foxr 3786: if ($language) {
1.1091 foxr 3787: $speller->set_option('lang', $language);
1.1090 foxr 3788: }
3789:
1.1091 foxr 3790: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3791:
1.1091 foxr 3792: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3793:
1.1091 foxr 3794: foreach my $word (@words) {
3795: if(! $speller->check($word)) {
3796: push(@misspellings, $word);
1.1090 foxr 3797: }
3798: }
1.1091 foxr 3799: return join(' ', @misspellings);
3800:
1.1090 foxr 3801: }
3802:
1.61 www 3803: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3804: =pod
3805:
1.112 bowersj2 3806: =head1 User Name Functions
3807:
3808: =over 4
3809:
1.648 raeburn 3810: =item * &plainname($uname,$udom,$first)
1.81 albertel 3811:
1.112 bowersj2 3812: Takes a users logon name and returns it as a string in
1.226 albertel 3813: "first middle last generation" form
3814: if $first is set to 'lastname' then it returns it as
3815: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3816:
3817: =cut
1.61 www 3818:
1.295 www 3819:
1.81 albertel 3820: ###############################################################
1.61 www 3821: sub plainname {
1.226 albertel 3822: my ($uname,$udom,$first)=@_;
1.537 albertel 3823: return if (!defined($uname) || !defined($udom));
1.295 www 3824: my %names=&getnames($uname,$udom);
1.226 albertel 3825: my $name=&Apache::lonnet::format_name($names{'firstname'},
3826: $names{'middlename'},
3827: $names{'lastname'},
3828: $names{'generation'},$first);
3829: $name=~s/^\s+//;
1.62 www 3830: $name=~s/\s+$//;
3831: $name=~s/\s+/ /g;
1.353 albertel 3832: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3833: return $name;
1.61 www 3834: }
1.66 www 3835:
3836: # -------------------------------------------------------------------- Nickname
1.81 albertel 3837: =pod
3838:
1.648 raeburn 3839: =item * &nickname($uname,$udom)
1.81 albertel 3840:
3841: Gets a users name and returns it as a string as
3842:
3843: ""nickname""
1.66 www 3844:
1.81 albertel 3845: if the user has a nickname or
3846:
3847: "first middle last generation"
3848:
3849: if the user does not
3850:
3851: =cut
1.66 www 3852:
3853: sub nickname {
3854: my ($uname,$udom)=@_;
1.537 albertel 3855: return if (!defined($uname) || !defined($udom));
1.295 www 3856: my %names=&getnames($uname,$udom);
1.68 albertel 3857: my $name=$names{'nickname'};
1.66 www 3858: if ($name) {
3859: $name='"'.$name.'"';
3860: } else {
3861: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3862: $names{'lastname'}.' '.$names{'generation'};
3863: $name=~s/\s+$//;
3864: $name=~s/\s+/ /g;
3865: }
3866: return $name;
3867: }
3868:
1.295 www 3869: sub getnames {
3870: my ($uname,$udom)=@_;
1.537 albertel 3871: return if (!defined($uname) || !defined($udom));
1.433 albertel 3872: if ($udom eq 'public' && $uname eq 'public') {
3873: return ('lastname' => &mt('Public'));
3874: }
1.295 www 3875: my $id=$uname.':'.$udom;
3876: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3877: if ($cached) {
3878: return %{$names};
3879: } else {
3880: my %loadnames=&Apache::lonnet::get('environment',
3881: ['firstname','middlename','lastname','generation','nickname'],
3882: $udom,$uname);
3883: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3884: return %loadnames;
3885: }
3886: }
1.61 www 3887:
1.542 raeburn 3888: # -------------------------------------------------------------------- getemails
1.648 raeburn 3889:
1.542 raeburn 3890: =pod
3891:
1.648 raeburn 3892: =item * &getemails($uname,$udom)
1.542 raeburn 3893:
3894: Gets a user's email information and returns it as a hash with keys:
3895: notification, critnotification, permanentemail
3896:
3897: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3898: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3899:
1.648 raeburn 3900:
1.542 raeburn 3901: =cut
3902:
1.648 raeburn 3903:
1.466 albertel 3904: sub getemails {
3905: my ($uname,$udom)=@_;
3906: if ($udom eq 'public' && $uname eq 'public') {
3907: return;
3908: }
1.467 www 3909: if (!$udom) { $udom=$env{'user.domain'}; }
3910: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3911: my $id=$uname.':'.$udom;
3912: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3913: if ($cached) {
3914: return %{$names};
3915: } else {
3916: my %loadnames=&Apache::lonnet::get('environment',
3917: ['notification','critnotification',
3918: 'permanentemail'],
3919: $udom,$uname);
3920: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3921: return %loadnames;
3922: }
3923: }
3924:
1.551 albertel 3925: sub flush_email_cache {
3926: my ($uname,$udom)=@_;
3927: if (!$udom) { $udom =$env{'user.domain'}; }
3928: if (!$uname) { $uname=$env{'user.name'}; }
3929: return if ($udom eq 'public' && $uname eq 'public');
3930: my $id=$uname.':'.$udom;
3931: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3932: }
3933:
1.728 raeburn 3934: # -------------------------------------------------------------------- getlangs
3935:
3936: =pod
3937:
3938: =item * &getlangs($uname,$udom)
3939:
3940: Gets a user's language preference and returns it as a hash with key:
3941: language.
3942:
3943: =cut
3944:
3945:
3946: sub getlangs {
3947: my ($uname,$udom) = @_;
3948: if (!$udom) { $udom =$env{'user.domain'}; }
3949: if (!$uname) { $uname=$env{'user.name'}; }
3950: my $id=$uname.':'.$udom;
3951: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3952: if ($cached) {
3953: return %{$langs};
3954: } else {
3955: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3956: $udom,$uname);
3957: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3958: return %loadlangs;
3959: }
3960: }
3961:
3962: sub flush_langs_cache {
3963: my ($uname,$udom)=@_;
3964: if (!$udom) { $udom =$env{'user.domain'}; }
3965: if (!$uname) { $uname=$env{'user.name'}; }
3966: return if ($udom eq 'public' && $uname eq 'public');
3967: my $id=$uname.':'.$udom;
3968: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3969: }
3970:
1.61 www 3971: # ------------------------------------------------------------------ Screenname
1.81 albertel 3972:
3973: =pod
3974:
1.648 raeburn 3975: =item * &screenname($uname,$udom)
1.81 albertel 3976:
3977: Gets a users screenname and returns it as a string
3978:
3979: =cut
1.61 www 3980:
3981: sub screenname {
3982: my ($uname,$udom)=@_;
1.258 albertel 3983: if ($uname eq $env{'user.name'} &&
3984: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3985: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3986: return $names{'screenname'};
1.62 www 3987: }
3988:
1.212 albertel 3989:
1.802 bisitz 3990: # ------------------------------------------------------------- Confirm Wrapper
3991: =pod
3992:
1.1142 raeburn 3993: =item * &confirmwrapper($message)
1.802 bisitz 3994:
3995: Wrap messages about completion of operation in box
3996:
3997: =cut
3998:
3999: sub confirmwrapper {
4000: my ($message)=@_;
4001: if ($message) {
4002: return "\n".'<div class="LC_confirm_box">'."\n"
4003: .$message."\n"
4004: .'</div>'."\n";
4005: } else {
4006: return $message;
4007: }
4008: }
4009:
1.62 www 4010: # ------------------------------------------------------------- Message Wrapper
4011:
4012: sub messagewrapper {
1.369 www 4013: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4014: return
1.441 albertel 4015: '<a href="/adm/email?compose=individual&'.
4016: 'recname='.$username.'&recdom='.$domain.
4017: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4018: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4019: }
1.802 bisitz 4020:
1.74 www 4021: # --------------------------------------------------------------- Notes Wrapper
4022:
4023: sub noteswrapper {
4024: my ($link,$un,$do)=@_;
4025: return
1.896 amueller 4026: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4027: }
1.802 bisitz 4028:
1.62 www 4029: # ------------------------------------------------------------- Aboutme Wrapper
4030:
4031: sub aboutmewrapper {
1.1070 raeburn 4032: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4033: if (!defined($username) && !defined($domain)) {
4034: return;
4035: }
1.1096 raeburn 4036: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4037: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4038: }
4039:
4040: # ------------------------------------------------------------ Syllabus Wrapper
4041:
4042: sub syllabuswrapper {
1.707 bisitz 4043: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4044: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4045: }
1.14 harris41 4046:
1.802 bisitz 4047: # -----------------------------------------------------------------------------
4048:
1.208 matthew 4049: sub track_student_link {
1.887 raeburn 4050: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4051: my $link ="/adm/trackstudent?";
1.208 matthew 4052: my $title = 'View recent activity';
4053: if (defined($sname) && $sname !~ /^\s*$/ &&
4054: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4055: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4056: $title .= ' of this student';
1.268 albertel 4057: }
1.208 matthew 4058: if (defined($target) && $target !~ /^\s*$/) {
4059: $target = qq{target="$target"};
4060: } else {
4061: $target = '';
4062: }
1.268 albertel 4063: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4064: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4065: $title = &mt($title);
4066: $linktext = &mt($linktext);
1.448 albertel 4067: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4068: &help_open_topic('View_recent_activity');
1.208 matthew 4069: }
4070:
1.781 raeburn 4071: sub slot_reservations_link {
4072: my ($linktext,$sname,$sdom,$target) = @_;
4073: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4074: my $title = 'View slot reservation history';
4075: if (defined($sname) && $sname !~ /^\s*$/ &&
4076: defined($sdom) && $sdom !~ /^\s*$/) {
4077: $link .= "&uname=$sname&udom=$sdom";
4078: $title .= ' of this student';
4079: }
4080: if (defined($target) && $target !~ /^\s*$/) {
4081: $target = qq{target="$target"};
4082: } else {
4083: $target = '';
4084: }
4085: $title = &mt($title);
4086: $linktext = &mt($linktext);
4087: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4088: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4089:
4090: }
4091:
1.508 www 4092: # ===================================================== Display a student photo
4093:
4094:
1.509 albertel 4095: sub student_image_tag {
1.508 www 4096: my ($domain,$user)=@_;
4097: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4098: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4099: return '<img src="'.$imgsrc.'" align="right" />';
4100: } else {
4101: return '';
4102: }
4103: }
4104:
1.112 bowersj2 4105: =pod
4106:
4107: =back
4108:
4109: =head1 Access .tab File Data
4110:
4111: =over 4
4112:
1.648 raeburn 4113: =item * &languageids()
1.112 bowersj2 4114:
4115: returns list of all language ids
4116:
4117: =cut
4118:
1.14 harris41 4119: sub languageids {
1.16 harris41 4120: return sort(keys(%language));
1.14 harris41 4121: }
4122:
1.112 bowersj2 4123: =pod
4124:
1.648 raeburn 4125: =item * &languagedescription()
1.112 bowersj2 4126:
4127: returns description of a specified language id
4128:
4129: =cut
4130:
1.14 harris41 4131: sub languagedescription {
1.125 www 4132: my $code=shift;
4133: return ($supported_language{$code}?'* ':'').
4134: $language{$code}.
1.126 www 4135: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4136: }
4137:
1.1048 foxr 4138: =pod
4139:
4140: =item * &plainlanguagedescription
4141:
4142: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4143: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4144:
4145: =cut
4146:
1.145 www 4147: sub plainlanguagedescription {
4148: my $code=shift;
4149: return $language{$code};
4150: }
4151:
1.1048 foxr 4152: =pod
4153:
4154: =item * &supportedlanguagecode
4155:
4156: Returns the supported language code (e.g. sptutf maps to pt) given a language
4157: code.
4158:
4159: =cut
4160:
1.145 www 4161: sub supportedlanguagecode {
4162: my $code=shift;
4163: return $supported_language{$code};
1.97 www 4164: }
4165:
1.112 bowersj2 4166: =pod
4167:
1.1048 foxr 4168: =item * &latexlanguage()
4169:
4170: Given a language key code returns the correspondnig language to use
4171: to select the correct hyphenation on LaTeX printouts. This is undef if there
4172: is no supported hyphenation for the language code.
4173:
4174: =cut
4175:
4176: sub latexlanguage {
4177: my $code = shift;
4178: return $latex_language{$code};
4179: }
4180:
4181: =pod
4182:
4183: =item * &latexhyphenation()
4184:
4185: Same as above but what's supplied is the language as it might be stored
4186: in the metadata.
4187:
4188: =cut
4189:
4190: sub latexhyphenation {
4191: my $key = shift;
4192: return $latex_language_bykey{$key};
4193: }
4194:
4195: =pod
4196:
1.648 raeburn 4197: =item * ©rightids()
1.112 bowersj2 4198:
4199: returns list of all copyrights
4200:
4201: =cut
4202:
4203: sub copyrightids {
4204: return sort(keys(%cprtag));
4205: }
4206:
4207: =pod
4208:
1.648 raeburn 4209: =item * ©rightdescription()
1.112 bowersj2 4210:
4211: returns description of a specified copyright id
4212:
4213: =cut
4214:
4215: sub copyrightdescription {
1.166 www 4216: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4217: }
1.197 matthew 4218:
4219: =pod
4220:
1.648 raeburn 4221: =item * &source_copyrightids()
1.192 taceyjo1 4222:
4223: returns list of all source copyrights
4224:
4225: =cut
4226:
4227: sub source_copyrightids {
4228: return sort(keys(%scprtag));
4229: }
4230:
4231: =pod
4232:
1.648 raeburn 4233: =item * &source_copyrightdescription()
1.192 taceyjo1 4234:
4235: returns description of a specified source copyright id
4236:
4237: =cut
4238:
4239: sub source_copyrightdescription {
4240: return &mt($scprtag{shift(@_)});
4241: }
1.112 bowersj2 4242:
4243: =pod
4244:
1.648 raeburn 4245: =item * &filecategories()
1.112 bowersj2 4246:
4247: returns list of all file categories
4248:
4249: =cut
4250:
4251: sub filecategories {
4252: return sort(keys(%category_extensions));
4253: }
4254:
4255: =pod
4256:
1.648 raeburn 4257: =item * &filecategorytypes()
1.112 bowersj2 4258:
4259: returns list of file types belonging to a given file
4260: category
4261:
4262: =cut
4263:
4264: sub filecategorytypes {
1.356 albertel 4265: my ($cat) = @_;
1.1248 raeburn 4266: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4267: return @{$category_extensions{lc($cat)}};
4268: } else {
4269: return ();
4270: }
1.112 bowersj2 4271: }
4272:
4273: =pod
4274:
1.648 raeburn 4275: =item * &fileembstyle()
1.112 bowersj2 4276:
4277: returns embedding style for a specified file type
4278:
4279: =cut
4280:
4281: sub fileembstyle {
4282: return $fe{lc(shift(@_))};
1.169 www 4283: }
4284:
1.351 www 4285: sub filemimetype {
4286: return $fm{lc(shift(@_))};
4287: }
4288:
1.169 www 4289:
4290: sub filecategoryselect {
4291: my ($name,$value)=@_;
1.189 matthew 4292: return &select_form($value,$name,
1.970 raeburn 4293: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4294: }
4295:
4296: =pod
4297:
1.648 raeburn 4298: =item * &filedescription()
1.112 bowersj2 4299:
4300: returns description for a specified file type
4301:
4302: =cut
4303:
4304: sub filedescription {
1.188 matthew 4305: my $file_description = $fd{lc(shift())};
4306: $file_description =~ s:([\[\]]):~$1:g;
4307: return &mt($file_description);
1.112 bowersj2 4308: }
4309:
4310: =pod
4311:
1.648 raeburn 4312: =item * &filedescriptionex()
1.112 bowersj2 4313:
4314: returns description for a specified file type with
4315: extra formatting
4316:
4317: =cut
4318:
4319: sub filedescriptionex {
4320: my $ex=shift;
1.188 matthew 4321: my $file_description = $fd{lc($ex)};
4322: $file_description =~ s:([\[\]]):~$1:g;
4323: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4324: }
4325:
4326: # End of .tab access
4327: =pod
4328:
4329: =back
4330:
4331: =cut
4332:
4333: # ------------------------------------------------------------------ File Types
4334: sub fileextensions {
4335: return sort(keys(%fe));
4336: }
4337:
1.97 www 4338: # ----------------------------------------------------------- Display Languages
4339: # returns a hash with all desired display languages
4340: #
4341:
4342: sub display_languages {
4343: my %languages=();
1.695 raeburn 4344: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4345: $languages{$lang}=1;
1.97 www 4346: }
4347: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4348: if ($env{'form.displaylanguage'}) {
1.356 albertel 4349: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4350: $languages{$lang}=1;
1.97 www 4351: }
4352: }
4353: return %languages;
1.14 harris41 4354: }
4355:
1.582 albertel 4356: sub languages {
4357: my ($possible_langs) = @_;
1.695 raeburn 4358: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4359: if (!ref($possible_langs)) {
4360: if( wantarray ) {
4361: return @preferred_langs;
4362: } else {
4363: return $preferred_langs[0];
4364: }
4365: }
4366: my %possibilities = map { $_ => 1 } (@$possible_langs);
4367: my @preferred_possibilities;
4368: foreach my $preferred_lang (@preferred_langs) {
4369: if (exists($possibilities{$preferred_lang})) {
4370: push(@preferred_possibilities, $preferred_lang);
4371: }
4372: }
4373: if( wantarray ) {
4374: return @preferred_possibilities;
4375: }
4376: return $preferred_possibilities[0];
4377: }
4378:
1.742 raeburn 4379: sub user_lang {
4380: my ($touname,$toudom,$fromcid) = @_;
4381: my @userlangs;
4382: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4383: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4384: $env{'course.'.$fromcid.'.languages'}));
4385: } else {
4386: my %langhash = &getlangs($touname,$toudom);
4387: if ($langhash{'languages'} ne '') {
4388: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4389: } else {
4390: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4391: if ($domdefs{'lang_def'} ne '') {
4392: @userlangs = ($domdefs{'lang_def'});
4393: }
4394: }
4395: }
4396: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4397: my $user_lh = Apache::localize->get_handle(@languages);
4398: return $user_lh;
4399: }
4400:
4401:
1.112 bowersj2 4402: ###############################################################
4403: ## Student Answer Attempts ##
4404: ###############################################################
4405:
4406: =pod
4407:
4408: =head1 Alternate Problem Views
4409:
4410: =over 4
4411:
1.648 raeburn 4412: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4413: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4414:
4415: Return string with previous attempt on problem. Arguments:
4416:
4417: =over 4
4418:
4419: =item * $symb: Problem, including path
4420:
4421: =item * $username: username of the desired student
4422:
4423: =item * $domain: domain of the desired student
1.14 harris41 4424:
1.112 bowersj2 4425: =item * $course: Course ID
1.14 harris41 4426:
1.112 bowersj2 4427: =item * $getattempt: Leave blank for all attempts, otherwise put
4428: something
1.14 harris41 4429:
1.112 bowersj2 4430: =item * $regexp: if string matches this regexp, the string will be
4431: sent to $gradesub
1.14 harris41 4432:
1.112 bowersj2 4433: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4434:
1.1199 raeburn 4435: =item * $usec: section of the desired student
4436:
4437: =item * $identifier: counter for student (multiple students one problem) or
4438: problem (one student; whole sequence).
4439:
1.112 bowersj2 4440: =back
1.14 harris41 4441:
1.112 bowersj2 4442: The output string is a table containing all desired attempts, if any.
1.16 harris41 4443:
1.112 bowersj2 4444: =cut
1.1 albertel 4445:
4446: sub get_previous_attempt {
1.1199 raeburn 4447: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4448: my $prevattempts='';
1.43 ng 4449: no strict 'refs';
1.1 albertel 4450: if ($symb) {
1.3 albertel 4451: my (%returnhash)=
4452: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4453: if ($returnhash{'version'}) {
4454: my %lasthash=();
4455: my $version;
4456: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4457: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4458: if ($key =~ /\.rawrndseed$/) {
4459: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4460: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4461: } else {
4462: $lasthash{$key}=$returnhash{$version.':'.$key};
4463: }
1.19 harris41 4464: }
1.1 albertel 4465: }
1.596 albertel 4466: $prevattempts=&start_data_table().&start_data_table_header_row();
4467: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4468: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4469: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4470: foreach my $key (sort(keys(%lasthash))) {
4471: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4472: if ($#parts > 0) {
1.31 albertel 4473: my $data=$parts[-1];
1.989 raeburn 4474: next if ($data eq 'foilorder');
1.31 albertel 4475: pop(@parts);
1.1010 www 4476: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4477: if ($data eq 'type') {
4478: unless ($showsurv) {
4479: my $id = join(',',@parts);
4480: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4481: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4482: $lasthidden{$ign.'.'.$id} = 1;
4483: }
1.945 raeburn 4484: }
1.1199 raeburn 4485: if ($identifier ne '') {
4486: my $id = join(',',@parts);
4487: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4488: $domain,$username,$usec,undef,$course) =~ /^no/) {
4489: $hidestatus{$ign.'.'.$id} = 1;
4490: }
4491: }
4492: } elsif ($data eq 'regrader') {
4493: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4494: my $id = join(',',@parts);
4495: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4496: }
1.1010 www 4497: }
1.31 albertel 4498: } else {
1.41 ng 4499: if ($#parts == 0) {
4500: $prevattempts.='<th>'.$parts[0].'</th>';
4501: } else {
4502: $prevattempts.='<th>'.$ign.'</th>';
4503: }
1.31 albertel 4504: }
1.16 harris41 4505: }
1.596 albertel 4506: $prevattempts.=&end_data_table_header_row();
1.40 ng 4507: if ($getattempt eq '') {
1.1199 raeburn 4508: my (%solved,%resets,%probstatus);
1.1200 raeburn 4509: if (($identifier ne '') && (keys(%regraded) > 0)) {
4510: for ($version=1;$version<=$returnhash{'version'};$version++) {
4511: foreach my $id (keys(%regraded)) {
4512: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4513: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4514: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4515: push(@{$resets{$id}},$version);
1.1199 raeburn 4516: }
4517: }
4518: }
1.1200 raeburn 4519: }
4520: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4521: my (@hidden,@unsolved);
1.945 raeburn 4522: if (%typeparts) {
4523: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4524: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4525: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4526: push(@hidden,$id);
1.1199 raeburn 4527: } elsif ($identifier ne '') {
4528: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4529: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4530: ($hidestatus{$id})) {
1.1200 raeburn 4531: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4532: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4533: push(@{$solved{$id}},$version);
4534: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4535: (ref($solved{$id}) eq 'ARRAY')) {
4536: my $skip;
4537: if (ref($resets{$id}) eq 'ARRAY') {
4538: foreach my $reset (@{$resets{$id}}) {
4539: if ($reset > $solved{$id}[-1]) {
4540: $skip=1;
4541: last;
4542: }
4543: }
4544: }
4545: unless ($skip) {
4546: my ($ign,$partslist) = split(/\./,$id,2);
4547: push(@unsolved,$partslist);
4548: }
4549: }
4550: }
1.945 raeburn 4551: }
4552: }
4553: }
4554: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4555: '<td>'.&mt('Transaction [_1]',$version);
4556: if (@unsolved) {
4557: $prevattempts .= '<span class="LC_nobreak"><label>'.
4558: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4559: &mt('Hide').'</label></span>';
4560: }
4561: $prevattempts .= '</td>';
1.945 raeburn 4562: if (@hidden) {
4563: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4564: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4565: my $hide;
4566: foreach my $id (@hidden) {
4567: if ($key =~ /^\Q$id\E/) {
4568: $hide = 1;
4569: last;
4570: }
4571: }
4572: if ($hide) {
4573: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4574: if (($data eq 'award') || ($data eq 'awarddetail')) {
4575: my $value = &format_previous_attempt_value($key,
4576: $returnhash{$version.':'.$key});
1.1173 kruse 4577: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4578: } else {
4579: $prevattempts.='<td> </td>';
4580: }
4581: } else {
4582: if ($key =~ /\./) {
1.1212 raeburn 4583: my $value = $returnhash{$version.':'.$key};
4584: if ($key =~ /\.rndseed$/) {
4585: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4586: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4587: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4588: }
4589: }
4590: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4591: ' </td>';
1.945 raeburn 4592: } else {
4593: $prevattempts.='<td> </td>';
4594: }
4595: }
4596: }
4597: } else {
4598: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4599: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4600: my $value = $returnhash{$version.':'.$key};
4601: if ($key =~ /\.rndseed$/) {
4602: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4603: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4604: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4605: }
4606: }
4607: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4608: ' </td>';
1.945 raeburn 4609: }
4610: }
4611: $prevattempts.=&end_data_table_row();
1.40 ng 4612: }
1.1 albertel 4613: }
1.945 raeburn 4614: my @currhidden = keys(%lasthidden);
1.596 albertel 4615: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4616: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4617: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4618: if (%typeparts) {
4619: my $hidden;
4620: foreach my $id (@currhidden) {
4621: if ($key =~ /^\Q$id\E/) {
4622: $hidden = 1;
4623: last;
4624: }
4625: }
4626: if ($hidden) {
4627: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4628: if (($data eq 'award') || ($data eq 'awarddetail')) {
4629: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4630: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4631: $value = &$gradesub($value);
4632: }
1.1173 kruse 4633: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4634: } else {
4635: $prevattempts.='<td> </td>';
4636: }
4637: } else {
4638: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4639: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4640: $value = &$gradesub($value);
4641: }
1.1173 kruse 4642: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4643: }
4644: } else {
4645: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4646: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4647: $value = &$gradesub($value);
4648: }
1.1173 kruse 4649: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4650: }
1.16 harris41 4651: }
1.596 albertel 4652: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4653: } else {
1.1305 raeburn 4654: my $msg;
4655: if ($symb =~ /ext\.tool$/) {
4656: $msg = &mt('No grade passed back.');
4657: } else {
4658: $msg = &mt('Nothing submitted - no attempts.');
4659: }
1.596 albertel 4660: $prevattempts=
4661: &start_data_table().&start_data_table_row().
1.1305 raeburn 4662: '<td>'.$msg.'</td>'.
1.596 albertel 4663: &end_data_table_row().&end_data_table();
1.1 albertel 4664: }
4665: } else {
1.596 albertel 4666: $prevattempts=
4667: &start_data_table().&start_data_table_row().
4668: '<td>'.&mt('No data.').'</td>'.
4669: &end_data_table_row().&end_data_table();
1.1 albertel 4670: }
1.10 albertel 4671: }
4672:
1.581 albertel 4673: sub format_previous_attempt_value {
4674: my ($key,$value) = @_;
1.1011 www 4675: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4676: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4677: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4678: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4679: } elsif ($key =~ /answerstring$/) {
4680: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4681: my @answer = %answers;
4682: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4683: my @anskeys = sort(keys(%answers));
4684: if (@anskeys == 1) {
4685: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4686: if ($answer =~ m{\0}) {
4687: $answer =~ s{\0}{,}g;
1.988 raeburn 4688: }
4689: my $tag_internal_answer_name = 'INTERNAL';
4690: if ($anskeys[0] eq $tag_internal_answer_name) {
4691: $value = $answer;
4692: } else {
4693: $value = $anskeys[0].'='.$answer;
4694: }
4695: } else {
4696: foreach my $ans (@anskeys) {
4697: my $answer = $answers{$ans};
1.1001 raeburn 4698: if ($answer =~ m{\0}) {
4699: $answer =~ s{\0}{,}g;
1.988 raeburn 4700: }
4701: $value .= $ans.'='.$answer.'<br />';;
4702: }
4703: }
1.581 albertel 4704: } else {
1.1173 kruse 4705: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4706: }
4707: return $value;
4708: }
4709:
4710:
1.107 albertel 4711: sub relative_to_absolute {
4712: my ($url,$output)=@_;
4713: my $parser=HTML::TokeParser->new(\$output);
4714: my $token;
4715: my $thisdir=$url;
4716: my @rlinks=();
4717: while ($token=$parser->get_token) {
4718: if ($token->[0] eq 'S') {
4719: if ($token->[1] eq 'a') {
4720: if ($token->[2]->{'href'}) {
4721: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4722: }
4723: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4724: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4725: } elsif ($token->[1] eq 'base') {
4726: $thisdir=$token->[2]->{'href'};
4727: }
4728: }
4729: }
4730: $thisdir=~s-/[^/]*$--;
1.356 albertel 4731: foreach my $link (@rlinks) {
1.726 raeburn 4732: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4733: ($link=~/^\//) ||
4734: ($link=~/^javascript:/i) ||
4735: ($link=~/^mailto:/i) ||
4736: ($link=~/^\#/)) {
4737: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4738: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4739: }
4740: }
4741: # -------------------------------------------------- Deal with Applet codebases
4742: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4743: return $output;
4744: }
4745:
1.112 bowersj2 4746: =pod
4747:
1.648 raeburn 4748: =item * &get_student_view()
1.112 bowersj2 4749:
4750: show a snapshot of what student was looking at
4751:
4752: =cut
4753:
1.10 albertel 4754: sub get_student_view {
1.186 albertel 4755: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4756: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4757: my (%form);
1.10 albertel 4758: my @elements=('symb','courseid','domain','username');
4759: foreach my $element (@elements) {
1.186 albertel 4760: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4761: }
1.186 albertel 4762: if (defined($moreenv)) {
4763: %form=(%form,%{$moreenv});
4764: }
1.236 albertel 4765: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4766: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4767: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4768: $feedurl =~ s{^/adm/wrapper}{};
4769: }
1.650 www 4770: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4771: $userview=~s/\<body[^\>]*\>//gi;
4772: $userview=~s/\<\/body\>//gi;
4773: $userview=~s/\<html\>//gi;
4774: $userview=~s/\<\/html\>//gi;
4775: $userview=~s/\<head\>//gi;
4776: $userview=~s/\<\/head\>//gi;
4777: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4778: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4779: if (wantarray) {
4780: return ($userview,$response);
4781: } else {
4782: return $userview;
4783: }
4784: }
4785:
4786: sub get_student_view_with_retries {
4787: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4788:
4789: my $ok = 0; # True if we got a good response.
4790: my $content;
4791: my $response;
4792:
4793: # Try to get the student_view done. within the retries count:
4794:
4795: do {
4796: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4797: $ok = $response->is_success;
4798: if (!$ok) {
4799: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4800: }
4801: $retries--;
4802: } while (!$ok && ($retries > 0));
4803:
4804: if (!$ok) {
4805: $content = ''; # On error return an empty content.
4806: }
1.651 www 4807: if (wantarray) {
4808: return ($content, $response);
4809: } else {
4810: return $content;
4811: }
1.11 albertel 4812: }
4813:
1.112 bowersj2 4814: =pod
4815:
1.648 raeburn 4816: =item * &get_student_answers()
1.112 bowersj2 4817:
4818: show a snapshot of how student was answering problem
4819:
4820: =cut
4821:
1.11 albertel 4822: sub get_student_answers {
1.100 sakharuk 4823: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4824: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4825: my (%moreenv);
1.11 albertel 4826: my @elements=('symb','courseid','domain','username');
4827: foreach my $element (@elements) {
1.186 albertel 4828: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4829: }
1.186 albertel 4830: $moreenv{'grade_target'}='answer';
4831: %moreenv=(%form,%moreenv);
1.497 raeburn 4832: $feedurl = &Apache::lonnet::clutter($feedurl);
4833: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4834: return $userview;
1.1 albertel 4835: }
1.116 albertel 4836:
4837: =pod
4838:
4839: =item * &submlink()
4840:
1.242 albertel 4841: Inputs: $text $uname $udom $symb $target
1.116 albertel 4842:
4843: Returns: A link to grades.pm such as to see the SUBM view of a student
4844:
4845: =cut
4846:
4847: ###############################################
4848: sub submlink {
1.242 albertel 4849: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4850: if (!($uname && $udom)) {
4851: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4852: &Apache::lonnet::whichuser($symb);
1.116 albertel 4853: if (!$symb) { $symb=$cursymb; }
4854: }
1.254 matthew 4855: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4856: $symb=&escape($symb);
1.960 bisitz 4857: if ($target) { $target=" target=\"$target\""; }
4858: return
4859: '<a href="/adm/grades?command=submission'.
4860: '&symb='.$symb.
4861: '&student='.$uname.
4862: '&userdom='.$udom.'"'.
4863: $target.'>'.$text.'</a>';
1.242 albertel 4864: }
4865: ##############################################
4866:
4867: =pod
4868:
4869: =item * &pgrdlink()
4870:
4871: Inputs: $text $uname $udom $symb $target
4872:
4873: Returns: A link to grades.pm such as to see the PGRD view of a student
4874:
4875: =cut
4876:
4877: ###############################################
4878: sub pgrdlink {
4879: my $link=&submlink(@_);
4880: $link=~s/(&command=submission)/$1&showgrading=yes/;
4881: return $link;
4882: }
4883: ##############################################
4884:
4885: =pod
4886:
4887: =item * &pprmlink()
4888:
4889: Inputs: $text $uname $udom $symb $target
4890:
4891: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4892: student and a specific resource
1.242 albertel 4893:
4894: =cut
4895:
4896: ###############################################
4897: sub pprmlink {
4898: my ($text,$uname,$udom,$symb,$target)=@_;
4899: if (!($uname && $udom)) {
4900: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4901: &Apache::lonnet::whichuser($symb);
1.242 albertel 4902: if (!$symb) { $symb=$cursymb; }
4903: }
1.254 matthew 4904: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4905: $symb=&escape($symb);
1.242 albertel 4906: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4907: return '<a href="/adm/parmset?command=set&'.
4908: 'symb='.$symb.'&uname='.$uname.
4909: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4910: }
4911: ##############################################
1.37 matthew 4912:
1.112 bowersj2 4913: =pod
4914:
4915: =back
4916:
4917: =cut
4918:
1.37 matthew 4919: ###############################################
1.51 www 4920:
4921:
4922: sub timehash {
1.687 raeburn 4923: my ($thistime) = @_;
4924: my $timezone = &Apache::lonlocal::gettimezone();
4925: my $dt = DateTime->from_epoch(epoch => $thistime)
4926: ->set_time_zone($timezone);
4927: my $wday = $dt->day_of_week();
4928: if ($wday == 7) { $wday = 0; }
4929: return ( 'second' => $dt->second(),
4930: 'minute' => $dt->minute(),
4931: 'hour' => $dt->hour(),
4932: 'day' => $dt->day_of_month(),
4933: 'month' => $dt->month(),
4934: 'year' => $dt->year(),
4935: 'weekday' => $wday,
4936: 'dayyear' => $dt->day_of_year(),
4937: 'dlsav' => $dt->is_dst() );
1.51 www 4938: }
4939:
1.370 www 4940: sub utc_string {
4941: my ($date)=@_;
1.371 www 4942: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4943: }
4944:
1.51 www 4945: sub maketime {
4946: my %th=@_;
1.687 raeburn 4947: my ($epoch_time,$timezone,$dt);
4948: $timezone = &Apache::lonlocal::gettimezone();
4949: eval {
4950: $dt = DateTime->new( year => $th{'year'},
4951: month => $th{'month'},
4952: day => $th{'day'},
4953: hour => $th{'hour'},
4954: minute => $th{'minute'},
4955: second => $th{'second'},
4956: time_zone => $timezone,
4957: );
4958: };
4959: if (!$@) {
4960: $epoch_time = $dt->epoch;
4961: if ($epoch_time) {
4962: return $epoch_time;
4963: }
4964: }
1.51 www 4965: return POSIX::mktime(
4966: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4967: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4968: }
4969:
4970: #########################################
1.51 www 4971:
4972: sub findallcourses {
1.482 raeburn 4973: my ($roles,$uname,$udom) = @_;
1.355 albertel 4974: my %roles;
4975: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4976: my %courses;
1.51 www 4977: my $now=time;
1.482 raeburn 4978: if (!defined($uname)) {
4979: $uname = $env{'user.name'};
4980: }
4981: if (!defined($udom)) {
4982: $udom = $env{'user.domain'};
4983: }
4984: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4985: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4986: if (!%roles) {
4987: %roles = (
4988: cc => 1,
1.907 raeburn 4989: co => 1,
1.482 raeburn 4990: in => 1,
4991: ep => 1,
4992: ta => 1,
4993: cr => 1,
4994: st => 1,
4995: );
4996: }
4997: foreach my $entry (keys(%roleshash)) {
4998: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4999: if ($trole =~ /^cr/) {
5000: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5001: } else {
5002: next if (!exists($roles{$trole}));
5003: }
5004: if ($tend) {
5005: next if ($tend < $now);
5006: }
5007: if ($tstart) {
5008: next if ($tstart > $now);
5009: }
1.1058 raeburn 5010: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5011: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5012: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5013: if ($secpart eq '') {
5014: ($cnum,$role) = split(/_/,$cnumpart);
5015: $sec = 'none';
1.1058 raeburn 5016: $value .= $cnum.'/';
1.482 raeburn 5017: } else {
5018: $cnum = $cnumpart;
5019: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5020: $value .= $cnum.'/'.$sec;
5021: }
5022: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5023: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5024: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5025: }
5026: } else {
5027: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5028: }
1.482 raeburn 5029: }
5030: } else {
5031: foreach my $key (keys(%env)) {
1.483 albertel 5032: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5033: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5034: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5035: next if ($role eq 'ca' || $role eq 'aa');
5036: next if (%roles && !exists($roles{$role}));
5037: my ($starttime,$endtime)=split(/\./,$env{$key});
5038: my $active=1;
5039: if ($starttime) {
5040: if ($now<$starttime) { $active=0; }
5041: }
5042: if ($endtime) {
5043: if ($now>$endtime) { $active=0; }
5044: }
5045: if ($active) {
1.1058 raeburn 5046: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5047: if ($sec eq '') {
5048: $sec = 'none';
1.1058 raeburn 5049: } else {
5050: $value .= $sec;
5051: }
5052: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5053: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5054: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5055: }
5056: } else {
5057: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5058: }
1.474 raeburn 5059: }
5060: }
1.51 www 5061: }
5062: }
1.474 raeburn 5063: return %courses;
1.51 www 5064: }
1.37 matthew 5065:
1.54 www 5066: ###############################################
1.474 raeburn 5067:
5068: sub blockcheck {
1.1189 raeburn 5069: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 5070:
1.1189 raeburn 5071: if (defined($udom) && defined($uname)) {
5072: # If uname and udom are for a course, check for blocks in the course.
5073: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5074: my ($startblock,$endblock,$triggerblock) =
5075: &get_blocks($setters,$activity,$udom,$uname,$url);
5076: return ($startblock,$endblock,$triggerblock);
5077: }
5078: } else {
1.490 raeburn 5079: $udom = $env{'user.domain'};
5080: $uname = $env{'user.name'};
5081: }
5082:
1.502 raeburn 5083: my $startblock = 0;
5084: my $endblock = 0;
1.1062 raeburn 5085: my $triggerblock = '';
1.482 raeburn 5086: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5087:
1.490 raeburn 5088: # If uname is for a user, and activity is course-specific, i.e.,
5089: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5090:
1.490 raeburn 5091: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5092: $activity eq 'groups' || $activity eq 'printout' ||
5093: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5094: ($env{'request.course.id'})) {
1.490 raeburn 5095: foreach my $key (keys(%live_courses)) {
5096: if ($key ne $env{'request.course.id'}) {
5097: delete($live_courses{$key});
5098: }
5099: }
5100: }
5101:
5102: my $otheruser = 0;
5103: my %own_courses;
5104: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5105: # Resource belongs to user other than current user.
5106: $otheruser = 1;
5107: # Gather courses for current user
5108: %own_courses =
5109: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5110: }
5111:
5112: # Gather active course roles - course coordinator, instructor,
5113: # exam proctor, ta, student, or custom role.
1.474 raeburn 5114:
5115: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5116: my ($cdom,$cnum);
5117: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5118: $cdom = $env{'course.'.$course.'.domain'};
5119: $cnum = $env{'course.'.$course.'.num'};
5120: } else {
1.490 raeburn 5121: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5122: }
5123: my $no_ownblock = 0;
5124: my $no_userblock = 0;
1.533 raeburn 5125: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5126: # Check if current user has 'evb' priv for this
5127: if (defined($own_courses{$course})) {
5128: foreach my $sec (keys(%{$own_courses{$course}})) {
5129: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5130: if ($sec ne 'none') {
5131: $checkrole .= '/'.$sec;
5132: }
5133: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5134: $no_ownblock = 1;
5135: last;
5136: }
5137: }
5138: }
5139: # if they have 'evb' priv and are currently not playing student
5140: next if (($no_ownblock) &&
5141: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5142: }
1.474 raeburn 5143: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5144: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5145: if ($sec ne 'none') {
1.482 raeburn 5146: $checkrole .= '/'.$sec;
1.474 raeburn 5147: }
1.490 raeburn 5148: if ($otheruser) {
5149: # Resource belongs to user other than current user.
5150: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5151: my (%allroles,%userroles);
5152: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5153: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5154: my ($trole,$tdom,$tnum,$tsec);
5155: if ($entry =~ /^cr/) {
5156: ($trole,$tdom,$tnum,$tsec) =
5157: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5158: } else {
5159: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5160: }
5161: my ($spec,$area,$trest);
5162: $area = '/'.$tdom.'/'.$tnum;
5163: $trest = $tnum;
5164: if ($tsec ne '') {
5165: $area .= '/'.$tsec;
5166: $trest .= '/'.$tsec;
5167: }
5168: $spec = $trole.'.'.$area;
5169: if ($trole =~ /^cr/) {
5170: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5171: $tdom,$spec,$trest,$area);
5172: } else {
5173: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5174: $tdom,$spec,$trest,$area);
5175: }
5176: }
1.1276 raeburn 5177: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5178: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5179: if ($1) {
5180: $no_userblock = 1;
5181: last;
5182: }
1.486 raeburn 5183: }
5184: }
1.490 raeburn 5185: } else {
5186: # Resource belongs to current user
5187: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5188: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5189: $no_ownblock = 1;
5190: last;
5191: }
1.474 raeburn 5192: }
5193: }
5194: # if they have the evb priv and are currently not playing student
1.482 raeburn 5195: next if (($no_ownblock) &&
1.491 albertel 5196: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5197: next if ($no_userblock);
1.474 raeburn 5198:
1.1303 raeburn 5199: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5200: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5201:
1.1062 raeburn 5202: my ($start,$end,$trigger) =
5203: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5204: if (($start != 0) &&
5205: (($startblock == 0) || ($startblock > $start))) {
5206: $startblock = $start;
1.1062 raeburn 5207: if ($trigger ne '') {
5208: $triggerblock = $trigger;
5209: }
1.502 raeburn 5210: }
5211: if (($end != 0) &&
5212: (($endblock == 0) || ($endblock < $end))) {
5213: $endblock = $end;
1.1062 raeburn 5214: if ($trigger ne '') {
5215: $triggerblock = $trigger;
5216: }
1.502 raeburn 5217: }
1.490 raeburn 5218: }
1.1062 raeburn 5219: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5220: }
5221:
5222: sub get_blocks {
1.1062 raeburn 5223: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5224: my $startblock = 0;
5225: my $endblock = 0;
1.1062 raeburn 5226: my $triggerblock = '';
1.490 raeburn 5227: my $course = $cdom.'_'.$cnum;
5228: $setters->{$course} = {};
5229: $setters->{$course}{'staff'} = [];
5230: $setters->{$course}{'times'} = [];
1.1062 raeburn 5231: $setters->{$course}{'triggers'} = [];
5232: my (@blockers,%triggered);
5233: my $now = time;
5234: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5235: if ($activity eq 'docs') {
5236: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5237: foreach my $block (@blockers) {
5238: if ($block =~ /^firstaccess____(.+)$/) {
5239: my $item = $1;
5240: my $type = 'map';
5241: my $timersymb = $item;
5242: if ($item eq 'course') {
5243: $type = 'course';
5244: } elsif ($item =~ /___\d+___/) {
5245: $type = 'resource';
5246: } else {
5247: $timersymb = &Apache::lonnet::symbread($item);
5248: }
5249: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5250: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5251: $triggered{$block} = {
5252: start => $start,
5253: end => $end,
5254: type => $type,
5255: };
5256: }
5257: }
5258: } else {
5259: foreach my $block (keys(%commblocks)) {
5260: if ($block =~ m/^(\d+)____(\d+)$/) {
5261: my ($start,$end) = ($1,$2);
5262: if ($start <= time && $end >= time) {
5263: if (ref($commblocks{$block}) eq 'HASH') {
5264: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5265: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5266: unless(grep(/^\Q$block\E$/,@blockers)) {
5267: push(@blockers,$block);
5268: }
5269: }
5270: }
5271: }
5272: }
5273: } elsif ($block =~ /^firstaccess____(.+)$/) {
5274: my $item = $1;
5275: my $timersymb = $item;
5276: my $type = 'map';
5277: if ($item eq 'course') {
5278: $type = 'course';
5279: } elsif ($item =~ /___\d+___/) {
5280: $type = 'resource';
5281: } else {
5282: $timersymb = &Apache::lonnet::symbread($item);
5283: }
5284: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5285: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5286: if ($start && $end) {
5287: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5288: if (ref($commblocks{$block}) eq 'HASH') {
5289: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5290: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5291: unless(grep(/^\Q$block\E$/,@blockers)) {
5292: push(@blockers,$block);
5293: $triggered{$block} = {
5294: start => $start,
5295: end => $end,
5296: type => $type,
5297: };
5298: }
5299: }
5300: }
1.1062 raeburn 5301: }
5302: }
1.490 raeburn 5303: }
1.1062 raeburn 5304: }
5305: }
5306: }
5307: foreach my $blocker (@blockers) {
5308: my ($staff_name,$staff_dom,$title,$blocks) =
5309: &parse_block_record($commblocks{$blocker});
5310: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5311: my ($start,$end,$triggertype);
5312: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5313: ($start,$end) = ($1,$2);
5314: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5315: $start = $triggered{$blocker}{'start'};
5316: $end = $triggered{$blocker}{'end'};
5317: $triggertype = $triggered{$blocker}{'type'};
5318: }
5319: if ($start) {
5320: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5321: if ($triggertype) {
5322: push(@{$$setters{$course}{'triggers'}},$triggertype);
5323: } else {
5324: push(@{$$setters{$course}{'triggers'}},0);
5325: }
5326: if ( ($startblock == 0) || ($startblock > $start) ) {
5327: $startblock = $start;
5328: if ($triggertype) {
5329: $triggerblock = $blocker;
1.474 raeburn 5330: }
5331: }
1.1062 raeburn 5332: if ( ($endblock == 0) || ($endblock < $end) ) {
5333: $endblock = $end;
5334: if ($triggertype) {
5335: $triggerblock = $blocker;
5336: }
5337: }
1.474 raeburn 5338: }
5339: }
1.1062 raeburn 5340: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5341: }
5342:
5343: sub parse_block_record {
5344: my ($record) = @_;
5345: my ($setuname,$setudom,$title,$blocks);
5346: if (ref($record) eq 'HASH') {
5347: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5348: $title = &unescape($record->{'event'});
5349: $blocks = $record->{'blocks'};
5350: } else {
5351: my @data = split(/:/,$record,3);
5352: if (scalar(@data) eq 2) {
5353: $title = $data[1];
5354: ($setuname,$setudom) = split(/@/,$data[0]);
5355: } else {
5356: ($setuname,$setudom,$title) = @data;
5357: }
5358: $blocks = { 'com' => 'on' };
5359: }
5360: return ($setuname,$setudom,$title,$blocks);
5361: }
5362:
1.854 kalberla 5363: sub blocking_status {
1.1189 raeburn 5364: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5365: my %setters;
1.890 droeschl 5366:
1.1061 raeburn 5367: # check for active blocking
1.1062 raeburn 5368: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5369: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5370: my $blocked = 0;
5371: if ($startblock && $endblock) {
5372: $blocked = 1;
5373: }
1.890 droeschl 5374:
1.1061 raeburn 5375: # caller just wants to know whether a block is active
5376: if (!wantarray) { return $blocked; }
5377:
5378: # build a link to a popup window containing the details
5379: my $querystring = "?activity=$activity";
5380: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5381: if (($activity eq 'port') || ($activity eq 'passwd')) {
5382: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5383: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5384: } elsif ($activity eq 'docs') {
5385: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5386: }
1.1061 raeburn 5387:
5388: my $output .= <<'END_MYBLOCK';
5389: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5390: var options = "width=" + w + ",height=" + h + ",";
5391: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5392: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5393: var newWin = window.open(url, wdwName, options);
5394: newWin.focus();
5395: }
1.890 droeschl 5396: END_MYBLOCK
1.854 kalberla 5397:
1.1061 raeburn 5398: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5399:
1.1061 raeburn 5400: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5401: my $text = &mt('Communication Blocked');
1.1217 raeburn 5402: my $class = 'LC_comblock';
1.1062 raeburn 5403: if ($activity eq 'docs') {
5404: $text = &mt('Content Access Blocked');
1.1217 raeburn 5405: $class = '';
1.1063 raeburn 5406: } elsif ($activity eq 'printout') {
5407: $text = &mt('Printing Blocked');
1.1232 raeburn 5408: } elsif ($activity eq 'passwd') {
5409: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5410: } elsif ($activity eq 'alert') {
5411: $text = &mt('Checking Critical Messages Blocked');
5412: } elsif ($activity eq 'reinit') {
5413: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5414: }
1.1061 raeburn 5415: $output .= <<"END_BLOCK";
1.1217 raeburn 5416: <div class='$class'>
1.869 kalberla 5417: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5418: title='$text'>
5419: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5420: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5421: title='$text'>$text</a>
1.867 kalberla 5422: </div>
5423:
5424: END_BLOCK
1.474 raeburn 5425:
1.1061 raeburn 5426: return ($blocked, $output);
1.854 kalberla 5427: }
1.490 raeburn 5428:
1.60 matthew 5429: ###############################################
5430:
1.682 raeburn 5431: sub check_ip_acc {
1.1201 raeburn 5432: my ($acc,$clientip)=@_;
1.682 raeburn 5433: &Apache::lonxml::debug("acc is $acc");
5434: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5435: return 1;
5436: }
1.1219 raeburn 5437: my $allowed;
1.1252 raeburn 5438: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5439:
5440: my $name;
1.1219 raeburn 5441: my %access = (
5442: allowfrom => 1,
5443: denyfrom => 0,
5444: );
5445: my @allows;
5446: my @denies;
5447: foreach my $item (split(',',$acc)) {
5448: $item =~ s/^\s*//;
5449: $item =~ s/\s*$//;
5450: my $pattern;
5451: if ($item =~ /^\!(.+)$/) {
5452: push(@denies,$1);
5453: } else {
5454: push(@allows,$item);
5455: }
5456: }
5457: my $numdenies = scalar(@denies);
5458: my $numallows = scalar(@allows);
5459: my $count = 0;
5460: foreach my $pattern (@denies,@allows) {
5461: $count ++;
5462: my $acctype = 'allowfrom';
5463: if ($count <= $numdenies) {
5464: $acctype = 'denyfrom';
5465: }
1.682 raeburn 5466: if ($pattern =~ /\*$/) {
5467: #35.8.*
5468: $pattern=~s/\*//;
1.1219 raeburn 5469: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5470: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5471: #35.8.3.[34-56]
5472: my $low=$2;
5473: my $high=$3;
5474: $pattern=$1;
5475: if ($ip =~ /^\Q$pattern\E/) {
5476: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5477: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5478: }
5479: } elsif ($pattern =~ /^\*/) {
5480: #*.msu.edu
5481: $pattern=~s/\*//;
5482: if (!defined($name)) {
5483: use Socket;
5484: my $netaddr=inet_aton($ip);
5485: ($name)=gethostbyaddr($netaddr,AF_INET);
5486: }
1.1219 raeburn 5487: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5488: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5489: #127.0.0.1
1.1219 raeburn 5490: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5491: } else {
5492: #some.name.com
5493: if (!defined($name)) {
5494: use Socket;
5495: my $netaddr=inet_aton($ip);
5496: ($name)=gethostbyaddr($netaddr,AF_INET);
5497: }
1.1219 raeburn 5498: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5499: }
5500: if ($allowed =~ /^(0|1)$/) { last; }
5501: }
5502: if ($allowed eq '') {
5503: if ($numdenies && !$numallows) {
5504: $allowed = 1;
5505: } else {
5506: $allowed = 0;
1.682 raeburn 5507: }
5508: }
5509: return $allowed;
5510: }
5511:
5512: ###############################################
5513:
1.60 matthew 5514: =pod
5515:
1.112 bowersj2 5516: =head1 Domain Template Functions
5517:
5518: =over 4
5519:
5520: =item * &determinedomain()
1.60 matthew 5521:
5522: Inputs: $domain (usually will be undef)
5523:
1.63 www 5524: Returns: Determines which domain should be used for designs
1.60 matthew 5525:
5526: =cut
1.54 www 5527:
1.60 matthew 5528: ###############################################
1.63 www 5529: sub determinedomain {
5530: my $domain=shift;
1.531 albertel 5531: if (! $domain) {
1.60 matthew 5532: # Determine domain if we have not been given one
1.893 raeburn 5533: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5534: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5535: if ($env{'request.role.domain'}) {
5536: $domain=$env{'request.role.domain'};
1.60 matthew 5537: }
5538: }
1.63 www 5539: return $domain;
5540: }
5541: ###############################################
1.517 raeburn 5542:
1.518 albertel 5543: sub devalidate_domconfig_cache {
5544: my ($udom)=@_;
5545: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5546: }
5547:
5548: # ---------------------- Get domain configuration for a domain
5549: sub get_domainconf {
5550: my ($udom) = @_;
5551: my $cachetime=1800;
5552: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5553: if (defined($cached)) { return %{$result}; }
5554:
5555: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5556: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5557: my (%designhash,%legacy);
1.518 albertel 5558: if (keys(%domconfig) > 0) {
5559: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5560: if (keys(%{$domconfig{'login'}})) {
5561: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5562: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5563: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5564: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5565: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5566: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5567: if ($key eq 'loginvia') {
5568: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5569: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5570: $designhash{$udom.'.login.loginvia'} = $server;
5571: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5572:
5573: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5574: } else {
5575: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5576: }
1.948 raeburn 5577: }
1.1208 raeburn 5578: } elsif ($key eq 'headtag') {
5579: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5580: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5581: }
1.946 raeburn 5582: }
1.1208 raeburn 5583: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5584: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5585: }
1.946 raeburn 5586: }
5587: }
5588: }
5589: } else {
5590: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5591: $designhash{$udom.'.login.'.$key.'_'.$img} =
5592: $domconfig{'login'}{$key}{$img};
5593: }
1.699 raeburn 5594: }
5595: } else {
5596: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5597: }
1.632 raeburn 5598: }
5599: } else {
5600: $legacy{'login'} = 1;
1.518 albertel 5601: }
1.632 raeburn 5602: } else {
5603: $legacy{'login'} = 1;
1.518 albertel 5604: }
5605: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5606: if (keys(%{$domconfig{'rolecolors'}})) {
5607: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5608: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5609: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5610: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5611: }
1.518 albertel 5612: }
5613: }
1.632 raeburn 5614: } else {
5615: $legacy{'rolecolors'} = 1;
1.518 albertel 5616: }
1.632 raeburn 5617: } else {
5618: $legacy{'rolecolors'} = 1;
1.518 albertel 5619: }
1.948 raeburn 5620: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5621: if ($domconfig{'autoenroll'}{'co-owners'}) {
5622: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5623: }
5624: }
1.632 raeburn 5625: if (keys(%legacy) > 0) {
5626: my %legacyhash = &get_legacy_domconf($udom);
5627: foreach my $item (keys(%legacyhash)) {
5628: if ($item =~ /^\Q$udom\E\.login/) {
5629: if ($legacy{'login'}) {
5630: $designhash{$item} = $legacyhash{$item};
5631: }
5632: } else {
5633: if ($legacy{'rolecolors'}) {
5634: $designhash{$item} = $legacyhash{$item};
5635: }
1.518 albertel 5636: }
5637: }
5638: }
1.632 raeburn 5639: } else {
5640: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5641: }
5642: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5643: $cachetime);
5644: return %designhash;
5645: }
5646:
1.632 raeburn 5647: sub get_legacy_domconf {
5648: my ($udom) = @_;
5649: my %legacyhash;
5650: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5651: my $designfile = $designdir.'/'.$udom.'.tab';
5652: if (-e $designfile) {
5653: if ( open (my $fh,"<$designfile") ) {
5654: while (my $line = <$fh>) {
5655: next if ($line =~ /^\#/);
5656: chomp($line);
5657: my ($key,$val)=(split(/\=/,$line));
5658: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5659: }
5660: close($fh);
5661: }
5662: }
1.1026 raeburn 5663: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5664: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5665: }
5666: return %legacyhash;
5667: }
5668:
1.63 www 5669: =pod
5670:
1.112 bowersj2 5671: =item * &domainlogo()
1.63 www 5672:
5673: Inputs: $domain (usually will be undef)
5674:
5675: Returns: A link to a domain logo, if the domain logo exists.
5676: If the domain logo does not exist, a description of the domain.
5677:
5678: =cut
1.112 bowersj2 5679:
1.63 www 5680: ###############################################
5681: sub domainlogo {
1.517 raeburn 5682: my $domain = &determinedomain(shift);
1.518 albertel 5683: my %designhash = &get_domainconf($domain);
1.517 raeburn 5684: # See if there is a logo
5685: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5686: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5687: if ($imgsrc =~ m{^/(adm|res)/}) {
5688: if ($imgsrc =~ m{^/res/}) {
5689: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5690: &Apache::lonnet::repcopy($local_name);
5691: }
5692: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5693: }
5694: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5695: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5696: return &Apache::lonnet::domain($domain,'description');
1.59 www 5697: } else {
1.60 matthew 5698: return '';
1.59 www 5699: }
5700: }
1.63 www 5701: ##############################################
5702:
5703: =pod
5704:
1.112 bowersj2 5705: =item * &designparm()
1.63 www 5706:
5707: Inputs: $which parameter; $domain (usually will be undef)
5708:
5709: Returns: value of designparamter $which
5710:
5711: =cut
1.112 bowersj2 5712:
1.397 albertel 5713:
1.400 albertel 5714: ##############################################
1.397 albertel 5715: sub designparm {
5716: my ($which,$domain)=@_;
5717: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5718: return $env{'environment.color.'.$which};
1.96 www 5719: }
1.63 www 5720: $domain=&determinedomain($domain);
1.1016 raeburn 5721: my %domdesign;
5722: unless ($domain eq 'public') {
5723: %domdesign = &get_domainconf($domain);
5724: }
1.520 raeburn 5725: my $output;
1.517 raeburn 5726: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5727: $output = $domdesign{$domain.'.'.$which};
1.63 www 5728: } else {
1.520 raeburn 5729: $output = $defaultdesign{$which};
5730: }
5731: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5732: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5733: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5734: if ($output =~ m{^/res/}) {
5735: my $local_name = &Apache::lonnet::filelocation('',$output);
5736: &Apache::lonnet::repcopy($local_name);
5737: }
1.520 raeburn 5738: $output = &lonhttpdurl($output);
5739: }
1.63 www 5740: }
1.520 raeburn 5741: return $output;
1.63 www 5742: }
1.59 www 5743:
1.822 bisitz 5744: ##############################################
5745: =pod
5746:
1.832 bisitz 5747: =item * &authorspace()
5748:
1.1028 raeburn 5749: Inputs: $url (usually will be undef).
1.832 bisitz 5750:
1.1132 raeburn 5751: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5752: directory being viewed (or for which action is being taken).
5753: If $url is provided, and begins /priv/<domain>/<uname>
5754: the path will be that portion of the $context argument.
5755: Otherwise the path will be for the author space of the current
5756: user when the current role is author, or for that of the
5757: co-author/assistant co-author space when the current role
5758: is co-author or assistant co-author.
1.832 bisitz 5759:
5760: =cut
5761:
5762: sub authorspace {
1.1028 raeburn 5763: my ($url) = @_;
5764: if ($url ne '') {
5765: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5766: return $1;
5767: }
5768: }
1.832 bisitz 5769: my $caname = '';
1.1024 www 5770: my $cadom = '';
1.1028 raeburn 5771: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5772: ($cadom,$caname) =
1.832 bisitz 5773: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5774: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5775: $caname = $env{'user.name'};
1.1024 www 5776: $cadom = $env{'user.domain'};
1.832 bisitz 5777: }
1.1028 raeburn 5778: if (($caname ne '') && ($cadom ne '')) {
5779: return "/priv/$cadom/$caname/";
5780: }
5781: return;
1.832 bisitz 5782: }
5783:
5784: ##############################################
5785: =pod
5786:
1.822 bisitz 5787: =item * &head_subbox()
5788:
5789: Inputs: $content (contains HTML code with page functions, etc.)
5790:
5791: Returns: HTML div with $content
5792: To be included in page header
5793:
5794: =cut
5795:
5796: sub head_subbox {
5797: my ($content)=@_;
5798: my $output =
1.993 raeburn 5799: '<div class="LC_head_subbox">'
1.822 bisitz 5800: .$content
5801: .'</div>'
5802: }
5803:
5804: ##############################################
5805: =pod
5806:
5807: =item * &CSTR_pageheader()
5808:
1.1026 raeburn 5809: Input: (optional) filename from which breadcrumb trail is built.
5810: In most cases no input as needed, as $env{'request.filename'}
5811: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5812:
5813: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5814: To be included on Authoring Space pages
1.822 bisitz 5815:
5816: =cut
5817:
5818: sub CSTR_pageheader {
1.1026 raeburn 5819: my ($trailfile) = @_;
5820: if ($trailfile eq '') {
5821: $trailfile = $env{'request.filename'};
5822: }
5823:
5824: # this is for resources; directories have customtitle, and crumbs
5825: # and select recent are created in lonpubdir.pm
5826:
5827: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5828: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5829: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5830: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5831: $formaction =~ s{/+}{/}g;
1.822 bisitz 5832:
5833: my $parentpath = '';
5834: my $lastitem = '';
5835: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5836: $parentpath = $1;
5837: $lastitem = $2;
5838: } else {
5839: $lastitem = $thisdisfn;
5840: }
1.921 bisitz 5841:
1.1246 raeburn 5842: my ($crsauthor,$title);
5843: if (($env{'request.course.id'}) &&
5844: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5845: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5846: $crsauthor = 1;
5847: $title = &mt('Course Authoring Space');
5848: } else {
5849: $title = &mt('Authoring Space');
5850: }
5851:
1.1314 raeburn 5852: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 5853: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 5854: $target = '';
5855: $crumbtarget = '';
1.1313 raeburn 5856: }
5857:
1.921 bisitz 5858: my $output =
1.822 bisitz 5859: '<div>'
5860: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5861: .'<b>'.$title.'</b> '
1.1314 raeburn 5862: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5863: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5864:
5865: if ($lastitem) {
5866: $output .=
5867: '<span class="LC_filename">'
5868: .$lastitem
5869: .'</span>';
5870: }
1.1245 raeburn 5871:
1.1246 raeburn 5872: if ($crsauthor) {
5873: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5874: } else {
5875: $output .=
5876: '<br />'
1.1314 raeburn 5877: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 5878: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5879: .'</form>'
5880: .&Apache::lonmenu::constspaceform();
5881: }
5882: $output .= '</div>';
1.921 bisitz 5883:
5884: return $output;
1.822 bisitz 5885: }
5886:
1.60 matthew 5887: ###############################################
5888: ###############################################
5889:
5890: =pod
5891:
1.112 bowersj2 5892: =back
5893:
1.549 albertel 5894: =head1 HTML Helpers
1.112 bowersj2 5895:
5896: =over 4
5897:
5898: =item * &bodytag()
1.60 matthew 5899:
5900: Returns a uniform header for LON-CAPA web pages.
5901:
5902: Inputs:
5903:
1.112 bowersj2 5904: =over 4
5905:
5906: =item * $title, A title to be displayed on the page.
5907:
5908: =item * $function, the current role (can be undef).
5909:
5910: =item * $addentries, extra parameters for the <body> tag.
5911:
5912: =item * $bodyonly, if defined, only return the <body> tag.
5913:
5914: =item * $domain, if defined, force a given domain.
5915:
5916: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5917: text interface only)
1.60 matthew 5918:
1.814 bisitz 5919: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5920: navigational links
1.317 albertel 5921:
1.338 albertel 5922: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5923:
1.460 albertel 5924: =item * $args, optional argument valid values are
5925: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 5926: use_absolute -> for external resource or syllabus, this will
5927: contain https://<hostname> if server uses
5928: https (as per hosts.tab), but request is for http
5929: hostname -> hostname, from $r->hostname().
1.460 albertel 5930:
1.1096 raeburn 5931: =item * $advtoolsref, optional argument, ref to an array containing
5932: inlineremote items to be added in "Functions" menu below
5933: breadcrumbs.
5934:
1.112 bowersj2 5935: =back
5936:
1.60 matthew 5937: Returns: A uniform header for LON-CAPA web pages.
5938: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5939: If $bodyonly is undef or zero, an html string containing a <body> tag and
5940: other decorations will be returned.
5941:
5942: =cut
5943:
1.54 www 5944: sub bodytag {
1.831 bisitz 5945: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5946: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5947:
1.954 raeburn 5948: my $public;
5949: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5950: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5951: $public = 1;
5952: }
1.460 albertel 5953: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5954: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 5955: my $hostname = $args->{'hostname'};
1.339 albertel 5956:
1.183 matthew 5957: $function = &get_users_function() if (!$function);
1.339 albertel 5958: my $img = &designparm($function.'.img',$domain);
5959: my $font = &designparm($function.'.font',$domain);
5960: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5961:
1.803 bisitz 5962: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5963: 'bgcolor' => $pgbg,
1.339 albertel 5964: 'text' => $font,
5965: 'alink' => &designparm($function.'.alink',$domain),
5966: 'vlink' => &designparm($function.'.vlink',$domain),
5967: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5968: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5969:
1.63 www 5970: # role and realm
1.1178 raeburn 5971: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5972: if ($realm) {
5973: $realm = '/'.$realm;
5974: }
1.378 raeburn 5975: if ($role eq 'ca') {
1.479 albertel 5976: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5977: $realm = &plainname($rname,$rdom);
1.378 raeburn 5978: }
1.55 www 5979: # realm
1.258 albertel 5980: if ($env{'request.course.id'}) {
1.378 raeburn 5981: if ($env{'request.role'} !~ /^cr/) {
5982: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5983: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5984: if ($env{'request.role.desc'}) {
5985: $role = $env{'request.role.desc'};
5986: } else {
5987: $role = &mt('Helpdesk[_1]',' '.$2);
5988: }
1.1257 raeburn 5989: } else {
5990: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5991: }
1.898 raeburn 5992: if ($env{'request.course.sec'}) {
5993: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5994: }
1.359 albertel 5995: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5996: } else {
5997: $role = &Apache::lonnet::plaintext($role);
1.54 www 5998: }
1.433 albertel 5999:
1.359 albertel 6000: if (!$realm) { $realm=' '; }
1.330 albertel 6001:
1.438 albertel 6002: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6003:
1.101 www 6004: # construct main body tag
1.359 albertel 6005: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6006: &Apache::lontexconvert::init_math_support();
1.252 albertel 6007:
1.1131 raeburn 6008: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6009:
1.1130 raeburn 6010: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6011: return $bodytag;
1.1130 raeburn 6012: }
1.359 albertel 6013:
1.954 raeburn 6014: if ($public) {
1.433 albertel 6015: undef($role);
6016: }
1.359 albertel 6017:
1.762 bisitz 6018: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6019: #
6020: # Extra info if you are the DC
6021: my $dc_info = '';
6022: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6023: $env{'course.'.$env{'request.course.id'}.
6024: '.domain'}.'/'})) {
6025: my $cid = $env{'request.course.id'};
1.917 raeburn 6026: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6027: $dc_info =~ s/\s+$//;
1.359 albertel 6028: }
6029:
1.1237 raeburn 6030: my $crstype;
6031: if ($env{'request.course.id'}) {
6032: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6033: } elsif ($args->{'crstype'}) {
6034: $crstype = $args->{'crstype'};
6035: }
6036: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6037: undef($role);
6038: } else {
1.1242 raeburn 6039: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6040: }
1.853 droeschl 6041:
1.903 droeschl 6042: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6043:
6044: # if ($env{'request.state'} eq 'construct') {
6045: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6046: # }
6047:
1.1130 raeburn 6048: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6049: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6050:
1.1237 raeburn 6051: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 6052:
1.916 droeschl 6053: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 6054: if ($dc_info) {
6055: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6056: }
1.1130 raeburn 6057: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 6058: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 6059: return $bodytag;
6060: }
1.894 droeschl 6061:
1.927 raeburn 6062: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 6063: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 6064: }
1.916 droeschl 6065:
1.1130 raeburn 6066: $bodytag .= $right;
1.852 droeschl 6067:
1.917 raeburn 6068: if ($dc_info) {
6069: $dc_info = &dc_courseid_toggle($dc_info);
6070: }
6071: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 6072:
1.1169 raeburn 6073: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6074: if ($args->{'no_secondary_menu'}) {
6075: return $bodytag;
6076: }
1.1169 raeburn 6077: #don't show menus for public users
1.954 raeburn 6078: if (!$public){
1.1154 raeburn 6079: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 6080: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6081: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6082: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6083: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1274 raeburn 6084: $args->{'bread_crumbs'},'','',$hostname);
1.1096 raeburn 6085: } elsif ($forcereg) {
6086: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6087: $args->{'group'},
1.1274 raeburn 6088: $args->{'hide_buttons'},
6089: $hostname);
1.1096 raeburn 6090: } else {
6091: $bodytag .=
6092: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6093: $forcereg,$args->{'group'},
6094: $args->{'bread_crumbs'},
1.1274 raeburn 6095: $advtoolsref,'',$hostname);
1.920 raeburn 6096: }
1.903 droeschl 6097: }else{
6098: # this is to seperate menu from content when there's no secondary
6099: # menu. Especially needed for public accessible ressources.
6100: $bodytag .= '<hr style="clear:both" />';
6101: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6102: }
1.903 droeschl 6103:
1.235 raeburn 6104: return $bodytag;
1.182 matthew 6105: }
6106:
1.917 raeburn 6107: sub dc_courseid_toggle {
6108: my ($dc_info) = @_;
1.980 raeburn 6109: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6110: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6111: &mt('(More ...)').'</a></span>'.
6112: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6113: }
6114:
1.330 albertel 6115: sub make_attr_string {
6116: my ($register,$attr_ref) = @_;
6117:
6118: if ($attr_ref && !ref($attr_ref)) {
6119: die("addentries Must be a hash ref ".
6120: join(':',caller(1))." ".
6121: join(':',caller(0))." ");
6122: }
6123:
6124: if ($register) {
1.339 albertel 6125: my ($on_load,$on_unload);
6126: foreach my $key (keys(%{$attr_ref})) {
6127: if (lc($key) eq 'onload') {
6128: $on_load.=$attr_ref->{$key}.';';
6129: delete($attr_ref->{$key});
6130:
6131: } elsif (lc($key) eq 'onunload') {
6132: $on_unload.=$attr_ref->{$key}.';';
6133: delete($attr_ref->{$key});
6134: }
6135: }
1.953 droeschl 6136: $attr_ref->{'onload'} = $on_load;
6137: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6138: }
1.339 albertel 6139:
1.330 albertel 6140: my $attr_string;
1.1159 raeburn 6141: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6142: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6143: }
6144: return $attr_string;
6145: }
6146:
6147:
1.182 matthew 6148: ###############################################
1.251 albertel 6149: ###############################################
6150:
6151: =pod
6152:
6153: =item * &endbodytag()
6154:
6155: Returns a uniform footer for LON-CAPA web pages.
6156:
1.635 raeburn 6157: Inputs: 1 - optional reference to an args hash
6158: If in the hash, key for noredirectlink has a value which evaluates to true,
6159: a 'Continue' link is not displayed if the page contains an
6160: internal redirect in the <head></head> section,
6161: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6162:
6163: =cut
6164:
6165: sub endbodytag {
1.635 raeburn 6166: my ($args) = @_;
1.1080 raeburn 6167: my $endbodytag;
6168: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6169: $endbodytag='</body>';
6170: }
1.315 albertel 6171: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6172: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6173: $endbodytag=
6174: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6175: &mt('Continue').'</a>'.
6176: $endbodytag;
6177: }
1.315 albertel 6178: }
1.251 albertel 6179: return $endbodytag;
6180: }
6181:
1.352 albertel 6182: =pod
6183:
6184: =item * &standard_css()
6185:
6186: Returns a style sheet
6187:
6188: Inputs: (all optional)
6189: domain -> force to color decorate a page for a specific
6190: domain
6191: function -> force usage of a specific rolish color scheme
6192: bgcolor -> override the default page bgcolor
6193:
6194: =cut
6195:
1.343 albertel 6196: sub standard_css {
1.345 albertel 6197: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6198: $function = &get_users_function() if (!$function);
6199: my $img = &designparm($function.'.img', $domain);
6200: my $tabbg = &designparm($function.'.tabbg', $domain);
6201: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6202: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6203: #second colour for later usage
1.345 albertel 6204: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6205: my $pgbg_or_bgcolor =
6206: $bgcolor ||
1.352 albertel 6207: &designparm($function.'.pgbg', $domain);
1.382 albertel 6208: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6209: my $alink = &designparm($function.'.alink', $domain);
6210: my $vlink = &designparm($function.'.vlink', $domain);
6211: my $link = &designparm($function.'.link', $domain);
6212:
1.602 albertel 6213: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6214: my $mono = 'monospace';
1.850 bisitz 6215: my $data_table_head = $sidebg;
6216: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6217: my $data_table_dark = '#E0E0E0';
1.470 banghart 6218: my $data_table_darker = '#CCCCCC';
1.349 albertel 6219: my $data_table_highlight = '#FFFF00';
1.352 albertel 6220: my $mail_new = '#FFBB77';
6221: my $mail_new_hover = '#DD9955';
6222: my $mail_read = '#BBBB77';
6223: my $mail_read_hover = '#999944';
6224: my $mail_replied = '#AAAA88';
6225: my $mail_replied_hover = '#888855';
6226: my $mail_other = '#99BBBB';
6227: my $mail_other_hover = '#669999';
1.391 albertel 6228: my $table_header = '#DDDDDD';
1.489 raeburn 6229: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6230: my $lg_border_color = '#C8C8C8';
1.952 onken 6231: my $button_hover = '#BF2317';
1.392 albertel 6232:
1.608 albertel 6233: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6234: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6235: : '0 3px 0 4px';
1.448 albertel 6236:
1.523 albertel 6237:
1.343 albertel 6238: return <<END;
1.947 droeschl 6239:
6240: /* needed for iframe to allow 100% height in FF */
6241: body, html {
6242: margin: 0;
6243: padding: 0 0.5%;
6244: height: 99%; /* to avoid scrollbars */
6245: }
6246:
1.795 www 6247: body {
1.911 bisitz 6248: font-family: $sans;
6249: line-height:130%;
6250: font-size:0.83em;
6251: color:$font;
1.795 www 6252: }
6253:
1.959 onken 6254: a:focus,
6255: a:focus img {
1.795 www 6256: color: red;
6257: }
1.698 harmsja 6258:
1.911 bisitz 6259: form, .inline {
6260: display: inline;
1.795 www 6261: }
1.721 harmsja 6262:
1.795 www 6263: .LC_right {
1.911 bisitz 6264: text-align:right;
1.795 www 6265: }
6266:
6267: .LC_middle {
1.911 bisitz 6268: vertical-align:middle;
1.795 www 6269: }
1.721 harmsja 6270:
1.1130 raeburn 6271: .LC_floatleft {
6272: float: left;
6273: }
6274:
6275: .LC_floatright {
6276: float: right;
6277: }
6278:
1.911 bisitz 6279: .LC_400Box {
6280: width:400px;
6281: }
1.721 harmsja 6282:
1.947 droeschl 6283: .LC_iframecontainer {
6284: width: 98%;
6285: margin: 0;
6286: position: fixed;
6287: top: 8.5em;
6288: bottom: 0;
6289: }
6290:
6291: .LC_iframecontainer iframe{
6292: border: none;
6293: width: 100%;
6294: height: 100%;
6295: }
6296:
1.778 bisitz 6297: .LC_filename {
6298: font-family: $mono;
6299: white-space:pre;
1.921 bisitz 6300: font-size: 120%;
1.778 bisitz 6301: }
6302:
6303: .LC_fileicon {
6304: border: none;
6305: height: 1.3em;
6306: vertical-align: text-bottom;
6307: margin-right: 0.3em;
6308: text-decoration:none;
6309: }
6310:
1.1008 www 6311: .LC_setting {
6312: text-decoration:underline;
6313: }
6314:
1.350 albertel 6315: .LC_error {
6316: color: red;
6317: }
1.795 www 6318:
1.1097 bisitz 6319: .LC_warning {
6320: color: darkorange;
6321: }
6322:
1.457 albertel 6323: .LC_diff_removed {
1.733 bisitz 6324: color: red;
1.394 albertel 6325: }
1.532 albertel 6326:
6327: .LC_info,
1.457 albertel 6328: .LC_success,
6329: .LC_diff_added {
1.350 albertel 6330: color: green;
6331: }
1.795 www 6332:
1.802 bisitz 6333: div.LC_confirm_box {
6334: background-color: #FAFAFA;
6335: border: 1px solid $lg_border_color;
6336: margin-right: 0;
6337: padding: 5px;
6338: }
6339:
6340: div.LC_confirm_box .LC_error img,
6341: div.LC_confirm_box .LC_success img {
6342: vertical-align: middle;
6343: }
6344:
1.1242 raeburn 6345: .LC_maxwidth {
6346: max-width: 100%;
6347: height: auto;
6348: }
6349:
1.1243 raeburn 6350: .LC_textsize_mobile {
6351: \@media only screen and (max-device-width: 480px) {
6352: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6353: }
6354: }
6355:
1.440 albertel 6356: .LC_icon {
1.771 droeschl 6357: border: none;
1.790 droeschl 6358: vertical-align: middle;
1.771 droeschl 6359: }
6360:
1.543 albertel 6361: .LC_docs_spacer {
6362: width: 25px;
6363: height: 1px;
1.771 droeschl 6364: border: none;
1.543 albertel 6365: }
1.346 albertel 6366:
1.532 albertel 6367: .LC_internal_info {
1.735 bisitz 6368: color: #999999;
1.532 albertel 6369: }
6370:
1.794 www 6371: .LC_discussion {
1.1050 www 6372: background: $data_table_dark;
1.911 bisitz 6373: border: 1px solid black;
6374: margin: 2px;
1.794 www 6375: }
6376:
6377: .LC_disc_action_left {
1.1050 www 6378: background: $sidebg;
1.911 bisitz 6379: text-align: left;
1.1050 www 6380: padding: 4px;
6381: margin: 2px;
1.794 www 6382: }
6383:
6384: .LC_disc_action_right {
1.1050 www 6385: background: $sidebg;
1.911 bisitz 6386: text-align: right;
1.1050 www 6387: padding: 4px;
6388: margin: 2px;
1.794 www 6389: }
6390:
6391: .LC_disc_new_item {
1.911 bisitz 6392: background: white;
6393: border: 2px solid red;
1.1050 www 6394: margin: 4px;
6395: padding: 4px;
1.794 www 6396: }
6397:
6398: .LC_disc_old_item {
1.911 bisitz 6399: background: white;
1.1050 www 6400: margin: 4px;
6401: padding: 4px;
1.794 www 6402: }
6403:
1.458 albertel 6404: table.LC_pastsubmission {
6405: border: 1px solid black;
6406: margin: 2px;
6407: }
6408:
1.924 bisitz 6409: table#LC_menubuttons {
1.345 albertel 6410: width: 100%;
6411: background: $pgbg;
1.392 albertel 6412: border: 2px;
1.402 albertel 6413: border-collapse: separate;
1.803 bisitz 6414: padding: 0;
1.345 albertel 6415: }
1.392 albertel 6416:
1.801 tempelho 6417: table#LC_title_bar a {
6418: color: $fontmenu;
6419: }
1.836 bisitz 6420:
1.807 droeschl 6421: table#LC_title_bar {
1.819 tempelho 6422: clear: both;
1.836 bisitz 6423: display: none;
1.807 droeschl 6424: }
6425:
1.795 www 6426: table#LC_title_bar,
1.933 droeschl 6427: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6428: table#LC_title_bar.LC_with_remote {
1.359 albertel 6429: width: 100%;
1.392 albertel 6430: border-color: $pgbg;
6431: border-style: solid;
6432: border-width: $border;
1.379 albertel 6433: background: $pgbg;
1.801 tempelho 6434: color: $fontmenu;
1.392 albertel 6435: border-collapse: collapse;
1.803 bisitz 6436: padding: 0;
1.819 tempelho 6437: margin: 0;
1.359 albertel 6438: }
1.795 www 6439:
1.933 droeschl 6440: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6441: margin: 0;
6442: padding: 0;
1.933 droeschl 6443: position: relative;
6444: list-style: none;
1.913 droeschl 6445: }
1.933 droeschl 6446: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6447: display: inline;
6448: }
1.933 droeschl 6449:
6450: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6451: padding: 0;
1.933 droeschl 6452: margin: 0;
6453: float: left;
1.913 droeschl 6454: }
1.933 droeschl 6455: .LC_breadcrumb_tools_tools {
6456: padding: 0;
6457: margin: 0;
1.913 droeschl 6458: float: right;
6459: }
6460:
1.1240 raeburn 6461: .LC_placement_prog {
6462: padding-right: 20px;
6463: font-weight: bold;
6464: font-size: 90%;
6465: }
6466:
1.359 albertel 6467: table#LC_title_bar td {
6468: background: $tabbg;
6469: }
1.795 www 6470:
1.911 bisitz 6471: table#LC_menubuttons img {
1.803 bisitz 6472: border: none;
1.346 albertel 6473: }
1.795 www 6474:
1.842 droeschl 6475: .LC_breadcrumbs_component {
1.911 bisitz 6476: float: right;
6477: margin: 0 1em;
1.357 albertel 6478: }
1.842 droeschl 6479: .LC_breadcrumbs_component img {
1.911 bisitz 6480: vertical-align: middle;
1.777 tempelho 6481: }
1.795 www 6482:
1.1243 raeburn 6483: .LC_breadcrumbs_hoverable {
6484: background: $sidebg;
6485: }
6486:
1.383 albertel 6487: td.LC_table_cell_checkbox {
6488: text-align: center;
6489: }
1.795 www 6490:
6491: .LC_fontsize_small {
1.911 bisitz 6492: font-size: 70%;
1.705 tempelho 6493: }
6494:
1.844 bisitz 6495: #LC_breadcrumbs {
1.911 bisitz 6496: clear:both;
6497: background: $sidebg;
6498: border-bottom: 1px solid $lg_border_color;
6499: line-height: 2.5em;
1.933 droeschl 6500: overflow: hidden;
1.911 bisitz 6501: margin: 0;
6502: padding: 0;
1.995 raeburn 6503: text-align: left;
1.819 tempelho 6504: }
1.862 bisitz 6505:
1.1098 bisitz 6506: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6507: clear:both;
6508: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6509: border: 1px solid $sidebg;
1.1098 bisitz 6510: margin: 0 0 10px 0;
1.966 bisitz 6511: padding: 3px;
1.995 raeburn 6512: text-align: left;
1.822 bisitz 6513: }
6514:
1.795 www 6515: .LC_fontsize_medium {
1.911 bisitz 6516: font-size: 85%;
1.705 tempelho 6517: }
6518:
1.795 www 6519: .LC_fontsize_large {
1.911 bisitz 6520: font-size: 120%;
1.705 tempelho 6521: }
6522:
1.346 albertel 6523: .LC_menubuttons_inline_text {
6524: color: $font;
1.698 harmsja 6525: font-size: 90%;
1.701 harmsja 6526: padding-left:3px;
1.346 albertel 6527: }
6528:
1.934 droeschl 6529: .LC_menubuttons_inline_text img{
6530: vertical-align: middle;
6531: }
6532:
1.1051 www 6533: li.LC_menubuttons_inline_text img {
1.951 onken 6534: cursor:pointer;
1.1002 droeschl 6535: text-decoration: none;
1.951 onken 6536: }
6537:
1.526 www 6538: .LC_menubuttons_link {
6539: text-decoration: none;
6540: }
1.795 www 6541:
1.522 albertel 6542: .LC_menubuttons_category {
1.521 www 6543: color: $font;
1.526 www 6544: background: $pgbg;
1.521 www 6545: font-size: larger;
6546: font-weight: bold;
6547: }
6548:
1.346 albertel 6549: td.LC_menubuttons_text {
1.911 bisitz 6550: color: $font;
1.346 albertel 6551: }
1.706 harmsja 6552:
1.346 albertel 6553: .LC_current_location {
6554: background: $tabbg;
6555: }
1.795 www 6556:
1.1286 raeburn 6557: td.LC_zero_height {
6558: line-height: 0;
6559: cellpadding: 0;
6560: }
6561:
1.938 bisitz 6562: table.LC_data_table {
1.347 albertel 6563: border: 1px solid #000000;
1.402 albertel 6564: border-collapse: separate;
1.426 albertel 6565: border-spacing: 1px;
1.610 albertel 6566: background: $pgbg;
1.347 albertel 6567: }
1.795 www 6568:
1.422 albertel 6569: .LC_data_table_dense {
6570: font-size: small;
6571: }
1.795 www 6572:
1.507 raeburn 6573: table.LC_nested_outer {
6574: border: 1px solid #000000;
1.589 raeburn 6575: border-collapse: collapse;
1.803 bisitz 6576: border-spacing: 0;
1.507 raeburn 6577: width: 100%;
6578: }
1.795 www 6579:
1.879 raeburn 6580: table.LC_innerpickbox,
1.507 raeburn 6581: table.LC_nested {
1.803 bisitz 6582: border: none;
1.589 raeburn 6583: border-collapse: collapse;
1.803 bisitz 6584: border-spacing: 0;
1.507 raeburn 6585: width: 100%;
6586: }
1.795 www 6587:
1.911 bisitz 6588: table.LC_data_table tr th,
6589: table.LC_calendar tr th,
1.879 raeburn 6590: table.LC_prior_tries tr th,
6591: table.LC_innerpickbox tr th {
1.349 albertel 6592: font-weight: bold;
6593: background-color: $data_table_head;
1.801 tempelho 6594: color:$fontmenu;
1.701 harmsja 6595: font-size:90%;
1.347 albertel 6596: }
1.795 www 6597:
1.879 raeburn 6598: table.LC_innerpickbox tr th,
6599: table.LC_innerpickbox tr td {
6600: vertical-align: top;
6601: }
6602:
1.711 raeburn 6603: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6604: background-color: #CCCCCC;
1.711 raeburn 6605: font-weight: bold;
6606: text-align: left;
6607: }
1.795 www 6608:
1.912 bisitz 6609: table.LC_data_table tr.LC_odd_row > td {
6610: background-color: $data_table_light;
6611: padding: 2px;
6612: vertical-align: top;
6613: }
6614:
1.809 bisitz 6615: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6616: background-color: $data_table_light;
1.912 bisitz 6617: vertical-align: top;
6618: }
6619:
6620: table.LC_data_table tr.LC_even_row > td {
6621: background-color: $data_table_dark;
1.425 albertel 6622: padding: 2px;
1.900 bisitz 6623: vertical-align: top;
1.347 albertel 6624: }
1.795 www 6625:
1.809 bisitz 6626: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6627: background-color: $data_table_dark;
1.900 bisitz 6628: vertical-align: top;
1.347 albertel 6629: }
1.795 www 6630:
1.425 albertel 6631: table.LC_data_table tr.LC_data_table_highlight td {
6632: background-color: $data_table_darker;
6633: }
1.795 www 6634:
1.639 raeburn 6635: table.LC_data_table tr td.LC_leftcol_header {
6636: background-color: $data_table_head;
6637: font-weight: bold;
6638: }
1.795 www 6639:
1.451 albertel 6640: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6641: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6642: font-weight: bold;
6643: font-style: italic;
6644: text-align: center;
6645: padding: 8px;
1.347 albertel 6646: }
1.795 www 6647:
1.1114 raeburn 6648: table.LC_data_table tr.LC_empty_row td,
6649: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6650: background-color: $sidebg;
6651: }
6652:
6653: table.LC_nested tr.LC_empty_row td {
6654: background-color: #FFFFFF;
6655: }
6656:
1.890 droeschl 6657: table.LC_caption {
6658: }
6659:
1.507 raeburn 6660: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6661: padding: 4ex
6662: }
1.795 www 6663:
1.507 raeburn 6664: table.LC_nested_outer tr th {
6665: font-weight: bold;
1.801 tempelho 6666: color:$fontmenu;
1.507 raeburn 6667: background-color: $data_table_head;
1.701 harmsja 6668: font-size: small;
1.507 raeburn 6669: border-bottom: 1px solid #000000;
6670: }
1.795 www 6671:
1.507 raeburn 6672: table.LC_nested_outer tr td.LC_subheader {
6673: background-color: $data_table_head;
6674: font-weight: bold;
6675: font-size: small;
6676: border-bottom: 1px solid #000000;
6677: text-align: right;
1.451 albertel 6678: }
1.795 www 6679:
1.507 raeburn 6680: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6681: background-color: #CCCCCC;
1.451 albertel 6682: font-weight: bold;
6683: font-size: small;
1.507 raeburn 6684: text-align: center;
6685: }
1.795 www 6686:
1.589 raeburn 6687: table.LC_nested tr.LC_info_row td.LC_left_item,
6688: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6689: text-align: left;
1.451 albertel 6690: }
1.795 www 6691:
1.507 raeburn 6692: table.LC_nested td {
1.735 bisitz 6693: background-color: #FFFFFF;
1.451 albertel 6694: font-size: small;
1.507 raeburn 6695: }
1.795 www 6696:
1.507 raeburn 6697: table.LC_nested_outer tr th.LC_right_item,
6698: table.LC_nested tr.LC_info_row td.LC_right_item,
6699: table.LC_nested tr.LC_odd_row td.LC_right_item,
6700: table.LC_nested tr td.LC_right_item {
1.451 albertel 6701: text-align: right;
6702: }
6703:
1.507 raeburn 6704: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6705: background-color: #EEEEEE;
1.451 albertel 6706: }
6707:
1.473 raeburn 6708: table.LC_createuser {
6709: }
6710:
6711: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6712: font-size: small;
1.473 raeburn 6713: }
6714:
6715: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6716: background-color: #CCCCCC;
1.473 raeburn 6717: font-weight: bold;
6718: text-align: center;
6719: }
6720:
1.349 albertel 6721: table.LC_calendar {
6722: border: 1px solid #000000;
6723: border-collapse: collapse;
1.917 raeburn 6724: width: 98%;
1.349 albertel 6725: }
1.795 www 6726:
1.349 albertel 6727: table.LC_calendar_pickdate {
6728: font-size: xx-small;
6729: }
1.795 www 6730:
1.349 albertel 6731: table.LC_calendar tr td {
6732: border: 1px solid #000000;
6733: vertical-align: top;
1.917 raeburn 6734: width: 14%;
1.349 albertel 6735: }
1.795 www 6736:
1.349 albertel 6737: table.LC_calendar tr td.LC_calendar_day_empty {
6738: background-color: $data_table_dark;
6739: }
1.795 www 6740:
1.779 bisitz 6741: table.LC_calendar tr td.LC_calendar_day_current {
6742: background-color: $data_table_highlight;
1.777 tempelho 6743: }
1.795 www 6744:
1.938 bisitz 6745: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6746: background-color: $mail_new;
6747: }
1.795 www 6748:
1.938 bisitz 6749: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6750: background-color: $mail_new_hover;
6751: }
1.795 www 6752:
1.938 bisitz 6753: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6754: background-color: $mail_read;
6755: }
1.795 www 6756:
1.938 bisitz 6757: /*
6758: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6759: background-color: $mail_read_hover;
6760: }
1.938 bisitz 6761: */
1.795 www 6762:
1.938 bisitz 6763: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6764: background-color: $mail_replied;
6765: }
1.795 www 6766:
1.938 bisitz 6767: /*
6768: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6769: background-color: $mail_replied_hover;
6770: }
1.938 bisitz 6771: */
1.795 www 6772:
1.938 bisitz 6773: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6774: background-color: $mail_other;
6775: }
1.795 www 6776:
1.938 bisitz 6777: /*
6778: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6779: background-color: $mail_other_hover;
6780: }
1.938 bisitz 6781: */
1.494 raeburn 6782:
1.777 tempelho 6783: table.LC_data_table tr > td.LC_browser_file,
6784: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6785: background: #AAEE77;
1.389 albertel 6786: }
1.795 www 6787:
1.777 tempelho 6788: table.LC_data_table tr > td.LC_browser_file_locked,
6789: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6790: background: #FFAA99;
1.387 albertel 6791: }
1.795 www 6792:
1.777 tempelho 6793: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6794: background: #888888;
1.779 bisitz 6795: }
1.795 www 6796:
1.777 tempelho 6797: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6798: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6799: background: #F8F866;
1.777 tempelho 6800: }
1.795 www 6801:
1.696 bisitz 6802: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6803: background: #E0E8FF;
1.387 albertel 6804: }
1.696 bisitz 6805:
1.707 bisitz 6806: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6807: /* background: #77FF77; */
1.707 bisitz 6808: }
1.795 www 6809:
1.707 bisitz 6810: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6811: border-right: 8px solid #FFFF77;
1.707 bisitz 6812: }
1.795 www 6813:
1.707 bisitz 6814: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6815: border-right: 8px solid #FFAA77;
1.707 bisitz 6816: }
1.795 www 6817:
1.707 bisitz 6818: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6819: border-right: 8px solid #FF7777;
1.707 bisitz 6820: }
1.795 www 6821:
1.707 bisitz 6822: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6823: border-right: 8px solid #AAFF77;
1.707 bisitz 6824: }
1.795 www 6825:
1.707 bisitz 6826: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6827: border-right: 8px solid #11CC55;
1.707 bisitz 6828: }
6829:
1.388 albertel 6830: span.LC_current_location {
1.701 harmsja 6831: font-size:larger;
1.388 albertel 6832: background: $pgbg;
6833: }
1.387 albertel 6834:
1.1029 www 6835: span.LC_current_nav_location {
6836: font-weight:bold;
6837: background: $sidebg;
6838: }
6839:
1.395 albertel 6840: span.LC_parm_menu_item {
6841: font-size: larger;
6842: }
1.795 www 6843:
1.395 albertel 6844: span.LC_parm_scope_all {
6845: color: red;
6846: }
1.795 www 6847:
1.395 albertel 6848: span.LC_parm_scope_folder {
6849: color: green;
6850: }
1.795 www 6851:
1.395 albertel 6852: span.LC_parm_scope_resource {
6853: color: orange;
6854: }
1.795 www 6855:
1.395 albertel 6856: span.LC_parm_part {
6857: color: blue;
6858: }
1.795 www 6859:
1.911 bisitz 6860: span.LC_parm_folder,
6861: span.LC_parm_symb {
1.395 albertel 6862: font-size: x-small;
6863: font-family: $mono;
6864: color: #AAAAAA;
6865: }
6866:
1.977 bisitz 6867: ul.LC_parm_parmlist li {
6868: display: inline-block;
6869: padding: 0.3em 0.8em;
6870: vertical-align: top;
6871: width: 150px;
6872: border-top:1px solid $lg_border_color;
6873: }
6874:
1.795 www 6875: td.LC_parm_overview_level_menu,
6876: td.LC_parm_overview_map_menu,
6877: td.LC_parm_overview_parm_selectors,
6878: td.LC_parm_overview_restrictions {
1.396 albertel 6879: border: 1px solid black;
6880: border-collapse: collapse;
6881: }
1.795 www 6882:
1.1285 raeburn 6883: span.LC_parm_recursive,
6884: td.LC_parm_recursive {
6885: font-weight: bold;
6886: font-size: smaller;
6887: }
6888:
1.396 albertel 6889: table.LC_parm_overview_restrictions td {
6890: border-width: 1px 4px 1px 4px;
6891: border-style: solid;
6892: border-color: $pgbg;
6893: text-align: center;
6894: }
1.795 www 6895:
1.396 albertel 6896: table.LC_parm_overview_restrictions th {
6897: background: $tabbg;
6898: border-width: 1px 4px 1px 4px;
6899: border-style: solid;
6900: border-color: $pgbg;
6901: }
1.795 www 6902:
1.398 albertel 6903: table#LC_helpmenu {
1.803 bisitz 6904: border: none;
1.398 albertel 6905: height: 55px;
1.803 bisitz 6906: border-spacing: 0;
1.398 albertel 6907: }
6908:
6909: table#LC_helpmenu fieldset legend {
6910: font-size: larger;
6911: }
1.795 www 6912:
1.397 albertel 6913: table#LC_helpmenu_links {
6914: width: 100%;
6915: border: 1px solid black;
6916: background: $pgbg;
1.803 bisitz 6917: padding: 0;
1.397 albertel 6918: border-spacing: 1px;
6919: }
1.795 www 6920:
1.397 albertel 6921: table#LC_helpmenu_links tr td {
6922: padding: 1px;
6923: background: $tabbg;
1.399 albertel 6924: text-align: center;
6925: font-weight: bold;
1.397 albertel 6926: }
1.396 albertel 6927:
1.795 www 6928: table#LC_helpmenu_links a:link,
6929: table#LC_helpmenu_links a:visited,
1.397 albertel 6930: table#LC_helpmenu_links a:active {
6931: text-decoration: none;
6932: color: $font;
6933: }
1.795 www 6934:
1.397 albertel 6935: table#LC_helpmenu_links a:hover {
6936: text-decoration: underline;
6937: color: $vlink;
6938: }
1.396 albertel 6939:
1.417 albertel 6940: .LC_chrt_popup_exists {
6941: border: 1px solid #339933;
6942: margin: -1px;
6943: }
1.795 www 6944:
1.417 albertel 6945: .LC_chrt_popup_up {
6946: border: 1px solid yellow;
6947: margin: -1px;
6948: }
1.795 www 6949:
1.417 albertel 6950: .LC_chrt_popup {
6951: border: 1px solid #8888FF;
6952: background: #CCCCFF;
6953: }
1.795 www 6954:
1.421 albertel 6955: table.LC_pick_box {
6956: border-collapse: separate;
6957: background: white;
6958: border: 1px solid black;
6959: border-spacing: 1px;
6960: }
1.795 www 6961:
1.421 albertel 6962: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6963: background: $sidebg;
1.421 albertel 6964: font-weight: bold;
1.900 bisitz 6965: text-align: left;
1.740 bisitz 6966: vertical-align: top;
1.421 albertel 6967: width: 184px;
6968: padding: 8px;
6969: }
1.795 www 6970:
1.579 raeburn 6971: table.LC_pick_box td.LC_pick_box_value {
6972: text-align: left;
6973: padding: 8px;
6974: }
1.795 www 6975:
1.579 raeburn 6976: table.LC_pick_box td.LC_pick_box_select {
6977: text-align: left;
6978: padding: 8px;
6979: }
1.795 www 6980:
1.424 albertel 6981: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6982: padding: 0;
1.421 albertel 6983: height: 1px;
6984: background: black;
6985: }
1.795 www 6986:
1.421 albertel 6987: table.LC_pick_box td.LC_pick_box_submit {
6988: text-align: right;
6989: }
1.795 www 6990:
1.579 raeburn 6991: table.LC_pick_box td.LC_evenrow_value {
6992: text-align: left;
6993: padding: 8px;
6994: background-color: $data_table_light;
6995: }
1.795 www 6996:
1.579 raeburn 6997: table.LC_pick_box td.LC_oddrow_value {
6998: text-align: left;
6999: padding: 8px;
7000: background-color: $data_table_light;
7001: }
1.795 www 7002:
1.579 raeburn 7003: span.LC_helpform_receipt_cat {
7004: font-weight: bold;
7005: }
1.795 www 7006:
1.424 albertel 7007: table.LC_group_priv_box {
7008: background: white;
7009: border: 1px solid black;
7010: border-spacing: 1px;
7011: }
1.795 www 7012:
1.424 albertel 7013: table.LC_group_priv_box td.LC_pick_box_title {
7014: background: $tabbg;
7015: font-weight: bold;
7016: text-align: right;
7017: width: 184px;
7018: }
1.795 www 7019:
1.424 albertel 7020: table.LC_group_priv_box td.LC_groups_fixed {
7021: background: $data_table_light;
7022: text-align: center;
7023: }
1.795 www 7024:
1.424 albertel 7025: table.LC_group_priv_box td.LC_groups_optional {
7026: background: $data_table_dark;
7027: text-align: center;
7028: }
1.795 www 7029:
1.424 albertel 7030: table.LC_group_priv_box td.LC_groups_functionality {
7031: background: $data_table_darker;
7032: text-align: center;
7033: font-weight: bold;
7034: }
1.795 www 7035:
1.424 albertel 7036: table.LC_group_priv td {
7037: text-align: left;
1.803 bisitz 7038: padding: 0;
1.424 albertel 7039: }
7040:
7041: .LC_navbuttons {
7042: margin: 2ex 0ex 2ex 0ex;
7043: }
1.795 www 7044:
1.423 albertel 7045: .LC_topic_bar {
7046: font-weight: bold;
7047: background: $tabbg;
1.918 wenzelju 7048: margin: 1em 0em 1em 2em;
1.805 bisitz 7049: padding: 3px;
1.918 wenzelju 7050: font-size: 1.2em;
1.423 albertel 7051: }
1.795 www 7052:
1.423 albertel 7053: .LC_topic_bar span {
1.918 wenzelju 7054: left: 0.5em;
7055: position: absolute;
1.423 albertel 7056: vertical-align: middle;
1.918 wenzelju 7057: font-size: 1.2em;
1.423 albertel 7058: }
1.795 www 7059:
1.423 albertel 7060: table.LC_course_group_status {
7061: margin: 20px;
7062: }
1.795 www 7063:
1.423 albertel 7064: table.LC_status_selector td {
7065: vertical-align: top;
7066: text-align: center;
1.424 albertel 7067: padding: 4px;
7068: }
1.795 www 7069:
1.599 albertel 7070: div.LC_feedback_link {
1.616 albertel 7071: clear: both;
1.829 kalberla 7072: background: $sidebg;
1.779 bisitz 7073: width: 100%;
1.829 kalberla 7074: padding-bottom: 10px;
7075: border: 1px $tabbg solid;
1.833 kalberla 7076: height: 22px;
7077: line-height: 22px;
7078: padding-top: 5px;
7079: }
7080:
7081: div.LC_feedback_link img {
7082: height: 22px;
1.867 kalberla 7083: vertical-align:middle;
1.829 kalberla 7084: }
7085:
1.911 bisitz 7086: div.LC_feedback_link a {
1.829 kalberla 7087: text-decoration: none;
1.489 raeburn 7088: }
1.795 www 7089:
1.867 kalberla 7090: div.LC_comblock {
1.911 bisitz 7091: display:inline;
1.867 kalberla 7092: color:$font;
7093: font-size:90%;
7094: }
7095:
7096: div.LC_feedback_link div.LC_comblock {
7097: padding-left:5px;
7098: }
7099:
7100: div.LC_feedback_link div.LC_comblock a {
7101: color:$font;
7102: }
7103:
1.489 raeburn 7104: span.LC_feedback_link {
1.858 bisitz 7105: /* background: $feedback_link_bg; */
1.599 albertel 7106: font-size: larger;
7107: }
1.795 www 7108:
1.599 albertel 7109: span.LC_message_link {
1.858 bisitz 7110: /* background: $feedback_link_bg; */
1.599 albertel 7111: font-size: larger;
7112: position: absolute;
7113: right: 1em;
1.489 raeburn 7114: }
1.421 albertel 7115:
1.515 albertel 7116: table.LC_prior_tries {
1.524 albertel 7117: border: 1px solid #000000;
7118: border-collapse: separate;
7119: border-spacing: 1px;
1.515 albertel 7120: }
1.523 albertel 7121:
1.515 albertel 7122: table.LC_prior_tries td {
1.524 albertel 7123: padding: 2px;
1.515 albertel 7124: }
1.523 albertel 7125:
7126: .LC_answer_correct {
1.795 www 7127: background: lightgreen;
7128: color: darkgreen;
7129: padding: 6px;
1.523 albertel 7130: }
1.795 www 7131:
1.523 albertel 7132: .LC_answer_charged_try {
1.797 www 7133: background: #FFAAAA;
1.795 www 7134: color: darkred;
7135: padding: 6px;
1.523 albertel 7136: }
1.795 www 7137:
1.779 bisitz 7138: .LC_answer_not_charged_try,
1.523 albertel 7139: .LC_answer_no_grade,
7140: .LC_answer_late {
1.795 www 7141: background: lightyellow;
1.523 albertel 7142: color: black;
1.795 www 7143: padding: 6px;
1.523 albertel 7144: }
1.795 www 7145:
1.523 albertel 7146: .LC_answer_previous {
1.795 www 7147: background: lightblue;
7148: color: darkblue;
7149: padding: 6px;
1.523 albertel 7150: }
1.795 www 7151:
1.779 bisitz 7152: .LC_answer_no_message {
1.777 tempelho 7153: background: #FFFFFF;
7154: color: black;
1.795 www 7155: padding: 6px;
1.779 bisitz 7156: }
1.795 www 7157:
1.779 bisitz 7158: .LC_answer_unknown {
7159: background: orange;
7160: color: black;
1.795 www 7161: padding: 6px;
1.777 tempelho 7162: }
1.795 www 7163:
1.529 albertel 7164: span.LC_prior_numerical,
7165: span.LC_prior_string,
7166: span.LC_prior_custom,
7167: span.LC_prior_reaction,
7168: span.LC_prior_math {
1.925 bisitz 7169: font-family: $mono;
1.523 albertel 7170: white-space: pre;
7171: }
7172:
1.525 albertel 7173: span.LC_prior_string {
1.925 bisitz 7174: font-family: $mono;
1.525 albertel 7175: white-space: pre;
7176: }
7177:
1.523 albertel 7178: table.LC_prior_option {
7179: width: 100%;
7180: border-collapse: collapse;
7181: }
1.795 www 7182:
1.911 bisitz 7183: table.LC_prior_rank,
1.795 www 7184: table.LC_prior_match {
1.528 albertel 7185: border-collapse: collapse;
7186: }
1.795 www 7187:
1.528 albertel 7188: table.LC_prior_option tr td,
7189: table.LC_prior_rank tr td,
7190: table.LC_prior_match tr td {
1.524 albertel 7191: border: 1px solid #000000;
1.515 albertel 7192: }
7193:
1.855 bisitz 7194: .LC_nobreak {
1.544 albertel 7195: white-space: nowrap;
1.519 raeburn 7196: }
7197:
1.576 raeburn 7198: span.LC_cusr_emph {
7199: font-style: italic;
7200: }
7201:
1.633 raeburn 7202: span.LC_cusr_subheading {
7203: font-weight: normal;
7204: font-size: 85%;
7205: }
7206:
1.861 bisitz 7207: div.LC_docs_entry_move {
1.859 bisitz 7208: border: 1px solid #BBBBBB;
1.545 albertel 7209: background: #DDDDDD;
1.861 bisitz 7210: width: 22px;
1.859 bisitz 7211: padding: 1px;
7212: margin: 0;
1.545 albertel 7213: }
7214:
1.861 bisitz 7215: table.LC_data_table tr > td.LC_docs_entry_commands,
7216: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7217: font-size: x-small;
7218: }
1.795 www 7219:
1.861 bisitz 7220: .LC_docs_entry_parameter {
7221: white-space: nowrap;
7222: }
7223:
1.544 albertel 7224: .LC_docs_copy {
1.545 albertel 7225: color: #000099;
1.544 albertel 7226: }
1.795 www 7227:
1.544 albertel 7228: .LC_docs_cut {
1.545 albertel 7229: color: #550044;
1.544 albertel 7230: }
1.795 www 7231:
1.544 albertel 7232: .LC_docs_rename {
1.545 albertel 7233: color: #009900;
1.544 albertel 7234: }
1.795 www 7235:
1.544 albertel 7236: .LC_docs_remove {
1.545 albertel 7237: color: #990000;
7238: }
7239:
1.1284 raeburn 7240: .LC_docs_alias {
7241: color: #440055;
7242: }
7243:
1.1286 raeburn 7244: .LC_domprefs_email,
1.1284 raeburn 7245: .LC_docs_alias_name,
1.547 albertel 7246: .LC_docs_reinit_warn,
7247: .LC_docs_ext_edit {
7248: font-size: x-small;
7249: }
7250:
1.545 albertel 7251: table.LC_docs_adddocs td,
7252: table.LC_docs_adddocs th {
7253: border: 1px solid #BBBBBB;
7254: padding: 4px;
7255: background: #DDDDDD;
1.543 albertel 7256: }
7257:
1.584 albertel 7258: table.LC_sty_begin {
7259: background: #BBFFBB;
7260: }
1.795 www 7261:
1.584 albertel 7262: table.LC_sty_end {
7263: background: #FFBBBB;
7264: }
7265:
1.589 raeburn 7266: table.LC_double_column {
1.803 bisitz 7267: border-width: 0;
1.589 raeburn 7268: border-collapse: collapse;
7269: width: 100%;
7270: padding: 2px;
7271: }
7272:
7273: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7274: top: 2px;
1.589 raeburn 7275: left: 2px;
7276: width: 47%;
7277: vertical-align: top;
7278: }
7279:
7280: table.LC_double_column tr td.LC_right_col {
7281: top: 2px;
1.779 bisitz 7282: right: 2px;
1.589 raeburn 7283: width: 47%;
7284: vertical-align: top;
7285: }
7286:
1.591 raeburn 7287: div.LC_left_float {
7288: float: left;
7289: padding-right: 5%;
1.597 albertel 7290: padding-bottom: 4px;
1.591 raeburn 7291: }
7292:
7293: div.LC_clear_float_header {
1.597 albertel 7294: padding-bottom: 2px;
1.591 raeburn 7295: }
7296:
7297: div.LC_clear_float_footer {
1.597 albertel 7298: padding-top: 10px;
1.591 raeburn 7299: clear: both;
7300: }
7301:
1.597 albertel 7302: div.LC_grade_show_user {
1.941 bisitz 7303: /* border-left: 5px solid $sidebg; */
7304: border-top: 5px solid #000000;
7305: margin: 50px 0 0 0;
1.936 bisitz 7306: padding: 15px 0 5px 10px;
1.597 albertel 7307: }
1.795 www 7308:
1.936 bisitz 7309: div.LC_grade_show_user_odd_row {
1.941 bisitz 7310: /* border-left: 5px solid #000000; */
7311: }
7312:
7313: div.LC_grade_show_user div.LC_Box {
7314: margin-right: 50px;
1.597 albertel 7315: }
7316:
7317: div.LC_grade_submissions,
7318: div.LC_grade_message_center,
1.936 bisitz 7319: div.LC_grade_info_links {
1.597 albertel 7320: margin: 5px;
7321: width: 99%;
7322: background: #FFFFFF;
7323: }
1.795 www 7324:
1.597 albertel 7325: div.LC_grade_submissions_header,
1.936 bisitz 7326: div.LC_grade_message_center_header {
1.705 tempelho 7327: font-weight: bold;
7328: font-size: large;
1.597 albertel 7329: }
1.795 www 7330:
1.597 albertel 7331: div.LC_grade_submissions_body,
1.936 bisitz 7332: div.LC_grade_message_center_body {
1.597 albertel 7333: border: 1px solid black;
7334: width: 99%;
7335: background: #FFFFFF;
7336: }
1.795 www 7337:
1.613 albertel 7338: table.LC_scantron_action {
7339: width: 100%;
7340: }
1.795 www 7341:
1.613 albertel 7342: table.LC_scantron_action tr th {
1.698 harmsja 7343: font-weight:bold;
7344: font-style:normal;
1.613 albertel 7345: }
1.795 www 7346:
1.779 bisitz 7347: .LC_edit_problem_header,
1.614 albertel 7348: div.LC_edit_problem_footer {
1.705 tempelho 7349: font-weight: normal;
7350: font-size: medium;
1.602 albertel 7351: margin: 2px;
1.1060 bisitz 7352: background-color: $sidebg;
1.600 albertel 7353: }
1.795 www 7354:
1.600 albertel 7355: div.LC_edit_problem_header,
1.602 albertel 7356: div.LC_edit_problem_header div,
1.614 albertel 7357: div.LC_edit_problem_footer,
7358: div.LC_edit_problem_footer div,
1.602 albertel 7359: div.LC_edit_problem_editxml_header,
7360: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7361: z-index: 100;
1.600 albertel 7362: }
1.795 www 7363:
1.600 albertel 7364: div.LC_edit_problem_header_title {
1.705 tempelho 7365: font-weight: bold;
7366: font-size: larger;
1.602 albertel 7367: background: $tabbg;
7368: padding: 3px;
1.1060 bisitz 7369: margin: 0 0 5px 0;
1.602 albertel 7370: }
1.795 www 7371:
1.602 albertel 7372: table.LC_edit_problem_header_title {
7373: width: 100%;
1.600 albertel 7374: background: $tabbg;
1.602 albertel 7375: }
7376:
1.1205 golterma 7377: div.LC_edit_actionbar {
7378: background-color: $sidebg;
1.1218 droeschl 7379: margin: 0;
7380: padding: 0;
7381: line-height: 200%;
1.602 albertel 7382: }
1.795 www 7383:
1.1218 droeschl 7384: div.LC_edit_actionbar div{
7385: padding: 0;
7386: margin: 0;
7387: display: inline-block;
1.600 albertel 7388: }
1.795 www 7389:
1.1124 bisitz 7390: .LC_edit_opt {
7391: padding-left: 1em;
7392: white-space: nowrap;
7393: }
7394:
1.1152 golterma 7395: .LC_edit_problem_latexhelper{
7396: text-align: right;
7397: }
7398:
7399: #LC_edit_problem_colorful div{
7400: margin-left: 40px;
7401: }
7402:
1.1205 golterma 7403: #LC_edit_problem_codemirror div{
7404: margin-left: 0px;
7405: }
7406:
1.911 bisitz 7407: img.stift {
1.803 bisitz 7408: border-width: 0;
7409: vertical-align: middle;
1.677 riegler 7410: }
1.680 riegler 7411:
1.923 bisitz 7412: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7413: vertical-align: top;
1.777 tempelho 7414: }
1.795 www 7415:
1.716 raeburn 7416: div.LC_createcourse {
1.911 bisitz 7417: margin: 10px 10px 10px 10px;
1.716 raeburn 7418: }
7419:
1.917 raeburn 7420: .LC_dccid {
1.1130 raeburn 7421: float: right;
1.917 raeburn 7422: margin: 0.2em 0 0 0;
7423: padding: 0;
7424: font-size: 90%;
7425: display:none;
7426: }
7427:
1.897 wenzelju 7428: ol.LC_primary_menu a:hover,
1.721 harmsja 7429: ol#LC_MenuBreadcrumbs a:hover,
7430: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7431: ul#LC_secondary_menu a:hover,
1.721 harmsja 7432: .LC_FormSectionClearButton input:hover
1.795 www 7433: ul.LC_TabContent li:hover a {
1.952 onken 7434: color:$button_hover;
1.911 bisitz 7435: text-decoration:none;
1.693 droeschl 7436: }
7437:
1.779 bisitz 7438: h1 {
1.911 bisitz 7439: padding: 0;
7440: line-height:130%;
1.693 droeschl 7441: }
1.698 harmsja 7442:
1.911 bisitz 7443: h2,
7444: h3,
7445: h4,
7446: h5,
7447: h6 {
7448: margin: 5px 0 5px 0;
7449: padding: 0;
7450: line-height:130%;
1.693 droeschl 7451: }
1.795 www 7452:
7453: .LC_hcell {
1.911 bisitz 7454: padding:3px 15px 3px 15px;
7455: margin: 0;
7456: background-color:$tabbg;
7457: color:$fontmenu;
7458: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7459: }
1.795 www 7460:
1.840 bisitz 7461: .LC_Box > .LC_hcell {
1.911 bisitz 7462: margin: 0 -10px 10px -10px;
1.835 bisitz 7463: }
7464:
1.721 harmsja 7465: .LC_noBorder {
1.911 bisitz 7466: border: 0;
1.698 harmsja 7467: }
1.693 droeschl 7468:
1.721 harmsja 7469: .LC_FormSectionClearButton input {
1.911 bisitz 7470: background-color:transparent;
7471: border: none;
7472: cursor:pointer;
7473: text-decoration:underline;
1.693 droeschl 7474: }
1.763 bisitz 7475:
7476: .LC_help_open_topic {
1.911 bisitz 7477: color: #FFFFFF;
7478: background-color: #EEEEFF;
7479: margin: 1px;
7480: padding: 4px;
7481: border: 1px solid #000033;
7482: white-space: nowrap;
7483: /* vertical-align: middle; */
1.759 neumanie 7484: }
1.693 droeschl 7485:
1.911 bisitz 7486: dl,
7487: ul,
7488: div,
7489: fieldset {
7490: margin: 10px 10px 10px 0;
7491: /* overflow: hidden; */
1.693 droeschl 7492: }
1.795 www 7493:
1.1211 raeburn 7494: article.geogebraweb div {
7495: margin: 0;
7496: }
7497:
1.838 bisitz 7498: fieldset > legend {
1.911 bisitz 7499: font-weight: bold;
7500: padding: 0 5px 0 5px;
1.838 bisitz 7501: }
7502:
1.813 bisitz 7503: #LC_nav_bar {
1.911 bisitz 7504: float: left;
1.995 raeburn 7505: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7506: margin: 0 0 2px 0;
1.807 droeschl 7507: }
7508:
1.916 droeschl 7509: #LC_realm {
7510: margin: 0.2em 0 0 0;
7511: padding: 0;
7512: font-weight: bold;
7513: text-align: center;
1.995 raeburn 7514: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7515: }
7516:
1.911 bisitz 7517: #LC_nav_bar em {
7518: font-weight: bold;
7519: font-style: normal;
1.807 droeschl 7520: }
7521:
1.897 wenzelju 7522: ol.LC_primary_menu {
1.934 droeschl 7523: margin: 0;
1.1076 raeburn 7524: padding: 0;
1.807 droeschl 7525: }
7526:
1.852 droeschl 7527: ol#LC_PathBreadcrumbs {
1.911 bisitz 7528: margin: 0;
1.693 droeschl 7529: }
7530:
1.897 wenzelju 7531: ol.LC_primary_menu li {
1.1076 raeburn 7532: color: RGB(80, 80, 80);
7533: vertical-align: middle;
7534: text-align: left;
7535: list-style: none;
1.1205 golterma 7536: position: relative;
1.1076 raeburn 7537: float: left;
1.1205 golterma 7538: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7539: line-height: 1.5em;
1.1076 raeburn 7540: }
7541:
1.1205 golterma 7542: ol.LC_primary_menu li a,
7543: ol.LC_primary_menu li p {
1.1076 raeburn 7544: display: block;
7545: margin: 0;
7546: padding: 0 5px 0 10px;
7547: text-decoration: none;
7548: }
7549:
1.1205 golterma 7550: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7551: display: inline-block;
7552: width: 95%;
7553: text-align: left;
7554: }
7555:
7556: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7557: display: inline-block;
7558: width: 5%;
7559: float: right;
7560: text-align: right;
7561: font-size: 70%;
7562: }
7563:
7564: ol.LC_primary_menu ul {
1.1076 raeburn 7565: display: none;
1.1205 golterma 7566: width: 15em;
1.1076 raeburn 7567: background-color: $data_table_light;
1.1205 golterma 7568: position: absolute;
7569: top: 100%;
1.1076 raeburn 7570: }
7571:
1.1205 golterma 7572: ol.LC_primary_menu ul ul {
7573: left: 100%;
7574: top: 0;
7575: }
7576:
7577: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7578: display: block;
7579: position: absolute;
7580: margin: 0;
7581: padding: 0;
1.1078 raeburn 7582: z-index: 2;
1.1076 raeburn 7583: }
7584:
7585: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7586: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7587: font-size: 90%;
1.911 bisitz 7588: vertical-align: top;
1.1076 raeburn 7589: float: none;
1.1079 raeburn 7590: border-left: 1px solid black;
7591: border-right: 1px solid black;
1.1205 golterma 7592: /* A dark bottom border to visualize different menu options;
7593: overwritten in the create_submenu routine for the last border-bottom of the menu */
7594: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7595: }
7596:
1.1205 golterma 7597: ol.LC_primary_menu li li p:hover {
7598: color:$button_hover;
7599: text-decoration:none;
7600: background-color:$data_table_dark;
1.1076 raeburn 7601: }
7602:
7603: ol.LC_primary_menu li li a:hover {
7604: color:$button_hover;
7605: background-color:$data_table_dark;
1.693 droeschl 7606: }
7607:
1.1205 golterma 7608: /* Font-size equal to the size of the predecessors*/
7609: ol.LC_primary_menu li:hover li li {
7610: font-size: 100%;
7611: }
7612:
1.897 wenzelju 7613: ol.LC_primary_menu li img {
1.911 bisitz 7614: vertical-align: bottom;
1.934 droeschl 7615: height: 1.1em;
1.1077 raeburn 7616: margin: 0.2em 0 0 0;
1.693 droeschl 7617: }
7618:
1.897 wenzelju 7619: ol.LC_primary_menu a {
1.911 bisitz 7620: color: RGB(80, 80, 80);
7621: text-decoration: none;
1.693 droeschl 7622: }
1.795 www 7623:
1.949 droeschl 7624: ol.LC_primary_menu a.LC_new_message {
7625: font-weight:bold;
7626: color: darkred;
7627: }
7628:
1.975 raeburn 7629: ol.LC_docs_parameters {
7630: margin-left: 0;
7631: padding: 0;
7632: list-style: none;
7633: }
7634:
7635: ol.LC_docs_parameters li {
7636: margin: 0;
7637: padding-right: 20px;
7638: display: inline;
7639: }
7640:
1.976 raeburn 7641: ol.LC_docs_parameters li:before {
7642: content: "\\002022 \\0020";
7643: }
7644:
7645: li.LC_docs_parameters_title {
7646: font-weight: bold;
7647: }
7648:
7649: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7650: content: "";
7651: }
7652:
1.897 wenzelju 7653: ul#LC_secondary_menu {
1.1107 raeburn 7654: clear: right;
1.911 bisitz 7655: color: $fontmenu;
7656: background: $tabbg;
7657: list-style: none;
7658: padding: 0;
7659: margin: 0;
7660: width: 100%;
1.995 raeburn 7661: text-align: left;
1.1107 raeburn 7662: float: left;
1.808 droeschl 7663: }
7664:
1.897 wenzelju 7665: ul#LC_secondary_menu li {
1.911 bisitz 7666: font-weight: bold;
7667: line-height: 1.8em;
1.1107 raeburn 7668: border-right: 1px solid black;
7669: float: left;
7670: }
7671:
7672: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7673: background-color: $data_table_light;
7674: }
7675:
7676: ul#LC_secondary_menu li a {
1.911 bisitz 7677: padding: 0 0.8em;
1.1107 raeburn 7678: }
7679:
7680: ul#LC_secondary_menu li ul {
7681: display: none;
7682: }
7683:
7684: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7685: display: block;
7686: position: absolute;
7687: margin: 0;
7688: padding: 0;
7689: list-style:none;
7690: float: none;
7691: background-color: $data_table_light;
7692: z-index: 2;
7693: margin-left: -1px;
7694: }
7695:
7696: ul#LC_secondary_menu li ul li {
7697: font-size: 90%;
7698: vertical-align: top;
7699: border-left: 1px solid black;
1.911 bisitz 7700: border-right: 1px solid black;
1.1119 raeburn 7701: background-color: $data_table_light;
1.1107 raeburn 7702: list-style:none;
7703: float: none;
7704: }
7705:
7706: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7707: background-color: $data_table_dark;
1.807 droeschl 7708: }
7709:
1.847 tempelho 7710: ul.LC_TabContent {
1.911 bisitz 7711: display:block;
7712: background: $sidebg;
7713: border-bottom: solid 1px $lg_border_color;
7714: list-style:none;
1.1020 raeburn 7715: margin: -1px -10px 0 -10px;
1.911 bisitz 7716: padding: 0;
1.693 droeschl 7717: }
7718:
1.795 www 7719: ul.LC_TabContent li,
7720: ul.LC_TabContentBigger li {
1.911 bisitz 7721: float:left;
1.741 harmsja 7722: }
1.795 www 7723:
1.897 wenzelju 7724: ul#LC_secondary_menu li a {
1.911 bisitz 7725: color: $fontmenu;
7726: text-decoration: none;
1.693 droeschl 7727: }
1.795 www 7728:
1.721 harmsja 7729: ul.LC_TabContent {
1.952 onken 7730: min-height:20px;
1.721 harmsja 7731: }
1.795 www 7732:
7733: ul.LC_TabContent li {
1.911 bisitz 7734: vertical-align:middle;
1.959 onken 7735: padding: 0 16px 0 10px;
1.911 bisitz 7736: background-color:$tabbg;
7737: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7738: border-left: solid 1px $font;
1.721 harmsja 7739: }
1.795 www 7740:
1.847 tempelho 7741: ul.LC_TabContent .right {
1.911 bisitz 7742: float:right;
1.847 tempelho 7743: }
7744:
1.911 bisitz 7745: ul.LC_TabContent li a,
7746: ul.LC_TabContent li {
7747: color:rgb(47,47,47);
7748: text-decoration:none;
7749: font-size:95%;
7750: font-weight:bold;
1.952 onken 7751: min-height:20px;
7752: }
7753:
1.959 onken 7754: ul.LC_TabContent li a:hover,
7755: ul.LC_TabContent li a:focus {
1.952 onken 7756: color: $button_hover;
1.959 onken 7757: background:none;
7758: outline:none;
1.952 onken 7759: }
7760:
7761: ul.LC_TabContent li:hover {
7762: color: $button_hover;
7763: cursor:pointer;
1.721 harmsja 7764: }
1.795 www 7765:
1.911 bisitz 7766: ul.LC_TabContent li.active {
1.952 onken 7767: color: $font;
1.911 bisitz 7768: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7769: border-bottom:solid 1px #FFFFFF;
7770: cursor: default;
1.744 ehlerst 7771: }
1.795 www 7772:
1.959 onken 7773: ul.LC_TabContent li.active a {
7774: color:$font;
7775: background:#FFFFFF;
7776: outline: none;
7777: }
1.1047 raeburn 7778:
7779: ul.LC_TabContent li.goback {
7780: float: left;
7781: border-left: none;
7782: }
7783:
1.870 tempelho 7784: #maincoursedoc {
1.911 bisitz 7785: clear:both;
1.870 tempelho 7786: }
7787:
7788: ul.LC_TabContentBigger {
1.911 bisitz 7789: display:block;
7790: list-style:none;
7791: padding: 0;
1.870 tempelho 7792: }
7793:
1.795 www 7794: ul.LC_TabContentBigger li {
1.911 bisitz 7795: vertical-align:bottom;
7796: height: 30px;
7797: font-size:110%;
7798: font-weight:bold;
7799: color: #737373;
1.841 tempelho 7800: }
7801:
1.957 onken 7802: ul.LC_TabContentBigger li.active {
7803: position: relative;
7804: top: 1px;
7805: }
7806:
1.870 tempelho 7807: ul.LC_TabContentBigger li a {
1.911 bisitz 7808: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7809: height: 30px;
7810: line-height: 30px;
7811: text-align: center;
7812: display: block;
7813: text-decoration: none;
1.958 onken 7814: outline: none;
1.741 harmsja 7815: }
1.795 www 7816:
1.870 tempelho 7817: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7818: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7819: color:$font;
1.744 ehlerst 7820: }
1.795 www 7821:
1.870 tempelho 7822: ul.LC_TabContentBigger li b {
1.911 bisitz 7823: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7824: display: block;
7825: float: left;
7826: padding: 0 30px;
1.957 onken 7827: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7828: }
7829:
1.956 onken 7830: ul.LC_TabContentBigger li:hover b {
7831: color:$button_hover;
7832: }
7833:
1.870 tempelho 7834: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7835: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7836: color:$font;
1.957 onken 7837: border: 0;
1.741 harmsja 7838: }
1.693 droeschl 7839:
1.870 tempelho 7840:
1.862 bisitz 7841: ul.LC_CourseBreadcrumbs {
7842: background: $sidebg;
1.1020 raeburn 7843: height: 2em;
1.862 bisitz 7844: padding-left: 10px;
1.1020 raeburn 7845: margin: 0;
1.862 bisitz 7846: list-style-position: inside;
7847: }
7848:
1.911 bisitz 7849: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7850: ol#LC_PathBreadcrumbs {
1.911 bisitz 7851: padding-left: 10px;
7852: margin: 0;
1.933 droeschl 7853: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7854: }
7855:
1.911 bisitz 7856: ol#LC_MenuBreadcrumbs li,
7857: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7858: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7859: display: inline;
1.933 droeschl 7860: white-space: normal;
1.693 droeschl 7861: }
7862:
1.823 bisitz 7863: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7864: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7865: text-decoration: none;
7866: font-size:90%;
1.693 droeschl 7867: }
1.795 www 7868:
1.969 droeschl 7869: ol#LC_MenuBreadcrumbs h1 {
7870: display: inline;
7871: font-size: 90%;
7872: line-height: 2.5em;
7873: margin: 0;
7874: padding: 0;
7875: }
7876:
1.795 www 7877: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7878: text-decoration:none;
7879: font-size:100%;
7880: font-weight:bold;
1.693 droeschl 7881: }
1.795 www 7882:
1.840 bisitz 7883: .LC_Box {
1.911 bisitz 7884: border: solid 1px $lg_border_color;
7885: padding: 0 10px 10px 10px;
1.746 neumanie 7886: }
1.795 www 7887:
1.1020 raeburn 7888: .LC_DocsBox {
7889: border: solid 1px $lg_border_color;
7890: padding: 0 0 10px 10px;
7891: }
7892:
1.795 www 7893: .LC_AboutMe_Image {
1.911 bisitz 7894: float:left;
7895: margin-right:10px;
1.747 neumanie 7896: }
1.795 www 7897:
7898: .LC_Clear_AboutMe_Image {
1.911 bisitz 7899: clear:left;
1.747 neumanie 7900: }
1.795 www 7901:
1.721 harmsja 7902: dl.LC_ListStyleClean dt {
1.911 bisitz 7903: padding-right: 5px;
7904: display: table-header-group;
1.693 droeschl 7905: }
7906:
1.721 harmsja 7907: dl.LC_ListStyleClean dd {
1.911 bisitz 7908: display: table-row;
1.693 droeschl 7909: }
7910:
1.721 harmsja 7911: .LC_ListStyleClean,
7912: .LC_ListStyleSimple,
7913: .LC_ListStyleNormal,
1.795 www 7914: .LC_ListStyleSpecial {
1.911 bisitz 7915: /* display:block; */
7916: list-style-position: inside;
7917: list-style-type: none;
7918: overflow: hidden;
7919: padding: 0;
1.693 droeschl 7920: }
7921:
1.721 harmsja 7922: .LC_ListStyleSimple li,
7923: .LC_ListStyleSimple dd,
7924: .LC_ListStyleNormal li,
7925: .LC_ListStyleNormal dd,
7926: .LC_ListStyleSpecial li,
1.795 www 7927: .LC_ListStyleSpecial dd {
1.911 bisitz 7928: margin: 0;
7929: padding: 5px 5px 5px 10px;
7930: clear: both;
1.693 droeschl 7931: }
7932:
1.721 harmsja 7933: .LC_ListStyleClean li,
7934: .LC_ListStyleClean dd {
1.911 bisitz 7935: padding-top: 0;
7936: padding-bottom: 0;
1.693 droeschl 7937: }
7938:
1.721 harmsja 7939: .LC_ListStyleSimple dd,
1.795 www 7940: .LC_ListStyleSimple li {
1.911 bisitz 7941: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7942: }
7943:
1.721 harmsja 7944: .LC_ListStyleSpecial li,
7945: .LC_ListStyleSpecial dd {
1.911 bisitz 7946: list-style-type: none;
7947: background-color: RGB(220, 220, 220);
7948: margin-bottom: 4px;
1.693 droeschl 7949: }
7950:
1.721 harmsja 7951: table.LC_SimpleTable {
1.911 bisitz 7952: margin:5px;
7953: border:solid 1px $lg_border_color;
1.795 www 7954: }
1.693 droeschl 7955:
1.721 harmsja 7956: table.LC_SimpleTable tr {
1.911 bisitz 7957: padding: 0;
7958: border:solid 1px $lg_border_color;
1.693 droeschl 7959: }
1.795 www 7960:
7961: table.LC_SimpleTable thead {
1.911 bisitz 7962: background:rgb(220,220,220);
1.693 droeschl 7963: }
7964:
1.721 harmsja 7965: div.LC_columnSection {
1.911 bisitz 7966: display: block;
7967: clear: both;
7968: overflow: hidden;
7969: margin: 0;
1.693 droeschl 7970: }
7971:
1.721 harmsja 7972: div.LC_columnSection>* {
1.911 bisitz 7973: float: left;
7974: margin: 10px 20px 10px 0;
7975: overflow:hidden;
1.693 droeschl 7976: }
1.721 harmsja 7977:
1.795 www 7978: table em {
1.911 bisitz 7979: font-weight: bold;
7980: font-style: normal;
1.748 schulted 7981: }
1.795 www 7982:
1.779 bisitz 7983: table.LC_tableBrowseRes,
1.795 www 7984: table.LC_tableOfContent {
1.911 bisitz 7985: border:none;
7986: border-spacing: 1px;
7987: padding: 3px;
7988: background-color: #FFFFFF;
7989: font-size: 90%;
1.753 droeschl 7990: }
1.789 droeschl 7991:
1.911 bisitz 7992: table.LC_tableOfContent {
7993: border-collapse: collapse;
1.789 droeschl 7994: }
7995:
1.771 droeschl 7996: table.LC_tableBrowseRes a,
1.768 schulted 7997: table.LC_tableOfContent a {
1.911 bisitz 7998: background-color: transparent;
7999: text-decoration: none;
1.753 droeschl 8000: }
8001:
1.795 www 8002: table.LC_tableOfContent img {
1.911 bisitz 8003: border: none;
8004: height: 1.3em;
8005: vertical-align: text-bottom;
8006: margin-right: 0.3em;
1.753 droeschl 8007: }
1.757 schulted 8008:
1.795 www 8009: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8010: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8011: }
8012:
1.795 www 8013: a#LC_content_toolbar_everything {
1.911 bisitz 8014: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8015: }
8016:
1.795 www 8017: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8018: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8019: }
8020:
1.795 www 8021: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8022: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8023: }
8024:
1.795 www 8025: a#LC_content_toolbar_changefolder {
1.911 bisitz 8026: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8027: }
8028:
1.795 www 8029: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8030: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8031: }
8032:
1.1043 raeburn 8033: a#LC_content_toolbar_edittoplevel {
8034: background-image:url(/res/adm/pages/edittoplevel.gif);
8035: }
8036:
1.795 www 8037: ul#LC_toolbar li a:hover {
1.911 bisitz 8038: background-position: bottom center;
1.757 schulted 8039: }
8040:
1.795 www 8041: ul#LC_toolbar {
1.911 bisitz 8042: padding: 0;
8043: margin: 2px;
8044: list-style:none;
8045: position:relative;
8046: background-color:white;
1.1082 raeburn 8047: overflow: auto;
1.757 schulted 8048: }
8049:
1.795 www 8050: ul#LC_toolbar li {
1.911 bisitz 8051: border:1px solid white;
8052: padding: 0;
8053: margin: 0;
8054: float: left;
8055: display:inline;
8056: vertical-align:middle;
1.1082 raeburn 8057: white-space: nowrap;
1.911 bisitz 8058: }
1.757 schulted 8059:
1.783 amueller 8060:
1.795 www 8061: a.LC_toolbarItem {
1.911 bisitz 8062: display:block;
8063: padding: 0;
8064: margin: 0;
8065: height: 32px;
8066: width: 32px;
8067: color:white;
8068: border: none;
8069: background-repeat:no-repeat;
8070: background-color:transparent;
1.757 schulted 8071: }
8072:
1.915 droeschl 8073: ul.LC_funclist {
8074: margin: 0;
8075: padding: 0.5em 1em 0.5em 0;
8076: }
8077:
1.933 droeschl 8078: ul.LC_funclist > li:first-child {
8079: font-weight:bold;
8080: margin-left:0.8em;
8081: }
8082:
1.915 droeschl 8083: ul.LC_funclist + ul.LC_funclist {
8084: /*
8085: left border as a seperator if we have more than
8086: one list
8087: */
8088: border-left: 1px solid $sidebg;
8089: /*
8090: this hides the left border behind the border of the
8091: outer box if element is wrapped to the next 'line'
8092: */
8093: margin-left: -1px;
8094: }
8095:
1.843 bisitz 8096: ul.LC_funclist li {
1.915 droeschl 8097: display: inline;
1.782 bisitz 8098: white-space: nowrap;
1.915 droeschl 8099: margin: 0 0 0 25px;
8100: line-height: 150%;
1.782 bisitz 8101: }
8102:
1.974 wenzelju 8103: .LC_hidden {
8104: display: none;
8105: }
8106:
1.1030 www 8107: .LCmodal-overlay {
8108: position:fixed;
8109: top:0;
8110: right:0;
8111: bottom:0;
8112: left:0;
8113: height:100%;
8114: width:100%;
8115: margin:0;
8116: padding:0;
8117: background:#999;
8118: opacity:.75;
8119: filter: alpha(opacity=75);
8120: -moz-opacity: 0.75;
8121: z-index:101;
8122: }
8123:
8124: * html .LCmodal-overlay {
8125: position: absolute;
8126: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8127: }
8128:
8129: .LCmodal-window {
8130: position:fixed;
8131: top:50%;
8132: left:50%;
8133: margin:0;
8134: padding:0;
8135: z-index:102;
8136: }
8137:
8138: * html .LCmodal-window {
8139: position:absolute;
8140: }
8141:
8142: .LCclose-window {
8143: position:absolute;
8144: width:32px;
8145: height:32px;
8146: right:8px;
8147: top:8px;
8148: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8149: text-indent:-99999px;
8150: overflow:hidden;
8151: cursor:pointer;
8152: }
8153:
1.1100 raeburn 8154: /*
1.1231 damieng 8155: styles used for response display
8156: */
8157: div.LC_radiofoil, div.LC_rankfoil {
8158: margin: .5em 0em .5em 0em;
8159: }
8160: table.LC_itemgroup {
8161: margin-top: 1em;
8162: }
8163:
8164: /*
1.1100 raeburn 8165: styles used by TTH when "Default set of options to pass to tth/m
8166: when converting TeX" in course settings has been set
8167:
8168: option passed: -t
8169:
8170: */
8171:
8172: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8173: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8174: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8175: td div.norm {line-height:normal;}
8176:
8177: /*
8178: option passed -y3
8179: */
8180:
8181: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8182: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8183: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8184:
1.1230 damieng 8185: /*
8186: sections with roles, for content only
8187: */
8188: section[class^="role-"] {
8189: padding-left: 10px;
8190: padding-right: 5px;
8191: margin-top: 8px;
8192: margin-bottom: 8px;
8193: border: 1px solid #2A4;
8194: border-radius: 5px;
8195: box-shadow: 0px 1px 1px #BBB;
8196: }
8197: section[class^="role-"]>h1 {
8198: position: relative;
8199: margin: 0px;
8200: padding-top: 10px;
8201: padding-left: 40px;
8202: }
8203: section[class^="role-"]>h1:before {
8204: position: absolute;
8205: left: -5px;
8206: top: 5px;
8207: }
8208: section.role-activity>h1:before {
8209: content:url('/adm/daxe/images/section_icons/activity.png');
8210: }
8211: section.role-advice>h1:before {
8212: content:url('/adm/daxe/images/section_icons/advice.png');
8213: }
8214: section.role-bibliography>h1:before {
8215: content:url('/adm/daxe/images/section_icons/bibliography.png');
8216: }
8217: section.role-citation>h1:before {
8218: content:url('/adm/daxe/images/section_icons/citation.png');
8219: }
8220: section.role-conclusion>h1:before {
8221: content:url('/adm/daxe/images/section_icons/conclusion.png');
8222: }
8223: section.role-definition>h1:before {
8224: content:url('/adm/daxe/images/section_icons/definition.png');
8225: }
8226: section.role-demonstration>h1:before {
8227: content:url('/adm/daxe/images/section_icons/demonstration.png');
8228: }
8229: section.role-example>h1:before {
8230: content:url('/adm/daxe/images/section_icons/example.png');
8231: }
8232: section.role-explanation>h1:before {
8233: content:url('/adm/daxe/images/section_icons/explanation.png');
8234: }
8235: section.role-introduction>h1:before {
8236: content:url('/adm/daxe/images/section_icons/introduction.png');
8237: }
8238: section.role-method>h1:before {
8239: content:url('/adm/daxe/images/section_icons/method.png');
8240: }
8241: section.role-more_information>h1:before {
8242: content:url('/adm/daxe/images/section_icons/more_information.png');
8243: }
8244: section.role-objectives>h1:before {
8245: content:url('/adm/daxe/images/section_icons/objectives.png');
8246: }
8247: section.role-prerequisites>h1:before {
8248: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8249: }
8250: section.role-remark>h1:before {
8251: content:url('/adm/daxe/images/section_icons/remark.png');
8252: }
8253: section.role-reminder>h1:before {
8254: content:url('/adm/daxe/images/section_icons/reminder.png');
8255: }
8256: section.role-summary>h1:before {
8257: content:url('/adm/daxe/images/section_icons/summary.png');
8258: }
8259: section.role-syntax>h1:before {
8260: content:url('/adm/daxe/images/section_icons/syntax.png');
8261: }
8262: section.role-warning>h1:before {
8263: content:url('/adm/daxe/images/section_icons/warning.png');
8264: }
8265:
1.1269 raeburn 8266: #LC_minitab_header {
8267: float:left;
8268: width:100%;
8269: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8270: font-size:93%;
8271: line-height:normal;
8272: margin: 0.5em 0 0.5em 0;
8273: }
8274: #LC_minitab_header ul {
8275: margin:0;
8276: padding:10px 10px 0;
8277: list-style:none;
8278: }
8279: #LC_minitab_header li {
8280: float:left;
8281: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8282: margin:0;
8283: padding:0 0 0 9px;
8284: }
8285: #LC_minitab_header a {
8286: display:block;
8287: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8288: padding:5px 15px 4px 6px;
8289: }
8290: #LC_minitab_header #LC_current_minitab {
8291: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8292: }
8293: #LC_minitab_header #LC_current_minitab a {
8294: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8295: padding-bottom:5px;
8296: }
8297:
8298:
1.343 albertel 8299: END
8300: }
8301:
1.306 albertel 8302: =pod
8303:
8304: =item * &headtag()
8305:
8306: Returns a uniform footer for LON-CAPA web pages.
8307:
1.307 albertel 8308: Inputs: $title - optional title for the head
8309: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8310: $args - optional arguments
1.319 albertel 8311: force_register - if is true call registerurl so the remote is
8312: informed
1.415 albertel 8313: redirect -> array ref of
8314: 1- seconds before redirect occurs
8315: 2- url to redirect to
8316: 3- whether the side effect should occur
1.315 albertel 8317: (side effect of setting
8318: $env{'internal.head.redirect'} to the url
8319: redirected too)
1.352 albertel 8320: domain -> force to color decorate a page for a specific
8321: domain
8322: function -> force usage of a specific rolish color scheme
8323: bgcolor -> override the default page bgcolor
1.460 albertel 8324: no_auto_mt_title
8325: -> prevent &mt()ing the title arg
1.464 albertel 8326:
1.306 albertel 8327: =cut
8328:
8329: sub headtag {
1.313 albertel 8330: my ($title,$head_extra,$args) = @_;
1.306 albertel 8331:
1.363 albertel 8332: my $function = $args->{'function'} || &get_users_function();
8333: my $domain = $args->{'domain'} || &determinedomain();
8334: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8335: my $httphost = $args->{'use_absolute'};
1.418 albertel 8336: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8337: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8338: #time(),
1.418 albertel 8339: $env{'environment.color.timestamp'},
1.363 albertel 8340: $function,$domain,$bgcolor);
8341:
1.369 www 8342: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8343:
1.308 albertel 8344: my $result =
8345: '<head>'.
1.1160 raeburn 8346: &font_settings($args);
1.319 albertel 8347:
1.1188 raeburn 8348: my $inhibitprint;
8349: if ($args->{'print_suppress'}) {
8350: $inhibitprint = &print_suppression();
8351: }
1.1064 raeburn 8352:
1.461 albertel 8353: if (!$args->{'frameset'}) {
8354: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8355: }
1.962 droeschl 8356: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8357: $result .= Apache::lonxml::display_title();
1.319 albertel 8358: }
1.436 albertel 8359: if (!$args->{'no_nav_bar'}
8360: && !$args->{'only_body'}
8361: && !$args->{'frameset'}) {
1.1154 raeburn 8362: $result .= &help_menu_js($httphost);
1.1032 www 8363: $result.=&modal_window();
1.1038 www 8364: $result.=&togglebox_script();
1.1034 www 8365: $result.=&wishlist_window();
1.1041 www 8366: $result.=&LCprogressbarUpdate_script();
1.1034 www 8367: } else {
8368: if ($args->{'add_modal'}) {
8369: $result.=&modal_window();
8370: }
8371: if ($args->{'add_wishlist'}) {
8372: $result.=&wishlist_window();
8373: }
1.1038 www 8374: if ($args->{'add_togglebox'}) {
8375: $result.=&togglebox_script();
8376: }
1.1041 www 8377: if ($args->{'add_progressbar'}) {
8378: $result.=&LCprogressbarUpdate_script();
8379: }
1.436 albertel 8380: }
1.314 albertel 8381: if (ref($args->{'redirect'})) {
1.414 albertel 8382: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8383: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8384: if (!$inhibit_continue) {
8385: $env{'internal.head.redirect'} = $url;
8386: }
1.313 albertel 8387: $result.=<<ADDMETA
8388: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8389: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8390: ADDMETA
1.1210 raeburn 8391: } else {
8392: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8393: my $requrl = $env{'request.uri'};
8394: if ($requrl eq '') {
8395: $requrl = $ENV{'REQUEST_URI'};
8396: $requrl =~ s/\?.+$//;
8397: }
8398: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8399: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8400: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8401: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8402: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8403: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8404: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8405: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8406: if ($domdefs{'offloadnow'}{$lonhost}) {
8407: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8408: if (($newserver) && ($newserver ne $lonhost)) {
8409: my $numsec = 5;
8410: my $timeout = $numsec * 1000;
8411: my ($newurl,$locknum,%locks,$msg);
8412: if ($env{'request.role.adv'}) {
8413: ($locknum,%locks) = &Apache::lonnet::get_locks();
8414: }
8415: my $disable_submit = 0;
8416: if ($requrl =~ /$LONCAPA::assess_re/) {
8417: $disable_submit = 1;
8418: }
8419: if ($locknum) {
8420: my @lockinfo = sort(values(%locks));
8421: $msg = &mt('Once the following tasks are complete: ')."\\n".
8422: join(", ",sort(values(%locks)))."\\n".
8423: &mt('your session will be transferred to a different server, after you click "Roles".');
8424: } else {
8425: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8426: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8427: }
8428: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8429: $newurl = '/adm/switchserver?otherserver='.$newserver;
8430: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8431: $newurl .= '&role='.$env{'request.role'};
8432: }
8433: if ($env{'request.symb'}) {
8434: $newurl .= '&symb='.$env{'request.symb'};
8435: } else {
8436: $newurl .= '&origurl='.$requrl;
8437: }
8438: }
1.1222 damieng 8439: &js_escape(\$msg);
1.1210 raeburn 8440: $result.=<<OFFLOAD
8441: <meta http-equiv="pragma" content="no-cache" />
8442: <script type="text/javascript">
1.1215 raeburn 8443: // <![CDATA[
1.1210 raeburn 8444: function LC_Offload_Now() {
8445: var dest = "$newurl";
8446: if (dest != '') {
8447: window.location.href="$newurl";
8448: }
8449: }
1.1214 raeburn 8450: \$(document).ready(function () {
8451: window.alert('$msg');
8452: if ($disable_submit) {
1.1210 raeburn 8453: \$(".LC_hwk_submit").prop("disabled", true);
8454: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8455: }
8456: setTimeout('LC_Offload_Now()', $timeout);
8457: });
1.1215 raeburn 8458: // ]]>
1.1210 raeburn 8459: </script>
8460: OFFLOAD
8461: }
8462: }
8463: }
8464: }
8465: }
8466: }
1.313 albertel 8467: }
1.306 albertel 8468: if (!defined($title)) {
8469: $title = 'The LearningOnline Network with CAPA';
8470: }
1.460 albertel 8471: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8472: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8473: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8474: if (!$args->{'frameset'}) {
8475: $result .= ' /';
8476: }
8477: $result .= '>'
1.1064 raeburn 8478: .$inhibitprint
1.414 albertel 8479: .$head_extra;
1.1242 raeburn 8480: my $clientmobile;
8481: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8482: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8483: } else {
8484: $clientmobile = $env{'browser.mobile'};
8485: }
8486: if ($clientmobile) {
1.1137 raeburn 8487: $result .= '
8488: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8489: <meta name="apple-mobile-web-app-capable" content="yes" />';
8490: }
1.1278 raeburn 8491: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8492: return $result.'</head>';
1.306 albertel 8493: }
8494:
8495: =pod
8496:
1.340 albertel 8497: =item * &font_settings()
8498:
8499: Returns neccessary <meta> to set the proper encoding
8500:
1.1160 raeburn 8501: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8502:
8503: =cut
8504:
8505: sub font_settings {
1.1160 raeburn 8506: my ($args) = @_;
1.340 albertel 8507: my $headerstring='';
1.1160 raeburn 8508: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8509: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8510: $headerstring.=
8511: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8512: if (!$args->{'frameset'}) {
8513: $headerstring.= ' /';
8514: }
8515: $headerstring .= '>'."\n";
1.340 albertel 8516: }
8517: return $headerstring;
8518: }
8519:
1.341 albertel 8520: =pod
8521:
1.1064 raeburn 8522: =item * &print_suppression()
8523:
8524: In course context returns css which causes the body to be blank when media="print",
8525: if printout generation is unavailable for the current resource.
8526:
8527: This could be because:
8528:
8529: (a) printstartdate is in the future
8530:
8531: (b) printenddate is in the past
8532:
8533: (c) there is an active exam block with "printout"
8534: functionality blocked
8535:
8536: Users with pav, pfo or evb privileges are exempt.
8537:
8538: Inputs: none
8539:
8540: =cut
8541:
8542:
8543: sub print_suppression {
8544: my $noprint;
8545: if ($env{'request.course.id'}) {
8546: my $scope = $env{'request.course.id'};
8547: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8548: (&Apache::lonnet::allowed('pfo',$scope))) {
8549: return;
8550: }
8551: if ($env{'request.course.sec'} ne '') {
8552: $scope .= "/$env{'request.course.sec'}";
8553: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8554: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8555: return;
1.1064 raeburn 8556: }
8557: }
8558: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8559: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8560: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8561: if ($blocked) {
8562: my $checkrole = "cm./$cdom/$cnum";
8563: if ($env{'request.course.sec'} ne '') {
8564: $checkrole .= "/$env{'request.course.sec'}";
8565: }
8566: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8567: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8568: $noprint = 1;
8569: }
8570: }
8571: unless ($noprint) {
8572: my $symb = &Apache::lonnet::symbread();
8573: if ($symb ne '') {
8574: my $navmap = Apache::lonnavmaps::navmap->new();
8575: if (ref($navmap)) {
8576: my $res = $navmap->getBySymb($symb);
8577: if (ref($res)) {
8578: if (!$res->resprintable()) {
8579: $noprint = 1;
8580: }
8581: }
8582: }
8583: }
8584: }
8585: if ($noprint) {
8586: return <<"ENDSTYLE";
8587: <style type="text/css" media="print">
8588: body { display:none }
8589: </style>
8590: ENDSTYLE
8591: }
8592: }
8593: return;
8594: }
8595:
8596: =pod
8597:
1.341 albertel 8598: =item * &xml_begin()
8599:
8600: Returns the needed doctype and <html>
8601:
8602: Inputs: none
8603:
8604: =cut
8605:
8606: sub xml_begin {
1.1168 raeburn 8607: my ($is_frameset) = @_;
1.341 albertel 8608: my $output='';
8609:
8610: if ($env{'browser.mathml'}) {
8611: $output='<?xml version="1.0"?>'
8612: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8613: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8614:
8615: # .'<!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">] >'
8616: .'<!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">'
8617: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8618: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8619: } elsif ($is_frameset) {
8620: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8621: '<html>'."\n";
1.341 albertel 8622: } else {
1.1168 raeburn 8623: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8624: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8625: }
8626: return $output;
8627: }
1.340 albertel 8628:
8629: =pod
8630:
1.306 albertel 8631: =item * &start_page()
8632:
8633: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8634:
1.648 raeburn 8635: Inputs:
8636:
8637: =over 4
8638:
8639: $title - optional title for the page
8640:
8641: $head_extra - optional extra HTML to incude inside the <head>
8642:
8643: $args - additional optional args supported are:
8644:
8645: =over 8
8646:
8647: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8648: arg on
1.814 bisitz 8649: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8650: add_entries -> additional attributes to add to the <body>
8651: domain -> force to color decorate a page for a
1.317 albertel 8652: specific domain
1.648 raeburn 8653: function -> force usage of a specific rolish color
1.317 albertel 8654: scheme
1.648 raeburn 8655: redirect -> see &headtag()
8656: bgcolor -> override the default page bg color
8657: js_ready -> return a string ready for being used in
1.317 albertel 8658: a javascript writeln
1.648 raeburn 8659: html_encode -> return a string ready for being used in
1.320 albertel 8660: a html attribute
1.648 raeburn 8661: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8662: $forcereg arg
1.648 raeburn 8663: frameset -> if true will start with a <frameset>
1.330 albertel 8664: rather than <body>
1.648 raeburn 8665: skip_phases -> hash ref of
1.338 albertel 8666: head -> skip the <html><head> generation
8667: body -> skip all <body> generation
1.648 raeburn 8668: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8669: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8670: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8671: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8672: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8673: group -> includes the current group, if page is for a
1.1274 raeburn 8674: specific group
8675: use_absolute -> for request for external resource or syllabus, this
8676: will contain https://<hostname> if server uses
8677: https (as per hosts.tab), but request is for http
8678: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8679:
1.648 raeburn 8680: =back
1.460 albertel 8681:
1.648 raeburn 8682: =back
1.562 albertel 8683:
1.306 albertel 8684: =cut
8685:
8686: sub start_page {
1.309 albertel 8687: my ($title,$head_extra,$args) = @_;
1.318 albertel 8688: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8689:
1.315 albertel 8690: $env{'internal.start_page'}++;
1.1096 raeburn 8691: my ($result,@advtools);
1.964 droeschl 8692:
1.338 albertel 8693: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8694: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8695: }
8696:
8697: if (! exists($args->{'skip_phases'}{'body'}) ) {
8698: if ($args->{'frameset'}) {
8699: my $attr_string = &make_attr_string($args->{'force_register'},
8700: $args->{'add_entries'});
8701: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8702: } else {
8703: $result .=
8704: &bodytag($title,
8705: $args->{'function'}, $args->{'add_entries'},
8706: $args->{'only_body'}, $args->{'domain'},
8707: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8708: $args->{'bgcolor'}, $args,
8709: \@advtools);
1.831 bisitz 8710: }
1.330 albertel 8711: }
1.338 albertel 8712:
1.315 albertel 8713: if ($args->{'js_ready'}) {
1.713 kaisler 8714: $result = &js_ready($result);
1.315 albertel 8715: }
1.320 albertel 8716: if ($args->{'html_encode'}) {
1.713 kaisler 8717: $result = &html_encode($result);
8718: }
8719:
1.813 bisitz 8720: # Preparation for new and consistent functionlist at top of screen
8721: # if ($args->{'functionlist'}) {
8722: # $result .= &build_functionlist();
8723: #}
8724:
1.964 droeschl 8725: # Don't add anything more if only_body wanted or in const space
8726: return $result if $args->{'only_body'}
8727: || $env{'request.state'} eq 'construct';
1.813 bisitz 8728:
8729: #Breadcrumbs
1.758 kaisler 8730: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8731: &Apache::lonhtmlcommon::clear_breadcrumbs();
8732: #if any br links exists, add them to the breadcrumbs
8733: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8734: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8735: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8736: }
8737: }
1.1096 raeburn 8738: # if @advtools array contains items add then to the breadcrumbs
8739: if (@advtools > 0) {
8740: &Apache::lonmenu::advtools_crumbs(@advtools);
8741: }
1.1312 raeburn 8742: my $ltiscope;
8743: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
8744: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8745: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8746: ($ltiscope) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
8747: }
1.1272 raeburn 8748: my $menulink;
8749: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8750: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8751: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8752: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8753: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8754: (!$env{'request.role.adv'}))) {
8755: $menulink = 0;
8756: } else {
8757: undef($menulink);
8758: }
1.758 kaisler 8759: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8760: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8761: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8762: } else {
1.1272 raeburn 8763: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8764: }
1.320 albertel 8765: }
1.315 albertel 8766: return $result;
1.306 albertel 8767: }
8768:
8769: sub end_page {
1.315 albertel 8770: my ($args) = @_;
8771: $env{'internal.end_page'}++;
1.330 albertel 8772: my $result;
1.335 albertel 8773: if ($args->{'discussion'}) {
8774: my ($target,$parser);
8775: if (ref($args->{'discussion'})) {
8776: ($target,$parser) =($args->{'discussion'}{'target'},
8777: $args->{'discussion'}{'parser'});
8778: }
8779: $result .= &Apache::lonxml::xmlend($target,$parser);
8780: }
1.330 albertel 8781: if ($args->{'frameset'}) {
8782: $result .= '</frameset>';
8783: } else {
1.635 raeburn 8784: $result .= &endbodytag($args);
1.330 albertel 8785: }
1.1080 raeburn 8786: unless ($args->{'notbody'}) {
8787: $result .= "\n</html>";
8788: }
1.330 albertel 8789:
1.315 albertel 8790: if ($args->{'js_ready'}) {
1.317 albertel 8791: $result = &js_ready($result);
1.315 albertel 8792: }
1.335 albertel 8793:
1.320 albertel 8794: if ($args->{'html_encode'}) {
8795: $result = &html_encode($result);
8796: }
1.335 albertel 8797:
1.315 albertel 8798: return $result;
8799: }
8800:
1.1034 www 8801: sub wishlist_window {
8802: return(<<'ENDWISHLIST');
1.1046 raeburn 8803: <script type="text/javascript">
1.1034 www 8804: // <![CDATA[
8805: // <!-- BEGIN LON-CAPA Internal
8806: function set_wishlistlink(title, path) {
8807: if (!title) {
8808: title = document.title;
8809: title = title.replace(/^LON-CAPA /,'');
8810: }
1.1175 raeburn 8811: title = encodeURIComponent(title);
1.1203 raeburn 8812: title = title.replace("'","\\\'");
1.1034 www 8813: if (!path) {
8814: path = location.pathname;
8815: }
1.1175 raeburn 8816: path = encodeURIComponent(path);
1.1203 raeburn 8817: path = path.replace("'","\\\'");
1.1034 www 8818: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8819: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8820: }
8821: // END LON-CAPA Internal -->
8822: // ]]>
8823: </script>
8824: ENDWISHLIST
8825: }
8826:
1.1030 www 8827: sub modal_window {
8828: return(<<'ENDMODAL');
1.1046 raeburn 8829: <script type="text/javascript">
1.1030 www 8830: // <![CDATA[
8831: // <!-- BEGIN LON-CAPA Internal
8832: var modalWindow = {
8833: parent:"body",
8834: windowId:null,
8835: content:null,
8836: width:null,
8837: height:null,
8838: close:function()
8839: {
8840: $(".LCmodal-window").remove();
8841: $(".LCmodal-overlay").remove();
8842: },
8843: open:function()
8844: {
8845: var modal = "";
8846: modal += "<div class=\"LCmodal-overlay\"></div>";
8847: 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;\">";
8848: modal += this.content;
8849: modal += "</div>";
8850:
8851: $(this.parent).append(modal);
8852:
8853: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8854: $(".LCclose-window").click(function(){modalWindow.close();});
8855: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8856: }
8857: };
1.1140 raeburn 8858: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8859: {
1.1266 raeburn 8860: source = source.replace(/'/g,"'");
1.1030 www 8861: modalWindow.windowId = "myModal";
8862: modalWindow.width = width;
8863: modalWindow.height = height;
1.1196 raeburn 8864: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8865: modalWindow.open();
1.1208 raeburn 8866: };
1.1030 www 8867: // END LON-CAPA Internal -->
8868: // ]]>
8869: </script>
8870: ENDMODAL
8871: }
8872:
8873: sub modal_link {
1.1140 raeburn 8874: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8875: unless ($width) { $width=480; }
8876: unless ($height) { $height=400; }
1.1031 www 8877: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8878: unless ($transparency) { $transparency='true'; }
8879:
1.1074 raeburn 8880: my $target_attr;
8881: if (defined($target)) {
8882: $target_attr = 'target="'.$target.'"';
8883: }
8884: return <<"ENDLINK";
1.1140 raeburn 8885: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8886: $linktext</a>
8887: ENDLINK
1.1030 www 8888: }
8889:
1.1032 www 8890: sub modal_adhoc_script {
8891: my ($funcname,$width,$height,$content)=@_;
8892: return (<<ENDADHOC);
1.1046 raeburn 8893: <script type="text/javascript">
1.1032 www 8894: // <![CDATA[
8895: var $funcname = function()
8896: {
8897: modalWindow.windowId = "myModal";
8898: modalWindow.width = $width;
8899: modalWindow.height = $height;
8900: modalWindow.content = '$content';
8901: modalWindow.open();
8902: };
8903: // ]]>
8904: </script>
8905: ENDADHOC
8906: }
8907:
1.1041 www 8908: sub modal_adhoc_inner {
8909: my ($funcname,$width,$height,$content)=@_;
8910: my $innerwidth=$width-20;
8911: $content=&js_ready(
1.1140 raeburn 8912: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8913: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8914: $content.
1.1041 www 8915: &end_scrollbox().
1.1140 raeburn 8916: &end_page()
1.1041 www 8917: );
8918: return &modal_adhoc_script($funcname,$width,$height,$content);
8919: }
8920:
8921: sub modal_adhoc_window {
8922: my ($funcname,$width,$height,$content,$linktext)=@_;
8923: return &modal_adhoc_inner($funcname,$width,$height,$content).
8924: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8925: }
8926:
8927: sub modal_adhoc_launch {
8928: my ($funcname,$width,$height,$content)=@_;
8929: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8930: <script type="text/javascript">
8931: // <![CDATA[
8932: $funcname();
8933: // ]]>
8934: </script>
8935: ENDLAUNCH
8936: }
8937:
8938: sub modal_adhoc_close {
8939: return (<<ENDCLOSE);
8940: <script type="text/javascript">
8941: // <![CDATA[
8942: modalWindow.close();
8943: // ]]>
8944: </script>
8945: ENDCLOSE
8946: }
8947:
1.1038 www 8948: sub togglebox_script {
8949: return(<<ENDTOGGLE);
8950: <script type="text/javascript">
8951: // <![CDATA[
8952: function LCtoggleDisplay(id,hidetext,showtext) {
8953: link = document.getElementById(id + "link").childNodes[0];
8954: with (document.getElementById(id).style) {
8955: if (display == "none" ) {
8956: display = "inline";
8957: link.nodeValue = hidetext;
8958: } else {
8959: display = "none";
8960: link.nodeValue = showtext;
8961: }
8962: }
8963: }
8964: // ]]>
8965: </script>
8966: ENDTOGGLE
8967: }
8968:
1.1039 www 8969: sub start_togglebox {
8970: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8971: unless ($heading) { $heading=''; } else { $heading.=' '; }
8972: unless ($showtext) { $showtext=&mt('show'); }
8973: unless ($hidetext) { $hidetext=&mt('hide'); }
8974: unless ($headerbg) { $headerbg='#FFFFFF'; }
8975: return &start_data_table().
8976: &start_data_table_header_row().
8977: '<td bgcolor="'.$headerbg.'">'.$heading.
8978: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8979: $showtext.'\')">'.$showtext.'</a>]</td>'.
8980: &end_data_table_header_row().
8981: '<tr id="'.$id.'" style="display:none""><td>';
8982: }
8983:
8984: sub end_togglebox {
8985: return '</td></tr>'.&end_data_table();
8986: }
8987:
1.1041 www 8988: sub LCprogressbar_script {
1.1302 raeburn 8989: my ($id,$number_to_do)=@_;
8990: if ($number_to_do) {
8991: return(<<ENDPROGRESS);
1.1041 www 8992: <script type="text/javascript">
8993: // <![CDATA[
1.1045 www 8994: \$('#progressbar$id').progressbar({
1.1041 www 8995: value: 0,
8996: change: function(event, ui) {
8997: var newVal = \$(this).progressbar('option', 'value');
8998: \$('.pblabel', this).text(LCprogressTxt);
8999: }
9000: });
9001: // ]]>
9002: </script>
9003: ENDPROGRESS
1.1302 raeburn 9004: } else {
9005: return(<<ENDPROGRESS);
9006: <script type="text/javascript">
9007: // <![CDATA[
9008: \$('#progressbar$id').progressbar({
9009: value: false,
9010: create: function(event, ui) {
9011: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9012: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9013: }
9014: });
9015: // ]]>
9016: </script>
9017: ENDPROGRESS
9018: }
1.1041 www 9019: }
9020:
9021: sub LCprogressbarUpdate_script {
9022: return(<<ENDPROGRESSUPDATE);
9023: <style type="text/css">
9024: .ui-progressbar { position:relative; }
1.1302 raeburn 9025: .progress-label {position: absolute; width: 100%; text-align: center; top: 1px; font-weight: bold; text-shadow: 1px 1px 0 #fff;margin: 0; line-height: 200%; }
1.1041 www 9026: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9027: </style>
9028: <script type="text/javascript">
9029: // <![CDATA[
1.1045 www 9030: var LCprogressTxt='---';
9031:
1.1302 raeburn 9032: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9033: LCprogressTxt=progresstext;
1.1302 raeburn 9034: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9035: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9036: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9037: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9038: } else {
9039: \$('#progressbar'+id).progressbar('value',percent);
9040: }
1.1041 www 9041: }
9042: // ]]>
9043: </script>
9044: ENDPROGRESSUPDATE
9045: }
9046:
1.1042 www 9047: my $LClastpercent;
1.1045 www 9048: my $LCidcnt;
9049: my $LCcurrentid;
1.1042 www 9050:
1.1041 www 9051: sub LCprogressbar {
1.1302 raeburn 9052: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9053: $LClastpercent=0;
1.1045 www 9054: $LCidcnt++;
9055: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9056: my ($starting,$content);
9057: if ($number_to_do) {
9058: $starting=&mt('Starting');
9059: $content=(<<ENDPROGBAR);
9060: $preamble
1.1045 www 9061: <div id="progressbar$LCcurrentid">
1.1041 www 9062: <span class="pblabel">$starting</span>
9063: </div>
9064: ENDPROGBAR
1.1302 raeburn 9065: } else {
9066: $starting=&mt('Loading...');
9067: $LClastpercent='false';
9068: $content=(<<ENDPROGBAR);
9069: $preamble
9070: <div id="progressbar$LCcurrentid">
9071: <div class="progress-label">$starting</div>
9072: </div>
9073: ENDPROGBAR
9074: }
9075: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9076: }
9077:
9078: sub LCprogressbarUpdate {
1.1302 raeburn 9079: my ($r,$val,$text,$number_to_do)=@_;
9080: if ($number_to_do) {
9081: unless ($val) {
9082: if ($LClastpercent) {
9083: $val=$LClastpercent;
9084: } else {
9085: $val=0;
9086: }
9087: }
9088: if ($val<0) { $val=0; }
9089: if ($val>100) { $val=0; }
9090: $LClastpercent=$val;
9091: unless ($text) { $text=$val.'%'; }
9092: } else {
9093: $val = 'false';
1.1042 www 9094: }
1.1041 www 9095: $text=&js_ready($text);
1.1044 www 9096: &r_print($r,<<ENDUPDATE);
1.1041 www 9097: <script type="text/javascript">
9098: // <![CDATA[
1.1302 raeburn 9099: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9100: // ]]>
9101: </script>
9102: ENDUPDATE
1.1035 www 9103: }
9104:
1.1042 www 9105: sub LCprogressbarClose {
9106: my ($r)=@_;
9107: $LClastpercent=0;
1.1044 www 9108: &r_print($r,<<ENDCLOSE);
1.1042 www 9109: <script type="text/javascript">
9110: // <![CDATA[
1.1045 www 9111: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9112: // ]]>
9113: </script>
9114: ENDCLOSE
1.1044 www 9115: }
9116:
9117: sub r_print {
9118: my ($r,$to_print)=@_;
9119: if ($r) {
9120: $r->print($to_print);
9121: $r->rflush();
9122: } else {
9123: print($to_print);
9124: }
1.1042 www 9125: }
9126:
1.320 albertel 9127: sub html_encode {
9128: my ($result) = @_;
9129:
1.322 albertel 9130: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9131:
9132: return $result;
9133: }
1.1044 www 9134:
1.317 albertel 9135: sub js_ready {
9136: my ($result) = @_;
9137:
1.323 albertel 9138: $result =~ s/[\n\r]/ /xmsg;
9139: $result =~ s/\\/\\\\/xmsg;
9140: $result =~ s/'/\\'/xmsg;
1.372 albertel 9141: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9142:
9143: return $result;
9144: }
9145:
1.315 albertel 9146: sub validate_page {
9147: if ( exists($env{'internal.start_page'})
1.316 albertel 9148: && $env{'internal.start_page'} > 1) {
9149: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9150: $env{'internal.start_page'}.' '.
1.316 albertel 9151: $ENV{'request.filename'});
1.315 albertel 9152: }
9153: if ( exists($env{'internal.end_page'})
1.316 albertel 9154: && $env{'internal.end_page'} > 1) {
9155: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9156: $env{'internal.end_page'}.' '.
1.316 albertel 9157: $env{'request.filename'});
1.315 albertel 9158: }
9159: if ( exists($env{'internal.start_page'})
9160: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9161: &Apache::lonnet::logthis('start_page called without end_page '.
9162: $env{'request.filename'});
1.315 albertel 9163: }
9164: if ( ! exists($env{'internal.start_page'})
9165: && exists($env{'internal.end_page'})) {
1.316 albertel 9166: &Apache::lonnet::logthis('end_page called without start_page'.
9167: $env{'request.filename'});
1.315 albertel 9168: }
1.306 albertel 9169: }
1.315 albertel 9170:
1.996 www 9171:
9172: sub start_scrollbox {
1.1140 raeburn 9173: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9174: unless ($outerwidth) { $outerwidth='520px'; }
9175: unless ($width) { $width='500px'; }
9176: unless ($height) { $height='200px'; }
1.1075 raeburn 9177: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9178: if ($id ne '') {
1.1140 raeburn 9179: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9180: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9181: }
1.1075 raeburn 9182: if ($bgcolor ne '') {
9183: $tdcol = "background-color: $bgcolor;";
9184: }
1.1137 raeburn 9185: my $nicescroll_js;
9186: if ($env{'browser.mobile'}) {
1.1140 raeburn 9187: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9188: }
9189: return <<"END";
9190: $nicescroll_js
9191:
9192: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9193: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9194: END
9195: }
9196:
9197: sub end_scrollbox {
9198: return '</div></td></tr></table>';
9199: }
9200:
9201: sub nicescroll_javascript {
9202: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9203: my %options;
9204: if (ref($cursor) eq 'HASH') {
9205: %options = %{$cursor};
9206: }
9207: unless ($options{'railalign'} =~ /^left|right$/) {
9208: $options{'railalign'} = 'left';
9209: }
9210: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9211: my $function = &get_users_function();
9212: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9213: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9214: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9215: }
1.1140 raeburn 9216: }
9217: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9218: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9219: $options{'cursoropacity'}='1.0';
9220: }
1.1140 raeburn 9221: } else {
9222: $options{'cursoropacity'}='1.0';
9223: }
9224: if ($options{'cursorfixedheight'} eq 'none') {
9225: delete($options{'cursorfixedheight'});
9226: } else {
9227: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9228: }
9229: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9230: delete($options{'railoffset'});
9231: }
9232: my @niceoptions;
9233: while (my($key,$value) = each(%options)) {
9234: if ($value =~ /^\{.+\}$/) {
9235: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9236: } else {
1.1140 raeburn 9237: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9238: }
1.1140 raeburn 9239: }
9240: my $nicescroll_js = '
1.1137 raeburn 9241: $(document).ready(
1.1140 raeburn 9242: function() {
9243: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9244: }
1.1137 raeburn 9245: );
9246: ';
1.1140 raeburn 9247: if ($framecheck) {
9248: $nicescroll_js .= '
9249: function expand_div(caller) {
9250: if (top === self) {
9251: document.getElementById("'.$id.'").style.width = "auto";
9252: document.getElementById("'.$id.'").style.height = "auto";
9253: } else {
9254: try {
9255: if (parent.frames) {
9256: if (parent.frames.length > 1) {
9257: var framesrc = parent.frames[1].location.href;
9258: var currsrc = framesrc.replace(/\#.*$/,"");
9259: if ((caller == "search") || (currsrc == "'.$location.'")) {
9260: document.getElementById("'.$id.'").style.width = "auto";
9261: document.getElementById("'.$id.'").style.height = "auto";
9262: }
9263: }
9264: }
9265: } catch (e) {
9266: return;
9267: }
1.1137 raeburn 9268: }
1.1140 raeburn 9269: return;
1.996 www 9270: }
1.1140 raeburn 9271: ';
9272: }
9273: if ($needjsready) {
9274: $nicescroll_js = '
9275: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9276: } else {
9277: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9278: }
9279: return $nicescroll_js;
1.996 www 9280: }
9281:
1.318 albertel 9282: sub simple_error_page {
1.1150 bisitz 9283: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9284: my %displayargs;
1.1151 raeburn 9285: if (ref($args) eq 'HASH') {
9286: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9287: if ($args->{'only_body'}) {
9288: $displayargs{'only_body'} = 1;
9289: }
9290: if ($args->{'no_nav_bar'}) {
9291: $displayargs{'no_nav_bar'} = 1;
9292: }
1.1151 raeburn 9293: } else {
9294: $msg = &mt($msg);
9295: }
1.1150 bisitz 9296:
1.318 albertel 9297: my $page =
1.1304 raeburn 9298: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9299: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9300: &Apache::loncommon::end_page();
9301: if (ref($r)) {
9302: $r->print($page);
1.327 albertel 9303: return;
1.318 albertel 9304: }
9305: return $page;
9306: }
1.347 albertel 9307:
9308: {
1.610 albertel 9309: my @row_count;
1.961 onken 9310:
9311: sub start_data_table_count {
9312: unshift(@row_count, 0);
9313: return;
9314: }
9315:
9316: sub end_data_table_count {
9317: shift(@row_count);
9318: return;
9319: }
9320:
1.347 albertel 9321: sub start_data_table {
1.1018 raeburn 9322: my ($add_class,$id) = @_;
1.422 albertel 9323: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9324: my $table_id;
9325: if (defined($id)) {
9326: $table_id = ' id="'.$id.'"';
9327: }
1.961 onken 9328: &start_data_table_count();
1.1018 raeburn 9329: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9330: }
9331:
9332: sub end_data_table {
1.961 onken 9333: &end_data_table_count();
1.389 albertel 9334: return '</table>'."\n";;
1.347 albertel 9335: }
9336:
9337: sub start_data_table_row {
1.974 wenzelju 9338: my ($add_class, $id) = @_;
1.610 albertel 9339: $row_count[0]++;
9340: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9341: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9342: $id = (' id="'.$id.'"') unless ($id eq '');
9343: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9344: }
1.471 banghart 9345:
9346: sub continue_data_table_row {
1.974 wenzelju 9347: my ($add_class, $id) = @_;
1.610 albertel 9348: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9349: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9350: $id = (' id="'.$id.'"') unless ($id eq '');
9351: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9352: }
1.347 albertel 9353:
9354: sub end_data_table_row {
1.389 albertel 9355: return '</tr>'."\n";;
1.347 albertel 9356: }
1.367 www 9357:
1.421 albertel 9358: sub start_data_table_empty_row {
1.707 bisitz 9359: # $row_count[0]++;
1.421 albertel 9360: return '<tr class="LC_empty_row" >'."\n";;
9361: }
9362:
9363: sub end_data_table_empty_row {
9364: return '</tr>'."\n";;
9365: }
9366:
1.367 www 9367: sub start_data_table_header_row {
1.389 albertel 9368: return '<tr class="LC_header_row">'."\n";;
1.367 www 9369: }
9370:
9371: sub end_data_table_header_row {
1.389 albertel 9372: return '</tr>'."\n";;
1.367 www 9373: }
1.890 droeschl 9374:
9375: sub data_table_caption {
9376: my $caption = shift;
9377: return "<caption class=\"LC_caption\">$caption</caption>";
9378: }
1.347 albertel 9379: }
9380:
1.548 albertel 9381: =pod
9382:
9383: =item * &inhibit_menu_check($arg)
9384:
9385: Checks for a inhibitmenu state and generates output to preserve it
9386:
9387: Inputs: $arg - can be any of
9388: - undef - in which case the return value is a string
9389: to add into arguments list of a uri
9390: - 'input' - in which case the return value is a HTML
9391: <form> <input> field of type hidden to
9392: preserve the value
9393: - a url - in which case the return value is the url with
9394: the neccesary cgi args added to preserve the
9395: inhibitmenu state
9396: - a ref to a url - no return value, but the string is
9397: updated to include the neccessary cgi
9398: args to preserve the inhibitmenu state
9399:
9400: =cut
9401:
9402: sub inhibit_menu_check {
9403: my ($arg) = @_;
9404: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9405: if ($arg eq 'input') {
9406: if ($env{'form.inhibitmenu'}) {
9407: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9408: } else {
9409: return
9410: }
9411: }
9412: if ($env{'form.inhibitmenu'}) {
9413: if (ref($arg)) {
9414: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9415: } elsif ($arg eq '') {
9416: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9417: } else {
9418: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9419: }
9420: }
9421: if (!ref($arg)) {
9422: return $arg;
9423: }
9424: }
9425:
1.251 albertel 9426: ###############################################
1.182 matthew 9427:
9428: =pod
9429:
1.549 albertel 9430: =back
9431:
9432: =head1 User Information Routines
9433:
9434: =over 4
9435:
1.405 albertel 9436: =item * &get_users_function()
1.182 matthew 9437:
9438: Used by &bodytag to determine the current users primary role.
9439: Returns either 'student','coordinator','admin', or 'author'.
9440:
9441: =cut
9442:
9443: ###############################################
9444: sub get_users_function {
1.815 tempelho 9445: my $function = 'norole';
1.818 tempelho 9446: if ($env{'request.role'}=~/^(st)/) {
9447: $function='student';
9448: }
1.907 raeburn 9449: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9450: $function='coordinator';
9451: }
1.258 albertel 9452: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9453: $function='admin';
9454: }
1.826 bisitz 9455: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9456: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9457: $function='author';
9458: }
9459: return $function;
1.54 www 9460: }
1.99 www 9461:
9462: ###############################################
9463:
1.233 raeburn 9464: =pod
9465:
1.821 raeburn 9466: =item * &show_course()
9467:
9468: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9469: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9470:
9471: Inputs:
9472: None
9473:
9474: Outputs:
9475: Scalar: 1 if 'Course' to be used, 0 otherwise.
9476:
9477: =cut
9478:
9479: ###############################################
9480: sub show_course {
9481: my $course = !$env{'user.adv'};
9482: if (!$env{'user.adv'}) {
9483: foreach my $env (keys(%env)) {
9484: next if ($env !~ m/^user\.priv\./);
9485: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9486: $course = 0;
9487: last;
9488: }
9489: }
9490: }
9491: return $course;
9492: }
9493:
9494: ###############################################
9495:
9496: =pod
9497:
1.542 raeburn 9498: =item * &check_user_status()
1.274 raeburn 9499:
9500: Determines current status of supplied role for a
9501: specific user. Roles can be active, previous or future.
9502:
9503: Inputs:
9504: user's domain, user's username, course's domain,
1.375 raeburn 9505: course's number, optional section ID.
1.274 raeburn 9506:
9507: Outputs:
9508: role status: active, previous or future.
9509:
9510: =cut
9511:
9512: sub check_user_status {
1.412 raeburn 9513: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9514: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9515: my @uroles = keys(%userinfo);
1.274 raeburn 9516: my $srchstr;
9517: my $active_chk = 'none';
1.412 raeburn 9518: my $now = time;
1.274 raeburn 9519: if (@uroles > 0) {
1.908 raeburn 9520: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9521: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9522: } else {
1.412 raeburn 9523: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9524: }
9525: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9526: my $role_end = 0;
9527: my $role_start = 0;
9528: $active_chk = 'active';
1.412 raeburn 9529: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9530: $role_end = $1;
9531: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9532: $role_start = $1;
1.274 raeburn 9533: }
9534: }
9535: if ($role_start > 0) {
1.412 raeburn 9536: if ($now < $role_start) {
1.274 raeburn 9537: $active_chk = 'future';
9538: }
9539: }
9540: if ($role_end > 0) {
1.412 raeburn 9541: if ($now > $role_end) {
1.274 raeburn 9542: $active_chk = 'previous';
9543: }
9544: }
9545: }
9546: }
9547: return $active_chk;
9548: }
9549:
9550: ###############################################
9551:
9552: =pod
9553:
1.405 albertel 9554: =item * &get_sections()
1.233 raeburn 9555:
9556: Determines all the sections for a course including
9557: sections with students and sections containing other roles.
1.419 raeburn 9558: Incoming parameters:
9559:
9560: 1. domain
9561: 2. course number
9562: 3. reference to array containing roles for which sections should
9563: be gathered (optional).
9564: 4. reference to array containing status types for which sections
9565: should be gathered (optional).
9566:
9567: If the third argument is undefined, sections are gathered for any role.
9568: If the fourth argument is undefined, sections are gathered for any status.
9569: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9570:
1.374 raeburn 9571: Returns section hash (keys are section IDs, values are
9572: number of users in each section), subject to the
1.419 raeburn 9573: optional roles filter, optional status filter
1.233 raeburn 9574:
9575: =cut
9576:
9577: ###############################################
9578: sub get_sections {
1.419 raeburn 9579: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9580: if (!defined($cdom) || !defined($cnum)) {
9581: my $cid = $env{'request.course.id'};
9582:
9583: return if (!defined($cid));
9584:
9585: $cdom = $env{'course.'.$cid.'.domain'};
9586: $cnum = $env{'course.'.$cid.'.num'};
9587: }
9588:
9589: my %sectioncount;
1.419 raeburn 9590: my $now = time;
1.240 albertel 9591:
1.1118 raeburn 9592: my $check_students = 1;
9593: my $only_students = 0;
9594: if (ref($possible_roles) eq 'ARRAY') {
9595: if (grep(/^st$/,@{$possible_roles})) {
9596: if (@{$possible_roles} == 1) {
9597: $only_students = 1;
9598: }
9599: } else {
9600: $check_students = 0;
9601: }
9602: }
9603:
9604: if ($check_students) {
1.276 albertel 9605: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9606: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9607: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9608: my $start_index = &Apache::loncoursedata::CL_START();
9609: my $end_index = &Apache::loncoursedata::CL_END();
9610: my $status;
1.366 albertel 9611: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9612: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9613: $data->[$status_index],
9614: $data->[$start_index],
9615: $data->[$end_index]);
9616: if ($stu_status eq 'Active') {
9617: $status = 'active';
9618: } elsif ($end < $now) {
9619: $status = 'previous';
9620: } elsif ($start > $now) {
9621: $status = 'future';
9622: }
9623: if ($section ne '-1' && $section !~ /^\s*$/) {
9624: if ((!defined($possible_status)) || (($status ne '') &&
9625: (grep/^\Q$status\E$/,@{$possible_status}))) {
9626: $sectioncount{$section}++;
9627: }
1.240 albertel 9628: }
9629: }
9630: }
1.1118 raeburn 9631: if ($only_students) {
9632: return %sectioncount;
9633: }
1.240 albertel 9634: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9635: foreach my $user (sort(keys(%courseroles))) {
9636: if ($user !~ /^(\w{2})/) { next; }
9637: my ($role) = ($user =~ /^(\w{2})/);
9638: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9639: my ($section,$status);
1.240 albertel 9640: if ($role eq 'cr' &&
9641: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9642: $section=$1;
9643: }
9644: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9645: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9646: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9647: if ($end == -1 && $start == -1) {
9648: next; #deleted role
9649: }
9650: if (!defined($possible_status)) {
9651: $sectioncount{$section}++;
9652: } else {
9653: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9654: $status = 'active';
9655: } elsif ($end < $now) {
9656: $status = 'future';
9657: } elsif ($start > $now) {
9658: $status = 'previous';
9659: }
9660: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9661: $sectioncount{$section}++;
9662: }
9663: }
1.233 raeburn 9664: }
1.366 albertel 9665: return %sectioncount;
1.233 raeburn 9666: }
9667:
1.274 raeburn 9668: ###############################################
1.294 raeburn 9669:
9670: =pod
1.405 albertel 9671:
9672: =item * &get_course_users()
9673:
1.275 raeburn 9674: Retrieves usernames:domains for users in the specified course
9675: with specific role(s), and access status.
9676:
9677: Incoming parameters:
1.277 albertel 9678: 1. course domain
9679: 2. course number
9680: 3. access status: users must have - either active,
1.275 raeburn 9681: previous, future, or all.
1.277 albertel 9682: 4. reference to array of permissible roles
1.288 raeburn 9683: 5. reference to array of section restrictions (optional)
9684: 6. reference to results object (hash of hashes).
9685: 7. reference to optional userdata hash
1.609 raeburn 9686: 8. reference to optional statushash
1.630 raeburn 9687: 9. flag if privileged users (except those set to unhide in
9688: course settings) should be excluded
1.609 raeburn 9689: Keys of top level results hash are roles.
1.275 raeburn 9690: Keys of inner hashes are username:domain, with
9691: values set to access type.
1.288 raeburn 9692: Optional userdata hash returns an array with arguments in the
9693: same order as loncoursedata::get_classlist() for student data.
9694:
1.609 raeburn 9695: Optional statushash returns
9696:
1.288 raeburn 9697: Entries for end, start, section and status are blank because
9698: of the possibility of multiple values for non-student roles.
9699:
1.275 raeburn 9700: =cut
1.405 albertel 9701:
1.275 raeburn 9702: ###############################################
1.405 albertel 9703:
1.275 raeburn 9704: sub get_course_users {
1.630 raeburn 9705: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9706: my %idx = ();
1.419 raeburn 9707: my %seclists;
1.288 raeburn 9708:
9709: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9710: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9711: $idx{end} = &Apache::loncoursedata::CL_END();
9712: $idx{start} = &Apache::loncoursedata::CL_START();
9713: $idx{id} = &Apache::loncoursedata::CL_ID();
9714: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9715: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9716: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9717:
1.290 albertel 9718: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9719: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9720: my $now = time;
1.277 albertel 9721: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9722: my $match = 0;
1.412 raeburn 9723: my $secmatch = 0;
1.419 raeburn 9724: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9725: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9726: if ($section eq '') {
9727: $section = 'none';
9728: }
1.291 albertel 9729: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9730: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9731: $secmatch = 1;
9732: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9733: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9734: $secmatch = 1;
9735: }
9736: } else {
1.419 raeburn 9737: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9738: $secmatch = 1;
9739: }
1.290 albertel 9740: }
1.412 raeburn 9741: if (!$secmatch) {
9742: next;
9743: }
1.419 raeburn 9744: }
1.275 raeburn 9745: if (defined($$types{'active'})) {
1.288 raeburn 9746: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9747: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9748: $match = 1;
1.275 raeburn 9749: }
9750: }
9751: if (defined($$types{'previous'})) {
1.609 raeburn 9752: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9753: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9754: $match = 1;
1.275 raeburn 9755: }
9756: }
9757: if (defined($$types{'future'})) {
1.609 raeburn 9758: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9759: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9760: $match = 1;
1.275 raeburn 9761: }
9762: }
1.609 raeburn 9763: if ($match) {
9764: push(@{$seclists{$student}},$section);
9765: if (ref($userdata) eq 'HASH') {
9766: $$userdata{$student} = $$classlist{$student};
9767: }
9768: if (ref($statushash) eq 'HASH') {
9769: $statushash->{$student}{'st'}{$section} = $status;
9770: }
1.288 raeburn 9771: }
1.275 raeburn 9772: }
9773: }
1.412 raeburn 9774: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9775: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9776: my $now = time;
1.609 raeburn 9777: my %displaystatus = ( previous => 'Expired',
9778: active => 'Active',
9779: future => 'Future',
9780: );
1.1121 raeburn 9781: my (%nothide,@possdoms);
1.630 raeburn 9782: if ($hidepriv) {
9783: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9784: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9785: if ($user !~ /:/) {
9786: $nothide{join(':',split(/[\@]/,$user))}=1;
9787: } else {
9788: $nothide{$user} = 1;
9789: }
9790: }
1.1121 raeburn 9791: my @possdoms = ($cdom);
9792: if ($coursehash{'checkforpriv'}) {
9793: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9794: }
1.630 raeburn 9795: }
1.439 raeburn 9796: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9797: my $match = 0;
1.412 raeburn 9798: my $secmatch = 0;
1.439 raeburn 9799: my $status;
1.412 raeburn 9800: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9801: $user =~ s/:$//;
1.439 raeburn 9802: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9803: if ($end == -1 || $start == -1) {
9804: next;
9805: }
9806: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9807: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9808: my ($uname,$udom) = split(/:/,$user);
9809: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9810: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9811: $secmatch = 1;
9812: } elsif ($usec eq '') {
1.420 albertel 9813: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9814: $secmatch = 1;
9815: }
9816: } else {
9817: if (grep(/^\Q$usec\E$/,@{$sections})) {
9818: $secmatch = 1;
9819: }
9820: }
9821: if (!$secmatch) {
9822: next;
9823: }
1.288 raeburn 9824: }
1.419 raeburn 9825: if ($usec eq '') {
9826: $usec = 'none';
9827: }
1.275 raeburn 9828: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9829: if ($hidepriv) {
1.1121 raeburn 9830: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9831: (!$nothide{$uname.':'.$udom})) {
9832: next;
9833: }
9834: }
1.503 raeburn 9835: if ($end > 0 && $end < $now) {
1.439 raeburn 9836: $status = 'previous';
9837: } elsif ($start > $now) {
9838: $status = 'future';
9839: } else {
9840: $status = 'active';
9841: }
1.277 albertel 9842: foreach my $type (keys(%{$types})) {
1.275 raeburn 9843: if ($status eq $type) {
1.420 albertel 9844: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9845: push(@{$$users{$role}{$user}},$type);
9846: }
1.288 raeburn 9847: $match = 1;
9848: }
9849: }
1.419 raeburn 9850: if (($match) && (ref($userdata) eq 'HASH')) {
9851: if (!exists($$userdata{$uname.':'.$udom})) {
9852: &get_user_info($udom,$uname,\%idx,$userdata);
9853: }
1.420 albertel 9854: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9855: push(@{$seclists{$uname.':'.$udom}},$usec);
9856: }
1.609 raeburn 9857: if (ref($statushash) eq 'HASH') {
9858: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9859: }
1.275 raeburn 9860: }
9861: }
9862: }
9863: }
1.290 albertel 9864: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9865: if ((defined($cdom)) && (defined($cnum))) {
9866: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9867: if ( defined($csettings{'internal.courseowner'}) ) {
9868: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9869: next if ($owner eq '');
9870: my ($ownername,$ownerdom);
9871: if ($owner =~ /^([^:]+):([^:]+)$/) {
9872: $ownername = $1;
9873: $ownerdom = $2;
9874: } else {
9875: $ownername = $owner;
9876: $ownerdom = $cdom;
9877: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9878: }
9879: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9880: if (defined($userdata) &&
1.609 raeburn 9881: !exists($$userdata{$owner})) {
9882: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9883: if (!grep(/^none$/,@{$seclists{$owner}})) {
9884: push(@{$seclists{$owner}},'none');
9885: }
9886: if (ref($statushash) eq 'HASH') {
9887: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9888: }
1.290 albertel 9889: }
1.279 raeburn 9890: }
9891: }
9892: }
1.419 raeburn 9893: foreach my $user (keys(%seclists)) {
9894: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9895: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9896: }
1.275 raeburn 9897: }
9898: return;
9899: }
9900:
1.288 raeburn 9901: sub get_user_info {
9902: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9903: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9904: &plainname($uname,$udom,'lastname');
1.291 albertel 9905: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9906: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9907: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9908: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9909: return;
9910: }
1.275 raeburn 9911:
1.472 raeburn 9912: ###############################################
9913:
9914: =pod
9915:
9916: =item * &get_user_quota()
9917:
1.1134 raeburn 9918: Retrieves quota assigned for storage of user files.
9919: Default is to report quota for portfolio files.
1.472 raeburn 9920:
9921: Incoming parameters:
9922: 1. user's username
9923: 2. user's domain
1.1134 raeburn 9924: 3. quota name - portfolio, author, or course
1.1136 raeburn 9925: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9926: 4. crstype - official, unofficial, textbook, placement or community,
9927: if quota name is course
1.472 raeburn 9928:
9929: Returns:
1.1163 raeburn 9930: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9931: 2. (Optional) Type of setting: custom or default
9932: (individually assigned or default for user's
9933: institutional status).
9934: 3. (Optional) - User's institutional status (e.g., faculty, staff
9935: or student - types as defined in localenroll::inst_usertypes
9936: for user's domain, which determines default quota for user.
9937: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9938:
9939: If a value has been stored in the user's environment,
1.536 raeburn 9940: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9941: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9942:
9943: =cut
9944:
9945: ###############################################
9946:
9947:
9948: sub get_user_quota {
1.1136 raeburn 9949: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9950: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9951: if (!defined($udom)) {
9952: $udom = $env{'user.domain'};
9953: }
9954: if (!defined($uname)) {
9955: $uname = $env{'user.name'};
9956: }
9957: if (($udom eq '' || $uname eq '') ||
9958: ($udom eq 'public') && ($uname eq 'public')) {
9959: $quota = 0;
1.536 raeburn 9960: $quotatype = 'default';
9961: $defquota = 0;
1.472 raeburn 9962: } else {
1.536 raeburn 9963: my $inststatus;
1.1134 raeburn 9964: if ($quotaname eq 'course') {
9965: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9966: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9967: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9968: } else {
9969: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9970: $quota = $cenv{'internal.uploadquota'};
9971: }
1.536 raeburn 9972: } else {
1.1134 raeburn 9973: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9974: if ($quotaname eq 'author') {
9975: $quota = $env{'environment.authorquota'};
9976: } else {
9977: $quota = $env{'environment.portfolioquota'};
9978: }
9979: $inststatus = $env{'environment.inststatus'};
9980: } else {
9981: my %userenv =
9982: &Apache::lonnet::get('environment',['portfolioquota',
9983: 'authorquota','inststatus'],$udom,$uname);
9984: my ($tmp) = keys(%userenv);
9985: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9986: if ($quotaname eq 'author') {
9987: $quota = $userenv{'authorquota'};
9988: } else {
9989: $quota = $userenv{'portfolioquota'};
9990: }
9991: $inststatus = $userenv{'inststatus'};
9992: } else {
9993: undef(%userenv);
9994: }
9995: }
9996: }
9997: if ($quota eq '' || wantarray) {
9998: if ($quotaname eq 'course') {
9999: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10000: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10001: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10002: ($crstype eq 'placement')) {
1.1136 raeburn 10003: $defquota = $domdefs{$crstype.'quota'};
10004: }
10005: if ($defquota eq '') {
10006: $defquota = 500;
10007: }
1.1134 raeburn 10008: } else {
10009: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10010: }
10011: if ($quota eq '') {
10012: $quota = $defquota;
10013: $quotatype = 'default';
10014: } else {
10015: $quotatype = 'custom';
10016: }
1.472 raeburn 10017: }
10018: }
1.536 raeburn 10019: if (wantarray) {
10020: return ($quota,$quotatype,$settingstatus,$defquota);
10021: } else {
10022: return $quota;
10023: }
1.472 raeburn 10024: }
10025:
10026: ###############################################
10027:
10028: =pod
10029:
10030: =item * &default_quota()
10031:
1.536 raeburn 10032: Retrieves default quota assigned for storage of user portfolio files,
10033: given an (optional) user's institutional status.
1.472 raeburn 10034:
10035: Incoming parameters:
1.1142 raeburn 10036:
1.472 raeburn 10037: 1. domain
1.536 raeburn 10038: 2. (Optional) institutional status(es). This is a : separated list of
10039: status types (e.g., faculty, staff, student etc.)
10040: which apply to the user for whom the default is being retrieved.
10041: If the institutional status string in undefined, the domain
1.1134 raeburn 10042: default quota will be returned.
10043: 3. quota name - portfolio, author, or course
10044: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10045:
10046: Returns:
1.1142 raeburn 10047:
1.1163 raeburn 10048: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10049: 2. (Optional) institutional type which determined the value of the
10050: default quota.
1.472 raeburn 10051:
10052: If a value has been stored in the domain's configuration db,
10053: it will return that, otherwise it returns 20 (for backwards
10054: compatibility with domains which have not set up a configuration
1.1163 raeburn 10055: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10056:
1.536 raeburn 10057: If the user's status includes multiple types (e.g., staff and student),
10058: the largest default quota which applies to the user determines the
10059: default quota returned.
10060:
1.472 raeburn 10061: =cut
10062:
10063: ###############################################
10064:
10065:
10066: sub default_quota {
1.1134 raeburn 10067: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10068: my ($defquota,$settingstatus);
10069: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10070: ['quotas'],$udom);
1.1134 raeburn 10071: my $key = 'defaultquota';
10072: if ($quotaname eq 'author') {
10073: $key = 'authorquota';
10074: }
1.622 raeburn 10075: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10076: if ($inststatus ne '') {
1.765 raeburn 10077: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10078: foreach my $item (@statuses) {
1.1134 raeburn 10079: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10080: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10081: if ($defquota eq '') {
1.1134 raeburn 10082: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10083: $settingstatus = $item;
1.1134 raeburn 10084: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10085: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10086: $settingstatus = $item;
10087: }
10088: }
1.1134 raeburn 10089: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10090: if ($quotahash{'quotas'}{$item} ne '') {
10091: if ($defquota eq '') {
10092: $defquota = $quotahash{'quotas'}{$item};
10093: $settingstatus = $item;
10094: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10095: $defquota = $quotahash{'quotas'}{$item};
10096: $settingstatus = $item;
10097: }
1.536 raeburn 10098: }
10099: }
10100: }
10101: }
10102: if ($defquota eq '') {
1.1134 raeburn 10103: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10104: $defquota = $quotahash{'quotas'}{$key}{'default'};
10105: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10106: $defquota = $quotahash{'quotas'}{'default'};
10107: }
1.536 raeburn 10108: $settingstatus = 'default';
1.1139 raeburn 10109: if ($defquota eq '') {
10110: if ($quotaname eq 'author') {
10111: $defquota = 500;
10112: }
10113: }
1.536 raeburn 10114: }
10115: } else {
10116: $settingstatus = 'default';
1.1134 raeburn 10117: if ($quotaname eq 'author') {
10118: $defquota = 500;
10119: } else {
10120: $defquota = 20;
10121: }
1.536 raeburn 10122: }
10123: if (wantarray) {
10124: return ($defquota,$settingstatus);
1.472 raeburn 10125: } else {
1.536 raeburn 10126: return $defquota;
1.472 raeburn 10127: }
10128: }
10129:
1.1135 raeburn 10130: ###############################################
10131:
10132: =pod
10133:
1.1136 raeburn 10134: =item * &excess_filesize_warning()
1.1135 raeburn 10135:
10136: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10137: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10138: space to be exceeded.
1.1136 raeburn 10139:
10140: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10141: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10142:
1.1165 raeburn 10143: Inputs: 7
1.1136 raeburn 10144: 1. username or coursenum
1.1135 raeburn 10145: 2. domain
1.1136 raeburn 10146: 3. context ('author' or 'course')
1.1135 raeburn 10147: 4. filename of file for which action is being requested
10148: 5. filesize (kB) of file
10149: 6. action being taken: copy or upload.
1.1237 raeburn 10150: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10151:
10152: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10153: otherwise return null.
10154:
10155: =back
1.1135 raeburn 10156:
10157: =cut
10158:
1.1136 raeburn 10159: sub excess_filesize_warning {
1.1165 raeburn 10160: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10161: my $current_disk_usage = 0;
1.1165 raeburn 10162: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10163: if ($context eq 'author') {
10164: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10165: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10166: } else {
10167: foreach my $subdir ('docs','supplemental') {
10168: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10169: }
10170: }
1.1135 raeburn 10171: $disk_quota = int($disk_quota * 1000);
10172: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10173: return '<p class="LC_warning">'.
1.1135 raeburn 10174: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10175: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10176: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10177: $disk_quota,$current_disk_usage).
10178: '</p>';
10179: }
10180: return;
10181: }
10182:
10183: ###############################################
10184:
10185:
1.1136 raeburn 10186:
10187:
1.384 raeburn 10188: sub get_secgrprole_info {
10189: my ($cdom,$cnum,$needroles,$type) = @_;
10190: my %sections_count = &get_sections($cdom,$cnum);
10191: my @sections = (sort {$a <=> $b} keys(%sections_count));
10192: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10193: my @groups = sort(keys(%curr_groups));
10194: my $allroles = [];
10195: my $rolehash;
10196: my $accesshash = {
10197: active => 'Currently has access',
10198: future => 'Will have future access',
10199: previous => 'Previously had access',
10200: };
10201: if ($needroles) {
10202: $rolehash = {'all' => 'all'};
1.385 albertel 10203: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10204: if (&Apache::lonnet::error(%user_roles)) {
10205: undef(%user_roles);
10206: }
10207: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10208: my ($role)=split(/\:/,$item,2);
10209: if ($role eq 'cr') { next; }
10210: if ($role =~ /^cr/) {
10211: $$rolehash{$role} = (split('/',$role))[3];
10212: } else {
10213: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10214: }
10215: }
10216: foreach my $key (sort(keys(%{$rolehash}))) {
10217: push(@{$allroles},$key);
10218: }
10219: push (@{$allroles},'st');
10220: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10221: }
10222: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10223: }
10224:
1.555 raeburn 10225: sub user_picker {
1.1279 raeburn 10226: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10227: my $currdom = $dom;
1.1253 raeburn 10228: my @alldoms = &Apache::lonnet::all_domains();
10229: if (@alldoms == 1) {
10230: my %domsrch = &Apache::lonnet::get_dom('configuration',
10231: ['directorysrch'],$alldoms[0]);
10232: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10233: my $showdom = $domdesc;
10234: if ($showdom eq '') {
10235: $showdom = $dom;
10236: }
10237: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10238: if ((!$domsrch{'directorysrch'}{'available'}) &&
10239: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10240: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10241: }
10242: }
10243: }
1.555 raeburn 10244: my %curr_selected = (
10245: srchin => 'dom',
1.580 raeburn 10246: srchby => 'lastname',
1.555 raeburn 10247: );
10248: my $srchterm;
1.625 raeburn 10249: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10250: if ($srch->{'srchby'} ne '') {
10251: $curr_selected{'srchby'} = $srch->{'srchby'};
10252: }
10253: if ($srch->{'srchin'} ne '') {
10254: $curr_selected{'srchin'} = $srch->{'srchin'};
10255: }
10256: if ($srch->{'srchtype'} ne '') {
10257: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10258: }
10259: if ($srch->{'srchdomain'} ne '') {
10260: $currdom = $srch->{'srchdomain'};
10261: }
10262: $srchterm = $srch->{'srchterm'};
10263: }
1.1222 damieng 10264: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10265: 'usr' => 'Search criteria',
1.563 raeburn 10266: 'doma' => 'Domain/institution to search',
1.558 albertel 10267: 'uname' => 'username',
10268: 'lastname' => 'last name',
1.555 raeburn 10269: 'lastfirst' => 'last name, first name',
1.558 albertel 10270: 'crs' => 'in this course',
1.576 raeburn 10271: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10272: 'alc' => 'all LON-CAPA',
1.573 raeburn 10273: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10274: 'exact' => 'is',
10275: 'contains' => 'contains',
1.569 raeburn 10276: 'begins' => 'begins with',
1.1222 damieng 10277: );
10278: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10279: 'youm' => "You must include some text to search for.",
10280: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10281: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10282: 'yomc' => "You must choose a domain when using an institutional directory search.",
10283: 'ymcd' => "You must choose a domain when using a domain search.",
10284: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10285: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10286: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10287: );
1.1222 damieng 10288: &html_escape(\%html_lt);
10289: &js_escape(\%js_lt);
1.1255 raeburn 10290: my $domform;
1.1277 raeburn 10291: my $allow_blank = 1;
1.1255 raeburn 10292: if ($fixeddom) {
1.1277 raeburn 10293: $allow_blank = 0;
10294: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10295: } else {
1.1287 raeburn 10296: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10297: my ($trusted,$untrusted);
1.1287 raeburn 10298: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10299: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10300: } elsif ($context eq 'author') {
1.1288 raeburn 10301: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10302: } elsif ($context eq 'domain') {
1.1288 raeburn 10303: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10304: }
1.1288 raeburn 10305: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10306: }
1.563 raeburn 10307: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10308:
10309: my @srchins = ('crs','dom','alc','instd');
10310:
10311: foreach my $option (@srchins) {
10312: # FIXME 'alc' option unavailable until
10313: # loncreateuser::print_user_query_page()
10314: # has been completed.
10315: next if ($option eq 'alc');
1.880 raeburn 10316: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10317: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10318: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10319: if ($curr_selected{'srchin'} eq $option) {
10320: $srchinsel .= '
1.1222 damieng 10321: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10322: } else {
10323: $srchinsel .= '
1.1222 damieng 10324: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10325: }
1.555 raeburn 10326: }
1.563 raeburn 10327: $srchinsel .= "\n </select>\n";
1.555 raeburn 10328:
10329: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10330: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10331: if ($curr_selected{'srchby'} eq $option) {
10332: $srchbysel .= '
1.1222 damieng 10333: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10334: } else {
10335: $srchbysel .= '
1.1222 damieng 10336: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10337: }
10338: }
10339: $srchbysel .= "\n </select>\n";
10340:
10341: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10342: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10343: if ($curr_selected{'srchtype'} eq $option) {
10344: $srchtypesel .= '
1.1222 damieng 10345: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10346: } else {
10347: $srchtypesel .= '
1.1222 damieng 10348: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10349: }
10350: }
10351: $srchtypesel .= "\n </select>\n";
10352:
1.558 albertel 10353: my ($newuserscript,$new_user_create);
1.994 raeburn 10354: my $context_dom = $env{'request.role.domain'};
10355: if ($context eq 'requestcrs') {
10356: if ($env{'form.coursedom'} ne '') {
10357: $context_dom = $env{'form.coursedom'};
10358: }
10359: }
1.556 raeburn 10360: if ($forcenewuser) {
1.576 raeburn 10361: if (ref($srch) eq 'HASH') {
1.994 raeburn 10362: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10363: if ($cancreate) {
10364: $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>';
10365: } else {
1.799 bisitz 10366: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10367: my %usertypetext = (
10368: official => 'institutional',
10369: unofficial => 'non-institutional',
10370: );
1.799 bisitz 10371: $new_user_create = '<p class="LC_warning">'
10372: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10373: .' '
10374: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10375: ,'<a href="'.$helplink.'">','</a>')
10376: .'</p><br />';
1.627 raeburn 10377: }
1.576 raeburn 10378: }
10379: }
10380:
1.556 raeburn 10381: $newuserscript = <<"ENDSCRIPT";
10382:
1.570 raeburn 10383: function setSearch(createnew,callingForm) {
1.556 raeburn 10384: if (createnew == 1) {
1.570 raeburn 10385: for (var i=0; i<callingForm.srchby.length; i++) {
10386: if (callingForm.srchby.options[i].value == 'uname') {
10387: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10388: }
10389: }
1.570 raeburn 10390: for (var i=0; i<callingForm.srchin.length; i++) {
10391: if ( callingForm.srchin.options[i].value == 'dom') {
10392: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10393: }
10394: }
1.570 raeburn 10395: for (var i=0; i<callingForm.srchtype.length; i++) {
10396: if (callingForm.srchtype.options[i].value == 'exact') {
10397: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10398: }
10399: }
1.570 raeburn 10400: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10401: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10402: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10403: }
10404: }
10405: }
10406: }
10407: ENDSCRIPT
1.558 albertel 10408:
1.556 raeburn 10409: }
10410:
1.555 raeburn 10411: my $output = <<"END_BLOCK";
1.556 raeburn 10412: <script type="text/javascript">
1.824 bisitz 10413: // <![CDATA[
1.570 raeburn 10414: function validateEntry(callingForm) {
1.558 albertel 10415:
1.556 raeburn 10416: var checkok = 1;
1.558 albertel 10417: var srchin;
1.570 raeburn 10418: for (var i=0; i<callingForm.srchin.length; i++) {
10419: if ( callingForm.srchin[i].checked ) {
10420: srchin = callingForm.srchin[i].value;
1.558 albertel 10421: }
10422: }
10423:
1.570 raeburn 10424: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10425: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10426: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10427: var srchterm = callingForm.srchterm.value;
10428: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10429: var msg = "";
10430:
10431: if (srchterm == "") {
10432: checkok = 0;
1.1222 damieng 10433: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10434: }
10435:
1.569 raeburn 10436: if (srchtype== 'begins') {
10437: if (srchterm.length < 2) {
10438: checkok = 0;
1.1222 damieng 10439: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10440: }
10441: }
10442:
1.556 raeburn 10443: if (srchtype== 'contains') {
10444: if (srchterm.length < 3) {
10445: checkok = 0;
1.1222 damieng 10446: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10447: }
10448: }
10449: if (srchin == 'instd') {
10450: if (srchdomain == '') {
10451: checkok = 0;
1.1222 damieng 10452: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10453: }
10454: }
10455: if (srchin == 'dom') {
10456: if (srchdomain == '') {
10457: checkok = 0;
1.1222 damieng 10458: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10459: }
10460: }
10461: if (srchby == 'lastfirst') {
10462: if (srchterm.indexOf(",") == -1) {
10463: checkok = 0;
1.1222 damieng 10464: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10465: }
10466: if (srchterm.indexOf(",") == srchterm.length -1) {
10467: checkok = 0;
1.1222 damieng 10468: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10469: }
10470: }
10471: if (checkok == 0) {
1.1222 damieng 10472: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10473: return;
10474: }
10475: if (checkok == 1) {
1.570 raeburn 10476: callingForm.submit();
1.556 raeburn 10477: }
10478: }
10479:
10480: $newuserscript
10481:
1.824 bisitz 10482: // ]]>
1.556 raeburn 10483: </script>
1.558 albertel 10484:
10485: $new_user_create
10486:
1.555 raeburn 10487: END_BLOCK
1.558 albertel 10488:
1.876 raeburn 10489: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10490: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10491: $domform.
10492: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10493: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10494: $srchbysel.
10495: $srchtypesel.
10496: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10497: $srchinsel.
10498: &Apache::lonhtmlcommon::row_closure(1).
10499: &Apache::lonhtmlcommon::end_pick_box().
10500: '<br />';
1.1253 raeburn 10501: return ($output,1);
1.555 raeburn 10502: }
10503:
1.612 raeburn 10504: sub user_rule_check {
1.615 raeburn 10505: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10506: my ($response,%inst_response);
1.612 raeburn 10507: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10508: if (keys(%{$usershash}) > 1) {
10509: my (%by_username,%by_id,%userdoms);
10510: my $checkid;
10511: if (ref($checks) eq 'HASH') {
10512: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10513: $checkid = 1;
10514: }
10515: }
10516: foreach my $user (keys(%{$usershash})) {
10517: my ($uname,$udom) = split(/:/,$user);
10518: if ($checkid) {
10519: if (ref($usershash->{$user}) eq 'HASH') {
10520: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10521: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10522: $userdoms{$udom} = 1;
1.1227 raeburn 10523: if (ref($inst_results) eq 'HASH') {
10524: $inst_results->{$uname.':'.$udom} = {};
10525: }
1.1226 raeburn 10526: }
10527: }
10528: } else {
10529: $by_username{$udom}{$uname} = 1;
10530: $userdoms{$udom} = 1;
1.1227 raeburn 10531: if (ref($inst_results) eq 'HASH') {
10532: $inst_results->{$uname.':'.$udom} = {};
10533: }
1.1226 raeburn 10534: }
10535: }
10536: foreach my $udom (keys(%userdoms)) {
10537: if (!$got_rules->{$udom}) {
10538: my %domconfig = &Apache::lonnet::get_dom('configuration',
10539: ['usercreation'],$udom);
10540: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10541: foreach my $item ('username','id') {
10542: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10543: $$curr_rules{$udom}{$item} =
10544: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10545: }
10546: }
10547: }
10548: $got_rules->{$udom} = 1;
10549: }
1.612 raeburn 10550: }
1.1226 raeburn 10551: if ($checkid) {
10552: foreach my $udom (keys(%by_id)) {
10553: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10554: if ($outcome eq 'ok') {
1.1227 raeburn 10555: foreach my $id (keys(%{$by_id{$udom}})) {
10556: my $uname = $by_id{$udom}{$id};
10557: $inst_response{$uname.':'.$udom} = $outcome;
10558: }
1.1226 raeburn 10559: if (ref($results) eq 'HASH') {
10560: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10561: if (exists($inst_response{$uname.':'.$udom})) {
10562: $inst_response{$uname.':'.$udom} = $outcome;
10563: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10564: }
1.1226 raeburn 10565: }
10566: }
10567: }
1.612 raeburn 10568: }
1.615 raeburn 10569: } else {
1.1226 raeburn 10570: foreach my $udom (keys(%by_username)) {
10571: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10572: if ($outcome eq 'ok') {
1.1227 raeburn 10573: foreach my $uname (keys(%{$by_username{$udom}})) {
10574: $inst_response{$uname.':'.$udom} = $outcome;
10575: }
1.1226 raeburn 10576: if (ref($results) eq 'HASH') {
10577: foreach my $uname (keys(%{$results})) {
10578: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10579: }
10580: }
10581: }
10582: }
1.612 raeburn 10583: }
1.1226 raeburn 10584: } elsif (keys(%{$usershash}) == 1) {
10585: my $user = (keys(%{$usershash}))[0];
10586: my ($uname,$udom) = split(/:/,$user);
10587: if (($udom ne '') && ($uname ne '')) {
10588: if (ref($usershash->{$user}) eq 'HASH') {
10589: if (ref($checks) eq 'HASH') {
10590: if (defined($checks->{'username'})) {
10591: ($inst_response{$user},%{$inst_results->{$user}}) =
10592: &Apache::lonnet::get_instuser($udom,$uname);
10593: } elsif (defined($checks->{'id'})) {
10594: if ($usershash->{$user}->{'id'} ne '') {
10595: ($inst_response{$user},%{$inst_results->{$user}}) =
10596: &Apache::lonnet::get_instuser($udom,undef,
10597: $usershash->{$user}->{'id'});
10598: } else {
10599: ($inst_response{$user},%{$inst_results->{$user}}) =
10600: &Apache::lonnet::get_instuser($udom,$uname);
10601: }
1.585 raeburn 10602: }
1.1226 raeburn 10603: } else {
10604: ($inst_response{$user},%{$inst_results->{$user}}) =
10605: &Apache::lonnet::get_instuser($udom,$uname);
10606: return;
10607: }
10608: if (!$got_rules->{$udom}) {
10609: my %domconfig = &Apache::lonnet::get_dom('configuration',
10610: ['usercreation'],$udom);
10611: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10612: foreach my $item ('username','id') {
10613: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10614: $$curr_rules{$udom}{$item} =
10615: $domconfig{'usercreation'}{$item.'_rule'};
10616: }
10617: }
10618: }
10619: $got_rules->{$udom} = 1;
1.585 raeburn 10620: }
10621: }
1.1226 raeburn 10622: } else {
10623: return;
10624: }
10625: } else {
10626: return;
10627: }
10628: foreach my $user (keys(%{$usershash})) {
10629: my ($uname,$udom) = split(/:/,$user);
10630: next if (($udom eq '') || ($uname eq ''));
10631: my $id;
1.1227 raeburn 10632: if (ref($inst_results) eq 'HASH') {
10633: if (ref($inst_results->{$user}) eq 'HASH') {
10634: $id = $inst_results->{$user}->{'id'};
10635: }
10636: }
10637: if ($id eq '') {
10638: if (ref($usershash->{$user})) {
10639: $id = $usershash->{$user}->{'id'};
10640: }
1.585 raeburn 10641: }
1.612 raeburn 10642: foreach my $item (keys(%{$checks})) {
10643: if (ref($$curr_rules{$udom}) eq 'HASH') {
10644: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10645: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10646: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10647: $$curr_rules{$udom}{$item});
1.612 raeburn 10648: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10649: if ($rule_check{$rule}) {
10650: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10651: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10652: if (ref($inst_results) eq 'HASH') {
10653: if (ref($inst_results->{$user}) eq 'HASH') {
10654: if (keys(%{$inst_results->{$user}}) == 0) {
10655: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10656: } elsif ($item eq 'id') {
10657: if ($inst_results->{$user}->{'id'} eq '') {
10658: $$alerts{$item}{$udom}{$uname} = 1;
10659: }
1.615 raeburn 10660: }
1.612 raeburn 10661: }
10662: }
1.615 raeburn 10663: }
10664: last;
1.585 raeburn 10665: }
10666: }
10667: }
10668: }
10669: }
10670: }
10671: }
10672: }
1.612 raeburn 10673: return;
10674: }
10675:
10676: sub user_rule_formats {
10677: my ($domain,$domdesc,$curr_rules,$check) = @_;
10678: my %text = (
10679: 'username' => 'Usernames',
10680: 'id' => 'IDs',
10681: );
10682: my $output;
10683: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10684: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10685: if (@{$ruleorder} > 0) {
1.1102 raeburn 10686: $output = '<br />'.
10687: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10688: '<span class="LC_cusr_emph">','</span>',$domdesc).
10689: ' <ul>';
1.612 raeburn 10690: foreach my $rule (@{$ruleorder}) {
10691: if (ref($curr_rules) eq 'ARRAY') {
10692: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10693: if (ref($rules->{$rule}) eq 'HASH') {
10694: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10695: $rules->{$rule}{'desc'}.'</li>';
10696: }
10697: }
10698: }
10699: }
10700: $output .= '</ul>';
10701: }
10702: }
10703: return $output;
10704: }
10705:
10706: sub instrule_disallow_msg {
1.615 raeburn 10707: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10708: my $response;
10709: my %text = (
10710: item => 'username',
10711: items => 'usernames',
10712: match => 'matches',
10713: do => 'does',
10714: action => 'a username',
10715: one => 'one',
10716: );
10717: if ($count > 1) {
10718: $text{'item'} = 'usernames';
10719: $text{'match'} ='match';
10720: $text{'do'} = 'do';
10721: $text{'action'} = 'usernames',
10722: $text{'one'} = 'ones';
10723: }
10724: if ($checkitem eq 'id') {
10725: $text{'items'} = 'IDs';
10726: $text{'item'} = 'ID';
10727: $text{'action'} = 'an ID';
1.615 raeburn 10728: if ($count > 1) {
10729: $text{'item'} = 'IDs';
10730: $text{'action'} = 'IDs';
10731: }
1.612 raeburn 10732: }
1.674 bisitz 10733: $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 10734: if ($mode eq 'upload') {
10735: if ($checkitem eq 'username') {
10736: $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'}.");
10737: } elsif ($checkitem eq 'id') {
1.674 bisitz 10738: $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 10739: }
1.669 raeburn 10740: } elsif ($mode eq 'selfcreate') {
10741: if ($checkitem eq 'id') {
10742: $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.");
10743: }
1.615 raeburn 10744: } else {
10745: if ($checkitem eq 'username') {
10746: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10747: } elsif ($checkitem eq 'id') {
10748: $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.");
10749: }
1.612 raeburn 10750: }
10751: return $response;
1.585 raeburn 10752: }
10753:
1.624 raeburn 10754: sub personal_data_fieldtitles {
10755: my %fieldtitles = &Apache::lonlocal::texthash (
10756: id => 'Student/Employee ID',
10757: permanentemail => 'E-mail address',
10758: lastname => 'Last Name',
10759: firstname => 'First Name',
10760: middlename => 'Middle Name',
10761: generation => 'Generation',
10762: gen => 'Generation',
1.765 raeburn 10763: inststatus => 'Affiliation',
1.624 raeburn 10764: );
10765: return %fieldtitles;
10766: }
10767:
1.642 raeburn 10768: sub sorted_inst_types {
10769: my ($dom) = @_;
1.1185 raeburn 10770: my ($usertypes,$order);
10771: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10772: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10773: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10774: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10775: } else {
10776: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10777: }
1.642 raeburn 10778: my $othertitle = &mt('All users');
10779: if ($env{'request.course.id'}) {
1.668 raeburn 10780: $othertitle = &mt('Any users');
1.642 raeburn 10781: }
10782: my @types;
10783: if (ref($order) eq 'ARRAY') {
10784: @types = @{$order};
10785: }
10786: if (@types == 0) {
10787: if (ref($usertypes) eq 'HASH') {
10788: @types = sort(keys(%{$usertypes}));
10789: }
10790: }
10791: if (keys(%{$usertypes}) > 0) {
10792: $othertitle = &mt('Other users');
10793: }
10794: return ($othertitle,$usertypes,\@types);
10795: }
10796:
1.645 raeburn 10797: sub get_institutional_codes {
10798: my ($settings,$allcourses,$LC_code) = @_;
10799: # Get complete list of course sections to update
10800: my @currsections = ();
10801: my @currxlists = ();
10802: my $coursecode = $$settings{'internal.coursecode'};
10803:
10804: if ($$settings{'internal.sectionnums'} ne '') {
10805: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10806: }
10807:
10808: if ($$settings{'internal.crosslistings'} ne '') {
10809: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10810: }
10811:
10812: if (@currxlists > 0) {
10813: foreach (@currxlists) {
10814: if (m/^([^:]+):(\w*)$/) {
10815: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10816: push(@{$allcourses},$1);
1.645 raeburn 10817: $$LC_code{$1} = $2;
10818: }
10819: }
10820: }
10821: }
10822:
10823: if (@currsections > 0) {
10824: foreach (@currsections) {
10825: if (m/^(\w+):(\w*)$/) {
10826: my $sec = $coursecode.$1;
10827: my $lc_sec = $2;
10828: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10829: push(@{$allcourses},$sec);
1.645 raeburn 10830: $$LC_code{$sec} = $lc_sec;
10831: }
10832: }
10833: }
10834: }
10835: return;
10836: }
10837:
1.971 raeburn 10838: sub get_standard_codeitems {
10839: return ('Year','Semester','Department','Number','Section');
10840: }
10841:
1.112 bowersj2 10842: =pod
10843:
1.780 raeburn 10844: =head1 Slot Helpers
10845:
10846: =over 4
10847:
10848: =item * sorted_slots()
10849:
1.1040 raeburn 10850: Sorts an array of slot names in order of an optional sort key,
10851: default sort is by slot start time (earliest first).
1.780 raeburn 10852:
10853: Inputs:
10854:
10855: =over 4
10856:
10857: slotsarr - Reference to array of unsorted slot names.
10858:
10859: slots - Reference to hash of hash, where outer hash keys are slot names.
10860:
1.1040 raeburn 10861: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10862:
1.549 albertel 10863: =back
10864:
1.780 raeburn 10865: Returns:
10866:
10867: =over 4
10868:
1.1040 raeburn 10869: sorted - An array of slot names sorted by a specified sort key
10870: (default sort key is start time of the slot).
1.780 raeburn 10871:
10872: =back
10873:
10874: =cut
10875:
10876:
10877: sub sorted_slots {
1.1040 raeburn 10878: my ($slotsarr,$slots,$sortkey) = @_;
10879: if ($sortkey eq '') {
10880: $sortkey = 'starttime';
10881: }
1.780 raeburn 10882: my @sorted;
10883: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10884: @sorted =
10885: sort {
10886: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10887: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10888: }
10889: if (ref($slots->{$a})) { return -1;}
10890: if (ref($slots->{$b})) { return 1;}
10891: return 0;
10892: } @{$slotsarr};
10893: }
10894: return @sorted;
10895: }
10896:
1.1040 raeburn 10897: =pod
10898:
10899: =item * get_future_slots()
10900:
10901: Inputs:
10902:
10903: =over 4
10904:
10905: cnum - course number
10906:
10907: cdom - course domain
10908:
10909: now - current UNIX time
10910:
10911: symb - optional symb
10912:
10913: =back
10914:
10915: Returns:
10916:
10917: =over 4
10918:
10919: sorted_reservable - ref to array of student_schedulable slots currently
10920: reservable, ordered by end date of reservation period.
10921:
10922: reservable_now - ref to hash of student_schedulable slots currently
10923: reservable.
10924:
10925: Keys in inner hash are:
10926: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10927: (b) endreserve: end date of reservation period.
10928: (c) uniqueperiod: start,end dates when slot is to be uniquely
10929: selected.
1.1040 raeburn 10930:
10931: sorted_future - ref to array of student_schedulable slots reservable in
10932: the future, ordered by start date of reservation period.
10933:
10934: future_reservable - ref to hash of student_schedulable slots reservable
10935: in the future.
10936:
10937: Keys in inner hash are:
10938: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10939: (b) startreserve: start date of reservation period.
10940: (c) uniqueperiod: start,end dates when slot is to be uniquely
10941: selected.
1.1040 raeburn 10942:
10943: =back
10944:
10945: =cut
10946:
10947: sub get_future_slots {
10948: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10949: my $map;
10950: if ($symb) {
10951: ($map) = &Apache::lonnet::decode_symb($symb);
10952: }
1.1040 raeburn 10953: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10954: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10955: foreach my $slot (keys(%slots)) {
10956: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10957: if ($symb) {
1.1229 raeburn 10958: if ($slots{$slot}->{'symb'} ne '') {
10959: my $canuse;
10960: my %oksymbs;
10961: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10962: map { $oksymbs{$_} = 1; } @slotsymbs;
10963: if ($oksymbs{$symb}) {
10964: $canuse = 1;
10965: } else {
10966: foreach my $item (@slotsymbs) {
10967: if ($item =~ /\.(page|sequence)$/) {
10968: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10969: if (($map ne '') && ($map eq $sloturl)) {
10970: $canuse = 1;
10971: last;
10972: }
10973: }
10974: }
10975: }
10976: next unless ($canuse);
10977: }
1.1040 raeburn 10978: }
10979: if (($slots{$slot}->{'starttime'} > $now) &&
10980: ($slots{$slot}->{'endtime'} > $now)) {
10981: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10982: my $userallowed = 0;
10983: if ($slots{$slot}->{'allowedsections'}) {
10984: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10985: if (!defined($env{'request.role.sec'})
10986: && grep(/^No section assigned$/,@allowed_sec)) {
10987: $userallowed=1;
10988: } else {
10989: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10990: $userallowed=1;
10991: }
10992: }
10993: unless ($userallowed) {
10994: if (defined($env{'request.course.groups'})) {
10995: my @groups = split(/:/,$env{'request.course.groups'});
10996: foreach my $group (@groups) {
10997: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10998: $userallowed=1;
10999: last;
11000: }
11001: }
11002: }
11003: }
11004: }
11005: if ($slots{$slot}->{'allowedusers'}) {
11006: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11007: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11008: if (grep(/^\Q$user\E$/,@allowed_users)) {
11009: $userallowed = 1;
11010: }
11011: }
11012: next unless($userallowed);
11013: }
11014: my $startreserve = $slots{$slot}->{'startreserve'};
11015: my $endreserve = $slots{$slot}->{'endreserve'};
11016: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11017: my $uniqueperiod;
11018: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11019: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11020: }
1.1040 raeburn 11021: if (($startreserve < $now) &&
11022: (!$endreserve || $endreserve > $now)) {
11023: my $lastres = $endreserve;
11024: if (!$lastres) {
11025: $lastres = $slots{$slot}->{'starttime'};
11026: }
11027: $reservable_now{$slot} = {
11028: symb => $symb,
1.1250 raeburn 11029: endreserve => $lastres,
11030: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11031: };
11032: } elsif (($startreserve > $now) &&
11033: (!$endreserve || $endreserve > $startreserve)) {
11034: $future_reservable{$slot} = {
11035: symb => $symb,
1.1250 raeburn 11036: startreserve => $startreserve,
11037: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11038: };
11039: }
11040: }
11041: }
11042: my @unsorted_reservable = keys(%reservable_now);
11043: if (@unsorted_reservable > 0) {
11044: @sorted_reservable =
11045: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11046: }
11047: my @unsorted_future = keys(%future_reservable);
11048: if (@unsorted_future > 0) {
11049: @sorted_future =
11050: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11051: }
11052: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11053: }
1.780 raeburn 11054:
11055: =pod
11056:
1.1057 foxr 11057: =back
11058:
1.549 albertel 11059: =head1 HTTP Helpers
11060:
11061: =over 4
11062:
1.648 raeburn 11063: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11064:
1.258 albertel 11065: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11066: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11067: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11068:
11069: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11070: $possible_names is an ref to an array of form element names. As an example:
11071: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11072: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11073:
11074: =cut
1.1 albertel 11075:
1.6 albertel 11076: sub get_unprocessed_cgi {
1.25 albertel 11077: my ($query,$possible_names)= @_;
1.26 matthew 11078: # $Apache::lonxml::debug=1;
1.356 albertel 11079: foreach my $pair (split(/&/,$query)) {
11080: my ($name, $value) = split(/=/,$pair);
1.369 www 11081: $name = &unescape($name);
1.25 albertel 11082: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11083: $value =~ tr/+/ /;
11084: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11085: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11086: }
1.16 harris41 11087: }
1.6 albertel 11088: }
11089:
1.112 bowersj2 11090: =pod
11091:
1.648 raeburn 11092: =item * &cacheheader()
1.112 bowersj2 11093:
11094: returns cache-controlling header code
11095:
11096: =cut
11097:
1.7 albertel 11098: sub cacheheader {
1.258 albertel 11099: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11100: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11101: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11102: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11103: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11104: return $output;
1.7 albertel 11105: }
11106:
1.112 bowersj2 11107: =pod
11108:
1.648 raeburn 11109: =item * &no_cache($r)
1.112 bowersj2 11110:
11111: specifies header code to not have cache
11112:
11113: =cut
11114:
1.9 albertel 11115: sub no_cache {
1.216 albertel 11116: my ($r) = @_;
11117: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11118: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11119: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11120: $r->no_cache(1);
11121: $r->header_out("Expires" => $date);
11122: $r->header_out("Pragma" => "no-cache");
1.123 www 11123: }
11124:
11125: sub content_type {
1.181 albertel 11126: my ($r,$type,$charset) = @_;
1.299 foxr 11127: if ($r) {
11128: # Note that printout.pl calls this with undef for $r.
11129: &no_cache($r);
11130: }
1.258 albertel 11131: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11132: unless ($charset) {
11133: $charset=&Apache::lonlocal::current_encoding;
11134: }
11135: if ($charset) { $type.='; charset='.$charset; }
11136: if ($r) {
11137: $r->content_type($type);
11138: } else {
11139: print("Content-type: $type\n\n");
11140: }
1.9 albertel 11141: }
1.25 albertel 11142:
1.112 bowersj2 11143: =pod
11144:
1.648 raeburn 11145: =item * &add_to_env($name,$value)
1.112 bowersj2 11146:
1.258 albertel 11147: adds $name to the %env hash with value
1.112 bowersj2 11148: $value, if $name already exists, the entry is converted to an array
11149: reference and $value is added to the array.
11150:
11151: =cut
11152:
1.25 albertel 11153: sub add_to_env {
11154: my ($name,$value)=@_;
1.258 albertel 11155: if (defined($env{$name})) {
11156: if (ref($env{$name})) {
1.25 albertel 11157: #already have multiple values
1.258 albertel 11158: push(@{ $env{$name} },$value);
1.25 albertel 11159: } else {
11160: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11161: my $first=$env{$name};
11162: undef($env{$name});
11163: push(@{ $env{$name} },$first,$value);
1.25 albertel 11164: }
11165: } else {
1.258 albertel 11166: $env{$name}=$value;
1.25 albertel 11167: }
1.31 albertel 11168: }
1.149 albertel 11169:
11170: =pod
11171:
1.648 raeburn 11172: =item * &get_env_multiple($name)
1.149 albertel 11173:
1.258 albertel 11174: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11175: values may be defined and end up as an array ref.
11176:
11177: returns an array of values
11178:
11179: =cut
11180:
11181: sub get_env_multiple {
11182: my ($name) = @_;
11183: my @values;
1.258 albertel 11184: if (defined($env{$name})) {
1.149 albertel 11185: # exists is it an array
1.258 albertel 11186: if (ref($env{$name})) {
11187: @values=@{ $env{$name} };
1.149 albertel 11188: } else {
1.258 albertel 11189: $values[0]=$env{$name};
1.149 albertel 11190: }
11191: }
11192: return(@values);
11193: }
11194:
1.1249 damieng 11195: # Looks at given dependencies, and returns something depending on the context.
11196: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11197: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11198: # For all other contexts, returns ($output, $counter, $numpathchg).
11199: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11200: # $counter: integer with the number of existing dependencies when no HTML output is returned, and the number of missing dependencies when an HTML output is returned.
11201: # $numpathchg: integer with the number of cleaned up dependency paths.
11202: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11203: # \%mapping: hash reference clean path -> original path for all dependencies.
11204: # @param {string} actionurl - The path to the handler, indicative of the context.
11205: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11206: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11207: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11208: # @param {hash reference} args - More parameters ! Possible keys: error_on_invalid_names (boolean), ignore_remote_references (boolean), current_path (string), docs_url (string), docs_title (string), context (string)
11209: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11210: sub ask_for_embedded_content {
1.1249 damieng 11211: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11212: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11213: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11214: %currsubfile,%unused,$rem);
1.1071 raeburn 11215: my $counter = 0;
11216: my $numnew = 0;
1.987 raeburn 11217: my $numremref = 0;
11218: my $numinvalid = 0;
11219: my $numpathchg = 0;
11220: my $numexisting = 0;
1.1071 raeburn 11221: my $numunused = 0;
11222: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11223: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11224: my $heading = &mt('Upload embedded files');
11225: my $buttontext = &mt('Upload');
11226:
1.1249 damieng 11227: # fills these variables based on the context:
11228: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11229: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11230: if ($env{'request.course.id'}) {
1.1123 raeburn 11231: if ($actionurl eq '/adm/dependencies') {
11232: $navmap = Apache::lonnavmaps::navmap->new();
11233: }
11234: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11235: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11236: }
1.1123 raeburn 11237: if (($actionurl eq '/adm/portfolio') ||
11238: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11239: my $current_path='/';
11240: if ($env{'form.currentpath'}) {
11241: $current_path = $env{'form.currentpath'};
11242: }
11243: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11244: $udom = $cdom;
11245: $uname = $cnum;
1.984 raeburn 11246: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11247: } else {
11248: $udom = $env{'user.domain'};
11249: $uname = $env{'user.name'};
11250: $url = '/userfiles/portfolio';
11251: }
1.987 raeburn 11252: $toplevel = $url.'/';
1.984 raeburn 11253: $url .= $current_path;
11254: $getpropath = 1;
1.987 raeburn 11255: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11256: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11257: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11258: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11259: $toplevel = $url;
1.984 raeburn 11260: if ($rest ne '') {
1.987 raeburn 11261: $url .= $rest;
11262: }
11263: } elsif ($actionurl eq '/adm/coursedocs') {
11264: if (ref($args) eq 'HASH') {
1.1071 raeburn 11265: $url = $args->{'docs_url'};
11266: $toplevel = $url;
1.1084 raeburn 11267: if ($args->{'context'} eq 'paste') {
11268: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11269: ($path) =
11270: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11271: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11272: $fileloc =~ s{^/}{};
11273: }
1.1071 raeburn 11274: }
1.1084 raeburn 11275: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11276: if ($env{'request.course.id'} ne '') {
11277: if (ref($args) eq 'HASH') {
11278: $url = $args->{'docs_url'};
11279: $title = $args->{'docs_title'};
1.1126 raeburn 11280: $toplevel = $url;
11281: unless ($toplevel =~ m{^/}) {
11282: $toplevel = "/$url";
11283: }
1.1085 raeburn 11284: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11285: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11286: $path = $1;
11287: } else {
11288: ($path) =
11289: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11290: }
1.1195 raeburn 11291: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11292: $fileloc = $toplevel;
11293: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11294: my ($udom,$uname,$fname) =
11295: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11296: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11297: } else {
11298: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11299: }
1.1071 raeburn 11300: $fileloc =~ s{^/}{};
11301: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11302: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11303: }
1.987 raeburn 11304: }
1.1123 raeburn 11305: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11306: $udom = $cdom;
11307: $uname = $cnum;
11308: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11309: $toplevel = $url;
11310: $path = $url;
11311: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11312: $fileloc =~ s{^/}{};
1.987 raeburn 11313: }
1.1249 damieng 11314:
11315: # parses the dependency paths to get some info
11316: # fills $newfiles, $mapping, $subdependencies, $dependencies
11317: # $newfiles: hash URL -> 1 for new files or external URLs
11318: # (will be completed later)
11319: # $mapping:
11320: # for external URLs: external URL -> external URL
11321: # for relative paths: clean path -> original path
11322: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11323: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11324: foreach my $file (keys(%{$allfiles})) {
11325: my $embed_file;
11326: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11327: $embed_file = $1;
11328: } else {
11329: $embed_file = $file;
11330: }
1.1158 raeburn 11331: my ($absolutepath,$cleaned_file);
11332: if ($embed_file =~ m{^\w+://}) {
11333: $cleaned_file = $embed_file;
1.1147 raeburn 11334: $newfiles{$cleaned_file} = 1;
11335: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11336: } else {
1.1158 raeburn 11337: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11338: if ($embed_file =~ m{^/}) {
11339: $absolutepath = $embed_file;
11340: }
1.1147 raeburn 11341: if ($cleaned_file =~ m{/}) {
11342: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11343: $path = &check_for_traversal($path,$url,$toplevel);
11344: my $item = $fname;
11345: if ($path ne '') {
11346: $item = $path.'/'.$fname;
11347: $subdependencies{$path}{$fname} = 1;
11348: } else {
11349: $dependencies{$item} = 1;
11350: }
11351: if ($absolutepath) {
11352: $mapping{$item} = $absolutepath;
11353: } else {
11354: $mapping{$item} = $embed_file;
11355: }
11356: } else {
11357: $dependencies{$embed_file} = 1;
11358: if ($absolutepath) {
1.1147 raeburn 11359: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11360: } else {
1.1147 raeburn 11361: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11362: }
11363: }
1.984 raeburn 11364: }
11365: }
1.1249 damieng 11366:
11367: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11368: # and lists
11369: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11370: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11371: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11372: # the path had to be cleaned up
11373: # $existing: hash clean path -> 1 if the file exists
11374: # $numexisting: number of keys in $existing
11375: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11376: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11377: # dependency subdirectories that are
11378: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11379: my $dirptr = 16384;
1.984 raeburn 11380: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11381: $currsubfile{$path} = {};
1.1123 raeburn 11382: if (($actionurl eq '/adm/portfolio') ||
11383: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11384: my ($sublistref,$listerror) =
11385: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11386: if (ref($sublistref) eq 'ARRAY') {
11387: foreach my $line (@{$sublistref}) {
11388: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11389: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11390: }
1.984 raeburn 11391: }
1.987 raeburn 11392: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11393: if (opendir(my $dir,$url.'/'.$path)) {
11394: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11395: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11396: }
1.1084 raeburn 11397: } elsif (($actionurl eq '/adm/dependencies') ||
11398: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11399: ($args->{'context'} eq 'paste')) ||
11400: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11401: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11402: my $dir;
11403: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11404: $dir = $fileloc;
11405: } else {
11406: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11407: }
1.1071 raeburn 11408: if ($dir ne '') {
11409: my ($sublistref,$listerror) =
11410: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11411: if (ref($sublistref) eq 'ARRAY') {
11412: foreach my $line (@{$sublistref}) {
11413: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11414: undef,$mtime)=split(/\&/,$line,12);
11415: unless (($testdir&$dirptr) ||
11416: ($file_name =~ /^\.\.?$/)) {
11417: $currsubfile{$path}{$file_name} = [$size,$mtime];
11418: }
11419: }
11420: }
11421: }
1.984 raeburn 11422: }
11423: }
11424: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11425: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11426: my $item = $path.'/'.$file;
11427: unless ($mapping{$item} eq $item) {
11428: $pathchanges{$item} = 1;
11429: }
11430: $existing{$item} = 1;
11431: $numexisting ++;
11432: } else {
11433: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11434: }
11435: }
1.1071 raeburn 11436: if ($actionurl eq '/adm/dependencies') {
11437: foreach my $path (keys(%currsubfile)) {
11438: if (ref($currsubfile{$path}) eq 'HASH') {
11439: foreach my $file (keys(%{$currsubfile{$path}})) {
11440: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11441: next if (($rem ne '') &&
11442: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11443: (ref($navmap) &&
11444: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11445: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11446: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11447: $unused{$path.'/'.$file} = 1;
11448: }
11449: }
11450: }
11451: }
11452: }
1.984 raeburn 11453: }
1.1249 damieng 11454:
11455: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11456: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11457: my %currfile;
1.1123 raeburn 11458: if (($actionurl eq '/adm/portfolio') ||
11459: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11460: my ($dirlistref,$listerror) =
11461: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11462: if (ref($dirlistref) eq 'ARRAY') {
11463: foreach my $line (@{$dirlistref}) {
11464: my ($file_name,$rest) = split(/\&/,$line,2);
11465: $currfile{$file_name} = 1;
11466: }
1.984 raeburn 11467: }
1.987 raeburn 11468: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11469: if (opendir(my $dir,$url)) {
1.987 raeburn 11470: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11471: map {$currfile{$_} = 1;} @dir_list;
11472: }
1.1084 raeburn 11473: } elsif (($actionurl eq '/adm/dependencies') ||
11474: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11475: ($args->{'context'} eq 'paste')) ||
11476: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11477: if ($env{'request.course.id'} ne '') {
11478: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11479: if ($dir ne '') {
11480: my ($dirlistref,$listerror) =
11481: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11482: if (ref($dirlistref) eq 'ARRAY') {
11483: foreach my $line (@{$dirlistref}) {
11484: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11485: $size,undef,$mtime)=split(/\&/,$line,12);
11486: unless (($testdir&$dirptr) ||
11487: ($file_name =~ /^\.\.?$/)) {
11488: $currfile{$file_name} = [$size,$mtime];
11489: }
11490: }
11491: }
11492: }
11493: }
1.984 raeburn 11494: }
1.1249 damieng 11495: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11496: # are not in subdirectories, using $currfile
1.984 raeburn 11497: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11498: if (exists($currfile{$file})) {
1.987 raeburn 11499: unless ($mapping{$file} eq $file) {
11500: $pathchanges{$file} = 1;
11501: }
11502: $existing{$file} = 1;
11503: $numexisting ++;
11504: } else {
1.984 raeburn 11505: $newfiles{$file} = 1;
11506: }
11507: }
1.1071 raeburn 11508: foreach my $file (keys(%currfile)) {
11509: unless (($file eq $filename) ||
11510: ($file eq $filename.'.bak') ||
11511: ($dependencies{$file})) {
1.1085 raeburn 11512: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11513: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11514: next if (($rem ne '') &&
11515: (($env{"httpref.$rem".$file} ne '') ||
11516: (ref($navmap) &&
11517: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11518: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11519: ($navmap->getResourceByUrl($rem.$1)))))));
11520: }
1.1085 raeburn 11521: }
1.1071 raeburn 11522: $unused{$file} = 1;
11523: }
11524: }
1.1249 damieng 11525:
11526: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11527: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11528: ($args->{'context'} eq 'paste')) {
11529: $counter = scalar(keys(%existing));
11530: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11531: return ($output,$counter,$numpathchg,\%existing);
11532: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11533: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11534: $counter = scalar(keys(%existing));
11535: $numpathchg = scalar(keys(%pathchanges));
11536: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11537: }
1.1249 damieng 11538:
11539: # returns HTML otherwise, with dependency results and to ask for more uploads
11540:
11541: # $upload_output: missing dependencies (with upload form)
11542: # $modify_output: uploaded dependencies (in use)
11543: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11544: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11545: if ($actionurl eq '/adm/dependencies') {
11546: next if ($embed_file =~ m{^\w+://});
11547: }
1.660 raeburn 11548: $upload_output .= &start_data_table_row().
1.1123 raeburn 11549: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11550: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11551: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11552: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11553: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11554: }
1.1123 raeburn 11555: $upload_output .= '</td>';
1.1071 raeburn 11556: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11557: $upload_output.='<td align="right">'.
11558: '<span class="LC_info LC_fontsize_medium">'.
11559: &mt("URL points to web address").'</span>';
1.987 raeburn 11560: $numremref++;
1.660 raeburn 11561: } elsif ($args->{'error_on_invalid_names'}
11562: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11563: $upload_output.='<td align="right"><span class="LC_warning">'.
11564: &mt('Invalid characters').'</span>';
1.987 raeburn 11565: $numinvalid++;
1.660 raeburn 11566: } else {
1.1123 raeburn 11567: $upload_output .= '<td>'.
11568: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11569: $embed_file,\%mapping,
1.1071 raeburn 11570: $allfiles,$codebase,'upload');
11571: $counter ++;
11572: $numnew ++;
1.987 raeburn 11573: }
11574: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11575: }
11576: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11577: if ($actionurl eq '/adm/dependencies') {
11578: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11579: $modify_output .= &start_data_table_row().
11580: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11581: '<img src="'.&icon($embed_file).'" border="0" />'.
11582: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11583: '<td>'.$size.'</td>'.
11584: '<td>'.$mtime.'</td>'.
11585: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11586: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11587: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11588: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11589: &embedded_file_element('upload_embedded',$counter,
11590: $embed_file,\%mapping,
11591: $allfiles,$codebase,'modify').
11592: '</div></td>'.
11593: &end_data_table_row()."\n";
11594: $counter ++;
11595: } else {
11596: $upload_output .= &start_data_table_row().
1.1123 raeburn 11597: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11598: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11599: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11600: &Apache::loncommon::end_data_table_row()."\n";
11601: }
11602: }
11603: my $delidx = $counter;
11604: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11605: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11606: $delete_output .= &start_data_table_row().
11607: '<td><img src="'.&icon($oldfile).'" />'.
11608: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11609: '<td>'.$size.'</td>'.
11610: '<td>'.$mtime.'</td>'.
11611: '<td><label><input type="checkbox" name="del_upload_dep" '.
11612: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11613: &embedded_file_element('upload_embedded',$delidx,
11614: $oldfile,\%mapping,$allfiles,
11615: $codebase,'delete').'</td>'.
11616: &end_data_table_row()."\n";
11617: $numunused ++;
11618: $delidx ++;
1.987 raeburn 11619: }
11620: if ($upload_output) {
11621: $upload_output = &start_data_table().
11622: $upload_output.
11623: &end_data_table()."\n";
11624: }
1.1071 raeburn 11625: if ($modify_output) {
11626: $modify_output = &start_data_table().
11627: &start_data_table_header_row().
11628: '<th>'.&mt('File').'</th>'.
11629: '<th>'.&mt('Size (KB)').'</th>'.
11630: '<th>'.&mt('Modified').'</th>'.
11631: '<th>'.&mt('Upload replacement?').'</th>'.
11632: &end_data_table_header_row().
11633: $modify_output.
11634: &end_data_table()."\n";
11635: }
11636: if ($delete_output) {
11637: $delete_output = &start_data_table().
11638: &start_data_table_header_row().
11639: '<th>'.&mt('File').'</th>'.
11640: '<th>'.&mt('Size (KB)').'</th>'.
11641: '<th>'.&mt('Modified').'</th>'.
11642: '<th>'.&mt('Delete?').'</th>'.
11643: &end_data_table_header_row().
11644: $delete_output.
11645: &end_data_table()."\n";
11646: }
1.987 raeburn 11647: my $applies = 0;
11648: if ($numremref) {
11649: $applies ++;
11650: }
11651: if ($numinvalid) {
11652: $applies ++;
11653: }
11654: if ($numexisting) {
11655: $applies ++;
11656: }
1.1071 raeburn 11657: if ($counter || $numunused) {
1.987 raeburn 11658: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11659: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11660: $state.'<h3>'.$heading.'</h3>';
11661: if ($actionurl eq '/adm/dependencies') {
11662: if ($numnew) {
11663: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11664: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11665: $upload_output.'<br />'."\n";
11666: }
11667: if ($numexisting) {
11668: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11669: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11670: $modify_output.'<br />'."\n";
11671: $buttontext = &mt('Save changes');
11672: }
11673: if ($numunused) {
11674: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11675: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11676: $delete_output.'<br />'."\n";
11677: $buttontext = &mt('Save changes');
11678: }
11679: } else {
11680: $output .= $upload_output.'<br />'."\n";
11681: }
11682: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11683: $counter.'" />'."\n";
11684: if ($actionurl eq '/adm/dependencies') {
11685: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11686: $numnew.'" />'."\n";
11687: } elsif ($actionurl eq '') {
1.987 raeburn 11688: $output .= '<input type="hidden" name="phase" value="three" />';
11689: }
11690: } elsif ($applies) {
11691: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11692: if ($applies > 1) {
11693: $output .=
1.1123 raeburn 11694: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11695: if ($numremref) {
11696: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11697: }
11698: if ($numinvalid) {
11699: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11700: }
11701: if ($numexisting) {
11702: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11703: }
11704: $output .= '</ul><br />';
11705: } elsif ($numremref) {
11706: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11707: } elsif ($numinvalid) {
11708: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11709: } elsif ($numexisting) {
11710: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11711: }
11712: $output .= $upload_output.'<br />';
11713: }
11714: my ($pathchange_output,$chgcount);
1.1071 raeburn 11715: $chgcount = $counter;
1.987 raeburn 11716: if (keys(%pathchanges) > 0) {
11717: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11718: if ($counter) {
1.987 raeburn 11719: $output .= &embedded_file_element('pathchange',$chgcount,
11720: $embed_file,\%mapping,
1.1071 raeburn 11721: $allfiles,$codebase,'change');
1.987 raeburn 11722: } else {
11723: $pathchange_output .=
11724: &start_data_table_row().
11725: '<td><input type ="checkbox" name="namechange" value="'.
11726: $chgcount.'" checked="checked" /></td>'.
11727: '<td>'.$mapping{$embed_file}.'</td>'.
11728: '<td>'.$embed_file.
11729: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11730: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11731: '</td>'.&end_data_table_row();
1.660 raeburn 11732: }
1.987 raeburn 11733: $numpathchg ++;
11734: $chgcount ++;
1.660 raeburn 11735: }
11736: }
1.1127 raeburn 11737: if (($counter) || ($numunused)) {
1.987 raeburn 11738: if ($numpathchg) {
11739: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11740: $numpathchg.'" />'."\n";
11741: }
11742: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11743: ($actionurl eq '/adm/imsimport')) {
11744: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11745: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11746: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11747: } elsif ($actionurl eq '/adm/dependencies') {
11748: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11749: }
1.1123 raeburn 11750: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11751: } elsif ($numpathchg) {
11752: my %pathchange = ();
11753: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11754: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11755: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11756: }
1.987 raeburn 11757: }
1.1071 raeburn 11758: return ($output,$counter,$numpathchg);
1.987 raeburn 11759: }
11760:
1.1147 raeburn 11761: =pod
11762:
11763: =item * clean_path($name)
11764:
11765: Performs clean-up of directories, subdirectories and filename in an
11766: embedded object, referenced in an HTML file which is being uploaded
11767: to a course or portfolio, where
11768: "Upload embedded images/multimedia files if HTML file" checkbox was
11769: checked.
11770:
11771: Clean-up is similar to replacements in lonnet::clean_filename()
11772: except each / between sub-directory and next level is preserved.
11773:
11774: =cut
11775:
11776: sub clean_path {
11777: my ($embed_file) = @_;
11778: $embed_file =~s{^/+}{};
11779: my @contents;
11780: if ($embed_file =~ m{/}) {
11781: @contents = split(/\//,$embed_file);
11782: } else {
11783: @contents = ($embed_file);
11784: }
11785: my $lastidx = scalar(@contents)-1;
11786: for (my $i=0; $i<=$lastidx; $i++) {
11787: $contents[$i]=~s{\\}{/}g;
11788: $contents[$i]=~s/\s+/\_/g;
11789: $contents[$i]=~s{[^/\w\.\-]}{}g;
11790: if ($i == $lastidx) {
11791: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11792: }
11793: }
11794: if ($lastidx > 0) {
11795: return join('/',@contents);
11796: } else {
11797: return $contents[0];
11798: }
11799: }
11800:
1.987 raeburn 11801: sub embedded_file_element {
1.1071 raeburn 11802: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11803: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11804: (ref($codebase) eq 'HASH'));
11805: my $output;
1.1071 raeburn 11806: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11807: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11808: }
11809: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11810: &escape($embed_file).'" />';
11811: unless (($context eq 'upload_embedded') &&
11812: ($mapping->{$embed_file} eq $embed_file)) {
11813: $output .='
11814: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11815: }
11816: my $attrib;
11817: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11818: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11819: }
11820: $output .=
11821: "\n\t\t".
11822: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11823: $attrib.'" />';
11824: if (exists($codebase->{$mapping->{$embed_file}})) {
11825: $output .=
11826: "\n\t\t".
11827: '<input name="codebase_'.$num.'" type="hidden" value="'.
11828: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11829: }
1.987 raeburn 11830: return $output;
1.660 raeburn 11831: }
11832:
1.1071 raeburn 11833: sub get_dependency_details {
11834: my ($currfile,$currsubfile,$embed_file) = @_;
11835: my ($size,$mtime,$showsize,$showmtime);
11836: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11837: if ($embed_file =~ m{/}) {
11838: my ($path,$fname) = split(/\//,$embed_file);
11839: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11840: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11841: }
11842: } else {
11843: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11844: ($size,$mtime) = @{$currfile->{$embed_file}};
11845: }
11846: }
11847: $showsize = $size/1024.0;
11848: $showsize = sprintf("%.1f",$showsize);
11849: if ($mtime > 0) {
11850: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11851: }
11852: }
11853: return ($showsize,$showmtime);
11854: }
11855:
11856: sub ask_embedded_js {
11857: return <<"END";
11858: <script type="text/javascript"">
11859: // <![CDATA[
11860: function toggleBrowse(counter) {
11861: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11862: var fileid = document.getElementById('embedded_item_'+counter);
11863: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11864: if (chkboxid.checked == true) {
11865: uploaddivid.style.display='block';
11866: } else {
11867: uploaddivid.style.display='none';
11868: fileid.value = '';
11869: }
11870: }
11871: // ]]>
11872: </script>
11873:
11874: END
11875: }
11876:
1.661 raeburn 11877: sub upload_embedded {
11878: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11879: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11880: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11881: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11882: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11883: my $orig_uploaded_filename =
11884: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11885: foreach my $type ('orig','ref','attrib','codebase') {
11886: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11887: $env{'form.embedded_'.$type.'_'.$i} =
11888: &unescape($env{'form.embedded_'.$type.'_'.$i});
11889: }
11890: }
1.661 raeburn 11891: my ($path,$fname) =
11892: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11893: # no path, whole string is fname
11894: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11895: $fname = &Apache::lonnet::clean_filename($fname);
11896: # See if there is anything left
11897: next if ($fname eq '');
11898:
11899: # Check if file already exists as a file or directory.
11900: my ($state,$msg);
11901: if ($context eq 'portfolio') {
11902: my $port_path = $dirpath;
11903: if ($group ne '') {
11904: $port_path = "groups/$group/$port_path";
11905: }
1.987 raeburn 11906: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11907: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11908: $dir_root,$port_path,$disk_quota,
11909: $current_disk_usage,$uname,$udom);
11910: if ($state eq 'will_exceed_quota'
1.984 raeburn 11911: || $state eq 'file_locked') {
1.661 raeburn 11912: $output .= $msg;
11913: next;
11914: }
11915: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11916: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11917: if ($state eq 'exists') {
11918: $output .= $msg;
11919: next;
11920: }
11921: }
11922: # Check if extension is valid
11923: if (($fname =~ /\.(\w+)$/) &&
11924: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11925: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11926: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11927: next;
11928: } elsif (($fname =~ /\.(\w+)$/) &&
11929: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11930: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11931: next;
11932: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11933: $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 11934: next;
11935: }
11936: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11937: my $subdir = $path;
11938: $subdir =~ s{/+$}{};
1.661 raeburn 11939: if ($context eq 'portfolio') {
1.984 raeburn 11940: my $result;
11941: if ($state eq 'existingfile') {
11942: $result=
11943: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11944: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11945: } else {
1.984 raeburn 11946: $result=
11947: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11948: $dirpath.
1.1123 raeburn 11949: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11950: if ($result !~ m|^/uploaded/|) {
11951: $output .= '<span class="LC_error">'
11952: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11953: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11954: .'</span><br />';
11955: next;
11956: } else {
1.987 raeburn 11957: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11958: $path.$fname.'</span>').'<br />';
1.984 raeburn 11959: }
1.661 raeburn 11960: }
1.1123 raeburn 11961: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11962: my $extendedsubdir = $dirpath.'/'.$subdir;
11963: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11964: my $result =
1.1126 raeburn 11965: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11966: if ($result !~ m|^/uploaded/|) {
11967: $output .= '<span class="LC_error">'
11968: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11969: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11970: .'</span><br />';
11971: next;
11972: } else {
11973: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11974: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11975: if ($context eq 'syllabus') {
11976: &Apache::lonnet::make_public_indefinitely($result);
11977: }
1.987 raeburn 11978: }
1.661 raeburn 11979: } else {
11980: # Save the file
11981: my $target = $env{'form.embedded_item_'.$i};
11982: my $fullpath = $dir_root.$dirpath.'/'.$path;
11983: my $dest = $fullpath.$fname;
11984: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11985: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11986: my $count;
11987: my $filepath = $dir_root;
1.1027 raeburn 11988: foreach my $subdir (@parts) {
11989: $filepath .= "/$subdir";
11990: if (!-e $filepath) {
1.661 raeburn 11991: mkdir($filepath,0770);
11992: }
11993: }
11994: my $fh;
11995: if (!open($fh,'>'.$dest)) {
11996: &Apache::lonnet::logthis('Failed to create '.$dest);
11997: $output .= '<span class="LC_error">'.
1.1071 raeburn 11998: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11999: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12000: '</span><br />';
12001: } else {
12002: if (!print $fh $env{'form.embedded_item_'.$i}) {
12003: &Apache::lonnet::logthis('Failed to write to '.$dest);
12004: $output .= '<span class="LC_error">'.
1.1071 raeburn 12005: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12006: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12007: '</span><br />';
12008: } else {
1.987 raeburn 12009: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12010: $url.'</span>').'<br />';
12011: unless ($context eq 'testbank') {
12012: $footer .= &mt('View embedded file: [_1]',
12013: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12014: }
12015: }
12016: close($fh);
12017: }
12018: }
12019: if ($env{'form.embedded_ref_'.$i}) {
12020: $pathchange{$i} = 1;
12021: }
12022: }
12023: if ($output) {
12024: $output = '<p>'.$output.'</p>';
12025: }
12026: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12027: $returnflag = 'ok';
1.1071 raeburn 12028: my $numpathchgs = scalar(keys(%pathchange));
12029: if ($numpathchgs > 0) {
1.987 raeburn 12030: if ($context eq 'portfolio') {
12031: $output .= '<p>'.&mt('or').'</p>';
12032: } elsif ($context eq 'testbank') {
1.1071 raeburn 12033: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12034: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12035: $returnflag = 'modify_orightml';
12036: }
12037: }
1.1071 raeburn 12038: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12039: }
12040:
12041: sub modify_html_form {
12042: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12043: my $end = 0;
12044: my $modifyform;
12045: if ($context eq 'upload_embedded') {
12046: return unless (ref($pathchange) eq 'HASH');
12047: if ($env{'form.number_embedded_items'}) {
12048: $end += $env{'form.number_embedded_items'};
12049: }
12050: if ($env{'form.number_pathchange_items'}) {
12051: $end += $env{'form.number_pathchange_items'};
12052: }
12053: if ($end) {
12054: for (my $i=0; $i<$end; $i++) {
12055: if ($i < $env{'form.number_embedded_items'}) {
12056: next unless($pathchange->{$i});
12057: }
12058: $modifyform .=
12059: &start_data_table_row().
12060: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12061: 'checked="checked" /></td>'.
12062: '<td>'.$env{'form.embedded_ref_'.$i}.
12063: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12064: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12065: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12066: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12067: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12068: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12069: '<td>'.$env{'form.embedded_orig_'.$i}.
12070: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12071: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12072: &end_data_table_row();
1.1071 raeburn 12073: }
1.987 raeburn 12074: }
12075: } else {
12076: $modifyform = $pathchgtable;
12077: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12078: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12079: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12080: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12081: }
12082: }
12083: if ($modifyform) {
1.1071 raeburn 12084: if ($actionurl eq '/adm/dependencies') {
12085: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12086: }
1.987 raeburn 12087: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12088: '<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".
12089: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12090: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12091: '</ol></p>'."\n".'<p>'.
12092: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12093: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12094: &start_data_table()."\n".
12095: &start_data_table_header_row().
12096: '<th>'.&mt('Change?').'</th>'.
12097: '<th>'.&mt('Current reference').'</th>'.
12098: '<th>'.&mt('Required reference').'</th>'.
12099: &end_data_table_header_row()."\n".
12100: $modifyform.
12101: &end_data_table().'<br />'."\n".$hiddenstate.
12102: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12103: '</form>'."\n";
12104: }
12105: return;
12106: }
12107:
12108: sub modify_html_refs {
1.1123 raeburn 12109: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12110: my $container;
12111: if ($context eq 'portfolio') {
12112: $container = $env{'form.container'};
12113: } elsif ($context eq 'coursedoc') {
12114: $container = $env{'form.primaryurl'};
1.1071 raeburn 12115: } elsif ($context eq 'manage_dependencies') {
12116: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12117: $container = "/$container";
1.1123 raeburn 12118: } elsif ($context eq 'syllabus') {
12119: $container = $url;
1.987 raeburn 12120: } else {
1.1027 raeburn 12121: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12122: }
12123: my (%allfiles,%codebase,$output,$content);
12124: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12125: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12126: if (wantarray) {
12127: return ('',0,0);
12128: } else {
12129: return;
12130: }
12131: }
12132: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12133: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12134: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12135: if (wantarray) {
12136: return ('',0,0);
12137: } else {
12138: return;
12139: }
12140: }
1.987 raeburn 12141: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12142: if ($content eq '-1') {
12143: if (wantarray) {
12144: return ('',0,0);
12145: } else {
12146: return;
12147: }
12148: }
1.987 raeburn 12149: } else {
1.1071 raeburn 12150: unless ($container =~ /^\Q$dir_root\E/) {
12151: if (wantarray) {
12152: return ('',0,0);
12153: } else {
12154: return;
12155: }
12156: }
1.987 raeburn 12157: if (open(my $fh,"<$container")) {
12158: $content = join('', <$fh>);
12159: close($fh);
12160: } else {
1.1071 raeburn 12161: if (wantarray) {
12162: return ('',0,0);
12163: } else {
12164: return;
12165: }
1.987 raeburn 12166: }
12167: }
12168: my ($count,$codebasecount) = (0,0);
12169: my $mm = new File::MMagic;
12170: my $mime_type = $mm->checktype_contents($content);
12171: if ($mime_type eq 'text/html') {
12172: my $parse_result =
12173: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12174: \%codebase,\$content);
12175: if ($parse_result eq 'ok') {
12176: foreach my $i (@changes) {
12177: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12178: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12179: if ($allfiles{$ref}) {
12180: my $newname = $orig;
12181: my ($attrib_regexp,$codebase);
1.1006 raeburn 12182: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12183: if ($attrib_regexp =~ /:/) {
12184: $attrib_regexp =~ s/\:/|/g;
12185: }
12186: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12187: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12188: $count += $numchg;
1.1123 raeburn 12189: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12190: delete($allfiles{$ref});
1.987 raeburn 12191: }
12192: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12193: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12194: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12195: $codebasecount ++;
12196: }
12197: }
12198: }
1.1123 raeburn 12199: my $skiprewrites;
1.987 raeburn 12200: if ($count || $codebasecount) {
12201: my $saveresult;
1.1071 raeburn 12202: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12203: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12204: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12205: if ($url eq $container) {
12206: my ($fname) = ($container =~ m{/([^/]+)$});
12207: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12208: $count,'<span class="LC_filename">'.
1.1071 raeburn 12209: $fname.'</span>').'</p>';
1.987 raeburn 12210: } else {
12211: $output = '<p class="LC_error">'.
12212: &mt('Error: update failed for: [_1].',
12213: '<span class="LC_filename">'.
12214: $container.'</span>').'</p>';
12215: }
1.1123 raeburn 12216: if ($context eq 'syllabus') {
12217: unless ($saveresult eq 'ok') {
12218: $skiprewrites = 1;
12219: }
12220: }
1.987 raeburn 12221: } else {
12222: if (open(my $fh,">$container")) {
12223: print $fh $content;
12224: close($fh);
12225: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12226: $count,'<span class="LC_filename">'.
12227: $container.'</span>').'</p>';
1.661 raeburn 12228: } else {
1.987 raeburn 12229: $output = '<p class="LC_error">'.
12230: &mt('Error: could not update [_1].',
12231: '<span class="LC_filename">'.
12232: $container.'</span>').'</p>';
1.661 raeburn 12233: }
12234: }
12235: }
1.1123 raeburn 12236: if (($context eq 'syllabus') && (!$skiprewrites)) {
12237: my ($actionurl,$state);
12238: $actionurl = "/public/$udom/$uname/syllabus";
12239: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12240: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12241: \%codebase,
12242: {'context' => 'rewrites',
12243: 'ignore_remote_references' => 1,});
12244: if (ref($mapping) eq 'HASH') {
12245: my $rewrites = 0;
12246: foreach my $key (keys(%{$mapping})) {
12247: next if ($key =~ m{^https?://});
12248: my $ref = $mapping->{$key};
12249: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12250: my $attrib;
12251: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12252: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12253: }
12254: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12255: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12256: $rewrites += $numchg;
12257: }
12258: }
12259: if ($rewrites) {
12260: my $saveresult;
12261: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12262: if ($url eq $container) {
12263: my ($fname) = ($container =~ m{/([^/]+)$});
12264: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12265: $count,'<span class="LC_filename">'.
12266: $fname.'</span>').'</p>';
12267: } else {
12268: $output .= '<p class="LC_error">'.
12269: &mt('Error: could not update links in [_1].',
12270: '<span class="LC_filename">'.
12271: $container.'</span>').'</p>';
12272:
12273: }
12274: }
12275: }
12276: }
1.987 raeburn 12277: } else {
12278: &logthis('Failed to parse '.$container.
12279: ' to modify references: '.$parse_result);
1.661 raeburn 12280: }
12281: }
1.1071 raeburn 12282: if (wantarray) {
12283: return ($output,$count,$codebasecount);
12284: } else {
12285: return $output;
12286: }
1.661 raeburn 12287: }
12288:
12289: sub check_for_existing {
12290: my ($path,$fname,$element) = @_;
12291: my ($state,$msg);
12292: if (-d $path.'/'.$fname) {
12293: $state = 'exists';
12294: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12295: } elsif (-e $path.'/'.$fname) {
12296: $state = 'exists';
12297: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12298: }
12299: if ($state eq 'exists') {
12300: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12301: }
12302: return ($state,$msg);
12303: }
12304:
12305: sub check_for_upload {
12306: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12307: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12308: my $filesize = length($env{'form.'.$element});
12309: if (!$filesize) {
12310: my $msg = '<span class="LC_error">'.
12311: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12312: '<span class="LC_filename">'.$fname.'</span>',
12313: $filesize).'<br />'.
1.1007 raeburn 12314: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12315: '</span>';
12316: return ('zero_bytes',$msg);
12317: }
12318: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12319: my $getpropath = 1;
1.1021 raeburn 12320: my ($dirlistref,$listerror) =
12321: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12322: my $found_file = 0;
12323: my $locked_file = 0;
1.991 raeburn 12324: my @lockers;
12325: my $navmap;
12326: if ($env{'request.course.id'}) {
12327: $navmap = Apache::lonnavmaps::navmap->new();
12328: }
1.1021 raeburn 12329: if (ref($dirlistref) eq 'ARRAY') {
12330: foreach my $line (@{$dirlistref}) {
12331: my ($file_name,$rest)=split(/\&/,$line,2);
12332: if ($file_name eq $fname){
12333: $file_name = $path.$file_name;
12334: if ($group ne '') {
12335: $file_name = $group.$file_name;
12336: }
12337: $found_file = 1;
12338: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12339: foreach my $lock (@lockers) {
12340: if (ref($lock) eq 'ARRAY') {
12341: my ($symb,$crsid) = @{$lock};
12342: if ($crsid eq $env{'request.course.id'}) {
12343: if (ref($navmap)) {
12344: my $res = $navmap->getBySymb($symb);
12345: foreach my $part (@{$res->parts()}) {
12346: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12347: unless (($slot_status == $res->RESERVED) ||
12348: ($slot_status == $res->RESERVED_LOCATION)) {
12349: $locked_file = 1;
12350: }
1.991 raeburn 12351: }
1.1021 raeburn 12352: } else {
12353: $locked_file = 1;
1.991 raeburn 12354: }
12355: } else {
12356: $locked_file = 1;
12357: }
12358: }
1.1021 raeburn 12359: }
12360: } else {
12361: my @info = split(/\&/,$rest);
12362: my $currsize = $info[6]/1000;
12363: if ($currsize < $filesize) {
12364: my $extra = $filesize - $currsize;
12365: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12366: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12367: &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 12368: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12369: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12370: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12371: return ('will_exceed_quota',$msg);
12372: }
1.984 raeburn 12373: }
12374: }
1.661 raeburn 12375: }
12376: }
12377: }
12378: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12379: my $msg = '<p class="LC_warning">'.
12380: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12381: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12382: return ('will_exceed_quota',$msg);
12383: } elsif ($found_file) {
12384: if ($locked_file) {
1.1179 bisitz 12385: my $msg = '<p class="LC_warning">';
1.661 raeburn 12386: $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 12387: $msg .= '</p>';
1.661 raeburn 12388: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12389: return ('file_locked',$msg);
12390: } else {
1.1179 bisitz 12391: my $msg = '<p class="LC_error">';
1.984 raeburn 12392: $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 12393: $msg .= '</p>';
1.984 raeburn 12394: return ('existingfile',$msg);
1.661 raeburn 12395: }
12396: }
12397: }
12398:
1.987 raeburn 12399: sub check_for_traversal {
12400: my ($path,$url,$toplevel) = @_;
12401: my @parts=split(/\//,$path);
12402: my $cleanpath;
12403: my $fullpath = $url;
12404: for (my $i=0;$i<@parts;$i++) {
12405: next if ($parts[$i] eq '.');
12406: if ($parts[$i] eq '..') {
12407: $fullpath =~ s{([^/]+/)$}{};
12408: } else {
12409: $fullpath .= $parts[$i].'/';
12410: }
12411: }
12412: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12413: $cleanpath = $1;
12414: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12415: my $curr_toprel = $1;
12416: my @parts = split(/\//,$curr_toprel);
12417: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12418: my @urlparts = split(/\//,$url_toprel);
12419: my $doubledots;
12420: my $startdiff = -1;
12421: for (my $i=0; $i<@urlparts; $i++) {
12422: if ($startdiff == -1) {
12423: unless ($urlparts[$i] eq $parts[$i]) {
12424: $startdiff = $i;
12425: $doubledots .= '../';
12426: }
12427: } else {
12428: $doubledots .= '../';
12429: }
12430: }
12431: if ($startdiff > -1) {
12432: $cleanpath = $doubledots;
12433: for (my $i=$startdiff; $i<@parts; $i++) {
12434: $cleanpath .= $parts[$i].'/';
12435: }
12436: }
12437: }
12438: $cleanpath =~ s{(/)$}{};
12439: return $cleanpath;
12440: }
1.31 albertel 12441:
1.1053 raeburn 12442: sub is_archive_file {
12443: my ($mimetype) = @_;
12444: if (($mimetype eq 'application/octet-stream') ||
12445: ($mimetype eq 'application/x-stuffit') ||
12446: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12447: return 1;
12448: }
12449: return;
12450: }
12451:
12452: sub decompress_form {
1.1065 raeburn 12453: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12454: my %lt = &Apache::lonlocal::texthash (
12455: this => 'This file is an archive file.',
1.1067 raeburn 12456: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12457: itsc => 'Its contents are as follows:',
1.1053 raeburn 12458: youm => 'You may wish to extract its contents.',
12459: extr => 'Extract contents',
1.1067 raeburn 12460: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12461: proa => 'Process automatically?',
1.1053 raeburn 12462: yes => 'Yes',
12463: no => 'No',
1.1067 raeburn 12464: fold => 'Title for folder containing movie',
12465: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12466: );
1.1065 raeburn 12467: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12468: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12469: my $info = &list_archive_contents($fileloc,\@paths);
12470: if (@paths) {
12471: foreach my $path (@paths) {
12472: $path =~ s{^/}{};
1.1067 raeburn 12473: if ($path =~ m{^([^/]+)/$}) {
12474: $topdir = $1;
12475: }
1.1065 raeburn 12476: if ($path =~ m{^([^/]+)/}) {
12477: $toplevel{$1} = $path;
12478: } else {
12479: $toplevel{$path} = $path;
12480: }
12481: }
12482: }
1.1067 raeburn 12483: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12484: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12485: "$topdir/media/",
12486: "$topdir/media/$topdir.mp4",
12487: "$topdir/media/FirstFrame.png",
12488: "$topdir/media/player.swf",
12489: "$topdir/media/swfobject.js",
12490: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12491: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12492: "$topdir/$topdir.mp4",
12493: "$topdir/$topdir\_config.xml",
12494: "$topdir/$topdir\_controller.swf",
12495: "$topdir/$topdir\_embed.css",
12496: "$topdir/$topdir\_First_Frame.png",
12497: "$topdir/$topdir\_player.html",
12498: "$topdir/$topdir\_Thumbnails.png",
12499: "$topdir/playerProductInstall.swf",
12500: "$topdir/scripts/",
12501: "$topdir/scripts/config_xml.js",
12502: "$topdir/scripts/handlebars.js",
12503: "$topdir/scripts/jquery-1.7.1.min.js",
12504: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12505: "$topdir/scripts/modernizr.js",
12506: "$topdir/scripts/player-min.js",
12507: "$topdir/scripts/swfobject.js",
12508: "$topdir/skins/",
12509: "$topdir/skins/configuration_express.xml",
12510: "$topdir/skins/express_show/",
12511: "$topdir/skins/express_show/player-min.css",
12512: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12513: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12514: "$topdir/$topdir.mp4",
12515: "$topdir/$topdir\_config.xml",
12516: "$topdir/$topdir\_controller.swf",
12517: "$topdir/$topdir\_embed.css",
12518: "$topdir/$topdir\_First_Frame.png",
12519: "$topdir/$topdir\_player.html",
12520: "$topdir/$topdir\_Thumbnails.png",
12521: "$topdir/playerProductInstall.swf",
12522: "$topdir/scripts/",
12523: "$topdir/scripts/config_xml.js",
12524: "$topdir/scripts/techsmith-smart-player.min.js",
12525: "$topdir/skins/",
12526: "$topdir/skins/configuration_express.xml",
12527: "$topdir/skins/express_show/",
12528: "$topdir/skins/express_show/spritesheet.min.css",
12529: "$topdir/skins/express_show/spritesheet.png",
12530: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12531: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12532: if (@diffs == 0) {
1.1164 raeburn 12533: $is_camtasia = 6;
12534: } else {
1.1197 raeburn 12535: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12536: if (@diffs == 0) {
12537: $is_camtasia = 8;
1.1197 raeburn 12538: } else {
12539: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12540: if (@diffs == 0) {
12541: $is_camtasia = 8;
12542: }
1.1164 raeburn 12543: }
1.1067 raeburn 12544: }
12545: }
12546: my $output;
12547: if ($is_camtasia) {
12548: $output = <<"ENDCAM";
12549: <script type="text/javascript" language="Javascript">
12550: // <![CDATA[
12551:
12552: function camtasiaToggle() {
12553: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12554: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12555: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12556: document.getElementById('camtasia_titles').style.display='block';
12557: } else {
12558: document.getElementById('camtasia_titles').style.display='none';
12559: }
12560: }
12561: }
12562: return;
12563: }
12564:
12565: // ]]>
12566: </script>
12567: <p>$lt{'camt'}</p>
12568: ENDCAM
1.1065 raeburn 12569: } else {
1.1067 raeburn 12570: $output = '<p>'.$lt{'this'};
12571: if ($info eq '') {
12572: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12573: } else {
12574: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12575: '<div><pre>'.$info.'</pre></div>';
12576: }
1.1065 raeburn 12577: }
1.1067 raeburn 12578: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12579: my $duplicates;
12580: my $num = 0;
12581: if (ref($dirlist) eq 'ARRAY') {
12582: foreach my $item (@{$dirlist}) {
12583: if (ref($item) eq 'ARRAY') {
12584: if (exists($toplevel{$item->[0]})) {
12585: $duplicates .=
12586: &start_data_table_row().
12587: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12588: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12589: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12590: 'value="1" />'.&mt('Yes').'</label>'.
12591: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12592: '<td>'.$item->[0].'</td>';
12593: if ($item->[2]) {
12594: $duplicates .= '<td>'.&mt('Directory').'</td>';
12595: } else {
12596: $duplicates .= '<td>'.&mt('File').'</td>';
12597: }
12598: $duplicates .= '<td>'.$item->[3].'</td>'.
12599: '<td>'.
12600: &Apache::lonlocal::locallocaltime($item->[4]).
12601: '</td>'.
12602: &end_data_table_row();
12603: $num ++;
12604: }
12605: }
12606: }
12607: }
12608: my $itemcount;
12609: if (@paths > 0) {
12610: $itemcount = scalar(@paths);
12611: } else {
12612: $itemcount = 1;
12613: }
1.1067 raeburn 12614: if ($is_camtasia) {
12615: $output .= $lt{'auto'}.'<br />'.
12616: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12617: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12618: $lt{'yes'}.'</label> <label>'.
12619: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12620: $lt{'no'}.'</label></span><br />'.
12621: '<div id="camtasia_titles" style="display:block">'.
12622: &Apache::lonhtmlcommon::start_pick_box().
12623: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12624: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12625: &Apache::lonhtmlcommon::row_closure().
12626: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12627: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12628: &Apache::lonhtmlcommon::row_closure(1).
12629: &Apache::lonhtmlcommon::end_pick_box().
12630: '</div>';
12631: }
1.1065 raeburn 12632: $output .=
12633: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12634: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12635: "\n";
1.1065 raeburn 12636: if ($duplicates ne '') {
12637: $output .= '<p><span class="LC_warning">'.
12638: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12639: &start_data_table().
12640: &start_data_table_header_row().
12641: '<th>'.&mt('Overwrite?').'</th>'.
12642: '<th>'.&mt('Name').'</th>'.
12643: '<th>'.&mt('Type').'</th>'.
12644: '<th>'.&mt('Size').'</th>'.
12645: '<th>'.&mt('Last modified').'</th>'.
12646: &end_data_table_header_row().
12647: $duplicates.
12648: &end_data_table().
12649: '</p>';
12650: }
1.1067 raeburn 12651: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12652: if (ref($hiddenelements) eq 'HASH') {
12653: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12654: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12655: }
12656: }
12657: $output .= <<"END";
1.1067 raeburn 12658: <br />
1.1053 raeburn 12659: <input type="submit" name="decompress" value="$lt{'extr'}" />
12660: </form>
12661: $noextract
12662: END
12663: return $output;
12664: }
12665:
1.1065 raeburn 12666: sub decompression_utility {
12667: my ($program) = @_;
12668: my @utilities = ('tar','gunzip','bunzip2','unzip');
12669: my $location;
12670: if (grep(/^\Q$program\E$/,@utilities)) {
12671: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12672: '/usr/sbin/') {
12673: if (-x $dir.$program) {
12674: $location = $dir.$program;
12675: last;
12676: }
12677: }
12678: }
12679: return $location;
12680: }
12681:
12682: sub list_archive_contents {
12683: my ($file,$pathsref) = @_;
12684: my (@cmd,$output);
12685: my $needsregexp;
12686: if ($file =~ /\.zip$/) {
12687: @cmd = (&decompression_utility('unzip'),"-l");
12688: $needsregexp = 1;
12689: } elsif (($file =~ m/\.tar\.gz$/) ||
12690: ($file =~ /\.tgz$/)) {
12691: @cmd = (&decompression_utility('tar'),"-ztf");
12692: } elsif ($file =~ /\.tar\.bz2$/) {
12693: @cmd = (&decompression_utility('tar'),"-jtf");
12694: } elsif ($file =~ m|\.tar$|) {
12695: @cmd = (&decompression_utility('tar'),"-tf");
12696: }
12697: if (@cmd) {
12698: undef($!);
12699: undef($@);
12700: if (open(my $fh,"-|", @cmd, $file)) {
12701: while (my $line = <$fh>) {
12702: $output .= $line;
12703: chomp($line);
12704: my $item;
12705: if ($needsregexp) {
12706: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12707: } else {
12708: $item = $line;
12709: }
12710: if ($item ne '') {
12711: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12712: push(@{$pathsref},$item);
12713: }
12714: }
12715: }
12716: close($fh);
12717: }
12718: }
12719: return $output;
12720: }
12721:
1.1053 raeburn 12722: sub decompress_uploaded_file {
12723: my ($file,$dir) = @_;
12724: &Apache::lonnet::appenv({'cgi.file' => $file});
12725: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12726: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12727: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12728: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12729: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12730: my $decompressed = $env{'cgi.decompressed'};
12731: &Apache::lonnet::delenv('cgi.file');
12732: &Apache::lonnet::delenv('cgi.dir');
12733: &Apache::lonnet::delenv('cgi.decompressed');
12734: return ($decompressed,$result);
12735: }
12736:
1.1055 raeburn 12737: sub process_decompression {
12738: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12739: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12740: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12741: &mt('Unexpected file path.').'</p>'."\n";
12742: }
12743: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12744: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12745: &mt('Unexpected course context.').'</p>'."\n";
12746: }
1.1293 raeburn 12747: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12748: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12749: &mt('Filename contained unexpected characters.').'</p>'."\n";
12750: }
1.1055 raeburn 12751: my ($dir,$error,$warning,$output);
1.1180 raeburn 12752: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12753: $error = &mt('Filename not a supported archive file type.').
12754: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12755: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12756: } else {
12757: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12758: if ($docuhome eq 'no_host') {
12759: $error = &mt('Could not determine home server for course.');
12760: } else {
12761: my @ids=&Apache::lonnet::current_machine_ids();
12762: my $currdir = "$dir_root/$destination";
12763: if (grep(/^\Q$docuhome\E$/,@ids)) {
12764: $dir = &LONCAPA::propath($docudom,$docuname).
12765: "$dir_root/$destination";
12766: } else {
12767: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12768: "$dir_root/$docudom/$docuname/$destination";
12769: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12770: $error = &mt('Archive file not found.');
12771: }
12772: }
1.1065 raeburn 12773: my (@to_overwrite,@to_skip);
12774: if ($env{'form.archive_overwrite_total'} > 0) {
12775: my $total = $env{'form.archive_overwrite_total'};
12776: for (my $i=0; $i<$total; $i++) {
12777: if ($env{'form.archive_overwrite_'.$i} == 1) {
12778: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12779: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12780: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12781: }
12782: }
12783: }
12784: my $numskip = scalar(@to_skip);
1.1292 raeburn 12785: my $numoverwrite = scalar(@to_overwrite);
12786: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12787: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12788: } elsif ($dir eq '') {
1.1055 raeburn 12789: $error = &mt('Directory containing archive file unavailable.');
12790: } elsif (!$error) {
1.1065 raeburn 12791: my ($decompressed,$display);
1.1292 raeburn 12792: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12793: my $tempdir = time.'_'.$$.int(rand(10000));
12794: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12795: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12796: ($decompressed,$display) =
12797: &decompress_uploaded_file($file,"$dir/$tempdir");
12798: foreach my $item (@to_skip) {
12799: if (($item ne '') && ($item !~ /\.\./)) {
12800: if (-f "$dir/$tempdir/$item") {
12801: unlink("$dir/$tempdir/$item");
12802: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12803: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12804: }
12805: }
12806: }
12807: foreach my $item (@to_overwrite) {
12808: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12809: if (($item ne '') && ($item !~ /\.\./)) {
12810: if (-f "$dir/$item") {
12811: unlink("$dir/$item");
12812: } elsif (-d "$dir/$item") {
1.1300 raeburn 12813: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12814: }
12815: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12816: }
1.1065 raeburn 12817: }
12818: }
1.1292 raeburn 12819: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12820: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12821: }
1.1065 raeburn 12822: }
12823: } else {
12824: ($decompressed,$display) =
12825: &decompress_uploaded_file($file,$dir);
12826: }
1.1055 raeburn 12827: if ($decompressed eq 'ok') {
1.1065 raeburn 12828: $output = '<p class="LC_info">'.
12829: &mt('Files extracted successfully from archive.').
12830: '</p>'."\n";
1.1055 raeburn 12831: my ($warning,$result,@contents);
12832: my ($newdirlistref,$newlisterror) =
12833: &Apache::lonnet::dirlist($currdir,$docudom,
12834: $docuname,1);
12835: my (%is_dir,%changes,@newitems);
12836: my $dirptr = 16384;
1.1065 raeburn 12837: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12838: foreach my $dir_line (@{$newdirlistref}) {
12839: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12840: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12841: push(@newitems,$item);
12842: if ($dirptr&$testdir) {
12843: $is_dir{$item} = 1;
12844: }
12845: $changes{$item} = 1;
12846: }
12847: }
12848: }
12849: if (keys(%changes) > 0) {
12850: foreach my $item (sort(@newitems)) {
12851: if ($changes{$item}) {
12852: push(@contents,$item);
12853: }
12854: }
12855: }
12856: if (@contents > 0) {
1.1067 raeburn 12857: my $wantform;
12858: unless ($env{'form.autoextract_camtasia'}) {
12859: $wantform = 1;
12860: }
1.1056 raeburn 12861: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12862: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12863: $currdir,\%is_dir,
12864: \%children,\%parent,
1.1056 raeburn 12865: \@contents,\%dirorder,
12866: \%titles,$wantform);
1.1055 raeburn 12867: if ($datatable ne '') {
12868: $output .= &archive_options_form('decompressed',$datatable,
12869: $count,$hiddenelem);
1.1065 raeburn 12870: my $startcount = 6;
1.1055 raeburn 12871: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12872: \%titles,\%children);
1.1055 raeburn 12873: }
1.1067 raeburn 12874: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12875: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12876: my %displayed;
12877: my $total = 1;
12878: $env{'form.archive_directory'} = [];
12879: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12880: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12881: $path =~ s{/$}{};
12882: my $item;
12883: if ($path ne '') {
12884: $item = "$path/$titles{$i}";
12885: } else {
12886: $item = $titles{$i};
12887: }
12888: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12889: if ($item eq $contents[0]) {
12890: push(@{$env{'form.archive_directory'}},$i);
12891: $env{'form.archive_'.$i} = 'display';
12892: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12893: $displayed{'folder'} = $i;
1.1164 raeburn 12894: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12895: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12896: $env{'form.archive_'.$i} = 'display';
12897: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12898: $displayed{'web'} = $i;
12899: } else {
1.1164 raeburn 12900: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12901: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12902: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12903: push(@{$env{'form.archive_directory'}},$i);
12904: }
12905: $env{'form.archive_'.$i} = 'dependency';
12906: }
12907: $total ++;
12908: }
12909: for (my $i=1; $i<$total; $i++) {
12910: next if ($i == $displayed{'web'});
12911: next if ($i == $displayed{'folder'});
12912: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12913: }
12914: $env{'form.phase'} = 'decompress_cleanup';
12915: $env{'form.archivedelete'} = 1;
12916: $env{'form.archive_count'} = $total-1;
12917: $output .=
12918: &process_extracted_files('coursedocs',$docudom,
12919: $docuname,$destination,
12920: $dir_root,$hiddenelem);
12921: }
1.1055 raeburn 12922: } else {
12923: $warning = &mt('No new items extracted from archive file.');
12924: }
12925: } else {
12926: $output = $display;
12927: $error = &mt('An error occurred during extraction from the archive file.');
12928: }
12929: }
12930: }
12931: }
12932: if ($error) {
12933: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12934: $error.'</p>'."\n";
12935: }
12936: if ($warning) {
12937: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12938: }
12939: return $output;
12940: }
12941:
12942: sub get_extracted {
1.1056 raeburn 12943: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12944: $titles,$wantform) = @_;
1.1055 raeburn 12945: my $count = 0;
12946: my $depth = 0;
12947: my $datatable;
1.1056 raeburn 12948: my @hierarchy;
1.1055 raeburn 12949: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12950: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12951: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12952: foreach my $item (@{$contents}) {
12953: $count ++;
1.1056 raeburn 12954: @{$dirorder->{$count}} = @hierarchy;
12955: $titles->{$count} = $item;
1.1055 raeburn 12956: &archive_hierarchy($depth,$count,$parent,$children);
12957: if ($wantform) {
12958: $datatable .= &archive_row($is_dir->{$item},$item,
12959: $currdir,$depth,$count);
12960: }
12961: if ($is_dir->{$item}) {
12962: $depth ++;
1.1056 raeburn 12963: push(@hierarchy,$count);
12964: $parent->{$depth} = $count;
1.1055 raeburn 12965: $datatable .=
12966: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12967: \$depth,\$count,\@hierarchy,$dirorder,
12968: $children,$parent,$titles,$wantform);
1.1055 raeburn 12969: $depth --;
1.1056 raeburn 12970: pop(@hierarchy);
1.1055 raeburn 12971: }
12972: }
12973: return ($count,$datatable);
12974: }
12975:
12976: sub recurse_extracted_archive {
1.1056 raeburn 12977: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12978: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12979: my $result='';
1.1056 raeburn 12980: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12981: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12982: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12983: return $result;
12984: }
12985: my $dirptr = 16384;
12986: my ($newdirlistref,$newlisterror) =
12987: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12988: if (ref($newdirlistref) eq 'ARRAY') {
12989: foreach my $dir_line (@{$newdirlistref}) {
12990: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12991: unless ($item =~ /^\.+$/) {
12992: $$count ++;
1.1056 raeburn 12993: @{$dirorder->{$$count}} = @{$hierarchy};
12994: $titles->{$$count} = $item;
1.1055 raeburn 12995: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12996:
1.1055 raeburn 12997: my $is_dir;
12998: if ($dirptr&$testdir) {
12999: $is_dir = 1;
13000: }
13001: if ($wantform) {
13002: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13003: }
13004: if ($is_dir) {
13005: $$depth ++;
1.1056 raeburn 13006: push(@{$hierarchy},$$count);
13007: $parent->{$$depth} = $$count;
1.1055 raeburn 13008: $result .=
13009: &recurse_extracted_archive("$currdir/$item",$docudom,
13010: $docuname,$depth,$count,
1.1056 raeburn 13011: $hierarchy,$dirorder,$children,
13012: $parent,$titles,$wantform);
1.1055 raeburn 13013: $$depth --;
1.1056 raeburn 13014: pop(@{$hierarchy});
1.1055 raeburn 13015: }
13016: }
13017: }
13018: }
13019: return $result;
13020: }
13021:
13022: sub archive_hierarchy {
13023: my ($depth,$count,$parent,$children) =@_;
13024: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13025: if (exists($parent->{$depth})) {
13026: $children->{$parent->{$depth}} .= $count.':';
13027: }
13028: }
13029: return;
13030: }
13031:
13032: sub archive_row {
13033: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13034: my ($name) = ($item =~ m{([^/]+)$});
13035: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13036: 'display' => 'Add as file',
1.1055 raeburn 13037: 'dependency' => 'Include as dependency',
13038: 'discard' => 'Discard',
13039: );
13040: if ($is_dir) {
1.1059 raeburn 13041: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13042: }
1.1056 raeburn 13043: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13044: my $offset = 0;
1.1055 raeburn 13045: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13046: $offset ++;
1.1065 raeburn 13047: if ($action ne 'display') {
13048: $offset ++;
13049: }
1.1055 raeburn 13050: $output .= '<td><span class="LC_nobreak">'.
13051: '<label><input type="radio" name="archive_'.$count.
13052: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13053: my $text = $choices{$action};
13054: if ($is_dir) {
13055: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13056: if ($action eq 'display') {
1.1059 raeburn 13057: $text = &mt('Add as folder');
1.1055 raeburn 13058: }
1.1056 raeburn 13059: } else {
13060: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13061:
13062: }
13063: $output .= ' /> '.$choices{$action}.'</label></span>';
13064: if ($action eq 'dependency') {
13065: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13066: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13067: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13068: '<option value=""></option>'."\n".
13069: '</select>'."\n".
13070: '</div>';
1.1059 raeburn 13071: } elsif ($action eq 'display') {
13072: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13073: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13074: '</div>';
1.1055 raeburn 13075: }
1.1056 raeburn 13076: $output .= '</td>';
1.1055 raeburn 13077: }
13078: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13079: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13080: for (my $i=0; $i<$depth; $i++) {
13081: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13082: }
13083: if ($is_dir) {
13084: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13085: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13086: } else {
13087: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13088: }
13089: $output .= ' '.$name.'</td>'."\n".
13090: &end_data_table_row();
13091: return $output;
13092: }
13093:
13094: sub archive_options_form {
1.1065 raeburn 13095: my ($form,$display,$count,$hiddenelem) = @_;
13096: my %lt = &Apache::lonlocal::texthash(
13097: perm => 'Permanently remove archive file?',
13098: hows => 'How should each extracted item be incorporated in the course?',
13099: cont => 'Content actions for all',
13100: addf => 'Add as folder/file',
13101: incd => 'Include as dependency for a displayed file',
13102: disc => 'Discard',
13103: no => 'No',
13104: yes => 'Yes',
13105: save => 'Save',
13106: );
13107: my $output = <<"END";
13108: <form name="$form" method="post" action="">
13109: <p><span class="LC_nobreak">$lt{'perm'}
13110: <label>
13111: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13112: </label>
13113:
13114: <label>
13115: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13116: </span>
13117: </p>
13118: <input type="hidden" name="phase" value="decompress_cleanup" />
13119: <br />$lt{'hows'}
13120: <div class="LC_columnSection">
13121: <fieldset>
13122: <legend>$lt{'cont'}</legend>
13123: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13124: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13125: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13126: </fieldset>
13127: </div>
13128: END
13129: return $output.
1.1055 raeburn 13130: &start_data_table()."\n".
1.1065 raeburn 13131: $display."\n".
1.1055 raeburn 13132: &end_data_table()."\n".
13133: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13134: $hiddenelem.
1.1065 raeburn 13135: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13136: '</form>';
13137: }
13138:
13139: sub archive_javascript {
1.1056 raeburn 13140: my ($startcount,$numitems,$titles,$children) = @_;
13141: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13142: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13143: my $scripttag = <<START;
13144: <script type="text/javascript">
13145: // <![CDATA[
13146:
13147: function checkAll(form,prefix) {
13148: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13149: for (var i=0; i < form.elements.length; i++) {
13150: var id = form.elements[i].id;
13151: if ((id != '') && (id != undefined)) {
13152: if (idstr.test(id)) {
13153: if (form.elements[i].type == 'radio') {
13154: form.elements[i].checked = true;
1.1056 raeburn 13155: var nostart = i-$startcount;
1.1059 raeburn 13156: var offset = nostart%7;
13157: var count = (nostart-offset)/7;
1.1056 raeburn 13158: dependencyCheck(form,count,offset);
1.1055 raeburn 13159: }
13160: }
13161: }
13162: }
13163: }
13164:
13165: function propagateCheck(form,count) {
13166: if (count > 0) {
1.1059 raeburn 13167: var startelement = $startcount + ((count-1) * 7);
13168: for (var j=1; j<6; j++) {
13169: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13170: var item = startelement + j;
13171: if (form.elements[item].type == 'radio') {
13172: if (form.elements[item].checked) {
13173: containerCheck(form,count,j);
13174: break;
13175: }
1.1055 raeburn 13176: }
13177: }
13178: }
13179: }
13180: }
13181:
13182: numitems = $numitems
1.1056 raeburn 13183: var titles = new Array(numitems);
13184: var parents = new Array(numitems);
1.1055 raeburn 13185: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13186: parents[i] = new Array;
1.1055 raeburn 13187: }
1.1059 raeburn 13188: var maintitle = '$maintitle';
1.1055 raeburn 13189:
13190: START
13191:
1.1056 raeburn 13192: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13193: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13194: for (my $i=0; $i<@contents; $i ++) {
13195: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13196: }
13197: }
13198:
1.1056 raeburn 13199: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13200: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13201: }
13202:
1.1055 raeburn 13203: $scripttag .= <<END;
13204:
13205: function containerCheck(form,count,offset) {
13206: if (count > 0) {
1.1056 raeburn 13207: dependencyCheck(form,count,offset);
1.1059 raeburn 13208: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13209: form.elements[item].checked = true;
13210: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13211: if (parents[count].length > 0) {
13212: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13213: containerCheck(form,parents[count][j],offset);
13214: }
13215: }
13216: }
13217: }
13218: }
13219:
13220: function dependencyCheck(form,count,offset) {
13221: if (count > 0) {
1.1059 raeburn 13222: var chosen = (offset+$startcount)+7*(count-1);
13223: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13224: var currtype = form.elements[depitem].type;
13225: if (form.elements[chosen].value == 'dependency') {
13226: document.getElementById('arc_depon_'+count).style.display='block';
13227: form.elements[depitem].options.length = 0;
13228: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13229: for (var i=1; i<=numitems; i++) {
13230: if (i == count) {
13231: continue;
13232: }
1.1059 raeburn 13233: var startelement = $startcount + (i-1) * 7;
13234: for (var j=1; j<6; j++) {
13235: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13236: var item = startelement + j;
13237: if (form.elements[item].type == 'radio') {
13238: if (form.elements[item].checked) {
13239: if (form.elements[item].value == 'display') {
13240: var n = form.elements[depitem].options.length;
13241: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13242: }
13243: }
13244: }
13245: }
13246: }
13247: }
13248: } else {
13249: document.getElementById('arc_depon_'+count).style.display='none';
13250: form.elements[depitem].options.length = 0;
13251: form.elements[depitem].options[0] = new Option('Select','',true,true);
13252: }
1.1059 raeburn 13253: titleCheck(form,count,offset);
1.1056 raeburn 13254: }
13255: }
13256:
13257: function propagateSelect(form,count,offset) {
13258: if (count > 0) {
1.1065 raeburn 13259: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13260: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13261: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13262: if (parents[count].length > 0) {
13263: for (var j=0; j<parents[count].length; j++) {
13264: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13265: }
13266: }
13267: }
13268: }
13269: }
1.1056 raeburn 13270:
13271: function containerSelect(form,count,offset,picked) {
13272: if (count > 0) {
1.1065 raeburn 13273: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13274: if (form.elements[item].type == 'radio') {
13275: if (form.elements[item].value == 'dependency') {
13276: if (form.elements[item+1].type == 'select-one') {
13277: for (var i=0; i<form.elements[item+1].options.length; i++) {
13278: if (form.elements[item+1].options[i].value == picked) {
13279: form.elements[item+1].selectedIndex = i;
13280: break;
13281: }
13282: }
13283: }
13284: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13285: if (parents[count].length > 0) {
13286: for (var j=0; j<parents[count].length; j++) {
13287: containerSelect(form,parents[count][j],offset,picked);
13288: }
13289: }
13290: }
13291: }
13292: }
13293: }
13294: }
13295:
1.1059 raeburn 13296: function titleCheck(form,count,offset) {
13297: if (count > 0) {
13298: var chosen = (offset+$startcount)+7*(count-1);
13299: var depitem = $startcount + ((count-1) * 7) + 2;
13300: var currtype = form.elements[depitem].type;
13301: if (form.elements[chosen].value == 'display') {
13302: document.getElementById('arc_title_'+count).style.display='block';
13303: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13304: document.getElementById('archive_title_'+count).value=maintitle;
13305: }
13306: } else {
13307: document.getElementById('arc_title_'+count).style.display='none';
13308: if (currtype == 'text') {
13309: document.getElementById('archive_title_'+count).value='';
13310: }
13311: }
13312: }
13313: return;
13314: }
13315:
1.1055 raeburn 13316: // ]]>
13317: </script>
13318: END
13319: return $scripttag;
13320: }
13321:
13322: sub process_extracted_files {
1.1067 raeburn 13323: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13324: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13325: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13326: my @ids=&Apache::lonnet::current_machine_ids();
13327: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13328: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13329: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13330: if (grep(/^\Q$docuhome\E$/,@ids)) {
13331: $prefix = &LONCAPA::propath($docudom,$docuname);
13332: $pathtocheck = "$dir_root/$destination";
13333: $dir = $dir_root;
13334: $ishome = 1;
13335: } else {
13336: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13337: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13338: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13339: }
13340: my $currdir = "$dir_root/$destination";
13341: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13342: if ($env{'form.folderpath'}) {
13343: my @items = split('&',$env{'form.folderpath'});
13344: $folders{'0'} = $items[-2];
1.1099 raeburn 13345: if ($env{'form.folderpath'} =~ /\:1$/) {
13346: $containers{'0'}='page';
13347: } else {
13348: $containers{'0'}='sequence';
13349: }
1.1055 raeburn 13350: }
13351: my @archdirs = &get_env_multiple('form.archive_directory');
13352: if ($numitems) {
13353: for (my $i=1; $i<=$numitems; $i++) {
13354: my $path = $env{'form.archive_content_'.$i};
13355: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13356: my $item = $1;
13357: $toplevelitems{$item} = $i;
13358: if (grep(/^\Q$i\E$/,@archdirs)) {
13359: $is_dir{$item} = 1;
13360: }
13361: }
13362: }
13363: }
1.1067 raeburn 13364: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13365: if (keys(%toplevelitems) > 0) {
13366: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13367: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13368: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13369: }
1.1066 raeburn 13370: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13371: if ($numitems) {
13372: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13373: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13374: my $path = $env{'form.archive_content_'.$i};
13375: if ($path =~ /^\Q$pathtocheck\E/) {
13376: if ($env{'form.archive_'.$i} eq 'discard') {
13377: if ($prefix ne '' && $path ne '') {
13378: if (-e $prefix.$path) {
1.1066 raeburn 13379: if ((@archdirs > 0) &&
13380: (grep(/^\Q$i\E$/,@archdirs))) {
13381: $todeletedir{$prefix.$path} = 1;
13382: } else {
13383: $todelete{$prefix.$path} = 1;
13384: }
1.1055 raeburn 13385: }
13386: }
13387: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13388: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13389: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13390: $docstitle = $env{'form.archive_title_'.$i};
13391: if ($docstitle eq '') {
13392: $docstitle = $title;
13393: }
1.1055 raeburn 13394: $outer = 0;
1.1056 raeburn 13395: if (ref($dirorder{$i}) eq 'ARRAY') {
13396: if (@{$dirorder{$i}} > 0) {
13397: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13398: if ($env{'form.archive_'.$item} eq 'display') {
13399: $outer = $item;
13400: last;
13401: }
13402: }
13403: }
13404: }
13405: my ($errtext,$fatal) =
13406: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13407: '/'.$folders{$outer}.'.'.
13408: $containers{$outer});
13409: next if ($fatal);
13410: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13411: if ($context eq 'coursedocs') {
1.1056 raeburn 13412: $mapinner{$i} = time;
1.1055 raeburn 13413: $folders{$i} = 'default_'.$mapinner{$i};
13414: $containers{$i} = 'sequence';
13415: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13416: $folders{$i}.'.'.$containers{$i};
13417: my $newidx = &LONCAPA::map::getresidx();
13418: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13419: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13420: push(@LONCAPA::map::order,$newidx);
13421: my ($outtext,$errtext) =
13422: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13423: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13424: '.'.$containers{$outer},1,1);
1.1056 raeburn 13425: $newseqid{$i} = $newidx;
1.1067 raeburn 13426: unless ($errtext) {
1.1294 raeburn 13427: $result .= '<li>'.&mt('Folder: [_1] added to course',
13428: &HTML::Entities::encode($docstitle,'<>&"')).
13429: '</li>'."\n";
1.1067 raeburn 13430: }
1.1055 raeburn 13431: }
13432: } else {
13433: if ($context eq 'coursedocs') {
13434: my $newidx=&LONCAPA::map::getresidx();
13435: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13436: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13437: $title;
1.1294 raeburn 13438: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13439: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13440: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13441: }
13442: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13443: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13444: }
13445: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13446: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13447: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13448: unless ($ishome) {
13449: my $fetch = "$newdest{$i}/$title";
13450: $fetch =~ s/^\Q$prefix$dir\E//;
13451: $prompttofetch{$fetch} = 1;
13452: }
1.1292 raeburn 13453: }
1.1067 raeburn 13454: }
1.1294 raeburn 13455: $LONCAPA::map::resources[$newidx]=
13456: $docstitle.':'.$url.':false:normal:res';
13457: push(@LONCAPA::map::order, $newidx);
13458: my ($outtext,$errtext)=
13459: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13460: $docuname.'/'.$folders{$outer}.
13461: '.'.$containers{$outer},1,1);
13462: unless ($errtext) {
13463: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13464: $result .= '<li>'.&mt('File: [_1] added to course',
13465: &HTML::Entities::encode($docstitle,'<>&"')).
13466: '</li>'."\n";
13467: }
1.1067 raeburn 13468: }
1.1294 raeburn 13469: } else {
13470: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13471: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13472: }
1.1055 raeburn 13473: }
13474: }
1.1086 raeburn 13475: }
13476: } else {
1.1294 raeburn 13477: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13478: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13479: }
13480: }
13481: for (my $i=1; $i<=$numitems; $i++) {
13482: next unless ($env{'form.archive_'.$i} eq 'dependency');
13483: my $path = $env{'form.archive_content_'.$i};
13484: if ($path =~ /^\Q$pathtocheck\E/) {
13485: my ($title) = ($path =~ m{/([^/]+)$});
13486: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13487: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13488: if (ref($dirorder{$i}) eq 'ARRAY') {
13489: my ($itemidx,$fullpath,$relpath);
13490: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13491: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13492: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13493: if ($dirorder{$i}->[$j] eq $container) {
13494: $itemidx = $j;
1.1056 raeburn 13495: }
13496: }
1.1086 raeburn 13497: }
13498: if ($itemidx eq '') {
13499: $itemidx = 0;
13500: }
13501: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13502: if ($mapinner{$referrer{$i}}) {
13503: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13504: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13505: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13506: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13507: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13508: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13509: if (!-e $fullpath) {
13510: mkdir($fullpath,0755);
1.1056 raeburn 13511: }
13512: }
1.1086 raeburn 13513: } else {
13514: last;
1.1056 raeburn 13515: }
1.1086 raeburn 13516: }
13517: }
13518: } elsif ($newdest{$referrer{$i}}) {
13519: $fullpath = $newdest{$referrer{$i}};
13520: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13521: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13522: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13523: last;
13524: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13525: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13526: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13527: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13528: if (!-e $fullpath) {
13529: mkdir($fullpath,0755);
1.1056 raeburn 13530: }
13531: }
1.1086 raeburn 13532: } else {
13533: last;
1.1056 raeburn 13534: }
1.1055 raeburn 13535: }
13536: }
1.1086 raeburn 13537: if ($fullpath ne '') {
13538: if (-e "$prefix$path") {
1.1292 raeburn 13539: unless (rename("$prefix$path","$fullpath/$title")) {
13540: $warning .= &mt('Failed to rename dependency').'<br />';
13541: }
1.1086 raeburn 13542: }
13543: if (-e "$fullpath/$title") {
13544: my $showpath;
13545: if ($relpath ne '') {
13546: $showpath = "$relpath/$title";
13547: } else {
13548: $showpath = "/$title";
13549: }
1.1294 raeburn 13550: $result .= '<li>'.&mt('[_1] included as a dependency',
13551: &HTML::Entities::encode($showpath,'<>&"')).
13552: '</li>'."\n";
1.1292 raeburn 13553: unless ($ishome) {
13554: my $fetch = "$fullpath/$title";
13555: $fetch =~ s/^\Q$prefix$dir\E//;
13556: $prompttofetch{$fetch} = 1;
13557: }
1.1086 raeburn 13558: }
13559: }
1.1055 raeburn 13560: }
1.1086 raeburn 13561: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13562: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13563: &HTML::Entities::encode($path,'<>&"'),
13564: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13565: '<br />';
1.1055 raeburn 13566: }
13567: } else {
1.1294 raeburn 13568: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13569: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13570: }
13571: }
13572: if (keys(%todelete)) {
13573: foreach my $key (keys(%todelete)) {
13574: unlink($key);
1.1066 raeburn 13575: }
13576: }
13577: if (keys(%todeletedir)) {
13578: foreach my $key (keys(%todeletedir)) {
13579: rmdir($key);
13580: }
13581: }
13582: foreach my $dir (sort(keys(%is_dir))) {
13583: if (($pathtocheck ne '') && ($dir ne '')) {
13584: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13585: }
13586: }
1.1067 raeburn 13587: if ($result ne '') {
13588: $output .= '<ul>'."\n".
13589: $result."\n".
13590: '</ul>';
13591: }
13592: unless ($ishome) {
13593: my $replicationfail;
13594: foreach my $item (keys(%prompttofetch)) {
13595: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13596: unless ($fetchresult eq 'ok') {
13597: $replicationfail .= '<li>'.$item.'</li>'."\n";
13598: }
13599: }
13600: if ($replicationfail) {
13601: $output .= '<p class="LC_error">'.
13602: &mt('Course home server failed to retrieve:').'<ul>'.
13603: $replicationfail.
13604: '</ul></p>';
13605: }
13606: }
1.1055 raeburn 13607: } else {
13608: $warning = &mt('No items found in archive.');
13609: }
13610: if ($error) {
13611: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13612: $error.'</p>'."\n";
13613: }
13614: if ($warning) {
13615: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13616: }
13617: return $output;
13618: }
13619:
1.1066 raeburn 13620: sub cleanup_empty_dirs {
13621: my ($path) = @_;
13622: if (($path ne '') && (-d $path)) {
13623: if (opendir(my $dirh,$path)) {
13624: my @dircontents = grep(!/^\./,readdir($dirh));
13625: my $numitems = 0;
13626: foreach my $item (@dircontents) {
13627: if (-d "$path/$item") {
1.1111 raeburn 13628: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13629: if (-e "$path/$item") {
13630: $numitems ++;
13631: }
13632: } else {
13633: $numitems ++;
13634: }
13635: }
13636: if ($numitems == 0) {
13637: rmdir($path);
13638: }
13639: closedir($dirh);
13640: }
13641: }
13642: return;
13643: }
13644:
1.41 ng 13645: =pod
1.45 matthew 13646:
1.1162 raeburn 13647: =item * &get_folder_hierarchy()
1.1068 raeburn 13648:
13649: Provides hierarchy of names of folders/sub-folders containing the current
13650: item,
13651:
13652: Inputs: 3
13653: - $navmap - navmaps object
13654:
13655: - $map - url for map (either the trigger itself, or map containing
13656: the resource, which is the trigger).
13657:
13658: - $showitem - 1 => show title for map itself; 0 => do not show.
13659:
13660: Outputs: 1 @pathitems - array of folder/subfolder names.
13661:
13662: =cut
13663:
13664: sub get_folder_hierarchy {
13665: my ($navmap,$map,$showitem) = @_;
13666: my @pathitems;
13667: if (ref($navmap)) {
13668: my $mapres = $navmap->getResourceByUrl($map);
13669: if (ref($mapres)) {
13670: my $pcslist = $mapres->map_hierarchy();
13671: if ($pcslist ne '') {
13672: my @pcs = split(/,/,$pcslist);
13673: foreach my $pc (@pcs) {
13674: if ($pc == 1) {
1.1129 raeburn 13675: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13676: } else {
13677: my $res = $navmap->getByMapPc($pc);
13678: if (ref($res)) {
13679: my $title = $res->compTitle();
13680: $title =~ s/\W+/_/g;
13681: if ($title ne '') {
13682: push(@pathitems,$title);
13683: }
13684: }
13685: }
13686: }
13687: }
1.1071 raeburn 13688: if ($showitem) {
13689: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13690: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13691: } else {
13692: my $maptitle = $mapres->compTitle();
13693: $maptitle =~ s/\W+/_/g;
13694: if ($maptitle ne '') {
13695: push(@pathitems,$maptitle);
13696: }
1.1068 raeburn 13697: }
13698: }
13699: }
13700: }
13701: return @pathitems;
13702: }
13703:
13704: =pod
13705:
1.1015 raeburn 13706: =item * &get_turnedin_filepath()
13707:
13708: Determines path in a user's portfolio file for storage of files uploaded
13709: to a specific essayresponse or dropbox item.
13710:
13711: Inputs: 3 required + 1 optional.
13712: $symb is symb for resource, $uname and $udom are for current user (required).
13713: $caller is optional (can be "submission", if routine is called when storing
13714: an upoaded file when "Submit Answer" button was pressed).
13715:
13716: Returns array containing $path and $multiresp.
13717: $path is path in portfolio. $multiresp is 1 if this resource contains more
13718: than one file upload item. Callers of routine should append partid as a
13719: subdirectory to $path in cases where $multiresp is 1.
13720:
13721: Called by: homework/essayresponse.pm and homework/structuretags.pm
13722:
13723: =cut
13724:
13725: sub get_turnedin_filepath {
13726: my ($symb,$uname,$udom,$caller) = @_;
13727: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13728: my $turnindir;
13729: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13730: $turnindir = $userhash{'turnindir'};
13731: my ($path,$multiresp);
13732: if ($turnindir eq '') {
13733: if ($caller eq 'submission') {
13734: $turnindir = &mt('turned in');
13735: $turnindir =~ s/\W+/_/g;
13736: my %newhash = (
13737: 'turnindir' => $turnindir,
13738: );
13739: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13740: }
13741: }
13742: if ($turnindir ne '') {
13743: $path = '/'.$turnindir.'/';
13744: my ($multipart,$turnin,@pathitems);
13745: my $navmap = Apache::lonnavmaps::navmap->new();
13746: if (defined($navmap)) {
13747: my $mapres = $navmap->getResourceByUrl($map);
13748: if (ref($mapres)) {
13749: my $pcslist = $mapres->map_hierarchy();
13750: if ($pcslist ne '') {
13751: foreach my $pc (split(/,/,$pcslist)) {
13752: my $res = $navmap->getByMapPc($pc);
13753: if (ref($res)) {
13754: my $title = $res->compTitle();
13755: $title =~ s/\W+/_/g;
13756: if ($title ne '') {
1.1149 raeburn 13757: if (($pc > 1) && (length($title) > 12)) {
13758: $title = substr($title,0,12);
13759: }
1.1015 raeburn 13760: push(@pathitems,$title);
13761: }
13762: }
13763: }
13764: }
13765: my $maptitle = $mapres->compTitle();
13766: $maptitle =~ s/\W+/_/g;
13767: if ($maptitle ne '') {
1.1149 raeburn 13768: if (length($maptitle) > 12) {
13769: $maptitle = substr($maptitle,0,12);
13770: }
1.1015 raeburn 13771: push(@pathitems,$maptitle);
13772: }
13773: unless ($env{'request.state'} eq 'construct') {
13774: my $res = $navmap->getBySymb($symb);
13775: if (ref($res)) {
13776: my $partlist = $res->parts();
13777: my $totaluploads = 0;
13778: if (ref($partlist) eq 'ARRAY') {
13779: foreach my $part (@{$partlist}) {
13780: my @types = $res->responseType($part);
13781: my @ids = $res->responseIds($part);
13782: for (my $i=0; $i < scalar(@ids); $i++) {
13783: if ($types[$i] eq 'essay') {
13784: my $partid = $part.'_'.$ids[$i];
13785: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13786: $totaluploads ++;
13787: }
13788: }
13789: }
13790: }
13791: if ($totaluploads > 1) {
13792: $multiresp = 1;
13793: }
13794: }
13795: }
13796: }
13797: } else {
13798: return;
13799: }
13800: } else {
13801: return;
13802: }
13803: my $restitle=&Apache::lonnet::gettitle($symb);
13804: $restitle =~ s/\W+/_/g;
13805: if ($restitle eq '') {
13806: $restitle = ($resurl =~ m{/[^/]+$});
13807: if ($restitle eq '') {
13808: $restitle = time;
13809: }
13810: }
1.1149 raeburn 13811: if (length($restitle) > 12) {
13812: $restitle = substr($restitle,0,12);
13813: }
1.1015 raeburn 13814: push(@pathitems,$restitle);
13815: $path .= join('/',@pathitems);
13816: }
13817: return ($path,$multiresp);
13818: }
13819:
13820: =pod
13821:
1.464 albertel 13822: =back
1.41 ng 13823:
1.112 bowersj2 13824: =head1 CSV Upload/Handling functions
1.38 albertel 13825:
1.41 ng 13826: =over 4
13827:
1.648 raeburn 13828: =item * &upfile_store($r)
1.41 ng 13829:
13830: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13831: needs $env{'form.upfile'}
1.41 ng 13832: returns $datatoken to be put into hidden field
13833:
13834: =cut
1.31 albertel 13835:
13836: sub upfile_store {
13837: my $r=shift;
1.258 albertel 13838: $env{'form.upfile'}=~s/\r/\n/gs;
13839: $env{'form.upfile'}=~s/\f/\n/gs;
13840: $env{'form.upfile'}=~s/\n+/\n/gs;
13841: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13842:
1.1299 raeburn 13843: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13844: '_enroll_'.$env{'request.course.id'}.'_'.
13845: time.'_'.$$);
13846: return if ($datatoken eq '');
13847:
1.31 albertel 13848: {
1.158 raeburn 13849: my $datafile = $r->dir_config('lonDaemons').
13850: '/tmp/'.$datatoken.'.tmp';
13851: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13852: print $fh $env{'form.upfile'};
1.158 raeburn 13853: close($fh);
13854: }
1.31 albertel 13855: }
13856: return $datatoken;
13857: }
13858:
1.56 matthew 13859: =pod
13860:
1.1290 raeburn 13861: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13862:
13863: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 13864: $datatoken is the name to assign to the temporary file.
1.258 albertel 13865: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13866:
13867: =cut
1.31 albertel 13868:
13869: sub load_tmp_file {
1.1290 raeburn 13870: my ($r,$datatoken) = @_;
13871: return if ($datatoken eq '');
1.31 albertel 13872: my @studentdata=();
13873: {
1.158 raeburn 13874: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 13875: '/tmp/'.$datatoken.'.tmp';
1.158 raeburn 13876: if ( open(my $fh,"<$studentfile") ) {
13877: @studentdata=<$fh>;
13878: close($fh);
13879: }
1.31 albertel 13880: }
1.258 albertel 13881: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13882: }
13883:
1.1290 raeburn 13884: sub valid_datatoken {
13885: my ($datatoken) = @_;
1.1291 raeburn 13886: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_$match_domain\_$match_courseid\_\d+_\d+$/) {
1.1290 raeburn 13887: return $datatoken;
13888: }
13889: return;
13890: }
13891:
1.56 matthew 13892: =pod
13893:
1.648 raeburn 13894: =item * &upfile_record_sep()
1.41 ng 13895:
13896: Separate uploaded file into records
13897: returns array of records,
1.258 albertel 13898: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13899:
13900: =cut
1.31 albertel 13901:
13902: sub upfile_record_sep {
1.258 albertel 13903: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13904: } else {
1.248 albertel 13905: my @records;
1.258 albertel 13906: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13907: if ($line=~/^\s*$/) { next; }
13908: push(@records,$line);
13909: }
13910: return @records;
1.31 albertel 13911: }
13912: }
13913:
1.56 matthew 13914: =pod
13915:
1.648 raeburn 13916: =item * &record_sep($record)
1.41 ng 13917:
1.258 albertel 13918: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13919:
13920: =cut
13921:
1.263 www 13922: sub takeleft {
13923: my $index=shift;
13924: return substr('0000'.$index,-4,4);
13925: }
13926:
1.31 albertel 13927: sub record_sep {
13928: my $record=shift;
13929: my %components=();
1.258 albertel 13930: if ($env{'form.upfiletype'} eq 'xml') {
13931: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13932: my $i=0;
1.356 albertel 13933: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13934: $field=~s/^(\"|\')//;
13935: $field=~s/(\"|\')$//;
1.263 www 13936: $components{&takeleft($i)}=$field;
1.31 albertel 13937: $i++;
13938: }
1.258 albertel 13939: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13940: my $i=0;
1.356 albertel 13941: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13942: $field=~s/^(\"|\')//;
13943: $field=~s/(\"|\')$//;
1.263 www 13944: $components{&takeleft($i)}=$field;
1.31 albertel 13945: $i++;
13946: }
13947: } else {
1.561 www 13948: my $separator=',';
1.480 banghart 13949: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13950: $separator=';';
1.480 banghart 13951: }
1.31 albertel 13952: my $i=0;
1.561 www 13953: # the character we are looking for to indicate the end of a quote or a record
13954: my $looking_for=$separator;
13955: # do not add the characters to the fields
13956: my $ignore=0;
13957: # we just encountered a separator (or the beginning of the record)
13958: my $just_found_separator=1;
13959: # store the field we are working on here
13960: my $field='';
13961: # work our way through all characters in record
13962: foreach my $character ($record=~/(.)/g) {
13963: if ($character eq $looking_for) {
13964: if ($character ne $separator) {
13965: # Found the end of a quote, again looking for separator
13966: $looking_for=$separator;
13967: $ignore=1;
13968: } else {
13969: # Found a separator, store away what we got
13970: $components{&takeleft($i)}=$field;
13971: $i++;
13972: $just_found_separator=1;
13973: $ignore=0;
13974: $field='';
13975: }
13976: next;
13977: }
13978: # single or double quotation marks after a separator indicate beginning of a quote
13979: # we are now looking for the end of the quote and need to ignore separators
13980: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13981: $looking_for=$character;
13982: next;
13983: }
13984: # ignore would be true after we reached the end of a quote
13985: if ($ignore) { next; }
13986: if (($just_found_separator) && ($character=~/\s/)) { next; }
13987: $field.=$character;
13988: $just_found_separator=0;
1.31 albertel 13989: }
1.561 www 13990: # catch the very last entry, since we never encountered the separator
13991: $components{&takeleft($i)}=$field;
1.31 albertel 13992: }
13993: return %components;
13994: }
13995:
1.144 matthew 13996: ######################################################
13997: ######################################################
13998:
1.56 matthew 13999: =pod
14000:
1.648 raeburn 14001: =item * &upfile_select_html()
1.41 ng 14002:
1.144 matthew 14003: Return HTML code to select a file from the users machine and specify
14004: the file type.
1.41 ng 14005:
14006: =cut
14007:
1.144 matthew 14008: ######################################################
14009: ######################################################
1.31 albertel 14010: sub upfile_select_html {
1.144 matthew 14011: my %Types = (
14012: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14013: semisv => &mt('Semicolon separated values'),
1.144 matthew 14014: space => &mt('Space separated'),
14015: tab => &mt('Tabulator separated'),
14016: # xml => &mt('HTML/XML'),
14017: );
14018: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14019: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14020: foreach my $type (sort(keys(%Types))) {
14021: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14022: }
14023: $Str .= "</select>\n";
14024: return $Str;
1.31 albertel 14025: }
14026:
1.301 albertel 14027: sub get_samples {
14028: my ($records,$toget) = @_;
14029: my @samples=({});
14030: my $got=0;
14031: foreach my $rec (@$records) {
14032: my %temp = &record_sep($rec);
14033: if (! grep(/\S/, values(%temp))) { next; }
14034: if (%temp) {
14035: $samples[$got]=\%temp;
14036: $got++;
14037: if ($got == $toget) { last; }
14038: }
14039: }
14040: return \@samples;
14041: }
14042:
1.144 matthew 14043: ######################################################
14044: ######################################################
14045:
1.56 matthew 14046: =pod
14047:
1.648 raeburn 14048: =item * &csv_print_samples($r,$records)
1.41 ng 14049:
14050: Prints a table of sample values from each column uploaded $r is an
14051: Apache Request ref, $records is an arrayref from
14052: &Apache::loncommon::upfile_record_sep
14053:
14054: =cut
14055:
1.144 matthew 14056: ######################################################
14057: ######################################################
1.31 albertel 14058: sub csv_print_samples {
14059: my ($r,$records) = @_;
1.662 bisitz 14060: my $samples = &get_samples($records,5);
1.301 albertel 14061:
1.594 raeburn 14062: $r->print(&mt('Samples').'<br />'.&start_data_table().
14063: &start_data_table_header_row());
1.356 albertel 14064: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14065: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14066: $r->print(&end_data_table_header_row());
1.301 albertel 14067: foreach my $hash (@$samples) {
1.594 raeburn 14068: $r->print(&start_data_table_row());
1.356 albertel 14069: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14070: $r->print('<td>');
1.356 albertel 14071: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14072: $r->print('</td>');
14073: }
1.594 raeburn 14074: $r->print(&end_data_table_row());
1.31 albertel 14075: }
1.594 raeburn 14076: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14077: }
14078:
1.144 matthew 14079: ######################################################
14080: ######################################################
14081:
1.56 matthew 14082: =pod
14083:
1.648 raeburn 14084: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14085:
14086: Prints a table to create associations between values and table columns.
1.144 matthew 14087:
1.41 ng 14088: $r is an Apache Request ref,
14089: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14090: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14091:
14092: =cut
14093:
1.144 matthew 14094: ######################################################
14095: ######################################################
1.31 albertel 14096: sub csv_print_select_table {
14097: my ($r,$records,$d) = @_;
1.301 albertel 14098: my $i=0;
14099: my $samples = &get_samples($records,1);
1.144 matthew 14100: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14101: &start_data_table().&start_data_table_header_row().
1.144 matthew 14102: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14103: '<th>'.&mt('Column').'</th>'.
14104: &end_data_table_header_row()."\n");
1.356 albertel 14105: foreach my $array_ref (@$d) {
14106: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14107: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14108:
1.875 bisitz 14109: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14110: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14111: $r->print('<option value="none"></option>');
1.356 albertel 14112: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14113: $r->print('<option value="'.$sample.'"'.
14114: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14115: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14116: }
1.594 raeburn 14117: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14118: $i++;
14119: }
1.594 raeburn 14120: $r->print(&end_data_table());
1.31 albertel 14121: $i--;
14122: return $i;
14123: }
1.56 matthew 14124:
1.144 matthew 14125: ######################################################
14126: ######################################################
14127:
1.56 matthew 14128: =pod
1.31 albertel 14129:
1.648 raeburn 14130: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14131:
14132: Prints a table of sample values from the upload and can make associate samples to internal names.
14133:
14134: $r is an Apache Request ref,
14135: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14136: $d is an array of 2 element arrays (internal name, displayed name)
14137:
14138: =cut
14139:
1.144 matthew 14140: ######################################################
14141: ######################################################
1.31 albertel 14142: sub csv_samples_select_table {
14143: my ($r,$records,$d) = @_;
14144: my $i=0;
1.144 matthew 14145: #
1.662 bisitz 14146: my $max_samples = 5;
14147: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14148: $r->print(&start_data_table().
14149: &start_data_table_header_row().'<th>'.
14150: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14151: &end_data_table_header_row());
1.301 albertel 14152:
14153: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14154: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14155: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14156: foreach my $option (@$d) {
14157: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14158: $r->print('<option value="'.$value.'"'.
1.253 albertel 14159: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14160: $display.'</option>');
1.31 albertel 14161: }
14162: $r->print('</select></td><td>');
1.662 bisitz 14163: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14164: if (defined($samples->[$line]{$key})) {
14165: $r->print($samples->[$line]{$key}."<br />\n");
14166: }
14167: }
1.594 raeburn 14168: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14169: $i++;
14170: }
1.594 raeburn 14171: $r->print(&end_data_table());
1.31 albertel 14172: $i--;
14173: return($i);
1.115 matthew 14174: }
14175:
1.144 matthew 14176: ######################################################
14177: ######################################################
14178:
1.115 matthew 14179: =pod
14180:
1.648 raeburn 14181: =item * &clean_excel_name($name)
1.115 matthew 14182:
14183: Returns a replacement for $name which does not contain any illegal characters.
14184:
14185: =cut
14186:
1.144 matthew 14187: ######################################################
14188: ######################################################
1.115 matthew 14189: sub clean_excel_name {
14190: my ($name) = @_;
14191: $name =~ s/[:\*\?\/\\]//g;
14192: if (length($name) > 31) {
14193: $name = substr($name,0,31);
14194: }
14195: return $name;
1.25 albertel 14196: }
1.84 albertel 14197:
1.85 albertel 14198: =pod
14199:
1.648 raeburn 14200: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14201:
14202: Returns either 1 or undef
14203:
14204: 1 if the part is to be hidden, undef if it is to be shown
14205:
14206: Arguments are:
14207:
14208: $id the id of the part to be checked
14209: $symb, optional the symb of the resource to check
14210: $udom, optional the domain of the user to check for
14211: $uname, optional the username of the user to check for
14212:
14213: =cut
1.84 albertel 14214:
14215: sub check_if_partid_hidden {
14216: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14217: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14218: $symb,$udom,$uname);
1.141 albertel 14219: my $truth=1;
14220: #if the string starts with !, then the list is the list to show not hide
14221: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14222: my @hiddenlist=split(/,/,$hiddenparts);
14223: foreach my $checkid (@hiddenlist) {
1.141 albertel 14224: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14225: }
1.141 albertel 14226: return !$truth;
1.84 albertel 14227: }
1.127 matthew 14228:
1.138 matthew 14229:
14230: ############################################################
14231: ############################################################
14232:
14233: =pod
14234:
1.157 matthew 14235: =back
14236:
1.138 matthew 14237: =head1 cgi-bin script and graphing routines
14238:
1.157 matthew 14239: =over 4
14240:
1.648 raeburn 14241: =item * &get_cgi_id()
1.138 matthew 14242:
14243: Inputs: none
14244:
14245: Returns an id which can be used to pass environment variables
14246: to various cgi-bin scripts. These environment variables will
14247: be removed from the users environment after a given time by
14248: the routine &Apache::lonnet::transfer_profile_to_env.
14249:
14250: =cut
14251:
14252: ############################################################
14253: ############################################################
1.152 albertel 14254: my $uniq=0;
1.136 matthew 14255: sub get_cgi_id {
1.154 albertel 14256: $uniq=($uniq+1)%100000;
1.280 albertel 14257: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14258: }
14259:
1.127 matthew 14260: ############################################################
14261: ############################################################
14262:
14263: =pod
14264:
1.648 raeburn 14265: =item * &DrawBarGraph()
1.127 matthew 14266:
1.138 matthew 14267: Facilitates the plotting of data in a (stacked) bar graph.
14268: Puts plot definition data into the users environment in order for
14269: graph.png to plot it. Returns an <img> tag for the plot.
14270: The bars on the plot are labeled '1','2',...,'n'.
14271:
14272: Inputs:
14273:
14274: =over 4
14275:
14276: =item $Title: string, the title of the plot
14277:
14278: =item $xlabel: string, text describing the X-axis of the plot
14279:
14280: =item $ylabel: string, text describing the Y-axis of the plot
14281:
14282: =item $Max: scalar, the maximum Y value to use in the plot
14283: If $Max is < any data point, the graph will not be rendered.
14284:
1.140 matthew 14285: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14286: they are plotted. If undefined, default values will be used.
14287:
1.178 matthew 14288: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14289:
1.138 matthew 14290: =item @Values: An array of array references. Each array reference holds data
14291: to be plotted in a stacked bar chart.
14292:
1.239 matthew 14293: =item If the final element of @Values is a hash reference the key/value
14294: pairs will be added to the graph definition.
14295:
1.138 matthew 14296: =back
14297:
14298: Returns:
14299:
14300: An <img> tag which references graph.png and the appropriate identifying
14301: information for the plot.
14302:
1.127 matthew 14303: =cut
14304:
14305: ############################################################
14306: ############################################################
1.134 matthew 14307: sub DrawBarGraph {
1.178 matthew 14308: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14309: #
14310: if (! defined($colors)) {
14311: $colors = ['#33ff00',
14312: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14313: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14314: ];
14315: }
1.228 matthew 14316: my $extra_settings = {};
14317: if (ref($Values[-1]) eq 'HASH') {
14318: $extra_settings = pop(@Values);
14319: }
1.127 matthew 14320: #
1.136 matthew 14321: my $identifier = &get_cgi_id();
14322: my $id = 'cgi.'.$identifier;
1.129 matthew 14323: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14324: return '';
14325: }
1.225 matthew 14326: #
14327: my @Labels;
14328: if (defined($labels)) {
14329: @Labels = @$labels;
14330: } else {
14331: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14332: push(@Labels,$i+1);
1.225 matthew 14333: }
14334: }
14335: #
1.129 matthew 14336: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14337: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14338: my %ValuesHash;
14339: my $NumSets=1;
14340: foreach my $array (@Values) {
14341: next if (! ref($array));
1.136 matthew 14342: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14343: join(',',@$array);
1.129 matthew 14344: }
1.127 matthew 14345: #
1.136 matthew 14346: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14347: if ($NumBars < 3) {
14348: $width = 120+$NumBars*32;
1.220 matthew 14349: $xskip = 1;
1.225 matthew 14350: $bar_width = 30;
14351: } elsif ($NumBars < 5) {
14352: $width = 120+$NumBars*20;
14353: $xskip = 1;
14354: $bar_width = 20;
1.220 matthew 14355: } elsif ($NumBars < 10) {
1.136 matthew 14356: $width = 120+$NumBars*15;
14357: $xskip = 1;
14358: $bar_width = 15;
14359: } elsif ($NumBars <= 25) {
14360: $width = 120+$NumBars*11;
14361: $xskip = 5;
14362: $bar_width = 8;
14363: } elsif ($NumBars <= 50) {
14364: $width = 120+$NumBars*8;
14365: $xskip = 5;
14366: $bar_width = 4;
14367: } else {
14368: $width = 120+$NumBars*8;
14369: $xskip = 5;
14370: $bar_width = 4;
14371: }
14372: #
1.137 matthew 14373: $Max = 1 if ($Max < 1);
14374: if ( int($Max) < $Max ) {
14375: $Max++;
14376: $Max = int($Max);
14377: }
1.127 matthew 14378: $Title = '' if (! defined($Title));
14379: $xlabel = '' if (! defined($xlabel));
14380: $ylabel = '' if (! defined($ylabel));
1.369 www 14381: $ValuesHash{$id.'.title'} = &escape($Title);
14382: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14383: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14384: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14385: $ValuesHash{$id.'.NumBars'} = $NumBars;
14386: $ValuesHash{$id.'.NumSets'} = $NumSets;
14387: $ValuesHash{$id.'.PlotType'} = 'bar';
14388: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14389: $ValuesHash{$id.'.height'} = $height;
14390: $ValuesHash{$id.'.width'} = $width;
14391: $ValuesHash{$id.'.xskip'} = $xskip;
14392: $ValuesHash{$id.'.bar_width'} = $bar_width;
14393: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14394: #
1.228 matthew 14395: # Deal with other parameters
14396: while (my ($key,$value) = each(%$extra_settings)) {
14397: $ValuesHash{$id.'.'.$key} = $value;
14398: }
14399: #
1.646 raeburn 14400: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14401: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14402: }
14403:
14404: ############################################################
14405: ############################################################
14406:
14407: =pod
14408:
1.648 raeburn 14409: =item * &DrawXYGraph()
1.137 matthew 14410:
1.138 matthew 14411: Facilitates the plotting of data in an XY graph.
14412: Puts plot definition data into the users environment in order for
14413: graph.png to plot it. Returns an <img> tag for the plot.
14414:
14415: Inputs:
14416:
14417: =over 4
14418:
14419: =item $Title: string, the title of the plot
14420:
14421: =item $xlabel: string, text describing the X-axis of the plot
14422:
14423: =item $ylabel: string, text describing the Y-axis of the plot
14424:
14425: =item $Max: scalar, the maximum Y value to use in the plot
14426: If $Max is < any data point, the graph will not be rendered.
14427:
14428: =item $colors: Array ref containing the hex color codes for the data to be
14429: plotted in. If undefined, default values will be used.
14430:
14431: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14432:
14433: =item $Ydata: Array ref containing Array refs.
1.185 www 14434: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14435:
14436: =item %Values: hash indicating or overriding any default values which are
14437: passed to graph.png.
14438: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14439:
14440: =back
14441:
14442: Returns:
14443:
14444: An <img> tag which references graph.png and the appropriate identifying
14445: information for the plot.
14446:
1.137 matthew 14447: =cut
14448:
14449: ############################################################
14450: ############################################################
14451: sub DrawXYGraph {
14452: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14453: #
14454: # Create the identifier for the graph
14455: my $identifier = &get_cgi_id();
14456: my $id = 'cgi.'.$identifier;
14457: #
14458: $Title = '' if (! defined($Title));
14459: $xlabel = '' if (! defined($xlabel));
14460: $ylabel = '' if (! defined($ylabel));
14461: my %ValuesHash =
14462: (
1.369 www 14463: $id.'.title' => &escape($Title),
14464: $id.'.xlabel' => &escape($xlabel),
14465: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14466: $id.'.y_max_value'=> $Max,
14467: $id.'.labels' => join(',',@$Xlabels),
14468: $id.'.PlotType' => 'XY',
14469: );
14470: #
14471: if (defined($colors) && ref($colors) eq 'ARRAY') {
14472: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14473: }
14474: #
14475: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14476: return '';
14477: }
14478: my $NumSets=1;
1.138 matthew 14479: foreach my $array (@{$Ydata}){
1.137 matthew 14480: next if (! ref($array));
14481: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14482: }
1.138 matthew 14483: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14484: #
14485: # Deal with other parameters
14486: while (my ($key,$value) = each(%Values)) {
14487: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14488: }
14489: #
1.646 raeburn 14490: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14491: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14492: }
14493:
14494: ############################################################
14495: ############################################################
14496:
14497: =pod
14498:
1.648 raeburn 14499: =item * &DrawXYYGraph()
1.138 matthew 14500:
14501: Facilitates the plotting of data in an XY graph with two Y axes.
14502: Puts plot definition data into the users environment in order for
14503: graph.png to plot it. Returns an <img> tag for the plot.
14504:
14505: Inputs:
14506:
14507: =over 4
14508:
14509: =item $Title: string, the title of the plot
14510:
14511: =item $xlabel: string, text describing the X-axis of the plot
14512:
14513: =item $ylabel: string, text describing the Y-axis of the plot
14514:
14515: =item $colors: Array ref containing the hex color codes for the data to be
14516: plotted in. If undefined, default values will be used.
14517:
14518: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14519:
14520: =item $Ydata1: The first data set
14521:
14522: =item $Min1: The minimum value of the left Y-axis
14523:
14524: =item $Max1: The maximum value of the left Y-axis
14525:
14526: =item $Ydata2: The second data set
14527:
14528: =item $Min2: The minimum value of the right Y-axis
14529:
14530: =item $Max2: The maximum value of the left Y-axis
14531:
14532: =item %Values: hash indicating or overriding any default values which are
14533: passed to graph.png.
14534: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14535:
14536: =back
14537:
14538: Returns:
14539:
14540: An <img> tag which references graph.png and the appropriate identifying
14541: information for the plot.
1.136 matthew 14542:
14543: =cut
14544:
14545: ############################################################
14546: ############################################################
1.137 matthew 14547: sub DrawXYYGraph {
14548: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14549: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14550: #
14551: # Create the identifier for the graph
14552: my $identifier = &get_cgi_id();
14553: my $id = 'cgi.'.$identifier;
14554: #
14555: $Title = '' if (! defined($Title));
14556: $xlabel = '' if (! defined($xlabel));
14557: $ylabel = '' if (! defined($ylabel));
14558: my %ValuesHash =
14559: (
1.369 www 14560: $id.'.title' => &escape($Title),
14561: $id.'.xlabel' => &escape($xlabel),
14562: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14563: $id.'.labels' => join(',',@$Xlabels),
14564: $id.'.PlotType' => 'XY',
14565: $id.'.NumSets' => 2,
1.137 matthew 14566: $id.'.two_axes' => 1,
14567: $id.'.y1_max_value' => $Max1,
14568: $id.'.y1_min_value' => $Min1,
14569: $id.'.y2_max_value' => $Max2,
14570: $id.'.y2_min_value' => $Min2,
1.136 matthew 14571: );
14572: #
1.137 matthew 14573: if (defined($colors) && ref($colors) eq 'ARRAY') {
14574: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14575: }
14576: #
14577: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14578: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14579: return '';
14580: }
14581: my $NumSets=1;
1.137 matthew 14582: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14583: next if (! ref($array));
14584: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14585: }
14586: #
14587: # Deal with other parameters
14588: while (my ($key,$value) = each(%Values)) {
14589: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14590: }
14591: #
1.646 raeburn 14592: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14593: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14594: }
14595:
14596: ############################################################
14597: ############################################################
14598:
14599: =pod
14600:
1.157 matthew 14601: =back
14602:
1.139 matthew 14603: =head1 Statistics helper routines?
14604:
14605: Bad place for them but what the hell.
14606:
1.157 matthew 14607: =over 4
14608:
1.648 raeburn 14609: =item * &chartlink()
1.139 matthew 14610:
14611: Returns a link to the chart for a specific student.
14612:
14613: Inputs:
14614:
14615: =over 4
14616:
14617: =item $linktext: The text of the link
14618:
14619: =item $sname: The students username
14620:
14621: =item $sdomain: The students domain
14622:
14623: =back
14624:
1.157 matthew 14625: =back
14626:
1.139 matthew 14627: =cut
14628:
14629: ############################################################
14630: ############################################################
14631: sub chartlink {
14632: my ($linktext, $sname, $sdomain) = @_;
14633: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14634: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14635: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14636: '">'.$linktext.'</a>';
1.153 matthew 14637: }
14638:
14639: #######################################################
14640: #######################################################
14641:
14642: =pod
14643:
14644: =head1 Course Environment Routines
1.157 matthew 14645:
14646: =over 4
1.153 matthew 14647:
1.648 raeburn 14648: =item * &restore_course_settings()
1.153 matthew 14649:
1.648 raeburn 14650: =item * &store_course_settings()
1.153 matthew 14651:
14652: Restores/Store indicated form parameters from the course environment.
14653: Will not overwrite existing values of the form parameters.
14654:
14655: Inputs:
14656: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14657:
14658: a hash ref describing the data to be stored. For example:
14659:
14660: %Save_Parameters = ('Status' => 'scalar',
14661: 'chartoutputmode' => 'scalar',
14662: 'chartoutputdata' => 'scalar',
14663: 'Section' => 'array',
1.373 raeburn 14664: 'Group' => 'array',
1.153 matthew 14665: 'StudentData' => 'array',
14666: 'Maps' => 'array');
14667:
14668: Returns: both routines return nothing
14669:
1.631 raeburn 14670: =back
14671:
1.153 matthew 14672: =cut
14673:
14674: #######################################################
14675: #######################################################
14676: sub store_course_settings {
1.496 albertel 14677: return &store_settings($env{'request.course.id'},@_);
14678: }
14679:
14680: sub store_settings {
1.153 matthew 14681: # save to the environment
14682: # appenv the same items, just to be safe
1.300 albertel 14683: my $udom = $env{'user.domain'};
14684: my $uname = $env{'user.name'};
1.496 albertel 14685: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14686: my %SaveHash;
14687: my %AppHash;
14688: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14689: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14690: my $envname = 'environment.'.$basename;
1.258 albertel 14691: if (exists($env{'form.'.$setting})) {
1.153 matthew 14692: # Save this value away
14693: if ($type eq 'scalar' &&
1.258 albertel 14694: (! exists($env{$envname}) ||
14695: $env{$envname} ne $env{'form.'.$setting})) {
14696: $SaveHash{$basename} = $env{'form.'.$setting};
14697: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14698: } elsif ($type eq 'array') {
14699: my $stored_form;
1.258 albertel 14700: if (ref($env{'form.'.$setting})) {
1.153 matthew 14701: $stored_form = join(',',
14702: map {
1.369 www 14703: &escape($_);
1.258 albertel 14704: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14705: } else {
14706: $stored_form =
1.369 www 14707: &escape($env{'form.'.$setting});
1.153 matthew 14708: }
14709: # Determine if the array contents are the same.
1.258 albertel 14710: if ($stored_form ne $env{$envname}) {
1.153 matthew 14711: $SaveHash{$basename} = $stored_form;
14712: $AppHash{$envname} = $stored_form;
14713: }
14714: }
14715: }
14716: }
14717: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14718: $udom,$uname);
1.153 matthew 14719: if ($put_result !~ /^(ok|delayed)/) {
14720: &Apache::lonnet::logthis('unable to save form parameters, '.
14721: 'got error:'.$put_result);
14722: }
14723: # Make sure these settings stick around in this session, too
1.646 raeburn 14724: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14725: return;
14726: }
14727:
14728: sub restore_course_settings {
1.499 albertel 14729: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14730: }
14731:
14732: sub restore_settings {
14733: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14734: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14735: next if (exists($env{'form.'.$setting}));
1.496 albertel 14736: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14737: '.'.$setting;
1.258 albertel 14738: if (exists($env{$envname})) {
1.153 matthew 14739: if ($type eq 'scalar') {
1.258 albertel 14740: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14741: } elsif ($type eq 'array') {
1.258 albertel 14742: $env{'form.'.$setting} = [
1.153 matthew 14743: map {
1.369 www 14744: &unescape($_);
1.258 albertel 14745: } split(',',$env{$envname})
1.153 matthew 14746: ];
14747: }
14748: }
14749: }
1.127 matthew 14750: }
14751:
1.618 raeburn 14752: #######################################################
14753: #######################################################
14754:
14755: =pod
14756:
14757: =head1 Domain E-mail Routines
14758:
14759: =over 4
14760:
1.648 raeburn 14761: =item * &build_recipient_list()
1.618 raeburn 14762:
1.1144 raeburn 14763: Build recipient lists for following types of e-mail:
1.766 raeburn 14764: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14765: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14766: module change checking, student/employee ID conflict checks, as
14767: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14768: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14769:
14770: Inputs:
1.619 raeburn 14771: defmail (scalar - email address of default recipient),
1.1144 raeburn 14772: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14773: requestsmail, updatesmail, or idconflictsmail).
14774:
1.619 raeburn 14775: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14776:
1.619 raeburn 14777: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14778: i.e., predates configuration by DC via domainprefs.pm
14779:
14780: $requname username of requester (if mailing type is helpdeskmail)
14781:
14782: $requdom domain of requester (if mailing type is helpdeskmail)
14783:
14784: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14785:
1.618 raeburn 14786:
1.655 raeburn 14787: Returns: comma separated list of addresses to which to send e-mail.
14788:
14789: =back
1.618 raeburn 14790:
14791: =cut
14792:
14793: ############################################################
14794: ############################################################
14795: sub build_recipient_list {
1.1297 raeburn 14796: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14797: my @recipients;
1.1270 raeburn 14798: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14799: my %domconfig =
1.1270 raeburn 14800: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14801: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14802: if (exists($domconfig{'contacts'}{$mailing})) {
14803: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14804: my @contacts = ('adminemail','supportemail');
14805: foreach my $item (@contacts) {
14806: if ($domconfig{'contacts'}{$mailing}{$item}) {
14807: my $addr = $domconfig{'contacts'}{$item};
14808: if (!grep(/^\Q$addr\E$/,@recipients)) {
14809: push(@recipients,$addr);
14810: }
1.619 raeburn 14811: }
1.1270 raeburn 14812: }
14813: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14814: if ($mailing eq 'helpdeskmail') {
14815: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14816: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14817: my @ok_bccs;
14818: foreach my $bcc (@bccs) {
14819: $bcc =~ s/^\s+//g;
14820: $bcc =~ s/\s+$//g;
14821: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14822: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14823: push(@ok_bccs,$bcc);
14824: }
14825: }
14826: }
14827: if (@ok_bccs > 0) {
14828: $allbcc = join(', ',@ok_bccs);
14829: }
14830: }
14831: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14832: }
14833: }
1.766 raeburn 14834: } elsif ($origmail ne '') {
1.1270 raeburn 14835: $lastresort = $origmail;
1.618 raeburn 14836: }
1.1297 raeburn 14837: if ($mailing eq 'helpdeskmail') {
14838: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14839: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14840: my ($inststatus,$inststatus_checked);
14841: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14842: ($env{'user.domain'} ne 'public')) {
14843: $inststatus_checked = 1;
14844: $inststatus = $env{'environment.inststatus'};
14845: }
14846: unless ($inststatus_checked) {
14847: if (($requname ne '') && ($requdom ne '')) {
14848: if (($requname =~ /^$match_username$/) &&
14849: ($requdom =~ /^$match_domain$/) &&
14850: (&Apache::lonnet::domain($requdom))) {
14851: my $requhome = &Apache::lonnet::homeserver($requname,
14852: $requdom);
14853: unless ($requhome eq 'no_host') {
14854: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14855: $inststatus = $userenv{'inststatus'};
14856: $inststatus_checked = 1;
14857: }
14858: }
14859: }
14860: }
14861: unless ($inststatus_checked) {
14862: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14863: my %srch = (srchby => 'email',
14864: srchdomain => $defdom,
14865: srchterm => $reqemail,
14866: srchtype => 'exact');
14867: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14868: foreach my $uname (keys(%srch_results)) {
14869: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14870: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14871: $inststatus_checked = 1;
14872: last;
14873: }
14874: }
14875: unless ($inststatus_checked) {
14876: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14877: if ($dirsrchres eq 'ok') {
14878: foreach my $uname (keys(%srch_results)) {
14879: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14880: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14881: $inststatus_checked = 1;
14882: last;
14883: }
14884: }
14885: }
14886: }
14887: }
14888: }
14889: if ($inststatus ne '') {
14890: foreach my $status (split(/\:/,$inststatus)) {
14891: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14892: my @contacts = ('adminemail','supportemail');
14893: foreach my $item (@contacts) {
14894: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14895: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14896: if (!grep(/^\Q$addr\E$/,@recipients)) {
14897: push(@recipients,$addr);
14898: }
14899: }
14900: }
14901: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14902: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14903: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14904: my @ok_bccs;
14905: foreach my $bcc (@bccs) {
14906: $bcc =~ s/^\s+//g;
14907: $bcc =~ s/\s+$//g;
14908: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14909: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14910: push(@ok_bccs,$bcc);
14911: }
14912: }
14913: }
14914: if (@ok_bccs > 0) {
14915: $allbcc = join(', ',@ok_bccs);
14916: }
14917: }
14918: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14919: last;
14920: }
14921: }
14922: }
14923: }
14924: }
1.619 raeburn 14925: } elsif ($origmail ne '') {
1.1270 raeburn 14926: $lastresort = $origmail;
14927: }
1.1297 raeburn 14928: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 14929: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14930: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14931: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14932: my %what = (
14933: perlvar => 1,
14934: );
14935: my $primary = &Apache::lonnet::domain($defdom,'primary');
14936: if ($primary) {
14937: my $gotaddr;
14938: my ($result,$returnhash) =
14939: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14940: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14941: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14942: $lastresort = $returnhash->{'lonSupportEMail'};
14943: $gotaddr = 1;
14944: }
14945: }
14946: unless ($gotaddr) {
14947: my $uintdom = &Apache::lonnet::internet_dom($primary);
14948: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14949: unless ($uintdom eq $intdom) {
14950: my %domconfig =
14951: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14952: if (ref($domconfig{'contacts'}) eq 'HASH') {
14953: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14954: my @contacts = ('adminemail','supportemail');
14955: foreach my $item (@contacts) {
14956: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14957: my $addr = $domconfig{'contacts'}{$item};
14958: if (!grep(/^\Q$addr\E$/,@recipients)) {
14959: push(@recipients,$addr);
14960: }
14961: }
14962: }
14963: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14964: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14965: }
14966: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14967: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14968: my @ok_bccs;
14969: foreach my $bcc (@bccs) {
14970: $bcc =~ s/^\s+//g;
14971: $bcc =~ s/\s+$//g;
14972: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14973: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14974: push(@ok_bccs,$bcc);
14975: }
14976: }
14977: }
14978: if (@ok_bccs > 0) {
14979: $allbcc = join(', ',@ok_bccs);
14980: }
14981: }
14982: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14983: }
14984: }
14985: }
14986: }
14987: }
14988: }
1.618 raeburn 14989: }
1.688 raeburn 14990: if (defined($defmail)) {
14991: if ($defmail ne '') {
14992: push(@recipients,$defmail);
14993: }
1.618 raeburn 14994: }
14995: if ($otheremails) {
1.619 raeburn 14996: my @others;
14997: if ($otheremails =~ /,/) {
14998: @others = split(/,/,$otheremails);
1.618 raeburn 14999: } else {
1.619 raeburn 15000: push(@others,$otheremails);
15001: }
15002: foreach my $addr (@others) {
15003: if (!grep(/^\Q$addr\E$/,@recipients)) {
15004: push(@recipients,$addr);
15005: }
1.618 raeburn 15006: }
15007: }
1.1298 raeburn 15008: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15009: if ((!@recipients) && ($lastresort ne '')) {
15010: push(@recipients,$lastresort);
15011: }
15012: } elsif ($lastresort ne '') {
15013: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15014: push(@recipients,$lastresort);
15015: }
15016: }
1.1271 raeburn 15017: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15018: if (wantarray) {
15019: return ($recipientlist,$allbcc,$addtext);
15020: } else {
15021: return $recipientlist;
15022: }
1.618 raeburn 15023: }
15024:
1.127 matthew 15025: ############################################################
15026: ############################################################
1.154 albertel 15027:
1.655 raeburn 15028: =pod
15029:
1.1224 musolffc 15030: =over 4
15031:
1.1223 musolffc 15032: =item * &mime_email()
15033:
15034: Sends an email with a possible attachment
15035:
15036: Inputs:
15037:
15038: =over 4
15039:
15040: from - Sender's email address
15041:
15042: to - Email address of recipient
15043:
15044: subject - Subject of email
15045:
15046: body - Body of email
15047:
15048: cc_string - Carbon copy email address
15049:
15050: bcc - Blind carbon copy email address
15051:
15052: type - File type of attachment
15053:
15054: attachment_path - Path of file to be attached
15055:
15056: file_name - Name of file to be attached
15057:
15058: attachment_text - The body of an attachment of type "TEXT"
15059:
15060: =back
15061:
15062: =back
15063:
15064: =cut
15065:
15066: ############################################################
15067: ############################################################
15068:
15069: sub mime_email {
15070: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15071: $file_name, $attachment_text) = @_;
15072: my $msg = MIME::Lite->new(
15073: From => $from,
15074: To => $to,
15075: Subject => $subject,
15076: Type =>'TEXT',
15077: Data => $body,
15078: );
15079: if ($cc_string ne '') {
15080: $msg->add("Cc" => $cc_string);
15081: }
15082: if ($bcc ne '') {
15083: $msg->add("Bcc" => $bcc);
15084: }
15085: $msg->attr("content-type" => "text/plain");
15086: $msg->attr("content-type.charset" => "UTF-8");
15087: # Attach file if given
15088: if ($attachment_path) {
15089: unless ($file_name) {
15090: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15091: }
15092: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15093: $msg->attach(Type => $type,
15094: Path => $attachment_path,
15095: Filename => $file_name
15096: );
15097: # Otherwise attach text if given
15098: } elsif ($attachment_text) {
15099: $msg->attach(Type => 'TEXT',
15100: Data => $attachment_text);
15101: }
15102: # Send it
15103: $msg->send('sendmail');
15104: }
15105:
15106: ############################################################
15107: ############################################################
15108:
15109: =pod
15110:
1.655 raeburn 15111: =head1 Course Catalog Routines
15112:
15113: =over 4
15114:
15115: =item * &gather_categories()
15116:
15117: Converts category definitions - keys of categories hash stored in
15118: coursecategories in configuration.db on the primary library server in a
15119: domain - to an array. Also generates javascript and idx hash used to
15120: generate Domain Coordinator interface for editing Course Categories.
15121:
15122: Inputs:
1.663 raeburn 15123:
1.655 raeburn 15124: categories (reference to hash of category definitions).
1.663 raeburn 15125:
1.655 raeburn 15126: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15127: categories and subcategories).
1.663 raeburn 15128:
1.655 raeburn 15129: idx (reference to hash of counters used in Domain Coordinator interface for
15130: editing Course Categories).
1.663 raeburn 15131:
1.655 raeburn 15132: jsarray (reference to array of categories used to create Javascript arrays for
15133: Domain Coordinator interface for editing Course Categories).
15134:
15135: Returns: nothing
15136:
15137: Side effects: populates cats, idx and jsarray.
15138:
15139: =cut
15140:
15141: sub gather_categories {
15142: my ($categories,$cats,$idx,$jsarray) = @_;
15143: my %counters;
15144: my $num = 0;
15145: foreach my $item (keys(%{$categories})) {
15146: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15147: if ($container eq '' && $depth == 0) {
15148: $cats->[$depth][$categories->{$item}] = $cat;
15149: } else {
15150: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15151: }
15152: my ($escitem,$tail) = split(/:/,$item,2);
15153: if ($counters{$tail} eq '') {
15154: $counters{$tail} = $num;
15155: $num ++;
15156: }
15157: if (ref($idx) eq 'HASH') {
15158: $idx->{$item} = $counters{$tail};
15159: }
15160: if (ref($jsarray) eq 'ARRAY') {
15161: push(@{$jsarray->[$counters{$tail}]},$item);
15162: }
15163: }
15164: return;
15165: }
15166:
15167: =pod
15168:
15169: =item * &extract_categories()
15170:
15171: Used to generate breadcrumb trails for course categories.
15172:
15173: Inputs:
1.663 raeburn 15174:
1.655 raeburn 15175: categories (reference to hash of category definitions).
1.663 raeburn 15176:
1.655 raeburn 15177: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15178: categories and subcategories).
1.663 raeburn 15179:
1.655 raeburn 15180: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15181:
1.655 raeburn 15182: allitems (reference to hash - key is category key
15183: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15184:
1.655 raeburn 15185: idx (reference to hash of counters used in Domain Coordinator interface for
15186: editing Course Categories).
1.663 raeburn 15187:
1.655 raeburn 15188: jsarray (reference to array of categories used to create Javascript arrays for
15189: Domain Coordinator interface for editing Course Categories).
15190:
1.665 raeburn 15191: subcats (reference to hash of arrays containing all subcategories within each
15192: category, -recursive)
15193:
1.655 raeburn 15194: Returns: nothing
15195:
15196: Side effects: populates trails and allitems hash references.
15197:
15198: =cut
15199:
15200: sub extract_categories {
1.665 raeburn 15201: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 15202: if (ref($categories) eq 'HASH') {
15203: &gather_categories($categories,$cats,$idx,$jsarray);
15204: if (ref($cats->[0]) eq 'ARRAY') {
15205: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15206: my $name = $cats->[0][$i];
15207: my $item = &escape($name).'::0';
15208: my $trailstr;
15209: if ($name eq 'instcode') {
15210: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15211: } elsif ($name eq 'communities') {
15212: $trailstr = &mt('Communities');
1.1239 raeburn 15213: } elsif ($name eq 'placement') {
15214: $trailstr = &mt('Placement Tests');
1.655 raeburn 15215: } else {
15216: $trailstr = $name;
15217: }
15218: if ($allitems->{$item} eq '') {
15219: push(@{$trails},$trailstr);
15220: $allitems->{$item} = scalar(@{$trails})-1;
15221: }
15222: my @parents = ($name);
15223: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15224: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15225: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15226: if (ref($subcats) eq 'HASH') {
15227: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15228: }
15229: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
15230: }
15231: } else {
15232: if (ref($subcats) eq 'HASH') {
15233: $subcats->{$item} = [];
1.655 raeburn 15234: }
15235: }
15236: }
15237: }
15238: }
15239: return;
15240: }
15241:
15242: =pod
15243:
1.1162 raeburn 15244: =item * &recurse_categories()
1.655 raeburn 15245:
15246: Recursively used to generate breadcrumb trails for course categories.
15247:
15248: Inputs:
1.663 raeburn 15249:
1.655 raeburn 15250: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15251: categories and subcategories).
1.663 raeburn 15252:
1.655 raeburn 15253: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15254:
15255: category (current course category, for which breadcrumb trail is being generated).
15256:
15257: trails (reference to array of breadcrumb trails for each category).
15258:
1.655 raeburn 15259: allitems (reference to hash - key is category key
15260: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15261:
1.655 raeburn 15262: parents (array containing containers directories for current category,
15263: back to top level).
15264:
15265: Returns: nothing
15266:
15267: Side effects: populates trails and allitems hash references
15268:
15269: =cut
15270:
15271: sub recurse_categories {
1.665 raeburn 15272: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 15273: my $shallower = $depth - 1;
15274: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15275: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15276: my $name = $cats->[$depth]{$category}[$k];
15277: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
15278: my $trailstr = join(' -> ',(@{$parents},$category));
15279: if ($allitems->{$item} eq '') {
15280: push(@{$trails},$trailstr);
15281: $allitems->{$item} = scalar(@{$trails})-1;
15282: }
15283: my $deeper = $depth+1;
15284: push(@{$parents},$category);
1.665 raeburn 15285: if (ref($subcats) eq 'HASH') {
15286: my $subcat = &escape($name).':'.$category.':'.$depth;
15287: for (my $j=@{$parents}; $j>=0; $j--) {
15288: my $higher;
15289: if ($j > 0) {
15290: $higher = &escape($parents->[$j]).':'.
15291: &escape($parents->[$j-1]).':'.$j;
15292: } else {
15293: $higher = &escape($parents->[$j]).'::'.$j;
15294: }
15295: push(@{$subcats->{$higher}},$subcat);
15296: }
15297: }
15298: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
15299: $subcats);
1.655 raeburn 15300: pop(@{$parents});
15301: }
15302: } else {
15303: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
15304: my $trailstr = join(' -> ',(@{$parents},$category));
15305: if ($allitems->{$item} eq '') {
15306: push(@{$trails},$trailstr);
15307: $allitems->{$item} = scalar(@{$trails})-1;
15308: }
15309: }
15310: return;
15311: }
15312:
1.663 raeburn 15313: =pod
15314:
1.1162 raeburn 15315: =item * &assign_categories_table()
1.663 raeburn 15316:
15317: Create a datatable for display of hierarchical categories in a domain,
15318: with checkboxes to allow a course to be categorized.
15319:
15320: Inputs:
15321:
15322: cathash - reference to hash of categories defined for the domain (from
15323: configuration.db)
15324:
15325: currcat - scalar with an & separated list of categories assigned to a course.
15326:
1.919 raeburn 15327: type - scalar contains course type (Course or Community).
15328:
1.1260 raeburn 15329: disabled - scalar (optional) contains disabled="disabled" if input elements are
15330: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15331:
1.663 raeburn 15332: Returns: $output (markup to be displayed)
15333:
15334: =cut
15335:
15336: sub assign_categories_table {
1.1259 raeburn 15337: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15338: my $output;
15339: if (ref($cathash) eq 'HASH') {
15340: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
15341: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15342: $maxdepth = scalar(@cats);
15343: if (@cats > 0) {
15344: my $itemcount = 0;
15345: if (ref($cats[0]) eq 'ARRAY') {
15346: my @currcategories;
15347: if ($currcat ne '') {
15348: @currcategories = split('&',$currcat);
15349: }
1.919 raeburn 15350: my $table;
1.663 raeburn 15351: for (my $i=0; $i<@{$cats[0]}; $i++) {
15352: my $parent = $cats[0][$i];
1.919 raeburn 15353: next if ($parent eq 'instcode');
15354: if ($type eq 'Community') {
15355: next unless ($parent eq 'communities');
1.1239 raeburn 15356: } elsif ($type eq 'Placement') {
15357: next unless ($parent eq 'placement');
1.919 raeburn 15358: } else {
1.1239 raeburn 15359: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15360: }
1.663 raeburn 15361: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15362: my $item = &escape($parent).'::0';
15363: my $checked = '';
15364: if (@currcategories > 0) {
15365: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15366: $checked = ' checked="checked"';
1.663 raeburn 15367: }
15368: }
1.919 raeburn 15369: my $parent_title = $parent;
15370: if ($parent eq 'communities') {
15371: $parent_title = &mt('Communities');
1.1239 raeburn 15372: } elsif ($parent eq 'placement') {
15373: $parent_title = &mt('Placement Tests');
1.919 raeburn 15374: }
15375: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15376: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15377: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15378: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15379: my $depth = 1;
15380: push(@path,$parent);
1.1259 raeburn 15381: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15382: pop(@path);
1.919 raeburn 15383: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15384: $itemcount ++;
15385: }
1.919 raeburn 15386: if ($itemcount) {
15387: $output = &Apache::loncommon::start_data_table().
15388: $table.
15389: &Apache::loncommon::end_data_table();
15390: }
1.663 raeburn 15391: }
15392: }
15393: }
15394: return $output;
15395: }
15396:
15397: =pod
15398:
1.1162 raeburn 15399: =item * &assign_category_rows()
1.663 raeburn 15400:
15401: Create a datatable row for display of nested categories in a domain,
15402: with checkboxes to allow a course to be categorized,called recursively.
15403:
15404: Inputs:
15405:
15406: itemcount - track row number for alternating colors
15407:
15408: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15409: categories and subcategories.
15410:
15411: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15412:
15413: parent - parent of current category item
15414:
15415: path - Array containing all categories back up through the hierarchy from the
15416: current category to the top level.
15417:
15418: currcategories - reference to array of current categories assigned to the course
15419:
1.1260 raeburn 15420: disabled - scalar (optional) contains disabled="disabled" if input elements are
15421: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15422:
1.663 raeburn 15423: Returns: $output (markup to be displayed).
15424:
15425: =cut
15426:
15427: sub assign_category_rows {
1.1259 raeburn 15428: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15429: my ($text,$name,$item,$chgstr);
15430: if (ref($cats) eq 'ARRAY') {
15431: my $maxdepth = scalar(@{$cats});
15432: if (ref($cats->[$depth]) eq 'HASH') {
15433: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15434: my $numchildren = @{$cats->[$depth]{$parent}};
15435: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15436: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15437: for (my $j=0; $j<$numchildren; $j++) {
15438: $name = $cats->[$depth]{$parent}[$j];
15439: $item = &escape($name).':'.&escape($parent).':'.$depth;
15440: my $deeper = $depth+1;
15441: my $checked = '';
15442: if (ref($currcategories) eq 'ARRAY') {
15443: if (@{$currcategories} > 0) {
15444: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15445: $checked = ' checked="checked"';
1.663 raeburn 15446: }
15447: }
15448: }
1.664 raeburn 15449: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15450: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15451: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15452: '<input type="hidden" name="catname" value="'.$name.'" />'.
15453: '</td><td>';
1.663 raeburn 15454: if (ref($path) eq 'ARRAY') {
15455: push(@{$path},$name);
1.1259 raeburn 15456: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15457: pop(@{$path});
15458: }
15459: $text .= '</td></tr>';
15460: }
15461: $text .= '</table></td>';
15462: }
15463: }
15464: }
15465: return $text;
15466: }
15467:
1.1181 raeburn 15468: =pod
15469:
15470: =back
15471:
15472: =cut
15473:
1.655 raeburn 15474: ############################################################
15475: ############################################################
15476:
15477:
1.443 albertel 15478: sub commit_customrole {
1.664 raeburn 15479: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15480: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15481: ($start?', '.&mt('starting').' '.localtime($start):'').
15482: ($end?', ending '.localtime($end):'').': <b>'.
15483: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15484: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15485: '</b><br />';
15486: return $output;
15487: }
15488:
15489: sub commit_standardrole {
1.1116 raeburn 15490: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15491: my ($output,$logmsg,$linefeed);
15492: if ($context eq 'auto') {
15493: $linefeed = "\n";
15494: } else {
15495: $linefeed = "<br />\n";
15496: }
1.443 albertel 15497: if ($three eq 'st') {
1.541 raeburn 15498: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15499: $one,$two,$sec,$context,$credits);
1.541 raeburn 15500: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15501: ($result eq 'unknown_course') || ($result eq 'refused')) {
15502: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15503: } else {
1.541 raeburn 15504: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15505: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15506: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15507: if ($context eq 'auto') {
15508: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15509: } else {
15510: $output .= '<b>'.$result.'</b>'.$linefeed.
15511: &mt('Add to classlist').': <b>ok</b>';
15512: }
15513: $output .= $linefeed;
1.443 albertel 15514: }
15515: } else {
15516: $output = &mt('Assigning').' '.$three.' in '.$url.
15517: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15518: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15519: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15520: if ($context eq 'auto') {
15521: $output .= $result.$linefeed;
15522: } else {
15523: $output .= '<b>'.$result.'</b>'.$linefeed;
15524: }
1.443 albertel 15525: }
15526: return $output;
15527: }
15528:
15529: sub commit_studentrole {
1.1116 raeburn 15530: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15531: $credits) = @_;
1.626 raeburn 15532: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15533: if ($context eq 'auto') {
15534: $linefeed = "\n";
15535: } else {
15536: $linefeed = '<br />'."\n";
15537: }
1.443 albertel 15538: if (defined($one) && defined($two)) {
15539: my $cid=$one.'_'.$two;
15540: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15541: my $secchange = 0;
15542: my $expire_role_result;
15543: my $modify_section_result;
1.628 raeburn 15544: if ($oldsec ne '-1') {
15545: if ($oldsec ne $sec) {
1.443 albertel 15546: $secchange = 1;
1.628 raeburn 15547: my $now = time;
1.443 albertel 15548: my $uurl='/'.$cid;
15549: $uurl=~s/\_/\//g;
15550: if ($oldsec) {
15551: $uurl.='/'.$oldsec;
15552: }
1.626 raeburn 15553: $oldsecurl = $uurl;
1.628 raeburn 15554: $expire_role_result =
1.652 raeburn 15555: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15556: if ($env{'request.course.sec'} ne '') {
15557: if ($expire_role_result eq 'refused') {
15558: my @roles = ('st');
15559: my @statuses = ('previous');
15560: my @roledoms = ($one);
15561: my $withsec = 1;
15562: my %roleshash =
15563: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15564: \@statuses,\@roles,\@roledoms,$withsec);
15565: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15566: my ($oldstart,$oldend) =
15567: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15568: if ($oldend > 0 && $oldend <= $now) {
15569: $expire_role_result = 'ok';
15570: }
15571: }
15572: }
15573: }
1.443 albertel 15574: $result = $expire_role_result;
15575: }
15576: }
15577: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15578: $modify_section_result =
15579: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15580: undef,undef,undef,$sec,
15581: $end,$start,'','',$cid,
15582: '',$context,$credits);
1.443 albertel 15583: if ($modify_section_result =~ /^ok/) {
15584: if ($secchange == 1) {
1.628 raeburn 15585: if ($sec eq '') {
15586: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15587: } else {
15588: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15589: }
1.443 albertel 15590: } elsif ($oldsec eq '-1') {
1.628 raeburn 15591: if ($sec eq '') {
15592: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15593: } else {
15594: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15595: }
1.443 albertel 15596: } else {
1.628 raeburn 15597: if ($sec eq '') {
15598: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15599: } else {
15600: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15601: }
1.443 albertel 15602: }
15603: } else {
1.1115 raeburn 15604: if ($secchange) {
1.628 raeburn 15605: $$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;
15606: } else {
15607: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15608: }
1.443 albertel 15609: }
15610: $result = $modify_section_result;
15611: } elsif ($secchange == 1) {
1.628 raeburn 15612: if ($oldsec eq '') {
1.1103 raeburn 15613: $$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 15614: } else {
15615: $$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;
15616: }
1.626 raeburn 15617: if ($expire_role_result eq 'refused') {
15618: my $newsecurl = '/'.$cid;
15619: $newsecurl =~ s/\_/\//g;
15620: if ($sec ne '') {
15621: $newsecurl.='/'.$sec;
15622: }
15623: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15624: if ($sec eq '') {
15625: $$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;
15626: } else {
15627: $$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;
15628: }
15629: }
15630: }
1.443 albertel 15631: }
15632: } else {
1.626 raeburn 15633: $$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 15634: $result = "error: incomplete course id\n";
15635: }
15636: return $result;
15637: }
15638:
1.1108 raeburn 15639: sub show_role_extent {
15640: my ($scope,$context,$role) = @_;
15641: $scope =~ s{^/}{};
15642: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15643: push(@courseroles,'co');
15644: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15645: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15646: $scope =~ s{/}{_};
15647: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15648: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15649: my ($audom,$auname) = split(/\//,$scope);
15650: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15651: &Apache::loncommon::plainname($auname,$audom).'</span>');
15652: } else {
15653: $scope =~ s{/$}{};
15654: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15655: &Apache::lonnet::domain($scope,'description').'</span>');
15656: }
15657: }
15658:
1.443 albertel 15659: ############################################################
15660: ############################################################
15661:
1.566 albertel 15662: sub check_clone {
1.578 raeburn 15663: my ($args,$linefeed) = @_;
1.566 albertel 15664: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15665: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15666: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15667: my $clonemsg;
15668: my $can_clone = 0;
1.944 raeburn 15669: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15670: if ($lctype ne 'community') {
15671: $lctype = 'course';
15672: }
1.566 albertel 15673: if ($clonehome eq 'no_host') {
1.944 raeburn 15674: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15675: $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'});
15676: } else {
15677: $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'});
15678: }
1.566 albertel 15679: } else {
15680: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15681: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15682: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15683: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
1.908 raeburn 15684: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15685: }
15686: }
1.1262 raeburn 15687: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15688: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15689: $can_clone = 1;
15690: } else {
1.1221 raeburn 15691: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15692: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15693: if ($clonehash{'cloners'} eq '') {
15694: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15695: if ($domdefs{'canclone'}) {
15696: unless ($domdefs{'canclone'} eq 'none') {
15697: if ($domdefs{'canclone'} eq 'domain') {
15698: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15699: $can_clone = 1;
15700: }
15701: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15702: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15703: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15704: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15705: $can_clone = 1;
15706: }
15707: }
15708: }
15709: }
1.578 raeburn 15710: } else {
1.1221 raeburn 15711: my @cloners = split(/,/,$clonehash{'cloners'});
15712: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15713: $can_clone = 1;
1.1221 raeburn 15714: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15715: $can_clone = 1;
1.1225 raeburn 15716: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15717: $can_clone = 1;
1.1221 raeburn 15718: }
15719: unless ($can_clone) {
1.1225 raeburn 15720: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15721: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15722: my (%gotdomdefaults,%gotcodedefaults);
15723: foreach my $cloner (@cloners) {
15724: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15725: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15726: my (%codedefaults,@code_order);
15727: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15728: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15729: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15730: }
15731: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15732: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15733: }
15734: } else {
15735: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15736: \%codedefaults,
15737: \@code_order);
15738: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15739: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15740: }
15741: if (@code_order > 0) {
15742: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15743: $cloner,$clonehash{'internal.coursecode'},
15744: $args->{'crscode'})) {
15745: $can_clone = 1;
15746: last;
15747: }
15748: }
15749: }
15750: }
15751: }
1.1225 raeburn 15752: }
15753: }
15754: unless ($can_clone) {
15755: my $ccrole = 'cc';
15756: if ($args->{'crstype'} eq 'Community') {
15757: $ccrole = 'co';
15758: }
15759: my %roleshash =
15760: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15761: $args->{'ccdomain'},
15762: 'userroles',['active'],[$ccrole],
15763: [$args->{'clonedomain'}]);
15764: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15765: $can_clone = 1;
15766: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15767: $args->{'ccuname'},$args->{'ccdomain'})) {
15768: $can_clone = 1;
1.1221 raeburn 15769: }
15770: }
15771: unless ($can_clone) {
15772: if ($args->{'crstype'} eq 'Community') {
15773: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.942 raeburn 15774: } else {
1.1221 raeburn 15775: $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'});
15776: }
1.566 albertel 15777: }
1.578 raeburn 15778: }
1.566 albertel 15779: }
15780: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15781: }
15782:
1.444 albertel 15783: sub construct_course {
1.1262 raeburn 15784: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15785: $cnum,$category,$coderef) = @_;
1.444 albertel 15786: my $outcome;
1.541 raeburn 15787: my $linefeed = '<br />'."\n";
15788: if ($context eq 'auto') {
15789: $linefeed = "\n";
15790: }
1.566 albertel 15791:
15792: #
15793: # Are we cloning?
15794: #
15795: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15796: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15797: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15798: if ($context ne 'auto') {
1.578 raeburn 15799: if ($clonemsg ne '') {
15800: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15801: }
1.566 albertel 15802: }
15803: $outcome .= $clonemsg.$linefeed;
15804:
15805: if (!$can_clone) {
15806: return (0,$outcome);
15807: }
15808: }
15809:
1.444 albertel 15810: #
15811: # Open course
15812: #
1.1239 raeburn 15813: my $showncrstype;
15814: if ($args->{'crstype'} eq 'Placement') {
15815: $showncrstype = 'placement test';
15816: } else {
15817: $showncrstype = lc($args->{'crstype'});
15818: }
1.444 albertel 15819: my %cenv=();
15820: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15821: $args->{'cdescr'},
15822: $args->{'curl'},
15823: $args->{'course_home'},
15824: $args->{'nonstandard'},
15825: $args->{'crscode'},
15826: $args->{'ccuname'}.':'.
15827: $args->{'ccdomain'},
1.882 raeburn 15828: $args->{'crstype'},
1.885 raeburn 15829: $cnum,$context,$category);
1.444 albertel 15830:
15831: # Note: The testing routines depend on this being output; see
15832: # Utils::Course. This needs to at least be output as a comment
15833: # if anyone ever decides to not show this, and Utils::Course::new
15834: # will need to be suitably modified.
1.1239 raeburn 15835: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15836: if ($$courseid =~ /^error:/) {
15837: return (0,$outcome);
15838: }
15839:
1.444 albertel 15840: #
15841: # Check if created correctly
15842: #
1.479 albertel 15843: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15844: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15845: if ($crsuhome eq 'no_host') {
15846: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15847: return (0,$outcome);
15848: }
1.541 raeburn 15849: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15850:
1.444 albertel 15851: #
1.566 albertel 15852: # Do the cloning
15853: #
15854: if ($can_clone && $cloneid) {
1.1239 raeburn 15855: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15856: if ($context ne 'auto') {
15857: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15858: }
15859: $outcome .= $clonemsg.$linefeed;
15860: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15861: # Copy all files
1.637 www 15862: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15863: # Restore URL
1.566 albertel 15864: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15865: # Restore title
1.566 albertel 15866: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15867: # Restore creation date, creator and creation context.
15868: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15869: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15870: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15871: # Mark as cloned
1.566 albertel 15872: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15873: # Need to clone grading mode
15874: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15875: $cenv{'grading'}=$newenv{'grading'};
15876: # Do not clone these environment entries
15877: &Apache::lonnet::del('environment',
15878: ['default_enrollment_start_date',
15879: 'default_enrollment_end_date',
15880: 'question.email',
15881: 'policy.email',
15882: 'comment.email',
15883: 'pch.users.denied',
1.725 raeburn 15884: 'plc.users.denied',
15885: 'hidefromcat',
1.1121 raeburn 15886: 'checkforpriv',
1.1166 raeburn 15887: 'categories',
15888: 'internal.uniquecode'],
1.638 www 15889: $$crsudom,$$crsunum);
1.1170 raeburn 15890: if ($args->{'textbook'}) {
15891: $cenv{'internal.textbook'} = $args->{'textbook'};
15892: }
1.444 albertel 15893: }
1.566 albertel 15894:
1.444 albertel 15895: #
15896: # Set environment (will override cloned, if existing)
15897: #
15898: my @sections = ();
15899: my @xlists = ();
15900: if ($args->{'crstype'}) {
15901: $cenv{'type'}=$args->{'crstype'};
15902: }
15903: if ($args->{'crsid'}) {
15904: $cenv{'courseid'}=$args->{'crsid'};
15905: }
15906: if ($args->{'crscode'}) {
15907: $cenv{'internal.coursecode'}=$args->{'crscode'};
15908: }
15909: if ($args->{'crsquota'} ne '') {
15910: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15911: } else {
15912: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15913: }
15914: if ($args->{'ccuname'}) {
15915: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15916: ':'.$args->{'ccdomain'};
15917: } else {
15918: $cenv{'internal.courseowner'} = $args->{'curruser'};
15919: }
1.1116 raeburn 15920: if ($args->{'defaultcredits'}) {
15921: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15922: }
1.444 albertel 15923: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15924: if ($args->{'crssections'}) {
15925: $cenv{'internal.sectionnums'} = '';
15926: if ($args->{'crssections'} =~ m/,/) {
15927: @sections = split/,/,$args->{'crssections'};
15928: } else {
15929: $sections[0] = $args->{'crssections'};
15930: }
15931: if (@sections > 0) {
15932: foreach my $item (@sections) {
15933: my ($sec,$gp) = split/:/,$item;
15934: my $class = $args->{'crscode'}.$sec;
15935: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15936: $cenv{'internal.sectionnums'} .= $item.',';
15937: unless ($addcheck eq 'ok') {
1.1263 raeburn 15938: push(@badclasses,$class);
1.444 albertel 15939: }
15940: }
15941: $cenv{'internal.sectionnums'} =~ s/,$//;
15942: }
15943: }
15944: # do not hide course coordinator from staff listing,
15945: # even if privileged
15946: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15947: # add course coordinator's domain to domains to check for privileged users
15948: # if different to course domain
15949: if ($$crsudom ne $args->{'ccdomain'}) {
15950: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15951: }
1.444 albertel 15952: # add crosslistings
15953: if ($args->{'crsxlist'}) {
15954: $cenv{'internal.crosslistings'}='';
15955: if ($args->{'crsxlist'} =~ m/,/) {
15956: @xlists = split/,/,$args->{'crsxlist'};
15957: } else {
15958: $xlists[0] = $args->{'crsxlist'};
15959: }
15960: if (@xlists > 0) {
15961: foreach my $item (@xlists) {
15962: my ($xl,$gp) = split/:/,$item;
15963: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15964: $cenv{'internal.crosslistings'} .= $item.',';
15965: unless ($addcheck eq 'ok') {
1.1263 raeburn 15966: push(@badclasses,$xl);
1.444 albertel 15967: }
15968: }
15969: $cenv{'internal.crosslistings'} =~ s/,$//;
15970: }
15971: }
15972: if ($args->{'autoadds'}) {
15973: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15974: }
15975: if ($args->{'autodrops'}) {
15976: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15977: }
15978: # check for notification of enrollment changes
15979: my @notified = ();
15980: if ($args->{'notify_owner'}) {
15981: if ($args->{'ccuname'} ne '') {
15982: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15983: }
15984: }
15985: if ($args->{'notify_dc'}) {
15986: if ($uname ne '') {
1.630 raeburn 15987: push(@notified,$uname.':'.$udom);
1.444 albertel 15988: }
15989: }
15990: if (@notified > 0) {
15991: my $notifylist;
15992: if (@notified > 1) {
15993: $notifylist = join(',',@notified);
15994: } else {
15995: $notifylist = $notified[0];
15996: }
15997: $cenv{'internal.notifylist'} = $notifylist;
15998: }
15999: if (@badclasses > 0) {
16000: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16001: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16002: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16003: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16004: );
1.1264 raeburn 16005: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16006: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 16007: if ($context eq 'auto') {
16008: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16009: } else {
1.566 albertel 16010: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16011: }
16012: foreach my $item (@badclasses) {
1.541 raeburn 16013: if ($context eq 'auto') {
1.1261 raeburn 16014: $outcome .= " - $item\n";
1.541 raeburn 16015: } else {
1.1261 raeburn 16016: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16017: }
1.1261 raeburn 16018: }
16019: if ($context eq 'auto') {
16020: $outcome .= $linefeed;
16021: } else {
16022: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16023: }
1.444 albertel 16024: }
16025: if ($args->{'no_end_date'}) {
16026: $args->{'endaccess'} = 0;
16027: }
16028: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16029: $cenv{'internal.autoend'}=$args->{'enrollend'};
16030: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16031: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16032: if ($args->{'showphotos'}) {
16033: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16034: }
16035: $cenv{'internal.authtype'} = $args->{'authtype'};
16036: $cenv{'internal.autharg'} = $args->{'autharg'};
16037: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16038: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16039: 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');
16040: if ($context eq 'auto') {
16041: $outcome .= $krb_msg;
16042: } else {
1.566 albertel 16043: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16044: }
16045: $outcome .= $linefeed;
1.444 albertel 16046: }
16047: }
16048: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16049: if ($args->{'setpolicy'}) {
16050: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16051: }
16052: if ($args->{'setcontent'}) {
16053: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16054: }
1.1251 raeburn 16055: if ($args->{'setcomment'}) {
16056: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16057: }
1.444 albertel 16058: }
16059: if ($args->{'reshome'}) {
16060: $cenv{'reshome'}=$args->{'reshome'}.'/';
16061: $cenv{'reshome'}=~s/\/+$/\//;
16062: }
16063: #
16064: # course has keyed access
16065: #
16066: if ($args->{'setkeys'}) {
16067: $cenv{'keyaccess'}='yes';
16068: }
16069: # if specified, key authority is not course, but user
16070: # only active if keyaccess is yes
16071: if ($args->{'keyauth'}) {
1.487 albertel 16072: my ($user,$domain) = split(':',$args->{'keyauth'});
16073: $user = &LONCAPA::clean_username($user);
16074: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16075: if ($user ne '' && $domain ne '') {
1.487 albertel 16076: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16077: }
16078: }
16079:
1.1166 raeburn 16080: #
1.1167 raeburn 16081: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16082: #
16083: if ($args->{'uniquecode'}) {
16084: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16085: if ($code) {
16086: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16087: my %crsinfo =
16088: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16089: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16090: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16091: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16092: }
1.1166 raeburn 16093: if (ref($coderef)) {
16094: $$coderef = $code;
16095: }
16096: }
16097: }
16098:
1.444 albertel 16099: if ($args->{'disresdis'}) {
16100: $cenv{'pch.roles.denied'}='st';
16101: }
16102: if ($args->{'disablechat'}) {
16103: $cenv{'plc.roles.denied'}='st';
16104: }
16105:
16106: # Record we've not yet viewed the Course Initialization Helper for this
16107: # course
16108: $cenv{'course.helper.not.run'} = 1;
16109: #
16110: # Use new Randomseed
16111: #
16112: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16113: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16114: #
16115: # The encryption code and receipt prefix for this course
16116: #
16117: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16118: $cenv{'internal.encpref'}=100+int(9*rand(99));
16119: #
16120: # By default, use standard grading
16121: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16122:
1.541 raeburn 16123: $outcome .= $linefeed.&mt('Setting environment').': '.
16124: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16125: #
16126: # Open all assignments
16127: #
16128: if ($args->{'openall'}) {
16129: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16130: my %storecontent = ($storeunder => time,
16131: $storeunder.'.type' => 'date_start');
16132:
16133: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16134: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16135: }
16136: #
16137: # Set first page
16138: #
16139: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16140: || ($cloneid)) {
1.445 albertel 16141: use LONCAPA::map;
1.444 albertel 16142: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16143:
16144: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16145: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16146:
1.444 albertel 16147: $outcome .= ($fatal?$errtext:'read ok').' - ';
16148: my $title; my $url;
16149: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16150: $title=&mt('Syllabus');
1.444 albertel 16151: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16152: } else {
1.963 raeburn 16153: $title=&mt('Table of Contents');
1.444 albertel 16154: $url='/adm/navmaps';
16155: }
1.445 albertel 16156:
16157: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16158: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16159:
16160: if ($errtext) { $fatal=2; }
1.541 raeburn 16161: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16162: }
1.566 albertel 16163:
1.1237 raeburn 16164: #
16165: # Set params for Placement Tests
16166: #
1.1239 raeburn 16167: if ($args->{'crstype'} eq 'Placement') {
16168: my %storecontent;
16169: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16170: my %defaults = (
16171: buttonshide => { value => 'yes',
16172: type => 'string_yesno',},
16173: type => { value => 'randomizetry',
16174: type => 'string_questiontype',},
16175: maxtries => { value => 1,
16176: type => 'int_pos',},
16177: problemstatus => { value => 'no',
16178: type => 'string_problemstatus',},
16179: );
16180: foreach my $key (keys(%defaults)) {
16181: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16182: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16183: }
1.1237 raeburn 16184: &Apache::lonnet::cput
16185: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16186: }
16187:
1.566 albertel 16188: return (1,$outcome);
1.444 albertel 16189: }
16190:
1.1166 raeburn 16191: sub make_unique_code {
16192: my ($cdom,$cnum) = @_;
16193: # get lock on uniquecodes db
16194: my $lockhash = {
16195: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16196: ':'.$env{'user.domain'},
16197: };
16198: my $tries = 0;
16199: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16200: my ($code,$error);
16201:
16202: while (($gotlock ne 'ok') && ($tries<3)) {
16203: $tries ++;
16204: sleep 1;
16205: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16206: }
16207: if ($gotlock eq 'ok') {
16208: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16209: my $gotcode;
16210: my $attempts = 0;
16211: while ((!$gotcode) && ($attempts < 100)) {
16212: $code = &generate_code();
16213: if (!exists($currcodes{$code})) {
16214: $gotcode = 1;
16215: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16216: $error = 'nostore';
16217: }
16218: }
16219: $attempts ++;
16220: }
16221: my @del_lock = ($cnum."\0".'uniquecodes');
16222: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16223: } else {
16224: $error = 'nolock';
16225: }
16226: return ($code,$error);
16227: }
16228:
16229: sub generate_code {
16230: my $code;
16231: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16232: for (my $i=0; $i<6; $i++) {
16233: my $lettnum = int (rand 2);
16234: my $item = '';
16235: if ($lettnum) {
16236: $item = $letts[int( rand(18) )];
16237: } else {
16238: $item = 1+int( rand(8) );
16239: }
16240: $code .= $item;
16241: }
16242: return $code;
16243: }
16244:
1.444 albertel 16245: ############################################################
16246: ############################################################
16247:
1.1237 raeburn 16248: # Community, Course and Placement Test
1.378 raeburn 16249: sub course_type {
16250: my ($cid) = @_;
16251: if (!defined($cid)) {
16252: $cid = $env{'request.course.id'};
16253: }
1.404 albertel 16254: if (defined($env{'course.'.$cid.'.type'})) {
16255: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16256: } else {
16257: return 'Course';
1.377 raeburn 16258: }
16259: }
1.156 albertel 16260:
1.406 raeburn 16261: sub group_term {
16262: my $crstype = &course_type();
16263: my %names = (
16264: 'Course' => 'group',
1.865 raeburn 16265: 'Community' => 'group',
1.1237 raeburn 16266: 'Placement' => 'group',
1.406 raeburn 16267: );
16268: return $names{$crstype};
16269: }
16270:
1.902 raeburn 16271: sub course_types {
1.1310 raeburn 16272: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16273: my %typename = (
16274: official => 'Official course',
16275: unofficial => 'Unofficial course',
16276: community => 'Community',
1.1165 raeburn 16277: textbook => 'Textbook course',
1.1237 raeburn 16278: placement => 'Placement test',
1.1310 raeburn 16279: lti => 'LTI provider',
1.902 raeburn 16280: );
16281: return (\@types,\%typename);
16282: }
16283:
1.156 albertel 16284: sub icon {
16285: my ($file)=@_;
1.505 albertel 16286: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16287: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16288: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16289: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16290: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16291: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16292: $curfext.".gif") {
16293: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16294: $curfext.".gif";
16295: }
16296: }
1.249 albertel 16297: return &lonhttpdurl($iconname);
1.154 albertel 16298: }
1.84 albertel 16299:
1.575 albertel 16300: sub lonhttpdurl {
1.692 www 16301: #
16302: # Had been used for "small fry" static images on separate port 8080.
16303: # Modify here if lightweight http functionality desired again.
16304: # Currently eliminated due to increasing firewall issues.
16305: #
1.575 albertel 16306: my ($url)=@_;
1.692 www 16307: return $url;
1.215 albertel 16308: }
16309:
1.213 albertel 16310: sub connection_aborted {
16311: my ($r)=@_;
16312: $r->print(" ");$r->rflush();
16313: my $c = $r->connection;
16314: return $c->aborted();
16315: }
16316:
1.221 foxr 16317: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16318: # strings as 'strings'.
16319: sub escape_single {
1.221 foxr 16320: my ($input) = @_;
1.223 albertel 16321: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16322: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16323: return $input;
16324: }
1.223 albertel 16325:
1.222 foxr 16326: # Same as escape_single, but escape's "'s This
16327: # can be used for "strings"
16328: sub escape_double {
16329: my ($input) = @_;
16330: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16331: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16332: return $input;
16333: }
1.223 albertel 16334:
1.222 foxr 16335: # Escapes the last element of a full URL.
16336: sub escape_url {
16337: my ($url) = @_;
1.238 raeburn 16338: my @urlslices = split(/\//, $url,-1);
1.369 www 16339: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16340: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16341: }
1.462 albertel 16342:
1.820 raeburn 16343: sub compare_arrays {
16344: my ($arrayref1,$arrayref2) = @_;
16345: my (@difference,%count);
16346: @difference = ();
16347: %count = ();
16348: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16349: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16350: foreach my $element (keys(%count)) {
16351: if ($count{$element} == 1) {
16352: push(@difference,$element);
16353: }
16354: }
16355: }
16356: return @difference;
16357: }
16358:
1.817 bisitz 16359: # -------------------------------------------------------- Initialize user login
1.462 albertel 16360: sub init_user_environment {
1.463 albertel 16361: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16362: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16363:
16364: my $public=($username eq 'public' && $domain eq 'public');
16365:
1.1062 raeburn 16366: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16367: my $now=time;
16368:
16369: if ($public) {
16370: my $max_public=100;
16371: my $oldest;
16372: my $oldest_time=0;
16373: for(my $next=1;$next<=$max_public;$next++) {
16374: if (-e $lonids."/publicuser_$next.id") {
16375: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16376: if ($mtime<$oldest_time || !$oldest_time) {
16377: $oldest_time=$mtime;
16378: $oldest=$next;
16379: }
16380: } else {
16381: $cookie="publicuser_$next";
16382: last;
16383: }
16384: }
16385: if (!$cookie) { $cookie="publicuser_$oldest"; }
16386: } else {
1.1275 raeburn 16387: # See if old ID present, if so, remove if this isn't a robot,
16388: # killing any existing non-robot sessions
1.463 albertel 16389: if (!$args->{'robot'}) {
16390: opendir(DIR,$lonids);
16391: while ($filename=readdir(DIR)) {
16392: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1295 raeburn 16393: if ($ENV{'SERVER_PORT'} == 443) {
16394: my $linkedfile;
16395: if (tie(my %oldenv,'GDBM_File',"$lonids/$cookie.id",
16396: &GDBM_READER(),0640)) {
16397: if (exists($oldenv{'user.linkedenv'})) {
16398: $linkedfile = $oldenv{'user.linkedenv'};
16399: }
16400: untie(%oldenv);
16401: }
16402: if (unlink($lonids.'/'.$filename)) {
16403: if ($linkedfile =~ /^[a-f0-9]+_linked\.id$/) {
16404: unlink($lonids.'/'.$linkedfile);
16405: }
16406: }
16407: } else {
16408: unlink($lonids.'/'.$filename);
16409: }
1.463 albertel 16410: }
1.462 albertel 16411: }
1.463 albertel 16412: closedir(DIR);
1.1204 raeburn 16413: # If there is a undeleted lockfile for the user's paste buffer remove it.
16414: my $namespace = 'nohist_courseeditor';
16415: my $lockingkey = 'paste'."\0".'locked_num';
16416: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16417: $domain,$username);
16418: if (exists($lockhash{$lockingkey})) {
16419: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16420: unless ($delresult eq 'ok') {
16421: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16422: }
16423: }
1.462 albertel 16424: }
16425: # Give them a new cookie
1.463 albertel 16426: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16427: : $now.$$.int(rand(10000)));
1.463 albertel 16428: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16429:
16430: # Initialize roles
16431:
1.1062 raeburn 16432: ($userroles,$firstaccenv,$timerintenv) =
16433: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16434: }
16435: # ------------------------------------ Check browser type and MathML capability
16436:
1.1194 raeburn 16437: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16438: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16439:
16440: # ------------------------------------------------------------- Get environment
16441:
16442: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16443: my ($tmp) = keys(%userenv);
1.1275 raeburn 16444: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16445: undef(%userenv);
16446: }
16447: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16448: $form->{'interface'}=$userenv{'interface'};
16449: }
16450: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16451:
16452: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16453: foreach my $option ('interface','localpath','localres') {
16454: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16455: }
16456: # --------------------------------------------------------- Write first profile
16457:
16458: {
16459: my %initial_env =
16460: ("user.name" => $username,
16461: "user.domain" => $domain,
16462: "user.home" => $authhost,
16463: "browser.type" => $clientbrowser,
16464: "browser.version" => $clientversion,
16465: "browser.mathml" => $clientmathml,
16466: "browser.unicode" => $clientunicode,
16467: "browser.os" => $clientos,
1.1137 raeburn 16468: "browser.mobile" => $clientmobile,
1.1141 raeburn 16469: "browser.info" => $clientinfo,
1.1194 raeburn 16470: "browser.osversion" => $clientosversion,
1.462 albertel 16471: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16472: "request.course.fn" => '',
16473: "request.course.uri" => '',
16474: "request.course.sec" => '',
16475: "request.role" => 'cm',
16476: "request.role.adv" => $env{'user.adv'},
16477: "request.host" => $ENV{'REMOTE_ADDR'},);
16478:
16479: if ($form->{'localpath'}) {
16480: $initial_env{"browser.localpath"} = $form->{'localpath'};
16481: $initial_env{"browser.localres"} = $form->{'localres'};
16482: }
16483:
16484: if ($form->{'interface'}) {
16485: $form->{'interface'}=~s/\W//gs;
16486: $initial_env{"browser.interface"} = $form->{'interface'};
16487: $env{'browser.interface'}=$form->{'interface'};
16488: }
16489:
1.1157 raeburn 16490: if ($form->{'iptoken'}) {
16491: my $lonhost = $r->dir_config('lonHostID');
16492: $initial_env{"user.noloadbalance"} = $lonhost;
16493: $env{'user.noloadbalance'} = $lonhost;
16494: }
16495:
1.1268 raeburn 16496: if ($form->{'noloadbalance'}) {
16497: my @hosts = &Apache::lonnet::current_machine_ids();
16498: my $hosthere = $form->{'noloadbalance'};
16499: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16500: $initial_env{"user.noloadbalance"} = $hosthere;
16501: $env{'user.noloadbalance'} = $hosthere;
16502: }
16503: }
16504:
1.1016 raeburn 16505: unless ($domain eq 'public') {
1.1273 raeburn 16506: my %is_adv = ( is_adv => $env{'user.adv'} );
16507: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16508:
16509: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16510: $userenv{'availabletools.'.$tool} =
16511: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16512: undef,\%userenv,\%domdef,\%is_adv);
16513: }
1.980 raeburn 16514:
1.1311 raeburn 16515: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16516: $userenv{'canrequest.'.$crstype} =
16517: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16518: 'reload','requestcourses',
16519: \%userenv,\%domdef,\%is_adv);
16520: }
1.724 raeburn 16521:
1.1273 raeburn 16522: $userenv{'canrequest.author'} =
16523: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16524: 'reload','requestauthor',
1.980 raeburn 16525: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16526: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16527: $domain,$username);
16528: my $reqstatus = $reqauthor{'author_status'};
16529: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16530: if (ref($reqauthor{'author'}) eq 'HASH') {
16531: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16532: $reqauthor{'author'}{'timestamp'};
16533: }
1.1092 raeburn 16534: }
1.1287 raeburn 16535: my ($types,$typename) = &course_types();
16536: if (ref($types) eq 'ARRAY') {
16537: my @options = ('approval','validate','autolimit');
16538: my $optregex = join('|',@options);
16539: my (%willtrust,%trustchecked);
16540: foreach my $type (@{$types}) {
16541: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16542: if ($dom_str ne '') {
16543: my $updatedstr = '';
16544: my @possdomains = split(',',$dom_str);
16545: foreach my $entry (@possdomains) {
16546: my ($extdom,$extopt) = split(':',$entry);
16547: unless ($trustchecked{$extdom}) {
16548: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16549: $trustchecked{$extdom} = 1;
16550: }
16551: if ($willtrust{$extdom}) {
16552: $updatedstr .= $entry.',';
16553: }
16554: }
16555: $updatedstr =~ s/,$//;
16556: if ($updatedstr) {
16557: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16558: } else {
16559: delete($userenv{'reqcrsotherdom.'.$type});
16560: }
16561: }
16562: }
16563: }
1.1092 raeburn 16564: }
1.462 albertel 16565: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16566:
1.462 albertel 16567: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16568: &GDBM_WRCREAT(),0640)) {
16569: &_add_to_env(\%disk_env,\%initial_env);
16570: &_add_to_env(\%disk_env,\%userenv,'environment.');
16571: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16572: if (ref($firstaccenv) eq 'HASH') {
16573: &_add_to_env(\%disk_env,$firstaccenv);
16574: }
16575: if (ref($timerintenv) eq 'HASH') {
16576: &_add_to_env(\%disk_env,$timerintenv);
16577: }
1.463 albertel 16578: if (ref($args->{'extra_env'})) {
16579: &_add_to_env(\%disk_env,$args->{'extra_env'});
16580: }
1.462 albertel 16581: untie(%disk_env);
16582: } else {
1.705 tempelho 16583: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16584: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16585: return 'error: '.$!;
16586: }
16587: }
16588: $env{'request.role'}='cm';
16589: $env{'request.role.adv'}=$env{'user.adv'};
16590: $env{'browser.type'}=$clientbrowser;
16591:
16592: return $cookie;
16593:
16594: }
16595:
16596: sub _add_to_env {
16597: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16598: if (ref($env_data) eq 'HASH') {
16599: while (my ($key,$value) = each(%$env_data)) {
16600: $idf->{$prefix.$key} = $value;
16601: $env{$prefix.$key} = $value;
16602: }
1.462 albertel 16603: }
16604: }
16605:
1.685 tempelho 16606: # --- Get the symbolic name of a problem and the url
16607: sub get_symb {
16608: my ($request,$silent) = @_;
1.726 raeburn 16609: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16610: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16611: if ($symb eq '') {
16612: if (!$silent) {
1.1071 raeburn 16613: if (ref($request)) {
16614: $request->print("Unable to handle ambiguous references:$url:.");
16615: }
1.685 tempelho 16616: return ();
16617: }
16618: }
16619: &Apache::lonenc::check_decrypt(\$symb);
16620: return ($symb);
16621: }
16622:
16623: # --------------------------------------------------------------Get annotation
16624:
16625: sub get_annotation {
16626: my ($symb,$enc) = @_;
16627:
16628: my $key = $symb;
16629: if (!$enc) {
16630: $key =
16631: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16632: }
16633: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16634: return $annotation{$key};
16635: }
16636:
16637: sub clean_symb {
1.731 raeburn 16638: my ($symb,$delete_enc) = @_;
1.685 tempelho 16639:
16640: &Apache::lonenc::check_decrypt(\$symb);
16641: my $enc = $env{'request.enc'};
1.731 raeburn 16642: if ($delete_enc) {
1.730 raeburn 16643: delete($env{'request.enc'});
16644: }
1.685 tempelho 16645:
16646: return ($symb,$enc);
16647: }
1.462 albertel 16648:
1.1181 raeburn 16649: ############################################################
16650: ############################################################
16651:
16652: =pod
16653:
16654: =head1 Routines for building display used to search for courses
16655:
16656:
16657: =over 4
16658:
16659: =item * &build_filters()
16660:
16661: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16662: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16663: and quotacheck.pl
16664:
1.1181 raeburn 16665:
16666: Inputs:
16667:
16668: filterlist - anonymous array of fields to include as potential filters
16669:
16670: crstype - course type
16671:
16672: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16673: to pop-open a course selector (will contain "extra element").
16674:
16675: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16676:
16677: filter - anonymous hash of criteria and their values
16678:
16679: action - form action
16680:
16681: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16682:
1.1182 raeburn 16683: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16684:
16685: cloneruname - username of owner of new course who wants to clone
16686:
16687: clonerudom - domain of owner of new course who wants to clone
16688:
16689: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16690:
16691: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16692:
16693: codedom - domain
16694:
16695: formname - value of form element named "form".
16696:
16697: fixeddom - domain, if fixed.
16698:
16699: prevphase - value to assign to form element named "phase" when going back to the previous screen
16700:
16701: cnameelement - name of form element in form on opener page which will receive title of selected course
16702:
16703: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16704:
16705: cdomelement - name of form element in form on opener page which will receive domain of selected course
16706:
16707: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16708:
16709: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16710:
16711: clonewarning - warning message about missing information for intended course owner when DC creates a course
16712:
1.1182 raeburn 16713:
1.1181 raeburn 16714: Returns: $output - HTML for display of search criteria, and hidden form elements.
16715:
1.1182 raeburn 16716:
1.1181 raeburn 16717: Side Effects: None
16718:
16719: =cut
16720:
16721: # ---------------------------------------------- search for courses based on last activity etc.
16722:
16723: sub build_filters {
16724: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16725: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16726: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16727: $cnameelement,$cnumelement,$cdomelement,$setroles,
16728: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16729: my ($list,$jscript);
1.1181 raeburn 16730: my $onchange = 'javascript:updateFilters(this)';
16731: my ($domainselectform,$sincefilterform,$createdfilterform,
16732: $ownerdomselectform,$persondomselectform,$instcodeform,
16733: $typeselectform,$instcodetitle);
16734: if ($formname eq '') {
16735: $formname = $caller;
16736: }
16737: foreach my $item (@{$filterlist}) {
16738: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16739: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16740: if ($item eq 'domainfilter') {
16741: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16742: } elsif ($item eq 'coursefilter') {
16743: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16744: } elsif ($item eq 'ownerfilter') {
16745: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16746: } elsif ($item eq 'ownerdomfilter') {
16747: $filter->{'ownerdomfilter'} =
16748: &LONCAPA::clean_domain($filter->{$item});
16749: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16750: 'ownerdomfilter',1);
16751: } elsif ($item eq 'personfilter') {
16752: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16753: } elsif ($item eq 'persondomfilter') {
16754: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16755: 'persondomfilter',1);
16756: } else {
16757: $filter->{$item} =~ s/\W//g;
16758: }
16759: if (!$filter->{$item}) {
16760: $filter->{$item} = '';
16761: }
16762: }
16763: if ($item eq 'domainfilter') {
16764: my $allow_blank = 1;
16765: if ($formname eq 'portform') {
16766: $allow_blank=0;
16767: } elsif ($formname eq 'studentform') {
16768: $allow_blank=0;
16769: }
16770: if ($fixeddom) {
16771: $domainselectform = '<input type="hidden" name="domainfilter"'.
16772: ' value="'.$codedom.'" />'.
16773: &Apache::lonnet::domain($codedom,'description');
16774: } else {
16775: $domainselectform = &select_dom_form($filter->{$item},
16776: 'domainfilter',
16777: $allow_blank,'',$onchange);
16778: }
16779: } else {
16780: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16781: }
16782: }
16783:
16784: # last course activity filter and selection
16785: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16786:
16787: # course created filter and selection
16788: if (exists($filter->{'createdfilter'})) {
16789: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16790: }
16791:
1.1239 raeburn 16792: my $prefix = $crstype;
16793: if ($crstype eq 'Placement') {
16794: $prefix = 'Placement Test'
16795: }
1.1181 raeburn 16796: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16797: 'cac' => "$prefix Activity",
16798: 'ccr' => "$prefix Created",
16799: 'cde' => "$prefix Title",
16800: 'cdo' => "$prefix Domain",
1.1181 raeburn 16801: 'ins' => 'Institutional Code',
16802: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16803: 'cow' => "$prefix Owner/Co-owner",
16804: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16805: 'cog' => 'Type',
16806: );
16807:
16808: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16809: my $typeval = 'Course';
16810: if ($crstype eq 'Community') {
16811: $typeval = 'Community';
1.1239 raeburn 16812: } elsif ($crstype eq 'Placement') {
16813: $typeval = 'Placement';
1.1181 raeburn 16814: }
16815: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16816: } else {
16817: $typeselectform = '<select name="type" size="1"';
16818: if ($onchange) {
16819: $typeselectform .= ' onchange="'.$onchange.'"';
16820: }
16821: $typeselectform .= '>'."\n";
1.1237 raeburn 16822: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16823: my $shown;
16824: if ($posstype eq 'Placement') {
16825: $shown = &mt('Placement Test');
16826: } else {
16827: $shown = &mt($posstype);
16828: }
1.1181 raeburn 16829: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16830: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16831: }
16832: $typeselectform.="</select>";
16833: }
16834:
16835: my ($cloneableonlyform,$cloneabletitle);
16836: if (exists($filter->{'cloneableonly'})) {
16837: my $cloneableon = '';
16838: my $cloneableoff = ' checked="checked"';
16839: if ($filter->{'cloneableonly'}) {
16840: $cloneableon = $cloneableoff;
16841: $cloneableoff = '';
16842: }
16843: $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>';
16844: if ($formname eq 'ccrs') {
1.1187 bisitz 16845: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16846: } else {
16847: $cloneabletitle = &mt('Cloneable by you');
16848: }
16849: }
16850: my $officialjs;
16851: if ($crstype eq 'Course') {
16852: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16853: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16854: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16855: if ($codedom) {
1.1181 raeburn 16856: $officialjs = 1;
16857: ($instcodeform,$jscript,$$numtitlesref) =
16858: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16859: $officialjs,$codetitlesref);
16860: if ($jscript) {
1.1182 raeburn 16861: $jscript = '<script type="text/javascript">'."\n".
16862: '// <![CDATA['."\n".
16863: $jscript."\n".
16864: '// ]]>'."\n".
16865: '</script>'."\n";
1.1181 raeburn 16866: }
16867: }
16868: if ($instcodeform eq '') {
16869: $instcodeform =
16870: '<input type="text" name="instcodefilter" size="10" value="'.
16871: $list->{'instcodefilter'}.'" />';
16872: $instcodetitle = $lt{'ins'};
16873: } else {
16874: $instcodetitle = $lt{'inc'};
16875: }
16876: if ($fixeddom) {
16877: $instcodetitle .= '<br />('.$codedom.')';
16878: }
16879: }
16880: }
16881: my $output = qq|
16882: <form method="post" name="filterpicker" action="$action">
16883: <input type="hidden" name="form" value="$formname" />
16884: |;
16885: if ($formname eq 'modifycourse') {
16886: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16887: '<input type="hidden" name="prevphase" value="'.
16888: $prevphase.'" />'."\n";
1.1198 musolffc 16889: } elsif ($formname eq 'quotacheck') {
16890: $output .= qq|
16891: <input type="hidden" name="sortby" value="" />
16892: <input type="hidden" name="sortorder" value="" />
16893: |;
16894: } else {
1.1181 raeburn 16895: my $name_input;
16896: if ($cnameelement ne '') {
16897: $name_input = '<input type="hidden" name="cnameelement" value="'.
16898: $cnameelement.'" />';
16899: }
16900: $output .= qq|
1.1182 raeburn 16901: <input type="hidden" name="cnumelement" value="$cnumelement" />
16902: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16903: $name_input
16904: $roleelement
16905: $multelement
16906: $typeelement
16907: |;
16908: if ($formname eq 'portform') {
16909: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16910: }
16911: }
16912: if ($fixeddom) {
16913: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16914: }
16915: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16916: if ($sincefilterform) {
16917: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16918: .$sincefilterform
16919: .&Apache::lonhtmlcommon::row_closure();
16920: }
16921: if ($createdfilterform) {
16922: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16923: .$createdfilterform
16924: .&Apache::lonhtmlcommon::row_closure();
16925: }
16926: if ($domainselectform) {
16927: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16928: .$domainselectform
16929: .&Apache::lonhtmlcommon::row_closure();
16930: }
16931: if ($typeselectform) {
16932: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16933: $output .= $typeselectform;
16934: } else {
16935: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16936: .$typeselectform
16937: .&Apache::lonhtmlcommon::row_closure();
16938: }
16939: }
16940: if ($instcodeform) {
16941: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16942: .$instcodeform
16943: .&Apache::lonhtmlcommon::row_closure();
16944: }
16945: if (exists($filter->{'ownerfilter'})) {
16946: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16947: '<table><tr><td>'.&mt('Username').'<br />'.
16948: '<input type="text" name="ownerfilter" size="20" value="'.
16949: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16950: $ownerdomselectform.'</td></tr></table>'.
16951: &Apache::lonhtmlcommon::row_closure();
16952: }
16953: if (exists($filter->{'personfilter'})) {
16954: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16955: '<table><tr><td>'.&mt('Username').'<br />'.
16956: '<input type="text" name="personfilter" size="20" value="'.
16957: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16958: $persondomselectform.'</td></tr></table>'.
16959: &Apache::lonhtmlcommon::row_closure();
16960: }
16961: if (exists($filter->{'coursefilter'})) {
16962: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16963: .'<input type="text" name="coursefilter" size="25" value="'
16964: .$list->{'coursefilter'}.'" />'
16965: .&Apache::lonhtmlcommon::row_closure();
16966: }
16967: if ($cloneableonlyform) {
16968: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16969: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16970: }
16971: if (exists($filter->{'descriptfilter'})) {
16972: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16973: .'<input type="text" name="descriptfilter" size="40" value="'
16974: .$list->{'descriptfilter'}.'" />'
16975: .&Apache::lonhtmlcommon::row_closure(1);
16976: }
16977: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16978: '<input type="hidden" name="updater" value="" />'."\n".
16979: '<input type="submit" name="gosearch" value="'.
16980: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16981: return $jscript.$clonewarning.$output;
16982: }
16983:
16984: =pod
16985:
16986: =item * &timebased_select_form()
16987:
1.1182 raeburn 16988: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16989: filter e.g., Course Activity, Course Created, when searching for courses
16990: or communities
16991:
16992: Inputs:
16993:
16994: item - name of form element (sincefilter or createdfilter)
16995:
16996: filter - anonymous hash of criteria and their values
16997:
16998: Returns: HTML for a select box contained a blank, then six time selections,
16999: with value set in incoming form variables currently selected.
17000:
17001: Side Effects: None
17002:
17003: =cut
17004:
17005: sub timebased_select_form {
17006: my ($item,$filter) = @_;
17007: if (ref($filter) eq 'HASH') {
17008: $filter->{$item} =~ s/[^\d-]//g;
17009: if (!$filter->{$item}) { $filter->{$item}=-1; }
17010: return &select_form(
17011: $filter->{$item},
17012: $item,
17013: { '-1' => '',
17014: '86400' => &mt('today'),
17015: '604800' => &mt('last week'),
17016: '2592000' => &mt('last month'),
17017: '7776000' => &mt('last three months'),
17018: '15552000' => &mt('last six months'),
17019: '31104000' => &mt('last year'),
17020: 'select_form_order' =>
17021: ['-1','86400','604800','2592000','7776000',
17022: '15552000','31104000']});
17023: }
17024: }
17025:
17026: =pod
17027:
17028: =item * &js_changer()
17029:
17030: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17031: when course type or domain is changed, and also to hide 'Searching ...' on
17032: page load completion for page showing search result.
1.1181 raeburn 17033:
17034: Inputs: None
17035:
1.1183 raeburn 17036: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17037:
17038: Side Effects: None
17039:
17040: =cut
17041:
17042: sub js_changer {
17043: return <<ENDJS;
17044: <script type="text/javascript">
17045: // <![CDATA[
17046: function updateFilters(caller) {
17047: if (typeof(caller) != "undefined") {
17048: document.filterpicker.updater.value = caller.name;
17049: }
17050: document.filterpicker.submit();
17051: }
1.1183 raeburn 17052:
17053: function hideSearching() {
17054: if (document.getElementById('searching')) {
17055: document.getElementById('searching').style.display = 'none';
17056: }
17057: return;
17058: }
17059:
1.1181 raeburn 17060: // ]]>
17061: </script>
17062:
17063: ENDJS
17064: }
17065:
17066: =pod
17067:
1.1182 raeburn 17068: =item * &search_courses()
17069:
17070: Process selected filters form course search form and pass to lonnet::courseiddump
17071: to retrieve a hash for which keys are courseIDs which match the selected filters.
17072:
17073: Inputs:
17074:
17075: dom - domain being searched
17076:
17077: type - course type ('Course' or 'Community' or '.' if any).
17078:
17079: filter - anonymous hash of criteria and their values
17080:
17081: numtitles - for institutional codes - number of categories
17082:
17083: cloneruname - optional username of new course owner
17084:
17085: clonerudom - optional domain of new course owner
17086:
1.1221 raeburn 17087: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17088: (used when DC is using course creation form)
17089:
17090: codetitles - reference to array of titles of components in institutional codes (official courses).
17091:
1.1221 raeburn 17092: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17093: (and so can clone automatically)
17094:
17095: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17096:
17097: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17098: courses to clone
1.1182 raeburn 17099:
17100: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17101:
17102:
17103: Side Effects: None
17104:
17105: =cut
17106:
17107:
17108: sub search_courses {
1.1221 raeburn 17109: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17110: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17111: my (%courses,%showcourses,$cloner);
17112: if (($filter->{'ownerfilter'} ne '') ||
17113: ($filter->{'ownerdomfilter'} ne '')) {
17114: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17115: $filter->{'ownerdomfilter'};
17116: }
17117: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17118: if (!$filter->{$item}) {
17119: $filter->{$item}='.';
17120: }
17121: }
17122: my $now = time;
17123: my $timefilter =
17124: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17125: my ($createdbefore,$createdafter);
17126: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17127: $createdbefore = $now;
17128: $createdafter = $now-$filter->{'createdfilter'};
17129: }
17130: my ($instcodefilter,$regexpok);
17131: if ($numtitles) {
17132: if ($env{'form.official'} eq 'on') {
17133: $instcodefilter =
17134: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17135: $regexpok = 1;
17136: } elsif ($env{'form.official'} eq 'off') {
17137: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17138: unless ($instcodefilter eq '') {
17139: $regexpok = -1;
17140: }
17141: }
17142: } else {
17143: $instcodefilter = $filter->{'instcodefilter'};
17144: }
17145: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17146: if ($type eq '') { $type = '.'; }
17147:
17148: if (($clonerudom ne '') && ($cloneruname ne '')) {
17149: $cloner = $cloneruname.':'.$clonerudom;
17150: }
17151: %courses = &Apache::lonnet::courseiddump($dom,
17152: $filter->{'descriptfilter'},
17153: $timefilter,
17154: $instcodefilter,
17155: $filter->{'combownerfilter'},
17156: $filter->{'coursefilter'},
17157: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17158: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17159: $filter->{'cloneableonly'},
17160: $createdbefore,$createdafter,undef,
1.1221 raeburn 17161: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17162: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17163: my $ccrole;
17164: if ($type eq 'Community') {
17165: $ccrole = 'co';
17166: } else {
17167: $ccrole = 'cc';
17168: }
17169: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17170: $filter->{'persondomfilter'},
17171: 'userroles',undef,
17172: [$ccrole,'in','ad','ep','ta','cr'],
17173: $dom);
17174: foreach my $role (keys(%rolehash)) {
17175: my ($cnum,$cdom,$courserole) = split(':',$role);
17176: my $cid = $cdom.'_'.$cnum;
17177: if (exists($courses{$cid})) {
17178: if (ref($courses{$cid}) eq 'HASH') {
17179: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17180: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17181: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17182: }
17183: } else {
17184: $courses{$cid}{roles} = [$courserole];
17185: }
17186: $showcourses{$cid} = $courses{$cid};
17187: }
17188: }
17189: }
17190: %courses = %showcourses;
17191: }
17192: return %courses;
17193: }
17194:
17195: =pod
17196:
1.1181 raeburn 17197: =back
17198:
1.1207 raeburn 17199: =head1 Routines for version requirements for current course.
17200:
17201: =over 4
17202:
17203: =item * &check_release_required()
17204:
17205: Compares required LON-CAPA version with version on server, and
17206: if required version is newer looks for a server with the required version.
17207:
17208: Looks first at servers in user's owen domain; if none suitable, looks at
17209: servers in course's domain are permitted to host sessions for user's domain.
17210:
17211: Inputs:
17212:
17213: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17214:
17215: $courseid - Course ID of current course
17216:
17217: $rolecode - User's current role in course (for switchserver query string).
17218:
17219: $required - LON-CAPA version needed by course (format: Major.Minor).
17220:
17221:
17222: Returns:
17223:
17224: $switchserver - query string tp append to /adm/switchserver call (if
17225: current server's LON-CAPA version is too old.
17226:
17227: $warning - Message is displayed if no suitable server could be found.
17228:
17229: =cut
17230:
17231: sub check_release_required {
17232: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17233: my ($switchserver,$warning);
17234: if ($required ne '') {
17235: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17236: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17237: if ($reqdmajor ne '' && $reqdminor ne '') {
17238: my $otherserver;
17239: if (($major eq '' && $minor eq '') ||
17240: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17241: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17242: my $switchlcrev =
17243: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17244: $userdomserver);
17245: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17246: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17247: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17248: my $cdom = $env{'course.'.$courseid.'.domain'};
17249: if ($cdom ne $env{'user.domain'}) {
17250: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17251: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17252: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17253: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17254: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17255: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17256: my $canhost =
17257: &Apache::lonnet::can_host_session($env{'user.domain'},
17258: $coursedomserver,
17259: $remoterev,
17260: $udomdefaults{'remotesessions'},
17261: $defdomdefaults{'hostedsessions'});
17262:
17263: if ($canhost) {
17264: $otherserver = $coursedomserver;
17265: } else {
17266: $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.");
17267: }
17268: } else {
17269: $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).");
17270: }
17271: } else {
17272: $otherserver = $userdomserver;
17273: }
17274: }
17275: if ($otherserver ne '') {
17276: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17277: }
17278: }
17279: }
17280: return ($switchserver,$warning);
17281: }
17282:
17283: =pod
17284:
17285: =item * &check_release_result()
17286:
17287: Inputs:
17288:
17289: $switchwarning - Warning message if no suitable server found to host session.
17290:
17291: $switchserver - query string to append to /adm/switchserver containing lonHostID
17292: and current role.
17293:
17294: Returns: HTML to display with information about requirement to switch server.
17295: Either displaying warning with link to Roles/Courses screen or
17296: display link to switchserver.
17297:
1.1181 raeburn 17298: =cut
17299:
1.1207 raeburn 17300: sub check_release_result {
17301: my ($switchwarning,$switchserver) = @_;
17302: my $output = &start_page('Selected course unavailable on this server').
17303: '<p class="LC_warning">';
17304: if ($switchwarning) {
17305: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17306: if (&show_course()) {
17307: $output .= &mt('Display courses');
17308: } else {
17309: $output .= &mt('Display roles');
17310: }
17311: $output .= '</a>';
17312: } elsif ($switchserver) {
17313: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17314: '<br />'.
17315: '<a href="/adm/switchserver?'.$switchserver.'">'.
17316: &mt('Switch Server').
17317: '</a>';
17318: }
17319: $output .= '</p>'.&end_page();
17320: return $output;
17321: }
17322:
17323: =pod
17324:
17325: =item * &needs_coursereinit()
17326:
17327: Determine if course contents stored for user's session needs to be
17328: refreshed, because content has changed since "Big Hash" last tied.
17329:
17330: Check for change is made if time last checked is more than 10 minutes ago
17331: (by default).
17332:
17333: Inputs:
17334:
17335: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17336:
17337: $interval (optional) - Time which may elapse (in s) between last check for content
17338: change in current course. (default: 600 s).
17339:
17340: Returns: an array; first element is:
17341:
17342: =over 4
17343:
17344: 'switch' - if content updates mean user's session
17345: needs to be switched to a server running a newer LON-CAPA version
17346:
17347: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17348: on current server hosting user's session
17349:
17350: '' - if no action required.
17351:
17352: =back
17353:
17354: If first item element is 'switch':
17355:
17356: second item is $switchwarning - Warning message if no suitable server found to host session.
17357:
17358: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17359: and current role.
17360:
17361: otherwise: no other elements returned.
17362:
17363: =back
17364:
17365: =cut
17366:
17367: sub needs_coursereinit {
17368: my ($loncaparev,$interval) = @_;
17369: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17370: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17371: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17372: my $now = time;
17373: if ($interval eq '') {
17374: $interval = 600;
17375: }
17376: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17377: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17378: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17379: if ($blocked) {
17380: return ();
17381: }
1.1207 raeburn 17382: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17383: if ($lastchange > $env{'request.course.tied'}) {
17384: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17385: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17386: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17387: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17388: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17389: $curr_reqd_hash{'internal.releaserequired'}});
17390: my ($switchserver,$switchwarning) =
17391: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17392: $curr_reqd_hash{'internal.releaserequired'});
17393: if ($switchwarning ne '' || $switchserver ne '') {
17394: return ('switch',$switchwarning,$switchserver);
17395: }
17396: }
17397: }
17398: return ('update');
17399: }
17400: }
17401: return ();
17402: }
1.1181 raeburn 17403:
1.1083 raeburn 17404: sub update_content_constraints {
17405: my ($cdom,$cnum,$chome,$cid) = @_;
17406: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17407: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17408: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17409: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17410: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17411: if ($item eq 'resourcetag') {
17412: if ($name eq 'responsetype') {
17413: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17414: }
1.1307 raeburn 17415: } elsif ($item eq 'course') {
17416: if ($name eq 'courserestype') {
17417: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17418: }
1.1083 raeburn 17419: }
17420: }
17421: my $navmap = Apache::lonnavmaps::navmap->new();
17422: if (defined($navmap)) {
1.1307 raeburn 17423: my (%allresponses,%allcrsrestypes);
17424: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17425: if ($res->is_tool()) {
17426: if ($allcrsrestypes{'exttool'}) {
17427: $allcrsrestypes{'exttool'} ++;
17428: } else {
17429: $allcrsrestypes{'exttool'} = 1;
17430: }
17431: next;
17432: }
1.1083 raeburn 17433: my %responses = $res->responseTypes();
17434: foreach my $key (keys(%responses)) {
17435: next unless(exists($checkresponsetypes{$key}));
17436: $allresponses{$key} += $responses{$key};
17437: }
17438: }
17439: foreach my $key (keys(%allresponses)) {
17440: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17441: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17442: ($reqdmajor,$reqdminor) = ($major,$minor);
17443: }
17444: }
1.1307 raeburn 17445: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17446: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17447: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17448: ($reqdmajor,$reqdminor) = ($major,$minor);
17449: }
17450: }
1.1083 raeburn 17451: undef($navmap);
17452: }
1.1308 raeburn 17453: my $suppmap = 'supplemental.sequence';
17454: my ($suppcount,$supptools,$errors) = (0,0,0);
17455: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17456: $suppcount,$supptools,$errors);
17457: if ($supptools) {
17458: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17459: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17460: ($reqdmajor,$reqdminor) = ($major,$minor);
17461: }
17462: }
1.1083 raeburn 17463: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17464: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17465: }
17466: return;
17467: }
17468:
1.1110 raeburn 17469: sub allmaps_incourse {
17470: my ($cdom,$cnum,$chome,$cid) = @_;
17471: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17472: $cid = $env{'request.course.id'};
17473: $cdom = $env{'course.'.$cid.'.domain'};
17474: $cnum = $env{'course.'.$cid.'.num'};
17475: $chome = $env{'course.'.$cid.'.home'};
17476: }
17477: my %allmaps = ();
17478: my $lastchange =
17479: &Apache::lonnet::get_coursechange($cdom,$cnum);
17480: if ($lastchange > $env{'request.course.tied'}) {
17481: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17482: unless ($ferr) {
17483: &update_content_constraints($cdom,$cnum,$chome,$cid);
17484: }
17485: }
17486: my $navmap = Apache::lonnavmaps::navmap->new();
17487: if (defined($navmap)) {
17488: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17489: $allmaps{$res->src()} = 1;
17490: }
17491: }
17492: return \%allmaps;
17493: }
17494:
1.1083 raeburn 17495: sub parse_supplemental_title {
17496: my ($title) = @_;
17497:
17498: my ($foldertitle,$renametitle);
17499: if ($title =~ /&&&/) {
17500: $title = &HTML::Entites::decode($title);
17501: }
17502: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17503: $renametitle=$4;
17504: my ($time,$uname,$udom) = ($1,$2,$3);
17505: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17506: my $name = &plainname($uname,$udom);
17507: $name = &HTML::Entities::encode($name,'"<>&\'');
17508: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17509: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17510: $name.': <br />'.$foldertitle;
17511: }
17512: if (wantarray) {
17513: return ($title,$foldertitle,$renametitle);
17514: }
17515: return $title;
17516: }
17517:
1.1143 raeburn 17518: sub recurse_supplemental {
1.1308 raeburn 17519: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17520: if ($suppmap) {
17521: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17522: if ($fatal) {
17523: $errors ++;
17524: } else {
17525: if ($#LONCAPA::map::resources > 0) {
17526: foreach my $res (@LONCAPA::map::resources) {
17527: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17528: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17529: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17530: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17531: $numfiles,$numexttools,$errors);
1.1143 raeburn 17532: } else {
1.1308 raeburn 17533: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17534: $numexttools ++;
17535: }
1.1143 raeburn 17536: $numfiles ++;
17537: }
17538: }
17539: }
17540: }
17541: }
17542: }
1.1308 raeburn 17543: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17544: }
17545:
1.1101 raeburn 17546: sub symb_to_docspath {
1.1267 raeburn 17547: my ($symb,$navmapref) = @_;
17548: return unless ($symb && ref($navmapref));
1.1101 raeburn 17549: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17550: if ($resurl=~/\.(sequence|page)$/) {
17551: $mapurl=$resurl;
17552: } elsif ($resurl eq 'adm/navmaps') {
17553: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17554: }
17555: my $mapresobj;
1.1267 raeburn 17556: unless (ref($$navmapref)) {
17557: $$navmapref = Apache::lonnavmaps::navmap->new();
17558: }
17559: if (ref($$navmapref)) {
17560: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17561: }
17562: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17563: my $type=$2;
17564: my $path;
17565: if (ref($mapresobj)) {
17566: my $pcslist = $mapresobj->map_hierarchy();
17567: if ($pcslist ne '') {
17568: foreach my $pc (split(/,/,$pcslist)) {
17569: next if ($pc <= 1);
1.1267 raeburn 17570: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17571: if (ref($res)) {
17572: my $thisurl = $res->src();
17573: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17574: my $thistitle = $res->title();
17575: $path .= '&'.
17576: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17577: &escape($thistitle).
1.1101 raeburn 17578: ':'.$res->randompick().
17579: ':'.$res->randomout().
17580: ':'.$res->encrypted().
17581: ':'.$res->randomorder().
17582: ':'.$res->is_page();
17583: }
17584: }
17585: }
17586: $path =~ s/^\&//;
17587: my $maptitle = $mapresobj->title();
17588: if ($mapurl eq 'default') {
1.1129 raeburn 17589: $maptitle = 'Main Content';
1.1101 raeburn 17590: }
17591: $path .= (($path ne '')? '&' : '').
17592: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17593: &escape($maptitle).
1.1101 raeburn 17594: ':'.$mapresobj->randompick().
17595: ':'.$mapresobj->randomout().
17596: ':'.$mapresobj->encrypted().
17597: ':'.$mapresobj->randomorder().
17598: ':'.$mapresobj->is_page();
17599: } else {
17600: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17601: my $ispage = (($type eq 'page')? 1 : '');
17602: if ($mapurl eq 'default') {
1.1129 raeburn 17603: $maptitle = 'Main Content';
1.1101 raeburn 17604: }
17605: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17606: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17607: }
17608: unless ($mapurl eq 'default') {
17609: $path = 'default&'.
1.1146 raeburn 17610: &escape('Main Content').
1.1101 raeburn 17611: ':::::&'.$path;
17612: }
17613: return $path;
17614: }
17615:
1.1094 raeburn 17616: sub captcha_display {
17617: my ($context,$lonhost) = @_;
17618: my ($output,$error);
1.1234 raeburn 17619: my ($captcha,$pubkey,$privkey,$version) =
17620: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17621: if ($captcha eq 'original') {
1.1094 raeburn 17622: $output = &create_captcha();
17623: unless ($output) {
1.1172 raeburn 17624: $error = 'captcha';
1.1094 raeburn 17625: }
17626: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17627: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17628: unless ($output) {
1.1172 raeburn 17629: $error = 'recaptcha';
1.1094 raeburn 17630: }
17631: }
1.1234 raeburn 17632: return ($output,$error,$captcha,$version);
1.1094 raeburn 17633: }
17634:
17635: sub captcha_response {
17636: my ($context,$lonhost) = @_;
17637: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17638: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17639: if ($captcha eq 'original') {
1.1094 raeburn 17640: ($captcha_chk,$captcha_error) = &check_captcha();
17641: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17642: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17643: } else {
17644: $captcha_chk = 1;
17645: }
17646: return ($captcha_chk,$captcha_error);
17647: }
17648:
17649: sub get_captcha_config {
17650: my ($context,$lonhost) = @_;
1.1234 raeburn 17651: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17652: my $hostname = &Apache::lonnet::hostname($lonhost);
17653: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17654: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17655: if ($context eq 'usercreation') {
17656: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17657: if (ref($domconfig{$context}) eq 'HASH') {
17658: $hashtocheck = $domconfig{$context}{'cancreate'};
17659: if (ref($hashtocheck) eq 'HASH') {
17660: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17661: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17662: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17663: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17664: }
17665: if ($privkey && $pubkey) {
17666: $captcha = 'recaptcha';
1.1234 raeburn 17667: $version = $hashtocheck->{'recaptchaversion'};
17668: if ($version ne '2') {
17669: $version = 1;
17670: }
1.1095 raeburn 17671: } else {
17672: $captcha = 'original';
17673: }
17674: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17675: $captcha = 'original';
17676: }
1.1094 raeburn 17677: }
1.1095 raeburn 17678: } else {
17679: $captcha = 'captcha';
17680: }
17681: } elsif ($context eq 'login') {
17682: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17683: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17684: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17685: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17686: if ($privkey && $pubkey) {
17687: $captcha = 'recaptcha';
1.1234 raeburn 17688: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17689: if ($version ne '2') {
17690: $version = 1;
17691: }
1.1095 raeburn 17692: } else {
17693: $captcha = 'original';
1.1094 raeburn 17694: }
1.1095 raeburn 17695: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17696: $captcha = 'original';
1.1094 raeburn 17697: }
17698: }
1.1234 raeburn 17699: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17700: }
17701:
17702: sub create_captcha {
17703: my %captcha_params = &captcha_settings();
17704: my ($output,$maxtries,$tries) = ('',10,0);
17705: while ($tries < $maxtries) {
17706: $tries ++;
17707: my $captcha = Authen::Captcha->new (
17708: output_folder => $captcha_params{'output_dir'},
17709: data_folder => $captcha_params{'db_dir'},
17710: );
17711: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17712:
17713: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17714: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17715: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17716: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17717: '<br />'.
17718: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17719: last;
17720: }
17721: }
17722: return $output;
17723: }
17724:
17725: sub captcha_settings {
17726: my %captcha_params = (
17727: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17728: www_output_dir => "/captchaspool",
17729: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17730: numchars => '5',
17731: );
17732: return %captcha_params;
17733: }
17734:
17735: sub check_captcha {
17736: my ($captcha_chk,$captcha_error);
17737: my $code = $env{'form.code'};
17738: my $md5sum = $env{'form.crypt'};
17739: my %captcha_params = &captcha_settings();
17740: my $captcha = Authen::Captcha->new(
17741: output_folder => $captcha_params{'output_dir'},
17742: data_folder => $captcha_params{'db_dir'},
17743: );
1.1109 raeburn 17744: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17745: my %captcha_hash = (
17746: 0 => 'Code not checked (file error)',
17747: -1 => 'Failed: code expired',
17748: -2 => 'Failed: invalid code (not in database)',
17749: -3 => 'Failed: invalid code (code does not match crypt)',
17750: );
17751: if ($captcha_chk != 1) {
17752: $captcha_error = $captcha_hash{$captcha_chk}
17753: }
17754: return ($captcha_chk,$captcha_error);
17755: }
17756:
17757: sub create_recaptcha {
1.1234 raeburn 17758: my ($pubkey,$version) = @_;
17759: if ($version >= 2) {
17760: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17761: } else {
17762: my $use_ssl;
17763: if ($ENV{'SERVER_PORT'} == 443) {
17764: $use_ssl = 1;
17765: }
17766: my $captcha = Captcha::reCAPTCHA->new;
17767: return $captcha->get_options_setter({theme => 'white'})."\n".
17768: $captcha->get_html($pubkey,undef,$use_ssl).
17769: &mt('If the text is hard to read, [_1] will replace them.',
17770: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17771: '<br /><br />';
17772: }
1.1094 raeburn 17773: }
17774:
17775: sub check_recaptcha {
1.1234 raeburn 17776: my ($privkey,$version) = @_;
1.1094 raeburn 17777: my $captcha_chk;
1.1234 raeburn 17778: if ($version >= 2) {
17779: my %info = (
17780: secret => $privkey,
17781: response => $env{'form.g-recaptcha-response'},
17782: remoteip => $ENV{'REMOTE_ADDR'},
17783: );
1.1280 raeburn 17784: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17785: $request->content(join('&',map {
17786: my $name = escape($_);
17787: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17788: ? join("&$name=", map {escape($_) } @{$info{$_}})
17789: : &escape($info{$_}) );
17790: } keys(%info)));
17791: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17792: if ($response->is_success) {
17793: my $data = JSON::DWIW->from_json($response->decoded_content);
17794: if (ref($data) eq 'HASH') {
17795: if ($data->{'success'}) {
17796: $captcha_chk = 1;
17797: }
17798: }
17799: }
17800: } else {
17801: my $captcha = Captcha::reCAPTCHA->new;
17802: my $captcha_result =
17803: $captcha->check_answer(
17804: $privkey,
17805: $ENV{'REMOTE_ADDR'},
17806: $env{'form.recaptcha_challenge_field'},
17807: $env{'form.recaptcha_response_field'},
17808: );
17809: if ($captcha_result->{is_valid}) {
17810: $captcha_chk = 1;
17811: }
1.1094 raeburn 17812: }
17813: return $captcha_chk;
17814: }
17815:
1.1174 raeburn 17816: sub emailusername_info {
1.1244 raeburn 17817: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17818: my %titles = &Apache::lonlocal::texthash (
17819: lastname => 'Last Name',
17820: firstname => 'First Name',
17821: institution => 'School/college/university',
17822: location => "School's city, state/province, country",
17823: web => "School's web address",
17824: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17825: id => 'Student/Employee ID',
1.1174 raeburn 17826: );
17827: return (\@fields,\%titles);
17828: }
17829:
1.1161 raeburn 17830: sub cleanup_html {
17831: my ($incoming) = @_;
17832: my $outgoing;
17833: if ($incoming ne '') {
17834: $outgoing = $incoming;
17835: $outgoing =~ s/;/;/g;
17836: $outgoing =~ s/\#/#/g;
17837: $outgoing =~ s/\&/&/g;
17838: $outgoing =~ s/</</g;
17839: $outgoing =~ s/>/>/g;
17840: $outgoing =~ s/\(/(/g;
17841: $outgoing =~ s/\)/)/g;
17842: $outgoing =~ s/"/"/g;
17843: $outgoing =~ s/'/'/g;
17844: $outgoing =~ s/\$/$/g;
17845: $outgoing =~ s{/}{/}g;
17846: $outgoing =~ s/=/=/g;
17847: $outgoing =~ s/\\/\/g
17848: }
17849: return $outgoing;
17850: }
17851:
1.1190 musolffc 17852: # Checks for critical messages and returns a redirect url if one exists.
17853: # $interval indicates how often to check for messages.
1.1282 raeburn 17854: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 17855: sub critical_redirect {
1.1282 raeburn 17856: my ($interval,$context) = @_;
1.1190 musolffc 17857: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 17858: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17859: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17860: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17861: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17862: if ($blocked) {
17863: my $checkrole = "cm./$cdom/$cnum";
17864: if ($env{'request.course.sec'} ne '') {
17865: $checkrole .= "/$env{'request.course.sec'}";
17866: }
17867: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17868: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17869: return;
17870: }
17871: }
17872: }
1.1190 musolffc 17873: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17874: $env{'user.name'});
17875: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17876: my $redirecturl;
1.1190 musolffc 17877: if ($what[0]) {
17878: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17879: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17880: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17881: return (1, $url);
1.1190 musolffc 17882: }
1.1191 raeburn 17883: }
17884: }
17885: return ();
1.1190 musolffc 17886: }
17887:
1.1174 raeburn 17888: # Use:
17889: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17890: #
17891: ##################################################
17892: # password associated functions #
17893: ##################################################
17894: sub des_keys {
17895: # Make a new key for DES encryption.
17896: # Each key has two parts which are returned separately.
17897: # Please note: Each key must be passed through the &hex function
17898: # before it is output to the web browser. The hex versions cannot
17899: # be used to decrypt.
17900: my @hexstr=('0','1','2','3','4','5','6','7',
17901: '8','9','a','b','c','d','e','f');
17902: my $lkey='';
17903: for (0..7) {
17904: $lkey.=$hexstr[rand(15)];
17905: }
17906: my $ukey='';
17907: for (0..7) {
17908: $ukey.=$hexstr[rand(15)];
17909: }
17910: return ($lkey,$ukey);
17911: }
17912:
17913: sub des_decrypt {
17914: my ($key,$cyphertext) = @_;
17915: my $keybin=pack("H16",$key);
17916: my $cypher;
17917: if ($Crypt::DES::VERSION>=2.03) {
17918: $cypher=new Crypt::DES $keybin;
17919: } else {
17920: $cypher=new DES $keybin;
17921: }
1.1233 raeburn 17922: my $plaintext='';
17923: my $cypherlength = length($cyphertext);
17924: my $numchunks = int($cypherlength/32);
17925: for (my $j=0; $j<$numchunks; $j++) {
17926: my $start = $j*32;
17927: my $cypherblock = substr($cyphertext,$start,32);
17928: my $chunk =
17929: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17930: $chunk .=
17931: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17932: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17933: $plaintext .= $chunk;
17934: }
1.1174 raeburn 17935: return $plaintext;
17936: }
17937:
1.1309 raeburn 17938: sub make_short_symbs {
17939: my ($cdom,$cnum,$navmap) = @_;
17940: return unless (ref($navmap));
17941: my ($numnew,@errors);
17942: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
17943: if (@toshorten) {
17944: my (%maps,%resources,%titles);
17945: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
17946: 'shorturls',$cdom,$cnum);
17947: my %tocreate;
17948: if (keys(%resources)) {
17949: foreach my $item (sort {$a <=> $b} (@toshorten)) {
17950: my $symb = $resources{$item};
17951: if ($symb) {
17952: $tocreate{$cnum.'&'.$symb} = 1;
17953: }
17954: }
17955: }
17956: if (keys(%tocreate)) {
17957: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
17958: my $su = Short::URL->new(no_vowels => 1);
17959: my $init = '';
17960: my (%newunique,%addcourse,%courseonly,%failed);
17961: # get lock on tiny db
17962: my $now = time;
17963: my $lockhash = {
17964: "lock\0$now" => $env{'user.name'}.
17965: ':'.$env{'user.domain'},
17966: };
17967: my $tries = 0;
17968: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17969: my ($code,$error);
17970: while (($gotlock ne 'ok') && ($tries<3)) {
17971: $tries ++;
17972: sleep 1;
17973: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17974: }
17975: if ($gotlock eq 'ok') {
17976: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
17977: \%addcourse,\%courseonly,\%failed);
17978: if (keys(%failed)) {
17979: my $numfailed = scalar(keys(%failed));
17980: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
17981: }
17982: if (keys(%newunique)) {
17983: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
17984: if ($putres eq 'ok') {
17985: $numnew = scalar(keys(%newunique));
17986: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
17987: unless ($newputres eq 'ok') {
17988: push(@errors,&mt('error: could not store course look-up of short URLs'));
17989: }
17990: } else {
17991: push(@errors,&mt('error: could not store unique six character URLs'));
17992: }
17993: }
17994: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
17995: unless ($dellockres eq 'ok') {
17996: push(@errors,&mt('error: could not release lockfile'));
17997: }
17998: } else {
17999: push(@errors,&mt('error: could not obtain lockfile'));
18000: }
18001: if (keys(%courseonly)) {
18002: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18003: if ($result ne 'ok') {
18004: push(@errors,&mt('error: could not update course look-up of short URLs'));
18005: }
18006: }
18007: }
18008: }
18009: return ($numnew,\@errors);
18010: }
18011:
18012: sub shorten_symbs {
18013: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18014: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18015: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18016: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18017: my (%possibles,%collisions);
18018: foreach my $key (keys(%{$tocreate})) {
18019: my $num = String::CRC32::crc32($key);
18020: my $tiny = $su->encode($num,$init);
18021: if ($tiny) {
18022: $possibles{$tiny} = $key;
18023: }
18024: }
18025: if (!$init) {
18026: $init = 1;
18027: } else {
18028: $init ++;
18029: }
18030: if (keys(%possibles)) {
18031: my @posstiny = keys(%possibles);
18032: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18033: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18034: if (keys(%currtiny)) {
18035: foreach my $key (keys(%currtiny)) {
18036: next if ($currtiny{$key} eq '');
18037: if ($currtiny{$key} eq $possibles{$key}) {
18038: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18039: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18040: $courseonly->{$tsymb} = $key;
18041: }
18042: } else {
18043: $collisions{$possibles{$key}} = 1;
18044: }
18045: delete($possibles{$key});
18046: }
18047: }
18048: foreach my $key (keys(%possibles)) {
18049: $newunique->{$key} = $possibles{$key};
18050: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18051: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18052: $addcourse->{$tsymb} = $key;
18053: }
18054: }
18055: }
18056: if (keys(%collisions)) {
18057: if ($init <5) {
18058: if (!$init) {
18059: $init = 1;
18060: } else {
18061: $init ++;
18062: }
18063: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18064: $newunique,$addcourse,$courseonly,$failed);
18065: } else {
18066: foreach my $key (keys(%collisions)) {
18067: $failed->{$key} = 1;
18068: }
18069: }
18070: }
18071: return $init;
18072: }
18073:
1.112 bowersj2 18074: 1;
18075: __END__;
1.41 ng 18076:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>