Annotation of loncom/interface/loncommon.pm, revision 1.1028.2.2
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1028.2.2! foxr 4: # $Id: loncommon.pm,v 1.1028.2.1 2011/12/26 13:47:18 foxr 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.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.1028.2.2! foxr 157: my %latex_language; # For choosing hyphenation in <transl..>
! 158: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 159: my %cprtag;
1.192 taceyjo1 160: my %scprtag;
1.351 www 161: my %fe; my %fd; my %fm;
1.41 ng 162: my %category_extensions;
1.12 harris41 163:
1.46 matthew 164: # ---------------------------------------------- Thesaurus variables
1.144 matthew 165: #
166: # %Keywords:
167: # A hash used by &keyword to determine if a word is considered a keyword.
168: # $thesaurus_db_file
169: # Scalar containing the full path to the thesaurus database.
1.46 matthew 170:
171: my %Keywords;
172: my $thesaurus_db_file;
173:
1.144 matthew 174: #
175: # Initialize values from language.tab, copyright.tab, filetypes.tab,
176: # thesaurus.tab, and filecategories.tab.
177: #
1.18 www 178: BEGIN {
1.46 matthew 179: # Variable initialization
180: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
181: #
1.22 www 182: unless ($readit) {
1.12 harris41 183: # ------------------------------------------------------------------- languages
184: {
1.158 raeburn 185: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
186: '/language.tab';
187: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 188: while (my $line = <$fh>) {
189: next if ($line=~/^\#/);
190: chomp($line);
1.1028.2.1 foxr 191: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 192: $language{$key}=$val.' - '.$enc;
193: if ($sup) {
194: $supported_language{$key}=$sup;
195: }
1.1028.2.1 foxr 196: if ($latex) {
1.1028.2.2! foxr 197: $latex_language_bykey{$key} = $latex;
1.1028.2.1 foxr 198: $latex_language{$two} = $latex;
199: }
1.158 raeburn 200: }
201: close($fh);
202: }
1.12 harris41 203: }
204: # ------------------------------------------------------------------ copyrights
205: {
1.158 raeburn 206: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
207: '/copyright.tab';
208: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 209: while (my $line = <$fh>) {
210: next if ($line=~/^\#/);
211: chomp($line);
212: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 213: $cprtag{$key}=$val;
214: }
215: close($fh);
216: }
1.12 harris41 217: }
1.351 www 218: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 219: {
220: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
221: '/source_copyright.tab';
222: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 223: while (my $line = <$fh>) {
224: next if ($line =~ /^\#/);
225: chomp($line);
226: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 227: $scprtag{$key}=$val;
228: }
229: close($fh);
230: }
231: }
1.63 www 232:
1.517 raeburn 233: # -------------------------------------------------------------- default domain designs
1.63 www 234: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 235: my $designfile = $designdir.'/default.tab';
236: if ( open (my $fh,"<$designfile") ) {
237: while (my $line = <$fh>) {
238: next if ($line =~ /^\#/);
239: chomp($line);
240: my ($key,$val)=(split(/\=/,$line));
241: if ($val) { $defaultdesign{$key}=$val; }
242: }
243: close($fh);
1.63 www 244: }
245:
1.15 harris41 246: # ------------------------------------------------------------- file categories
247: {
1.158 raeburn 248: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
249: '/filecategories.tab';
250: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 251: while (my $line = <$fh>) {
252: next if ($line =~ /^\#/);
253: chomp($line);
254: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 255: push @{$category_extensions{lc($category)}},$extension;
256: }
257: close($fh);
258: }
259:
1.15 harris41 260: }
1.12 harris41 261: # ------------------------------------------------------------------ file types
262: {
1.158 raeburn 263: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
264: '/filetypes.tab';
265: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 266: while (my $line = <$fh>) {
267: next if ($line =~ /^\#/);
268: chomp($line);
269: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 270: if ($descr ne '') {
271: $fe{$ending}=lc($emb);
272: $fd{$ending}=$descr;
1.351 www 273: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 274: }
275: }
276: close($fh);
277: }
1.12 harris41 278: }
1.22 www 279: &Apache::lonnet::logthis(
1.705 tempelho 280: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 281: $readit=1;
1.46 matthew 282: } # end of unless($readit)
1.32 matthew 283:
284: }
1.112 bowersj2 285:
1.42 matthew 286: ###############################################################
287: ## HTML and Javascript Helper Functions ##
288: ###############################################################
289:
290: =pod
291:
1.112 bowersj2 292: =head1 HTML and Javascript Functions
1.42 matthew 293:
1.112 bowersj2 294: =over 4
295:
1.648 raeburn 296: =item * &browser_and_searcher_javascript()
1.112 bowersj2 297:
298: X<browsing, javascript>X<searching, javascript>Returns a string
299: containing javascript with two functions, C<openbrowser> and
300: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
301: tags.
1.42 matthew 302:
1.648 raeburn 303: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 304:
305: inputs: formname, elementname, only, omit
306:
307: formname and elementname indicate the name of the html form and name of
308: the element that the results of the browsing selection are to be placed in.
309:
310: Specifying 'only' will restrict the browser to displaying only files
1.185 www 311: with the given extension. Can be a comma separated list.
1.42 matthew 312:
313: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 314: with the given extension. Can be a comma separated list.
1.42 matthew 315:
1.648 raeburn 316: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 317:
318: Inputs: formname, elementname
319:
320: formname and elementname specify the name of the html form and the name
321: of the element the selection from the search results will be placed in.
1.542 raeburn 322:
1.42 matthew 323: =cut
324:
325: sub browser_and_searcher_javascript {
1.199 albertel 326: my ($mode)=@_;
327: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 328: my $resurl=&escape_single(&lastresurl());
1.42 matthew 329: return <<END;
1.219 albertel 330: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 331: var editbrowser = null;
1.135 albertel 332: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 333: var url = '$resurl/?';
1.42 matthew 334: if (editbrowser == null) {
335: url += 'launch=1&';
336: }
337: url += 'catalogmode=interactive&';
1.199 albertel 338: url += 'mode=$mode&';
1.611 albertel 339: url += 'inhibitmenu=yes&';
1.42 matthew 340: url += 'form=' + formname + '&';
341: if (only != null) {
342: url += 'only=' + only + '&';
1.217 albertel 343: } else {
344: url += 'only=&';
345: }
1.42 matthew 346: if (omit != null) {
347: url += 'omit=' + omit + '&';
1.217 albertel 348: } else {
349: url += 'omit=&';
350: }
1.135 albertel 351: if (titleelement != null) {
352: url += 'titleelement=' + titleelement + '&';
1.217 albertel 353: } else {
354: url += 'titleelement=&';
355: }
1.42 matthew 356: url += 'element=' + elementname + '';
357: var title = 'Browser';
1.435 albertel 358: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 359: options += ',width=700,height=600';
360: editbrowser = open(url,title,options,'1');
361: editbrowser.focus();
362: }
363: var editsearcher;
1.135 albertel 364: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 365: var url = '/adm/searchcat?';
366: if (editsearcher == null) {
367: url += 'launch=1&';
368: }
369: url += 'catalogmode=interactive&';
1.199 albertel 370: url += 'mode=$mode&';
1.42 matthew 371: url += 'form=' + formname + '&';
1.135 albertel 372: if (titleelement != null) {
373: url += 'titleelement=' + titleelement + '&';
1.217 albertel 374: } else {
375: url += 'titleelement=&';
376: }
1.42 matthew 377: url += 'element=' + elementname + '';
378: var title = 'Search';
1.435 albertel 379: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 380: options += ',width=700,height=600';
381: editsearcher = open(url,title,options,'1');
382: editsearcher.focus();
383: }
1.219 albertel 384: // END LON-CAPA Internal -->
1.42 matthew 385: END
1.170 www 386: }
387:
388: sub lastresurl {
1.258 albertel 389: if ($env{'environment.lastresurl'}) {
390: return $env{'environment.lastresurl'}
1.170 www 391: } else {
392: return '/res';
393: }
394: }
395:
396: sub storeresurl {
397: my $resurl=&Apache::lonnet::clutter(shift);
398: unless ($resurl=~/^\/res/) { return 0; }
399: $resurl=~s/\/$//;
400: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 401: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 402: return 1;
1.42 matthew 403: }
404:
1.74 www 405: sub studentbrowser_javascript {
1.111 www 406: unless (
1.258 albertel 407: (($env{'request.course.id'}) &&
1.302 albertel 408: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
409: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
410: '/'.$env{'request.course.sec'})
411: ))
1.258 albertel 412: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 413: ) { return ''; }
1.74 www 414: return (<<'ENDSTDBRW');
1.776 bisitz 415: <script type="text/javascript" language="Javascript">
1.824 bisitz 416: // <![CDATA[
1.74 www 417: var stdeditbrowser;
1.999 www 418: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 419: var url = '/adm/pickstudent?';
420: var filter;
1.558 albertel 421: if (!ignorefilter) {
422: eval('filter=document.'+formname+'.'+uname+'.value;');
423: }
1.74 www 424: if (filter != null) {
425: if (filter != '') {
426: url += 'filter='+filter+'&';
427: }
428: }
429: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 430: '&udomelement='+udom+
431: '&clicker='+clicker;
1.111 www 432: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 433: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 434: var title = 'Student_Browser';
1.74 www 435: var options = 'scrollbars=1,resizable=1,menubar=0';
436: options += ',width=700,height=600';
437: stdeditbrowser = open(url,title,options,'1');
438: stdeditbrowser.focus();
439: }
1.824 bisitz 440: // ]]>
1.74 www 441: </script>
442: ENDSTDBRW
443: }
1.42 matthew 444:
1.1003 www 445: sub resourcebrowser_javascript {
446: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 447: return (<<'ENDRESBRW');
1.1003 www 448: <script type="text/javascript" language="Javascript">
449: // <![CDATA[
450: var reseditbrowser;
1.1004 www 451: function openresbrowser(formname,reslink) {
1.1005 www 452: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 453: var title = 'Resource_Browser';
454: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 455: options += ',width=700,height=500';
1.1004 www 456: reseditbrowser = open(url,title,options,'1');
457: reseditbrowser.focus();
1.1003 www 458: }
459: // ]]>
460: </script>
1.1004 www 461: ENDRESBRW
1.1003 www 462: }
463:
1.74 www 464: sub selectstudent_link {
1.999 www 465: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
466: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
467: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
468: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 469: if ($env{'request.course.id'}) {
1.302 albertel 470: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
471: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
472: '/'.$env{'request.course.sec'})) {
1.111 www 473: return '';
474: }
1.999 www 475: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 476: if ($courseadvonly) {
477: $callargs .= ",'',1,1";
478: }
479: return '<span class="LC_nobreak">'.
480: '<a href="javascript:openstdbrowser('.$callargs.');">'.
481: &mt('Select User').'</a></span>';
1.74 www 482: }
1.258 albertel 483: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 484: $callargs .= ",'',1";
1.793 raeburn 485: return '<span class="LC_nobreak">'.
486: '<a href="javascript:openstdbrowser('.$callargs.');">'.
487: &mt('Select User').'</a></span>';
1.111 www 488: }
489: return '';
1.91 www 490: }
491:
1.1004 www 492: sub selectresource_link {
493: my ($form,$reslink,$arg)=@_;
494:
495: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
496: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
497: unless ($env{'request.course.id'}) { return $arg; }
498: return '<span class="LC_nobreak">'.
499: '<a href="javascript:openresbrowser('.$callargs.');">'.
500: $arg.'</a></span>';
501: }
502:
503:
504:
1.653 raeburn 505: sub authorbrowser_javascript {
506: return <<"ENDAUTHORBRW";
1.776 bisitz 507: <script type="text/javascript" language="JavaScript">
1.824 bisitz 508: // <![CDATA[
1.653 raeburn 509: var stdeditbrowser;
510:
511: function openauthorbrowser(formname,udom) {
512: var url = '/adm/pickauthor?';
513: url += 'form='+formname+'&roledom='+udom;
514: var title = 'Author_Browser';
515: var options = 'scrollbars=1,resizable=1,menubar=0';
516: options += ',width=700,height=600';
517: stdeditbrowser = open(url,title,options,'1');
518: stdeditbrowser.focus();
519: }
520:
1.824 bisitz 521: // ]]>
1.653 raeburn 522: </script>
523: ENDAUTHORBRW
524: }
525:
1.91 www 526: sub coursebrowser_javascript {
1.909 raeburn 527: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 528: my $wintitle = 'Course_Browser';
1.931 raeburn 529: if ($crstype eq 'Community') {
1.932 raeburn 530: $wintitle = 'Community_Browser';
1.909 raeburn 531: }
1.876 raeburn 532: my $id_functions = &javascript_index_functions();
533: my $output = '
1.776 bisitz 534: <script type="text/javascript" language="JavaScript">
1.824 bisitz 535: // <![CDATA[
1.468 raeburn 536: var stdeditbrowser;'."\n";
1.876 raeburn 537:
538: $output .= <<"ENDSTDBRW";
1.909 raeburn 539: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 540: var url = '/adm/pickcourse?';
1.895 raeburn 541: var formid = getFormIdByName(formname);
1.876 raeburn 542: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 543: if (domainfilter != null) {
544: if (domainfilter != '') {
545: url += 'domainfilter='+domainfilter+'&';
546: }
547: }
1.91 www 548: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 549: '&cdomelement='+udom+
550: '&cnameelement='+desc;
1.468 raeburn 551: if (extra_element !=null && extra_element != '') {
1.594 raeburn 552: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 553: url += '&roleelement='+extra_element;
554: if (domainfilter == null || domainfilter == '') {
555: url += '&domainfilter='+extra_element;
556: }
1.234 raeburn 557: }
1.468 raeburn 558: else {
559: if (formname == 'portform') {
560: url += '&setroles='+extra_element;
1.800 raeburn 561: } else {
562: if (formname == 'rules') {
563: url += '&fixeddom='+extra_element;
564: }
1.468 raeburn 565: }
566: }
1.230 raeburn 567: }
1.909 raeburn 568: if (type != null && type != '') {
569: url += '&type='+type;
570: }
571: if (type_elem != null && type_elem != '') {
572: url += '&typeelement='+type_elem;
573: }
1.872 raeburn 574: if (formname == 'ccrs') {
575: var ownername = document.forms[formid].ccuname.value;
576: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
577: url += '&cloner='+ownername+':'+ownerdom;
578: }
1.293 raeburn 579: if (multflag !=null && multflag != '') {
580: url += '&multiple='+multflag;
581: }
1.909 raeburn 582: var title = '$wintitle';
1.91 www 583: var options = 'scrollbars=1,resizable=1,menubar=0';
584: options += ',width=700,height=600';
585: stdeditbrowser = open(url,title,options,'1');
586: stdeditbrowser.focus();
587: }
1.876 raeburn 588: $id_functions
589: ENDSTDBRW
1.905 raeburn 590: if (($sec_element ne '') || ($role_element ne '')) {
591: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 592: }
593: $output .= '
594: // ]]>
595: </script>';
596: return $output;
597: }
598:
599: sub javascript_index_functions {
600: return <<"ENDJS";
601:
602: function getFormIdByName(formname) {
603: for (var i=0;i<document.forms.length;i++) {
604: if (document.forms[i].name == formname) {
605: return i;
606: }
607: }
608: return -1;
609: }
610:
611: function getIndexByName(formid,item) {
612: for (var i=0;i<document.forms[formid].elements.length;i++) {
613: if (document.forms[formid].elements[i].name == item) {
614: return i;
615: }
616: }
617: return -1;
618: }
1.468 raeburn 619:
1.876 raeburn 620: function getDomainFromSelectbox(formname,udom) {
621: var userdom;
622: var formid = getFormIdByName(formname);
623: if (formid > -1) {
624: var domid = getIndexByName(formid,udom);
625: if (domid > -1) {
626: if (document.forms[formid].elements[domid].type == 'select-one') {
627: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
628: }
629: if (document.forms[formid].elements[domid].type == 'hidden') {
630: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 631: }
632: }
633: }
1.876 raeburn 634: return userdom;
635: }
636:
637: ENDJS
1.468 raeburn 638:
1.876 raeburn 639: }
640:
1.1017 raeburn 641: sub javascript_array_indexof {
1.1018 raeburn 642: return <<ENDJS;
1.1017 raeburn 643: <script type="text/javascript" language="JavaScript">
644: // <![CDATA[
645:
646: if (!Array.prototype.indexOf) {
647: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
648: "use strict";
649: if (this === void 0 || this === null) {
650: throw new TypeError();
651: }
652: var t = Object(this);
653: var len = t.length >>> 0;
654: if (len === 0) {
655: return -1;
656: }
657: var n = 0;
658: if (arguments.length > 0) {
659: n = Number(arguments[1]);
660: if (n !== n) { // shortcut for verifying if it's NaN
661: n = 0;
662: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
663: n = (n > 0 || -1) * Math.floor(Math.abs(n));
664: }
665: }
666: if (n >= len) {
667: return -1;
668: }
669: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
670: for (; k < len; k++) {
671: if (k in t && t[k] === searchElement) {
672: return k;
673: }
674: }
675: return -1;
676: }
677: }
678:
679: // ]]>
680: </script>
681:
682: ENDJS
683:
684: }
685:
1.876 raeburn 686: sub userbrowser_javascript {
687: my $id_functions = &javascript_index_functions();
688: return <<"ENDUSERBRW";
689:
1.888 raeburn 690: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 691: var url = '/adm/pickuser?';
692: var userdom = getDomainFromSelectbox(formname,udom);
693: if (userdom != null) {
694: if (userdom != '') {
695: url += 'srchdom='+userdom+'&';
696: }
697: }
698: url += 'form=' + formname + '&unameelement='+uname+
699: '&udomelement='+udom+
700: '&ulastelement='+ulast+
701: '&ufirstelement='+ufirst+
702: '&uemailelement='+uemail+
1.881 raeburn 703: '&hideudomelement='+hideudom+
704: '&coursedom='+crsdom;
1.888 raeburn 705: if ((caller != null) && (caller != undefined)) {
706: url += '&caller='+caller;
707: }
1.876 raeburn 708: var title = 'User_Browser';
709: var options = 'scrollbars=1,resizable=1,menubar=0';
710: options += ',width=700,height=600';
711: var stdeditbrowser = open(url,title,options,'1');
712: stdeditbrowser.focus();
713: }
714:
1.888 raeburn 715: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 716: var formid = getFormIdByName(formname);
717: if (formid > -1) {
1.888 raeburn 718: var unameid = getIndexByName(formid,uname);
1.876 raeburn 719: var domid = getIndexByName(formid,udom);
720: var hidedomid = getIndexByName(formid,origdom);
721: if (hidedomid > -1) {
722: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 723: var unameval = document.forms[formid].elements[unameid].value;
724: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
725: if (domid > -1) {
726: var slct = document.forms[formid].elements[domid];
727: if (slct.type == 'select-one') {
728: var i;
729: for (i=0;i<slct.length;i++) {
730: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
731: }
732: }
733: if (slct.type == 'hidden') {
734: slct.value = fixeddom;
1.876 raeburn 735: }
736: }
1.468 raeburn 737: }
738: }
739: }
1.876 raeburn 740: return;
741: }
742:
743: $id_functions
744: ENDUSERBRW
1.468 raeburn 745: }
746:
747: sub setsec_javascript {
1.905 raeburn 748: my ($sec_element,$formname,$role_element) = @_;
749: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
750: $communityrolestr);
751: if ($role_element ne '') {
752: my @allroles = ('st','ta','ep','in','ad');
753: foreach my $crstype ('Course','Community') {
754: if ($crstype eq 'Community') {
755: foreach my $role (@allroles) {
756: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
757: }
758: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
759: } else {
760: foreach my $role (@allroles) {
761: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
762: }
763: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
764: }
765: }
766: $rolestr = '"'.join('","',@allroles).'"';
767: $courserolestr = '"'.join('","',@courserolenames).'"';
768: $communityrolestr = '"'.join('","',@communityrolenames).'"';
769: }
1.468 raeburn 770: my $setsections = qq|
771: function setSect(sectionlist) {
1.629 raeburn 772: var sectionsArray = new Array();
773: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
774: sectionsArray = sectionlist.split(",");
775: }
1.468 raeburn 776: var numSections = sectionsArray.length;
777: document.$formname.$sec_element.length = 0;
778: if (numSections == 0) {
779: document.$formname.$sec_element.multiple=false;
780: document.$formname.$sec_element.size=1;
781: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
782: } else {
783: if (numSections == 1) {
784: document.$formname.$sec_element.multiple=false;
785: document.$formname.$sec_element.size=1;
786: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
787: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
788: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
789: } else {
790: for (var i=0; i<numSections; i++) {
791: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
792: }
793: document.$formname.$sec_element.multiple=true
794: if (numSections < 3) {
795: document.$formname.$sec_element.size=numSections;
796: } else {
797: document.$formname.$sec_element.size=3;
798: }
799: document.$formname.$sec_element.options[0].selected = false
800: }
801: }
1.91 www 802: }
1.905 raeburn 803:
804: function setRole(crstype) {
1.468 raeburn 805: |;
1.905 raeburn 806: if ($role_element eq '') {
807: $setsections .= ' return;
808: }
809: ';
810: } else {
811: $setsections .= qq|
812: var elementLength = document.$formname.$role_element.length;
813: var allroles = Array($rolestr);
814: var courserolenames = Array($courserolestr);
815: var communityrolenames = Array($communityrolestr);
816: if (elementLength != undefined) {
817: if (document.$formname.$role_element.options[5].value == 'cc') {
818: if (crstype == 'Course') {
819: return;
820: } else {
821: allroles[5] = 'co';
822: for (var i=0; i<6; i++) {
823: document.$formname.$role_element.options[i].value = allroles[i];
824: document.$formname.$role_element.options[i].text = communityrolenames[i];
825: }
826: }
827: } else {
828: if (crstype == 'Community') {
829: return;
830: } else {
831: allroles[5] = 'cc';
832: for (var i=0; i<6; i++) {
833: document.$formname.$role_element.options[i].value = allroles[i];
834: document.$formname.$role_element.options[i].text = courserolenames[i];
835: }
836: }
837: }
838: }
839: return;
840: }
841: |;
842: }
1.468 raeburn 843: return $setsections;
844: }
845:
1.91 www 846: sub selectcourse_link {
1.909 raeburn 847: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
848: $typeelement) = @_;
849: my $type = $selecttype;
1.871 raeburn 850: my $linktext = &mt('Select Course');
851: if ($selecttype eq 'Community') {
1.909 raeburn 852: $linktext = &mt('Select Community');
1.906 raeburn 853: } elsif ($selecttype eq 'Course/Community') {
854: $linktext = &mt('Select Course/Community');
1.909 raeburn 855: $type = '';
1.1019 raeburn 856: } elsif ($selecttype eq 'Select') {
857: $linktext = &mt('Select');
858: $type = '';
1.871 raeburn 859: }
1.787 bisitz 860: return '<span class="LC_nobreak">'
861: ."<a href='"
862: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
863: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 864: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 865: ."'>".$linktext.'</a>'
1.787 bisitz 866: .'</span>';
1.74 www 867: }
1.42 matthew 868:
1.653 raeburn 869: sub selectauthor_link {
870: my ($form,$udom)=@_;
871: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
872: &mt('Select Author').'</a>';
873: }
874:
1.876 raeburn 875: sub selectuser_link {
1.881 raeburn 876: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 877: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 878: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 879: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 880: ');">'.$linktext.'</a>';
1.876 raeburn 881: }
882:
1.273 raeburn 883: sub check_uncheck_jscript {
884: my $jscript = <<"ENDSCRT";
885: function checkAll(field) {
886: if (field.length > 0) {
887: for (i = 0; i < field.length; i++) {
888: field[i].checked = true ;
889: }
890: } else {
891: field.checked = true
892: }
893: }
894:
895: function uncheckAll(field) {
896: if (field.length > 0) {
897: for (i = 0; i < field.length; i++) {
898: field[i].checked = false ;
1.543 albertel 899: }
900: } else {
1.273 raeburn 901: field.checked = false ;
902: }
903: }
904: ENDSCRT
905: return $jscript;
906: }
907:
1.656 www 908: sub select_timezone {
1.659 raeburn 909: my ($name,$selected,$onchange,$includeempty)=@_;
910: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
911: if ($includeempty) {
912: $output .= '<option value=""';
913: if (($selected eq '') || ($selected eq 'local')) {
914: $output .= ' selected="selected" ';
915: }
916: $output .= '> </option>';
917: }
1.657 raeburn 918: my @timezones = DateTime::TimeZone->all_names;
919: foreach my $tzone (@timezones) {
920: $output.= '<option value="'.$tzone.'"';
921: if ($tzone eq $selected) {
922: $output.=' selected="selected"';
923: }
924: $output.=">$tzone</option>\n";
1.656 www 925: }
926: $output.="</select>";
927: return $output;
928: }
1.273 raeburn 929:
1.687 raeburn 930: sub select_datelocale {
931: my ($name,$selected,$onchange,$includeempty)=@_;
932: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
933: if ($includeempty) {
934: $output .= '<option value=""';
935: if ($selected eq '') {
936: $output .= ' selected="selected" ';
937: }
938: $output .= '> </option>';
939: }
940: my (@possibles,%locale_names);
941: my @locales = DateTime::Locale::Catalog::Locales;
942: foreach my $locale (@locales) {
943: if (ref($locale) eq 'HASH') {
944: my $id = $locale->{'id'};
945: if ($id ne '') {
946: my $en_terr = $locale->{'en_territory'};
947: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 948: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 949: if (grep(/^en$/,@languages) || !@languages) {
950: if ($en_terr ne '') {
951: $locale_names{$id} = '('.$en_terr.')';
952: } elsif ($native_terr ne '') {
953: $locale_names{$id} = $native_terr;
954: }
955: } else {
956: if ($native_terr ne '') {
957: $locale_names{$id} = $native_terr.' ';
958: } elsif ($en_terr ne '') {
959: $locale_names{$id} = '('.$en_terr.')';
960: }
961: }
962: push (@possibles,$id);
963: }
964: }
965: }
966: foreach my $item (sort(@possibles)) {
967: $output.= '<option value="'.$item.'"';
968: if ($item eq $selected) {
969: $output.=' selected="selected"';
970: }
971: $output.=">$item";
972: if ($locale_names{$item} ne '') {
973: $output.=" $locale_names{$item}</option>\n";
974: }
975: $output.="</option>\n";
976: }
977: $output.="</select>";
978: return $output;
979: }
980:
1.792 raeburn 981: sub select_language {
982: my ($name,$selected,$includeempty) = @_;
983: my %langchoices;
984: if ($includeempty) {
985: %langchoices = ('' => 'No language preference');
986: }
987: foreach my $id (&languageids()) {
988: my $code = &supportedlanguagecode($id);
989: if ($code) {
990: $langchoices{$code} = &plainlanguagedescription($id);
991: }
992: }
1.970 raeburn 993: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 994: }
995:
1.42 matthew 996: =pod
1.36 matthew 997:
1.648 raeburn 998: =item * &linked_select_forms(...)
1.36 matthew 999:
1000: linked_select_forms returns a string containing a <script></script> block
1001: and html for two <select> menus. The select menus will be linked in that
1002: changing the value of the first menu will result in new values being placed
1003: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1004: order unless a defined order is provided.
1.36 matthew 1005:
1006: linked_select_forms takes the following ordered inputs:
1007:
1008: =over 4
1009:
1.112 bowersj2 1010: =item * $formname, the name of the <form> tag
1.36 matthew 1011:
1.112 bowersj2 1012: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1013:
1.112 bowersj2 1014: =item * $firstdefault, the default value for the first menu
1.36 matthew 1015:
1.112 bowersj2 1016: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1017:
1.112 bowersj2 1018: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1019:
1.112 bowersj2 1020: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1021:
1.609 raeburn 1022: =item * $menuorder, the order of values in the first menu
1023:
1.41 ng 1024: =back
1025:
1.36 matthew 1026: Below is an example of such a hash. Only the 'text', 'default', and
1027: 'select2' keys must appear as stated. keys(%menu) are the possible
1028: values for the first select menu. The text that coincides with the
1.41 ng 1029: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1030: and text for the second menu are given in the hash pointed to by
1031: $menu{$choice1}->{'select2'}.
1032:
1.112 bowersj2 1033: my %menu = ( A1 => { text =>"Choice A1" ,
1034: default => "B3",
1035: select2 => {
1036: B1 => "Choice B1",
1037: B2 => "Choice B2",
1038: B3 => "Choice B3",
1039: B4 => "Choice B4"
1.609 raeburn 1040: },
1041: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1042: },
1043: A2 => { text =>"Choice A2" ,
1044: default => "C2",
1045: select2 => {
1046: C1 => "Choice C1",
1047: C2 => "Choice C2",
1048: C3 => "Choice C3"
1.609 raeburn 1049: },
1050: order => ['C2','C1','C3'],
1.112 bowersj2 1051: },
1052: A3 => { text =>"Choice A3" ,
1053: default => "D6",
1054: select2 => {
1055: D1 => "Choice D1",
1056: D2 => "Choice D2",
1057: D3 => "Choice D3",
1058: D4 => "Choice D4",
1059: D5 => "Choice D5",
1060: D6 => "Choice D6",
1061: D7 => "Choice D7"
1.609 raeburn 1062: },
1063: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1064: }
1065: );
1.36 matthew 1066:
1067: =cut
1068:
1069: sub linked_select_forms {
1070: my ($formname,
1071: $middletext,
1072: $firstdefault,
1073: $firstselectname,
1074: $secondselectname,
1.609 raeburn 1075: $hashref,
1076: $menuorder,
1.36 matthew 1077: ) = @_;
1078: my $second = "document.$formname.$secondselectname";
1079: my $first = "document.$formname.$firstselectname";
1080: # output the javascript to do the changing
1081: my $result = '';
1.776 bisitz 1082: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1083: $result.="// <![CDATA[\n";
1.36 matthew 1084: $result.="var select2data = new Object();\n";
1085: $" = '","';
1086: my $debug = '';
1087: foreach my $s1 (sort(keys(%$hashref))) {
1088: $result.="select2data.d_$s1 = new Object();\n";
1089: $result.="select2data.d_$s1.def = new String('".
1090: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1091: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1092: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1093: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1094: @s2values = @{$hashref->{$s1}->{'order'}};
1095: }
1.36 matthew 1096: $result.="\"@s2values\");\n";
1097: $result.="select2data.d_$s1.texts = new Array(";
1098: my @s2texts;
1099: foreach my $value (@s2values) {
1100: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1101: }
1102: $result.="\"@s2texts\");\n";
1103: }
1104: $"=' ';
1105: $result.= <<"END";
1106:
1107: function select1_changed() {
1108: // Determine new choice
1109: var newvalue = "d_" + $first.value;
1110: // update select2
1111: var values = select2data[newvalue].values;
1112: var texts = select2data[newvalue].texts;
1113: var select2def = select2data[newvalue].def;
1114: var i;
1115: // out with the old
1116: for (i = 0; i < $second.options.length; i++) {
1117: $second.options[i] = null;
1118: }
1119: // in with the nuclear
1120: for (i=0;i<values.length; i++) {
1121: $second.options[i] = new Option(values[i]);
1.143 matthew 1122: $second.options[i].value = values[i];
1.36 matthew 1123: $second.options[i].text = texts[i];
1124: if (values[i] == select2def) {
1125: $second.options[i].selected = true;
1126: }
1127: }
1128: }
1.824 bisitz 1129: // ]]>
1.36 matthew 1130: </script>
1131: END
1132: # output the initial values for the selection lists
1133: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1134: my @order = sort(keys(%{$hashref}));
1135: if (ref($menuorder) eq 'ARRAY') {
1136: @order = @{$menuorder};
1137: }
1138: foreach my $value (@order) {
1.36 matthew 1139: $result.=" <option value=\"$value\" ";
1.253 albertel 1140: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1141: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1142: }
1143: $result .= "</select>\n";
1144: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1145: $result .= $middletext;
1146: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1147: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1148:
1149: my @secondorder = sort(keys(%select2));
1150: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1151: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1152: }
1153: foreach my $value (@secondorder) {
1.36 matthew 1154: $result.=" <option value=\"$value\" ";
1.253 albertel 1155: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1156: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1157: }
1158: $result .= "</select>\n";
1159: # return $debug;
1160: return $result;
1161: } # end of sub linked_select_forms {
1162:
1.45 matthew 1163: =pod
1.44 bowersj2 1164:
1.973 raeburn 1165: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1166:
1.112 bowersj2 1167: Returns a string corresponding to an HTML link to the given help
1168: $topic, where $topic corresponds to the name of a .tex file in
1169: /home/httpd/html/adm/help/tex, with underscores replaced by
1170: spaces.
1171:
1172: $text will optionally be linked to the same topic, allowing you to
1173: link text in addition to the graphic. If you do not want to link
1174: text, but wish to specify one of the later parameters, pass an
1175: empty string.
1176:
1177: $stayOnPage is a value that will be interpreted as a boolean. If true,
1178: the link will not open a new window. If false, the link will open
1179: a new window using Javascript. (Default is false.)
1180:
1181: $width and $height are optional numerical parameters that will
1182: override the width and height of the popped up window, which may
1.973 raeburn 1183: be useful for certain help topics with big pictures included.
1184:
1185: $imgid is the id of the img tag used for the help icon. This may be
1186: used in a javascript call to switch the image src. See
1187: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1188:
1189: =cut
1190:
1191: sub help_open_topic {
1.973 raeburn 1192: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1193: $text = "" if (not defined $text);
1.44 bowersj2 1194: $stayOnPage = 0 if (not defined $stayOnPage);
1195: $width = 350 if (not defined $width);
1196: $height = 400 if (not defined $height);
1197: my $filename = $topic;
1198: $filename =~ s/ /_/g;
1199:
1.48 bowersj2 1200: my $template = "";
1201: my $link;
1.572 banghart 1202:
1.159 www 1203: $topic=~s/\W/\_/g;
1.44 bowersj2 1204:
1.572 banghart 1205: if (!$stayOnPage) {
1.72 bowersj2 1206: $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 1207: } else {
1.48 bowersj2 1208: $link = "/adm/help/${filename}.hlp";
1209: }
1210:
1211: # Add the text
1.755 neumanie 1212: if ($text ne "") {
1.763 bisitz 1213: $template.='<span class="LC_help_open_topic">'
1214: .'<a target="_top" href="'.$link.'">'
1215: .$text.'</a>';
1.48 bowersj2 1216: }
1217:
1.763 bisitz 1218: # (Always) Add the graphic
1.179 matthew 1219: my $title = &mt('Online Help');
1.667 raeburn 1220: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1221: if ($imgid ne '') {
1222: $imgid = ' id="'.$imgid.'"';
1223: }
1.763 bisitz 1224: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1225: .'<img src="'.$helpicon.'" border="0"'
1226: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1227: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1228: .' /></a>';
1229: if ($text ne "") {
1230: $template.='</span>';
1231: }
1.44 bowersj2 1232: return $template;
1233:
1.106 bowersj2 1234: }
1235:
1236: # This is a quicky function for Latex cheatsheet editing, since it
1237: # appears in at least four places
1238: sub helpLatexCheatsheet {
1.732 raeburn 1239: my ($topic,$text,$not_author) = @_;
1240: my $out;
1.106 bowersj2 1241: my $addOther = '';
1.732 raeburn 1242: if ($topic) {
1.763 bisitz 1243: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1244: undef, undef, 600).
1245: '</span> ';
1246: }
1247: $out = '<span>' # Start cheatsheet
1248: .$addOther
1249: .'<span>'
1250: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1251: undef,undef,600)
1252: .'</span> <span>'
1253: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1254: undef,undef,600)
1255: .'</span>';
1.732 raeburn 1256: unless ($not_author) {
1.763 bisitz 1257: $out .= ' <span>'
1258: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1259: undef,undef,600)
1260: .'</span>';
1.732 raeburn 1261: }
1.763 bisitz 1262: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1263: return $out;
1.172 www 1264: }
1265:
1.430 albertel 1266: sub general_help {
1267: my $helptopic='Student_Intro';
1268: if ($env{'request.role'}=~/^(ca|au)/) {
1269: $helptopic='Authoring_Intro';
1.907 raeburn 1270: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1271: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1272: } elsif ($env{'request.role'}=~/^dc/) {
1273: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1274: }
1275: return $helptopic;
1276: }
1277:
1278: sub update_help_link {
1279: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1280: my $origurl = $ENV{'REQUEST_URI'};
1281: $origurl=~s|^/~|/priv/|;
1282: my $timestamp = time;
1283: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1284: $$datum = &escape($$datum);
1285: }
1286:
1287: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1288: my $output .= <<"ENDOUTPUT";
1289: <script type="text/javascript">
1.824 bisitz 1290: // <![CDATA[
1.430 albertel 1291: banner_link = '$banner_link';
1.824 bisitz 1292: // ]]>
1.430 albertel 1293: </script>
1294: ENDOUTPUT
1295: return $output;
1296: }
1297:
1298: # now just updates the help link and generates a blue icon
1.193 raeburn 1299: sub help_open_menu {
1.430 albertel 1300: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1301: = @_;
1.949 droeschl 1302: $stayOnPage = 1;
1.430 albertel 1303: my $output;
1304: if ($component_help) {
1305: if (!$text) {
1306: $output=&help_open_topic($component_help,undef,$stayOnPage,
1307: $width,$height);
1308: } else {
1309: my $help_text;
1310: $help_text=&unescape($topic);
1311: $output='<table><tr><td>'.
1312: &help_open_topic($component_help,$help_text,$stayOnPage,
1313: $width,$height).'</td></tr></table>';
1314: }
1315: }
1316: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1317: return $output.$banner_link;
1318: }
1319:
1320: sub top_nav_help {
1321: my ($text) = @_;
1.436 albertel 1322: $text = &mt($text);
1.949 droeschl 1323: my $stay_on_page = 1;
1324:
1.572 banghart 1325: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1326: : "javascript:helpMenu('open')";
1.572 banghart 1327: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1328:
1.201 raeburn 1329: my $title = &mt('Get help');
1.436 albertel 1330:
1331: return <<"END";
1332: $banner_link
1333: <a href="$link" title="$title">$text</a>
1334: END
1335: }
1336:
1337: sub help_menu_js {
1338: my ($text) = @_;
1.949 droeschl 1339: my $stayOnPage = 1;
1.436 albertel 1340: my $width = 620;
1341: my $height = 600;
1.430 albertel 1342: my $helptopic=&general_help();
1343: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1344: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1345: my $start_page =
1346: &Apache::loncommon::start_page('Help Menu', undef,
1347: {'frameset' => 1,
1348: 'js_ready' => 1,
1349: 'add_entries' => {
1350: 'border' => '0',
1.579 raeburn 1351: 'rows' => "110,*",},});
1.331 albertel 1352: my $end_page =
1353: &Apache::loncommon::end_page({'frameset' => 1,
1354: 'js_ready' => 1,});
1355:
1.436 albertel 1356: my $template .= <<"ENDTEMPLATE";
1357: <script type="text/javascript">
1.877 bisitz 1358: // <![CDATA[
1.253 albertel 1359: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1360: var banner_link = '';
1.243 raeburn 1361: function helpMenu(target) {
1362: var caller = this;
1363: if (target == 'open') {
1364: var newWindow = null;
1365: try {
1.262 albertel 1366: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1367: }
1368: catch(error) {
1369: writeHelp(caller);
1370: return;
1371: }
1372: if (newWindow) {
1373: caller = newWindow;
1374: }
1.193 raeburn 1375: }
1.243 raeburn 1376: writeHelp(caller);
1377: return;
1378: }
1379: function writeHelp(caller) {
1.430 albertel 1380: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1381: caller.document.close()
1382: caller.focus()
1.193 raeburn 1383: }
1.877 bisitz 1384: // END LON-CAPA Internal -->
1.253 albertel 1385: // ]]>
1.436 albertel 1386: </script>
1.193 raeburn 1387: ENDTEMPLATE
1388: return $template;
1389: }
1390:
1.172 www 1391: sub help_open_bug {
1392: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1393: unless ($env{'user.adv'}) { return ''; }
1.172 www 1394: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1395: $text = "" if (not defined $text);
1396: $stayOnPage=1;
1.184 albertel 1397: $width = 600 if (not defined $width);
1398: $height = 600 if (not defined $height);
1.172 www 1399:
1400: $topic=~s/\W+/\+/g;
1401: my $link='';
1402: my $template='';
1.379 albertel 1403: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1404: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1405: if (!$stayOnPage)
1406: {
1407: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1408: }
1409: else
1410: {
1411: $link = $url;
1412: }
1413: # Add the text
1414: if ($text ne "")
1415: {
1416: $template .=
1417: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1418: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1419: }
1420:
1421: # Add the graphic
1.179 matthew 1422: my $title = &mt('Report a Bug');
1.215 albertel 1423: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1424: $template .= <<"ENDTEMPLATE";
1.436 albertel 1425: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1426: ENDTEMPLATE
1427: if ($text ne '') { $template.='</td></tr></table>' };
1428: return $template;
1429:
1430: }
1431:
1432: sub help_open_faq {
1433: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1434: unless ($env{'user.adv'}) { return ''; }
1.172 www 1435: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1436: $text = "" if (not defined $text);
1437: $stayOnPage=1;
1438: $width = 350 if (not defined $width);
1439: $height = 400 if (not defined $height);
1440:
1441: $topic=~s/\W+/\+/g;
1442: my $link='';
1443: my $template='';
1444: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1445: if (!$stayOnPage)
1446: {
1447: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1448: }
1449: else
1450: {
1451: $link = $url;
1452: }
1453:
1454: # Add the text
1455: if ($text ne "")
1456: {
1457: $template .=
1.173 www 1458: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1459: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1460: }
1461:
1462: # Add the graphic
1.179 matthew 1463: my $title = &mt('View the FAQ');
1.215 albertel 1464: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1465: $template .= <<"ENDTEMPLATE";
1.436 albertel 1466: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1467: ENDTEMPLATE
1468: if ($text ne '') { $template.='</td></tr></table>' };
1469: return $template;
1470:
1.44 bowersj2 1471: }
1.37 matthew 1472:
1.180 matthew 1473: ###############################################################
1474: ###############################################################
1475:
1.45 matthew 1476: =pod
1477:
1.648 raeburn 1478: =item * &change_content_javascript():
1.256 matthew 1479:
1480: This and the next function allow you to create small sections of an
1481: otherwise static HTML page that you can update on the fly with
1482: Javascript, even in Netscape 4.
1483:
1484: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1485: must be written to the HTML page once. It will prove the Javascript
1486: function "change(name, content)". Calling the change function with the
1487: name of the section
1488: you want to update, matching the name passed to C<changable_area>, and
1489: the new content you want to put in there, will put the content into
1490: that area.
1491:
1492: B<Note>: Netscape 4 only reserves enough space for the changable area
1493: to contain room for the original contents. You need to "make space"
1494: for whatever changes you wish to make, and be B<sure> to check your
1495: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1496: it's adequate for updating a one-line status display, but little more.
1497: This script will set the space to 100% width, so you only need to
1498: worry about height in Netscape 4.
1499:
1500: Modern browsers are much less limiting, and if you can commit to the
1501: user not using Netscape 4, this feature may be used freely with
1502: pretty much any HTML.
1503:
1504: =cut
1505:
1506: sub change_content_javascript {
1507: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1508: if ($env{'browser.type'} eq 'netscape' &&
1509: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1510: return (<<NETSCAPE4);
1511: function change(name, content) {
1512: doc = document.layers[name+"___escape"].layers[0].document;
1513: doc.open();
1514: doc.write(content);
1515: doc.close();
1516: }
1517: NETSCAPE4
1518: } else {
1519: # Otherwise, we need to use semi-standards-compliant code
1520: # (technically, "innerHTML" isn't standard but the equivalent
1521: # is really scary, and every useful browser supports it
1522: return (<<DOMBASED);
1523: function change(name, content) {
1524: element = document.getElementById(name);
1525: element.innerHTML = content;
1526: }
1527: DOMBASED
1528: }
1529: }
1530:
1531: =pod
1532:
1.648 raeburn 1533: =item * &changable_area($name,$origContent):
1.256 matthew 1534:
1535: This provides a "changable area" that can be modified on the fly via
1536: the Javascript code provided in C<change_content_javascript>. $name is
1537: the name you will use to reference the area later; do not repeat the
1538: same name on a given HTML page more then once. $origContent is what
1539: the area will originally contain, which can be left blank.
1540:
1541: =cut
1542:
1543: sub changable_area {
1544: my ($name, $origContent) = @_;
1545:
1.258 albertel 1546: if ($env{'browser.type'} eq 'netscape' &&
1547: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1548: # If this is netscape 4, we need to use the Layer tag
1549: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1550: } else {
1551: return "<span id='$name'>$origContent</span>";
1552: }
1553: }
1554:
1555: =pod
1556:
1.648 raeburn 1557: =item * &viewport_geometry_js
1.590 raeburn 1558:
1559: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1560:
1561: =cut
1562:
1563:
1564: sub viewport_geometry_js {
1565: return <<"GEOMETRY";
1566: var Geometry = {};
1567: function init_geometry() {
1568: if (Geometry.init) { return };
1569: Geometry.init=1;
1570: if (window.innerHeight) {
1571: Geometry.getViewportHeight = function() { return window.innerHeight; };
1572: Geometry.getViewportWidth = function() { return window.innerWidth; };
1573: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1574: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1575: }
1576: else if (document.documentElement && document.documentElement.clientHeight) {
1577: Geometry.getViewportHeight =
1578: function() { return document.documentElement.clientHeight; };
1579: Geometry.getViewportWidth =
1580: function() { return document.documentElement.clientWidth; };
1581:
1582: Geometry.getHorizontalScroll =
1583: function() { return document.documentElement.scrollLeft; };
1584: Geometry.getVerticalScroll =
1585: function() { return document.documentElement.scrollTop; };
1586: }
1587: else if (document.body.clientHeight) {
1588: Geometry.getViewportHeight =
1589: function() { return document.body.clientHeight; };
1590: Geometry.getViewportWidth =
1591: function() { return document.body.clientWidth; };
1592: Geometry.getHorizontalScroll =
1593: function() { return document.body.scrollLeft; };
1594: Geometry.getVerticalScroll =
1595: function() { return document.body.scrollTop; };
1596: }
1597: }
1598:
1599: GEOMETRY
1600: }
1601:
1602: =pod
1603:
1.648 raeburn 1604: =item * &viewport_size_js()
1.590 raeburn 1605:
1606: 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.
1607:
1608: =cut
1609:
1610: sub viewport_size_js {
1611: my $geometry = &viewport_geometry_js();
1612: return <<"DIMS";
1613:
1614: $geometry
1615:
1616: function getViewportDims(width,height) {
1617: init_geometry();
1618: width.value = Geometry.getViewportWidth();
1619: height.value = Geometry.getViewportHeight();
1620: return;
1621: }
1622:
1623: DIMS
1624: }
1625:
1626: =pod
1627:
1.648 raeburn 1628: =item * &resize_textarea_js()
1.565 albertel 1629:
1630: emits the needed javascript to resize a textarea to be as big as possible
1631:
1632: creates a function resize_textrea that takes two IDs first should be
1633: the id of the element to resize, second should be the id of a div that
1634: surrounds everything that comes after the textarea, this routine needs
1635: to be attached to the <body> for the onload and onresize events.
1636:
1.648 raeburn 1637: =back
1.565 albertel 1638:
1639: =cut
1640:
1641: sub resize_textarea_js {
1.590 raeburn 1642: my $geometry = &viewport_geometry_js();
1.565 albertel 1643: return <<"RESIZE";
1644: <script type="text/javascript">
1.824 bisitz 1645: // <![CDATA[
1.590 raeburn 1646: $geometry
1.565 albertel 1647:
1.588 albertel 1648: function getX(element) {
1649: var x = 0;
1650: while (element) {
1651: x += element.offsetLeft;
1652: element = element.offsetParent;
1653: }
1654: return x;
1655: }
1656: function getY(element) {
1657: var y = 0;
1658: while (element) {
1659: y += element.offsetTop;
1660: element = element.offsetParent;
1661: }
1662: return y;
1663: }
1664:
1665:
1.565 albertel 1666: function resize_textarea(textarea_id,bottom_id) {
1667: init_geometry();
1668: var textarea = document.getElementById(textarea_id);
1669: //alert(textarea);
1670:
1.588 albertel 1671: var textarea_top = getY(textarea);
1.565 albertel 1672: var textarea_height = textarea.offsetHeight;
1673: var bottom = document.getElementById(bottom_id);
1.588 albertel 1674: var bottom_top = getY(bottom);
1.565 albertel 1675: var bottom_height = bottom.offsetHeight;
1676: var window_height = Geometry.getViewportHeight();
1.588 albertel 1677: var fudge = 23;
1.565 albertel 1678: var new_height = window_height-fudge-textarea_top-bottom_height;
1679: if (new_height < 300) {
1680: new_height = 300;
1681: }
1682: textarea.style.height=new_height+'px';
1683: }
1.824 bisitz 1684: // ]]>
1.565 albertel 1685: </script>
1686: RESIZE
1687:
1688: }
1689:
1690: =pod
1691:
1.256 matthew 1692: =head1 Excel and CSV file utility routines
1693:
1694: =over 4
1695:
1696: =cut
1697:
1698: ###############################################################
1699: ###############################################################
1700:
1701: =pod
1702:
1.648 raeburn 1703: =item * &csv_translate($text)
1.37 matthew 1704:
1.185 www 1705: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1706: format.
1707:
1708: =cut
1709:
1.180 matthew 1710: ###############################################################
1711: ###############################################################
1.37 matthew 1712: sub csv_translate {
1713: my $text = shift;
1714: $text =~ s/\"/\"\"/g;
1.209 albertel 1715: $text =~ s/\n/ /g;
1.37 matthew 1716: return $text;
1717: }
1.180 matthew 1718:
1719: ###############################################################
1720: ###############################################################
1721:
1722: =pod
1723:
1.648 raeburn 1724: =item * &define_excel_formats()
1.180 matthew 1725:
1726: Define some commonly used Excel cell formats.
1727:
1728: Currently supported formats:
1729:
1730: =over 4
1731:
1732: =item header
1733:
1734: =item bold
1735:
1736: =item h1
1737:
1738: =item h2
1739:
1740: =item h3
1741:
1.256 matthew 1742: =item h4
1743:
1744: =item i
1745:
1.180 matthew 1746: =item date
1747:
1748: =back
1749:
1750: Inputs: $workbook
1751:
1752: Returns: $format, a hash reference.
1753:
1754: =cut
1755:
1756: ###############################################################
1757: ###############################################################
1758: sub define_excel_formats {
1759: my ($workbook) = @_;
1760: my $format;
1761: $format->{'header'} = $workbook->add_format(bold => 1,
1762: bottom => 1,
1763: align => 'center');
1764: $format->{'bold'} = $workbook->add_format(bold=>1);
1765: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1766: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1767: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1768: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1769: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1770: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1771: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1772: return $format;
1773: }
1774:
1775: ###############################################################
1776: ###############################################################
1.113 bowersj2 1777:
1778: =pod
1779:
1.648 raeburn 1780: =item * &create_workbook()
1.255 matthew 1781:
1782: Create an Excel worksheet. If it fails, output message on the
1783: request object and return undefs.
1784:
1785: Inputs: Apache request object
1786:
1787: Returns (undef) on failure,
1788: Excel worksheet object, scalar with filename, and formats
1789: from &Apache::loncommon::define_excel_formats on success
1790:
1791: =cut
1792:
1793: ###############################################################
1794: ###############################################################
1795: sub create_workbook {
1796: my ($r) = @_;
1797: #
1798: # Create the excel spreadsheet
1799: my $filename = '/prtspool/'.
1.258 albertel 1800: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1801: time.'_'.rand(1000000000).'.xls';
1802: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1803: if (! defined($workbook)) {
1804: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1805: $r->print(
1806: '<p class="LC_error">'
1807: .&mt('Problems occurred in creating the new Excel file.')
1808: .' '.&mt('This error has been logged.')
1809: .' '.&mt('Please alert your LON-CAPA administrator.')
1810: .'</p>'
1811: );
1.255 matthew 1812: return (undef);
1813: }
1814: #
1.1014 foxr 1815: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1816: #
1817: my $format = &Apache::loncommon::define_excel_formats($workbook);
1818: return ($workbook,$filename,$format);
1819: }
1820:
1821: ###############################################################
1822: ###############################################################
1823:
1824: =pod
1825:
1.648 raeburn 1826: =item * &create_text_file()
1.113 bowersj2 1827:
1.542 raeburn 1828: Create a file to write to and eventually make available to the user.
1.256 matthew 1829: If file creation fails, outputs an error message on the request object and
1830: return undefs.
1.113 bowersj2 1831:
1.256 matthew 1832: Inputs: Apache request object, and file suffix
1.113 bowersj2 1833:
1.256 matthew 1834: Returns (undef) on failure,
1835: Filehandle and filename on success.
1.113 bowersj2 1836:
1837: =cut
1838:
1.256 matthew 1839: ###############################################################
1840: ###############################################################
1841: sub create_text_file {
1842: my ($r,$suffix) = @_;
1843: if (! defined($suffix)) { $suffix = 'txt'; };
1844: my $fh;
1845: my $filename = '/prtspool/'.
1.258 albertel 1846: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1847: time.'_'.rand(1000000000).'.'.$suffix;
1848: $fh = Apache::File->new('>/home/httpd'.$filename);
1849: if (! defined($fh)) {
1850: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1851: $r->print(
1852: '<p class="LC_error">'
1853: .&mt('Problems occurred in creating the output file.')
1854: .' '.&mt('This error has been logged.')
1855: .' '.&mt('Please alert your LON-CAPA administrator.')
1856: .'</p>'
1857: );
1.113 bowersj2 1858: }
1.256 matthew 1859: return ($fh,$filename)
1.113 bowersj2 1860: }
1861:
1862:
1.256 matthew 1863: =pod
1.113 bowersj2 1864:
1865: =back
1866:
1867: =cut
1.37 matthew 1868:
1869: ###############################################################
1.33 matthew 1870: ## Home server <option> list generating code ##
1871: ###############################################################
1.35 matthew 1872:
1.169 www 1873: # ------------------------------------------
1874:
1875: sub domain_select {
1876: my ($name,$value,$multiple)=@_;
1877: my %domains=map {
1.514 albertel 1878: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1879: } &Apache::lonnet::all_domains();
1.169 www 1880: if ($multiple) {
1881: $domains{''}=&mt('Any domain');
1.550 albertel 1882: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1883: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1884: } else {
1.550 albertel 1885: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1886: return &select_form($name,$value,\%domains);
1.169 www 1887: }
1888: }
1889:
1.282 albertel 1890: #-------------------------------------------
1891:
1892: =pod
1893:
1.519 raeburn 1894: =head1 Routines for form select boxes
1895:
1896: =over 4
1897:
1.648 raeburn 1898: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1899:
1900: Returns a string containing a <select> element int multiple mode
1901:
1902:
1903: Args:
1904: $name - name of the <select> element
1.506 raeburn 1905: $value - scalar or array ref of values that should already be selected
1.282 albertel 1906: $size - number of rows long the select element is
1.283 albertel 1907: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1908: (shown text should already have been &mt())
1.506 raeburn 1909: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1910:
1.282 albertel 1911: =cut
1912:
1913: #-------------------------------------------
1.169 www 1914: sub multiple_select_form {
1.284 albertel 1915: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1916: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1917: my $output='';
1.191 matthew 1918: if (! defined($size)) {
1919: $size = 4;
1.283 albertel 1920: if (scalar(keys(%$hash))<4) {
1921: $size = scalar(keys(%$hash));
1.191 matthew 1922: }
1923: }
1.734 bisitz 1924: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1925: my @order;
1.506 raeburn 1926: if (ref($order) eq 'ARRAY') {
1927: @order = @{$order};
1928: } else {
1929: @order = sort(keys(%$hash));
1.501 banghart 1930: }
1931: if (exists($$hash{'select_form_order'})) {
1932: @order = @{$$hash{'select_form_order'}};
1933: }
1934:
1.284 albertel 1935: foreach my $key (@order) {
1.356 albertel 1936: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1937: $output.='selected="selected" ' if ($selected{$key});
1938: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1939: }
1940: $output.="</select>\n";
1941: return $output;
1942: }
1943:
1.88 www 1944: #-------------------------------------------
1945:
1946: =pod
1947:
1.970 raeburn 1948: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1949:
1950: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1951: allow a user to select options from a ref to a hash containing:
1952: option_name => displayed text. An optional $onchange can include
1953: a javascript onchange item, e.g., onchange="this.form.submit();"
1954:
1.88 www 1955: See lonrights.pm for an example invocation and use.
1956:
1957: =cut
1958:
1959: #-------------------------------------------
1960: sub select_form {
1.970 raeburn 1961: my ($def,$name,$hashref,$onchange) = @_;
1962: return unless (ref($hashref) eq 'HASH');
1963: if ($onchange) {
1964: $onchange = ' onchange="'.$onchange.'"';
1965: }
1966: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1967: my @keys;
1.970 raeburn 1968: if (exists($hashref->{'select_form_order'})) {
1969: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1970: } else {
1.970 raeburn 1971: @keys=sort(keys(%{$hashref}));
1.128 albertel 1972: }
1.356 albertel 1973: foreach my $key (@keys) {
1974: $selectform.=
1975: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1976: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 1977: ">".$hashref->{$key}."</option>\n";
1.88 www 1978: }
1979: $selectform.="</select>";
1980: return $selectform;
1981: }
1982:
1.475 www 1983: # For display filters
1984:
1985: sub display_filter {
1986: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1987: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1988: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1989: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1990: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1991: '</label></span> <span class="LC_nobreak">'.
1.475 www 1992: &mt('Filter [_1]',
1.477 www 1993: &select_form($env{'form.displayfilter'},
1994: 'displayfilter',
1.970 raeburn 1995: {'currentfolder' => 'Current folder/page',
1.477 www 1996: 'containing' => 'Containing phrase',
1.970 raeburn 1997: 'none' => 'None'})).
1.714 bisitz 1998: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1999: }
2000:
1.167 www 2001: sub gradeleveldescription {
2002: my $gradelevel=shift;
2003: my %gradelevels=(0 => 'Not specified',
2004: 1 => 'Grade 1',
2005: 2 => 'Grade 2',
2006: 3 => 'Grade 3',
2007: 4 => 'Grade 4',
2008: 5 => 'Grade 5',
2009: 6 => 'Grade 6',
2010: 7 => 'Grade 7',
2011: 8 => 'Grade 8',
2012: 9 => 'Grade 9',
2013: 10 => 'Grade 10',
2014: 11 => 'Grade 11',
2015: 12 => 'Grade 12',
2016: 13 => 'Grade 13',
2017: 14 => '100 Level',
2018: 15 => '200 Level',
2019: 16 => '300 Level',
2020: 17 => '400 Level',
2021: 18 => 'Graduate Level');
2022: return &mt($gradelevels{$gradelevel});
2023: }
2024:
1.163 www 2025: sub select_level_form {
2026: my ($deflevel,$name)=@_;
2027: unless ($deflevel) { $deflevel=0; }
1.167 www 2028: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2029: for (my $i=0; $i<=18; $i++) {
2030: $selectform.="<option value=\"$i\" ".
1.253 albertel 2031: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2032: ">".&gradeleveldescription($i)."</option>\n";
2033: }
2034: $selectform.="</select>";
2035: return $selectform;
1.163 www 2036: }
1.167 www 2037:
1.35 matthew 2038: #-------------------------------------------
2039:
1.45 matthew 2040: =pod
2041:
1.910 raeburn 2042: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2043:
2044: Returns a string containing a <select name='$name' size='1'> form to
2045: allow a user to select the domain to preform an operation in.
2046: See loncreateuser.pm for an example invocation and use.
2047:
1.90 www 2048: If the $includeempty flag is set, it also includes an empty choice ("no domain
2049: selected");
2050:
1.743 raeburn 2051: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2052:
1.910 raeburn 2053: 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.
2054:
2055: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2056:
1.35 matthew 2057: =cut
2058:
2059: #-------------------------------------------
1.34 matthew 2060: sub select_dom_form {
1.910 raeburn 2061: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2062: if ($onchange) {
1.874 raeburn 2063: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2064: }
1.910 raeburn 2065: my @domains;
2066: if (ref($incdoms) eq 'ARRAY') {
2067: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2068: } else {
2069: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2070: }
1.90 www 2071: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2072: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2073: foreach my $dom (@domains) {
2074: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2075: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2076: if ($showdomdesc) {
2077: if ($dom ne '') {
2078: my $domdesc = &Apache::lonnet::domain($dom,'description');
2079: if ($domdesc ne '') {
2080: $selectdomain .= ' ('.$domdesc.')';
2081: }
2082: }
2083: }
2084: $selectdomain .= "</option>\n";
1.34 matthew 2085: }
2086: $selectdomain.="</select>";
2087: return $selectdomain;
2088: }
2089:
1.35 matthew 2090: #-------------------------------------------
2091:
1.45 matthew 2092: =pod
2093:
1.648 raeburn 2094: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2095:
1.586 raeburn 2096: input: 4 arguments (two required, two optional) -
2097: $domain - domain of new user
2098: $name - name of form element
2099: $default - Value of 'default' causes a default item to be first
2100: option, and selected by default.
2101: $hide - Value of 'hide' causes hiding of the name of the server,
2102: if 1 server found, or default, if 0 found.
1.594 raeburn 2103: output: returns 2 items:
1.586 raeburn 2104: (a) form element which contains either:
2105: (i) <select name="$name">
2106: <option value="$hostid1">$hostid $servers{$hostid}</option>
2107: <option value="$hostid2">$hostid $servers{$hostid}</option>
2108: </select>
2109: form item if there are multiple library servers in $domain, or
2110: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2111: if there is only one library server in $domain.
2112:
2113: (b) number of library servers found.
2114:
2115: See loncreateuser.pm for example of use.
1.35 matthew 2116:
2117: =cut
2118:
2119: #-------------------------------------------
1.586 raeburn 2120: sub home_server_form_item {
2121: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2122: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2123: my $result;
2124: my $numlib = keys(%servers);
2125: if ($numlib > 1) {
2126: $result .= '<select name="'.$name.'" />'."\n";
2127: if ($default) {
1.804 bisitz 2128: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2129: '</option>'."\n";
2130: }
2131: foreach my $hostid (sort(keys(%servers))) {
2132: $result.= '<option value="'.$hostid.'">'.
2133: $hostid.' '.$servers{$hostid}."</option>\n";
2134: }
2135: $result .= '</select>'."\n";
2136: } elsif ($numlib == 1) {
2137: my $hostid;
2138: foreach my $item (keys(%servers)) {
2139: $hostid = $item;
2140: }
2141: $result .= '<input type="hidden" name="'.$name.'" value="'.
2142: $hostid.'" />';
2143: if (!$hide) {
2144: $result .= $hostid.' '.$servers{$hostid};
2145: }
2146: $result .= "\n";
2147: } elsif ($default) {
2148: $result .= '<input type="hidden" name="'.$name.
2149: '" value="default" />';
2150: if (!$hide) {
2151: $result .= &mt('default');
2152: }
2153: $result .= "\n";
1.33 matthew 2154: }
1.586 raeburn 2155: return ($result,$numlib);
1.33 matthew 2156: }
1.112 bowersj2 2157:
2158: =pod
2159:
1.534 albertel 2160: =back
2161:
1.112 bowersj2 2162: =cut
1.87 matthew 2163:
2164: ###############################################################
1.112 bowersj2 2165: ## Decoding User Agent ##
1.87 matthew 2166: ###############################################################
2167:
2168: =pod
2169:
1.112 bowersj2 2170: =head1 Decoding the User Agent
2171:
2172: =over 4
2173:
2174: =item * &decode_user_agent()
1.87 matthew 2175:
2176: Inputs: $r
2177:
2178: Outputs:
2179:
2180: =over 4
2181:
1.112 bowersj2 2182: =item * $httpbrowser
1.87 matthew 2183:
1.112 bowersj2 2184: =item * $clientbrowser
1.87 matthew 2185:
1.112 bowersj2 2186: =item * $clientversion
1.87 matthew 2187:
1.112 bowersj2 2188: =item * $clientmathml
1.87 matthew 2189:
1.112 bowersj2 2190: =item * $clientunicode
1.87 matthew 2191:
1.112 bowersj2 2192: =item * $clientos
1.87 matthew 2193:
2194: =back
2195:
1.157 matthew 2196: =back
2197:
1.87 matthew 2198: =cut
2199:
2200: ###############################################################
2201: ###############################################################
2202: sub decode_user_agent {
1.247 albertel 2203: my ($r)=@_;
1.87 matthew 2204: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2205: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2206: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2207: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2208: my $clientbrowser='unknown';
2209: my $clientversion='0';
2210: my $clientmathml='';
2211: my $clientunicode='0';
2212: for (my $i=0;$i<=$#browsertype;$i++) {
2213: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2214: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2215: $clientbrowser=$bname;
2216: $httpbrowser=~/$vreg/i;
2217: $clientversion=$1;
2218: $clientmathml=($clientversion>=$minv);
2219: $clientunicode=($clientversion>=$univ);
2220: }
2221: }
2222: my $clientos='unknown';
2223: if (($httpbrowser=~/linux/i) ||
2224: ($httpbrowser=~/unix/i) ||
2225: ($httpbrowser=~/ux/i) ||
2226: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2227: if (($httpbrowser=~/vax/i) ||
2228: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2229: if ($httpbrowser=~/next/i) { $clientos='next'; }
2230: if (($httpbrowser=~/mac/i) ||
2231: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2232: if ($httpbrowser=~/win/i) { $clientos='win'; }
2233: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2234: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2235: $clientunicode,$clientos,);
2236: }
2237:
1.32 matthew 2238: ###############################################################
2239: ## Authentication changing form generation subroutines ##
2240: ###############################################################
2241: ##
2242: ## All of the authform_xxxxxxx subroutines take their inputs in a
2243: ## hash, and have reasonable default values.
2244: ##
2245: ## formname = the name given in the <form> tag.
1.35 matthew 2246: #-------------------------------------------
2247:
1.45 matthew 2248: =pod
2249:
1.112 bowersj2 2250: =head1 Authentication Routines
2251:
2252: =over 4
2253:
1.648 raeburn 2254: =item * &authform_xxxxxx()
1.35 matthew 2255:
2256: The authform_xxxxxx subroutines provide javascript and html forms which
2257: handle some of the conveniences required for authentication forms.
2258: This is not an optimal method, but it works.
2259:
2260: =over 4
2261:
1.112 bowersj2 2262: =item * authform_header
1.35 matthew 2263:
1.112 bowersj2 2264: =item * authform_authorwarning
1.35 matthew 2265:
1.112 bowersj2 2266: =item * authform_nochange
1.35 matthew 2267:
1.112 bowersj2 2268: =item * authform_kerberos
1.35 matthew 2269:
1.112 bowersj2 2270: =item * authform_internal
1.35 matthew 2271:
1.112 bowersj2 2272: =item * authform_filesystem
1.35 matthew 2273:
2274: =back
2275:
1.648 raeburn 2276: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2277:
1.35 matthew 2278: =cut
2279:
2280: #-------------------------------------------
1.32 matthew 2281: sub authform_header{
2282: my %in = (
2283: formname => 'cu',
1.80 albertel 2284: kerb_def_dom => '',
1.32 matthew 2285: @_,
2286: );
2287: $in{'formname'} = 'document.' . $in{'formname'};
2288: my $result='';
1.80 albertel 2289:
2290: #---------------------------------------------- Code for upper case translation
2291: my $Javascript_toUpperCase;
2292: unless ($in{kerb_def_dom}) {
2293: $Javascript_toUpperCase =<<"END";
2294: switch (choice) {
2295: case 'krb': currentform.elements[choicearg].value =
2296: currentform.elements[choicearg].value.toUpperCase();
2297: break;
2298: default:
2299: }
2300: END
2301: } else {
2302: $Javascript_toUpperCase = "";
2303: }
2304:
1.165 raeburn 2305: my $radioval = "'nochange'";
1.591 raeburn 2306: if (defined($in{'curr_authtype'})) {
2307: if ($in{'curr_authtype'} ne '') {
2308: $radioval = "'".$in{'curr_authtype'}."arg'";
2309: }
1.174 matthew 2310: }
1.165 raeburn 2311: my $argfield = 'null';
1.591 raeburn 2312: if (defined($in{'mode'})) {
1.165 raeburn 2313: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2314: if (defined($in{'curr_autharg'})) {
2315: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2316: $argfield = "'$in{'curr_autharg'}'";
2317: }
2318: }
2319: }
2320: }
2321:
1.32 matthew 2322: $result.=<<"END";
2323: var current = new Object();
1.165 raeburn 2324: current.radiovalue = $radioval;
2325: current.argfield = $argfield;
1.32 matthew 2326:
2327: function changed_radio(choice,currentform) {
2328: var choicearg = choice + 'arg';
2329: // If a radio button in changed, we need to change the argfield
2330: if (current.radiovalue != choice) {
2331: current.radiovalue = choice;
2332: if (current.argfield != null) {
2333: currentform.elements[current.argfield].value = '';
2334: }
2335: if (choice == 'nochange') {
2336: current.argfield = null;
2337: } else {
2338: current.argfield = choicearg;
2339: switch(choice) {
2340: case 'krb':
2341: currentform.elements[current.argfield].value =
2342: "$in{'kerb_def_dom'}";
2343: break;
2344: default:
2345: break;
2346: }
2347: }
2348: }
2349: return;
2350: }
1.22 www 2351:
1.32 matthew 2352: function changed_text(choice,currentform) {
2353: var choicearg = choice + 'arg';
2354: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2355: $Javascript_toUpperCase
1.32 matthew 2356: // clear old field
2357: if ((current.argfield != choicearg) && (current.argfield != null)) {
2358: currentform.elements[current.argfield].value = '';
2359: }
2360: current.argfield = choicearg;
2361: }
2362: set_auth_radio_buttons(choice,currentform);
2363: return;
1.20 www 2364: }
1.32 matthew 2365:
2366: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2367: var numauthchoices = currentform.login.length;
2368: if (typeof numauthchoices == "undefined") {
2369: return;
2370: }
1.32 matthew 2371: var i=0;
1.986 raeburn 2372: while (i < numauthchoices) {
1.32 matthew 2373: if (currentform.login[i].value == newvalue) { break; }
2374: i++;
2375: }
1.986 raeburn 2376: if (i == numauthchoices) {
1.32 matthew 2377: return;
2378: }
2379: current.radiovalue = newvalue;
2380: currentform.login[i].checked = true;
2381: return;
2382: }
2383: END
2384: return $result;
2385: }
2386:
2387: sub authform_authorwarning{
2388: my $result='';
1.144 matthew 2389: $result='<i>'.
2390: &mt('As a general rule, only authors or co-authors should be '.
2391: 'filesystem authenticated '.
2392: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2393: return $result;
2394: }
2395:
2396: sub authform_nochange{
2397: my %in = (
2398: formname => 'document.cu',
2399: kerb_def_dom => 'MSU.EDU',
2400: @_,
2401: );
1.586 raeburn 2402: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2403: my $result;
2404: if (keys(%can_assign) == 0) {
2405: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2406: } else {
2407: $result = '<label>'.&mt('[_1] Do not change login data',
2408: '<input type="radio" name="login" value="nochange" '.
2409: 'checked="checked" onclick="'.
1.281 albertel 2410: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2411: '</label>';
1.586 raeburn 2412: }
1.32 matthew 2413: return $result;
2414: }
2415:
1.591 raeburn 2416: sub authform_kerberos {
1.32 matthew 2417: my %in = (
2418: formname => 'document.cu',
2419: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2420: kerb_def_auth => 'krb4',
1.32 matthew 2421: @_,
2422: );
1.586 raeburn 2423: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2424: $autharg,$jscall);
2425: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2426: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2427: $check5 = ' checked="checked"';
1.80 albertel 2428: } else {
1.772 bisitz 2429: $check4 = ' checked="checked"';
1.80 albertel 2430: }
1.165 raeburn 2431: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2432: if (defined($in{'curr_authtype'})) {
2433: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2434: $krbcheck = ' checked="checked"';
1.623 raeburn 2435: if (defined($in{'mode'})) {
2436: if ($in{'mode'} eq 'modifyuser') {
2437: $krbcheck = '';
2438: }
2439: }
1.591 raeburn 2440: if (defined($in{'curr_kerb_ver'})) {
2441: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2442: $check5 = ' checked="checked"';
1.591 raeburn 2443: $check4 = '';
2444: } else {
1.772 bisitz 2445: $check4 = ' checked="checked"';
1.591 raeburn 2446: $check5 = '';
2447: }
1.586 raeburn 2448: }
1.591 raeburn 2449: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2450: $krbarg = $in{'curr_autharg'};
2451: }
1.586 raeburn 2452: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2453: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2454: $result =
2455: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2456: $in{'curr_autharg'},$krbver);
2457: } else {
2458: $result =
2459: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2460: }
2461: return $result;
2462: }
2463: }
2464: } else {
2465: if ($authnum == 1) {
1.784 bisitz 2466: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2467: }
2468: }
1.586 raeburn 2469: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2470: return;
1.587 raeburn 2471: } elsif ($authtype eq '') {
1.591 raeburn 2472: if (defined($in{'mode'})) {
1.587 raeburn 2473: if ($in{'mode'} eq 'modifycourse') {
2474: if ($authnum == 1) {
1.784 bisitz 2475: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2476: }
2477: }
2478: }
1.586 raeburn 2479: }
2480: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2481: if ($authtype eq '') {
2482: $authtype = '<input type="radio" name="login" value="krb" '.
2483: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2484: $krbcheck.' />';
2485: }
2486: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2487: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2488: $in{'curr_authtype'} eq 'krb5') ||
2489: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2490: $in{'curr_authtype'} eq 'krb4')) {
2491: $result .= &mt
1.144 matthew 2492: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2493: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2494: '<label>'.$authtype,
1.281 albertel 2495: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2496: 'value="'.$krbarg.'" '.
1.144 matthew 2497: 'onchange="'.$jscall.'" />',
1.281 albertel 2498: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2499: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2500: '</label>');
1.586 raeburn 2501: } elsif ($can_assign{'krb4'}) {
2502: $result .= &mt
2503: ('[_1] Kerberos authenticated with domain [_2] '.
2504: '[_3] Version 4 [_4]',
2505: '<label>'.$authtype,
2506: '</label><input type="text" size="10" name="krbarg" '.
2507: 'value="'.$krbarg.'" '.
2508: 'onchange="'.$jscall.'" />',
2509: '<label><input type="hidden" name="krbver" value="4" />',
2510: '</label>');
2511: } elsif ($can_assign{'krb5'}) {
2512: $result .= &mt
2513: ('[_1] Kerberos authenticated with domain [_2] '.
2514: '[_3] Version 5 [_4]',
2515: '<label>'.$authtype,
2516: '</label><input type="text" size="10" name="krbarg" '.
2517: 'value="'.$krbarg.'" '.
2518: 'onchange="'.$jscall.'" />',
2519: '<label><input type="hidden" name="krbver" value="5" />',
2520: '</label>');
2521: }
1.32 matthew 2522: return $result;
2523: }
2524:
2525: sub authform_internal{
1.586 raeburn 2526: my %in = (
1.32 matthew 2527: formname => 'document.cu',
2528: kerb_def_dom => 'MSU.EDU',
2529: @_,
2530: );
1.586 raeburn 2531: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2532: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2533: if (defined($in{'curr_authtype'})) {
2534: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2535: if ($can_assign{'int'}) {
1.772 bisitz 2536: $intcheck = 'checked="checked" ';
1.623 raeburn 2537: if (defined($in{'mode'})) {
2538: if ($in{'mode'} eq 'modifyuser') {
2539: $intcheck = '';
2540: }
2541: }
1.591 raeburn 2542: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2543: $intarg = $in{'curr_autharg'};
2544: }
2545: } else {
2546: $result = &mt('Currently internally authenticated.');
2547: return $result;
1.165 raeburn 2548: }
2549: }
1.586 raeburn 2550: } else {
2551: if ($authnum == 1) {
1.784 bisitz 2552: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2553: }
2554: }
2555: if (!$can_assign{'int'}) {
2556: return;
1.587 raeburn 2557: } elsif ($authtype eq '') {
1.591 raeburn 2558: if (defined($in{'mode'})) {
1.587 raeburn 2559: if ($in{'mode'} eq 'modifycourse') {
2560: if ($authnum == 1) {
1.784 bisitz 2561: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2562: }
2563: }
2564: }
1.165 raeburn 2565: }
1.586 raeburn 2566: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2567: if ($authtype eq '') {
2568: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2569: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2570: }
1.605 bisitz 2571: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2572: $intarg.'" onchange="'.$jscall.'" />';
2573: $result = &mt
1.144 matthew 2574: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2575: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2576: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2577: return $result;
2578: }
2579:
2580: sub authform_local{
2581: my %in = (
2582: formname => 'document.cu',
2583: kerb_def_dom => 'MSU.EDU',
2584: @_,
2585: );
1.586 raeburn 2586: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2587: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2588: if (defined($in{'curr_authtype'})) {
2589: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2590: if ($can_assign{'loc'}) {
1.772 bisitz 2591: $loccheck = 'checked="checked" ';
1.623 raeburn 2592: if (defined($in{'mode'})) {
2593: if ($in{'mode'} eq 'modifyuser') {
2594: $loccheck = '';
2595: }
2596: }
1.591 raeburn 2597: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2598: $locarg = $in{'curr_autharg'};
2599: }
2600: } else {
2601: $result = &mt('Currently using local (institutional) authentication.');
2602: return $result;
1.165 raeburn 2603: }
2604: }
1.586 raeburn 2605: } else {
2606: if ($authnum == 1) {
1.784 bisitz 2607: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2608: }
2609: }
2610: if (!$can_assign{'loc'}) {
2611: return;
1.587 raeburn 2612: } elsif ($authtype eq '') {
1.591 raeburn 2613: if (defined($in{'mode'})) {
1.587 raeburn 2614: if ($in{'mode'} eq 'modifycourse') {
2615: if ($authnum == 1) {
1.784 bisitz 2616: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2617: }
2618: }
2619: }
1.165 raeburn 2620: }
1.586 raeburn 2621: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2622: if ($authtype eq '') {
2623: $authtype = '<input type="radio" name="login" value="loc" '.
2624: $loccheck.' onchange="'.$jscall.'" onclick="'.
2625: $jscall.'" />';
2626: }
2627: $autharg = '<input type="text" size="10" name="locarg" value="'.
2628: $locarg.'" onchange="'.$jscall.'" />';
2629: $result = &mt('[_1] Local Authentication with argument [_2]',
2630: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2631: return $result;
2632: }
2633:
2634: sub authform_filesystem{
2635: my %in = (
2636: formname => 'document.cu',
2637: kerb_def_dom => 'MSU.EDU',
2638: @_,
2639: );
1.586 raeburn 2640: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2641: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2642: if (defined($in{'curr_authtype'})) {
2643: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2644: if ($can_assign{'fsys'}) {
1.772 bisitz 2645: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2646: if (defined($in{'mode'})) {
2647: if ($in{'mode'} eq 'modifyuser') {
2648: $fsyscheck = '';
2649: }
2650: }
1.586 raeburn 2651: } else {
2652: $result = &mt('Currently Filesystem Authenticated.');
2653: return $result;
2654: }
2655: }
2656: } else {
2657: if ($authnum == 1) {
1.784 bisitz 2658: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2659: }
2660: }
2661: if (!$can_assign{'fsys'}) {
2662: return;
1.587 raeburn 2663: } elsif ($authtype eq '') {
1.591 raeburn 2664: if (defined($in{'mode'})) {
1.587 raeburn 2665: if ($in{'mode'} eq 'modifycourse') {
2666: if ($authnum == 1) {
1.784 bisitz 2667: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2668: }
2669: }
2670: }
1.586 raeburn 2671: }
2672: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2673: if ($authtype eq '') {
2674: $authtype = '<input type="radio" name="login" value="fsys" '.
2675: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2676: $jscall.'" />';
2677: }
2678: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2679: ' onchange="'.$jscall.'" />';
2680: $result = &mt
1.144 matthew 2681: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2682: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2683: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2684: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2685: 'onchange="'.$jscall.'" />');
1.32 matthew 2686: return $result;
2687: }
2688:
1.586 raeburn 2689: sub get_assignable_auth {
2690: my ($dom) = @_;
2691: if ($dom eq '') {
2692: $dom = $env{'request.role.domain'};
2693: }
2694: my %can_assign = (
2695: krb4 => 1,
2696: krb5 => 1,
2697: int => 1,
2698: loc => 1,
2699: );
2700: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2701: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2702: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2703: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2704: my $context;
2705: if ($env{'request.role'} =~ /^au/) {
2706: $context = 'author';
2707: } elsif ($env{'request.role'} =~ /^dc/) {
2708: $context = 'domain';
2709: } elsif ($env{'request.course.id'}) {
2710: $context = 'course';
2711: }
2712: if ($context) {
2713: if (ref($authhash->{$context}) eq 'HASH') {
2714: %can_assign = %{$authhash->{$context}};
2715: }
2716: }
2717: }
2718: }
2719: my $authnum = 0;
2720: foreach my $key (keys(%can_assign)) {
2721: if ($can_assign{$key}) {
2722: $authnum ++;
2723: }
2724: }
2725: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2726: $authnum --;
2727: }
2728: return ($authnum,%can_assign);
2729: }
2730:
1.80 albertel 2731: ###############################################################
2732: ## Get Kerberos Defaults for Domain ##
2733: ###############################################################
2734: ##
2735: ## Returns default kerberos version and an associated argument
2736: ## as listed in file domain.tab. If not listed, provides
2737: ## appropriate default domain and kerberos version.
2738: ##
2739: #-------------------------------------------
2740:
2741: =pod
2742:
1.648 raeburn 2743: =item * &get_kerberos_defaults()
1.80 albertel 2744:
2745: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2746: version and domain. If not found, it defaults to version 4 and the
2747: domain of the server.
1.80 albertel 2748:
1.648 raeburn 2749: =over 4
2750:
1.80 albertel 2751: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2752:
1.648 raeburn 2753: =back
2754:
2755: =back
2756:
1.80 albertel 2757: =cut
2758:
2759: #-------------------------------------------
2760: sub get_kerberos_defaults {
2761: my $domain=shift;
1.641 raeburn 2762: my ($krbdef,$krbdefdom);
2763: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2764: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2765: $krbdef = $domdefaults{'auth_def'};
2766: $krbdefdom = $domdefaults{'auth_arg_def'};
2767: } else {
1.80 albertel 2768: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2769: my $krbdefdom=$1;
2770: $krbdefdom=~tr/a-z/A-Z/;
2771: $krbdef = "krb4";
2772: }
2773: return ($krbdef,$krbdefdom);
2774: }
1.112 bowersj2 2775:
1.32 matthew 2776:
1.46 matthew 2777: ###############################################################
2778: ## Thesaurus Functions ##
2779: ###############################################################
1.20 www 2780:
1.46 matthew 2781: =pod
1.20 www 2782:
1.112 bowersj2 2783: =head1 Thesaurus Functions
2784:
2785: =over 4
2786:
1.648 raeburn 2787: =item * &initialize_keywords()
1.46 matthew 2788:
2789: Initializes the package variable %Keywords if it is empty. Uses the
2790: package variable $thesaurus_db_file.
2791:
2792: =cut
2793:
2794: ###################################################
2795:
2796: sub initialize_keywords {
2797: return 1 if (scalar keys(%Keywords));
2798: # If we are here, %Keywords is empty, so fill it up
2799: # Make sure the file we need exists...
2800: if (! -e $thesaurus_db_file) {
2801: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2802: " failed because it does not exist");
2803: return 0;
2804: }
2805: # Set up the hash as a database
2806: my %thesaurus_db;
2807: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2808: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2809: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2810: $thesaurus_db_file);
2811: return 0;
2812: }
2813: # Get the average number of appearances of a word.
2814: my $avecount = $thesaurus_db{'average.count'};
2815: # Put keywords (those that appear > average) into %Keywords
2816: while (my ($word,$data)=each (%thesaurus_db)) {
2817: my ($count,undef) = split /:/,$data;
2818: $Keywords{$word}++ if ($count > $avecount);
2819: }
2820: untie %thesaurus_db;
2821: # Remove special values from %Keywords.
1.356 albertel 2822: foreach my $value ('total.count','average.count') {
2823: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2824: }
1.46 matthew 2825: return 1;
2826: }
2827:
2828: ###################################################
2829:
2830: =pod
2831:
1.648 raeburn 2832: =item * &keyword($word)
1.46 matthew 2833:
2834: Returns true if $word is a keyword. A keyword is a word that appears more
2835: than the average number of times in the thesaurus database. Calls
2836: &initialize_keywords
2837:
2838: =cut
2839:
2840: ###################################################
1.20 www 2841:
2842: sub keyword {
1.46 matthew 2843: return if (!&initialize_keywords());
2844: my $word=lc(shift());
2845: $word=~s/\W//g;
2846: return exists($Keywords{$word});
1.20 www 2847: }
1.46 matthew 2848:
2849: ###############################################################
2850:
2851: =pod
1.20 www 2852:
1.648 raeburn 2853: =item * &get_related_words()
1.46 matthew 2854:
1.160 matthew 2855: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2856: an array of words. If the keyword is not in the thesaurus, an empty array
2857: will be returned. The order of the words returned is determined by the
2858: database which holds them.
2859:
2860: Uses global $thesaurus_db_file.
2861:
2862: =cut
2863:
2864: ###############################################################
2865: sub get_related_words {
2866: my $keyword = shift;
2867: my %thesaurus_db;
2868: if (! -e $thesaurus_db_file) {
2869: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2870: "failed because the file does not exist");
2871: return ();
2872: }
2873: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2874: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2875: return ();
2876: }
2877: my @Words=();
1.429 www 2878: my $count=0;
1.46 matthew 2879: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2880: # The first element is the number of times
2881: # the word appears. We do not need it now.
1.429 www 2882: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2883: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2884: my $threshold=$mostfrequentcount/10;
2885: foreach my $possibleword (@RelatedWords) {
2886: my ($word,$wordcount)=split(/\,/,$possibleword);
2887: if ($wordcount>$threshold) {
2888: push(@Words,$word);
2889: $count++;
2890: if ($count>10) { last; }
2891: }
1.20 www 2892: }
2893: }
1.46 matthew 2894: untie %thesaurus_db;
2895: return @Words;
1.14 harris41 2896: }
1.46 matthew 2897:
1.112 bowersj2 2898: =pod
2899:
2900: =back
2901:
2902: =cut
1.61 www 2903:
2904: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2905: =pod
2906:
1.112 bowersj2 2907: =head1 User Name Functions
2908:
2909: =over 4
2910:
1.648 raeburn 2911: =item * &plainname($uname,$udom,$first)
1.81 albertel 2912:
1.112 bowersj2 2913: Takes a users logon name and returns it as a string in
1.226 albertel 2914: "first middle last generation" form
2915: if $first is set to 'lastname' then it returns it as
2916: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2917:
2918: =cut
1.61 www 2919:
1.295 www 2920:
1.81 albertel 2921: ###############################################################
1.61 www 2922: sub plainname {
1.226 albertel 2923: my ($uname,$udom,$first)=@_;
1.537 albertel 2924: return if (!defined($uname) || !defined($udom));
1.295 www 2925: my %names=&getnames($uname,$udom);
1.226 albertel 2926: my $name=&Apache::lonnet::format_name($names{'firstname'},
2927: $names{'middlename'},
2928: $names{'lastname'},
2929: $names{'generation'},$first);
2930: $name=~s/^\s+//;
1.62 www 2931: $name=~s/\s+$//;
2932: $name=~s/\s+/ /g;
1.353 albertel 2933: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2934: return $name;
1.61 www 2935: }
1.66 www 2936:
2937: # -------------------------------------------------------------------- Nickname
1.81 albertel 2938: =pod
2939:
1.648 raeburn 2940: =item * &nickname($uname,$udom)
1.81 albertel 2941:
2942: Gets a users name and returns it as a string as
2943:
2944: ""nickname""
1.66 www 2945:
1.81 albertel 2946: if the user has a nickname or
2947:
2948: "first middle last generation"
2949:
2950: if the user does not
2951:
2952: =cut
1.66 www 2953:
2954: sub nickname {
2955: my ($uname,$udom)=@_;
1.537 albertel 2956: return if (!defined($uname) || !defined($udom));
1.295 www 2957: my %names=&getnames($uname,$udom);
1.68 albertel 2958: my $name=$names{'nickname'};
1.66 www 2959: if ($name) {
2960: $name='"'.$name.'"';
2961: } else {
2962: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2963: $names{'lastname'}.' '.$names{'generation'};
2964: $name=~s/\s+$//;
2965: $name=~s/\s+/ /g;
2966: }
2967: return $name;
2968: }
2969:
1.295 www 2970: sub getnames {
2971: my ($uname,$udom)=@_;
1.537 albertel 2972: return if (!defined($uname) || !defined($udom));
1.433 albertel 2973: if ($udom eq 'public' && $uname eq 'public') {
2974: return ('lastname' => &mt('Public'));
2975: }
1.295 www 2976: my $id=$uname.':'.$udom;
2977: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2978: if ($cached) {
2979: return %{$names};
2980: } else {
2981: my %loadnames=&Apache::lonnet::get('environment',
2982: ['firstname','middlename','lastname','generation','nickname'],
2983: $udom,$uname);
2984: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2985: return %loadnames;
2986: }
2987: }
1.61 www 2988:
1.542 raeburn 2989: # -------------------------------------------------------------------- getemails
1.648 raeburn 2990:
1.542 raeburn 2991: =pod
2992:
1.648 raeburn 2993: =item * &getemails($uname,$udom)
1.542 raeburn 2994:
2995: Gets a user's email information and returns it as a hash with keys:
2996: notification, critnotification, permanentemail
2997:
2998: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2999: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3000:
1.648 raeburn 3001:
1.542 raeburn 3002: =cut
3003:
1.648 raeburn 3004:
1.466 albertel 3005: sub getemails {
3006: my ($uname,$udom)=@_;
3007: if ($udom eq 'public' && $uname eq 'public') {
3008: return;
3009: }
1.467 www 3010: if (!$udom) { $udom=$env{'user.domain'}; }
3011: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3012: my $id=$uname.':'.$udom;
3013: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3014: if ($cached) {
3015: return %{$names};
3016: } else {
3017: my %loadnames=&Apache::lonnet::get('environment',
3018: ['notification','critnotification',
3019: 'permanentemail'],
3020: $udom,$uname);
3021: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3022: return %loadnames;
3023: }
3024: }
3025:
1.551 albertel 3026: sub flush_email_cache {
3027: my ($uname,$udom)=@_;
3028: if (!$udom) { $udom =$env{'user.domain'}; }
3029: if (!$uname) { $uname=$env{'user.name'}; }
3030: return if ($udom eq 'public' && $uname eq 'public');
3031: my $id=$uname.':'.$udom;
3032: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3033: }
3034:
1.728 raeburn 3035: # -------------------------------------------------------------------- getlangs
3036:
3037: =pod
3038:
3039: =item * &getlangs($uname,$udom)
3040:
3041: Gets a user's language preference and returns it as a hash with key:
3042: language.
3043:
3044: =cut
3045:
3046:
3047: sub getlangs {
3048: my ($uname,$udom) = @_;
3049: if (!$udom) { $udom =$env{'user.domain'}; }
3050: if (!$uname) { $uname=$env{'user.name'}; }
3051: my $id=$uname.':'.$udom;
3052: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3053: if ($cached) {
3054: return %{$langs};
3055: } else {
3056: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3057: $udom,$uname);
3058: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3059: return %loadlangs;
3060: }
3061: }
3062:
3063: sub flush_langs_cache {
3064: my ($uname,$udom)=@_;
3065: if (!$udom) { $udom =$env{'user.domain'}; }
3066: if (!$uname) { $uname=$env{'user.name'}; }
3067: return if ($udom eq 'public' && $uname eq 'public');
3068: my $id=$uname.':'.$udom;
3069: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3070: }
3071:
1.61 www 3072: # ------------------------------------------------------------------ Screenname
1.81 albertel 3073:
3074: =pod
3075:
1.648 raeburn 3076: =item * &screenname($uname,$udom)
1.81 albertel 3077:
3078: Gets a users screenname and returns it as a string
3079:
3080: =cut
1.61 www 3081:
3082: sub screenname {
3083: my ($uname,$udom)=@_;
1.258 albertel 3084: if ($uname eq $env{'user.name'} &&
3085: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3086: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3087: return $names{'screenname'};
1.62 www 3088: }
3089:
1.212 albertel 3090:
1.802 bisitz 3091: # ------------------------------------------------------------- Confirm Wrapper
3092: =pod
3093:
3094: =item confirmwrapper
3095:
3096: Wrap messages about completion of operation in box
3097:
3098: =cut
3099:
3100: sub confirmwrapper {
3101: my ($message)=@_;
3102: if ($message) {
3103: return "\n".'<div class="LC_confirm_box">'."\n"
3104: .$message."\n"
3105: .'</div>'."\n";
3106: } else {
3107: return $message;
3108: }
3109: }
3110:
1.62 www 3111: # ------------------------------------------------------------- Message Wrapper
3112:
3113: sub messagewrapper {
1.369 www 3114: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3115: return
1.441 albertel 3116: '<a href="/adm/email?compose=individual&'.
3117: 'recname='.$username.'&recdom='.$domain.
3118: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3119: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3120: }
1.802 bisitz 3121:
1.74 www 3122: # --------------------------------------------------------------- Notes Wrapper
3123:
3124: sub noteswrapper {
3125: my ($link,$un,$do)=@_;
3126: return
1.896 amueller 3127: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3128: }
1.802 bisitz 3129:
1.62 www 3130: # ------------------------------------------------------------- Aboutme Wrapper
3131:
3132: sub aboutmewrapper {
1.166 www 3133: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3134: if (!defined($username) && !defined($domain)) {
3135: return;
3136: }
1.892 amueller 3137: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3138: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3139: }
3140:
3141: # ------------------------------------------------------------ Syllabus Wrapper
3142:
3143: sub syllabuswrapper {
1.707 bisitz 3144: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3145: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3146: }
1.14 harris41 3147:
1.802 bisitz 3148: # -----------------------------------------------------------------------------
3149:
1.208 matthew 3150: sub track_student_link {
1.887 raeburn 3151: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3152: my $link ="/adm/trackstudent?";
1.208 matthew 3153: my $title = 'View recent activity';
3154: if (defined($sname) && $sname !~ /^\s*$/ &&
3155: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3156: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3157: $title .= ' of this student';
1.268 albertel 3158: }
1.208 matthew 3159: if (defined($target) && $target !~ /^\s*$/) {
3160: $target = qq{target="$target"};
3161: } else {
3162: $target = '';
3163: }
1.268 albertel 3164: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3165: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3166: $title = &mt($title);
3167: $linktext = &mt($linktext);
1.448 albertel 3168: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3169: &help_open_topic('View_recent_activity');
1.208 matthew 3170: }
3171:
1.781 raeburn 3172: sub slot_reservations_link {
3173: my ($linktext,$sname,$sdom,$target) = @_;
3174: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3175: my $title = 'View slot reservation history';
3176: if (defined($sname) && $sname !~ /^\s*$/ &&
3177: defined($sdom) && $sdom !~ /^\s*$/) {
3178: $link .= "&uname=$sname&udom=$sdom";
3179: $title .= ' of this student';
3180: }
3181: if (defined($target) && $target !~ /^\s*$/) {
3182: $target = qq{target="$target"};
3183: } else {
3184: $target = '';
3185: }
3186: $title = &mt($title);
3187: $linktext = &mt($linktext);
3188: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3189: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3190:
3191: }
3192:
1.508 www 3193: # ===================================================== Display a student photo
3194:
3195:
1.509 albertel 3196: sub student_image_tag {
1.508 www 3197: my ($domain,$user)=@_;
3198: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3199: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3200: return '<img src="'.$imgsrc.'" align="right" />';
3201: } else {
3202: return '';
3203: }
3204: }
3205:
1.112 bowersj2 3206: =pod
3207:
3208: =back
3209:
3210: =head1 Access .tab File Data
3211:
3212: =over 4
3213:
1.648 raeburn 3214: =item * &languageids()
1.112 bowersj2 3215:
3216: returns list of all language ids
3217:
3218: =cut
3219:
1.14 harris41 3220: sub languageids {
1.16 harris41 3221: return sort(keys(%language));
1.14 harris41 3222: }
3223:
1.112 bowersj2 3224: =pod
3225:
1.648 raeburn 3226: =item * &languagedescription()
1.112 bowersj2 3227:
3228: returns description of a specified language id
3229:
3230: =cut
3231:
1.14 harris41 3232: sub languagedescription {
1.125 www 3233: my $code=shift;
3234: return ($supported_language{$code}?'* ':'').
3235: $language{$code}.
1.126 www 3236: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3237: }
3238:
1.1028.2.1 foxr 3239: =pod
3240:
3241: =item * &plainlanguagedescription
3242:
3243: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3244: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3245:
3246: =cut
3247:
1.145 www 3248: sub plainlanguagedescription {
3249: my $code=shift;
3250: return $language{$code};
3251: }
3252:
1.1028.2.1 foxr 3253: =pod
3254:
3255: =item * &supportedlanguagecode
3256:
3257: Returns the supported language code (e.g. sptutf maps to pt) given a language
3258: code.
3259:
3260: =cut
3261:
1.145 www 3262: sub supportedlanguagecode {
3263: my $code=shift;
3264: return $supported_language{$code};
1.97 www 3265: }
3266:
1.112 bowersj2 3267: =pod
3268:
1.1028.2.1 foxr 3269: =item * &latexlanguage()
3270:
3271: Given a language key code returns the correspondnig language to use
3272: to select the correct hyphenation on LaTeX printouts. This is undef if there
3273: is no supported hyphenation for the language code.
3274:
3275: =cut
3276:
3277: sub latexlanguage {
3278: my $code = shift;
3279: return $latex_language{$code};
3280: }
3281:
3282: =pod
3283:
1.1028.2.2! foxr 3284: =item * &latexhyphenation()
! 3285:
! 3286: Same as above but what's supplied is the language as it might be stored
! 3287: in the metadata.
! 3288:
! 3289: =cut
! 3290:
! 3291: sub latexhyphenation {
! 3292: my $key = shift;
! 3293: return $latex_language_bykey{$key};
! 3294: }
! 3295:
! 3296: =pod
! 3297:
1.648 raeburn 3298: =item * ©rightids()
1.112 bowersj2 3299:
3300: returns list of all copyrights
3301:
3302: =cut
3303:
3304: sub copyrightids {
3305: return sort(keys(%cprtag));
3306: }
3307:
3308: =pod
3309:
1.648 raeburn 3310: =item * ©rightdescription()
1.112 bowersj2 3311:
3312: returns description of a specified copyright id
3313:
3314: =cut
3315:
3316: sub copyrightdescription {
1.166 www 3317: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3318: }
1.197 matthew 3319:
3320: =pod
3321:
1.648 raeburn 3322: =item * &source_copyrightids()
1.192 taceyjo1 3323:
3324: returns list of all source copyrights
3325:
3326: =cut
3327:
3328: sub source_copyrightids {
3329: return sort(keys(%scprtag));
3330: }
3331:
3332: =pod
3333:
1.648 raeburn 3334: =item * &source_copyrightdescription()
1.192 taceyjo1 3335:
3336: returns description of a specified source copyright id
3337:
3338: =cut
3339:
3340: sub source_copyrightdescription {
3341: return &mt($scprtag{shift(@_)});
3342: }
1.112 bowersj2 3343:
3344: =pod
3345:
1.648 raeburn 3346: =item * &filecategories()
1.112 bowersj2 3347:
3348: returns list of all file categories
3349:
3350: =cut
3351:
3352: sub filecategories {
3353: return sort(keys(%category_extensions));
3354: }
3355:
3356: =pod
3357:
1.648 raeburn 3358: =item * &filecategorytypes()
1.112 bowersj2 3359:
3360: returns list of file types belonging to a given file
3361: category
3362:
3363: =cut
3364:
3365: sub filecategorytypes {
1.356 albertel 3366: my ($cat) = @_;
3367: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3368: }
3369:
3370: =pod
3371:
1.648 raeburn 3372: =item * &fileembstyle()
1.112 bowersj2 3373:
3374: returns embedding style for a specified file type
3375:
3376: =cut
3377:
3378: sub fileembstyle {
3379: return $fe{lc(shift(@_))};
1.169 www 3380: }
3381:
1.351 www 3382: sub filemimetype {
3383: return $fm{lc(shift(@_))};
3384: }
3385:
1.169 www 3386:
3387: sub filecategoryselect {
3388: my ($name,$value)=@_;
1.189 matthew 3389: return &select_form($value,$name,
1.970 raeburn 3390: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3391: }
3392:
3393: =pod
3394:
1.648 raeburn 3395: =item * &filedescription()
1.112 bowersj2 3396:
3397: returns description for a specified file type
3398:
3399: =cut
3400:
3401: sub filedescription {
1.188 matthew 3402: my $file_description = $fd{lc(shift())};
3403: $file_description =~ s:([\[\]]):~$1:g;
3404: return &mt($file_description);
1.112 bowersj2 3405: }
3406:
3407: =pod
3408:
1.648 raeburn 3409: =item * &filedescriptionex()
1.112 bowersj2 3410:
3411: returns description for a specified file type with
3412: extra formatting
3413:
3414: =cut
3415:
3416: sub filedescriptionex {
3417: my $ex=shift;
1.188 matthew 3418: my $file_description = $fd{lc($ex)};
3419: $file_description =~ s:([\[\]]):~$1:g;
3420: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3421: }
3422:
3423: # End of .tab access
3424: =pod
3425:
3426: =back
3427:
3428: =cut
3429:
3430: # ------------------------------------------------------------------ File Types
3431: sub fileextensions {
3432: return sort(keys(%fe));
3433: }
3434:
1.97 www 3435: # ----------------------------------------------------------- Display Languages
3436: # returns a hash with all desired display languages
3437: #
3438:
3439: sub display_languages {
3440: my %languages=();
1.695 raeburn 3441: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3442: $languages{$lang}=1;
1.97 www 3443: }
3444: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3445: if ($env{'form.displaylanguage'}) {
1.356 albertel 3446: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3447: $languages{$lang}=1;
1.97 www 3448: }
3449: }
3450: return %languages;
1.14 harris41 3451: }
3452:
1.582 albertel 3453: sub languages {
3454: my ($possible_langs) = @_;
1.695 raeburn 3455: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3456: if (!ref($possible_langs)) {
3457: if( wantarray ) {
3458: return @preferred_langs;
3459: } else {
3460: return $preferred_langs[0];
3461: }
3462: }
3463: my %possibilities = map { $_ => 1 } (@$possible_langs);
3464: my @preferred_possibilities;
3465: foreach my $preferred_lang (@preferred_langs) {
3466: if (exists($possibilities{$preferred_lang})) {
3467: push(@preferred_possibilities, $preferred_lang);
3468: }
3469: }
3470: if( wantarray ) {
3471: return @preferred_possibilities;
3472: }
3473: return $preferred_possibilities[0];
3474: }
3475:
1.742 raeburn 3476: sub user_lang {
3477: my ($touname,$toudom,$fromcid) = @_;
3478: my @userlangs;
3479: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3480: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3481: $env{'course.'.$fromcid.'.languages'}));
3482: } else {
3483: my %langhash = &getlangs($touname,$toudom);
3484: if ($langhash{'languages'} ne '') {
3485: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3486: } else {
3487: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3488: if ($domdefs{'lang_def'} ne '') {
3489: @userlangs = ($domdefs{'lang_def'});
3490: }
3491: }
3492: }
3493: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3494: my $user_lh = Apache::localize->get_handle(@languages);
3495: return $user_lh;
3496: }
3497:
3498:
1.112 bowersj2 3499: ###############################################################
3500: ## Student Answer Attempts ##
3501: ###############################################################
3502:
3503: =pod
3504:
3505: =head1 Alternate Problem Views
3506:
3507: =over 4
3508:
1.648 raeburn 3509: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3510: $getattempt, $regexp, $gradesub)
3511:
3512: Return string with previous attempt on problem. Arguments:
3513:
3514: =over 4
3515:
3516: =item * $symb: Problem, including path
3517:
3518: =item * $username: username of the desired student
3519:
3520: =item * $domain: domain of the desired student
1.14 harris41 3521:
1.112 bowersj2 3522: =item * $course: Course ID
1.14 harris41 3523:
1.112 bowersj2 3524: =item * $getattempt: Leave blank for all attempts, otherwise put
3525: something
1.14 harris41 3526:
1.112 bowersj2 3527: =item * $regexp: if string matches this regexp, the string will be
3528: sent to $gradesub
1.14 harris41 3529:
1.112 bowersj2 3530: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3531:
1.112 bowersj2 3532: =back
1.14 harris41 3533:
1.112 bowersj2 3534: The output string is a table containing all desired attempts, if any.
1.16 harris41 3535:
1.112 bowersj2 3536: =cut
1.1 albertel 3537:
3538: sub get_previous_attempt {
1.43 ng 3539: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3540: my $prevattempts='';
1.43 ng 3541: no strict 'refs';
1.1 albertel 3542: if ($symb) {
1.3 albertel 3543: my (%returnhash)=
3544: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3545: if ($returnhash{'version'}) {
3546: my %lasthash=();
3547: my $version;
3548: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3549: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3550: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3551: }
1.1 albertel 3552: }
1.596 albertel 3553: $prevattempts=&start_data_table().&start_data_table_header_row();
3554: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3555: my (%typeparts,%lasthidden);
1.945 raeburn 3556: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3557: foreach my $key (sort(keys(%lasthash))) {
3558: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3559: if ($#parts > 0) {
1.31 albertel 3560: my $data=$parts[-1];
1.989 raeburn 3561: next if ($data eq 'foilorder');
1.31 albertel 3562: pop(@parts);
1.1010 www 3563: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3564: if ($data eq 'type') {
3565: unless ($showsurv) {
3566: my $id = join(',',@parts);
3567: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3568: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3569: $lasthidden{$ign.'.'.$id} = 1;
3570: }
1.945 raeburn 3571: }
1.1010 www 3572: }
1.31 albertel 3573: } else {
1.41 ng 3574: if ($#parts == 0) {
3575: $prevattempts.='<th>'.$parts[0].'</th>';
3576: } else {
3577: $prevattempts.='<th>'.$ign.'</th>';
3578: }
1.31 albertel 3579: }
1.16 harris41 3580: }
1.596 albertel 3581: $prevattempts.=&end_data_table_header_row();
1.40 ng 3582: if ($getattempt eq '') {
3583: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3584: my @hidden;
3585: if (%typeparts) {
3586: foreach my $id (keys(%typeparts)) {
3587: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3588: push(@hidden,$id);
3589: }
3590: }
3591: }
3592: $prevattempts.=&start_data_table_row().
3593: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3594: if (@hidden) {
3595: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3596: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3597: my $hide;
3598: foreach my $id (@hidden) {
3599: if ($key =~ /^\Q$id\E/) {
3600: $hide = 1;
3601: last;
3602: }
3603: }
3604: if ($hide) {
3605: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3606: if (($data eq 'award') || ($data eq 'awarddetail')) {
3607: my $value = &format_previous_attempt_value($key,
3608: $returnhash{$version.':'.$key});
3609: $prevattempts.='<td>'.$value.' </td>';
3610: } else {
3611: $prevattempts.='<td> </td>';
3612: }
3613: } else {
3614: if ($key =~ /\./) {
3615: my $value = &format_previous_attempt_value($key,
3616: $returnhash{$version.':'.$key});
3617: $prevattempts.='<td>'.$value.' </td>';
3618: } else {
3619: $prevattempts.='<td> </td>';
3620: }
3621: }
3622: }
3623: } else {
3624: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3625: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3626: my $value = &format_previous_attempt_value($key,
3627: $returnhash{$version.':'.$key});
3628: $prevattempts.='<td>'.$value.' </td>';
3629: }
3630: }
3631: $prevattempts.=&end_data_table_row();
1.40 ng 3632: }
1.1 albertel 3633: }
1.945 raeburn 3634: my @currhidden = keys(%lasthidden);
1.596 albertel 3635: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3636: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3637: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3638: if (%typeparts) {
3639: my $hidden;
3640: foreach my $id (@currhidden) {
3641: if ($key =~ /^\Q$id\E/) {
3642: $hidden = 1;
3643: last;
3644: }
3645: }
3646: if ($hidden) {
3647: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3648: if (($data eq 'award') || ($data eq 'awarddetail')) {
3649: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3650: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3651: $value = &$gradesub($value);
3652: }
3653: $prevattempts.='<td>'.$value.' </td>';
3654: } else {
3655: $prevattempts.='<td> </td>';
3656: }
3657: } else {
3658: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3659: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3660: $value = &$gradesub($value);
3661: }
3662: $prevattempts.='<td>'.$value.' </td>';
3663: }
3664: } else {
3665: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3666: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3667: $value = &$gradesub($value);
3668: }
3669: $prevattempts.='<td>'.$value.' </td>';
3670: }
1.16 harris41 3671: }
1.596 albertel 3672: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3673: } else {
1.596 albertel 3674: $prevattempts=
3675: &start_data_table().&start_data_table_row().
3676: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3677: &end_data_table_row().&end_data_table();
1.1 albertel 3678: }
3679: } else {
1.596 albertel 3680: $prevattempts=
3681: &start_data_table().&start_data_table_row().
3682: '<td>'.&mt('No data.').'</td>'.
3683: &end_data_table_row().&end_data_table();
1.1 albertel 3684: }
1.10 albertel 3685: }
3686:
1.581 albertel 3687: sub format_previous_attempt_value {
3688: my ($key,$value) = @_;
1.1011 www 3689: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3690: $value = &Apache::lonlocal::locallocaltime($value);
3691: } elsif (ref($value) eq 'ARRAY') {
3692: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3693: } elsif ($key =~ /answerstring$/) {
3694: my %answers = &Apache::lonnet::str2hash($value);
3695: my @anskeys = sort(keys(%answers));
3696: if (@anskeys == 1) {
3697: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3698: if ($answer =~ m{\0}) {
3699: $answer =~ s{\0}{,}g;
1.988 raeburn 3700: }
3701: my $tag_internal_answer_name = 'INTERNAL';
3702: if ($anskeys[0] eq $tag_internal_answer_name) {
3703: $value = $answer;
3704: } else {
3705: $value = $anskeys[0].'='.$answer;
3706: }
3707: } else {
3708: foreach my $ans (@anskeys) {
3709: my $answer = $answers{$ans};
1.1001 raeburn 3710: if ($answer =~ m{\0}) {
3711: $answer =~ s{\0}{,}g;
1.988 raeburn 3712: }
3713: $value .= $ans.'='.$answer.'<br />';;
3714: }
3715: }
1.581 albertel 3716: } else {
3717: $value = &unescape($value);
3718: }
3719: return $value;
3720: }
3721:
3722:
1.107 albertel 3723: sub relative_to_absolute {
3724: my ($url,$output)=@_;
3725: my $parser=HTML::TokeParser->new(\$output);
3726: my $token;
3727: my $thisdir=$url;
3728: my @rlinks=();
3729: while ($token=$parser->get_token) {
3730: if ($token->[0] eq 'S') {
3731: if ($token->[1] eq 'a') {
3732: if ($token->[2]->{'href'}) {
3733: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3734: }
3735: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3736: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3737: } elsif ($token->[1] eq 'base') {
3738: $thisdir=$token->[2]->{'href'};
3739: }
3740: }
3741: }
3742: $thisdir=~s-/[^/]*$--;
1.356 albertel 3743: foreach my $link (@rlinks) {
1.726 raeburn 3744: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3745: ($link=~/^\//) ||
3746: ($link=~/^javascript:/i) ||
3747: ($link=~/^mailto:/i) ||
3748: ($link=~/^\#/)) {
3749: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3750: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3751: }
3752: }
3753: # -------------------------------------------------- Deal with Applet codebases
3754: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3755: return $output;
3756: }
3757:
1.112 bowersj2 3758: =pod
3759:
1.648 raeburn 3760: =item * &get_student_view()
1.112 bowersj2 3761:
3762: show a snapshot of what student was looking at
3763:
3764: =cut
3765:
1.10 albertel 3766: sub get_student_view {
1.186 albertel 3767: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3768: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3769: my (%form);
1.10 albertel 3770: my @elements=('symb','courseid','domain','username');
3771: foreach my $element (@elements) {
1.186 albertel 3772: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3773: }
1.186 albertel 3774: if (defined($moreenv)) {
3775: %form=(%form,%{$moreenv});
3776: }
1.236 albertel 3777: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3778: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3779: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3780: $userview=~s/\<body[^\>]*\>//gi;
3781: $userview=~s/\<\/body\>//gi;
3782: $userview=~s/\<html\>//gi;
3783: $userview=~s/\<\/html\>//gi;
3784: $userview=~s/\<head\>//gi;
3785: $userview=~s/\<\/head\>//gi;
3786: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3787: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3788: if (wantarray) {
3789: return ($userview,$response);
3790: } else {
3791: return $userview;
3792: }
3793: }
3794:
3795: sub get_student_view_with_retries {
3796: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3797:
3798: my $ok = 0; # True if we got a good response.
3799: my $content;
3800: my $response;
3801:
3802: # Try to get the student_view done. within the retries count:
3803:
3804: do {
3805: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3806: $ok = $response->is_success;
3807: if (!$ok) {
3808: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3809: }
3810: $retries--;
3811: } while (!$ok && ($retries > 0));
3812:
3813: if (!$ok) {
3814: $content = ''; # On error return an empty content.
3815: }
1.651 www 3816: if (wantarray) {
3817: return ($content, $response);
3818: } else {
3819: return $content;
3820: }
1.11 albertel 3821: }
3822:
1.112 bowersj2 3823: =pod
3824:
1.648 raeburn 3825: =item * &get_student_answers()
1.112 bowersj2 3826:
3827: show a snapshot of how student was answering problem
3828:
3829: =cut
3830:
1.11 albertel 3831: sub get_student_answers {
1.100 sakharuk 3832: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3833: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3834: my (%moreenv);
1.11 albertel 3835: my @elements=('symb','courseid','domain','username');
3836: foreach my $element (@elements) {
1.186 albertel 3837: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3838: }
1.186 albertel 3839: $moreenv{'grade_target'}='answer';
3840: %moreenv=(%form,%moreenv);
1.497 raeburn 3841: $feedurl = &Apache::lonnet::clutter($feedurl);
3842: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3843: return $userview;
1.1 albertel 3844: }
1.116 albertel 3845:
3846: =pod
3847:
3848: =item * &submlink()
3849:
1.242 albertel 3850: Inputs: $text $uname $udom $symb $target
1.116 albertel 3851:
3852: Returns: A link to grades.pm such as to see the SUBM view of a student
3853:
3854: =cut
3855:
3856: ###############################################
3857: sub submlink {
1.242 albertel 3858: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3859: if (!($uname && $udom)) {
3860: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3861: &Apache::lonnet::whichuser($symb);
1.116 albertel 3862: if (!$symb) { $symb=$cursymb; }
3863: }
1.254 matthew 3864: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3865: $symb=&escape($symb);
1.960 bisitz 3866: if ($target) { $target=" target=\"$target\""; }
3867: return
3868: '<a href="/adm/grades?command=submission'.
3869: '&symb='.$symb.
3870: '&student='.$uname.
3871: '&userdom='.$udom.'"'.
3872: $target.'>'.$text.'</a>';
1.242 albertel 3873: }
3874: ##############################################
3875:
3876: =pod
3877:
3878: =item * &pgrdlink()
3879:
3880: Inputs: $text $uname $udom $symb $target
3881:
3882: Returns: A link to grades.pm such as to see the PGRD view of a student
3883:
3884: =cut
3885:
3886: ###############################################
3887: sub pgrdlink {
3888: my $link=&submlink(@_);
3889: $link=~s/(&command=submission)/$1&showgrading=yes/;
3890: return $link;
3891: }
3892: ##############################################
3893:
3894: =pod
3895:
3896: =item * &pprmlink()
3897:
3898: Inputs: $text $uname $udom $symb $target
3899:
3900: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3901: student and a specific resource
1.242 albertel 3902:
3903: =cut
3904:
3905: ###############################################
3906: sub pprmlink {
3907: my ($text,$uname,$udom,$symb,$target)=@_;
3908: if (!($uname && $udom)) {
3909: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3910: &Apache::lonnet::whichuser($symb);
1.242 albertel 3911: if (!$symb) { $symb=$cursymb; }
3912: }
1.254 matthew 3913: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3914: $symb=&escape($symb);
1.242 albertel 3915: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3916: return '<a href="/adm/parmset?command=set&'.
3917: 'symb='.$symb.'&uname='.$uname.
3918: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3919: }
3920: ##############################################
1.37 matthew 3921:
1.112 bowersj2 3922: =pod
3923:
3924: =back
3925:
3926: =cut
3927:
1.37 matthew 3928: ###############################################
1.51 www 3929:
3930:
3931: sub timehash {
1.687 raeburn 3932: my ($thistime) = @_;
3933: my $timezone = &Apache::lonlocal::gettimezone();
3934: my $dt = DateTime->from_epoch(epoch => $thistime)
3935: ->set_time_zone($timezone);
3936: my $wday = $dt->day_of_week();
3937: if ($wday == 7) { $wday = 0; }
3938: return ( 'second' => $dt->second(),
3939: 'minute' => $dt->minute(),
3940: 'hour' => $dt->hour(),
3941: 'day' => $dt->day_of_month(),
3942: 'month' => $dt->month(),
3943: 'year' => $dt->year(),
3944: 'weekday' => $wday,
3945: 'dayyear' => $dt->day_of_year(),
3946: 'dlsav' => $dt->is_dst() );
1.51 www 3947: }
3948:
1.370 www 3949: sub utc_string {
3950: my ($date)=@_;
1.371 www 3951: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3952: }
3953:
1.51 www 3954: sub maketime {
3955: my %th=@_;
1.687 raeburn 3956: my ($epoch_time,$timezone,$dt);
3957: $timezone = &Apache::lonlocal::gettimezone();
3958: eval {
3959: $dt = DateTime->new( year => $th{'year'},
3960: month => $th{'month'},
3961: day => $th{'day'},
3962: hour => $th{'hour'},
3963: minute => $th{'minute'},
3964: second => $th{'second'},
3965: time_zone => $timezone,
3966: );
3967: };
3968: if (!$@) {
3969: $epoch_time = $dt->epoch;
3970: if ($epoch_time) {
3971: return $epoch_time;
3972: }
3973: }
1.51 www 3974: return POSIX::mktime(
3975: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3976: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3977: }
3978:
3979: #########################################
1.51 www 3980:
3981: sub findallcourses {
1.482 raeburn 3982: my ($roles,$uname,$udom) = @_;
1.355 albertel 3983: my %roles;
3984: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3985: my %courses;
1.51 www 3986: my $now=time;
1.482 raeburn 3987: if (!defined($uname)) {
3988: $uname = $env{'user.name'};
3989: }
3990: if (!defined($udom)) {
3991: $udom = $env{'user.domain'};
3992: }
3993: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.982 raeburn 3994: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3995: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3996: $extra);
1.482 raeburn 3997: if (!%roles) {
3998: %roles = (
3999: cc => 1,
1.907 raeburn 4000: co => 1,
1.482 raeburn 4001: in => 1,
4002: ep => 1,
4003: ta => 1,
4004: cr => 1,
4005: st => 1,
4006: );
4007: }
4008: foreach my $entry (keys(%roleshash)) {
4009: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4010: if ($trole =~ /^cr/) {
4011: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4012: } else {
4013: next if (!exists($roles{$trole}));
4014: }
4015: if ($tend) {
4016: next if ($tend < $now);
4017: }
4018: if ($tstart) {
4019: next if ($tstart > $now);
4020: }
4021: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
4022: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
4023: if ($secpart eq '') {
4024: ($cnum,$role) = split(/_/,$cnumpart);
4025: $sec = 'none';
4026: $realsec = '';
4027: } else {
4028: $cnum = $cnumpart;
4029: ($sec,$role) = split(/_/,$secpart);
4030: $realsec = $sec;
1.490 raeburn 4031: }
1.482 raeburn 4032: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
4033: }
4034: } else {
4035: foreach my $key (keys(%env)) {
1.483 albertel 4036: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4037: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4038: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4039: next if ($role eq 'ca' || $role eq 'aa');
4040: next if (%roles && !exists($roles{$role}));
4041: my ($starttime,$endtime)=split(/\./,$env{$key});
4042: my $active=1;
4043: if ($starttime) {
4044: if ($now<$starttime) { $active=0; }
4045: }
4046: if ($endtime) {
4047: if ($now>$endtime) { $active=0; }
4048: }
4049: if ($active) {
4050: if ($sec eq '') {
4051: $sec = 'none';
4052: }
4053: $courses{$cdom.'_'.$cnum}{$sec} =
4054: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 4055: }
4056: }
1.51 www 4057: }
4058: }
1.474 raeburn 4059: return %courses;
1.51 www 4060: }
1.37 matthew 4061:
1.54 www 4062: ###############################################
1.474 raeburn 4063:
4064: sub blockcheck {
1.482 raeburn 4065: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 4066:
4067: if (!defined($udom)) {
4068: $udom = $env{'user.domain'};
4069: }
4070: if (!defined($uname)) {
4071: $uname = $env{'user.name'};
4072: }
4073:
4074: # If uname and udom are for a course, check for blocks in the course.
4075:
4076: if (&Apache::lonnet::is_course($udom,$uname)) {
4077: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 4078: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 4079: return ($startblock,$endblock);
4080: }
1.474 raeburn 4081:
1.502 raeburn 4082: my $startblock = 0;
4083: my $endblock = 0;
1.482 raeburn 4084: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4085:
1.490 raeburn 4086: # If uname is for a user, and activity is course-specific, i.e.,
4087: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4088:
1.490 raeburn 4089: if (($activity eq 'boards' || $activity eq 'chat' ||
4090: $activity eq 'groups') && ($env{'request.course.id'})) {
4091: foreach my $key (keys(%live_courses)) {
4092: if ($key ne $env{'request.course.id'}) {
4093: delete($live_courses{$key});
4094: }
4095: }
4096: }
4097:
4098: my $otheruser = 0;
4099: my %own_courses;
4100: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4101: # Resource belongs to user other than current user.
4102: $otheruser = 1;
4103: # Gather courses for current user
4104: %own_courses =
4105: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4106: }
4107:
4108: # Gather active course roles - course coordinator, instructor,
4109: # exam proctor, ta, student, or custom role.
1.474 raeburn 4110:
4111: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4112: my ($cdom,$cnum);
4113: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4114: $cdom = $env{'course.'.$course.'.domain'};
4115: $cnum = $env{'course.'.$course.'.num'};
4116: } else {
1.490 raeburn 4117: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4118: }
4119: my $no_ownblock = 0;
4120: my $no_userblock = 0;
1.533 raeburn 4121: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4122: # Check if current user has 'evb' priv for this
4123: if (defined($own_courses{$course})) {
4124: foreach my $sec (keys(%{$own_courses{$course}})) {
4125: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4126: if ($sec ne 'none') {
4127: $checkrole .= '/'.$sec;
4128: }
4129: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4130: $no_ownblock = 1;
4131: last;
4132: }
4133: }
4134: }
4135: # if they have 'evb' priv and are currently not playing student
4136: next if (($no_ownblock) &&
4137: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4138: }
1.474 raeburn 4139: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4140: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4141: if ($sec ne 'none') {
1.482 raeburn 4142: $checkrole .= '/'.$sec;
1.474 raeburn 4143: }
1.490 raeburn 4144: if ($otheruser) {
4145: # Resource belongs to user other than current user.
4146: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 4147: my ($trole,$tdom,$tnum,$tsec);
4148: my $entry = $live_courses{$course}{$sec};
4149: if ($entry =~ /^cr/) {
4150: ($trole,$tdom,$tnum,$tsec) =
4151: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4152: } else {
4153: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4154: }
4155: my ($spec,$area,$trest,%allroles,%userroles);
4156: $area = '/'.$tdom.'/'.$tnum;
4157: $trest = $tnum;
4158: if ($tsec ne '') {
4159: $area .= '/'.$tsec;
4160: $trest .= '/'.$tsec;
4161: }
4162: $spec = $trole.'.'.$area;
4163: if ($trole =~ /^cr/) {
4164: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4165: $tdom,$spec,$trest,$area);
4166: } else {
4167: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4168: $tdom,$spec,$trest,$area);
4169: }
4170: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4171: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4172: if ($1) {
4173: $no_userblock = 1;
4174: last;
4175: }
4176: }
1.490 raeburn 4177: } else {
4178: # Resource belongs to current user
4179: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4180: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4181: $no_ownblock = 1;
4182: last;
4183: }
1.474 raeburn 4184: }
4185: }
4186: # if they have the evb priv and are currently not playing student
1.482 raeburn 4187: next if (($no_ownblock) &&
1.491 albertel 4188: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4189: next if ($no_userblock);
1.474 raeburn 4190:
1.866 kalberla 4191: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4192: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4193:
4194: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4195: if (($start != 0) &&
4196: (($startblock == 0) || ($startblock > $start))) {
4197: $startblock = $start;
4198: }
4199: if (($end != 0) &&
4200: (($endblock == 0) || ($endblock < $end))) {
4201: $endblock = $end;
4202: }
1.490 raeburn 4203: }
4204: return ($startblock,$endblock);
4205: }
4206:
4207: sub get_blocks {
4208: my ($setters,$activity,$cdom,$cnum) = @_;
4209: my $startblock = 0;
4210: my $endblock = 0;
4211: my $course = $cdom.'_'.$cnum;
4212: $setters->{$course} = {};
4213: $setters->{$course}{'staff'} = [];
4214: $setters->{$course}{'times'} = [];
4215: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4216: foreach my $record (keys(%records)) {
4217: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4218: if ($start <= time && $end >= time) {
4219: my ($staff_name,$staff_dom,$title,$blocks) =
4220: &parse_block_record($records{$record});
4221: if ($blocks->{$activity} eq 'on') {
4222: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4223: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4224: if ( ($startblock == 0) || ($startblock > $start) ) {
4225: $startblock = $start;
1.490 raeburn 4226: }
1.491 albertel 4227: if ( ($endblock == 0) || ($endblock < $end) ) {
4228: $endblock = $end;
1.474 raeburn 4229: }
4230: }
4231: }
4232: }
4233: return ($startblock,$endblock);
4234: }
4235:
4236: sub parse_block_record {
4237: my ($record) = @_;
4238: my ($setuname,$setudom,$title,$blocks);
4239: if (ref($record) eq 'HASH') {
4240: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4241: $title = &unescape($record->{'event'});
4242: $blocks = $record->{'blocks'};
4243: } else {
4244: my @data = split(/:/,$record,3);
4245: if (scalar(@data) eq 2) {
4246: $title = $data[1];
4247: ($setuname,$setudom) = split(/@/,$data[0]);
4248: } else {
4249: ($setuname,$setudom,$title) = @data;
4250: }
4251: $blocks = { 'com' => 'on' };
4252: }
4253: return ($setuname,$setudom,$title,$blocks);
4254: }
4255:
1.854 kalberla 4256: sub blocking_status {
4257: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4258: my %setters;
1.890 droeschl 4259:
4260: # check for active blocking
1.867 kalberla 4261: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4262:
1.890 droeschl 4263: my $blocked = $startblock && $endblock ? 1 : 0;
4264:
4265: # caller just wants to know whether a block is active
4266: if (!wantarray) { return $blocked; }
4267:
4268: # build a link to a popup window containing the details
4269: my $querystring = "?activity=$activity";
4270: # $uname and $udom decide whose portfolio the user is trying to look at
4271: $querystring .= "&udom=$udom" if $udom;
4272: $querystring .= "&uname=$uname" if $uname;
4273:
4274: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4275: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4276: var options = "width=" + w + ",height=" + h + ",";
4277: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4278: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4279: var newWin = window.open(url, wdwName, options);
4280: newWin.focus();
4281: }
1.890 droeschl 4282: END_MYBLOCK
1.854 kalberla 4283:
1.890 droeschl 4284: $output = Apache::lonhtmlcommon::scripttag($output);
4285:
1.854 kalberla 4286: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4287: my $text = mt('Communication Blocked');
4288:
1.867 kalberla 4289: $output .= <<"END_BLOCK";
4290: <div class='LC_comblock'>
1.869 kalberla 4291: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4292: title='$text'>
4293: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4294: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4295: title='$text'>$text</a>
1.867 kalberla 4296: </div>
4297:
4298: END_BLOCK
1.474 raeburn 4299:
1.854 kalberla 4300: return ($blocked, $output);
4301: }
1.490 raeburn 4302:
1.60 matthew 4303: ###############################################
4304:
1.682 raeburn 4305: sub check_ip_acc {
4306: my ($acc)=@_;
4307: &Apache::lonxml::debug("acc is $acc");
4308: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4309: return 1;
4310: }
4311: my $allowed=0;
4312: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4313:
4314: my $name;
4315: foreach my $pattern (split(',',$acc)) {
4316: $pattern =~ s/^\s*//;
4317: $pattern =~ s/\s*$//;
4318: if ($pattern =~ /\*$/) {
4319: #35.8.*
4320: $pattern=~s/\*//;
4321: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4322: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4323: #35.8.3.[34-56]
4324: my $low=$2;
4325: my $high=$3;
4326: $pattern=$1;
4327: if ($ip =~ /^\Q$pattern\E/) {
4328: my $last=(split(/\./,$ip))[3];
4329: if ($last <=$high && $last >=$low) { $allowed=1; }
4330: }
4331: } elsif ($pattern =~ /^\*/) {
4332: #*.msu.edu
4333: $pattern=~s/\*//;
4334: if (!defined($name)) {
4335: use Socket;
4336: my $netaddr=inet_aton($ip);
4337: ($name)=gethostbyaddr($netaddr,AF_INET);
4338: }
4339: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4340: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4341: #127.0.0.1
4342: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4343: } else {
4344: #some.name.com
4345: if (!defined($name)) {
4346: use Socket;
4347: my $netaddr=inet_aton($ip);
4348: ($name)=gethostbyaddr($netaddr,AF_INET);
4349: }
4350: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4351: }
4352: if ($allowed) { last; }
4353: }
4354: return $allowed;
4355: }
4356:
4357: ###############################################
4358:
1.60 matthew 4359: =pod
4360:
1.112 bowersj2 4361: =head1 Domain Template Functions
4362:
4363: =over 4
4364:
4365: =item * &determinedomain()
1.60 matthew 4366:
4367: Inputs: $domain (usually will be undef)
4368:
1.63 www 4369: Returns: Determines which domain should be used for designs
1.60 matthew 4370:
4371: =cut
1.54 www 4372:
1.60 matthew 4373: ###############################################
1.63 www 4374: sub determinedomain {
4375: my $domain=shift;
1.531 albertel 4376: if (! $domain) {
1.60 matthew 4377: # Determine domain if we have not been given one
1.893 raeburn 4378: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4379: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4380: if ($env{'request.role.domain'}) {
4381: $domain=$env{'request.role.domain'};
1.60 matthew 4382: }
4383: }
1.63 www 4384: return $domain;
4385: }
4386: ###############################################
1.517 raeburn 4387:
1.518 albertel 4388: sub devalidate_domconfig_cache {
4389: my ($udom)=@_;
4390: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4391: }
4392:
4393: # ---------------------- Get domain configuration for a domain
4394: sub get_domainconf {
4395: my ($udom) = @_;
4396: my $cachetime=1800;
4397: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4398: if (defined($cached)) { return %{$result}; }
4399:
4400: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4401: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4402: my (%designhash,%legacy);
1.518 albertel 4403: if (keys(%domconfig) > 0) {
4404: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4405: if (keys(%{$domconfig{'login'}})) {
4406: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4407: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4408: if ($key eq 'loginvia') {
4409: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4410: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4411: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4412: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4413: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4414: $designhash{$udom.'.login.loginvia'} = $server;
4415: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4416:
4417: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4418: } else {
1.1013 raeburn 4419: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4420: }
4421: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4422: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4423: }
1.946 raeburn 4424: }
4425: }
4426: }
4427: }
4428: } else {
4429: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4430: $designhash{$udom.'.login.'.$key.'_'.$img} =
4431: $domconfig{'login'}{$key}{$img};
4432: }
1.699 raeburn 4433: }
4434: } else {
4435: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4436: }
1.632 raeburn 4437: }
4438: } else {
4439: $legacy{'login'} = 1;
1.518 albertel 4440: }
1.632 raeburn 4441: } else {
4442: $legacy{'login'} = 1;
1.518 albertel 4443: }
4444: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4445: if (keys(%{$domconfig{'rolecolors'}})) {
4446: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4447: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4448: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4449: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4450: }
1.518 albertel 4451: }
4452: }
1.632 raeburn 4453: } else {
4454: $legacy{'rolecolors'} = 1;
1.518 albertel 4455: }
1.632 raeburn 4456: } else {
4457: $legacy{'rolecolors'} = 1;
1.518 albertel 4458: }
1.948 raeburn 4459: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4460: if ($domconfig{'autoenroll'}{'co-owners'}) {
4461: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4462: }
4463: }
1.632 raeburn 4464: if (keys(%legacy) > 0) {
4465: my %legacyhash = &get_legacy_domconf($udom);
4466: foreach my $item (keys(%legacyhash)) {
4467: if ($item =~ /^\Q$udom\E\.login/) {
4468: if ($legacy{'login'}) {
4469: $designhash{$item} = $legacyhash{$item};
4470: }
4471: } else {
4472: if ($legacy{'rolecolors'}) {
4473: $designhash{$item} = $legacyhash{$item};
4474: }
1.518 albertel 4475: }
4476: }
4477: }
1.632 raeburn 4478: } else {
4479: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4480: }
4481: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4482: $cachetime);
4483: return %designhash;
4484: }
4485:
1.632 raeburn 4486: sub get_legacy_domconf {
4487: my ($udom) = @_;
4488: my %legacyhash;
4489: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4490: my $designfile = $designdir.'/'.$udom.'.tab';
4491: if (-e $designfile) {
4492: if ( open (my $fh,"<$designfile") ) {
4493: while (my $line = <$fh>) {
4494: next if ($line =~ /^\#/);
4495: chomp($line);
4496: my ($key,$val)=(split(/\=/,$line));
4497: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4498: }
4499: close($fh);
4500: }
4501: }
1.1026 raeburn 4502: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4503: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4504: }
4505: return %legacyhash;
4506: }
4507:
1.63 www 4508: =pod
4509:
1.112 bowersj2 4510: =item * &domainlogo()
1.63 www 4511:
4512: Inputs: $domain (usually will be undef)
4513:
4514: Returns: A link to a domain logo, if the domain logo exists.
4515: If the domain logo does not exist, a description of the domain.
4516:
4517: =cut
1.112 bowersj2 4518:
1.63 www 4519: ###############################################
4520: sub domainlogo {
1.517 raeburn 4521: my $domain = &determinedomain(shift);
1.518 albertel 4522: my %designhash = &get_domainconf($domain);
1.517 raeburn 4523: # See if there is a logo
4524: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4525: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4526: if ($imgsrc =~ m{^/(adm|res)/}) {
4527: if ($imgsrc =~ m{^/res/}) {
4528: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4529: &Apache::lonnet::repcopy($local_name);
4530: }
4531: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4532: }
4533: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4534: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4535: return &Apache::lonnet::domain($domain,'description');
1.59 www 4536: } else {
1.60 matthew 4537: return '';
1.59 www 4538: }
4539: }
1.63 www 4540: ##############################################
4541:
4542: =pod
4543:
1.112 bowersj2 4544: =item * &designparm()
1.63 www 4545:
4546: Inputs: $which parameter; $domain (usually will be undef)
4547:
4548: Returns: value of designparamter $which
4549:
4550: =cut
1.112 bowersj2 4551:
1.397 albertel 4552:
1.400 albertel 4553: ##############################################
1.397 albertel 4554: sub designparm {
4555: my ($which,$domain)=@_;
4556: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4557: return $env{'environment.color.'.$which};
1.96 www 4558: }
1.63 www 4559: $domain=&determinedomain($domain);
1.1016 raeburn 4560: my %domdesign;
4561: unless ($domain eq 'public') {
4562: %domdesign = &get_domainconf($domain);
4563: }
1.520 raeburn 4564: my $output;
1.517 raeburn 4565: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4566: $output = $domdesign{$domain.'.'.$which};
1.63 www 4567: } else {
1.520 raeburn 4568: $output = $defaultdesign{$which};
4569: }
4570: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4571: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4572: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4573: if ($output =~ m{^/res/}) {
4574: my $local_name = &Apache::lonnet::filelocation('',$output);
4575: &Apache::lonnet::repcopy($local_name);
4576: }
1.520 raeburn 4577: $output = &lonhttpdurl($output);
4578: }
1.63 www 4579: }
1.520 raeburn 4580: return $output;
1.63 www 4581: }
1.59 www 4582:
1.822 bisitz 4583: ##############################################
4584: =pod
4585:
1.832 bisitz 4586: =item * &authorspace()
4587:
1.1028 raeburn 4588: Inputs: $url (usually will be undef).
1.832 bisitz 4589:
1.1028 raeburn 4590: Returns: Path to Construction Space containing the resource or
4591: directory being viewed (or for which action is being taken).
4592: If $url is provided, and begins /priv/<domain>/<uname>
4593: the path will be that portion of the $context argument.
4594: Otherwise the path will be for the author space of the current
4595: user when the current role is author, or for that of the
4596: co-author/assistant co-author space when the current role
4597: is co-author or assistant co-author.
1.832 bisitz 4598:
4599: =cut
4600:
4601: sub authorspace {
1.1028 raeburn 4602: my ($url) = @_;
4603: if ($url ne '') {
4604: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4605: return $1;
4606: }
4607: }
1.832 bisitz 4608: my $caname = '';
1.1024 www 4609: my $cadom = '';
1.1028 raeburn 4610: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4611: ($cadom,$caname) =
1.832 bisitz 4612: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4613: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4614: $caname = $env{'user.name'};
1.1024 www 4615: $cadom = $env{'user.domain'};
1.832 bisitz 4616: }
1.1028 raeburn 4617: if (($caname ne '') && ($cadom ne '')) {
4618: return "/priv/$cadom/$caname/";
4619: }
4620: return;
1.832 bisitz 4621: }
4622:
4623: ##############################################
4624: =pod
4625:
1.822 bisitz 4626: =item * &head_subbox()
4627:
4628: Inputs: $content (contains HTML code with page functions, etc.)
4629:
4630: Returns: HTML div with $content
4631: To be included in page header
4632:
4633: =cut
4634:
4635: sub head_subbox {
4636: my ($content)=@_;
4637: my $output =
1.993 raeburn 4638: '<div class="LC_head_subbox">'
1.822 bisitz 4639: .$content
4640: .'</div>'
4641: }
4642:
4643: ##############################################
4644: =pod
4645:
4646: =item * &CSTR_pageheader()
4647:
1.1026 raeburn 4648: Input: (optional) filename from which breadcrumb trail is built.
4649: In most cases no input as needed, as $env{'request.filename'}
4650: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4651:
4652: Returns: HTML div with CSTR path and recent box
4653: To be included on Construction Space pages
4654:
4655: =cut
4656:
4657: sub CSTR_pageheader {
1.1026 raeburn 4658: my ($trailfile) = @_;
4659: if ($trailfile eq '') {
4660: $trailfile = $env{'request.filename'};
4661: }
4662:
4663: # this is for resources; directories have customtitle, and crumbs
4664: # and select recent are created in lonpubdir.pm
4665:
4666: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4667: my ($udom,$uname,$thisdisfn)=
1.1026 raeburn 4668: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)/(.*)$});
4669: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4670: $formaction =~ s{/+}{/}g;
1.822 bisitz 4671:
4672: my $parentpath = '';
4673: my $lastitem = '';
4674: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4675: $parentpath = $1;
4676: $lastitem = $2;
4677: } else {
4678: $lastitem = $thisdisfn;
4679: }
1.921 bisitz 4680:
4681: my $output =
1.822 bisitz 4682: '<div>'
4683: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4684: .'<b>'.&mt('Construction Space:').'</b> '
4685: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4686: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4687: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4688:
4689: if ($lastitem) {
4690: $output .=
4691: '<span class="LC_filename">'
4692: .$lastitem
4693: .'</span>';
4694: }
4695: $output .=
4696: '<br />'
1.822 bisitz 4697: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4698: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4699: .'</form>'
4700: .&Apache::lonmenu::constspaceform()
4701: .'</div>';
1.921 bisitz 4702:
4703: return $output;
1.822 bisitz 4704: }
4705:
1.60 matthew 4706: ###############################################
4707: ###############################################
4708:
4709: =pod
4710:
1.112 bowersj2 4711: =back
4712:
1.549 albertel 4713: =head1 HTML Helpers
1.112 bowersj2 4714:
4715: =over 4
4716:
4717: =item * &bodytag()
1.60 matthew 4718:
4719: Returns a uniform header for LON-CAPA web pages.
4720:
4721: Inputs:
4722:
1.112 bowersj2 4723: =over 4
4724:
4725: =item * $title, A title to be displayed on the page.
4726:
4727: =item * $function, the current role (can be undef).
4728:
4729: =item * $addentries, extra parameters for the <body> tag.
4730:
4731: =item * $bodyonly, if defined, only return the <body> tag.
4732:
4733: =item * $domain, if defined, force a given domain.
4734:
4735: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4736: text interface only)
1.60 matthew 4737:
1.814 bisitz 4738: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4739: navigational links
1.317 albertel 4740:
1.338 albertel 4741: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4742:
1.460 albertel 4743: =item * $args, optional argument valid values are
4744: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4745: inherit_jsmath -> when creating popup window in a page,
4746: should it have jsmath forced on by the
4747: current page
1.460 albertel 4748:
1.112 bowersj2 4749: =back
4750:
1.60 matthew 4751: Returns: A uniform header for LON-CAPA web pages.
4752: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4753: If $bodyonly is undef or zero, an html string containing a <body> tag and
4754: other decorations will be returned.
4755:
4756: =cut
4757:
1.54 www 4758: sub bodytag {
1.831 bisitz 4759: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962 droeschl 4760: $no_nav_bar,$bgcolor,$args)=@_;
1.339 albertel 4761:
1.954 raeburn 4762: my $public;
4763: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4764: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4765: $public = 1;
4766: }
1.460 albertel 4767: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4768:
1.183 matthew 4769: $function = &get_users_function() if (!$function);
1.339 albertel 4770: my $img = &designparm($function.'.img',$domain);
4771: my $font = &designparm($function.'.font',$domain);
4772: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4773:
1.803 bisitz 4774: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4775: 'bgcolor' => $pgbg,
1.339 albertel 4776: 'text' => $font,
4777: 'alink' => &designparm($function.'.alink',$domain),
4778: 'vlink' => &designparm($function.'.vlink',$domain),
4779: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4780: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4781:
1.63 www 4782: # role and realm
1.378 raeburn 4783: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4784: if ($role eq 'ca') {
1.479 albertel 4785: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4786: $realm = &plainname($rname,$rdom);
1.378 raeburn 4787: }
1.55 www 4788: # realm
1.258 albertel 4789: if ($env{'request.course.id'}) {
1.378 raeburn 4790: if ($env{'request.role'} !~ /^cr/) {
4791: $role = &Apache::lonnet::plaintext($role,&course_type());
4792: }
1.898 raeburn 4793: if ($env{'request.course.sec'}) {
4794: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4795: }
1.359 albertel 4796: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4797: } else {
4798: $role = &Apache::lonnet::plaintext($role);
1.54 www 4799: }
1.433 albertel 4800:
1.359 albertel 4801: if (!$realm) { $realm=' '; }
1.330 albertel 4802:
1.438 albertel 4803: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4804:
1.101 www 4805: # construct main body tag
1.359 albertel 4806: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4807: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4808:
1.530 albertel 4809: if ($bodyonly) {
1.60 matthew 4810: return $bodytag;
1.798 tempelho 4811: }
1.359 albertel 4812:
1.410 albertel 4813: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 4814: if ($public) {
1.433 albertel 4815: undef($role);
1.434 albertel 4816: } else {
4817: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4818: }
1.359 albertel 4819:
1.762 bisitz 4820: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4821: #
4822: # Extra info if you are the DC
4823: my $dc_info = '';
4824: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4825: $env{'course.'.$env{'request.course.id'}.
4826: '.domain'}.'/'})) {
4827: my $cid = $env{'request.course.id'};
1.917 raeburn 4828: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4829: $dc_info =~ s/\s+$//;
1.359 albertel 4830: }
4831:
1.898 raeburn 4832: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4833: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4834:
1.916 droeschl 4835: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4836: return $bodytag;
4837: }
1.903 droeschl 4838:
4839: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4840:
4841: # if ($env{'request.state'} eq 'construct') {
4842: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4843: # }
4844:
1.359 albertel 4845:
4846:
1.916 droeschl 4847: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4848: if ($dc_info) {
4849: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4850: }
1.916 droeschl 4851: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4852: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4853: return $bodytag;
4854: }
1.894 droeschl 4855:
1.927 raeburn 4856: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4857: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4858: }
1.916 droeschl 4859:
1.903 droeschl 4860: $bodytag .= Apache::lonhtmlcommon::scripttag(
4861: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4862:
1.903 droeschl 4863: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4864:
1.917 raeburn 4865: if ($dc_info) {
4866: $dc_info = &dc_courseid_toggle($dc_info);
4867: }
4868: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4869:
1.903 droeschl 4870: #don't show menus for public users
1.954 raeburn 4871: if (!$public){
1.903 droeschl 4872: $bodytag .= Apache::lonmenu::secondary_menu();
4873: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4874: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4875: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 4876: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 4877: $args->{'bread_crumbs'});
4878: } elsif ($forcereg) {
4879: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4880: }
1.903 droeschl 4881: }else{
4882: # this is to seperate menu from content when there's no secondary
4883: # menu. Especially needed for public accessible ressources.
4884: $bodytag .= '<hr style="clear:both" />';
4885: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4886: }
1.903 droeschl 4887:
1.235 raeburn 4888: return $bodytag;
1.182 matthew 4889: }
4890:
1.917 raeburn 4891: sub dc_courseid_toggle {
4892: my ($dc_info) = @_;
1.980 raeburn 4893: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4894: '<a href="javascript:showCourseID();">'.
4895: &mt('(More ...)').'</a></span>'.
4896: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4897: }
4898:
1.330 albertel 4899: sub make_attr_string {
4900: my ($register,$attr_ref) = @_;
4901:
4902: if ($attr_ref && !ref($attr_ref)) {
4903: die("addentries Must be a hash ref ".
4904: join(':',caller(1))." ".
4905: join(':',caller(0))." ");
4906: }
4907:
4908: if ($register) {
1.339 albertel 4909: my ($on_load,$on_unload);
4910: foreach my $key (keys(%{$attr_ref})) {
4911: if (lc($key) eq 'onload') {
4912: $on_load.=$attr_ref->{$key}.';';
4913: delete($attr_ref->{$key});
4914:
4915: } elsif (lc($key) eq 'onunload') {
4916: $on_unload.=$attr_ref->{$key}.';';
4917: delete($attr_ref->{$key});
4918: }
4919: }
1.953 droeschl 4920: $attr_ref->{'onload'} = $on_load;
4921: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 4922: }
1.339 albertel 4923:
1.330 albertel 4924: my $attr_string;
4925: foreach my $attr (keys(%$attr_ref)) {
4926: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4927: }
4928: return $attr_string;
4929: }
4930:
4931:
1.182 matthew 4932: ###############################################
1.251 albertel 4933: ###############################################
4934:
4935: =pod
4936:
4937: =item * &endbodytag()
4938:
4939: Returns a uniform footer for LON-CAPA web pages.
4940:
1.635 raeburn 4941: Inputs: 1 - optional reference to an args hash
4942: If in the hash, key for noredirectlink has a value which evaluates to true,
4943: a 'Continue' link is not displayed if the page contains an
4944: internal redirect in the <head></head> section,
4945: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4946:
4947: =cut
4948:
4949: sub endbodytag {
1.635 raeburn 4950: my ($args) = @_;
1.251 albertel 4951: my $endbodytag='</body>';
1.269 albertel 4952: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4953: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4954: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4955: $endbodytag=
4956: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4957: &mt('Continue').'</a>'.
4958: $endbodytag;
4959: }
1.315 albertel 4960: }
1.251 albertel 4961: return $endbodytag;
4962: }
4963:
1.352 albertel 4964: =pod
4965:
4966: =item * &standard_css()
4967:
4968: Returns a style sheet
4969:
4970: Inputs: (all optional)
4971: domain -> force to color decorate a page for a specific
4972: domain
4973: function -> force usage of a specific rolish color scheme
4974: bgcolor -> override the default page bgcolor
4975:
4976: =cut
4977:
1.343 albertel 4978: sub standard_css {
1.345 albertel 4979: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4980: $function = &get_users_function() if (!$function);
4981: my $img = &designparm($function.'.img', $domain);
4982: my $tabbg = &designparm($function.'.tabbg', $domain);
4983: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4984: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4985: #second colour for later usage
1.345 albertel 4986: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4987: my $pgbg_or_bgcolor =
4988: $bgcolor ||
1.352 albertel 4989: &designparm($function.'.pgbg', $domain);
1.382 albertel 4990: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4991: my $alink = &designparm($function.'.alink', $domain);
4992: my $vlink = &designparm($function.'.vlink', $domain);
4993: my $link = &designparm($function.'.link', $domain);
4994:
1.602 albertel 4995: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4996: my $mono = 'monospace';
1.850 bisitz 4997: my $data_table_head = $sidebg;
4998: my $data_table_light = '#FAFAFA';
4999: my $data_table_dark = '#F0F0F0';
1.470 banghart 5000: my $data_table_darker = '#CCCCCC';
1.349 albertel 5001: my $data_table_highlight = '#FFFF00';
1.352 albertel 5002: my $mail_new = '#FFBB77';
5003: my $mail_new_hover = '#DD9955';
5004: my $mail_read = '#BBBB77';
5005: my $mail_read_hover = '#999944';
5006: my $mail_replied = '#AAAA88';
5007: my $mail_replied_hover = '#888855';
5008: my $mail_other = '#99BBBB';
5009: my $mail_other_hover = '#669999';
1.391 albertel 5010: my $table_header = '#DDDDDD';
1.489 raeburn 5011: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5012: my $lg_border_color = '#C8C8C8';
1.952 onken 5013: my $button_hover = '#BF2317';
1.392 albertel 5014:
1.608 albertel 5015: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5016: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5017: : '0 3px 0 4px';
1.448 albertel 5018:
1.523 albertel 5019:
1.343 albertel 5020: return <<END;
1.947 droeschl 5021:
5022: /* needed for iframe to allow 100% height in FF */
5023: body, html {
5024: margin: 0;
5025: padding: 0 0.5%;
5026: height: 99%; /* to avoid scrollbars */
5027: }
5028:
1.795 www 5029: body {
1.911 bisitz 5030: font-family: $sans;
5031: line-height:130%;
5032: font-size:0.83em;
5033: color:$font;
1.795 www 5034: }
5035:
1.959 onken 5036: a:focus,
5037: a:focus img {
1.795 www 5038: color: red;
1.911 bisitz 5039: background: yellow;
1.795 www 5040: }
1.698 harmsja 5041:
1.911 bisitz 5042: form, .inline {
5043: display: inline;
1.795 www 5044: }
1.721 harmsja 5045:
1.795 www 5046: .LC_right {
1.911 bisitz 5047: text-align:right;
1.795 www 5048: }
5049:
5050: .LC_middle {
1.911 bisitz 5051: vertical-align:middle;
1.795 www 5052: }
1.721 harmsja 5053:
1.911 bisitz 5054: .LC_400Box {
5055: width:400px;
5056: }
1.721 harmsja 5057:
1.947 droeschl 5058: .LC_iframecontainer {
5059: width: 98%;
5060: margin: 0;
5061: position: fixed;
5062: top: 8.5em;
5063: bottom: 0;
5064: }
5065:
5066: .LC_iframecontainer iframe{
5067: border: none;
5068: width: 100%;
5069: height: 100%;
5070: }
5071:
1.778 bisitz 5072: .LC_filename {
5073: font-family: $mono;
5074: white-space:pre;
1.921 bisitz 5075: font-size: 120%;
1.778 bisitz 5076: }
5077:
5078: .LC_fileicon {
5079: border: none;
5080: height: 1.3em;
5081: vertical-align: text-bottom;
5082: margin-right: 0.3em;
5083: text-decoration:none;
5084: }
5085:
1.1008 www 5086: .LC_setting {
5087: text-decoration:underline;
5088: }
5089:
1.350 albertel 5090: .LC_error {
5091: color: red;
5092: font-size: larger;
5093: }
1.795 www 5094:
1.457 albertel 5095: .LC_warning,
5096: .LC_diff_removed {
1.733 bisitz 5097: color: red;
1.394 albertel 5098: }
1.532 albertel 5099:
5100: .LC_info,
1.457 albertel 5101: .LC_success,
5102: .LC_diff_added {
1.350 albertel 5103: color: green;
5104: }
1.795 www 5105:
1.802 bisitz 5106: div.LC_confirm_box {
5107: background-color: #FAFAFA;
5108: border: 1px solid $lg_border_color;
5109: margin-right: 0;
5110: padding: 5px;
5111: }
5112:
5113: div.LC_confirm_box .LC_error img,
5114: div.LC_confirm_box .LC_success img {
5115: vertical-align: middle;
5116: }
5117:
1.440 albertel 5118: .LC_icon {
1.771 droeschl 5119: border: none;
1.790 droeschl 5120: vertical-align: middle;
1.771 droeschl 5121: }
5122:
1.543 albertel 5123: .LC_docs_spacer {
5124: width: 25px;
5125: height: 1px;
1.771 droeschl 5126: border: none;
1.543 albertel 5127: }
1.346 albertel 5128:
1.532 albertel 5129: .LC_internal_info {
1.735 bisitz 5130: color: #999999;
1.532 albertel 5131: }
5132:
1.794 www 5133: .LC_discussion {
1.911 bisitz 5134: background: $tabbg;
5135: border: 1px solid black;
5136: margin: 2px;
1.794 www 5137: }
5138:
5139: .LC_disc_action_links_bar {
1.911 bisitz 5140: background: $tabbg;
5141: border: none;
5142: margin: 4px;
1.794 www 5143: }
5144:
5145: .LC_disc_action_left {
1.911 bisitz 5146: text-align: left;
1.794 www 5147: }
5148:
5149: .LC_disc_action_right {
1.911 bisitz 5150: text-align: right;
1.794 www 5151: }
5152:
5153: .LC_disc_new_item {
1.911 bisitz 5154: background: white;
5155: border: 2px solid red;
5156: margin: 2px;
1.794 www 5157: }
5158:
5159: .LC_disc_old_item {
1.911 bisitz 5160: background: white;
5161: border: 1px solid black;
5162: margin: 2px;
1.794 www 5163: }
5164:
1.458 albertel 5165: table.LC_pastsubmission {
5166: border: 1px solid black;
5167: margin: 2px;
5168: }
5169:
1.924 bisitz 5170: table#LC_menubuttons {
1.345 albertel 5171: width: 100%;
5172: background: $pgbg;
1.392 albertel 5173: border: 2px;
1.402 albertel 5174: border-collapse: separate;
1.803 bisitz 5175: padding: 0;
1.345 albertel 5176: }
1.392 albertel 5177:
1.801 tempelho 5178: table#LC_title_bar a {
5179: color: $fontmenu;
5180: }
1.836 bisitz 5181:
1.807 droeschl 5182: table#LC_title_bar {
1.819 tempelho 5183: clear: both;
1.836 bisitz 5184: display: none;
1.807 droeschl 5185: }
5186:
1.795 www 5187: table#LC_title_bar,
1.933 droeschl 5188: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5189: table#LC_title_bar.LC_with_remote {
1.359 albertel 5190: width: 100%;
1.392 albertel 5191: border-color: $pgbg;
5192: border-style: solid;
5193: border-width: $border;
1.379 albertel 5194: background: $pgbg;
1.801 tempelho 5195: color: $fontmenu;
1.392 albertel 5196: border-collapse: collapse;
1.803 bisitz 5197: padding: 0;
1.819 tempelho 5198: margin: 0;
1.359 albertel 5199: }
1.795 www 5200:
1.933 droeschl 5201: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5202: margin: 0;
5203: padding: 0;
1.933 droeschl 5204: position: relative;
5205: list-style: none;
1.913 droeschl 5206: }
1.933 droeschl 5207: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5208: display: inline;
5209: }
1.933 droeschl 5210:
5211: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5212: padding: 0;
1.933 droeschl 5213: margin: 0;
5214: float: left;
1.913 droeschl 5215: }
1.933 droeschl 5216: .LC_breadcrumb_tools_tools {
5217: padding: 0;
5218: margin: 0;
1.913 droeschl 5219: float: right;
5220: }
5221:
1.359 albertel 5222: table#LC_title_bar td {
5223: background: $tabbg;
5224: }
1.795 www 5225:
1.911 bisitz 5226: table#LC_menubuttons img {
1.803 bisitz 5227: border: none;
1.346 albertel 5228: }
1.795 www 5229:
1.842 droeschl 5230: .LC_breadcrumbs_component {
1.911 bisitz 5231: float: right;
5232: margin: 0 1em;
1.357 albertel 5233: }
1.842 droeschl 5234: .LC_breadcrumbs_component img {
1.911 bisitz 5235: vertical-align: middle;
1.777 tempelho 5236: }
1.795 www 5237:
1.383 albertel 5238: td.LC_table_cell_checkbox {
5239: text-align: center;
5240: }
1.795 www 5241:
5242: .LC_fontsize_small {
1.911 bisitz 5243: font-size: 70%;
1.705 tempelho 5244: }
5245:
1.844 bisitz 5246: #LC_breadcrumbs {
1.911 bisitz 5247: clear:both;
5248: background: $sidebg;
5249: border-bottom: 1px solid $lg_border_color;
5250: line-height: 2.5em;
1.933 droeschl 5251: overflow: hidden;
1.911 bisitz 5252: margin: 0;
5253: padding: 0;
1.995 raeburn 5254: text-align: left;
1.819 tempelho 5255: }
1.862 bisitz 5256:
1.993 raeburn 5257: .LC_head_subbox {
1.911 bisitz 5258: clear:both;
5259: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5260: border: 1px solid $sidebg;
5261: margin: 0 0 10px 0;
1.966 bisitz 5262: padding: 3px;
1.995 raeburn 5263: text-align: left;
1.822 bisitz 5264: }
5265:
1.795 www 5266: .LC_fontsize_medium {
1.911 bisitz 5267: font-size: 85%;
1.705 tempelho 5268: }
5269:
1.795 www 5270: .LC_fontsize_large {
1.911 bisitz 5271: font-size: 120%;
1.705 tempelho 5272: }
5273:
1.346 albertel 5274: .LC_menubuttons_inline_text {
5275: color: $font;
1.698 harmsja 5276: font-size: 90%;
1.701 harmsja 5277: padding-left:3px;
1.346 albertel 5278: }
5279:
1.934 droeschl 5280: .LC_menubuttons_inline_text img{
5281: vertical-align: middle;
5282: }
5283:
1.951 onken 5284: li.LC_menubuttons_inline_text img,a {
5285: cursor:pointer;
1.1002 droeschl 5286: text-decoration: none;
1.951 onken 5287: }
5288:
1.526 www 5289: .LC_menubuttons_link {
5290: text-decoration: none;
5291: }
1.795 www 5292:
1.522 albertel 5293: .LC_menubuttons_category {
1.521 www 5294: color: $font;
1.526 www 5295: background: $pgbg;
1.521 www 5296: font-size: larger;
5297: font-weight: bold;
5298: }
5299:
1.346 albertel 5300: td.LC_menubuttons_text {
1.911 bisitz 5301: color: $font;
1.346 albertel 5302: }
1.706 harmsja 5303:
1.346 albertel 5304: .LC_current_location {
5305: background: $tabbg;
5306: }
1.795 www 5307:
1.938 bisitz 5308: table.LC_data_table {
1.347 albertel 5309: border: 1px solid #000000;
1.402 albertel 5310: border-collapse: separate;
1.426 albertel 5311: border-spacing: 1px;
1.610 albertel 5312: background: $pgbg;
1.347 albertel 5313: }
1.795 www 5314:
1.422 albertel 5315: .LC_data_table_dense {
5316: font-size: small;
5317: }
1.795 www 5318:
1.507 raeburn 5319: table.LC_nested_outer {
5320: border: 1px solid #000000;
1.589 raeburn 5321: border-collapse: collapse;
1.803 bisitz 5322: border-spacing: 0;
1.507 raeburn 5323: width: 100%;
5324: }
1.795 www 5325:
1.879 raeburn 5326: table.LC_innerpickbox,
1.507 raeburn 5327: table.LC_nested {
1.803 bisitz 5328: border: none;
1.589 raeburn 5329: border-collapse: collapse;
1.803 bisitz 5330: border-spacing: 0;
1.507 raeburn 5331: width: 100%;
5332: }
1.795 www 5333:
1.911 bisitz 5334: table.LC_data_table tr th,
5335: table.LC_calendar tr th,
1.879 raeburn 5336: table.LC_prior_tries tr th,
5337: table.LC_innerpickbox tr th {
1.349 albertel 5338: font-weight: bold;
5339: background-color: $data_table_head;
1.801 tempelho 5340: color:$fontmenu;
1.701 harmsja 5341: font-size:90%;
1.347 albertel 5342: }
1.795 www 5343:
1.879 raeburn 5344: table.LC_innerpickbox tr th,
5345: table.LC_innerpickbox tr td {
5346: vertical-align: top;
5347: }
5348:
1.711 raeburn 5349: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5350: background-color: #CCCCCC;
1.711 raeburn 5351: font-weight: bold;
5352: text-align: left;
5353: }
1.795 www 5354:
1.912 bisitz 5355: table.LC_data_table tr.LC_odd_row > td {
5356: background-color: $data_table_light;
5357: padding: 2px;
5358: vertical-align: top;
5359: }
5360:
1.809 bisitz 5361: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5362: background-color: $data_table_light;
1.912 bisitz 5363: vertical-align: top;
5364: }
5365:
5366: table.LC_data_table tr.LC_even_row > td {
5367: background-color: $data_table_dark;
1.425 albertel 5368: padding: 2px;
1.900 bisitz 5369: vertical-align: top;
1.347 albertel 5370: }
1.795 www 5371:
1.809 bisitz 5372: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5373: background-color: $data_table_dark;
1.900 bisitz 5374: vertical-align: top;
1.347 albertel 5375: }
1.795 www 5376:
1.425 albertel 5377: table.LC_data_table tr.LC_data_table_highlight td {
5378: background-color: $data_table_darker;
5379: }
1.795 www 5380:
1.639 raeburn 5381: table.LC_data_table tr td.LC_leftcol_header {
5382: background-color: $data_table_head;
5383: font-weight: bold;
5384: }
1.795 www 5385:
1.451 albertel 5386: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5387: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5388: font-weight: bold;
5389: font-style: italic;
5390: text-align: center;
5391: padding: 8px;
1.347 albertel 5392: }
1.795 www 5393:
1.940 bisitz 5394: table.LC_data_table tr.LC_empty_row td {
5395: background-color: $sidebg;
5396: }
5397:
5398: table.LC_nested tr.LC_empty_row td {
5399: background-color: #FFFFFF;
5400: }
5401:
1.890 droeschl 5402: table.LC_caption {
5403: }
5404:
1.507 raeburn 5405: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5406: padding: 4ex
5407: }
1.795 www 5408:
1.507 raeburn 5409: table.LC_nested_outer tr th {
5410: font-weight: bold;
1.801 tempelho 5411: color:$fontmenu;
1.507 raeburn 5412: background-color: $data_table_head;
1.701 harmsja 5413: font-size: small;
1.507 raeburn 5414: border-bottom: 1px solid #000000;
5415: }
1.795 www 5416:
1.507 raeburn 5417: table.LC_nested_outer tr td.LC_subheader {
5418: background-color: $data_table_head;
5419: font-weight: bold;
5420: font-size: small;
5421: border-bottom: 1px solid #000000;
5422: text-align: right;
1.451 albertel 5423: }
1.795 www 5424:
1.507 raeburn 5425: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5426: background-color: #CCCCCC;
1.451 albertel 5427: font-weight: bold;
5428: font-size: small;
1.507 raeburn 5429: text-align: center;
5430: }
1.795 www 5431:
1.589 raeburn 5432: table.LC_nested tr.LC_info_row td.LC_left_item,
5433: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5434: text-align: left;
1.451 albertel 5435: }
1.795 www 5436:
1.507 raeburn 5437: table.LC_nested td {
1.735 bisitz 5438: background-color: #FFFFFF;
1.451 albertel 5439: font-size: small;
1.507 raeburn 5440: }
1.795 www 5441:
1.507 raeburn 5442: table.LC_nested_outer tr th.LC_right_item,
5443: table.LC_nested tr.LC_info_row td.LC_right_item,
5444: table.LC_nested tr.LC_odd_row td.LC_right_item,
5445: table.LC_nested tr td.LC_right_item {
1.451 albertel 5446: text-align: right;
5447: }
5448:
1.507 raeburn 5449: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5450: background-color: #EEEEEE;
1.451 albertel 5451: }
5452:
1.473 raeburn 5453: table.LC_createuser {
5454: }
5455:
5456: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5457: font-size: small;
1.473 raeburn 5458: }
5459:
5460: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5461: background-color: #CCCCCC;
1.473 raeburn 5462: font-weight: bold;
5463: text-align: center;
5464: }
5465:
1.349 albertel 5466: table.LC_calendar {
5467: border: 1px solid #000000;
5468: border-collapse: collapse;
1.917 raeburn 5469: width: 98%;
1.349 albertel 5470: }
1.795 www 5471:
1.349 albertel 5472: table.LC_calendar_pickdate {
5473: font-size: xx-small;
5474: }
1.795 www 5475:
1.349 albertel 5476: table.LC_calendar tr td {
5477: border: 1px solid #000000;
5478: vertical-align: top;
1.917 raeburn 5479: width: 14%;
1.349 albertel 5480: }
1.795 www 5481:
1.349 albertel 5482: table.LC_calendar tr td.LC_calendar_day_empty {
5483: background-color: $data_table_dark;
5484: }
1.795 www 5485:
1.779 bisitz 5486: table.LC_calendar tr td.LC_calendar_day_current {
5487: background-color: $data_table_highlight;
1.777 tempelho 5488: }
1.795 www 5489:
1.938 bisitz 5490: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5491: background-color: $mail_new;
5492: }
1.795 www 5493:
1.938 bisitz 5494: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5495: background-color: $mail_new_hover;
5496: }
1.795 www 5497:
1.938 bisitz 5498: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5499: background-color: $mail_read;
5500: }
1.795 www 5501:
1.938 bisitz 5502: /*
5503: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5504: background-color: $mail_read_hover;
5505: }
1.938 bisitz 5506: */
1.795 www 5507:
1.938 bisitz 5508: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5509: background-color: $mail_replied;
5510: }
1.795 www 5511:
1.938 bisitz 5512: /*
5513: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5514: background-color: $mail_replied_hover;
5515: }
1.938 bisitz 5516: */
1.795 www 5517:
1.938 bisitz 5518: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5519: background-color: $mail_other;
5520: }
1.795 www 5521:
1.938 bisitz 5522: /*
5523: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5524: background-color: $mail_other_hover;
5525: }
1.938 bisitz 5526: */
1.494 raeburn 5527:
1.777 tempelho 5528: table.LC_data_table tr > td.LC_browser_file,
5529: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5530: background: #AAEE77;
1.389 albertel 5531: }
1.795 www 5532:
1.777 tempelho 5533: table.LC_data_table tr > td.LC_browser_file_locked,
5534: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5535: background: #FFAA99;
1.387 albertel 5536: }
1.795 www 5537:
1.777 tempelho 5538: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5539: background: #888888;
1.779 bisitz 5540: }
1.795 www 5541:
1.777 tempelho 5542: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5543: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5544: background: #F8F866;
1.777 tempelho 5545: }
1.795 www 5546:
1.696 bisitz 5547: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5548: background: #E0E8FF;
1.387 albertel 5549: }
1.696 bisitz 5550:
1.707 bisitz 5551: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5552: /* background: #77FF77; */
1.707 bisitz 5553: }
1.795 www 5554:
1.707 bisitz 5555: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5556: border-right: 8px solid #FFFF77;
1.707 bisitz 5557: }
1.795 www 5558:
1.707 bisitz 5559: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5560: border-right: 8px solid #FFAA77;
1.707 bisitz 5561: }
1.795 www 5562:
1.707 bisitz 5563: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5564: border-right: 8px solid #FF7777;
1.707 bisitz 5565: }
1.795 www 5566:
1.707 bisitz 5567: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5568: border-right: 8px solid #AAFF77;
1.707 bisitz 5569: }
1.795 www 5570:
1.707 bisitz 5571: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5572: border-right: 8px solid #11CC55;
1.707 bisitz 5573: }
5574:
1.388 albertel 5575: span.LC_current_location {
1.701 harmsja 5576: font-size:larger;
1.388 albertel 5577: background: $pgbg;
5578: }
1.387 albertel 5579:
1.395 albertel 5580: span.LC_parm_menu_item {
5581: font-size: larger;
5582: }
1.795 www 5583:
1.395 albertel 5584: span.LC_parm_scope_all {
5585: color: red;
5586: }
1.795 www 5587:
1.395 albertel 5588: span.LC_parm_scope_folder {
5589: color: green;
5590: }
1.795 www 5591:
1.395 albertel 5592: span.LC_parm_scope_resource {
5593: color: orange;
5594: }
1.795 www 5595:
1.395 albertel 5596: span.LC_parm_part {
5597: color: blue;
5598: }
1.795 www 5599:
1.911 bisitz 5600: span.LC_parm_folder,
5601: span.LC_parm_symb {
1.395 albertel 5602: font-size: x-small;
5603: font-family: $mono;
5604: color: #AAAAAA;
5605: }
5606:
1.977 bisitz 5607: ul.LC_parm_parmlist li {
5608: display: inline-block;
5609: padding: 0.3em 0.8em;
5610: vertical-align: top;
5611: width: 150px;
5612: border-top:1px solid $lg_border_color;
5613: }
5614:
1.795 www 5615: td.LC_parm_overview_level_menu,
5616: td.LC_parm_overview_map_menu,
5617: td.LC_parm_overview_parm_selectors,
5618: td.LC_parm_overview_restrictions {
1.396 albertel 5619: border: 1px solid black;
5620: border-collapse: collapse;
5621: }
1.795 www 5622:
1.396 albertel 5623: table.LC_parm_overview_restrictions td {
5624: border-width: 1px 4px 1px 4px;
5625: border-style: solid;
5626: border-color: $pgbg;
5627: text-align: center;
5628: }
1.795 www 5629:
1.396 albertel 5630: table.LC_parm_overview_restrictions th {
5631: background: $tabbg;
5632: border-width: 1px 4px 1px 4px;
5633: border-style: solid;
5634: border-color: $pgbg;
5635: }
1.795 www 5636:
1.398 albertel 5637: table#LC_helpmenu {
1.803 bisitz 5638: border: none;
1.398 albertel 5639: height: 55px;
1.803 bisitz 5640: border-spacing: 0;
1.398 albertel 5641: }
5642:
5643: table#LC_helpmenu fieldset legend {
5644: font-size: larger;
5645: }
1.795 www 5646:
1.397 albertel 5647: table#LC_helpmenu_links {
5648: width: 100%;
5649: border: 1px solid black;
5650: background: $pgbg;
1.803 bisitz 5651: padding: 0;
1.397 albertel 5652: border-spacing: 1px;
5653: }
1.795 www 5654:
1.397 albertel 5655: table#LC_helpmenu_links tr td {
5656: padding: 1px;
5657: background: $tabbg;
1.399 albertel 5658: text-align: center;
5659: font-weight: bold;
1.397 albertel 5660: }
1.396 albertel 5661:
1.795 www 5662: table#LC_helpmenu_links a:link,
5663: table#LC_helpmenu_links a:visited,
1.397 albertel 5664: table#LC_helpmenu_links a:active {
5665: text-decoration: none;
5666: color: $font;
5667: }
1.795 www 5668:
1.397 albertel 5669: table#LC_helpmenu_links a:hover {
5670: text-decoration: underline;
5671: color: $vlink;
5672: }
1.396 albertel 5673:
1.417 albertel 5674: .LC_chrt_popup_exists {
5675: border: 1px solid #339933;
5676: margin: -1px;
5677: }
1.795 www 5678:
1.417 albertel 5679: .LC_chrt_popup_up {
5680: border: 1px solid yellow;
5681: margin: -1px;
5682: }
1.795 www 5683:
1.417 albertel 5684: .LC_chrt_popup {
5685: border: 1px solid #8888FF;
5686: background: #CCCCFF;
5687: }
1.795 www 5688:
1.421 albertel 5689: table.LC_pick_box {
5690: border-collapse: separate;
5691: background: white;
5692: border: 1px solid black;
5693: border-spacing: 1px;
5694: }
1.795 www 5695:
1.421 albertel 5696: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5697: background: $sidebg;
1.421 albertel 5698: font-weight: bold;
1.900 bisitz 5699: text-align: left;
1.740 bisitz 5700: vertical-align: top;
1.421 albertel 5701: width: 184px;
5702: padding: 8px;
5703: }
1.795 www 5704:
1.579 raeburn 5705: table.LC_pick_box td.LC_pick_box_value {
5706: text-align: left;
5707: padding: 8px;
5708: }
1.795 www 5709:
1.579 raeburn 5710: table.LC_pick_box td.LC_pick_box_select {
5711: text-align: left;
5712: padding: 8px;
5713: }
1.795 www 5714:
1.424 albertel 5715: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5716: padding: 0;
1.421 albertel 5717: height: 1px;
5718: background: black;
5719: }
1.795 www 5720:
1.421 albertel 5721: table.LC_pick_box td.LC_pick_box_submit {
5722: text-align: right;
5723: }
1.795 www 5724:
1.579 raeburn 5725: table.LC_pick_box td.LC_evenrow_value {
5726: text-align: left;
5727: padding: 8px;
5728: background-color: $data_table_light;
5729: }
1.795 www 5730:
1.579 raeburn 5731: table.LC_pick_box td.LC_oddrow_value {
5732: text-align: left;
5733: padding: 8px;
5734: background-color: $data_table_light;
5735: }
1.795 www 5736:
1.579 raeburn 5737: span.LC_helpform_receipt_cat {
5738: font-weight: bold;
5739: }
1.795 www 5740:
1.424 albertel 5741: table.LC_group_priv_box {
5742: background: white;
5743: border: 1px solid black;
5744: border-spacing: 1px;
5745: }
1.795 www 5746:
1.424 albertel 5747: table.LC_group_priv_box td.LC_pick_box_title {
5748: background: $tabbg;
5749: font-weight: bold;
5750: text-align: right;
5751: width: 184px;
5752: }
1.795 www 5753:
1.424 albertel 5754: table.LC_group_priv_box td.LC_groups_fixed {
5755: background: $data_table_light;
5756: text-align: center;
5757: }
1.795 www 5758:
1.424 albertel 5759: table.LC_group_priv_box td.LC_groups_optional {
5760: background: $data_table_dark;
5761: text-align: center;
5762: }
1.795 www 5763:
1.424 albertel 5764: table.LC_group_priv_box td.LC_groups_functionality {
5765: background: $data_table_darker;
5766: text-align: center;
5767: font-weight: bold;
5768: }
1.795 www 5769:
1.424 albertel 5770: table.LC_group_priv td {
5771: text-align: left;
1.803 bisitz 5772: padding: 0;
1.424 albertel 5773: }
5774:
5775: .LC_navbuttons {
5776: margin: 2ex 0ex 2ex 0ex;
5777: }
1.795 www 5778:
1.423 albertel 5779: .LC_topic_bar {
5780: font-weight: bold;
5781: background: $tabbg;
1.918 wenzelju 5782: margin: 1em 0em 1em 2em;
1.805 bisitz 5783: padding: 3px;
1.918 wenzelju 5784: font-size: 1.2em;
1.423 albertel 5785: }
1.795 www 5786:
1.423 albertel 5787: .LC_topic_bar span {
1.918 wenzelju 5788: left: 0.5em;
5789: position: absolute;
1.423 albertel 5790: vertical-align: middle;
1.918 wenzelju 5791: font-size: 1.2em;
1.423 albertel 5792: }
1.795 www 5793:
1.423 albertel 5794: table.LC_course_group_status {
5795: margin: 20px;
5796: }
1.795 www 5797:
1.423 albertel 5798: table.LC_status_selector td {
5799: vertical-align: top;
5800: text-align: center;
1.424 albertel 5801: padding: 4px;
5802: }
1.795 www 5803:
1.599 albertel 5804: div.LC_feedback_link {
1.616 albertel 5805: clear: both;
1.829 kalberla 5806: background: $sidebg;
1.779 bisitz 5807: width: 100%;
1.829 kalberla 5808: padding-bottom: 10px;
5809: border: 1px $tabbg solid;
1.833 kalberla 5810: height: 22px;
5811: line-height: 22px;
5812: padding-top: 5px;
5813: }
5814:
5815: div.LC_feedback_link img {
5816: height: 22px;
1.867 kalberla 5817: vertical-align:middle;
1.829 kalberla 5818: }
5819:
1.911 bisitz 5820: div.LC_feedback_link a {
1.829 kalberla 5821: text-decoration: none;
1.489 raeburn 5822: }
1.795 www 5823:
1.867 kalberla 5824: div.LC_comblock {
1.911 bisitz 5825: display:inline;
1.867 kalberla 5826: color:$font;
5827: font-size:90%;
5828: }
5829:
5830: div.LC_feedback_link div.LC_comblock {
5831: padding-left:5px;
5832: }
5833:
5834: div.LC_feedback_link div.LC_comblock a {
5835: color:$font;
5836: }
5837:
1.489 raeburn 5838: span.LC_feedback_link {
1.858 bisitz 5839: /* background: $feedback_link_bg; */
1.599 albertel 5840: font-size: larger;
5841: }
1.795 www 5842:
1.599 albertel 5843: span.LC_message_link {
1.858 bisitz 5844: /* background: $feedback_link_bg; */
1.599 albertel 5845: font-size: larger;
5846: position: absolute;
5847: right: 1em;
1.489 raeburn 5848: }
1.421 albertel 5849:
1.515 albertel 5850: table.LC_prior_tries {
1.524 albertel 5851: border: 1px solid #000000;
5852: border-collapse: separate;
5853: border-spacing: 1px;
1.515 albertel 5854: }
1.523 albertel 5855:
1.515 albertel 5856: table.LC_prior_tries td {
1.524 albertel 5857: padding: 2px;
1.515 albertel 5858: }
1.523 albertel 5859:
5860: .LC_answer_correct {
1.795 www 5861: background: lightgreen;
5862: color: darkgreen;
5863: padding: 6px;
1.523 albertel 5864: }
1.795 www 5865:
1.523 albertel 5866: .LC_answer_charged_try {
1.797 www 5867: background: #FFAAAA;
1.795 www 5868: color: darkred;
5869: padding: 6px;
1.523 albertel 5870: }
1.795 www 5871:
1.779 bisitz 5872: .LC_answer_not_charged_try,
1.523 albertel 5873: .LC_answer_no_grade,
5874: .LC_answer_late {
1.795 www 5875: background: lightyellow;
1.523 albertel 5876: color: black;
1.795 www 5877: padding: 6px;
1.523 albertel 5878: }
1.795 www 5879:
1.523 albertel 5880: .LC_answer_previous {
1.795 www 5881: background: lightblue;
5882: color: darkblue;
5883: padding: 6px;
1.523 albertel 5884: }
1.795 www 5885:
1.779 bisitz 5886: .LC_answer_no_message {
1.777 tempelho 5887: background: #FFFFFF;
5888: color: black;
1.795 www 5889: padding: 6px;
1.779 bisitz 5890: }
1.795 www 5891:
1.779 bisitz 5892: .LC_answer_unknown {
5893: background: orange;
5894: color: black;
1.795 www 5895: padding: 6px;
1.777 tempelho 5896: }
1.795 www 5897:
1.529 albertel 5898: span.LC_prior_numerical,
5899: span.LC_prior_string,
5900: span.LC_prior_custom,
5901: span.LC_prior_reaction,
5902: span.LC_prior_math {
1.925 bisitz 5903: font-family: $mono;
1.523 albertel 5904: white-space: pre;
5905: }
5906:
1.525 albertel 5907: span.LC_prior_string {
1.925 bisitz 5908: font-family: $mono;
1.525 albertel 5909: white-space: pre;
5910: }
5911:
1.523 albertel 5912: table.LC_prior_option {
5913: width: 100%;
5914: border-collapse: collapse;
5915: }
1.795 www 5916:
1.911 bisitz 5917: table.LC_prior_rank,
1.795 www 5918: table.LC_prior_match {
1.528 albertel 5919: border-collapse: collapse;
5920: }
1.795 www 5921:
1.528 albertel 5922: table.LC_prior_option tr td,
5923: table.LC_prior_rank tr td,
5924: table.LC_prior_match tr td {
1.524 albertel 5925: border: 1px solid #000000;
1.515 albertel 5926: }
5927:
1.855 bisitz 5928: .LC_nobreak {
1.544 albertel 5929: white-space: nowrap;
1.519 raeburn 5930: }
5931:
1.576 raeburn 5932: span.LC_cusr_emph {
5933: font-style: italic;
5934: }
5935:
1.633 raeburn 5936: span.LC_cusr_subheading {
5937: font-weight: normal;
5938: font-size: 85%;
5939: }
5940:
1.861 bisitz 5941: div.LC_docs_entry_move {
1.859 bisitz 5942: border: 1px solid #BBBBBB;
1.545 albertel 5943: background: #DDDDDD;
1.861 bisitz 5944: width: 22px;
1.859 bisitz 5945: padding: 1px;
5946: margin: 0;
1.545 albertel 5947: }
5948:
1.861 bisitz 5949: table.LC_data_table tr > td.LC_docs_entry_commands,
5950: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5951: background: #DDDDDD;
5952: font-size: x-small;
5953: }
1.795 www 5954:
1.861 bisitz 5955: .LC_docs_entry_parameter {
5956: white-space: nowrap;
5957: }
5958:
1.544 albertel 5959: .LC_docs_copy {
1.545 albertel 5960: color: #000099;
1.544 albertel 5961: }
1.795 www 5962:
1.544 albertel 5963: .LC_docs_cut {
1.545 albertel 5964: color: #550044;
1.544 albertel 5965: }
1.795 www 5966:
1.544 albertel 5967: .LC_docs_rename {
1.545 albertel 5968: color: #009900;
1.544 albertel 5969: }
1.795 www 5970:
1.544 albertel 5971: .LC_docs_remove {
1.545 albertel 5972: color: #990000;
5973: }
5974:
1.547 albertel 5975: .LC_docs_reinit_warn,
5976: .LC_docs_ext_edit {
5977: font-size: x-small;
5978: }
5979:
1.545 albertel 5980: table.LC_docs_adddocs td,
5981: table.LC_docs_adddocs th {
5982: border: 1px solid #BBBBBB;
5983: padding: 4px;
5984: background: #DDDDDD;
1.543 albertel 5985: }
5986:
1.584 albertel 5987: table.LC_sty_begin {
5988: background: #BBFFBB;
5989: }
1.795 www 5990:
1.584 albertel 5991: table.LC_sty_end {
5992: background: #FFBBBB;
5993: }
5994:
1.589 raeburn 5995: table.LC_double_column {
1.803 bisitz 5996: border-width: 0;
1.589 raeburn 5997: border-collapse: collapse;
5998: width: 100%;
5999: padding: 2px;
6000: }
6001:
6002: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6003: top: 2px;
1.589 raeburn 6004: left: 2px;
6005: width: 47%;
6006: vertical-align: top;
6007: }
6008:
6009: table.LC_double_column tr td.LC_right_col {
6010: top: 2px;
1.779 bisitz 6011: right: 2px;
1.589 raeburn 6012: width: 47%;
6013: vertical-align: top;
6014: }
6015:
1.591 raeburn 6016: div.LC_left_float {
6017: float: left;
6018: padding-right: 5%;
1.597 albertel 6019: padding-bottom: 4px;
1.591 raeburn 6020: }
6021:
6022: div.LC_clear_float_header {
1.597 albertel 6023: padding-bottom: 2px;
1.591 raeburn 6024: }
6025:
6026: div.LC_clear_float_footer {
1.597 albertel 6027: padding-top: 10px;
1.591 raeburn 6028: clear: both;
6029: }
6030:
1.597 albertel 6031: div.LC_grade_show_user {
1.941 bisitz 6032: /* border-left: 5px solid $sidebg; */
6033: border-top: 5px solid #000000;
6034: margin: 50px 0 0 0;
1.936 bisitz 6035: padding: 15px 0 5px 10px;
1.597 albertel 6036: }
1.795 www 6037:
1.936 bisitz 6038: div.LC_grade_show_user_odd_row {
1.941 bisitz 6039: /* border-left: 5px solid #000000; */
6040: }
6041:
6042: div.LC_grade_show_user div.LC_Box {
6043: margin-right: 50px;
1.597 albertel 6044: }
6045:
6046: div.LC_grade_submissions,
6047: div.LC_grade_message_center,
1.936 bisitz 6048: div.LC_grade_info_links {
1.597 albertel 6049: margin: 5px;
6050: width: 99%;
6051: background: #FFFFFF;
6052: }
1.795 www 6053:
1.597 albertel 6054: div.LC_grade_submissions_header,
1.936 bisitz 6055: div.LC_grade_message_center_header {
1.705 tempelho 6056: font-weight: bold;
6057: font-size: large;
1.597 albertel 6058: }
1.795 www 6059:
1.597 albertel 6060: div.LC_grade_submissions_body,
1.936 bisitz 6061: div.LC_grade_message_center_body {
1.597 albertel 6062: border: 1px solid black;
6063: width: 99%;
6064: background: #FFFFFF;
6065: }
1.795 www 6066:
1.613 albertel 6067: table.LC_scantron_action {
6068: width: 100%;
6069: }
1.795 www 6070:
1.613 albertel 6071: table.LC_scantron_action tr th {
1.698 harmsja 6072: font-weight:bold;
6073: font-style:normal;
1.613 albertel 6074: }
1.795 www 6075:
1.779 bisitz 6076: .LC_edit_problem_header,
1.614 albertel 6077: div.LC_edit_problem_footer {
1.705 tempelho 6078: font-weight: normal;
6079: font-size: medium;
1.602 albertel 6080: margin: 2px;
1.600 albertel 6081: }
1.795 www 6082:
1.600 albertel 6083: div.LC_edit_problem_header,
1.602 albertel 6084: div.LC_edit_problem_header div,
1.614 albertel 6085: div.LC_edit_problem_footer,
6086: div.LC_edit_problem_footer div,
1.602 albertel 6087: div.LC_edit_problem_editxml_header,
6088: div.LC_edit_problem_editxml_header div {
1.600 albertel 6089: margin-top: 5px;
6090: }
1.795 www 6091:
1.600 albertel 6092: div.LC_edit_problem_header_title {
1.705 tempelho 6093: font-weight: bold;
6094: font-size: larger;
1.602 albertel 6095: background: $tabbg;
6096: padding: 3px;
6097: }
1.795 www 6098:
1.602 albertel 6099: table.LC_edit_problem_header_title {
6100: width: 100%;
1.600 albertel 6101: background: $tabbg;
1.602 albertel 6102: }
6103:
6104: div.LC_edit_problem_discards {
6105: float: left;
6106: padding-bottom: 5px;
6107: }
1.795 www 6108:
1.602 albertel 6109: div.LC_edit_problem_saves {
6110: float: right;
6111: padding-bottom: 5px;
1.600 albertel 6112: }
1.795 www 6113:
1.911 bisitz 6114: img.stift {
1.803 bisitz 6115: border-width: 0;
6116: vertical-align: middle;
1.677 riegler 6117: }
1.680 riegler 6118:
1.923 bisitz 6119: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6120: vertical-align: top;
1.777 tempelho 6121: }
1.795 www 6122:
1.716 raeburn 6123: div.LC_createcourse {
1.911 bisitz 6124: margin: 10px 10px 10px 10px;
1.716 raeburn 6125: }
6126:
1.917 raeburn 6127: .LC_dccid {
6128: margin: 0.2em 0 0 0;
6129: padding: 0;
6130: font-size: 90%;
6131: display:none;
6132: }
6133:
1.698 harmsja 6134: a:hover,
1.897 wenzelju 6135: ol.LC_primary_menu a:hover,
1.721 harmsja 6136: ol#LC_MenuBreadcrumbs a:hover,
6137: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6138: ul#LC_secondary_menu a:hover,
1.721 harmsja 6139: .LC_FormSectionClearButton input:hover
1.795 www 6140: ul.LC_TabContent li:hover a {
1.952 onken 6141: color:$button_hover;
1.911 bisitz 6142: text-decoration:none;
1.693 droeschl 6143: }
6144:
1.779 bisitz 6145: h1 {
1.911 bisitz 6146: padding: 0;
6147: line-height:130%;
1.693 droeschl 6148: }
1.698 harmsja 6149:
1.911 bisitz 6150: h2,
6151: h3,
6152: h4,
6153: h5,
6154: h6 {
6155: margin: 5px 0 5px 0;
6156: padding: 0;
6157: line-height:130%;
1.693 droeschl 6158: }
1.795 www 6159:
6160: .LC_hcell {
1.911 bisitz 6161: padding:3px 15px 3px 15px;
6162: margin: 0;
6163: background-color:$tabbg;
6164: color:$fontmenu;
6165: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6166: }
1.795 www 6167:
1.840 bisitz 6168: .LC_Box > .LC_hcell {
1.911 bisitz 6169: margin: 0 -10px 10px -10px;
1.835 bisitz 6170: }
6171:
1.721 harmsja 6172: .LC_noBorder {
1.911 bisitz 6173: border: 0;
1.698 harmsja 6174: }
1.693 droeschl 6175:
1.721 harmsja 6176: .LC_FormSectionClearButton input {
1.911 bisitz 6177: background-color:transparent;
6178: border: none;
6179: cursor:pointer;
6180: text-decoration:underline;
1.693 droeschl 6181: }
1.763 bisitz 6182:
6183: .LC_help_open_topic {
1.911 bisitz 6184: color: #FFFFFF;
6185: background-color: #EEEEFF;
6186: margin: 1px;
6187: padding: 4px;
6188: border: 1px solid #000033;
6189: white-space: nowrap;
6190: /* vertical-align: middle; */
1.759 neumanie 6191: }
1.693 droeschl 6192:
1.911 bisitz 6193: dl,
6194: ul,
6195: div,
6196: fieldset {
6197: margin: 10px 10px 10px 0;
6198: /* overflow: hidden; */
1.693 droeschl 6199: }
1.795 www 6200:
1.838 bisitz 6201: fieldset > legend {
1.911 bisitz 6202: font-weight: bold;
6203: padding: 0 5px 0 5px;
1.838 bisitz 6204: }
6205:
1.813 bisitz 6206: #LC_nav_bar {
1.911 bisitz 6207: float: left;
1.995 raeburn 6208: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6209: margin: 0 0 2px 0;
1.807 droeschl 6210: }
6211:
1.916 droeschl 6212: #LC_realm {
6213: margin: 0.2em 0 0 0;
6214: padding: 0;
6215: font-weight: bold;
6216: text-align: center;
1.995 raeburn 6217: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6218: }
6219:
1.911 bisitz 6220: #LC_nav_bar em {
6221: font-weight: bold;
6222: font-style: normal;
1.807 droeschl 6223: }
6224:
1.897 wenzelju 6225: ol.LC_primary_menu {
1.911 bisitz 6226: float: right;
1.934 droeschl 6227: margin: 0;
1.995 raeburn 6228: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6229: }
6230:
1.852 droeschl 6231: ol#LC_PathBreadcrumbs {
1.911 bisitz 6232: margin: 0;
1.693 droeschl 6233: }
6234:
1.897 wenzelju 6235: ol.LC_primary_menu li {
1.911 bisitz 6236: display: inline;
6237: padding: 5px 5px 0 10px;
6238: vertical-align: top;
1.693 droeschl 6239: }
6240:
1.897 wenzelju 6241: ol.LC_primary_menu li img {
1.911 bisitz 6242: vertical-align: bottom;
1.934 droeschl 6243: height: 1.1em;
1.693 droeschl 6244: }
6245:
1.897 wenzelju 6246: ol.LC_primary_menu a {
1.911 bisitz 6247: color: RGB(80, 80, 80);
6248: text-decoration: none;
1.693 droeschl 6249: }
1.795 www 6250:
1.949 droeschl 6251: ol.LC_primary_menu a.LC_new_message {
6252: font-weight:bold;
6253: color: darkred;
6254: }
6255:
1.975 raeburn 6256: ol.LC_docs_parameters {
6257: margin-left: 0;
6258: padding: 0;
6259: list-style: none;
6260: }
6261:
6262: ol.LC_docs_parameters li {
6263: margin: 0;
6264: padding-right: 20px;
6265: display: inline;
6266: }
6267:
1.976 raeburn 6268: ol.LC_docs_parameters li:before {
6269: content: "\\002022 \\0020";
6270: }
6271:
6272: li.LC_docs_parameters_title {
6273: font-weight: bold;
6274: }
6275:
6276: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6277: content: "";
6278: }
6279:
1.897 wenzelju 6280: ul#LC_secondary_menu {
1.911 bisitz 6281: clear: both;
6282: color: $fontmenu;
6283: background: $tabbg;
6284: list-style: none;
6285: padding: 0;
6286: margin: 0;
6287: width: 100%;
1.995 raeburn 6288: text-align: left;
1.808 droeschl 6289: }
6290:
1.897 wenzelju 6291: ul#LC_secondary_menu li {
1.911 bisitz 6292: font-weight: bold;
6293: line-height: 1.8em;
6294: padding: 0 0.8em;
6295: border-right: 1px solid black;
6296: display: inline;
6297: vertical-align: middle;
1.807 droeschl 6298: }
6299:
1.847 tempelho 6300: ul.LC_TabContent {
1.911 bisitz 6301: display:block;
6302: background: $sidebg;
6303: border-bottom: solid 1px $lg_border_color;
6304: list-style:none;
1.1020 raeburn 6305: margin: -1px -10px 0 -10px;
1.911 bisitz 6306: padding: 0;
1.693 droeschl 6307: }
6308:
1.795 www 6309: ul.LC_TabContent li,
6310: ul.LC_TabContentBigger li {
1.911 bisitz 6311: float:left;
1.741 harmsja 6312: }
1.795 www 6313:
1.897 wenzelju 6314: ul#LC_secondary_menu li a {
1.911 bisitz 6315: color: $fontmenu;
6316: text-decoration: none;
1.693 droeschl 6317: }
1.795 www 6318:
1.721 harmsja 6319: ul.LC_TabContent {
1.952 onken 6320: min-height:20px;
1.721 harmsja 6321: }
1.795 www 6322:
6323: ul.LC_TabContent li {
1.911 bisitz 6324: vertical-align:middle;
1.959 onken 6325: padding: 0 16px 0 10px;
1.911 bisitz 6326: background-color:$tabbg;
6327: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6328: border-left: solid 1px $font;
1.721 harmsja 6329: }
1.795 www 6330:
1.847 tempelho 6331: ul.LC_TabContent .right {
1.911 bisitz 6332: float:right;
1.847 tempelho 6333: }
6334:
1.911 bisitz 6335: ul.LC_TabContent li a,
6336: ul.LC_TabContent li {
6337: color:rgb(47,47,47);
6338: text-decoration:none;
6339: font-size:95%;
6340: font-weight:bold;
1.952 onken 6341: min-height:20px;
6342: }
6343:
1.959 onken 6344: ul.LC_TabContent li a:hover,
6345: ul.LC_TabContent li a:focus {
1.952 onken 6346: color: $button_hover;
1.959 onken 6347: background:none;
6348: outline:none;
1.952 onken 6349: }
6350:
6351: ul.LC_TabContent li:hover {
6352: color: $button_hover;
6353: cursor:pointer;
1.721 harmsja 6354: }
1.795 www 6355:
1.911 bisitz 6356: ul.LC_TabContent li.active {
1.952 onken 6357: color: $font;
1.911 bisitz 6358: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6359: border-bottom:solid 1px #FFFFFF;
6360: cursor: default;
1.744 ehlerst 6361: }
1.795 www 6362:
1.959 onken 6363: ul.LC_TabContent li.active a {
6364: color:$font;
6365: background:#FFFFFF;
6366: outline: none;
6367: }
1.870 tempelho 6368: #maincoursedoc {
1.911 bisitz 6369: clear:both;
1.870 tempelho 6370: }
6371:
6372: ul.LC_TabContentBigger {
1.911 bisitz 6373: display:block;
6374: list-style:none;
6375: padding: 0;
1.870 tempelho 6376: }
6377:
1.795 www 6378: ul.LC_TabContentBigger li {
1.911 bisitz 6379: vertical-align:bottom;
6380: height: 30px;
6381: font-size:110%;
6382: font-weight:bold;
6383: color: #737373;
1.841 tempelho 6384: }
6385:
1.957 onken 6386: ul.LC_TabContentBigger li.active {
6387: position: relative;
6388: top: 1px;
6389: }
6390:
1.870 tempelho 6391: ul.LC_TabContentBigger li a {
1.911 bisitz 6392: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6393: height: 30px;
6394: line-height: 30px;
6395: text-align: center;
6396: display: block;
6397: text-decoration: none;
1.958 onken 6398: outline: none;
1.741 harmsja 6399: }
1.795 www 6400:
1.870 tempelho 6401: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6402: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6403: color:$font;
1.744 ehlerst 6404: }
1.795 www 6405:
1.870 tempelho 6406: ul.LC_TabContentBigger li b {
1.911 bisitz 6407: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6408: display: block;
6409: float: left;
6410: padding: 0 30px;
1.957 onken 6411: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6412: }
6413:
1.956 onken 6414: ul.LC_TabContentBigger li:hover b {
6415: color:$button_hover;
6416: }
6417:
1.870 tempelho 6418: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6419: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6420: color:$font;
1.957 onken 6421: border: 0;
1.741 harmsja 6422: }
1.693 droeschl 6423:
1.870 tempelho 6424:
1.862 bisitz 6425: ul.LC_CourseBreadcrumbs {
6426: background: $sidebg;
1.1020 raeburn 6427: height: 2em;
1.862 bisitz 6428: padding-left: 10px;
1.1020 raeburn 6429: margin: 0;
1.862 bisitz 6430: list-style-position: inside;
6431: }
6432:
1.911 bisitz 6433: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6434: ol#LC_PathBreadcrumbs {
1.911 bisitz 6435: padding-left: 10px;
6436: margin: 0;
1.933 droeschl 6437: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6438: }
6439:
1.911 bisitz 6440: ol#LC_MenuBreadcrumbs li,
6441: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6442: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6443: display: inline;
1.933 droeschl 6444: white-space: normal;
1.693 droeschl 6445: }
6446:
1.823 bisitz 6447: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6448: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6449: text-decoration: none;
6450: font-size:90%;
1.693 droeschl 6451: }
1.795 www 6452:
1.969 droeschl 6453: ol#LC_MenuBreadcrumbs h1 {
6454: display: inline;
6455: font-size: 90%;
6456: line-height: 2.5em;
6457: margin: 0;
6458: padding: 0;
6459: }
6460:
1.795 www 6461: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6462: text-decoration:none;
6463: font-size:100%;
6464: font-weight:bold;
1.693 droeschl 6465: }
1.795 www 6466:
1.840 bisitz 6467: .LC_Box {
1.911 bisitz 6468: border: solid 1px $lg_border_color;
6469: padding: 0 10px 10px 10px;
1.746 neumanie 6470: }
1.795 www 6471:
1.1020 raeburn 6472: .LC_DocsBox {
6473: border: solid 1px $lg_border_color;
6474: padding: 0 0 10px 10px;
6475: }
6476:
1.795 www 6477: .LC_AboutMe_Image {
1.911 bisitz 6478: float:left;
6479: margin-right:10px;
1.747 neumanie 6480: }
1.795 www 6481:
6482: .LC_Clear_AboutMe_Image {
1.911 bisitz 6483: clear:left;
1.747 neumanie 6484: }
1.795 www 6485:
1.721 harmsja 6486: dl.LC_ListStyleClean dt {
1.911 bisitz 6487: padding-right: 5px;
6488: display: table-header-group;
1.693 droeschl 6489: }
6490:
1.721 harmsja 6491: dl.LC_ListStyleClean dd {
1.911 bisitz 6492: display: table-row;
1.693 droeschl 6493: }
6494:
1.721 harmsja 6495: .LC_ListStyleClean,
6496: .LC_ListStyleSimple,
6497: .LC_ListStyleNormal,
1.795 www 6498: .LC_ListStyleSpecial {
1.911 bisitz 6499: /* display:block; */
6500: list-style-position: inside;
6501: list-style-type: none;
6502: overflow: hidden;
6503: padding: 0;
1.693 droeschl 6504: }
6505:
1.721 harmsja 6506: .LC_ListStyleSimple li,
6507: .LC_ListStyleSimple dd,
6508: .LC_ListStyleNormal li,
6509: .LC_ListStyleNormal dd,
6510: .LC_ListStyleSpecial li,
1.795 www 6511: .LC_ListStyleSpecial dd {
1.911 bisitz 6512: margin: 0;
6513: padding: 5px 5px 5px 10px;
6514: clear: both;
1.693 droeschl 6515: }
6516:
1.721 harmsja 6517: .LC_ListStyleClean li,
6518: .LC_ListStyleClean dd {
1.911 bisitz 6519: padding-top: 0;
6520: padding-bottom: 0;
1.693 droeschl 6521: }
6522:
1.721 harmsja 6523: .LC_ListStyleSimple dd,
1.795 www 6524: .LC_ListStyleSimple li {
1.911 bisitz 6525: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6526: }
6527:
1.721 harmsja 6528: .LC_ListStyleSpecial li,
6529: .LC_ListStyleSpecial dd {
1.911 bisitz 6530: list-style-type: none;
6531: background-color: RGB(220, 220, 220);
6532: margin-bottom: 4px;
1.693 droeschl 6533: }
6534:
1.721 harmsja 6535: table.LC_SimpleTable {
1.911 bisitz 6536: margin:5px;
6537: border:solid 1px $lg_border_color;
1.795 www 6538: }
1.693 droeschl 6539:
1.721 harmsja 6540: table.LC_SimpleTable tr {
1.911 bisitz 6541: padding: 0;
6542: border:solid 1px $lg_border_color;
1.693 droeschl 6543: }
1.795 www 6544:
6545: table.LC_SimpleTable thead {
1.911 bisitz 6546: background:rgb(220,220,220);
1.693 droeschl 6547: }
6548:
1.721 harmsja 6549: div.LC_columnSection {
1.911 bisitz 6550: display: block;
6551: clear: both;
6552: overflow: hidden;
6553: margin: 0;
1.693 droeschl 6554: }
6555:
1.721 harmsja 6556: div.LC_columnSection>* {
1.911 bisitz 6557: float: left;
6558: margin: 10px 20px 10px 0;
6559: overflow:hidden;
1.693 droeschl 6560: }
1.721 harmsja 6561:
1.795 www 6562: table em {
1.911 bisitz 6563: font-weight: bold;
6564: font-style: normal;
1.748 schulted 6565: }
1.795 www 6566:
1.779 bisitz 6567: table.LC_tableBrowseRes,
1.795 www 6568: table.LC_tableOfContent {
1.911 bisitz 6569: border:none;
6570: border-spacing: 1px;
6571: padding: 3px;
6572: background-color: #FFFFFF;
6573: font-size: 90%;
1.753 droeschl 6574: }
1.789 droeschl 6575:
1.911 bisitz 6576: table.LC_tableOfContent {
6577: border-collapse: collapse;
1.789 droeschl 6578: }
6579:
1.771 droeschl 6580: table.LC_tableBrowseRes a,
1.768 schulted 6581: table.LC_tableOfContent a {
1.911 bisitz 6582: background-color: transparent;
6583: text-decoration: none;
1.753 droeschl 6584: }
6585:
1.795 www 6586: table.LC_tableOfContent img {
1.911 bisitz 6587: border: none;
6588: height: 1.3em;
6589: vertical-align: text-bottom;
6590: margin-right: 0.3em;
1.753 droeschl 6591: }
1.757 schulted 6592:
1.795 www 6593: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6594: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6595: }
6596:
1.795 www 6597: a#LC_content_toolbar_everything {
1.911 bisitz 6598: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6599: }
6600:
1.795 www 6601: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6602: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6603: }
6604:
1.795 www 6605: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6606: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6607: }
6608:
1.795 www 6609: a#LC_content_toolbar_changefolder {
1.911 bisitz 6610: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6611: }
6612:
1.795 www 6613: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6614: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6615: }
6616:
1.795 www 6617: ul#LC_toolbar li a:hover {
1.911 bisitz 6618: background-position: bottom center;
1.757 schulted 6619: }
6620:
1.795 www 6621: ul#LC_toolbar {
1.911 bisitz 6622: padding: 0;
6623: margin: 2px;
6624: list-style:none;
6625: position:relative;
6626: background-color:white;
1.757 schulted 6627: }
6628:
1.795 www 6629: ul#LC_toolbar li {
1.911 bisitz 6630: border:1px solid white;
6631: padding: 0;
6632: margin: 0;
6633: float: left;
6634: display:inline;
6635: vertical-align:middle;
6636: }
1.757 schulted 6637:
1.783 amueller 6638:
1.795 www 6639: a.LC_toolbarItem {
1.911 bisitz 6640: display:block;
6641: padding: 0;
6642: margin: 0;
6643: height: 32px;
6644: width: 32px;
6645: color:white;
6646: border: none;
6647: background-repeat:no-repeat;
6648: background-color:transparent;
1.757 schulted 6649: }
6650:
1.915 droeschl 6651: ul.LC_funclist {
6652: margin: 0;
6653: padding: 0.5em 1em 0.5em 0;
6654: }
6655:
1.933 droeschl 6656: ul.LC_funclist > li:first-child {
6657: font-weight:bold;
6658: margin-left:0.8em;
6659: }
6660:
1.915 droeschl 6661: ul.LC_funclist + ul.LC_funclist {
6662: /*
6663: left border as a seperator if we have more than
6664: one list
6665: */
6666: border-left: 1px solid $sidebg;
6667: /*
6668: this hides the left border behind the border of the
6669: outer box if element is wrapped to the next 'line'
6670: */
6671: margin-left: -1px;
6672: }
6673:
1.843 bisitz 6674: ul.LC_funclist li {
1.915 droeschl 6675: display: inline;
1.782 bisitz 6676: white-space: nowrap;
1.915 droeschl 6677: margin: 0 0 0 25px;
6678: line-height: 150%;
1.782 bisitz 6679: }
6680:
1.974 wenzelju 6681: .LC_hidden {
6682: display: none;
6683: }
6684:
1.343 albertel 6685: END
6686: }
6687:
1.306 albertel 6688: =pod
6689:
6690: =item * &headtag()
6691:
6692: Returns a uniform footer for LON-CAPA web pages.
6693:
1.307 albertel 6694: Inputs: $title - optional title for the head
6695: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6696: $args - optional arguments
1.319 albertel 6697: force_register - if is true call registerurl so the remote is
6698: informed
1.415 albertel 6699: redirect -> array ref of
6700: 1- seconds before redirect occurs
6701: 2- url to redirect to
6702: 3- whether the side effect should occur
1.315 albertel 6703: (side effect of setting
6704: $env{'internal.head.redirect'} to the url
6705: redirected too)
1.352 albertel 6706: domain -> force to color decorate a page for a specific
6707: domain
6708: function -> force usage of a specific rolish color scheme
6709: bgcolor -> override the default page bgcolor
1.460 albertel 6710: no_auto_mt_title
6711: -> prevent &mt()ing the title arg
1.464 albertel 6712:
1.306 albertel 6713: =cut
6714:
6715: sub headtag {
1.313 albertel 6716: my ($title,$head_extra,$args) = @_;
1.306 albertel 6717:
1.363 albertel 6718: my $function = $args->{'function'} || &get_users_function();
6719: my $domain = $args->{'domain'} || &determinedomain();
6720: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6721: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6722: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6723: #time(),
1.418 albertel 6724: $env{'environment.color.timestamp'},
1.363 albertel 6725: $function,$domain,$bgcolor);
6726:
1.369 www 6727: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6728:
1.308 albertel 6729: my $result =
6730: '<head>'.
1.461 albertel 6731: &font_settings();
1.319 albertel 6732:
1.461 albertel 6733: if (!$args->{'frameset'}) {
6734: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6735: }
1.962 droeschl 6736: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
6737: $result .= Apache::lonxml::display_title();
1.319 albertel 6738: }
1.436 albertel 6739: if (!$args->{'no_nav_bar'}
6740: && !$args->{'only_body'}
6741: && !$args->{'frameset'}) {
6742: $result .= &help_menu_js();
6743: }
1.319 albertel 6744:
1.314 albertel 6745: if (ref($args->{'redirect'})) {
1.414 albertel 6746: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6747: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6748: if (!$inhibit_continue) {
6749: $env{'internal.head.redirect'} = $url;
6750: }
1.313 albertel 6751: $result.=<<ADDMETA
6752: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6753: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6754: ADDMETA
6755: }
1.306 albertel 6756: if (!defined($title)) {
6757: $title = 'The LearningOnline Network with CAPA';
6758: }
1.460 albertel 6759: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6760: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6761: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6762: .$head_extra;
1.962 droeschl 6763: return $result.'</head>';
1.306 albertel 6764: }
6765:
6766: =pod
6767:
1.340 albertel 6768: =item * &font_settings()
6769:
6770: Returns neccessary <meta> to set the proper encoding
6771:
6772: Inputs: none
6773:
6774: =cut
6775:
6776: sub font_settings {
6777: my $headerstring='';
1.647 www 6778: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6779: $headerstring.=
6780: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6781: }
6782: return $headerstring;
6783: }
6784:
1.341 albertel 6785: =pod
6786:
6787: =item * &xml_begin()
6788:
6789: Returns the needed doctype and <html>
6790:
6791: Inputs: none
6792:
6793: =cut
6794:
6795: sub xml_begin {
6796: my $output='';
6797:
6798: if ($env{'browser.mathml'}) {
6799: $output='<?xml version="1.0"?>'
6800: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6801: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6802:
6803: # .'<!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">] >'
6804: .'<!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">'
6805: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6806: .'xmlns="http://www.w3.org/1999/xhtml">';
6807: } else {
1.849 bisitz 6808: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6809: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6810: }
6811: return $output;
6812: }
1.340 albertel 6813:
6814: =pod
6815:
1.306 albertel 6816: =item * &start_page()
6817:
6818: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6819:
1.648 raeburn 6820: Inputs:
6821:
6822: =over 4
6823:
6824: $title - optional title for the page
6825:
6826: $head_extra - optional extra HTML to incude inside the <head>
6827:
6828: $args - additional optional args supported are:
6829:
6830: =over 8
6831:
6832: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6833: arg on
1.814 bisitz 6834: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6835: add_entries -> additional attributes to add to the <body>
6836: domain -> force to color decorate a page for a
1.317 albertel 6837: specific domain
1.648 raeburn 6838: function -> force usage of a specific rolish color
1.317 albertel 6839: scheme
1.648 raeburn 6840: redirect -> see &headtag()
6841: bgcolor -> override the default page bg color
6842: js_ready -> return a string ready for being used in
1.317 albertel 6843: a javascript writeln
1.648 raeburn 6844: html_encode -> return a string ready for being used in
1.320 albertel 6845: a html attribute
1.648 raeburn 6846: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6847: $forcereg arg
1.648 raeburn 6848: frameset -> if true will start with a <frameset>
1.330 albertel 6849: rather than <body>
1.648 raeburn 6850: skip_phases -> hash ref of
1.338 albertel 6851: head -> skip the <html><head> generation
6852: body -> skip all <body> generation
1.648 raeburn 6853: no_auto_mt_title -> prevent &mt()ing the title arg
6854: inherit_jsmath -> when creating popup window in a page,
6855: should it have jsmath forced on by the
6856: current page
1.867 kalberla 6857: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 6858: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6859:
1.648 raeburn 6860: =back
1.460 albertel 6861:
1.648 raeburn 6862: =back
1.562 albertel 6863:
1.306 albertel 6864: =cut
6865:
6866: sub start_page {
1.309 albertel 6867: my ($title,$head_extra,$args) = @_;
1.318 albertel 6868: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.964 droeschl 6869: #SD
6870: #I don't see why we copy certain elements of %$args to %head_args
6871: #head args is passed to headtag() and this routine only reads those
6872: #keys that are needed. There doesn't happen any writes or any processing
6873: #of other keys.
6874: #proposal: just pass $args to headtag instead of \%head_args and delete
6875: #marked lines
6876: #<- MARK
1.313 albertel 6877: my %head_args;
1.352 albertel 6878: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6879: 'bgcolor','frameset','no_nav_bar','only_body',
6880: 'no_auto_mt_title') {
1.319 albertel 6881: if (defined($args->{$arg})) {
1.324 raeburn 6882: $head_args{$arg} = $args->{$arg};
1.319 albertel 6883: }
1.313 albertel 6884: }
1.964 droeschl 6885: #MARK ->
1.319 albertel 6886:
1.315 albertel 6887: $env{'internal.start_page'}++;
1.338 albertel 6888: my $result;
1.964 droeschl 6889:
1.338 albertel 6890: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.964 droeschl 6891: $result .=
6892: &xml_begin() . &headtag($title,$head_extra,\%head_args);
6893: #replace prev line by
6894: # &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 6895: }
6896:
6897: if (! exists($args->{'skip_phases'}{'body'}) ) {
6898: if ($args->{'frameset'}) {
6899: my $attr_string = &make_attr_string($args->{'force_register'},
6900: $args->{'add_entries'});
6901: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6902: } else {
6903: $result .=
6904: &bodytag($title,
6905: $args->{'function'}, $args->{'add_entries'},
6906: $args->{'only_body'}, $args->{'domain'},
6907: $args->{'force_register'}, $args->{'no_nav_bar'},
1.962 droeschl 6908: $args->{'bgcolor'}, $args);
1.831 bisitz 6909: }
1.330 albertel 6910: }
1.338 albertel 6911:
1.315 albertel 6912: if ($args->{'js_ready'}) {
1.713 kaisler 6913: $result = &js_ready($result);
1.315 albertel 6914: }
1.320 albertel 6915: if ($args->{'html_encode'}) {
1.713 kaisler 6916: $result = &html_encode($result);
6917: }
6918:
1.813 bisitz 6919: # Preparation for new and consistent functionlist at top of screen
6920: # if ($args->{'functionlist'}) {
6921: # $result .= &build_functionlist();
6922: #}
6923:
1.964 droeschl 6924: # Don't add anything more if only_body wanted or in const space
6925: return $result if $args->{'only_body'}
6926: || $env{'request.state'} eq 'construct';
1.813 bisitz 6927:
6928: #Breadcrumbs
1.758 kaisler 6929: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6930: &Apache::lonhtmlcommon::clear_breadcrumbs();
6931: #if any br links exists, add them to the breadcrumbs
6932: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6933: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6934: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6935: }
6936: }
6937:
6938: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6939: if(exists($args->{'bread_crumbs_component'})){
6940: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6941: }else{
6942: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6943: }
1.320 albertel 6944: }
1.315 albertel 6945: return $result;
1.306 albertel 6946: }
6947:
6948: sub end_page {
1.315 albertel 6949: my ($args) = @_;
6950: $env{'internal.end_page'}++;
1.330 albertel 6951: my $result;
1.335 albertel 6952: if ($args->{'discussion'}) {
6953: my ($target,$parser);
6954: if (ref($args->{'discussion'})) {
6955: ($target,$parser) =($args->{'discussion'}{'target'},
6956: $args->{'discussion'}{'parser'});
6957: }
6958: $result .= &Apache::lonxml::xmlend($target,$parser);
6959: }
6960:
1.330 albertel 6961: if ($args->{'frameset'}) {
6962: $result .= '</frameset>';
6963: } else {
1.635 raeburn 6964: $result .= &endbodytag($args);
1.330 albertel 6965: }
6966: $result .= "\n</html>";
6967:
1.315 albertel 6968: if ($args->{'js_ready'}) {
1.317 albertel 6969: $result = &js_ready($result);
1.315 albertel 6970: }
1.335 albertel 6971:
1.320 albertel 6972: if ($args->{'html_encode'}) {
6973: $result = &html_encode($result);
6974: }
1.335 albertel 6975:
1.315 albertel 6976: return $result;
6977: }
6978:
1.320 albertel 6979: sub html_encode {
6980: my ($result) = @_;
6981:
1.322 albertel 6982: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6983:
6984: return $result;
6985: }
1.317 albertel 6986: sub js_ready {
6987: my ($result) = @_;
6988:
1.323 albertel 6989: $result =~ s/[\n\r]/ /xmsg;
6990: $result =~ s/\\/\\\\/xmsg;
6991: $result =~ s/'/\\'/xmsg;
1.372 albertel 6992: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6993:
6994: return $result;
6995: }
6996:
1.315 albertel 6997: sub validate_page {
6998: if ( exists($env{'internal.start_page'})
1.316 albertel 6999: && $env{'internal.start_page'} > 1) {
7000: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7001: $env{'internal.start_page'}.' '.
1.316 albertel 7002: $ENV{'request.filename'});
1.315 albertel 7003: }
7004: if ( exists($env{'internal.end_page'})
1.316 albertel 7005: && $env{'internal.end_page'} > 1) {
7006: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7007: $env{'internal.end_page'}.' '.
1.316 albertel 7008: $env{'request.filename'});
1.315 albertel 7009: }
7010: if ( exists($env{'internal.start_page'})
7011: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7012: &Apache::lonnet::logthis('start_page called without end_page '.
7013: $env{'request.filename'});
1.315 albertel 7014: }
7015: if ( ! exists($env{'internal.start_page'})
7016: && exists($env{'internal.end_page'})) {
1.316 albertel 7017: &Apache::lonnet::logthis('end_page called without start_page'.
7018: $env{'request.filename'});
1.315 albertel 7019: }
1.306 albertel 7020: }
1.315 albertel 7021:
1.996 www 7022:
7023: sub start_scrollbox {
1.1018 raeburn 7024: my ($outerwidth,$width,$height,$id)=@_;
1.998 raeburn 7025: unless ($outerwidth) { $outerwidth='520px'; }
7026: unless ($width) { $width='500px'; }
7027: unless ($height) { $height='200px'; }
1.1020 raeburn 7028: my ($table_id,$div_id);
1.1018 raeburn 7029: if ($id ne '') {
1.1020 raeburn 7030: $table_id = " id='table_$id'";
7031: $div_id = " id='div_$id'";
1.1018 raeburn 7032: }
1.1020 raeburn 7033: return "<table style='width: $outerwidth; border: 1px solid none;'$table_id><tr><td style='width: $width;' bgcolor='#FFFFFF'><div style='overflow:auto; width:$width; height: $height;'$div_id>";
1.996 www 7034: }
7035:
7036: sub end_scrollbox {
1.998 raeburn 7037: return '</td></tr></table>';
1.996 www 7038: }
7039:
1.318 albertel 7040: sub simple_error_page {
7041: my ($r,$title,$msg) = @_;
7042: my $page =
7043: &Apache::loncommon::start_page($title).
7044: &mt($msg).
7045: &Apache::loncommon::end_page();
7046: if (ref($r)) {
7047: $r->print($page);
1.327 albertel 7048: return;
1.318 albertel 7049: }
7050: return $page;
7051: }
1.347 albertel 7052:
7053: {
1.610 albertel 7054: my @row_count;
1.961 onken 7055:
7056: sub start_data_table_count {
7057: unshift(@row_count, 0);
7058: return;
7059: }
7060:
7061: sub end_data_table_count {
7062: shift(@row_count);
7063: return;
7064: }
7065:
1.347 albertel 7066: sub start_data_table {
1.1018 raeburn 7067: my ($add_class,$id) = @_;
1.422 albertel 7068: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 7069: my $table_id;
7070: if (defined($id)) {
7071: $table_id = ' id="'.$id.'"';
7072: }
1.961 onken 7073: &start_data_table_count();
1.1018 raeburn 7074: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 7075: }
7076:
7077: sub end_data_table {
1.961 onken 7078: &end_data_table_count();
1.389 albertel 7079: return '</table>'."\n";;
1.347 albertel 7080: }
7081:
7082: sub start_data_table_row {
1.974 wenzelju 7083: my ($add_class, $id) = @_;
1.610 albertel 7084: $row_count[0]++;
7085: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7086: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 7087: $id = (' id="'.$id.'"') unless ($id eq '');
7088: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 7089: }
1.471 banghart 7090:
7091: sub continue_data_table_row {
1.974 wenzelju 7092: my ($add_class, $id) = @_;
1.610 albertel 7093: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 7094: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
7095: $id = (' id="'.$id.'"') unless ($id eq '');
7096: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 7097: }
1.347 albertel 7098:
7099: sub end_data_table_row {
1.389 albertel 7100: return '</tr>'."\n";;
1.347 albertel 7101: }
1.367 www 7102:
1.421 albertel 7103: sub start_data_table_empty_row {
1.707 bisitz 7104: # $row_count[0]++;
1.421 albertel 7105: return '<tr class="LC_empty_row" >'."\n";;
7106: }
7107:
7108: sub end_data_table_empty_row {
7109: return '</tr>'."\n";;
7110: }
7111:
1.367 www 7112: sub start_data_table_header_row {
1.389 albertel 7113: return '<tr class="LC_header_row">'."\n";;
1.367 www 7114: }
7115:
7116: sub end_data_table_header_row {
1.389 albertel 7117: return '</tr>'."\n";;
1.367 www 7118: }
1.890 droeschl 7119:
7120: sub data_table_caption {
7121: my $caption = shift;
7122: return "<caption class=\"LC_caption\">$caption</caption>";
7123: }
1.347 albertel 7124: }
7125:
1.548 albertel 7126: =pod
7127:
7128: =item * &inhibit_menu_check($arg)
7129:
7130: Checks for a inhibitmenu state and generates output to preserve it
7131:
7132: Inputs: $arg - can be any of
7133: - undef - in which case the return value is a string
7134: to add into arguments list of a uri
7135: - 'input' - in which case the return value is a HTML
7136: <form> <input> field of type hidden to
7137: preserve the value
7138: - a url - in which case the return value is the url with
7139: the neccesary cgi args added to preserve the
7140: inhibitmenu state
7141: - a ref to a url - no return value, but the string is
7142: updated to include the neccessary cgi
7143: args to preserve the inhibitmenu state
7144:
7145: =cut
7146:
7147: sub inhibit_menu_check {
7148: my ($arg) = @_;
7149: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7150: if ($arg eq 'input') {
7151: if ($env{'form.inhibitmenu'}) {
7152: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7153: } else {
7154: return
7155: }
7156: }
7157: if ($env{'form.inhibitmenu'}) {
7158: if (ref($arg)) {
7159: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7160: } elsif ($arg eq '') {
7161: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7162: } else {
7163: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7164: }
7165: }
7166: if (!ref($arg)) {
7167: return $arg;
7168: }
7169: }
7170:
1.251 albertel 7171: ###############################################
1.182 matthew 7172:
7173: =pod
7174:
1.549 albertel 7175: =back
7176:
7177: =head1 User Information Routines
7178:
7179: =over 4
7180:
1.405 albertel 7181: =item * &get_users_function()
1.182 matthew 7182:
7183: Used by &bodytag to determine the current users primary role.
7184: Returns either 'student','coordinator','admin', or 'author'.
7185:
7186: =cut
7187:
7188: ###############################################
7189: sub get_users_function {
1.815 tempelho 7190: my $function = 'norole';
1.818 tempelho 7191: if ($env{'request.role'}=~/^(st)/) {
7192: $function='student';
7193: }
1.907 raeburn 7194: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7195: $function='coordinator';
7196: }
1.258 albertel 7197: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7198: $function='admin';
7199: }
1.826 bisitz 7200: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 7201: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 7202: $function='author';
7203: }
7204: return $function;
1.54 www 7205: }
1.99 www 7206:
7207: ###############################################
7208:
1.233 raeburn 7209: =pod
7210:
1.821 raeburn 7211: =item * &show_course()
7212:
7213: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7214: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7215:
7216: Inputs:
7217: None
7218:
7219: Outputs:
7220: Scalar: 1 if 'Course' to be used, 0 otherwise.
7221:
7222: =cut
7223:
7224: ###############################################
7225: sub show_course {
7226: my $course = !$env{'user.adv'};
7227: if (!$env{'user.adv'}) {
7228: foreach my $env (keys(%env)) {
7229: next if ($env !~ m/^user\.priv\./);
7230: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7231: $course = 0;
7232: last;
7233: }
7234: }
7235: }
7236: return $course;
7237: }
7238:
7239: ###############################################
7240:
7241: =pod
7242:
1.542 raeburn 7243: =item * &check_user_status()
1.274 raeburn 7244:
7245: Determines current status of supplied role for a
7246: specific user. Roles can be active, previous or future.
7247:
7248: Inputs:
7249: user's domain, user's username, course's domain,
1.375 raeburn 7250: course's number, optional section ID.
1.274 raeburn 7251:
7252: Outputs:
7253: role status: active, previous or future.
7254:
7255: =cut
7256:
7257: sub check_user_status {
1.412 raeburn 7258: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.982 raeburn 7259: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7260: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7261: my @uroles = keys %userinfo;
7262: my $srchstr;
7263: my $active_chk = 'none';
1.412 raeburn 7264: my $now = time;
1.274 raeburn 7265: if (@uroles > 0) {
1.908 raeburn 7266: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7267: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7268: } else {
1.412 raeburn 7269: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7270: }
7271: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7272: my $role_end = 0;
7273: my $role_start = 0;
7274: $active_chk = 'active';
1.412 raeburn 7275: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7276: $role_end = $1;
7277: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7278: $role_start = $1;
1.274 raeburn 7279: }
7280: }
7281: if ($role_start > 0) {
1.412 raeburn 7282: if ($now < $role_start) {
1.274 raeburn 7283: $active_chk = 'future';
7284: }
7285: }
7286: if ($role_end > 0) {
1.412 raeburn 7287: if ($now > $role_end) {
1.274 raeburn 7288: $active_chk = 'previous';
7289: }
7290: }
7291: }
7292: }
7293: return $active_chk;
7294: }
7295:
7296: ###############################################
7297:
7298: =pod
7299:
1.405 albertel 7300: =item * &get_sections()
1.233 raeburn 7301:
7302: Determines all the sections for a course including
7303: sections with students and sections containing other roles.
1.419 raeburn 7304: Incoming parameters:
7305:
7306: 1. domain
7307: 2. course number
7308: 3. reference to array containing roles for which sections should
7309: be gathered (optional).
7310: 4. reference to array containing status types for which sections
7311: should be gathered (optional).
7312:
7313: If the third argument is undefined, sections are gathered for any role.
7314: If the fourth argument is undefined, sections are gathered for any status.
7315: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7316:
1.374 raeburn 7317: Returns section hash (keys are section IDs, values are
7318: number of users in each section), subject to the
1.419 raeburn 7319: optional roles filter, optional status filter
1.233 raeburn 7320:
7321: =cut
7322:
7323: ###############################################
7324: sub get_sections {
1.419 raeburn 7325: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7326: if (!defined($cdom) || !defined($cnum)) {
7327: my $cid = $env{'request.course.id'};
7328:
7329: return if (!defined($cid));
7330:
7331: $cdom = $env{'course.'.$cid.'.domain'};
7332: $cnum = $env{'course.'.$cid.'.num'};
7333: }
7334:
7335: my %sectioncount;
1.419 raeburn 7336: my $now = time;
1.240 albertel 7337:
1.366 albertel 7338: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7339: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7340: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7341: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7342: my $start_index = &Apache::loncoursedata::CL_START();
7343: my $end_index = &Apache::loncoursedata::CL_END();
7344: my $status;
1.366 albertel 7345: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7346: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7347: $data->[$status_index],
7348: $data->[$start_index],
7349: $data->[$end_index]);
7350: if ($stu_status eq 'Active') {
7351: $status = 'active';
7352: } elsif ($end < $now) {
7353: $status = 'previous';
7354: } elsif ($start > $now) {
7355: $status = 'future';
7356: }
7357: if ($section ne '-1' && $section !~ /^\s*$/) {
7358: if ((!defined($possible_status)) || (($status ne '') &&
7359: (grep/^\Q$status\E$/,@{$possible_status}))) {
7360: $sectioncount{$section}++;
7361: }
1.240 albertel 7362: }
7363: }
7364: }
7365: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7366: foreach my $user (sort(keys(%courseroles))) {
7367: if ($user !~ /^(\w{2})/) { next; }
7368: my ($role) = ($user =~ /^(\w{2})/);
7369: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7370: my ($section,$status);
1.240 albertel 7371: if ($role eq 'cr' &&
7372: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7373: $section=$1;
7374: }
7375: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7376: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7377: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7378: if ($end == -1 && $start == -1) {
7379: next; #deleted role
7380: }
7381: if (!defined($possible_status)) {
7382: $sectioncount{$section}++;
7383: } else {
7384: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7385: $status = 'active';
7386: } elsif ($end < $now) {
7387: $status = 'future';
7388: } elsif ($start > $now) {
7389: $status = 'previous';
7390: }
7391: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7392: $sectioncount{$section}++;
7393: }
7394: }
1.233 raeburn 7395: }
1.366 albertel 7396: return %sectioncount;
1.233 raeburn 7397: }
7398:
1.274 raeburn 7399: ###############################################
1.294 raeburn 7400:
7401: =pod
1.405 albertel 7402:
7403: =item * &get_course_users()
7404:
1.275 raeburn 7405: Retrieves usernames:domains for users in the specified course
7406: with specific role(s), and access status.
7407:
7408: Incoming parameters:
1.277 albertel 7409: 1. course domain
7410: 2. course number
7411: 3. access status: users must have - either active,
1.275 raeburn 7412: previous, future, or all.
1.277 albertel 7413: 4. reference to array of permissible roles
1.288 raeburn 7414: 5. reference to array of section restrictions (optional)
7415: 6. reference to results object (hash of hashes).
7416: 7. reference to optional userdata hash
1.609 raeburn 7417: 8. reference to optional statushash
1.630 raeburn 7418: 9. flag if privileged users (except those set to unhide in
7419: course settings) should be excluded
1.609 raeburn 7420: Keys of top level results hash are roles.
1.275 raeburn 7421: Keys of inner hashes are username:domain, with
7422: values set to access type.
1.288 raeburn 7423: Optional userdata hash returns an array with arguments in the
7424: same order as loncoursedata::get_classlist() for student data.
7425:
1.609 raeburn 7426: Optional statushash returns
7427:
1.288 raeburn 7428: Entries for end, start, section and status are blank because
7429: of the possibility of multiple values for non-student roles.
7430:
1.275 raeburn 7431: =cut
1.405 albertel 7432:
1.275 raeburn 7433: ###############################################
1.405 albertel 7434:
1.275 raeburn 7435: sub get_course_users {
1.630 raeburn 7436: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7437: my %idx = ();
1.419 raeburn 7438: my %seclists;
1.288 raeburn 7439:
7440: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7441: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7442: $idx{end} = &Apache::loncoursedata::CL_END();
7443: $idx{start} = &Apache::loncoursedata::CL_START();
7444: $idx{id} = &Apache::loncoursedata::CL_ID();
7445: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7446: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7447: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7448:
1.290 albertel 7449: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7450: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7451: my $now = time;
1.277 albertel 7452: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7453: my $match = 0;
1.412 raeburn 7454: my $secmatch = 0;
1.419 raeburn 7455: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7456: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7457: if ($section eq '') {
7458: $section = 'none';
7459: }
1.291 albertel 7460: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7461: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7462: $secmatch = 1;
7463: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7464: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7465: $secmatch = 1;
7466: }
7467: } else {
1.419 raeburn 7468: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7469: $secmatch = 1;
7470: }
1.290 albertel 7471: }
1.412 raeburn 7472: if (!$secmatch) {
7473: next;
7474: }
1.419 raeburn 7475: }
1.275 raeburn 7476: if (defined($$types{'active'})) {
1.288 raeburn 7477: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7478: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7479: $match = 1;
1.275 raeburn 7480: }
7481: }
7482: if (defined($$types{'previous'})) {
1.609 raeburn 7483: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7484: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7485: $match = 1;
1.275 raeburn 7486: }
7487: }
7488: if (defined($$types{'future'})) {
1.609 raeburn 7489: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7490: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7491: $match = 1;
1.275 raeburn 7492: }
7493: }
1.609 raeburn 7494: if ($match) {
7495: push(@{$seclists{$student}},$section);
7496: if (ref($userdata) eq 'HASH') {
7497: $$userdata{$student} = $$classlist{$student};
7498: }
7499: if (ref($statushash) eq 'HASH') {
7500: $statushash->{$student}{'st'}{$section} = $status;
7501: }
1.288 raeburn 7502: }
1.275 raeburn 7503: }
7504: }
1.412 raeburn 7505: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7506: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7507: my $now = time;
1.609 raeburn 7508: my %displaystatus = ( previous => 'Expired',
7509: active => 'Active',
7510: future => 'Future',
7511: );
1.630 raeburn 7512: my %nothide;
7513: if ($hidepriv) {
7514: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7515: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7516: if ($user !~ /:/) {
7517: $nothide{join(':',split(/[\@]/,$user))}=1;
7518: } else {
7519: $nothide{$user} = 1;
7520: }
7521: }
7522: }
1.439 raeburn 7523: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7524: my $match = 0;
1.412 raeburn 7525: my $secmatch = 0;
1.439 raeburn 7526: my $status;
1.412 raeburn 7527: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7528: $user =~ s/:$//;
1.439 raeburn 7529: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7530: if ($end == -1 || $start == -1) {
7531: next;
7532: }
7533: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7534: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7535: my ($uname,$udom) = split(/:/,$user);
7536: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7537: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7538: $secmatch = 1;
7539: } elsif ($usec eq '') {
1.420 albertel 7540: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7541: $secmatch = 1;
7542: }
7543: } else {
7544: if (grep(/^\Q$usec\E$/,@{$sections})) {
7545: $secmatch = 1;
7546: }
7547: }
7548: if (!$secmatch) {
7549: next;
7550: }
1.288 raeburn 7551: }
1.419 raeburn 7552: if ($usec eq '') {
7553: $usec = 'none';
7554: }
1.275 raeburn 7555: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7556: if ($hidepriv) {
7557: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7558: (!$nothide{$uname.':'.$udom})) {
7559: next;
7560: }
7561: }
1.503 raeburn 7562: if ($end > 0 && $end < $now) {
1.439 raeburn 7563: $status = 'previous';
7564: } elsif ($start > $now) {
7565: $status = 'future';
7566: } else {
7567: $status = 'active';
7568: }
1.277 albertel 7569: foreach my $type (keys(%{$types})) {
1.275 raeburn 7570: if ($status eq $type) {
1.420 albertel 7571: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7572: push(@{$$users{$role}{$user}},$type);
7573: }
1.288 raeburn 7574: $match = 1;
7575: }
7576: }
1.419 raeburn 7577: if (($match) && (ref($userdata) eq 'HASH')) {
7578: if (!exists($$userdata{$uname.':'.$udom})) {
7579: &get_user_info($udom,$uname,\%idx,$userdata);
7580: }
1.420 albertel 7581: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7582: push(@{$seclists{$uname.':'.$udom}},$usec);
7583: }
1.609 raeburn 7584: if (ref($statushash) eq 'HASH') {
7585: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7586: }
1.275 raeburn 7587: }
7588: }
7589: }
7590: }
1.290 albertel 7591: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7592: if ((defined($cdom)) && (defined($cnum))) {
7593: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7594: if ( defined($csettings{'internal.courseowner'}) ) {
7595: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7596: next if ($owner eq '');
7597: my ($ownername,$ownerdom);
7598: if ($owner =~ /^([^:]+):([^:]+)$/) {
7599: $ownername = $1;
7600: $ownerdom = $2;
7601: } else {
7602: $ownername = $owner;
7603: $ownerdom = $cdom;
7604: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7605: }
7606: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7607: if (defined($userdata) &&
1.609 raeburn 7608: !exists($$userdata{$owner})) {
7609: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7610: if (!grep(/^none$/,@{$seclists{$owner}})) {
7611: push(@{$seclists{$owner}},'none');
7612: }
7613: if (ref($statushash) eq 'HASH') {
7614: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7615: }
1.290 albertel 7616: }
1.279 raeburn 7617: }
7618: }
7619: }
1.419 raeburn 7620: foreach my $user (keys(%seclists)) {
7621: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7622: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7623: }
1.275 raeburn 7624: }
7625: return;
7626: }
7627:
1.288 raeburn 7628: sub get_user_info {
7629: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7630: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7631: &plainname($uname,$udom,'lastname');
1.291 albertel 7632: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7633: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7634: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7635: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7636: return;
7637: }
1.275 raeburn 7638:
1.472 raeburn 7639: ###############################################
7640:
7641: =pod
7642:
7643: =item * &get_user_quota()
7644:
7645: Retrieves quota assigned for storage of portfolio files for a user
7646:
7647: Incoming parameters:
7648: 1. user's username
7649: 2. user's domain
7650:
7651: Returns:
1.536 raeburn 7652: 1. Disk quota (in Mb) assigned to student.
7653: 2. (Optional) Type of setting: custom or default
7654: (individually assigned or default for user's
7655: institutional status).
7656: 3. (Optional) - User's institutional status (e.g., faculty, staff
7657: or student - types as defined in localenroll::inst_usertypes
7658: for user's domain, which determines default quota for user.
7659: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7660:
7661: If a value has been stored in the user's environment,
1.536 raeburn 7662: it will return that, otherwise it returns the maximal default
7663: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7664:
7665: =cut
7666:
7667: ###############################################
7668:
7669:
7670: sub get_user_quota {
7671: my ($uname,$udom) = @_;
1.536 raeburn 7672: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7673: if (!defined($udom)) {
7674: $udom = $env{'user.domain'};
7675: }
7676: if (!defined($uname)) {
7677: $uname = $env{'user.name'};
7678: }
7679: if (($udom eq '' || $uname eq '') ||
7680: ($udom eq 'public') && ($uname eq 'public')) {
7681: $quota = 0;
1.536 raeburn 7682: $quotatype = 'default';
7683: $defquota = 0;
1.472 raeburn 7684: } else {
1.536 raeburn 7685: my $inststatus;
1.472 raeburn 7686: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7687: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7688: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7689: } else {
1.536 raeburn 7690: my %userenv =
7691: &Apache::lonnet::get('environment',['portfolioquota',
7692: 'inststatus'],$udom,$uname);
1.472 raeburn 7693: my ($tmp) = keys(%userenv);
7694: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7695: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7696: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7697: } else {
7698: undef(%userenv);
7699: }
7700: }
1.536 raeburn 7701: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7702: if ($quota eq '') {
1.536 raeburn 7703: $quota = $defquota;
7704: $quotatype = 'default';
7705: } else {
7706: $quotatype = 'custom';
1.472 raeburn 7707: }
7708: }
1.536 raeburn 7709: if (wantarray) {
7710: return ($quota,$quotatype,$settingstatus,$defquota);
7711: } else {
7712: return $quota;
7713: }
1.472 raeburn 7714: }
7715:
7716: ###############################################
7717:
7718: =pod
7719:
7720: =item * &default_quota()
7721:
1.536 raeburn 7722: Retrieves default quota assigned for storage of user portfolio files,
7723: given an (optional) user's institutional status.
1.472 raeburn 7724:
7725: Incoming parameters:
7726: 1. domain
1.536 raeburn 7727: 2. (Optional) institutional status(es). This is a : separated list of
7728: status types (e.g., faculty, staff, student etc.)
7729: which apply to the user for whom the default is being retrieved.
7730: If the institutional status string in undefined, the domain
7731: default quota will be returned.
1.472 raeburn 7732:
7733: Returns:
7734: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7735: 2. (Optional) institutional type which determined the value of the
7736: default quota.
1.472 raeburn 7737:
7738: If a value has been stored in the domain's configuration db,
7739: it will return that, otherwise it returns 20 (for backwards
7740: compatibility with domains which have not set up a configuration
7741: db file; the original statically defined portfolio quota was 20 Mb).
7742:
1.536 raeburn 7743: If the user's status includes multiple types (e.g., staff and student),
7744: the largest default quota which applies to the user determines the
7745: default quota returned.
7746:
1.780 raeburn 7747: =back
7748:
1.472 raeburn 7749: =cut
7750:
7751: ###############################################
7752:
7753:
7754: sub default_quota {
1.536 raeburn 7755: my ($udom,$inststatus) = @_;
7756: my ($defquota,$settingstatus);
7757: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7758: ['quotas'],$udom);
7759: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7760: if ($inststatus ne '') {
1.765 raeburn 7761: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7762: foreach my $item (@statuses) {
1.711 raeburn 7763: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7764: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7765: if ($defquota eq '') {
7766: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7767: $settingstatus = $item;
7768: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7769: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7770: $settingstatus = $item;
7771: }
7772: }
7773: } else {
7774: if ($quotahash{'quotas'}{$item} ne '') {
7775: if ($defquota eq '') {
7776: $defquota = $quotahash{'quotas'}{$item};
7777: $settingstatus = $item;
7778: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7779: $defquota = $quotahash{'quotas'}{$item};
7780: $settingstatus = $item;
7781: }
1.536 raeburn 7782: }
7783: }
7784: }
7785: }
7786: if ($defquota eq '') {
1.711 raeburn 7787: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7788: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7789: } else {
7790: $defquota = $quotahash{'quotas'}{'default'};
7791: }
1.536 raeburn 7792: $settingstatus = 'default';
7793: }
7794: } else {
7795: $settingstatus = 'default';
7796: $defquota = 20;
7797: }
7798: if (wantarray) {
7799: return ($defquota,$settingstatus);
1.472 raeburn 7800: } else {
1.536 raeburn 7801: return $defquota;
1.472 raeburn 7802: }
7803: }
7804:
1.384 raeburn 7805: sub get_secgrprole_info {
7806: my ($cdom,$cnum,$needroles,$type) = @_;
7807: my %sections_count = &get_sections($cdom,$cnum);
7808: my @sections = (sort {$a <=> $b} keys(%sections_count));
7809: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7810: my @groups = sort(keys(%curr_groups));
7811: my $allroles = [];
7812: my $rolehash;
7813: my $accesshash = {
7814: active => 'Currently has access',
7815: future => 'Will have future access',
7816: previous => 'Previously had access',
7817: };
7818: if ($needroles) {
7819: $rolehash = {'all' => 'all'};
1.385 albertel 7820: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7821: if (&Apache::lonnet::error(%user_roles)) {
7822: undef(%user_roles);
7823: }
7824: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7825: my ($role)=split(/\:/,$item,2);
7826: if ($role eq 'cr') { next; }
7827: if ($role =~ /^cr/) {
7828: $$rolehash{$role} = (split('/',$role))[3];
7829: } else {
7830: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7831: }
7832: }
7833: foreach my $key (sort(keys(%{$rolehash}))) {
7834: push(@{$allroles},$key);
7835: }
7836: push (@{$allroles},'st');
7837: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7838: }
7839: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7840: }
7841:
1.555 raeburn 7842: sub user_picker {
1.994 raeburn 7843: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 7844: my $currdom = $dom;
7845: my %curr_selected = (
7846: srchin => 'dom',
1.580 raeburn 7847: srchby => 'lastname',
1.555 raeburn 7848: );
7849: my $srchterm;
1.625 raeburn 7850: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7851: if ($srch->{'srchby'} ne '') {
7852: $curr_selected{'srchby'} = $srch->{'srchby'};
7853: }
7854: if ($srch->{'srchin'} ne '') {
7855: $curr_selected{'srchin'} = $srch->{'srchin'};
7856: }
7857: if ($srch->{'srchtype'} ne '') {
7858: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7859: }
7860: if ($srch->{'srchdomain'} ne '') {
7861: $currdom = $srch->{'srchdomain'};
7862: }
7863: $srchterm = $srch->{'srchterm'};
7864: }
7865: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7866: 'usr' => 'Search criteria',
1.563 raeburn 7867: 'doma' => 'Domain/institution to search',
1.558 albertel 7868: 'uname' => 'username',
7869: 'lastname' => 'last name',
1.555 raeburn 7870: 'lastfirst' => 'last name, first name',
1.558 albertel 7871: 'crs' => 'in this course',
1.576 raeburn 7872: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7873: 'alc' => 'all LON-CAPA',
1.573 raeburn 7874: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7875: 'exact' => 'is',
7876: 'contains' => 'contains',
1.569 raeburn 7877: 'begins' => 'begins with',
1.571 raeburn 7878: 'youm' => "You must include some text to search for.",
7879: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7880: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7881: 'yomc' => "You must choose a domain when using an institutional directory search.",
7882: 'ymcd' => "You must choose a domain when using a domain search.",
7883: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7884: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7885: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7886: );
1.563 raeburn 7887: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7888: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7889:
7890: my @srchins = ('crs','dom','alc','instd');
7891:
7892: foreach my $option (@srchins) {
7893: # FIXME 'alc' option unavailable until
7894: # loncreateuser::print_user_query_page()
7895: # has been completed.
7896: next if ($option eq 'alc');
1.880 raeburn 7897: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7898: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7899: if ($curr_selected{'srchin'} eq $option) {
7900: $srchinsel .= '
7901: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7902: } else {
7903: $srchinsel .= '
7904: <option value="'.$option.'">'.$lt{$option}.'</option>';
7905: }
1.555 raeburn 7906: }
1.563 raeburn 7907: $srchinsel .= "\n </select>\n";
1.555 raeburn 7908:
7909: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7910: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7911: if ($curr_selected{'srchby'} eq $option) {
7912: $srchbysel .= '
7913: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7914: } else {
7915: $srchbysel .= '
7916: <option value="'.$option.'">'.$lt{$option}.'</option>';
7917: }
7918: }
7919: $srchbysel .= "\n </select>\n";
7920:
7921: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7922: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7923: if ($curr_selected{'srchtype'} eq $option) {
7924: $srchtypesel .= '
7925: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7926: } else {
7927: $srchtypesel .= '
7928: <option value="'.$option.'">'.$lt{$option}.'</option>';
7929: }
7930: }
7931: $srchtypesel .= "\n </select>\n";
7932:
1.558 albertel 7933: my ($newuserscript,$new_user_create);
1.994 raeburn 7934: my $context_dom = $env{'request.role.domain'};
7935: if ($context eq 'requestcrs') {
7936: if ($env{'form.coursedom'} ne '') {
7937: $context_dom = $env{'form.coursedom'};
7938: }
7939: }
1.556 raeburn 7940: if ($forcenewuser) {
1.576 raeburn 7941: if (ref($srch) eq 'HASH') {
1.994 raeburn 7942: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 7943: if ($cancreate) {
7944: $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>';
7945: } else {
1.799 bisitz 7946: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7947: my %usertypetext = (
7948: official => 'institutional',
7949: unofficial => 'non-institutional',
7950: );
1.799 bisitz 7951: $new_user_create = '<p class="LC_warning">'
7952: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7953: .' '
7954: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7955: ,'<a href="'.$helplink.'">','</a>')
7956: .'</p><br />';
1.627 raeburn 7957: }
1.576 raeburn 7958: }
7959: }
7960:
1.556 raeburn 7961: $newuserscript = <<"ENDSCRIPT";
7962:
1.570 raeburn 7963: function setSearch(createnew,callingForm) {
1.556 raeburn 7964: if (createnew == 1) {
1.570 raeburn 7965: for (var i=0; i<callingForm.srchby.length; i++) {
7966: if (callingForm.srchby.options[i].value == 'uname') {
7967: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7968: }
7969: }
1.570 raeburn 7970: for (var i=0; i<callingForm.srchin.length; i++) {
7971: if ( callingForm.srchin.options[i].value == 'dom') {
7972: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7973: }
7974: }
1.570 raeburn 7975: for (var i=0; i<callingForm.srchtype.length; i++) {
7976: if (callingForm.srchtype.options[i].value == 'exact') {
7977: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7978: }
7979: }
1.570 raeburn 7980: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 7981: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 7982: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7983: }
7984: }
7985: }
7986: }
7987: ENDSCRIPT
1.558 albertel 7988:
1.556 raeburn 7989: }
7990:
1.555 raeburn 7991: my $output = <<"END_BLOCK";
1.556 raeburn 7992: <script type="text/javascript">
1.824 bisitz 7993: // <![CDATA[
1.570 raeburn 7994: function validateEntry(callingForm) {
1.558 albertel 7995:
1.556 raeburn 7996: var checkok = 1;
1.558 albertel 7997: var srchin;
1.570 raeburn 7998: for (var i=0; i<callingForm.srchin.length; i++) {
7999: if ( callingForm.srchin[i].checked ) {
8000: srchin = callingForm.srchin[i].value;
1.558 albertel 8001: }
8002: }
8003:
1.570 raeburn 8004: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8005: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8006: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8007: var srchterm = callingForm.srchterm.value;
8008: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8009: var msg = "";
8010:
8011: if (srchterm == "") {
8012: checkok = 0;
1.571 raeburn 8013: msg += "$lt{'youm'}\\n";
1.556 raeburn 8014: }
8015:
1.569 raeburn 8016: if (srchtype== 'begins') {
8017: if (srchterm.length < 2) {
8018: checkok = 0;
1.571 raeburn 8019: msg += "$lt{'thte'}\\n";
1.569 raeburn 8020: }
8021: }
8022:
1.556 raeburn 8023: if (srchtype== 'contains') {
8024: if (srchterm.length < 3) {
8025: checkok = 0;
1.571 raeburn 8026: msg += "$lt{'thet'}\\n";
1.556 raeburn 8027: }
8028: }
8029: if (srchin == 'instd') {
8030: if (srchdomain == '') {
8031: checkok = 0;
1.571 raeburn 8032: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8033: }
8034: }
8035: if (srchin == 'dom') {
8036: if (srchdomain == '') {
8037: checkok = 0;
1.571 raeburn 8038: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8039: }
8040: }
8041: if (srchby == 'lastfirst') {
8042: if (srchterm.indexOf(",") == -1) {
8043: checkok = 0;
1.571 raeburn 8044: msg += "$lt{'whus'}\\n";
1.556 raeburn 8045: }
8046: if (srchterm.indexOf(",") == srchterm.length -1) {
8047: checkok = 0;
1.571 raeburn 8048: msg += "$lt{'whse'}\\n";
1.556 raeburn 8049: }
8050: }
8051: if (checkok == 0) {
1.571 raeburn 8052: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8053: return;
8054: }
8055: if (checkok == 1) {
1.570 raeburn 8056: callingForm.submit();
1.556 raeburn 8057: }
8058: }
8059:
8060: $newuserscript
8061:
1.824 bisitz 8062: // ]]>
1.556 raeburn 8063: </script>
1.558 albertel 8064:
8065: $new_user_create
8066:
1.555 raeburn 8067: END_BLOCK
1.558 albertel 8068:
1.876 raeburn 8069: $output .= &Apache::lonhtmlcommon::start_pick_box().
8070: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8071: $domform.
8072: &Apache::lonhtmlcommon::row_closure().
8073: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8074: $srchbysel.
8075: $srchtypesel.
8076: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8077: $srchinsel.
8078: &Apache::lonhtmlcommon::row_closure(1).
8079: &Apache::lonhtmlcommon::end_pick_box().
8080: '<br />';
1.555 raeburn 8081: return $output;
8082: }
8083:
1.612 raeburn 8084: sub user_rule_check {
1.615 raeburn 8085: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8086: my $response;
8087: if (ref($usershash) eq 'HASH') {
8088: foreach my $user (keys(%{$usershash})) {
8089: my ($uname,$udom) = split(/:/,$user);
8090: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8091: my ($id,$newuser);
1.612 raeburn 8092: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8093: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8094: $id = $usershash->{$user}->{'id'};
8095: }
8096: my $inst_response;
8097: if (ref($checks) eq 'HASH') {
8098: if (defined($checks->{'username'})) {
1.615 raeburn 8099: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8100: &Apache::lonnet::get_instuser($udom,$uname);
8101: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8102: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8103: &Apache::lonnet::get_instuser($udom,undef,$id);
8104: }
1.615 raeburn 8105: } else {
8106: ($inst_response,%{$inst_results->{$user}}) =
8107: &Apache::lonnet::get_instuser($udom,$uname);
8108: return;
1.612 raeburn 8109: }
1.615 raeburn 8110: if (!$got_rules->{$udom}) {
1.612 raeburn 8111: my %domconfig = &Apache::lonnet::get_dom('configuration',
8112: ['usercreation'],$udom);
8113: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8114: foreach my $item ('username','id') {
1.612 raeburn 8115: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8116: $$curr_rules{$udom}{$item} =
8117: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8118: }
8119: }
8120: }
1.615 raeburn 8121: $got_rules->{$udom} = 1;
1.585 raeburn 8122: }
1.612 raeburn 8123: foreach my $item (keys(%{$checks})) {
8124: if (ref($$curr_rules{$udom}) eq 'HASH') {
8125: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8126: if (@{$$curr_rules{$udom}{$item}} > 0) {
8127: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8128: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8129: if ($rule_check{$rule}) {
8130: $$rulematch{$user}{$item} = $rule;
8131: if ($inst_response eq 'ok') {
1.615 raeburn 8132: if (ref($inst_results) eq 'HASH') {
8133: if (ref($inst_results->{$user}) eq 'HASH') {
8134: if (keys(%{$inst_results->{$user}}) == 0) {
8135: $$alerts{$item}{$udom}{$uname} = 1;
8136: }
1.612 raeburn 8137: }
8138: }
1.615 raeburn 8139: }
8140: last;
1.585 raeburn 8141: }
8142: }
8143: }
8144: }
8145: }
8146: }
8147: }
8148: }
1.612 raeburn 8149: return;
8150: }
8151:
8152: sub user_rule_formats {
8153: my ($domain,$domdesc,$curr_rules,$check) = @_;
8154: my %text = (
8155: 'username' => 'Usernames',
8156: 'id' => 'IDs',
8157: );
8158: my $output;
8159: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8160: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8161: if (@{$ruleorder} > 0) {
8162: $output = '<br />'.&mt("$text{$check} with the following format(s) may <span class=\"LC_cusr_emph\">only</span> be used for verified users at [_1]:",$domdesc).' <ul>';
8163: foreach my $rule (@{$ruleorder}) {
8164: if (ref($curr_rules) eq 'ARRAY') {
8165: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8166: if (ref($rules->{$rule}) eq 'HASH') {
8167: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8168: $rules->{$rule}{'desc'}.'</li>';
8169: }
8170: }
8171: }
8172: }
8173: $output .= '</ul>';
8174: }
8175: }
8176: return $output;
8177: }
8178:
8179: sub instrule_disallow_msg {
1.615 raeburn 8180: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8181: my $response;
8182: my %text = (
8183: item => 'username',
8184: items => 'usernames',
8185: match => 'matches',
8186: do => 'does',
8187: action => 'a username',
8188: one => 'one',
8189: );
8190: if ($count > 1) {
8191: $text{'item'} = 'usernames';
8192: $text{'match'} ='match';
8193: $text{'do'} = 'do';
8194: $text{'action'} = 'usernames',
8195: $text{'one'} = 'ones';
8196: }
8197: if ($checkitem eq 'id') {
8198: $text{'items'} = 'IDs';
8199: $text{'item'} = 'ID';
8200: $text{'action'} = 'an ID';
1.615 raeburn 8201: if ($count > 1) {
8202: $text{'item'} = 'IDs';
8203: $text{'action'} = 'IDs';
8204: }
1.612 raeburn 8205: }
1.674 bisitz 8206: $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 8207: if ($mode eq 'upload') {
8208: if ($checkitem eq 'username') {
8209: $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'}.");
8210: } elsif ($checkitem eq 'id') {
1.674 bisitz 8211: $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 8212: }
1.669 raeburn 8213: } elsif ($mode eq 'selfcreate') {
8214: if ($checkitem eq 'id') {
8215: $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.");
8216: }
1.615 raeburn 8217: } else {
8218: if ($checkitem eq 'username') {
8219: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8220: } elsif ($checkitem eq 'id') {
8221: $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.");
8222: }
1.612 raeburn 8223: }
8224: return $response;
1.585 raeburn 8225: }
8226:
1.624 raeburn 8227: sub personal_data_fieldtitles {
8228: my %fieldtitles = &Apache::lonlocal::texthash (
8229: id => 'Student/Employee ID',
8230: permanentemail => 'E-mail address',
8231: lastname => 'Last Name',
8232: firstname => 'First Name',
8233: middlename => 'Middle Name',
8234: generation => 'Generation',
8235: gen => 'Generation',
1.765 raeburn 8236: inststatus => 'Affiliation',
1.624 raeburn 8237: );
8238: return %fieldtitles;
8239: }
8240:
1.642 raeburn 8241: sub sorted_inst_types {
8242: my ($dom) = @_;
8243: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8244: my $othertitle = &mt('All users');
8245: if ($env{'request.course.id'}) {
1.668 raeburn 8246: $othertitle = &mt('Any users');
1.642 raeburn 8247: }
8248: my @types;
8249: if (ref($order) eq 'ARRAY') {
8250: @types = @{$order};
8251: }
8252: if (@types == 0) {
8253: if (ref($usertypes) eq 'HASH') {
8254: @types = sort(keys(%{$usertypes}));
8255: }
8256: }
8257: if (keys(%{$usertypes}) > 0) {
8258: $othertitle = &mt('Other users');
8259: }
8260: return ($othertitle,$usertypes,\@types);
8261: }
8262:
1.645 raeburn 8263: sub get_institutional_codes {
8264: my ($settings,$allcourses,$LC_code) = @_;
8265: # Get complete list of course sections to update
8266: my @currsections = ();
8267: my @currxlists = ();
8268: my $coursecode = $$settings{'internal.coursecode'};
8269:
8270: if ($$settings{'internal.sectionnums'} ne '') {
8271: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8272: }
8273:
8274: if ($$settings{'internal.crosslistings'} ne '') {
8275: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8276: }
8277:
8278: if (@currxlists > 0) {
8279: foreach (@currxlists) {
8280: if (m/^([^:]+):(\w*)$/) {
8281: unless (grep/^$1$/,@{$allcourses}) {
8282: push @{$allcourses},$1;
8283: $$LC_code{$1} = $2;
8284: }
8285: }
8286: }
8287: }
8288:
8289: if (@currsections > 0) {
8290: foreach (@currsections) {
8291: if (m/^(\w+):(\w*)$/) {
8292: my $sec = $coursecode.$1;
8293: my $lc_sec = $2;
8294: unless (grep/^$sec$/,@{$allcourses}) {
8295: push @{$allcourses},$sec;
8296: $$LC_code{$sec} = $lc_sec;
8297: }
8298: }
8299: }
8300: }
8301: return;
8302: }
8303:
1.971 raeburn 8304: sub get_standard_codeitems {
8305: return ('Year','Semester','Department','Number','Section');
8306: }
8307:
1.112 bowersj2 8308: =pod
8309:
1.780 raeburn 8310: =head1 Slot Helpers
8311:
8312: =over 4
8313:
8314: =item * sorted_slots()
8315:
8316: Sorts an array of slot names in order of slot start time (earliest first).
8317:
8318: Inputs:
8319:
8320: =over 4
8321:
8322: slotsarr - Reference to array of unsorted slot names.
8323:
8324: slots - Reference to hash of hash, where outer hash keys are slot names.
8325:
1.549 albertel 8326: =back
8327:
1.780 raeburn 8328: Returns:
8329:
8330: =over 4
8331:
8332: sorted - An array of slot names sorted by the start time of the slot.
8333:
8334: =back
8335:
8336: =back
8337:
8338: =cut
8339:
8340:
8341: sub sorted_slots {
8342: my ($slotsarr,$slots) = @_;
8343: my @sorted;
8344: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8345: @sorted =
8346: sort {
8347: if (ref($slots->{$a}) && ref($slots->{$b})) {
8348: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8349: }
8350: if (ref($slots->{$a})) { return -1;}
8351: if (ref($slots->{$b})) { return 1;}
8352: return 0;
8353: } @{$slotsarr};
8354: }
8355: return @sorted;
8356: }
8357:
8358:
8359: =pod
8360:
1.549 albertel 8361: =head1 HTTP Helpers
8362:
8363: =over 4
8364:
1.648 raeburn 8365: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8366:
1.258 albertel 8367: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8368: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8369: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8370:
8371: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8372: $possible_names is an ref to an array of form element names. As an example:
8373: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8374: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8375:
8376: =cut
1.1 albertel 8377:
1.6 albertel 8378: sub get_unprocessed_cgi {
1.25 albertel 8379: my ($query,$possible_names)= @_;
1.26 matthew 8380: # $Apache::lonxml::debug=1;
1.356 albertel 8381: foreach my $pair (split(/&/,$query)) {
8382: my ($name, $value) = split(/=/,$pair);
1.369 www 8383: $name = &unescape($name);
1.25 albertel 8384: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8385: $value =~ tr/+/ /;
8386: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8387: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8388: }
1.16 harris41 8389: }
1.6 albertel 8390: }
8391:
1.112 bowersj2 8392: =pod
8393:
1.648 raeburn 8394: =item * &cacheheader()
1.112 bowersj2 8395:
8396: returns cache-controlling header code
8397:
8398: =cut
8399:
1.7 albertel 8400: sub cacheheader {
1.258 albertel 8401: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8402: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8403: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8404: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8405: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8406: return $output;
1.7 albertel 8407: }
8408:
1.112 bowersj2 8409: =pod
8410:
1.648 raeburn 8411: =item * &no_cache($r)
1.112 bowersj2 8412:
8413: specifies header code to not have cache
8414:
8415: =cut
8416:
1.9 albertel 8417: sub no_cache {
1.216 albertel 8418: my ($r) = @_;
8419: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8420: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8421: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8422: $r->no_cache(1);
8423: $r->header_out("Expires" => $date);
8424: $r->header_out("Pragma" => "no-cache");
1.123 www 8425: }
8426:
8427: sub content_type {
1.181 albertel 8428: my ($r,$type,$charset) = @_;
1.299 foxr 8429: if ($r) {
8430: # Note that printout.pl calls this with undef for $r.
8431: &no_cache($r);
8432: }
1.258 albertel 8433: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8434: unless ($charset) {
8435: $charset=&Apache::lonlocal::current_encoding;
8436: }
8437: if ($charset) { $type.='; charset='.$charset; }
8438: if ($r) {
8439: $r->content_type($type);
8440: } else {
8441: print("Content-type: $type\n\n");
8442: }
1.9 albertel 8443: }
1.25 albertel 8444:
1.112 bowersj2 8445: =pod
8446:
1.648 raeburn 8447: =item * &add_to_env($name,$value)
1.112 bowersj2 8448:
1.258 albertel 8449: adds $name to the %env hash with value
1.112 bowersj2 8450: $value, if $name already exists, the entry is converted to an array
8451: reference and $value is added to the array.
8452:
8453: =cut
8454:
1.25 albertel 8455: sub add_to_env {
8456: my ($name,$value)=@_;
1.258 albertel 8457: if (defined($env{$name})) {
8458: if (ref($env{$name})) {
1.25 albertel 8459: #already have multiple values
1.258 albertel 8460: push(@{ $env{$name} },$value);
1.25 albertel 8461: } else {
8462: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8463: my $first=$env{$name};
8464: undef($env{$name});
8465: push(@{ $env{$name} },$first,$value);
1.25 albertel 8466: }
8467: } else {
1.258 albertel 8468: $env{$name}=$value;
1.25 albertel 8469: }
1.31 albertel 8470: }
1.149 albertel 8471:
8472: =pod
8473:
1.648 raeburn 8474: =item * &get_env_multiple($name)
1.149 albertel 8475:
1.258 albertel 8476: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8477: values may be defined and end up as an array ref.
8478:
8479: returns an array of values
8480:
8481: =cut
8482:
8483: sub get_env_multiple {
8484: my ($name) = @_;
8485: my @values;
1.258 albertel 8486: if (defined($env{$name})) {
1.149 albertel 8487: # exists is it an array
1.258 albertel 8488: if (ref($env{$name})) {
8489: @values=@{ $env{$name} };
1.149 albertel 8490: } else {
1.258 albertel 8491: $values[0]=$env{$name};
1.149 albertel 8492: }
8493: }
8494: return(@values);
8495: }
8496:
1.660 raeburn 8497: sub ask_for_embedded_content {
8498: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.987 raeburn 8499: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660 raeburn 8500: my $num = 0;
1.987 raeburn 8501: my $numremref = 0;
8502: my $numinvalid = 0;
8503: my $numpathchg = 0;
8504: my $numexisting = 0;
8505: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.984 raeburn 8506: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8507: my $current_path='/';
8508: if ($env{'form.currentpath'}) {
8509: $current_path = $env{'form.currentpath'};
8510: }
8511: if ($actionurl eq '/adm/coursegrp_portfolio') {
8512: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8513: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8514: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8515: } else {
8516: $udom = $env{'user.domain'};
8517: $uname = $env{'user.name'};
8518: $url = '/userfiles/portfolio';
8519: }
1.987 raeburn 8520: $toplevel = $url.'/';
1.984 raeburn 8521: $url .= $current_path;
8522: $getpropath = 1;
1.987 raeburn 8523: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8524: ($actionurl eq '/adm/imsimport')) {
1.1022 www 8525: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 8526: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 8527: $toplevel = $url;
1.984 raeburn 8528: if ($rest ne '') {
1.987 raeburn 8529: $url .= $rest;
8530: }
8531: } elsif ($actionurl eq '/adm/coursedocs') {
8532: if (ref($args) eq 'HASH') {
8533: $url = $args->{'docs_url'};
8534: $toplevel = $url;
8535: }
8536: }
8537: my $now = time();
8538: foreach my $embed_file (keys(%{$allfiles})) {
8539: my $absolutepath;
8540: if ($embed_file =~ m{^\w+://}) {
8541: $newfiles{$embed_file} = 1;
8542: $mapping{$embed_file} = $embed_file;
8543: } else {
8544: if ($embed_file =~ m{^/}) {
8545: $absolutepath = $embed_file;
8546: $embed_file =~ s{^(/+)}{};
8547: }
8548: if ($embed_file =~ m{/}) {
8549: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8550: $path = &check_for_traversal($path,$url,$toplevel);
8551: my $item = $fname;
8552: if ($path ne '') {
8553: $item = $path.'/'.$fname;
8554: $subdependencies{$path}{$fname} = 1;
8555: } else {
8556: $dependencies{$item} = 1;
8557: }
8558: if ($absolutepath) {
8559: $mapping{$item} = $absolutepath;
8560: } else {
8561: $mapping{$item} = $embed_file;
8562: }
8563: } else {
8564: $dependencies{$embed_file} = 1;
8565: if ($absolutepath) {
8566: $mapping{$embed_file} = $absolutepath;
8567: } else {
8568: $mapping{$embed_file} = $embed_file;
8569: }
8570: }
1.984 raeburn 8571: }
8572: }
8573: foreach my $path (keys(%subdependencies)) {
8574: my %currsubfile;
8575: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 8576: my ($sublistref,$listerror) =
8577: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8578: if (ref($sublistref) eq 'ARRAY') {
8579: foreach my $line (@{$sublistref}) {
8580: my ($file_name,$rest) = split(/\&/,$line,2);
8581: $currsubfile{$file_name} = 1;
8582: }
1.984 raeburn 8583: }
1.987 raeburn 8584: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 8585: if (opendir(my $dir,$url.'/'.$path)) {
8586: my @subdir_list = grep(!/^\./,readdir($dir));
8587: map {$currsubfile{$_} = 1;} @subdir_list;
8588: }
8589: }
8590: foreach my $file (keys(%{$subdependencies{$path}})) {
1.987 raeburn 8591: if ($currsubfile{$file}) {
8592: my $item = $path.'/'.$file;
8593: unless ($mapping{$item} eq $item) {
8594: $pathchanges{$item} = 1;
8595: }
8596: $existing{$item} = 1;
8597: $numexisting ++;
8598: } else {
8599: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 8600: }
8601: }
8602: }
1.987 raeburn 8603: my %currfile;
1.984 raeburn 8604: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 8605: my ($dirlistref,$listerror) =
8606: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8607: if (ref($dirlistref) eq 'ARRAY') {
8608: foreach my $line (@{$dirlistref}) {
8609: my ($file_name,$rest) = split(/\&/,$line,2);
8610: $currfile{$file_name} = 1;
8611: }
1.984 raeburn 8612: }
1.987 raeburn 8613: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 8614: if (opendir(my $dir,$url)) {
1.987 raeburn 8615: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 8616: map {$currfile{$_} = 1;} @dir_list;
8617: }
8618: }
8619: foreach my $file (keys(%dependencies)) {
1.987 raeburn 8620: if ($currfile{$file}) {
8621: unless ($mapping{$file} eq $file) {
8622: $pathchanges{$file} = 1;
8623: }
8624: $existing{$file} = 1;
8625: $numexisting ++;
8626: } else {
1.984 raeburn 8627: $newfiles{$file} = 1;
8628: }
8629: }
8630: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8631: $upload_output .= &start_data_table_row().
1.987 raeburn 8632: '<td><span class="LC_filename">'.$embed_file.'</span>';
8633: unless ($mapping{$embed_file} eq $embed_file) {
8634: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
8635: }
8636: $upload_output .= '</td><td>';
1.660 raeburn 8637: if ($args->{'ignore_remote_references'}
8638: && $embed_file =~ m{^\w+://}) {
8639: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 8640: $numremref++;
1.660 raeburn 8641: } elsif ($args->{'error_on_invalid_names'}
8642: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8643:
1.987 raeburn 8644: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
8645: $numinvalid++;
1.660 raeburn 8646: } else {
1.987 raeburn 8647: $upload_output .= &embedded_file_element('upload_embedded',$num,
8648: $embed_file,\%mapping,
8649: $allfiles,$codebase);
8650: $num++;
8651: }
8652: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
8653: }
8654: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
8655: $upload_output .= &start_data_table_row().
8656: '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
8657: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
8658: &Apache::loncommon::end_data_table_row()."\n";
8659: }
8660: if ($upload_output) {
8661: $upload_output = &start_data_table().
8662: $upload_output.
8663: &end_data_table()."\n";
8664: }
8665: my $applies = 0;
8666: if ($numremref) {
8667: $applies ++;
8668: }
8669: if ($numinvalid) {
8670: $applies ++;
8671: }
8672: if ($numexisting) {
8673: $applies ++;
8674: }
8675: if ($num) {
8676: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8677: ' method="post" enctype="multipart/form-data">'."\n".
8678: $state.
8679: '<h3>'.&mt('Upload embedded files').
8680: ':</h3>'.$upload_output.'<br />'."\n".
8681: '<input type ="hidden" name="number_embedded_items" value="'.
8682: $num.'" />'."\n";
8683: if ($actionurl eq '') {
8684: $output .= '<input type="hidden" name="phase" value="three" />';
8685: }
8686: } elsif ($applies) {
8687: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
8688: if ($applies > 1) {
8689: $output .=
8690: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
8691: if ($numremref) {
8692: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
8693: }
8694: if ($numinvalid) {
8695: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
8696: }
8697: if ($numexisting) {
8698: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
8699: }
8700: $output .= '</ul><br />';
8701: } elsif ($numremref) {
8702: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
8703: } elsif ($numinvalid) {
8704: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
8705: } elsif ($numexisting) {
8706: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
8707: }
8708: $output .= $upload_output.'<br />';
8709: }
8710: my ($pathchange_output,$chgcount);
8711: $chgcount = $num;
8712: if (keys(%pathchanges) > 0) {
8713: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
8714: if ($num) {
8715: $output .= &embedded_file_element('pathchange',$chgcount,
8716: $embed_file,\%mapping,
8717: $allfiles,$codebase);
8718: } else {
8719: $pathchange_output .=
8720: &start_data_table_row().
8721: '<td><input type ="checkbox" name="namechange" value="'.
8722: $chgcount.'" checked="checked" /></td>'.
8723: '<td>'.$mapping{$embed_file}.'</td>'.
8724: '<td>'.$embed_file.
8725: &embedded_file_element('pathchange',$numpathchg,$embed_file,
8726: \%mapping,$allfiles,$codebase).
8727: '</td>'.&end_data_table_row();
1.660 raeburn 8728: }
1.987 raeburn 8729: $numpathchg ++;
8730: $chgcount ++;
1.660 raeburn 8731: }
8732: }
1.984 raeburn 8733: if ($num) {
1.987 raeburn 8734: if ($numpathchg) {
8735: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
8736: $numpathchg.'" />'."\n";
8737: }
8738: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8739: ($actionurl eq '/adm/imsimport')) {
8740: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
8741: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
8742: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
8743: }
8744: $output .= '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8745: &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
8746: } elsif ($numpathchg) {
8747: my %pathchange = ();
8748: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
8749: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8750: $output .= '<p>'.&mt('or').'</p>';
8751: }
8752: }
8753: return ($output,$num,$numpathchg);
8754: }
8755:
8756: sub embedded_file_element {
8757: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
8758: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
8759: (ref($codebase) eq 'HASH'));
8760: my $output;
8761: if ($context eq 'upload_embedded') {
8762: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
8763: }
8764: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
8765: &escape($embed_file).'" />';
8766: unless (($context eq 'upload_embedded') &&
8767: ($mapping->{$embed_file} eq $embed_file)) {
8768: $output .='
8769: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
8770: }
8771: my $attrib;
8772: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
8773: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
8774: }
8775: $output .=
8776: "\n\t\t".
8777: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8778: $attrib.'" />';
8779: if (exists($codebase->{$mapping->{$embed_file}})) {
8780: $output .=
8781: "\n\t\t".
8782: '<input name="codebase_'.$num.'" type="hidden" value="'.
8783: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 8784: }
1.987 raeburn 8785: return $output;
1.660 raeburn 8786: }
8787:
1.661 raeburn 8788: sub upload_embedded {
8789: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 8790: $current_disk_usage,$hiddenstate,$actionurl) = @_;
8791: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 8792: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8793: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8794: my $orig_uploaded_filename =
8795: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 8796: foreach my $type ('orig','ref','attrib','codebase') {
8797: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
8798: $env{'form.embedded_'.$type.'_'.$i} =
8799: &unescape($env{'form.embedded_'.$type.'_'.$i});
8800: }
8801: }
1.661 raeburn 8802: my ($path,$fname) =
8803: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8804: # no path, whole string is fname
8805: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8806: $fname = &Apache::lonnet::clean_filename($fname);
8807: # See if there is anything left
8808: next if ($fname eq '');
8809:
8810: # Check if file already exists as a file or directory.
8811: my ($state,$msg);
8812: if ($context eq 'portfolio') {
8813: my $port_path = $dirpath;
8814: if ($group ne '') {
8815: $port_path = "groups/$group/$port_path";
8816: }
1.987 raeburn 8817: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
8818: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 8819: $dir_root,$port_path,$disk_quota,
8820: $current_disk_usage,$uname,$udom);
8821: if ($state eq 'will_exceed_quota'
1.984 raeburn 8822: || $state eq 'file_locked') {
1.661 raeburn 8823: $output .= $msg;
8824: next;
8825: }
8826: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8827: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8828: if ($state eq 'exists') {
8829: $output .= $msg;
8830: next;
8831: }
8832: }
8833: # Check if extension is valid
8834: if (($fname =~ /\.(\w+)$/) &&
8835: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 8836: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 8837: next;
8838: } elsif (($fname =~ /\.(\w+)$/) &&
8839: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 8840: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 8841: next;
8842: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 8843: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 8844: next;
8845: }
8846:
8847: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8848: if ($context eq 'portfolio') {
1.984 raeburn 8849: my $result;
8850: if ($state eq 'existingfile') {
8851: $result=
8852: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 8853: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 8854: } else {
1.984 raeburn 8855: $result=
8856: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 8857: $dirpath.
8858: $env{'form.currentpath'}.$path);
1.984 raeburn 8859: if ($result !~ m|^/uploaded/|) {
8860: $output .= '<span class="LC_error">'
8861: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8862: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8863: .'</span><br />';
8864: next;
8865: } else {
1.987 raeburn 8866: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8867: $path.$fname.'</span>').'<br />';
1.984 raeburn 8868: }
1.661 raeburn 8869: }
1.987 raeburn 8870: } elsif ($context eq 'coursedoc') {
8871: my $result =
8872: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
8873: $dirpath.'/'.$path);
8874: if ($result !~ m|^/uploaded/|) {
8875: $output .= '<span class="LC_error">'
8876: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8877: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8878: .'</span><br />';
8879: next;
8880: } else {
8881: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8882: $path.$fname.'</span>').'<br />';
8883: }
1.661 raeburn 8884: } else {
8885: # Save the file
8886: my $target = $env{'form.embedded_item_'.$i};
8887: my $fullpath = $dir_root.$dirpath.'/'.$path;
8888: my $dest = $fullpath.$fname;
8889: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 8890: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 8891: my $count;
8892: my $filepath = $dir_root;
1.1027 raeburn 8893: foreach my $subdir (@parts) {
8894: $filepath .= "/$subdir";
8895: if (!-e $filepath) {
1.661 raeburn 8896: mkdir($filepath,0770);
8897: }
8898: }
8899: my $fh;
8900: if (!open($fh,'>'.$dest)) {
8901: &Apache::lonnet::logthis('Failed to create '.$dest);
8902: $output .= '<span class="LC_error">'.
8903: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8904: '</span><br />';
8905: } else {
8906: if (!print $fh $env{'form.embedded_item_'.$i}) {
8907: &Apache::lonnet::logthis('Failed to write to '.$dest);
8908: $output .= '<span class="LC_error">'.
8909: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8910: '</span><br />';
8911: } else {
1.987 raeburn 8912: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8913: $url.'</span>').'<br />';
8914: unless ($context eq 'testbank') {
8915: $footer .= &mt('View embedded file: [_1]',
8916: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
8917: }
8918: }
8919: close($fh);
8920: }
8921: }
8922: if ($env{'form.embedded_ref_'.$i}) {
8923: $pathchange{$i} = 1;
8924: }
8925: }
8926: if ($output) {
8927: $output = '<p>'.$output.'</p>';
8928: }
8929: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
8930: $returnflag = 'ok';
8931: if (keys(%pathchange) > 0) {
8932: if ($context eq 'portfolio') {
8933: $output .= '<p>'.&mt('or').'</p>';
8934: } elsif ($context eq 'testbank') {
1.988 raeburn 8935: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 8936: $returnflag = 'modify_orightml';
8937: }
8938: }
8939: return ($output.$footer,$returnflag);
8940: }
8941:
8942: sub modify_html_form {
8943: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
8944: my $end = 0;
8945: my $modifyform;
8946: if ($context eq 'upload_embedded') {
8947: return unless (ref($pathchange) eq 'HASH');
8948: if ($env{'form.number_embedded_items'}) {
8949: $end += $env{'form.number_embedded_items'};
8950: }
8951: if ($env{'form.number_pathchange_items'}) {
8952: $end += $env{'form.number_pathchange_items'};
8953: }
8954: if ($end) {
8955: for (my $i=0; $i<$end; $i++) {
8956: if ($i < $env{'form.number_embedded_items'}) {
8957: next unless($pathchange->{$i});
8958: }
8959: $modifyform .=
8960: &start_data_table_row().
8961: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
8962: 'checked="checked" /></td>'.
8963: '<td>'.$env{'form.embedded_ref_'.$i}.
8964: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
8965: &escape($env{'form.embedded_ref_'.$i}).'" />'.
8966: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
8967: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
8968: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
8969: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
8970: '<td>'.$env{'form.embedded_orig_'.$i}.
8971: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
8972: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
8973: &end_data_table_row();
8974: }
8975: }
8976: } else {
8977: $modifyform = $pathchgtable;
8978: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
8979: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
8980: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8981: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
8982: }
8983: }
8984: if ($modifyform) {
8985: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
8986: '<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".
8987: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
8988: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
8989: '</ol></p>'."\n".'<p>'.
8990: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
8991: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
8992: &start_data_table()."\n".
8993: &start_data_table_header_row().
8994: '<th>'.&mt('Change?').'</th>'.
8995: '<th>'.&mt('Current reference').'</th>'.
8996: '<th>'.&mt('Required reference').'</th>'.
8997: &end_data_table_header_row()."\n".
8998: $modifyform.
8999: &end_data_table().'<br />'."\n".$hiddenstate.
9000: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
9001: '</form>'."\n";
9002: }
9003: return;
9004: }
9005:
9006: sub modify_html_refs {
9007: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
9008: my $container;
9009: if ($context eq 'portfolio') {
9010: $container = $env{'form.container'};
9011: } elsif ($context eq 'coursedoc') {
9012: $container = $env{'form.primaryurl'};
9013: } else {
1.1027 raeburn 9014: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 9015: }
9016: my (%allfiles,%codebase,$output,$content);
9017: my @changes = &get_env_multiple('form.namechange');
9018: return unless (@changes > 0);
9019: if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
9020: return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
9021: $content = &Apache::lonnet::getfile($container);
9022: return if ($content eq '-1');
9023: } else {
9024: return unless ($container =~ /^\Q$dir_root\E/);
9025: if (open(my $fh,"<$container")) {
9026: $content = join('', <$fh>);
9027: close($fh);
9028: } else {
9029: return;
9030: }
9031: }
9032: my ($count,$codebasecount) = (0,0);
9033: my $mm = new File::MMagic;
9034: my $mime_type = $mm->checktype_contents($content);
9035: if ($mime_type eq 'text/html') {
9036: my $parse_result =
9037: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
9038: \%codebase,\$content);
9039: if ($parse_result eq 'ok') {
9040: foreach my $i (@changes) {
9041: my $orig = &unescape($env{'form.embedded_orig_'.$i});
9042: my $ref = &unescape($env{'form.embedded_ref_'.$i});
9043: if ($allfiles{$ref}) {
9044: my $newname = $orig;
9045: my ($attrib_regexp,$codebase);
1.1006 raeburn 9046: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 9047: if ($attrib_regexp =~ /:/) {
9048: $attrib_regexp =~ s/\:/|/g;
9049: }
9050: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
9051: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
9052: $count += $numchg;
9053: }
9054: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 9055: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 9056: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
9057: $codebasecount ++;
9058: }
9059: }
9060: }
9061: if ($count || $codebasecount) {
9062: my $saveresult;
9063: if ($context eq 'portfolio' || $context eq 'coursedoc') {
9064: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
9065: if ($url eq $container) {
9066: my ($fname) = ($container =~ m{/([^/]+)$});
9067: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9068: $count,'<span class="LC_filename">'.
9069: $fname.'</span>').'</p>';
9070: } else {
9071: $output = '<p class="LC_error">'.
9072: &mt('Error: update failed for: [_1].',
9073: '<span class="LC_filename">'.
9074: $container.'</span>').'</p>';
9075: }
9076: } else {
9077: if (open(my $fh,">$container")) {
9078: print $fh $content;
9079: close($fh);
9080: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9081: $count,'<span class="LC_filename">'.
9082: $container.'</span>').'</p>';
1.661 raeburn 9083: } else {
1.987 raeburn 9084: $output = '<p class="LC_error">'.
9085: &mt('Error: could not update [_1].',
9086: '<span class="LC_filename">'.
9087: $container.'</span>').'</p>';
1.661 raeburn 9088: }
9089: }
9090: }
1.987 raeburn 9091: } else {
9092: &logthis('Failed to parse '.$container.
9093: ' to modify references: '.$parse_result);
1.661 raeburn 9094: }
9095: }
9096: return $output;
9097: }
9098:
9099: sub check_for_existing {
9100: my ($path,$fname,$element) = @_;
9101: my ($state,$msg);
9102: if (-d $path.'/'.$fname) {
9103: $state = 'exists';
9104: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9105: } elsif (-e $path.'/'.$fname) {
9106: $state = 'exists';
9107: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9108: }
9109: if ($state eq 'exists') {
9110: $msg = '<span class="LC_error">'.$msg.'</span><br />';
9111: }
9112: return ($state,$msg);
9113: }
9114:
9115: sub check_for_upload {
9116: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
9117: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 9118: my $filesize = length($env{'form.'.$element});
9119: if (!$filesize) {
9120: my $msg = '<span class="LC_error">'.
9121: &mt('Unable to upload [_1]. (size = [_2] bytes)',
9122: '<span class="LC_filename">'.$fname.'</span>',
9123: $filesize).'<br />'.
1.1007 raeburn 9124: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 9125: '</span>';
9126: return ('zero_bytes',$msg);
9127: }
9128: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 9129: my $getpropath = 1;
1.1021 raeburn 9130: my ($dirlistref,$listerror) =
9131: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 9132: my $found_file = 0;
9133: my $locked_file = 0;
1.991 raeburn 9134: my @lockers;
9135: my $navmap;
9136: if ($env{'request.course.id'}) {
9137: $navmap = Apache::lonnavmaps::navmap->new();
9138: }
1.1021 raeburn 9139: if (ref($dirlistref) eq 'ARRAY') {
9140: foreach my $line (@{$dirlistref}) {
9141: my ($file_name,$rest)=split(/\&/,$line,2);
9142: if ($file_name eq $fname){
9143: $file_name = $path.$file_name;
9144: if ($group ne '') {
9145: $file_name = $group.$file_name;
9146: }
9147: $found_file = 1;
9148: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
9149: foreach my $lock (@lockers) {
9150: if (ref($lock) eq 'ARRAY') {
9151: my ($symb,$crsid) = @{$lock};
9152: if ($crsid eq $env{'request.course.id'}) {
9153: if (ref($navmap)) {
9154: my $res = $navmap->getBySymb($symb);
9155: foreach my $part (@{$res->parts()}) {
9156: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
9157: unless (($slot_status == $res->RESERVED) ||
9158: ($slot_status == $res->RESERVED_LOCATION)) {
9159: $locked_file = 1;
9160: }
1.991 raeburn 9161: }
1.1021 raeburn 9162: } else {
9163: $locked_file = 1;
1.991 raeburn 9164: }
9165: } else {
9166: $locked_file = 1;
9167: }
9168: }
1.1021 raeburn 9169: }
9170: } else {
9171: my @info = split(/\&/,$rest);
9172: my $currsize = $info[6]/1000;
9173: if ($currsize < $filesize) {
9174: my $extra = $filesize - $currsize;
9175: if (($current_disk_usage + $extra) > $disk_quota) {
9176: my $msg = '<span class="LC_error">'.
9177: &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.',
9178: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
9179: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
9180: $disk_quota,$current_disk_usage);
9181: return ('will_exceed_quota',$msg);
9182: }
1.984 raeburn 9183: }
9184: }
1.661 raeburn 9185: }
9186: }
9187: }
9188: if (($current_disk_usage + $filesize) > $disk_quota){
9189: my $msg = '<span class="LC_error">'.
9190: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
9191: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
9192: return ('will_exceed_quota',$msg);
9193: } elsif ($found_file) {
9194: if ($locked_file) {
9195: my $msg = '<span class="LC_error">';
9196: $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>');
9197: $msg .= '</span><br />';
9198: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
9199: return ('file_locked',$msg);
9200: } else {
9201: my $msg = '<span class="LC_error">';
1.984 raeburn 9202: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661 raeburn 9203: $msg .= '</span>';
1.984 raeburn 9204: return ('existingfile',$msg);
1.661 raeburn 9205: }
9206: }
9207: }
9208:
1.987 raeburn 9209: sub check_for_traversal {
9210: my ($path,$url,$toplevel) = @_;
9211: my @parts=split(/\//,$path);
9212: my $cleanpath;
9213: my $fullpath = $url;
9214: for (my $i=0;$i<@parts;$i++) {
9215: next if ($parts[$i] eq '.');
9216: if ($parts[$i] eq '..') {
9217: $fullpath =~ s{([^/]+/)$}{};
9218: } else {
9219: $fullpath .= $parts[$i].'/';
9220: }
9221: }
9222: if ($fullpath =~ /^\Q$url\E(.*)$/) {
9223: $cleanpath = $1;
9224: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
9225: my $curr_toprel = $1;
9226: my @parts = split(/\//,$curr_toprel);
9227: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
9228: my @urlparts = split(/\//,$url_toprel);
9229: my $doubledots;
9230: my $startdiff = -1;
9231: for (my $i=0; $i<@urlparts; $i++) {
9232: if ($startdiff == -1) {
9233: unless ($urlparts[$i] eq $parts[$i]) {
9234: $startdiff = $i;
9235: $doubledots .= '../';
9236: }
9237: } else {
9238: $doubledots .= '../';
9239: }
9240: }
9241: if ($startdiff > -1) {
9242: $cleanpath = $doubledots;
9243: for (my $i=$startdiff; $i<@parts; $i++) {
9244: $cleanpath .= $parts[$i].'/';
9245: }
9246: }
9247: }
9248: $cleanpath =~ s{(/)$}{};
9249: return $cleanpath;
9250: }
1.31 albertel 9251:
1.41 ng 9252: =pod
1.45 matthew 9253:
1.1015 raeburn 9254: =item * &get_turnedin_filepath()
9255:
9256: Determines path in a user's portfolio file for storage of files uploaded
9257: to a specific essayresponse or dropbox item.
9258:
9259: Inputs: 3 required + 1 optional.
9260: $symb is symb for resource, $uname and $udom are for current user (required).
9261: $caller is optional (can be "submission", if routine is called when storing
9262: an upoaded file when "Submit Answer" button was pressed).
9263:
9264: Returns array containing $path and $multiresp.
9265: $path is path in portfolio. $multiresp is 1 if this resource contains more
9266: than one file upload item. Callers of routine should append partid as a
9267: subdirectory to $path in cases where $multiresp is 1.
9268:
9269: Called by: homework/essayresponse.pm and homework/structuretags.pm
9270:
9271: =cut
9272:
9273: sub get_turnedin_filepath {
9274: my ($symb,$uname,$udom,$caller) = @_;
9275: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
9276: my $turnindir;
9277: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
9278: $turnindir = $userhash{'turnindir'};
9279: my ($path,$multiresp);
9280: if ($turnindir eq '') {
9281: if ($caller eq 'submission') {
9282: $turnindir = &mt('turned in');
9283: $turnindir =~ s/\W+/_/g;
9284: my %newhash = (
9285: 'turnindir' => $turnindir,
9286: );
9287: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
9288: }
9289: }
9290: if ($turnindir ne '') {
9291: $path = '/'.$turnindir.'/';
9292: my ($multipart,$turnin,@pathitems);
9293: my $navmap = Apache::lonnavmaps::navmap->new();
9294: if (defined($navmap)) {
9295: my $mapres = $navmap->getResourceByUrl($map);
9296: if (ref($mapres)) {
9297: my $pcslist = $mapres->map_hierarchy();
9298: if ($pcslist ne '') {
9299: foreach my $pc (split(/,/,$pcslist)) {
9300: my $res = $navmap->getByMapPc($pc);
9301: if (ref($res)) {
9302: my $title = $res->compTitle();
9303: $title =~ s/\W+/_/g;
9304: if ($title ne '') {
9305: push(@pathitems,$title);
9306: }
9307: }
9308: }
9309: }
9310: my $maptitle = $mapres->compTitle();
9311: $maptitle =~ s/\W+/_/g;
9312: if ($maptitle ne '') {
9313: push(@pathitems,$maptitle);
9314: }
9315: unless ($env{'request.state'} eq 'construct') {
9316: my $res = $navmap->getBySymb($symb);
9317: if (ref($res)) {
9318: my $partlist = $res->parts();
9319: my $totaluploads = 0;
9320: if (ref($partlist) eq 'ARRAY') {
9321: foreach my $part (@{$partlist}) {
9322: my @types = $res->responseType($part);
9323: my @ids = $res->responseIds($part);
9324: for (my $i=0; $i < scalar(@ids); $i++) {
9325: if ($types[$i] eq 'essay') {
9326: my $partid = $part.'_'.$ids[$i];
9327: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
9328: $totaluploads ++;
9329: }
9330: }
9331: }
9332: }
9333: if ($totaluploads > 1) {
9334: $multiresp = 1;
9335: }
9336: }
9337: }
9338: }
9339: } else {
9340: return;
9341: }
9342: } else {
9343: return;
9344: }
9345: my $restitle=&Apache::lonnet::gettitle($symb);
9346: $restitle =~ s/\W+/_/g;
9347: if ($restitle eq '') {
9348: $restitle = ($resurl =~ m{/[^/]+$});
9349: if ($restitle eq '') {
9350: $restitle = time;
9351: }
9352: }
9353: push(@pathitems,$restitle);
9354: $path .= join('/',@pathitems);
9355: }
9356: return ($path,$multiresp);
9357: }
9358:
9359: =pod
9360:
1.464 albertel 9361: =back
1.41 ng 9362:
1.112 bowersj2 9363: =head1 CSV Upload/Handling functions
1.38 albertel 9364:
1.41 ng 9365: =over 4
9366:
1.648 raeburn 9367: =item * &upfile_store($r)
1.41 ng 9368:
9369: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 9370: needs $env{'form.upfile'}
1.41 ng 9371: returns $datatoken to be put into hidden field
9372:
9373: =cut
1.31 albertel 9374:
9375: sub upfile_store {
9376: my $r=shift;
1.258 albertel 9377: $env{'form.upfile'}=~s/\r/\n/gs;
9378: $env{'form.upfile'}=~s/\f/\n/gs;
9379: $env{'form.upfile'}=~s/\n+/\n/gs;
9380: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 9381:
1.258 albertel 9382: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
9383: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 9384: {
1.158 raeburn 9385: my $datafile = $r->dir_config('lonDaemons').
9386: '/tmp/'.$datatoken.'.tmp';
9387: if ( open(my $fh,">$datafile") ) {
1.258 albertel 9388: print $fh $env{'form.upfile'};
1.158 raeburn 9389: close($fh);
9390: }
1.31 albertel 9391: }
9392: return $datatoken;
9393: }
9394:
1.56 matthew 9395: =pod
9396:
1.648 raeburn 9397: =item * &load_tmp_file($r)
1.41 ng 9398:
9399: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 9400: needs $env{'form.datatoken'},
9401: sets $env{'form.upfile'} to the contents of the file
1.41 ng 9402:
9403: =cut
1.31 albertel 9404:
9405: sub load_tmp_file {
9406: my $r=shift;
9407: my @studentdata=();
9408: {
1.158 raeburn 9409: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 9410: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 9411: if ( open(my $fh,"<$studentfile") ) {
9412: @studentdata=<$fh>;
9413: close($fh);
9414: }
1.31 albertel 9415: }
1.258 albertel 9416: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 9417: }
9418:
1.56 matthew 9419: =pod
9420:
1.648 raeburn 9421: =item * &upfile_record_sep()
1.41 ng 9422:
9423: Separate uploaded file into records
9424: returns array of records,
1.258 albertel 9425: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 9426:
9427: =cut
1.31 albertel 9428:
9429: sub upfile_record_sep {
1.258 albertel 9430: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 9431: } else {
1.248 albertel 9432: my @records;
1.258 albertel 9433: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 9434: if ($line=~/^\s*$/) { next; }
9435: push(@records,$line);
9436: }
9437: return @records;
1.31 albertel 9438: }
9439: }
9440:
1.56 matthew 9441: =pod
9442:
1.648 raeburn 9443: =item * &record_sep($record)
1.41 ng 9444:
1.258 albertel 9445: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 9446:
9447: =cut
9448:
1.263 www 9449: sub takeleft {
9450: my $index=shift;
9451: return substr('0000'.$index,-4,4);
9452: }
9453:
1.31 albertel 9454: sub record_sep {
9455: my $record=shift;
9456: my %components=();
1.258 albertel 9457: if ($env{'form.upfiletype'} eq 'xml') {
9458: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 9459: my $i=0;
1.356 albertel 9460: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 9461: $field=~s/^(\"|\')//;
9462: $field=~s/(\"|\')$//;
1.263 www 9463: $components{&takeleft($i)}=$field;
1.31 albertel 9464: $i++;
9465: }
1.258 albertel 9466: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 9467: my $i=0;
1.356 albertel 9468: foreach my $field (split(/\t/,$record)) {
1.31 albertel 9469: $field=~s/^(\"|\')//;
9470: $field=~s/(\"|\')$//;
1.263 www 9471: $components{&takeleft($i)}=$field;
1.31 albertel 9472: $i++;
9473: }
9474: } else {
1.561 www 9475: my $separator=',';
1.480 banghart 9476: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 9477: $separator=';';
1.480 banghart 9478: }
1.31 albertel 9479: my $i=0;
1.561 www 9480: # the character we are looking for to indicate the end of a quote or a record
9481: my $looking_for=$separator;
9482: # do not add the characters to the fields
9483: my $ignore=0;
9484: # we just encountered a separator (or the beginning of the record)
9485: my $just_found_separator=1;
9486: # store the field we are working on here
9487: my $field='';
9488: # work our way through all characters in record
9489: foreach my $character ($record=~/(.)/g) {
9490: if ($character eq $looking_for) {
9491: if ($character ne $separator) {
9492: # Found the end of a quote, again looking for separator
9493: $looking_for=$separator;
9494: $ignore=1;
9495: } else {
9496: # Found a separator, store away what we got
9497: $components{&takeleft($i)}=$field;
9498: $i++;
9499: $just_found_separator=1;
9500: $ignore=0;
9501: $field='';
9502: }
9503: next;
9504: }
9505: # single or double quotation marks after a separator indicate beginning of a quote
9506: # we are now looking for the end of the quote and need to ignore separators
9507: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
9508: $looking_for=$character;
9509: next;
9510: }
9511: # ignore would be true after we reached the end of a quote
9512: if ($ignore) { next; }
9513: if (($just_found_separator) && ($character=~/\s/)) { next; }
9514: $field.=$character;
9515: $just_found_separator=0;
1.31 albertel 9516: }
1.561 www 9517: # catch the very last entry, since we never encountered the separator
9518: $components{&takeleft($i)}=$field;
1.31 albertel 9519: }
9520: return %components;
9521: }
9522:
1.144 matthew 9523: ######################################################
9524: ######################################################
9525:
1.56 matthew 9526: =pod
9527:
1.648 raeburn 9528: =item * &upfile_select_html()
1.41 ng 9529:
1.144 matthew 9530: Return HTML code to select a file from the users machine and specify
9531: the file type.
1.41 ng 9532:
9533: =cut
9534:
1.144 matthew 9535: ######################################################
9536: ######################################################
1.31 albertel 9537: sub upfile_select_html {
1.144 matthew 9538: my %Types = (
9539: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 9540: semisv => &mt('Semicolon separated values'),
1.144 matthew 9541: space => &mt('Space separated'),
9542: tab => &mt('Tabulator separated'),
9543: # xml => &mt('HTML/XML'),
9544: );
9545: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 9546: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 9547: foreach my $type (sort(keys(%Types))) {
9548: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
9549: }
9550: $Str .= "</select>\n";
9551: return $Str;
1.31 albertel 9552: }
9553:
1.301 albertel 9554: sub get_samples {
9555: my ($records,$toget) = @_;
9556: my @samples=({});
9557: my $got=0;
9558: foreach my $rec (@$records) {
9559: my %temp = &record_sep($rec);
9560: if (! grep(/\S/, values(%temp))) { next; }
9561: if (%temp) {
9562: $samples[$got]=\%temp;
9563: $got++;
9564: if ($got == $toget) { last; }
9565: }
9566: }
9567: return \@samples;
9568: }
9569:
1.144 matthew 9570: ######################################################
9571: ######################################################
9572:
1.56 matthew 9573: =pod
9574:
1.648 raeburn 9575: =item * &csv_print_samples($r,$records)
1.41 ng 9576:
9577: Prints a table of sample values from each column uploaded $r is an
9578: Apache Request ref, $records is an arrayref from
9579: &Apache::loncommon::upfile_record_sep
9580:
9581: =cut
9582:
1.144 matthew 9583: ######################################################
9584: ######################################################
1.31 albertel 9585: sub csv_print_samples {
9586: my ($r,$records) = @_;
1.662 bisitz 9587: my $samples = &get_samples($records,5);
1.301 albertel 9588:
1.594 raeburn 9589: $r->print(&mt('Samples').'<br />'.&start_data_table().
9590: &start_data_table_header_row());
1.356 albertel 9591: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 9592: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 9593: $r->print(&end_data_table_header_row());
1.301 albertel 9594: foreach my $hash (@$samples) {
1.594 raeburn 9595: $r->print(&start_data_table_row());
1.356 albertel 9596: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 9597: $r->print('<td>');
1.356 albertel 9598: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 9599: $r->print('</td>');
9600: }
1.594 raeburn 9601: $r->print(&end_data_table_row());
1.31 albertel 9602: }
1.594 raeburn 9603: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 9604: }
9605:
1.144 matthew 9606: ######################################################
9607: ######################################################
9608:
1.56 matthew 9609: =pod
9610:
1.648 raeburn 9611: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 9612:
9613: Prints a table to create associations between values and table columns.
1.144 matthew 9614:
1.41 ng 9615: $r is an Apache Request ref,
9616: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 9617: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 9618:
9619: =cut
9620:
1.144 matthew 9621: ######################################################
9622: ######################################################
1.31 albertel 9623: sub csv_print_select_table {
9624: my ($r,$records,$d) = @_;
1.301 albertel 9625: my $i=0;
9626: my $samples = &get_samples($records,1);
1.144 matthew 9627: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 9628: &start_data_table().&start_data_table_header_row().
1.144 matthew 9629: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 9630: '<th>'.&mt('Column').'</th>'.
9631: &end_data_table_header_row()."\n");
1.356 albertel 9632: foreach my $array_ref (@$d) {
9633: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 9634: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 9635:
1.875 bisitz 9636: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 9637: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 9638: $r->print('<option value="none"></option>');
1.356 albertel 9639: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
9640: $r->print('<option value="'.$sample.'"'.
9641: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 9642: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 9643: }
1.594 raeburn 9644: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 9645: $i++;
9646: }
1.594 raeburn 9647: $r->print(&end_data_table());
1.31 albertel 9648: $i--;
9649: return $i;
9650: }
1.56 matthew 9651:
1.144 matthew 9652: ######################################################
9653: ######################################################
9654:
1.56 matthew 9655: =pod
1.31 albertel 9656:
1.648 raeburn 9657: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 9658:
9659: Prints a table of sample values from the upload and can make associate samples to internal names.
9660:
9661: $r is an Apache Request ref,
9662: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
9663: $d is an array of 2 element arrays (internal name, displayed name)
9664:
9665: =cut
9666:
1.144 matthew 9667: ######################################################
9668: ######################################################
1.31 albertel 9669: sub csv_samples_select_table {
9670: my ($r,$records,$d) = @_;
9671: my $i=0;
1.144 matthew 9672: #
1.662 bisitz 9673: my $max_samples = 5;
9674: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 9675: $r->print(&start_data_table().
9676: &start_data_table_header_row().'<th>'.
9677: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
9678: &end_data_table_header_row());
1.301 albertel 9679:
9680: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 9681: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 9682: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 9683: foreach my $option (@$d) {
9684: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 9685: $r->print('<option value="'.$value.'"'.
1.253 albertel 9686: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 9687: $display.'</option>');
1.31 albertel 9688: }
9689: $r->print('</select></td><td>');
1.662 bisitz 9690: foreach my $line (0..($max_samples-1)) {
1.301 albertel 9691: if (defined($samples->[$line]{$key})) {
9692: $r->print($samples->[$line]{$key}."<br />\n");
9693: }
9694: }
1.594 raeburn 9695: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9696: $i++;
9697: }
1.594 raeburn 9698: $r->print(&end_data_table());
1.31 albertel 9699: $i--;
9700: return($i);
1.115 matthew 9701: }
9702:
1.144 matthew 9703: ######################################################
9704: ######################################################
9705:
1.115 matthew 9706: =pod
9707:
1.648 raeburn 9708: =item * &clean_excel_name($name)
1.115 matthew 9709:
9710: Returns a replacement for $name which does not contain any illegal characters.
9711:
9712: =cut
9713:
1.144 matthew 9714: ######################################################
9715: ######################################################
1.115 matthew 9716: sub clean_excel_name {
9717: my ($name) = @_;
9718: $name =~ s/[:\*\?\/\\]//g;
9719: if (length($name) > 31) {
9720: $name = substr($name,0,31);
9721: }
9722: return $name;
1.25 albertel 9723: }
1.84 albertel 9724:
1.85 albertel 9725: =pod
9726:
1.648 raeburn 9727: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9728:
9729: Returns either 1 or undef
9730:
9731: 1 if the part is to be hidden, undef if it is to be shown
9732:
9733: Arguments are:
9734:
9735: $id the id of the part to be checked
9736: $symb, optional the symb of the resource to check
9737: $udom, optional the domain of the user to check for
9738: $uname, optional the username of the user to check for
9739:
9740: =cut
1.84 albertel 9741:
9742: sub check_if_partid_hidden {
9743: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9744: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9745: $symb,$udom,$uname);
1.141 albertel 9746: my $truth=1;
9747: #if the string starts with !, then the list is the list to show not hide
9748: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9749: my @hiddenlist=split(/,/,$hiddenparts);
9750: foreach my $checkid (@hiddenlist) {
1.141 albertel 9751: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9752: }
1.141 albertel 9753: return !$truth;
1.84 albertel 9754: }
1.127 matthew 9755:
1.138 matthew 9756:
9757: ############################################################
9758: ############################################################
9759:
9760: =pod
9761:
1.157 matthew 9762: =back
9763:
1.138 matthew 9764: =head1 cgi-bin script and graphing routines
9765:
1.157 matthew 9766: =over 4
9767:
1.648 raeburn 9768: =item * &get_cgi_id()
1.138 matthew 9769:
9770: Inputs: none
9771:
9772: Returns an id which can be used to pass environment variables
9773: to various cgi-bin scripts. These environment variables will
9774: be removed from the users environment after a given time by
9775: the routine &Apache::lonnet::transfer_profile_to_env.
9776:
9777: =cut
9778:
9779: ############################################################
9780: ############################################################
1.152 albertel 9781: my $uniq=0;
1.136 matthew 9782: sub get_cgi_id {
1.154 albertel 9783: $uniq=($uniq+1)%100000;
1.280 albertel 9784: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9785: }
9786:
1.127 matthew 9787: ############################################################
9788: ############################################################
9789:
9790: =pod
9791:
1.648 raeburn 9792: =item * &DrawBarGraph()
1.127 matthew 9793:
1.138 matthew 9794: Facilitates the plotting of data in a (stacked) bar graph.
9795: Puts plot definition data into the users environment in order for
9796: graph.png to plot it. Returns an <img> tag for the plot.
9797: The bars on the plot are labeled '1','2',...,'n'.
9798:
9799: Inputs:
9800:
9801: =over 4
9802:
9803: =item $Title: string, the title of the plot
9804:
9805: =item $xlabel: string, text describing the X-axis of the plot
9806:
9807: =item $ylabel: string, text describing the Y-axis of the plot
9808:
9809: =item $Max: scalar, the maximum Y value to use in the plot
9810: If $Max is < any data point, the graph will not be rendered.
9811:
1.140 matthew 9812: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9813: they are plotted. If undefined, default values will be used.
9814:
1.178 matthew 9815: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9816:
1.138 matthew 9817: =item @Values: An array of array references. Each array reference holds data
9818: to be plotted in a stacked bar chart.
9819:
1.239 matthew 9820: =item If the final element of @Values is a hash reference the key/value
9821: pairs will be added to the graph definition.
9822:
1.138 matthew 9823: =back
9824:
9825: Returns:
9826:
9827: An <img> tag which references graph.png and the appropriate identifying
9828: information for the plot.
9829:
1.127 matthew 9830: =cut
9831:
9832: ############################################################
9833: ############################################################
1.134 matthew 9834: sub DrawBarGraph {
1.178 matthew 9835: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9836: #
9837: if (! defined($colors)) {
9838: $colors = ['#33ff00',
9839: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9840: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9841: ];
9842: }
1.228 matthew 9843: my $extra_settings = {};
9844: if (ref($Values[-1]) eq 'HASH') {
9845: $extra_settings = pop(@Values);
9846: }
1.127 matthew 9847: #
1.136 matthew 9848: my $identifier = &get_cgi_id();
9849: my $id = 'cgi.'.$identifier;
1.129 matthew 9850: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9851: return '';
9852: }
1.225 matthew 9853: #
9854: my @Labels;
9855: if (defined($labels)) {
9856: @Labels = @$labels;
9857: } else {
9858: for (my $i=0;$i<@{$Values[0]};$i++) {
9859: push (@Labels,$i+1);
9860: }
9861: }
9862: #
1.129 matthew 9863: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9864: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9865: my %ValuesHash;
9866: my $NumSets=1;
9867: foreach my $array (@Values) {
9868: next if (! ref($array));
1.136 matthew 9869: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9870: join(',',@$array);
1.129 matthew 9871: }
1.127 matthew 9872: #
1.136 matthew 9873: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9874: if ($NumBars < 3) {
9875: $width = 120+$NumBars*32;
1.220 matthew 9876: $xskip = 1;
1.225 matthew 9877: $bar_width = 30;
9878: } elsif ($NumBars < 5) {
9879: $width = 120+$NumBars*20;
9880: $xskip = 1;
9881: $bar_width = 20;
1.220 matthew 9882: } elsif ($NumBars < 10) {
1.136 matthew 9883: $width = 120+$NumBars*15;
9884: $xskip = 1;
9885: $bar_width = 15;
9886: } elsif ($NumBars <= 25) {
9887: $width = 120+$NumBars*11;
9888: $xskip = 5;
9889: $bar_width = 8;
9890: } elsif ($NumBars <= 50) {
9891: $width = 120+$NumBars*8;
9892: $xskip = 5;
9893: $bar_width = 4;
9894: } else {
9895: $width = 120+$NumBars*8;
9896: $xskip = 5;
9897: $bar_width = 4;
9898: }
9899: #
1.137 matthew 9900: $Max = 1 if ($Max < 1);
9901: if ( int($Max) < $Max ) {
9902: $Max++;
9903: $Max = int($Max);
9904: }
1.127 matthew 9905: $Title = '' if (! defined($Title));
9906: $xlabel = '' if (! defined($xlabel));
9907: $ylabel = '' if (! defined($ylabel));
1.369 www 9908: $ValuesHash{$id.'.title'} = &escape($Title);
9909: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9910: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9911: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9912: $ValuesHash{$id.'.NumBars'} = $NumBars;
9913: $ValuesHash{$id.'.NumSets'} = $NumSets;
9914: $ValuesHash{$id.'.PlotType'} = 'bar';
9915: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9916: $ValuesHash{$id.'.height'} = $height;
9917: $ValuesHash{$id.'.width'} = $width;
9918: $ValuesHash{$id.'.xskip'} = $xskip;
9919: $ValuesHash{$id.'.bar_width'} = $bar_width;
9920: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9921: #
1.228 matthew 9922: # Deal with other parameters
9923: while (my ($key,$value) = each(%$extra_settings)) {
9924: $ValuesHash{$id.'.'.$key} = $value;
9925: }
9926: #
1.646 raeburn 9927: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9928: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9929: }
9930:
9931: ############################################################
9932: ############################################################
9933:
9934: =pod
9935:
1.648 raeburn 9936: =item * &DrawXYGraph()
1.137 matthew 9937:
1.138 matthew 9938: Facilitates the plotting of data in an XY graph.
9939: Puts plot definition data into the users environment in order for
9940: graph.png to plot it. Returns an <img> tag for the plot.
9941:
9942: Inputs:
9943:
9944: =over 4
9945:
9946: =item $Title: string, the title of the plot
9947:
9948: =item $xlabel: string, text describing the X-axis of the plot
9949:
9950: =item $ylabel: string, text describing the Y-axis of the plot
9951:
9952: =item $Max: scalar, the maximum Y value to use in the plot
9953: If $Max is < any data point, the graph will not be rendered.
9954:
9955: =item $colors: Array ref containing the hex color codes for the data to be
9956: plotted in. If undefined, default values will be used.
9957:
9958: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9959:
9960: =item $Ydata: Array ref containing Array refs.
1.185 www 9961: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9962:
9963: =item %Values: hash indicating or overriding any default values which are
9964: passed to graph.png.
9965: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9966:
9967: =back
9968:
9969: Returns:
9970:
9971: An <img> tag which references graph.png and the appropriate identifying
9972: information for the plot.
9973:
1.137 matthew 9974: =cut
9975:
9976: ############################################################
9977: ############################################################
9978: sub DrawXYGraph {
9979: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9980: #
9981: # Create the identifier for the graph
9982: my $identifier = &get_cgi_id();
9983: my $id = 'cgi.'.$identifier;
9984: #
9985: $Title = '' if (! defined($Title));
9986: $xlabel = '' if (! defined($xlabel));
9987: $ylabel = '' if (! defined($ylabel));
9988: my %ValuesHash =
9989: (
1.369 www 9990: $id.'.title' => &escape($Title),
9991: $id.'.xlabel' => &escape($xlabel),
9992: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9993: $id.'.y_max_value'=> $Max,
9994: $id.'.labels' => join(',',@$Xlabels),
9995: $id.'.PlotType' => 'XY',
9996: );
9997: #
9998: if (defined($colors) && ref($colors) eq 'ARRAY') {
9999: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
10000: }
10001: #
10002: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
10003: return '';
10004: }
10005: my $NumSets=1;
1.138 matthew 10006: foreach my $array (@{$Ydata}){
1.137 matthew 10007: next if (! ref($array));
10008: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
10009: }
1.138 matthew 10010: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 10011: #
10012: # Deal with other parameters
10013: while (my ($key,$value) = each(%Values)) {
10014: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 10015: }
10016: #
1.646 raeburn 10017: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 10018: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
10019: }
10020:
10021: ############################################################
10022: ############################################################
10023:
10024: =pod
10025:
1.648 raeburn 10026: =item * &DrawXYYGraph()
1.138 matthew 10027:
10028: Facilitates the plotting of data in an XY graph with two Y axes.
10029: Puts plot definition data into the users environment in order for
10030: graph.png to plot it. Returns an <img> tag for the plot.
10031:
10032: Inputs:
10033:
10034: =over 4
10035:
10036: =item $Title: string, the title of the plot
10037:
10038: =item $xlabel: string, text describing the X-axis of the plot
10039:
10040: =item $ylabel: string, text describing the Y-axis of the plot
10041:
10042: =item $colors: Array ref containing the hex color codes for the data to be
10043: plotted in. If undefined, default values will be used.
10044:
10045: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
10046:
10047: =item $Ydata1: The first data set
10048:
10049: =item $Min1: The minimum value of the left Y-axis
10050:
10051: =item $Max1: The maximum value of the left Y-axis
10052:
10053: =item $Ydata2: The second data set
10054:
10055: =item $Min2: The minimum value of the right Y-axis
10056:
10057: =item $Max2: The maximum value of the left Y-axis
10058:
10059: =item %Values: hash indicating or overriding any default values which are
10060: passed to graph.png.
10061: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
10062:
10063: =back
10064:
10065: Returns:
10066:
10067: An <img> tag which references graph.png and the appropriate identifying
10068: information for the plot.
1.136 matthew 10069:
10070: =cut
10071:
10072: ############################################################
10073: ############################################################
1.137 matthew 10074: sub DrawXYYGraph {
10075: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
10076: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 10077: #
10078: # Create the identifier for the graph
10079: my $identifier = &get_cgi_id();
10080: my $id = 'cgi.'.$identifier;
10081: #
10082: $Title = '' if (! defined($Title));
10083: $xlabel = '' if (! defined($xlabel));
10084: $ylabel = '' if (! defined($ylabel));
10085: my %ValuesHash =
10086: (
1.369 www 10087: $id.'.title' => &escape($Title),
10088: $id.'.xlabel' => &escape($xlabel),
10089: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 10090: $id.'.labels' => join(',',@$Xlabels),
10091: $id.'.PlotType' => 'XY',
10092: $id.'.NumSets' => 2,
1.137 matthew 10093: $id.'.two_axes' => 1,
10094: $id.'.y1_max_value' => $Max1,
10095: $id.'.y1_min_value' => $Min1,
10096: $id.'.y2_max_value' => $Max2,
10097: $id.'.y2_min_value' => $Min2,
1.136 matthew 10098: );
10099: #
1.137 matthew 10100: if (defined($colors) && ref($colors) eq 'ARRAY') {
10101: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
10102: }
10103: #
10104: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
10105: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 10106: return '';
10107: }
10108: my $NumSets=1;
1.137 matthew 10109: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 10110: next if (! ref($array));
10111: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 10112: }
10113: #
10114: # Deal with other parameters
10115: while (my ($key,$value) = each(%Values)) {
10116: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 10117: }
10118: #
1.646 raeburn 10119: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 10120: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 10121: }
10122:
10123: ############################################################
10124: ############################################################
10125:
10126: =pod
10127:
1.157 matthew 10128: =back
10129:
1.139 matthew 10130: =head1 Statistics helper routines?
10131:
10132: Bad place for them but what the hell.
10133:
1.157 matthew 10134: =over 4
10135:
1.648 raeburn 10136: =item * &chartlink()
1.139 matthew 10137:
10138: Returns a link to the chart for a specific student.
10139:
10140: Inputs:
10141:
10142: =over 4
10143:
10144: =item $linktext: The text of the link
10145:
10146: =item $sname: The students username
10147:
10148: =item $sdomain: The students domain
10149:
10150: =back
10151:
1.157 matthew 10152: =back
10153:
1.139 matthew 10154: =cut
10155:
10156: ############################################################
10157: ############################################################
10158: sub chartlink {
10159: my ($linktext, $sname, $sdomain) = @_;
10160: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 10161: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 10162: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 10163: '">'.$linktext.'</a>';
1.153 matthew 10164: }
10165:
10166: #######################################################
10167: #######################################################
10168:
10169: =pod
10170:
10171: =head1 Course Environment Routines
1.157 matthew 10172:
10173: =over 4
1.153 matthew 10174:
1.648 raeburn 10175: =item * &restore_course_settings()
1.153 matthew 10176:
1.648 raeburn 10177: =item * &store_course_settings()
1.153 matthew 10178:
10179: Restores/Store indicated form parameters from the course environment.
10180: Will not overwrite existing values of the form parameters.
10181:
10182: Inputs:
10183: a scalar describing the data (e.g. 'chart', 'problem_analysis')
10184:
10185: a hash ref describing the data to be stored. For example:
10186:
10187: %Save_Parameters = ('Status' => 'scalar',
10188: 'chartoutputmode' => 'scalar',
10189: 'chartoutputdata' => 'scalar',
10190: 'Section' => 'array',
1.373 raeburn 10191: 'Group' => 'array',
1.153 matthew 10192: 'StudentData' => 'array',
10193: 'Maps' => 'array');
10194:
10195: Returns: both routines return nothing
10196:
1.631 raeburn 10197: =back
10198:
1.153 matthew 10199: =cut
10200:
10201: #######################################################
10202: #######################################################
10203: sub store_course_settings {
1.496 albertel 10204: return &store_settings($env{'request.course.id'},@_);
10205: }
10206:
10207: sub store_settings {
1.153 matthew 10208: # save to the environment
10209: # appenv the same items, just to be safe
1.300 albertel 10210: my $udom = $env{'user.domain'};
10211: my $uname = $env{'user.name'};
1.496 albertel 10212: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10213: my %SaveHash;
10214: my %AppHash;
10215: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 10216: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 10217: my $envname = 'environment.'.$basename;
1.258 albertel 10218: if (exists($env{'form.'.$setting})) {
1.153 matthew 10219: # Save this value away
10220: if ($type eq 'scalar' &&
1.258 albertel 10221: (! exists($env{$envname}) ||
10222: $env{$envname} ne $env{'form.'.$setting})) {
10223: $SaveHash{$basename} = $env{'form.'.$setting};
10224: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 10225: } elsif ($type eq 'array') {
10226: my $stored_form;
1.258 albertel 10227: if (ref($env{'form.'.$setting})) {
1.153 matthew 10228: $stored_form = join(',',
10229: map {
1.369 www 10230: &escape($_);
1.258 albertel 10231: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 10232: } else {
10233: $stored_form =
1.369 www 10234: &escape($env{'form.'.$setting});
1.153 matthew 10235: }
10236: # Determine if the array contents are the same.
1.258 albertel 10237: if ($stored_form ne $env{$envname}) {
1.153 matthew 10238: $SaveHash{$basename} = $stored_form;
10239: $AppHash{$envname} = $stored_form;
10240: }
10241: }
10242: }
10243: }
10244: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 10245: $udom,$uname);
1.153 matthew 10246: if ($put_result !~ /^(ok|delayed)/) {
10247: &Apache::lonnet::logthis('unable to save form parameters, '.
10248: 'got error:'.$put_result);
10249: }
10250: # Make sure these settings stick around in this session, too
1.646 raeburn 10251: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 10252: return;
10253: }
10254:
10255: sub restore_course_settings {
1.499 albertel 10256: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 10257: }
10258:
10259: sub restore_settings {
10260: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10261: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 10262: next if (exists($env{'form.'.$setting}));
1.496 albertel 10263: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 10264: '.'.$setting;
1.258 albertel 10265: if (exists($env{$envname})) {
1.153 matthew 10266: if ($type eq 'scalar') {
1.258 albertel 10267: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 10268: } elsif ($type eq 'array') {
1.258 albertel 10269: $env{'form.'.$setting} = [
1.153 matthew 10270: map {
1.369 www 10271: &unescape($_);
1.258 albertel 10272: } split(',',$env{$envname})
1.153 matthew 10273: ];
10274: }
10275: }
10276: }
1.127 matthew 10277: }
10278:
1.618 raeburn 10279: #######################################################
10280: #######################################################
10281:
10282: =pod
10283:
10284: =head1 Domain E-mail Routines
10285:
10286: =over 4
10287:
1.648 raeburn 10288: =item * &build_recipient_list()
1.618 raeburn 10289:
1.884 raeburn 10290: Build recipient lists for five types of e-mail:
1.766 raeburn 10291: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 10292: (d) Help requests, (e) Course requests needing approval, generated by
10293: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
10294: loncoursequeueadmin.pm respectively.
1.618 raeburn 10295:
10296: Inputs:
1.619 raeburn 10297: defmail (scalar - email address of default recipient),
1.618 raeburn 10298: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 10299: defdom (domain for which to retrieve configuration settings),
10300: origmail (scalar - email address of recipient from loncapa.conf,
10301: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 10302:
1.655 raeburn 10303: Returns: comma separated list of addresses to which to send e-mail.
10304:
10305: =back
1.618 raeburn 10306:
10307: =cut
10308:
10309: ############################################################
10310: ############################################################
10311: sub build_recipient_list {
1.619 raeburn 10312: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 10313: my @recipients;
10314: my $otheremails;
10315: my %domconfig =
10316: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
10317: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 10318: if (exists($domconfig{'contacts'}{$mailing})) {
10319: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
10320: my @contacts = ('adminemail','supportemail');
10321: foreach my $item (@contacts) {
10322: if ($domconfig{'contacts'}{$mailing}{$item}) {
10323: my $addr = $domconfig{'contacts'}{$item};
10324: if (!grep(/^\Q$addr\E$/,@recipients)) {
10325: push(@recipients,$addr);
10326: }
1.619 raeburn 10327: }
1.766 raeburn 10328: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 10329: }
10330: }
1.766 raeburn 10331: } elsif ($origmail ne '') {
10332: push(@recipients,$origmail);
1.618 raeburn 10333: }
1.619 raeburn 10334: } elsif ($origmail ne '') {
10335: push(@recipients,$origmail);
1.618 raeburn 10336: }
1.688 raeburn 10337: if (defined($defmail)) {
10338: if ($defmail ne '') {
10339: push(@recipients,$defmail);
10340: }
1.618 raeburn 10341: }
10342: if ($otheremails) {
1.619 raeburn 10343: my @others;
10344: if ($otheremails =~ /,/) {
10345: @others = split(/,/,$otheremails);
1.618 raeburn 10346: } else {
1.619 raeburn 10347: push(@others,$otheremails);
10348: }
10349: foreach my $addr (@others) {
10350: if (!grep(/^\Q$addr\E$/,@recipients)) {
10351: push(@recipients,$addr);
10352: }
1.618 raeburn 10353: }
10354: }
1.619 raeburn 10355: my $recipientlist = join(',',@recipients);
1.618 raeburn 10356: return $recipientlist;
10357: }
10358:
1.127 matthew 10359: ############################################################
10360: ############################################################
1.154 albertel 10361:
1.655 raeburn 10362: =pod
10363:
10364: =head1 Course Catalog Routines
10365:
10366: =over 4
10367:
10368: =item * &gather_categories()
10369:
10370: Converts category definitions - keys of categories hash stored in
10371: coursecategories in configuration.db on the primary library server in a
10372: domain - to an array. Also generates javascript and idx hash used to
10373: generate Domain Coordinator interface for editing Course Categories.
10374:
10375: Inputs:
1.663 raeburn 10376:
1.655 raeburn 10377: categories (reference to hash of category definitions).
1.663 raeburn 10378:
1.655 raeburn 10379: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10380: categories and subcategories).
1.663 raeburn 10381:
1.655 raeburn 10382: idx (reference to hash of counters used in Domain Coordinator interface for
10383: editing Course Categories).
1.663 raeburn 10384:
1.655 raeburn 10385: jsarray (reference to array of categories used to create Javascript arrays for
10386: Domain Coordinator interface for editing Course Categories).
10387:
10388: Returns: nothing
10389:
10390: Side effects: populates cats, idx and jsarray.
10391:
10392: =cut
10393:
10394: sub gather_categories {
10395: my ($categories,$cats,$idx,$jsarray) = @_;
10396: my %counters;
10397: my $num = 0;
10398: foreach my $item (keys(%{$categories})) {
10399: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10400: if ($container eq '' && $depth == 0) {
10401: $cats->[$depth][$categories->{$item}] = $cat;
10402: } else {
10403: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
10404: }
10405: my ($escitem,$tail) = split(/:/,$item,2);
10406: if ($counters{$tail} eq '') {
10407: $counters{$tail} = $num;
10408: $num ++;
10409: }
10410: if (ref($idx) eq 'HASH') {
10411: $idx->{$item} = $counters{$tail};
10412: }
10413: if (ref($jsarray) eq 'ARRAY') {
10414: push(@{$jsarray->[$counters{$tail}]},$item);
10415: }
10416: }
10417: return;
10418: }
10419:
10420: =pod
10421:
10422: =item * &extract_categories()
10423:
10424: Used to generate breadcrumb trails for course categories.
10425:
10426: Inputs:
1.663 raeburn 10427:
1.655 raeburn 10428: categories (reference to hash of category definitions).
1.663 raeburn 10429:
1.655 raeburn 10430: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10431: categories and subcategories).
1.663 raeburn 10432:
1.655 raeburn 10433: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 10434:
1.655 raeburn 10435: allitems (reference to hash - key is category key
10436: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10437:
1.655 raeburn 10438: idx (reference to hash of counters used in Domain Coordinator interface for
10439: editing Course Categories).
1.663 raeburn 10440:
1.655 raeburn 10441: jsarray (reference to array of categories used to create Javascript arrays for
10442: Domain Coordinator interface for editing Course Categories).
10443:
1.665 raeburn 10444: subcats (reference to hash of arrays containing all subcategories within each
10445: category, -recursive)
10446:
1.655 raeburn 10447: Returns: nothing
10448:
10449: Side effects: populates trails and allitems hash references.
10450:
10451: =cut
10452:
10453: sub extract_categories {
1.665 raeburn 10454: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 10455: if (ref($categories) eq 'HASH') {
10456: &gather_categories($categories,$cats,$idx,$jsarray);
10457: if (ref($cats->[0]) eq 'ARRAY') {
10458: for (my $i=0; $i<@{$cats->[0]}; $i++) {
10459: my $name = $cats->[0][$i];
10460: my $item = &escape($name).'::0';
10461: my $trailstr;
10462: if ($name eq 'instcode') {
10463: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 10464: } elsif ($name eq 'communities') {
10465: $trailstr = &mt('Communities');
1.655 raeburn 10466: } else {
10467: $trailstr = $name;
10468: }
10469: if ($allitems->{$item} eq '') {
10470: push(@{$trails},$trailstr);
10471: $allitems->{$item} = scalar(@{$trails})-1;
10472: }
10473: my @parents = ($name);
10474: if (ref($cats->[1]{$name}) eq 'ARRAY') {
10475: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
10476: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 10477: if (ref($subcats) eq 'HASH') {
10478: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
10479: }
10480: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
10481: }
10482: } else {
10483: if (ref($subcats) eq 'HASH') {
10484: $subcats->{$item} = [];
1.655 raeburn 10485: }
10486: }
10487: }
10488: }
10489: }
10490: return;
10491: }
10492:
10493: =pod
10494:
10495: =item *&recurse_categories()
10496:
10497: Recursively used to generate breadcrumb trails for course categories.
10498:
10499: Inputs:
1.663 raeburn 10500:
1.655 raeburn 10501: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10502: categories and subcategories).
1.663 raeburn 10503:
1.655 raeburn 10504: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 10505:
10506: category (current course category, for which breadcrumb trail is being generated).
10507:
10508: trails (reference to array of breadcrumb trails for each category).
10509:
1.655 raeburn 10510: allitems (reference to hash - key is category key
10511: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10512:
1.655 raeburn 10513: parents (array containing containers directories for current category,
10514: back to top level).
10515:
10516: Returns: nothing
10517:
10518: Side effects: populates trails and allitems hash references
10519:
10520: =cut
10521:
10522: sub recurse_categories {
1.665 raeburn 10523: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 10524: my $shallower = $depth - 1;
10525: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
10526: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
10527: my $name = $cats->[$depth]{$category}[$k];
10528: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10529: my $trailstr = join(' -> ',(@{$parents},$category));
10530: if ($allitems->{$item} eq '') {
10531: push(@{$trails},$trailstr);
10532: $allitems->{$item} = scalar(@{$trails})-1;
10533: }
10534: my $deeper = $depth+1;
10535: push(@{$parents},$category);
1.665 raeburn 10536: if (ref($subcats) eq 'HASH') {
10537: my $subcat = &escape($name).':'.$category.':'.$depth;
10538: for (my $j=@{$parents}; $j>=0; $j--) {
10539: my $higher;
10540: if ($j > 0) {
10541: $higher = &escape($parents->[$j]).':'.
10542: &escape($parents->[$j-1]).':'.$j;
10543: } else {
10544: $higher = &escape($parents->[$j]).'::'.$j;
10545: }
10546: push(@{$subcats->{$higher}},$subcat);
10547: }
10548: }
10549: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
10550: $subcats);
1.655 raeburn 10551: pop(@{$parents});
10552: }
10553: } else {
10554: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10555: my $trailstr = join(' -> ',(@{$parents},$category));
10556: if ($allitems->{$item} eq '') {
10557: push(@{$trails},$trailstr);
10558: $allitems->{$item} = scalar(@{$trails})-1;
10559: }
10560: }
10561: return;
10562: }
10563:
1.663 raeburn 10564: =pod
10565:
10566: =item *&assign_categories_table()
10567:
10568: Create a datatable for display of hierarchical categories in a domain,
10569: with checkboxes to allow a course to be categorized.
10570:
10571: Inputs:
10572:
10573: cathash - reference to hash of categories defined for the domain (from
10574: configuration.db)
10575:
10576: currcat - scalar with an & separated list of categories assigned to a course.
10577:
1.919 raeburn 10578: type - scalar contains course type (Course or Community).
10579:
1.663 raeburn 10580: Returns: $output (markup to be displayed)
10581:
10582: =cut
10583:
10584: sub assign_categories_table {
1.919 raeburn 10585: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 10586: my $output;
10587: if (ref($cathash) eq 'HASH') {
10588: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
10589: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
10590: $maxdepth = scalar(@cats);
10591: if (@cats > 0) {
10592: my $itemcount = 0;
10593: if (ref($cats[0]) eq 'ARRAY') {
10594: my @currcategories;
10595: if ($currcat ne '') {
10596: @currcategories = split('&',$currcat);
10597: }
1.919 raeburn 10598: my $table;
1.663 raeburn 10599: for (my $i=0; $i<@{$cats[0]}; $i++) {
10600: my $parent = $cats[0][$i];
1.919 raeburn 10601: next if ($parent eq 'instcode');
10602: if ($type eq 'Community') {
10603: next unless ($parent eq 'communities');
10604: } else {
10605: next if ($parent eq 'communities');
10606: }
1.663 raeburn 10607: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10608: my $item = &escape($parent).'::0';
10609: my $checked = '';
10610: if (@currcategories > 0) {
10611: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 10612: $checked = ' checked="checked"';
1.663 raeburn 10613: }
10614: }
1.919 raeburn 10615: my $parent_title = $parent;
10616: if ($parent eq 'communities') {
10617: $parent_title = &mt('Communities');
10618: }
10619: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
10620: '<input type="checkbox" name="usecategory" value="'.
10621: $item.'"'.$checked.' />'.$parent_title.'</span>'.
10622: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 10623: my $depth = 1;
10624: push(@path,$parent);
1.919 raeburn 10625: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 10626: pop(@path);
1.919 raeburn 10627: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 10628: $itemcount ++;
10629: }
1.919 raeburn 10630: if ($itemcount) {
10631: $output = &Apache::loncommon::start_data_table().
10632: $table.
10633: &Apache::loncommon::end_data_table();
10634: }
1.663 raeburn 10635: }
10636: }
10637: }
10638: return $output;
10639: }
10640:
10641: =pod
10642:
10643: =item *&assign_category_rows()
10644:
10645: Create a datatable row for display of nested categories in a domain,
10646: with checkboxes to allow a course to be categorized,called recursively.
10647:
10648: Inputs:
10649:
10650: itemcount - track row number for alternating colors
10651:
10652: cats - reference to array of arrays/hashes which encapsulates hierarchy of
10653: categories and subcategories.
10654:
10655: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
10656:
10657: parent - parent of current category item
10658:
10659: path - Array containing all categories back up through the hierarchy from the
10660: current category to the top level.
10661:
10662: currcategories - reference to array of current categories assigned to the course
10663:
10664: Returns: $output (markup to be displayed).
10665:
10666: =cut
10667:
10668: sub assign_category_rows {
10669: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
10670: my ($text,$name,$item,$chgstr);
10671: if (ref($cats) eq 'ARRAY') {
10672: my $maxdepth = scalar(@{$cats});
10673: if (ref($cats->[$depth]) eq 'HASH') {
10674: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10675: my $numchildren = @{$cats->[$depth]{$parent}};
10676: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10677: $text .= '<td><table class="LC_datatable">';
10678: for (my $j=0; $j<$numchildren; $j++) {
10679: $name = $cats->[$depth]{$parent}[$j];
10680: $item = &escape($name).':'.&escape($parent).':'.$depth;
10681: my $deeper = $depth+1;
10682: my $checked = '';
10683: if (ref($currcategories) eq 'ARRAY') {
10684: if (@{$currcategories} > 0) {
10685: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 10686: $checked = ' checked="checked"';
1.663 raeburn 10687: }
10688: }
10689: }
1.664 raeburn 10690: $text .= '<tr><td><span class="LC_nobreak"><label>'.
10691: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 10692: $item.'"'.$checked.' />'.$name.'</label></span>'.
10693: '<input type="hidden" name="catname" value="'.$name.'" />'.
10694: '</td><td>';
1.663 raeburn 10695: if (ref($path) eq 'ARRAY') {
10696: push(@{$path},$name);
10697: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10698: pop(@{$path});
10699: }
10700: $text .= '</td></tr>';
10701: }
10702: $text .= '</table></td>';
10703: }
10704: }
10705: }
10706: return $text;
10707: }
10708:
1.655 raeburn 10709: ############################################################
10710: ############################################################
10711:
10712:
1.443 albertel 10713: sub commit_customrole {
1.664 raeburn 10714: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10715: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10716: ($start?', '.&mt('starting').' '.localtime($start):'').
10717: ($end?', ending '.localtime($end):'').': <b>'.
10718: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10719: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10720: '</b><br />';
10721: return $output;
10722: }
10723:
10724: sub commit_standardrole {
1.541 raeburn 10725: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10726: my ($output,$logmsg,$linefeed);
10727: if ($context eq 'auto') {
10728: $linefeed = "\n";
10729: } else {
10730: $linefeed = "<br />\n";
10731: }
1.443 albertel 10732: if ($three eq 'st') {
1.541 raeburn 10733: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10734: $one,$two,$sec,$context);
10735: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10736: ($result eq 'unknown_course') || ($result eq 'refused')) {
10737: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10738: } else {
1.541 raeburn 10739: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10740: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10741: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10742: if ($context eq 'auto') {
10743: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10744: } else {
10745: $output .= '<b>'.$result.'</b>'.$linefeed.
10746: &mt('Add to classlist').': <b>ok</b>';
10747: }
10748: $output .= $linefeed;
1.443 albertel 10749: }
10750: } else {
10751: $output = &mt('Assigning').' '.$three.' in '.$url.
10752: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10753: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10754: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10755: if ($context eq 'auto') {
10756: $output .= $result.$linefeed;
10757: } else {
10758: $output .= '<b>'.$result.'</b>'.$linefeed;
10759: }
1.443 albertel 10760: }
10761: return $output;
10762: }
10763:
10764: sub commit_studentrole {
1.541 raeburn 10765: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10766: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10767: if ($context eq 'auto') {
10768: $linefeed = "\n";
10769: } else {
10770: $linefeed = '<br />'."\n";
10771: }
1.443 albertel 10772: if (defined($one) && defined($two)) {
10773: my $cid=$one.'_'.$two;
10774: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10775: my $secchange = 0;
10776: my $expire_role_result;
10777: my $modify_section_result;
1.628 raeburn 10778: if ($oldsec ne '-1') {
10779: if ($oldsec ne $sec) {
1.443 albertel 10780: $secchange = 1;
1.628 raeburn 10781: my $now = time;
1.443 albertel 10782: my $uurl='/'.$cid;
10783: $uurl=~s/\_/\//g;
10784: if ($oldsec) {
10785: $uurl.='/'.$oldsec;
10786: }
1.626 raeburn 10787: $oldsecurl = $uurl;
1.628 raeburn 10788: $expire_role_result =
1.652 raeburn 10789: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10790: if ($env{'request.course.sec'} ne '') {
10791: if ($expire_role_result eq 'refused') {
10792: my @roles = ('st');
10793: my @statuses = ('previous');
10794: my @roledoms = ($one);
10795: my $withsec = 1;
10796: my %roleshash =
10797: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10798: \@statuses,\@roles,\@roledoms,$withsec);
10799: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10800: my ($oldstart,$oldend) =
10801: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10802: if ($oldend > 0 && $oldend <= $now) {
10803: $expire_role_result = 'ok';
10804: }
10805: }
10806: }
10807: }
1.443 albertel 10808: $result = $expire_role_result;
10809: }
10810: }
10811: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10812: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10813: if ($modify_section_result =~ /^ok/) {
10814: if ($secchange == 1) {
1.628 raeburn 10815: if ($sec eq '') {
10816: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10817: } else {
10818: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10819: }
1.443 albertel 10820: } elsif ($oldsec eq '-1') {
1.628 raeburn 10821: if ($sec eq '') {
10822: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10823: } else {
10824: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10825: }
1.443 albertel 10826: } else {
1.628 raeburn 10827: if ($sec eq '') {
10828: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10829: } else {
10830: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10831: }
1.443 albertel 10832: }
10833: } else {
1.628 raeburn 10834: if ($secchange) {
10835: $$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;
10836: } else {
10837: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10838: }
1.443 albertel 10839: }
10840: $result = $modify_section_result;
10841: } elsif ($secchange == 1) {
1.628 raeburn 10842: if ($oldsec eq '') {
10843: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10844: } else {
10845: $$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;
10846: }
1.626 raeburn 10847: if ($expire_role_result eq 'refused') {
10848: my $newsecurl = '/'.$cid;
10849: $newsecurl =~ s/\_/\//g;
10850: if ($sec ne '') {
10851: $newsecurl.='/'.$sec;
10852: }
10853: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10854: if ($sec eq '') {
10855: $$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;
10856: } else {
10857: $$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;
10858: }
10859: }
10860: }
1.443 albertel 10861: }
10862: } else {
1.626 raeburn 10863: $$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 10864: $result = "error: incomplete course id\n";
10865: }
10866: return $result;
10867: }
10868:
10869: ############################################################
10870: ############################################################
10871:
1.566 albertel 10872: sub check_clone {
1.578 raeburn 10873: my ($args,$linefeed) = @_;
1.566 albertel 10874: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10875: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10876: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10877: my $clonemsg;
10878: my $can_clone = 0;
1.944 raeburn 10879: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10880: if ($lctype ne 'community') {
10881: $lctype = 'course';
10882: }
1.566 albertel 10883: if ($clonehome eq 'no_host') {
1.944 raeburn 10884: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10885: $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'});
10886: } else {
10887: $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'});
10888: }
1.566 albertel 10889: } else {
10890: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10891: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10892: if ($clonedesc{'type'} ne 'Community') {
10893: $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'});
10894: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10895: }
10896: }
1.882 raeburn 10897: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10898: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10899: $can_clone = 1;
10900: } else {
10901: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10902: $args->{'clonedomain'},$args->{'clonecourse'});
10903: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10904: if (grep(/^\*$/,@cloners)) {
10905: $can_clone = 1;
10906: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10907: $can_clone = 1;
10908: } else {
1.908 raeburn 10909: my $ccrole = 'cc';
1.944 raeburn 10910: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10911: $ccrole = 'co';
10912: }
1.578 raeburn 10913: my %roleshash =
10914: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10915: $args->{'ccdomain'},
1.908 raeburn 10916: 'userroles',['active'],[$ccrole],
1.578 raeburn 10917: [$args->{'clonedomain'}]);
1.908 raeburn 10918: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10919: $can_clone = 1;
10920: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10921: $can_clone = 1;
10922: } else {
1.944 raeburn 10923: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10924: $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'});
10925: } else {
10926: $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'});
10927: }
1.578 raeburn 10928: }
1.566 albertel 10929: }
1.578 raeburn 10930: }
1.566 albertel 10931: }
10932: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10933: }
10934:
1.444 albertel 10935: sub construct_course {
1.885 raeburn 10936: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10937: my $outcome;
1.541 raeburn 10938: my $linefeed = '<br />'."\n";
10939: if ($context eq 'auto') {
10940: $linefeed = "\n";
10941: }
1.566 albertel 10942:
10943: #
10944: # Are we cloning?
10945: #
10946: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10947: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10948: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10949: if ($context ne 'auto') {
1.578 raeburn 10950: if ($clonemsg ne '') {
10951: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10952: }
1.566 albertel 10953: }
10954: $outcome .= $clonemsg.$linefeed;
10955:
10956: if (!$can_clone) {
10957: return (0,$outcome);
10958: }
10959: }
10960:
1.444 albertel 10961: #
10962: # Open course
10963: #
10964: my $crstype = lc($args->{'crstype'});
10965: my %cenv=();
10966: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10967: $args->{'cdescr'},
10968: $args->{'curl'},
10969: $args->{'course_home'},
10970: $args->{'nonstandard'},
10971: $args->{'crscode'},
10972: $args->{'ccuname'}.':'.
10973: $args->{'ccdomain'},
1.882 raeburn 10974: $args->{'crstype'},
1.885 raeburn 10975: $cnum,$context,$category);
1.444 albertel 10976:
10977: # Note: The testing routines depend on this being output; see
10978: # Utils::Course. This needs to at least be output as a comment
10979: # if anyone ever decides to not show this, and Utils::Course::new
10980: # will need to be suitably modified.
1.541 raeburn 10981: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10982: if ($$courseid =~ /^error:/) {
10983: return (0,$outcome);
10984: }
10985:
1.444 albertel 10986: #
10987: # Check if created correctly
10988: #
1.479 albertel 10989: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10990: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10991: if ($crsuhome eq 'no_host') {
10992: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10993: return (0,$outcome);
10994: }
1.541 raeburn 10995: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10996:
1.444 albertel 10997: #
1.566 albertel 10998: # Do the cloning
10999: #
11000: if ($can_clone && $cloneid) {
11001: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
11002: if ($context ne 'auto') {
11003: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
11004: }
11005: $outcome .= $clonemsg.$linefeed;
11006: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 11007: # Copy all files
1.637 www 11008: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 11009: # Restore URL
1.566 albertel 11010: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 11011: # Restore title
1.566 albertel 11012: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 11013: # Restore creation date, creator and creation context.
11014: $cenv{'internal.created'}=$oldcenv{'internal.created'};
11015: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
11016: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 11017: # Mark as cloned
1.566 albertel 11018: $cenv{'clonedfrom'}=$cloneid;
1.638 www 11019: # Need to clone grading mode
11020: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
11021: $cenv{'grading'}=$newenv{'grading'};
11022: # Do not clone these environment entries
11023: &Apache::lonnet::del('environment',
11024: ['default_enrollment_start_date',
11025: 'default_enrollment_end_date',
11026: 'question.email',
11027: 'policy.email',
11028: 'comment.email',
11029: 'pch.users.denied',
1.725 raeburn 11030: 'plc.users.denied',
11031: 'hidefromcat',
11032: 'categories'],
1.638 www 11033: $$crsudom,$$crsunum);
1.444 albertel 11034: }
1.566 albertel 11035:
1.444 albertel 11036: #
11037: # Set environment (will override cloned, if existing)
11038: #
11039: my @sections = ();
11040: my @xlists = ();
11041: if ($args->{'crstype'}) {
11042: $cenv{'type'}=$args->{'crstype'};
11043: }
11044: if ($args->{'crsid'}) {
11045: $cenv{'courseid'}=$args->{'crsid'};
11046: }
11047: if ($args->{'crscode'}) {
11048: $cenv{'internal.coursecode'}=$args->{'crscode'};
11049: }
11050: if ($args->{'crsquota'} ne '') {
11051: $cenv{'internal.coursequota'}=$args->{'crsquota'};
11052: } else {
11053: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
11054: }
11055: if ($args->{'ccuname'}) {
11056: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
11057: ':'.$args->{'ccdomain'};
11058: } else {
11059: $cenv{'internal.courseowner'} = $args->{'curruser'};
11060: }
11061: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
11062: if ($args->{'crssections'}) {
11063: $cenv{'internal.sectionnums'} = '';
11064: if ($args->{'crssections'} =~ m/,/) {
11065: @sections = split/,/,$args->{'crssections'};
11066: } else {
11067: $sections[0] = $args->{'crssections'};
11068: }
11069: if (@sections > 0) {
11070: foreach my $item (@sections) {
11071: my ($sec,$gp) = split/:/,$item;
11072: my $class = $args->{'crscode'}.$sec;
11073: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
11074: $cenv{'internal.sectionnums'} .= $item.',';
11075: unless ($addcheck eq 'ok') {
11076: push @badclasses, $class;
11077: }
11078: }
11079: $cenv{'internal.sectionnums'} =~ s/,$//;
11080: }
11081: }
11082: # do not hide course coordinator from staff listing,
11083: # even if privileged
11084: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11085: # add crosslistings
11086: if ($args->{'crsxlist'}) {
11087: $cenv{'internal.crosslistings'}='';
11088: if ($args->{'crsxlist'} =~ m/,/) {
11089: @xlists = split/,/,$args->{'crsxlist'};
11090: } else {
11091: $xlists[0] = $args->{'crsxlist'};
11092: }
11093: if (@xlists > 0) {
11094: foreach my $item (@xlists) {
11095: my ($xl,$gp) = split/:/,$item;
11096: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
11097: $cenv{'internal.crosslistings'} .= $item.',';
11098: unless ($addcheck eq 'ok') {
11099: push @badclasses, $xl;
11100: }
11101: }
11102: $cenv{'internal.crosslistings'} =~ s/,$//;
11103: }
11104: }
11105: if ($args->{'autoadds'}) {
11106: $cenv{'internal.autoadds'}=$args->{'autoadds'};
11107: }
11108: if ($args->{'autodrops'}) {
11109: $cenv{'internal.autodrops'}=$args->{'autodrops'};
11110: }
11111: # check for notification of enrollment changes
11112: my @notified = ();
11113: if ($args->{'notify_owner'}) {
11114: if ($args->{'ccuname'} ne '') {
11115: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
11116: }
11117: }
11118: if ($args->{'notify_dc'}) {
11119: if ($uname ne '') {
1.630 raeburn 11120: push(@notified,$uname.':'.$udom);
1.444 albertel 11121: }
11122: }
11123: if (@notified > 0) {
11124: my $notifylist;
11125: if (@notified > 1) {
11126: $notifylist = join(',',@notified);
11127: } else {
11128: $notifylist = $notified[0];
11129: }
11130: $cenv{'internal.notifylist'} = $notifylist;
11131: }
11132: if (@badclasses > 0) {
11133: my %lt=&Apache::lonlocal::texthash(
11134: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
11135: 'dnhr' => 'does not have rights to access enrollment in these classes',
11136: 'adby' => 'as determined by the policies of your institution on access to official classlists'
11137: );
1.541 raeburn 11138: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
11139: ' ('.$lt{'adby'}.')';
11140: if ($context eq 'auto') {
11141: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 11142: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 11143: foreach my $item (@badclasses) {
11144: if ($context eq 'auto') {
11145: $outcome .= " - $item\n";
11146: } else {
11147: $outcome .= "<li>$item</li>\n";
11148: }
11149: }
11150: if ($context eq 'auto') {
11151: $outcome .= $linefeed;
11152: } else {
1.566 albertel 11153: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 11154: }
11155: }
1.444 albertel 11156: }
11157: if ($args->{'no_end_date'}) {
11158: $args->{'endaccess'} = 0;
11159: }
11160: $cenv{'internal.autostart'}=$args->{'enrollstart'};
11161: $cenv{'internal.autoend'}=$args->{'enrollend'};
11162: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
11163: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
11164: if ($args->{'showphotos'}) {
11165: $cenv{'internal.showphotos'}=$args->{'showphotos'};
11166: }
11167: $cenv{'internal.authtype'} = $args->{'authtype'};
11168: $cenv{'internal.autharg'} = $args->{'autharg'};
11169: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
11170: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 11171: 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');
11172: if ($context eq 'auto') {
11173: $outcome .= $krb_msg;
11174: } else {
1.566 albertel 11175: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 11176: }
11177: $outcome .= $linefeed;
1.444 albertel 11178: }
11179: }
11180: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
11181: if ($args->{'setpolicy'}) {
11182: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11183: }
11184: if ($args->{'setcontent'}) {
11185: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11186: }
11187: }
11188: if ($args->{'reshome'}) {
11189: $cenv{'reshome'}=$args->{'reshome'}.'/';
11190: $cenv{'reshome'}=~s/\/+$/\//;
11191: }
11192: #
11193: # course has keyed access
11194: #
11195: if ($args->{'setkeys'}) {
11196: $cenv{'keyaccess'}='yes';
11197: }
11198: # if specified, key authority is not course, but user
11199: # only active if keyaccess is yes
11200: if ($args->{'keyauth'}) {
1.487 albertel 11201: my ($user,$domain) = split(':',$args->{'keyauth'});
11202: $user = &LONCAPA::clean_username($user);
11203: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 11204: if ($user ne '' && $domain ne '') {
1.487 albertel 11205: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 11206: }
11207: }
11208:
11209: if ($args->{'disresdis'}) {
11210: $cenv{'pch.roles.denied'}='st';
11211: }
11212: if ($args->{'disablechat'}) {
11213: $cenv{'plc.roles.denied'}='st';
11214: }
11215:
11216: # Record we've not yet viewed the Course Initialization Helper for this
11217: # course
11218: $cenv{'course.helper.not.run'} = 1;
11219: #
11220: # Use new Randomseed
11221: #
11222: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
11223: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
11224: #
11225: # The encryption code and receipt prefix for this course
11226: #
11227: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
11228: $cenv{'internal.encpref'}=100+int(9*rand(99));
11229: #
11230: # By default, use standard grading
11231: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
11232:
1.541 raeburn 11233: $outcome .= $linefeed.&mt('Setting environment').': '.
11234: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11235: #
11236: # Open all assignments
11237: #
11238: if ($args->{'openall'}) {
11239: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
11240: my %storecontent = ($storeunder => time,
11241: $storeunder.'.type' => 'date_start');
11242:
11243: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 11244: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11245: }
11246: #
11247: # Set first page
11248: #
11249: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
11250: || ($cloneid)) {
1.445 albertel 11251: use LONCAPA::map;
1.444 albertel 11252: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 11253:
11254: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
11255: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
11256:
1.444 albertel 11257: $outcome .= ($fatal?$errtext:'read ok').' - ';
11258: my $title; my $url;
11259: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 11260: $title=&mt('Syllabus');
1.444 albertel 11261: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
11262: } else {
1.963 raeburn 11263: $title=&mt('Table of Contents');
1.444 albertel 11264: $url='/adm/navmaps';
11265: }
1.445 albertel 11266:
11267: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
11268: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
11269:
11270: if ($errtext) { $fatal=2; }
1.541 raeburn 11271: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 11272: }
1.566 albertel 11273:
11274: return (1,$outcome);
1.444 albertel 11275: }
11276:
11277: ############################################################
11278: ############################################################
11279:
1.953 droeschl 11280: #SD
11281: # only Community and Course, or anything else?
1.378 raeburn 11282: sub course_type {
11283: my ($cid) = @_;
11284: if (!defined($cid)) {
11285: $cid = $env{'request.course.id'};
11286: }
1.404 albertel 11287: if (defined($env{'course.'.$cid.'.type'})) {
11288: return $env{'course.'.$cid.'.type'};
1.378 raeburn 11289: } else {
11290: return 'Course';
1.377 raeburn 11291: }
11292: }
1.156 albertel 11293:
1.406 raeburn 11294: sub group_term {
11295: my $crstype = &course_type();
11296: my %names = (
11297: 'Course' => 'group',
1.865 raeburn 11298: 'Community' => 'group',
1.406 raeburn 11299: );
11300: return $names{$crstype};
11301: }
11302:
1.902 raeburn 11303: sub course_types {
11304: my @types = ('official','unofficial','community');
11305: my %typename = (
11306: official => 'Official course',
11307: unofficial => 'Unofficial course',
11308: community => 'Community',
11309: );
11310: return (\@types,\%typename);
11311: }
11312:
1.156 albertel 11313: sub icon {
11314: my ($file)=@_;
1.505 albertel 11315: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 11316: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 11317: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 11318: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
11319: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
11320: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11321: $curfext.".gif") {
11322: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11323: $curfext.".gif";
11324: }
11325: }
1.249 albertel 11326: return &lonhttpdurl($iconname);
1.154 albertel 11327: }
1.84 albertel 11328:
1.575 albertel 11329: sub lonhttpdurl {
1.692 www 11330: #
11331: # Had been used for "small fry" static images on separate port 8080.
11332: # Modify here if lightweight http functionality desired again.
11333: # Currently eliminated due to increasing firewall issues.
11334: #
1.575 albertel 11335: my ($url)=@_;
1.692 www 11336: return $url;
1.215 albertel 11337: }
11338:
1.213 albertel 11339: sub connection_aborted {
11340: my ($r)=@_;
11341: $r->print(" ");$r->rflush();
11342: my $c = $r->connection;
11343: return $c->aborted();
11344: }
11345:
1.221 foxr 11346: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 11347: # strings as 'strings'.
11348: sub escape_single {
1.221 foxr 11349: my ($input) = @_;
1.223 albertel 11350: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 11351: $input =~ s/\'/\\\'/g; # Esacpe the 's....
11352: return $input;
11353: }
1.223 albertel 11354:
1.222 foxr 11355: # Same as escape_single, but escape's "'s This
11356: # can be used for "strings"
11357: sub escape_double {
11358: my ($input) = @_;
11359: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
11360: $input =~ s/\"/\\\"/g; # Esacpe the "s....
11361: return $input;
11362: }
1.223 albertel 11363:
1.222 foxr 11364: # Escapes the last element of a full URL.
11365: sub escape_url {
11366: my ($url) = @_;
1.238 raeburn 11367: my @urlslices = split(/\//, $url,-1);
1.369 www 11368: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 11369: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 11370: }
1.462 albertel 11371:
1.820 raeburn 11372: sub compare_arrays {
11373: my ($arrayref1,$arrayref2) = @_;
11374: my (@difference,%count);
11375: @difference = ();
11376: %count = ();
11377: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
11378: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
11379: foreach my $element (keys(%count)) {
11380: if ($count{$element} == 1) {
11381: push(@difference,$element);
11382: }
11383: }
11384: }
11385: return @difference;
11386: }
11387:
1.817 bisitz 11388: # -------------------------------------------------------- Initialize user login
1.462 albertel 11389: sub init_user_environment {
1.463 albertel 11390: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 11391: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
11392:
11393: my $public=($username eq 'public' && $domain eq 'public');
11394:
11395: # See if old ID present, if so, remove
11396:
11397: my ($filename,$cookie,$userroles);
11398: my $now=time;
11399:
11400: if ($public) {
11401: my $max_public=100;
11402: my $oldest;
11403: my $oldest_time=0;
11404: for(my $next=1;$next<=$max_public;$next++) {
11405: if (-e $lonids."/publicuser_$next.id") {
11406: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
11407: if ($mtime<$oldest_time || !$oldest_time) {
11408: $oldest_time=$mtime;
11409: $oldest=$next;
11410: }
11411: } else {
11412: $cookie="publicuser_$next";
11413: last;
11414: }
11415: }
11416: if (!$cookie) { $cookie="publicuser_$oldest"; }
11417: } else {
1.463 albertel 11418: # if this isn't a robot, kill any existing non-robot sessions
11419: if (!$args->{'robot'}) {
11420: opendir(DIR,$lonids);
11421: while ($filename=readdir(DIR)) {
11422: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
11423: unlink($lonids.'/'.$filename);
11424: }
1.462 albertel 11425: }
1.463 albertel 11426: closedir(DIR);
1.462 albertel 11427: }
11428: # Give them a new cookie
1.463 albertel 11429: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 11430: : $now.$$.int(rand(10000)));
1.463 albertel 11431: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 11432:
11433: # Initialize roles
11434:
11435: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
11436: }
11437: # ------------------------------------ Check browser type and MathML capability
11438:
11439: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
11440: $clientunicode,$clientos) = &decode_user_agent($r);
11441:
11442: # ------------------------------------------------------------- Get environment
11443:
11444: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
11445: my ($tmp) = keys(%userenv);
11446: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11447: } else {
11448: undef(%userenv);
11449: }
11450: if (($userenv{'interface'}) && (!$form->{'interface'})) {
11451: $form->{'interface'}=$userenv{'interface'};
11452: }
11453: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
11454:
11455: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 11456: foreach my $option ('interface','localpath','localres') {
11457: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 11458: }
11459: # --------------------------------------------------------- Write first profile
11460:
11461: {
11462: my %initial_env =
11463: ("user.name" => $username,
11464: "user.domain" => $domain,
11465: "user.home" => $authhost,
11466: "browser.type" => $clientbrowser,
11467: "browser.version" => $clientversion,
11468: "browser.mathml" => $clientmathml,
11469: "browser.unicode" => $clientunicode,
11470: "browser.os" => $clientos,
11471: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
11472: "request.course.fn" => '',
11473: "request.course.uri" => '',
11474: "request.course.sec" => '',
11475: "request.role" => 'cm',
11476: "request.role.adv" => $env{'user.adv'},
11477: "request.host" => $ENV{'REMOTE_ADDR'},);
11478:
11479: if ($form->{'localpath'}) {
11480: $initial_env{"browser.localpath"} = $form->{'localpath'};
11481: $initial_env{"browser.localres"} = $form->{'localres'};
11482: }
11483:
11484: if ($form->{'interface'}) {
11485: $form->{'interface'}=~s/\W//gs;
11486: $initial_env{"browser.interface"} = $form->{'interface'};
11487: $env{'browser.interface'}=$form->{'interface'};
11488: }
11489:
1.981 raeburn 11490: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 11491: my %domdef;
11492: unless ($domain eq 'public') {
11493: %domdef = &Apache::lonnet::get_domain_defaults($domain);
11494: }
1.980 raeburn 11495:
1.724 raeburn 11496: foreach my $tool ('aboutme','blog','portfolio') {
11497: $userenv{'availabletools.'.$tool} =
1.980 raeburn 11498: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
11499: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 11500: }
11501:
1.864 raeburn 11502: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 11503: $userenv{'canrequest.'.$crstype} =
11504: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 11505: 'reload','requestcourses',
11506: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 11507: }
11508:
1.462 albertel 11509: $env{'user.environment'} = "$lonids/$cookie.id";
11510:
11511: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
11512: &GDBM_WRCREAT(),0640)) {
11513: &_add_to_env(\%disk_env,\%initial_env);
11514: &_add_to_env(\%disk_env,\%userenv,'environment.');
11515: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 11516: if (ref($args->{'extra_env'})) {
11517: &_add_to_env(\%disk_env,$args->{'extra_env'});
11518: }
1.462 albertel 11519: untie(%disk_env);
11520: } else {
1.705 tempelho 11521: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
11522: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 11523: return 'error: '.$!;
11524: }
11525: }
11526: $env{'request.role'}='cm';
11527: $env{'request.role.adv'}=$env{'user.adv'};
11528: $env{'browser.type'}=$clientbrowser;
11529:
11530: return $cookie;
11531:
11532: }
11533:
11534: sub _add_to_env {
11535: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 11536: if (ref($env_data) eq 'HASH') {
11537: while (my ($key,$value) = each(%$env_data)) {
11538: $idf->{$prefix.$key} = $value;
11539: $env{$prefix.$key} = $value;
11540: }
1.462 albertel 11541: }
11542: }
11543:
1.685 tempelho 11544: # --- Get the symbolic name of a problem and the url
11545: sub get_symb {
11546: my ($request,$silent) = @_;
1.726 raeburn 11547: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 11548: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
11549: if ($symb eq '') {
11550: if (!$silent) {
11551: $request->print("Unable to handle ambiguous references:$url:.");
11552: return ();
11553: }
11554: }
11555: &Apache::lonenc::check_decrypt(\$symb);
11556: return ($symb);
11557: }
11558:
11559: # --------------------------------------------------------------Get annotation
11560:
11561: sub get_annotation {
11562: my ($symb,$enc) = @_;
11563:
11564: my $key = $symb;
11565: if (!$enc) {
11566: $key =
11567: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
11568: }
11569: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
11570: return $annotation{$key};
11571: }
11572:
11573: sub clean_symb {
1.731 raeburn 11574: my ($symb,$delete_enc) = @_;
1.685 tempelho 11575:
11576: &Apache::lonenc::check_decrypt(\$symb);
11577: my $enc = $env{'request.enc'};
1.731 raeburn 11578: if ($delete_enc) {
1.730 raeburn 11579: delete($env{'request.enc'});
11580: }
1.685 tempelho 11581:
11582: return ($symb,$enc);
11583: }
1.462 albertel 11584:
1.990 raeburn 11585: sub build_release_hashes {
11586: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
11587: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
11588: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
11589: (ref($randomizetry) eq 'HASH'));
11590: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
11591: my ($item,$name,$value) = split(/:/,$key);
11592: if ($item eq 'parameter') {
11593: if (ref($checkparms->{$name}) eq 'ARRAY') {
11594: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
11595: push(@{$checkparms->{$name}},$value);
11596: }
11597: } else {
11598: push(@{$checkparms->{$name}},$value);
11599: }
11600: } elsif ($item eq 'resourcetag') {
11601: if ($name eq 'responsetype') {
11602: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
11603: }
11604: } elsif ($item eq 'course') {
11605: if ($name eq 'crstype') {
11606: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
11607: }
11608: }
11609: }
11610: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
11611: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
11612: return;
11613: }
11614:
1.41 ng 11615: =pod
11616:
11617: =back
11618:
1.112 bowersj2 11619: =cut
1.41 ng 11620:
1.112 bowersj2 11621: 1;
11622: __END__;
1.41 ng 11623:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>