Annotation of loncom/interface/loncommon.pm, revision 1.948.2.33.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.948.2.33.2. (raeburn 4:): # $Id: loncommon.pm,v 1.948.2.33.2.1 2012/02/09 00:45:40 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.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.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.948.2.32 raeburn 412: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
1.948.2.32 raeburn 424: '&udomelement='+udom+
425: '&clicker='+clicker;
1.111 www 426: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 427: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 428: var title = 'Student_Browser';
1.74 www 429: var options = 'scrollbars=1,resizable=1,menubar=0';
430: options += ',width=700,height=600';
431: stdeditbrowser = open(url,title,options,'1');
432: stdeditbrowser.focus();
433: }
1.824 bisitz 434: // ]]>
1.74 www 435: </script>
436: ENDSTDBRW
437: }
1.42 matthew 438:
1.74 www 439: sub selectstudent_link {
1.948.2.32 raeburn 440: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
441: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
442: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
443: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 444: if ($env{'request.course.id'}) {
1.302 albertel 445: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
446: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
447: '/'.$env{'request.course.sec'})) {
1.111 www 448: return '';
449: }
1.948.2.32 raeburn 450: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 451: if ($courseadvonly) {
452: $callargs .= ",'',1,1";
453: }
454: return '<span class="LC_nobreak">'.
455: '<a href="javascript:openstdbrowser('.$callargs.');">'.
456: &mt('Select User').'</a></span>';
1.74 www 457: }
1.258 albertel 458: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.948.2.31 raeburn 459: $callargs .= ",'',1";
1.793 raeburn 460: return '<span class="LC_nobreak">'.
461: '<a href="javascript:openstdbrowser('.$callargs.');">'.
462: &mt('Select User').'</a></span>';
1.111 www 463: }
464: return '';
1.91 www 465: }
466:
1.653 raeburn 467: sub authorbrowser_javascript {
468: return <<"ENDAUTHORBRW";
1.776 bisitz 469: <script type="text/javascript" language="JavaScript">
1.824 bisitz 470: // <![CDATA[
1.653 raeburn 471: var stdeditbrowser;
472:
473: function openauthorbrowser(formname,udom) {
474: var url = '/adm/pickauthor?';
475: url += 'form='+formname+'&roledom='+udom;
476: var title = 'Author_Browser';
477: var options = 'scrollbars=1,resizable=1,menubar=0';
478: options += ',width=700,height=600';
479: stdeditbrowser = open(url,title,options,'1');
480: stdeditbrowser.focus();
481: }
482:
1.824 bisitz 483: // ]]>
1.653 raeburn 484: </script>
485: ENDAUTHORBRW
486: }
487:
1.91 www 488: sub coursebrowser_javascript {
1.909 raeburn 489: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 490: my $wintitle = 'Course_Browser';
1.931 raeburn 491: if ($crstype eq 'Community') {
1.932 raeburn 492: $wintitle = 'Community_Browser';
1.909 raeburn 493: }
1.876 raeburn 494: my $id_functions = &javascript_index_functions();
495: my $output = '
1.776 bisitz 496: <script type="text/javascript" language="JavaScript">
1.824 bisitz 497: // <![CDATA[
1.468 raeburn 498: var stdeditbrowser;'."\n";
1.876 raeburn 499:
500: $output .= <<"ENDSTDBRW";
1.909 raeburn 501: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 502: var url = '/adm/pickcourse?';
1.895 raeburn 503: var formid = getFormIdByName(formname);
1.876 raeburn 504: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 505: if (domainfilter != null) {
506: if (domainfilter != '') {
507: url += 'domainfilter='+domainfilter+'&';
508: }
509: }
1.91 www 510: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 511: '&cdomelement='+udom+
512: '&cnameelement='+desc;
1.468 raeburn 513: if (extra_element !=null && extra_element != '') {
1.594 raeburn 514: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 515: url += '&roleelement='+extra_element;
516: if (domainfilter == null || domainfilter == '') {
517: url += '&domainfilter='+extra_element;
518: }
1.234 raeburn 519: }
1.468 raeburn 520: else {
521: if (formname == 'portform') {
522: url += '&setroles='+extra_element;
1.800 raeburn 523: } else {
524: if (formname == 'rules') {
525: url += '&fixeddom='+extra_element;
526: }
1.468 raeburn 527: }
528: }
1.230 raeburn 529: }
1.909 raeburn 530: if (type != null && type != '') {
531: url += '&type='+type;
532: }
533: if (type_elem != null && type_elem != '') {
534: url += '&typeelement='+type_elem;
535: }
1.872 raeburn 536: if (formname == 'ccrs') {
537: var ownername = document.forms[formid].ccuname.value;
538: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
539: url += '&cloner='+ownername+':'+ownerdom;
540: }
1.293 raeburn 541: if (multflag !=null && multflag != '') {
542: url += '&multiple='+multflag;
543: }
1.909 raeburn 544: var title = '$wintitle';
1.91 www 545: var options = 'scrollbars=1,resizable=1,menubar=0';
546: options += ',width=700,height=600';
547: stdeditbrowser = open(url,title,options,'1');
548: stdeditbrowser.focus();
549: }
1.876 raeburn 550: $id_functions
551: ENDSTDBRW
1.905 raeburn 552: if (($sec_element ne '') || ($role_element ne '')) {
553: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 554: }
555: $output .= '
556: // ]]>
557: </script>';
558: return $output;
559: }
560:
561: sub javascript_index_functions {
562: return <<"ENDJS";
563:
564: function getFormIdByName(formname) {
565: for (var i=0;i<document.forms.length;i++) {
566: if (document.forms[i].name == formname) {
567: return i;
568: }
569: }
570: return -1;
571: }
572:
573: function getIndexByName(formid,item) {
574: for (var i=0;i<document.forms[formid].elements.length;i++) {
575: if (document.forms[formid].elements[i].name == item) {
576: return i;
577: }
578: }
579: return -1;
580: }
1.468 raeburn 581:
1.876 raeburn 582: function getDomainFromSelectbox(formname,udom) {
583: var userdom;
584: var formid = getFormIdByName(formname);
585: if (formid > -1) {
586: var domid = getIndexByName(formid,udom);
587: if (domid > -1) {
588: if (document.forms[formid].elements[domid].type == 'select-one') {
589: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
590: }
591: if (document.forms[formid].elements[domid].type == 'hidden') {
592: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 593: }
594: }
595: }
1.876 raeburn 596: return userdom;
597: }
598:
599: ENDJS
1.468 raeburn 600:
1.876 raeburn 601: }
602:
1.948.2.31 raeburn 603: sub javascript_array_indexof {
604: return <<ENDJS;
605: <script type="text/javascript" language="JavaScript">
606: // <![CDATA[
607:
608: if (!Array.prototype.indexOf) {
609: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
610: "use strict";
611: if (this === void 0 || this === null) {
612: throw new TypeError();
613: }
614: var t = Object(this);
615: var len = t.length >>> 0;
616: if (len === 0) {
617: return -1;
618: }
619: var n = 0;
620: if (arguments.length > 0) {
621: n = Number(arguments[1]);
622: if (n !== n) { // shortcut for verifying if it's NaN
623: n = 0;
624: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
625: n = (n > 0 || -1) * Math.floor(Math.abs(n));
626: }
627: }
628: if (n >= len) {
629: return -1;
630: }
631: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
632: for (; k < len; k++) {
633: if (k in t && t[k] === searchElement) {
634: return k;
635: }
636: }
637: return -1;
638: }
639: }
640:
641: // ]]>
642: </script>
643:
644: ENDJS
645:
646: }
647:
1.876 raeburn 648: sub userbrowser_javascript {
649: my $id_functions = &javascript_index_functions();
650: return <<"ENDUSERBRW";
651:
1.888 raeburn 652: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 653: var url = '/adm/pickuser?';
654: var userdom = getDomainFromSelectbox(formname,udom);
655: if (userdom != null) {
656: if (userdom != '') {
657: url += 'srchdom='+userdom+'&';
658: }
659: }
660: url += 'form=' + formname + '&unameelement='+uname+
661: '&udomelement='+udom+
662: '&ulastelement='+ulast+
663: '&ufirstelement='+ufirst+
664: '&uemailelement='+uemail+
1.881 raeburn 665: '&hideudomelement='+hideudom+
666: '&coursedom='+crsdom;
1.888 raeburn 667: if ((caller != null) && (caller != undefined)) {
668: url += '&caller='+caller;
669: }
1.876 raeburn 670: var title = 'User_Browser';
671: var options = 'scrollbars=1,resizable=1,menubar=0';
672: options += ',width=700,height=600';
673: var stdeditbrowser = open(url,title,options,'1');
674: stdeditbrowser.focus();
675: }
676:
1.888 raeburn 677: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 678: var formid = getFormIdByName(formname);
679: if (formid > -1) {
1.888 raeburn 680: var unameid = getIndexByName(formid,uname);
1.876 raeburn 681: var domid = getIndexByName(formid,udom);
682: var hidedomid = getIndexByName(formid,origdom);
683: if (hidedomid > -1) {
684: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 685: var unameval = document.forms[formid].elements[unameid].value;
686: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
687: if (domid > -1) {
688: var slct = document.forms[formid].elements[domid];
689: if (slct.type == 'select-one') {
690: var i;
691: for (i=0;i<slct.length;i++) {
692: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
693: }
694: }
695: if (slct.type == 'hidden') {
696: slct.value = fixeddom;
1.876 raeburn 697: }
698: }
1.468 raeburn 699: }
700: }
701: }
1.876 raeburn 702: return;
703: }
704:
705: $id_functions
706: ENDUSERBRW
1.468 raeburn 707: }
708:
709: sub setsec_javascript {
1.905 raeburn 710: my ($sec_element,$formname,$role_element) = @_;
711: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
712: $communityrolestr);
713: if ($role_element ne '') {
714: my @allroles = ('st','ta','ep','in','ad');
715: foreach my $crstype ('Course','Community') {
716: if ($crstype eq 'Community') {
717: foreach my $role (@allroles) {
718: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
719: }
720: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
721: } else {
722: foreach my $role (@allroles) {
723: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
724: }
725: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
726: }
727: }
728: $rolestr = '"'.join('","',@allroles).'"';
729: $courserolestr = '"'.join('","',@courserolenames).'"';
730: $communityrolestr = '"'.join('","',@communityrolenames).'"';
731: }
1.468 raeburn 732: my $setsections = qq|
733: function setSect(sectionlist) {
1.629 raeburn 734: var sectionsArray = new Array();
735: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
736: sectionsArray = sectionlist.split(",");
737: }
1.468 raeburn 738: var numSections = sectionsArray.length;
739: document.$formname.$sec_element.length = 0;
740: if (numSections == 0) {
741: document.$formname.$sec_element.multiple=false;
742: document.$formname.$sec_element.size=1;
743: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
744: } else {
745: if (numSections == 1) {
746: document.$formname.$sec_element.multiple=false;
747: document.$formname.$sec_element.size=1;
748: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
749: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
750: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
751: } else {
752: for (var i=0; i<numSections; i++) {
753: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
754: }
755: document.$formname.$sec_element.multiple=true
756: if (numSections < 3) {
757: document.$formname.$sec_element.size=numSections;
758: } else {
759: document.$formname.$sec_element.size=3;
760: }
761: document.$formname.$sec_element.options[0].selected = false
762: }
763: }
1.91 www 764: }
1.905 raeburn 765:
766: function setRole(crstype) {
1.468 raeburn 767: |;
1.905 raeburn 768: if ($role_element eq '') {
769: $setsections .= ' return;
770: }
771: ';
772: } else {
773: $setsections .= qq|
774: var elementLength = document.$formname.$role_element.length;
775: var allroles = Array($rolestr);
776: var courserolenames = Array($courserolestr);
777: var communityrolenames = Array($communityrolestr);
778: if (elementLength != undefined) {
779: if (document.$formname.$role_element.options[5].value == 'cc') {
780: if (crstype == 'Course') {
781: return;
782: } else {
783: allroles[5] = 'co';
784: for (var i=0; i<6; i++) {
785: document.$formname.$role_element.options[i].value = allroles[i];
786: document.$formname.$role_element.options[i].text = communityrolenames[i];
787: }
788: }
789: } else {
790: if (crstype == 'Community') {
791: return;
792: } else {
793: allroles[5] = 'cc';
794: for (var i=0; i<6; i++) {
795: document.$formname.$role_element.options[i].value = allroles[i];
796: document.$formname.$role_element.options[i].text = courserolenames[i];
797: }
798: }
799: }
800: }
801: return;
802: }
803: |;
804: }
1.468 raeburn 805: return $setsections;
806: }
807:
1.91 www 808: sub selectcourse_link {
1.909 raeburn 809: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
810: $typeelement) = @_;
811: my $type = $selecttype;
1.871 raeburn 812: my $linktext = &mt('Select Course');
813: if ($selecttype eq 'Community') {
1.909 raeburn 814: $linktext = &mt('Select Community');
1.906 raeburn 815: } elsif ($selecttype eq 'Course/Community') {
816: $linktext = &mt('Select Course/Community');
1.909 raeburn 817: $type = '';
1.948.2.31 raeburn 818: } elsif ($selecttype eq 'Select') {
819: $linktext = &mt('Select');
820: $type = '';
1.871 raeburn 821: }
1.787 bisitz 822: return '<span class="LC_nobreak">'
823: ."<a href='"
824: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
825: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 826: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 827: ."'>".$linktext.'</a>'
1.787 bisitz 828: .'</span>';
1.74 www 829: }
1.42 matthew 830:
1.653 raeburn 831: sub selectauthor_link {
832: my ($form,$udom)=@_;
833: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
834: &mt('Select Author').'</a>';
835: }
836:
1.876 raeburn 837: sub selectuser_link {
1.881 raeburn 838: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 839: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 840: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 841: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 842: ');">'.$linktext.'</a>';
1.876 raeburn 843: }
844:
1.273 raeburn 845: sub check_uncheck_jscript {
846: my $jscript = <<"ENDSCRT";
847: function checkAll(field) {
848: if (field.length > 0) {
849: for (i = 0; i < field.length; i++) {
850: field[i].checked = true ;
851: }
852: } else {
853: field.checked = true
854: }
855: }
856:
857: function uncheckAll(field) {
858: if (field.length > 0) {
859: for (i = 0; i < field.length; i++) {
860: field[i].checked = false ;
1.543 albertel 861: }
862: } else {
1.273 raeburn 863: field.checked = false ;
864: }
865: }
866: ENDSCRT
867: return $jscript;
868: }
869:
1.656 www 870: sub select_timezone {
1.659 raeburn 871: my ($name,$selected,$onchange,$includeempty)=@_;
872: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
873: if ($includeempty) {
874: $output .= '<option value=""';
875: if (($selected eq '') || ($selected eq 'local')) {
876: $output .= ' selected="selected" ';
877: }
878: $output .= '> </option>';
879: }
1.657 raeburn 880: my @timezones = DateTime::TimeZone->all_names;
881: foreach my $tzone (@timezones) {
882: $output.= '<option value="'.$tzone.'"';
883: if ($tzone eq $selected) {
884: $output.=' selected="selected"';
885: }
886: $output.=">$tzone</option>\n";
1.656 www 887: }
888: $output.="</select>";
889: return $output;
890: }
1.273 raeburn 891:
1.687 raeburn 892: sub select_datelocale {
893: my ($name,$selected,$onchange,$includeempty)=@_;
894: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
895: if ($includeempty) {
896: $output .= '<option value=""';
897: if ($selected eq '') {
898: $output .= ' selected="selected" ';
899: }
900: $output .= '> </option>';
901: }
902: my (@possibles,%locale_names);
903: my @locales = DateTime::Locale::Catalog::Locales;
904: foreach my $locale (@locales) {
905: if (ref($locale) eq 'HASH') {
906: my $id = $locale->{'id'};
907: if ($id ne '') {
908: my $en_terr = $locale->{'en_territory'};
909: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 910: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 911: if (grep(/^en$/,@languages) || !@languages) {
912: if ($en_terr ne '') {
913: $locale_names{$id} = '('.$en_terr.')';
914: } elsif ($native_terr ne '') {
915: $locale_names{$id} = $native_terr;
916: }
917: } else {
918: if ($native_terr ne '') {
919: $locale_names{$id} = $native_terr.' ';
920: } elsif ($en_terr ne '') {
921: $locale_names{$id} = '('.$en_terr.')';
922: }
923: }
924: push (@possibles,$id);
925: }
926: }
927: }
928: foreach my $item (sort(@possibles)) {
929: $output.= '<option value="'.$item.'"';
930: if ($item eq $selected) {
931: $output.=' selected="selected"';
932: }
933: $output.=">$item";
934: if ($locale_names{$item} ne '') {
935: $output.=" $locale_names{$item}</option>\n";
936: }
937: $output.="</option>\n";
938: }
939: $output.="</select>";
940: return $output;
941: }
942:
1.792 raeburn 943: sub select_language {
944: my ($name,$selected,$includeempty) = @_;
945: my %langchoices;
946: if ($includeempty) {
947: %langchoices = ('' => 'No language preference');
948: }
949: foreach my $id (&languageids()) {
950: my $code = &supportedlanguagecode($id);
951: if ($code) {
952: $langchoices{$code} = &plainlanguagedescription($id);
953: }
954: }
1.948.2.7 raeburn 955: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 956: }
957:
1.42 matthew 958: =pod
1.36 matthew 959:
1.648 raeburn 960: =item * &linked_select_forms(...)
1.36 matthew 961:
962: linked_select_forms returns a string containing a <script></script> block
963: and html for two <select> menus. The select menus will be linked in that
964: changing the value of the first menu will result in new values being placed
965: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 966: order unless a defined order is provided.
1.36 matthew 967:
968: linked_select_forms takes the following ordered inputs:
969:
970: =over 4
971:
1.112 bowersj2 972: =item * $formname, the name of the <form> tag
1.36 matthew 973:
1.112 bowersj2 974: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 975:
1.112 bowersj2 976: =item * $firstdefault, the default value for the first menu
1.36 matthew 977:
1.112 bowersj2 978: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 979:
1.112 bowersj2 980: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 981:
1.112 bowersj2 982: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 983:
1.609 raeburn 984: =item * $menuorder, the order of values in the first menu
985:
1.41 ng 986: =back
987:
1.36 matthew 988: Below is an example of such a hash. Only the 'text', 'default', and
989: 'select2' keys must appear as stated. keys(%menu) are the possible
990: values for the first select menu. The text that coincides with the
1.41 ng 991: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 992: and text for the second menu are given in the hash pointed to by
993: $menu{$choice1}->{'select2'}.
994:
1.112 bowersj2 995: my %menu = ( A1 => { text =>"Choice A1" ,
996: default => "B3",
997: select2 => {
998: B1 => "Choice B1",
999: B2 => "Choice B2",
1000: B3 => "Choice B3",
1001: B4 => "Choice B4"
1.609 raeburn 1002: },
1003: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1004: },
1005: A2 => { text =>"Choice A2" ,
1006: default => "C2",
1007: select2 => {
1008: C1 => "Choice C1",
1009: C2 => "Choice C2",
1010: C3 => "Choice C3"
1.609 raeburn 1011: },
1012: order => ['C2','C1','C3'],
1.112 bowersj2 1013: },
1014: A3 => { text =>"Choice A3" ,
1015: default => "D6",
1016: select2 => {
1017: D1 => "Choice D1",
1018: D2 => "Choice D2",
1019: D3 => "Choice D3",
1020: D4 => "Choice D4",
1021: D5 => "Choice D5",
1022: D6 => "Choice D6",
1023: D7 => "Choice D7"
1.609 raeburn 1024: },
1025: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1026: }
1027: );
1.36 matthew 1028:
1029: =cut
1030:
1031: sub linked_select_forms {
1032: my ($formname,
1033: $middletext,
1034: $firstdefault,
1035: $firstselectname,
1036: $secondselectname,
1.609 raeburn 1037: $hashref,
1038: $menuorder,
1.36 matthew 1039: ) = @_;
1040: my $second = "document.$formname.$secondselectname";
1041: my $first = "document.$formname.$firstselectname";
1042: # output the javascript to do the changing
1043: my $result = '';
1.776 bisitz 1044: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1045: $result.="// <![CDATA[\n";
1.36 matthew 1046: $result.="var select2data = new Object();\n";
1047: $" = '","';
1048: my $debug = '';
1049: foreach my $s1 (sort(keys(%$hashref))) {
1050: $result.="select2data.d_$s1 = new Object();\n";
1051: $result.="select2data.d_$s1.def = new String('".
1052: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1053: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1054: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1055: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1056: @s2values = @{$hashref->{$s1}->{'order'}};
1057: }
1.36 matthew 1058: $result.="\"@s2values\");\n";
1059: $result.="select2data.d_$s1.texts = new Array(";
1060: my @s2texts;
1061: foreach my $value (@s2values) {
1062: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1063: }
1064: $result.="\"@s2texts\");\n";
1065: }
1066: $"=' ';
1067: $result.= <<"END";
1068:
1069: function select1_changed() {
1070: // Determine new choice
1071: var newvalue = "d_" + $first.value;
1072: // update select2
1073: var values = select2data[newvalue].values;
1074: var texts = select2data[newvalue].texts;
1075: var select2def = select2data[newvalue].def;
1076: var i;
1077: // out with the old
1078: for (i = 0; i < $second.options.length; i++) {
1079: $second.options[i] = null;
1080: }
1081: // in with the nuclear
1082: for (i=0;i<values.length; i++) {
1083: $second.options[i] = new Option(values[i]);
1.143 matthew 1084: $second.options[i].value = values[i];
1.36 matthew 1085: $second.options[i].text = texts[i];
1086: if (values[i] == select2def) {
1087: $second.options[i].selected = true;
1088: }
1089: }
1090: }
1.824 bisitz 1091: // ]]>
1.36 matthew 1092: </script>
1093: END
1094: # output the initial values for the selection lists
1095: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1096: my @order = sort(keys(%{$hashref}));
1097: if (ref($menuorder) eq 'ARRAY') {
1098: @order = @{$menuorder};
1099: }
1100: foreach my $value (@order) {
1.36 matthew 1101: $result.=" <option value=\"$value\" ";
1.253 albertel 1102: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1103: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1104: }
1105: $result .= "</select>\n";
1106: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1107: $result .= $middletext;
1108: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1109: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1110:
1111: my @secondorder = sort(keys(%select2));
1112: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1113: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1114: }
1115: foreach my $value (@secondorder) {
1.36 matthew 1116: $result.=" <option value=\"$value\" ";
1.253 albertel 1117: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1118: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1119: }
1120: $result .= "</select>\n";
1121: # return $debug;
1122: return $result;
1123: } # end of sub linked_select_forms {
1124:
1.45 matthew 1125: =pod
1.44 bowersj2 1126:
1.948.2.7 raeburn 1127: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1128:
1.112 bowersj2 1129: Returns a string corresponding to an HTML link to the given help
1130: $topic, where $topic corresponds to the name of a .tex file in
1131: /home/httpd/html/adm/help/tex, with underscores replaced by
1132: spaces.
1133:
1134: $text will optionally be linked to the same topic, allowing you to
1135: link text in addition to the graphic. If you do not want to link
1136: text, but wish to specify one of the later parameters, pass an
1137: empty string.
1138:
1139: $stayOnPage is a value that will be interpreted as a boolean. If true,
1140: the link will not open a new window. If false, the link will open
1141: a new window using Javascript. (Default is false.)
1142:
1143: $width and $height are optional numerical parameters that will
1144: override the width and height of the popped up window, which may
1145: be useful for certain help topics with big pictures included.
1.44 bowersj2 1146:
1147: =cut
1148:
1149: sub help_open_topic {
1.948.2.7 raeburn 1150: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1151: $text = "" if (not defined $text);
1.44 bowersj2 1152: $stayOnPage = 0 if (not defined $stayOnPage);
1153: $width = 350 if (not defined $width);
1154: $height = 400 if (not defined $height);
1155: my $filename = $topic;
1156: $filename =~ s/ /_/g;
1157:
1.48 bowersj2 1158: my $template = "";
1159: my $link;
1.572 banghart 1160:
1.159 www 1161: $topic=~s/\W/\_/g;
1.44 bowersj2 1162:
1.572 banghart 1163: if (!$stayOnPage) {
1.72 bowersj2 1164: $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 1165: } else {
1.48 bowersj2 1166: $link = "/adm/help/${filename}.hlp";
1167: }
1168:
1169: # Add the text
1.755 neumanie 1170: if ($text ne "") {
1.763 bisitz 1171: $template.='<span class="LC_help_open_topic">'
1172: .'<a target="_top" href="'.$link.'">'
1173: .$text.'</a>';
1.48 bowersj2 1174: }
1175:
1.763 bisitz 1176: # (Always) Add the graphic
1.179 matthew 1177: my $title = &mt('Online Help');
1.667 raeburn 1178: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.948.2.7 raeburn 1179: if ($imgid ne '') {
1180: $imgid = ' id="'.$imgid.'"';
1181: }
1.763 bisitz 1182: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1183: .'<img src="'.$helpicon.'" border="0"'
1184: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.948.2.7 raeburn 1185: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1186: .' /></a>';
1.948.2.7 raeburn 1187: if ($text ne "") {
1.763 bisitz 1188: $template.='</span>';
1189: }
1.44 bowersj2 1190: return $template;
1191:
1.106 bowersj2 1192: }
1193:
1194: # This is a quicky function for Latex cheatsheet editing, since it
1195: # appears in at least four places
1196: sub helpLatexCheatsheet {
1.732 raeburn 1197: my ($topic,$text,$not_author) = @_;
1198: my $out;
1.106 bowersj2 1199: my $addOther = '';
1.732 raeburn 1200: if ($topic) {
1.763 bisitz 1201: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1202: undef, undef, 600).
1203: '</span> ';
1204: }
1205: $out = '<span>' # Start cheatsheet
1206: .$addOther
1207: .'<span>'
1208: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1209: undef,undef,600)
1210: .'</span> <span>'
1211: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1212: undef,undef,600)
1213: .'</span>';
1.732 raeburn 1214: unless ($not_author) {
1.763 bisitz 1215: $out .= ' <span>'
1216: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1217: undef,undef,600)
1218: .'</span>';
1.732 raeburn 1219: }
1.763 bisitz 1220: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1221: return $out;
1.172 www 1222: }
1223:
1.430 albertel 1224: sub general_help {
1225: my $helptopic='Student_Intro';
1226: if ($env{'request.role'}=~/^(ca|au)/) {
1227: $helptopic='Authoring_Intro';
1.907 raeburn 1228: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1229: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1230: } elsif ($env{'request.role'}=~/^dc/) {
1231: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1232: }
1233: return $helptopic;
1234: }
1235:
1236: sub update_help_link {
1237: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1238: my $origurl = $ENV{'REQUEST_URI'};
1239: $origurl=~s|^/~|/priv/|;
1240: my $timestamp = time;
1241: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1242: $$datum = &escape($$datum);
1243: }
1244:
1245: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1246: my $output .= <<"ENDOUTPUT";
1247: <script type="text/javascript">
1.824 bisitz 1248: // <![CDATA[
1.430 albertel 1249: banner_link = '$banner_link';
1.824 bisitz 1250: // ]]>
1.430 albertel 1251: </script>
1252: ENDOUTPUT
1253: return $output;
1254: }
1255:
1256: # now just updates the help link and generates a blue icon
1.193 raeburn 1257: sub help_open_menu {
1.430 albertel 1258: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1259: = @_;
1.430 albertel 1260: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1261: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1262: # if environment.remote is on (using remote control UI)
1.798 tempelho 1263: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1264: $stayOnPage=1;
1.430 albertel 1265: }
1266: my $output;
1267: if ($component_help) {
1268: if (!$text) {
1269: $output=&help_open_topic($component_help,undef,$stayOnPage,
1270: $width,$height);
1271: } else {
1272: my $help_text;
1273: $help_text=&unescape($topic);
1274: $output='<table><tr><td>'.
1275: &help_open_topic($component_help,$help_text,$stayOnPage,
1276: $width,$height).'</td></tr></table>';
1277: }
1278: }
1279: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1280: return $output.$banner_link;
1281: }
1282:
1283: sub top_nav_help {
1284: my ($text) = @_;
1.436 albertel 1285: $text = &mt($text);
1.572 banghart 1286: my $stay_on_page =
1.798 tempelho 1287: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1288: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1289: : "javascript:helpMenu('open')";
1.572 banghart 1290: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1291:
1.201 raeburn 1292: my $title = &mt('Get help');
1.436 albertel 1293:
1294: return <<"END";
1295: $banner_link
1296: <a href="$link" title="$title">$text</a>
1297: END
1298: }
1299:
1300: sub help_menu_js {
1301: my ($text) = @_;
1302:
1303: my $stayOnPage =
1.798 tempelho 1304: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1305:
1306: my $width = 620;
1307: my $height = 600;
1.430 albertel 1308: my $helptopic=&general_help();
1309: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1310: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1311: my $start_page =
1312: &Apache::loncommon::start_page('Help Menu', undef,
1313: {'frameset' => 1,
1314: 'js_ready' => 1,
1315: 'add_entries' => {
1316: 'border' => '0',
1.579 raeburn 1317: 'rows' => "110,*",},});
1.331 albertel 1318: my $end_page =
1319: &Apache::loncommon::end_page({'frameset' => 1,
1320: 'js_ready' => 1,});
1321:
1.436 albertel 1322: my $template .= <<"ENDTEMPLATE";
1323: <script type="text/javascript">
1.877 bisitz 1324: // <![CDATA[
1.253 albertel 1325: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1326: var banner_link = '';
1.243 raeburn 1327: function helpMenu(target) {
1328: var caller = this;
1329: if (target == 'open') {
1330: var newWindow = null;
1331: try {
1.262 albertel 1332: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1333: }
1334: catch(error) {
1335: writeHelp(caller);
1336: return;
1337: }
1338: if (newWindow) {
1339: caller = newWindow;
1340: }
1.193 raeburn 1341: }
1.243 raeburn 1342: writeHelp(caller);
1343: return;
1344: }
1345: function writeHelp(caller) {
1.430 albertel 1346: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1347: caller.document.close()
1348: caller.focus()
1.193 raeburn 1349: }
1.877 bisitz 1350: // END LON-CAPA Internal -->
1.253 albertel 1351: // ]]>
1.436 albertel 1352: </script>
1.193 raeburn 1353: ENDTEMPLATE
1354: return $template;
1355: }
1356:
1.172 www 1357: sub help_open_bug {
1358: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1359: unless ($env{'user.adv'}) { return ''; }
1.172 www 1360: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1361: $text = "" if (not defined $text);
1362: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1363: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1364: $stayOnPage=1;
1365: }
1.184 albertel 1366: $width = 600 if (not defined $width);
1367: $height = 600 if (not defined $height);
1.172 www 1368:
1369: $topic=~s/\W+/\+/g;
1370: my $link='';
1371: my $template='';
1.379 albertel 1372: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1373: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1374: if (!$stayOnPage)
1375: {
1376: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1377: }
1378: else
1379: {
1380: $link = $url;
1381: }
1382: # Add the text
1383: if ($text ne "")
1384: {
1385: $template .=
1386: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1387: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1388: }
1389:
1390: # Add the graphic
1.179 matthew 1391: my $title = &mt('Report a Bug');
1.215 albertel 1392: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1393: $template .= <<"ENDTEMPLATE";
1.436 albertel 1394: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1395: ENDTEMPLATE
1396: if ($text ne '') { $template.='</td></tr></table>' };
1397: return $template;
1398:
1399: }
1400:
1401: sub help_open_faq {
1402: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1403: unless ($env{'user.adv'}) { return ''; }
1.172 www 1404: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1405: $text = "" if (not defined $text);
1406: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1407: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1408: $stayOnPage=1;
1409: }
1410: $width = 350 if (not defined $width);
1411: $height = 400 if (not defined $height);
1412:
1413: $topic=~s/\W+/\+/g;
1414: my $link='';
1415: my $template='';
1416: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1417: if (!$stayOnPage)
1418: {
1419: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1420: }
1421: else
1422: {
1423: $link = $url;
1424: }
1425:
1426: # Add the text
1427: if ($text ne "")
1428: {
1429: $template .=
1.173 www 1430: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1431: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1432: }
1433:
1434: # Add the graphic
1.179 matthew 1435: my $title = &mt('View the FAQ');
1.215 albertel 1436: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1437: $template .= <<"ENDTEMPLATE";
1.436 albertel 1438: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1439: ENDTEMPLATE
1440: if ($text ne '') { $template.='</td></tr></table>' };
1441: return $template;
1442:
1.44 bowersj2 1443: }
1.37 matthew 1444:
1.180 matthew 1445: ###############################################################
1446: ###############################################################
1447:
1.45 matthew 1448: =pod
1449:
1.648 raeburn 1450: =item * &change_content_javascript():
1.256 matthew 1451:
1452: This and the next function allow you to create small sections of an
1453: otherwise static HTML page that you can update on the fly with
1454: Javascript, even in Netscape 4.
1455:
1456: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1457: must be written to the HTML page once. It will prove the Javascript
1458: function "change(name, content)". Calling the change function with the
1459: name of the section
1460: you want to update, matching the name passed to C<changable_area>, and
1461: the new content you want to put in there, will put the content into
1462: that area.
1463:
1464: B<Note>: Netscape 4 only reserves enough space for the changable area
1465: to contain room for the original contents. You need to "make space"
1466: for whatever changes you wish to make, and be B<sure> to check your
1467: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1468: it's adequate for updating a one-line status display, but little more.
1469: This script will set the space to 100% width, so you only need to
1470: worry about height in Netscape 4.
1471:
1472: Modern browsers are much less limiting, and if you can commit to the
1473: user not using Netscape 4, this feature may be used freely with
1474: pretty much any HTML.
1475:
1476: =cut
1477:
1478: sub change_content_javascript {
1479: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1480: if ($env{'browser.type'} eq 'netscape' &&
1481: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1482: return (<<NETSCAPE4);
1483: function change(name, content) {
1484: doc = document.layers[name+"___escape"].layers[0].document;
1485: doc.open();
1486: doc.write(content);
1487: doc.close();
1488: }
1489: NETSCAPE4
1490: } else {
1491: # Otherwise, we need to use semi-standards-compliant code
1492: # (technically, "innerHTML" isn't standard but the equivalent
1493: # is really scary, and every useful browser supports it
1494: return (<<DOMBASED);
1495: function change(name, content) {
1496: element = document.getElementById(name);
1497: element.innerHTML = content;
1498: }
1499: DOMBASED
1500: }
1501: }
1502:
1503: =pod
1504:
1.648 raeburn 1505: =item * &changable_area($name,$origContent):
1.256 matthew 1506:
1507: This provides a "changable area" that can be modified on the fly via
1508: the Javascript code provided in C<change_content_javascript>. $name is
1509: the name you will use to reference the area later; do not repeat the
1510: same name on a given HTML page more then once. $origContent is what
1511: the area will originally contain, which can be left blank.
1512:
1513: =cut
1514:
1515: sub changable_area {
1516: my ($name, $origContent) = @_;
1517:
1.258 albertel 1518: if ($env{'browser.type'} eq 'netscape' &&
1519: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1520: # If this is netscape 4, we need to use the Layer tag
1521: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1522: } else {
1523: return "<span id='$name'>$origContent</span>";
1524: }
1525: }
1526:
1527: =pod
1528:
1.648 raeburn 1529: =item * &viewport_geometry_js
1.590 raeburn 1530:
1531: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1532:
1533: =cut
1534:
1535:
1536: sub viewport_geometry_js {
1537: return <<"GEOMETRY";
1538: var Geometry = {};
1539: function init_geometry() {
1540: if (Geometry.init) { return };
1541: Geometry.init=1;
1542: if (window.innerHeight) {
1543: Geometry.getViewportHeight = function() { return window.innerHeight; };
1544: Geometry.getViewportWidth = function() { return window.innerWidth; };
1545: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1546: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1547: }
1548: else if (document.documentElement && document.documentElement.clientHeight) {
1549: Geometry.getViewportHeight =
1550: function() { return document.documentElement.clientHeight; };
1551: Geometry.getViewportWidth =
1552: function() { return document.documentElement.clientWidth; };
1553:
1554: Geometry.getHorizontalScroll =
1555: function() { return document.documentElement.scrollLeft; };
1556: Geometry.getVerticalScroll =
1557: function() { return document.documentElement.scrollTop; };
1558: }
1559: else if (document.body.clientHeight) {
1560: Geometry.getViewportHeight =
1561: function() { return document.body.clientHeight; };
1562: Geometry.getViewportWidth =
1563: function() { return document.body.clientWidth; };
1564: Geometry.getHorizontalScroll =
1565: function() { return document.body.scrollLeft; };
1566: Geometry.getVerticalScroll =
1567: function() { return document.body.scrollTop; };
1568: }
1569: }
1570:
1571: GEOMETRY
1572: }
1573:
1574: =pod
1575:
1.648 raeburn 1576: =item * &viewport_size_js()
1.590 raeburn 1577:
1578: 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.
1579:
1580: =cut
1581:
1582: sub viewport_size_js {
1583: my $geometry = &viewport_geometry_js();
1584: return <<"DIMS";
1585:
1586: $geometry
1587:
1588: function getViewportDims(width,height) {
1589: init_geometry();
1590: width.value = Geometry.getViewportWidth();
1591: height.value = Geometry.getViewportHeight();
1592: return;
1593: }
1594:
1595: DIMS
1596: }
1597:
1598: =pod
1599:
1.648 raeburn 1600: =item * &resize_textarea_js()
1.565 albertel 1601:
1602: emits the needed javascript to resize a textarea to be as big as possible
1603:
1604: creates a function resize_textrea that takes two IDs first should be
1605: the id of the element to resize, second should be the id of a div that
1606: surrounds everything that comes after the textarea, this routine needs
1607: to be attached to the <body> for the onload and onresize events.
1608:
1.648 raeburn 1609: =back
1.565 albertel 1610:
1611: =cut
1612:
1613: sub resize_textarea_js {
1.590 raeburn 1614: my $geometry = &viewport_geometry_js();
1.565 albertel 1615: return <<"RESIZE";
1616: <script type="text/javascript">
1.824 bisitz 1617: // <![CDATA[
1.590 raeburn 1618: $geometry
1.565 albertel 1619:
1.588 albertel 1620: function getX(element) {
1621: var x = 0;
1622: while (element) {
1623: x += element.offsetLeft;
1624: element = element.offsetParent;
1625: }
1626: return x;
1627: }
1628: function getY(element) {
1629: var y = 0;
1630: while (element) {
1631: y += element.offsetTop;
1632: element = element.offsetParent;
1633: }
1634: return y;
1635: }
1636:
1637:
1.565 albertel 1638: function resize_textarea(textarea_id,bottom_id) {
1639: init_geometry();
1640: var textarea = document.getElementById(textarea_id);
1641: //alert(textarea);
1642:
1.588 albertel 1643: var textarea_top = getY(textarea);
1.565 albertel 1644: var textarea_height = textarea.offsetHeight;
1645: var bottom = document.getElementById(bottom_id);
1.588 albertel 1646: var bottom_top = getY(bottom);
1.565 albertel 1647: var bottom_height = bottom.offsetHeight;
1648: var window_height = Geometry.getViewportHeight();
1.588 albertel 1649: var fudge = 23;
1.565 albertel 1650: var new_height = window_height-fudge-textarea_top-bottom_height;
1651: if (new_height < 300) {
1652: new_height = 300;
1653: }
1654: textarea.style.height=new_height+'px';
1655: }
1.824 bisitz 1656: // ]]>
1.565 albertel 1657: </script>
1658: RESIZE
1659:
1660: }
1661:
1662: =pod
1663:
1.256 matthew 1664: =head1 Excel and CSV file utility routines
1665:
1666: =over 4
1667:
1668: =cut
1669:
1670: ###############################################################
1671: ###############################################################
1672:
1673: =pod
1674:
1.648 raeburn 1675: =item * &csv_translate($text)
1.37 matthew 1676:
1.185 www 1677: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1678: format.
1679:
1680: =cut
1681:
1.180 matthew 1682: ###############################################################
1683: ###############################################################
1.37 matthew 1684: sub csv_translate {
1685: my $text = shift;
1686: $text =~ s/\"/\"\"/g;
1.209 albertel 1687: $text =~ s/\n/ /g;
1.37 matthew 1688: return $text;
1689: }
1.180 matthew 1690:
1691: ###############################################################
1692: ###############################################################
1693:
1694: =pod
1695:
1.648 raeburn 1696: =item * &define_excel_formats()
1.180 matthew 1697:
1698: Define some commonly used Excel cell formats.
1699:
1700: Currently supported formats:
1701:
1702: =over 4
1703:
1704: =item header
1705:
1706: =item bold
1707:
1708: =item h1
1709:
1710: =item h2
1711:
1712: =item h3
1713:
1.256 matthew 1714: =item h4
1715:
1716: =item i
1717:
1.180 matthew 1718: =item date
1719:
1720: =back
1721:
1722: Inputs: $workbook
1723:
1724: Returns: $format, a hash reference.
1725:
1726: =cut
1727:
1728: ###############################################################
1729: ###############################################################
1730: sub define_excel_formats {
1731: my ($workbook) = @_;
1732: my $format;
1733: $format->{'header'} = $workbook->add_format(bold => 1,
1734: bottom => 1,
1735: align => 'center');
1736: $format->{'bold'} = $workbook->add_format(bold=>1);
1737: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1738: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1739: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1740: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1741: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1742: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1743: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1744: return $format;
1745: }
1746:
1747: ###############################################################
1748: ###############################################################
1.113 bowersj2 1749:
1750: =pod
1751:
1.648 raeburn 1752: =item * &create_workbook()
1.255 matthew 1753:
1754: Create an Excel worksheet. If it fails, output message on the
1755: request object and return undefs.
1756:
1757: Inputs: Apache request object
1758:
1759: Returns (undef) on failure,
1760: Excel worksheet object, scalar with filename, and formats
1761: from &Apache::loncommon::define_excel_formats on success
1762:
1763: =cut
1764:
1765: ###############################################################
1766: ###############################################################
1767: sub create_workbook {
1768: my ($r) = @_;
1769: #
1770: # Create the excel spreadsheet
1771: my $filename = '/prtspool/'.
1.258 albertel 1772: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1773: time.'_'.rand(1000000000).'.xls';
1774: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1775: if (! defined($workbook)) {
1776: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1777: $r->print(
1778: '<p class="LC_error">'
1779: .&mt('Problems occurred in creating the new Excel file.')
1780: .' '.&mt('This error has been logged.')
1781: .' '.&mt('Please alert your LON-CAPA administrator.')
1782: .'</p>'
1783: );
1.255 matthew 1784: return (undef);
1785: }
1786: #
1787: $workbook->set_tempdir('/home/httpd/perl/tmp');
1788: #
1789: my $format = &Apache::loncommon::define_excel_formats($workbook);
1790: return ($workbook,$filename,$format);
1791: }
1792:
1793: ###############################################################
1794: ###############################################################
1795:
1796: =pod
1797:
1.648 raeburn 1798: =item * &create_text_file()
1.113 bowersj2 1799:
1.542 raeburn 1800: Create a file to write to and eventually make available to the user.
1.256 matthew 1801: If file creation fails, outputs an error message on the request object and
1802: return undefs.
1.113 bowersj2 1803:
1.256 matthew 1804: Inputs: Apache request object, and file suffix
1.113 bowersj2 1805:
1.256 matthew 1806: Returns (undef) on failure,
1807: Filehandle and filename on success.
1.113 bowersj2 1808:
1809: =cut
1810:
1.256 matthew 1811: ###############################################################
1812: ###############################################################
1813: sub create_text_file {
1814: my ($r,$suffix) = @_;
1815: if (! defined($suffix)) { $suffix = 'txt'; };
1816: my $fh;
1817: my $filename = '/prtspool/'.
1.258 albertel 1818: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1819: time.'_'.rand(1000000000).'.'.$suffix;
1820: $fh = Apache::File->new('>/home/httpd'.$filename);
1821: if (! defined($fh)) {
1822: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1823: $r->print(
1824: '<p class="LC_error">'
1825: .&mt('Problems occurred in creating the output file.')
1826: .' '.&mt('This error has been logged.')
1827: .' '.&mt('Please alert your LON-CAPA administrator.')
1828: .'</p>'
1829: );
1.113 bowersj2 1830: }
1.256 matthew 1831: return ($fh,$filename)
1.113 bowersj2 1832: }
1833:
1834:
1.256 matthew 1835: =pod
1.113 bowersj2 1836:
1837: =back
1838:
1839: =cut
1.37 matthew 1840:
1841: ###############################################################
1.33 matthew 1842: ## Home server <option> list generating code ##
1843: ###############################################################
1.35 matthew 1844:
1.169 www 1845: # ------------------------------------------
1846:
1847: sub domain_select {
1848: my ($name,$value,$multiple)=@_;
1849: my %domains=map {
1.514 albertel 1850: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1851: } &Apache::lonnet::all_domains();
1.169 www 1852: if ($multiple) {
1853: $domains{''}=&mt('Any domain');
1.550 albertel 1854: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1855: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1856: } else {
1.550 albertel 1857: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.948.2.7 raeburn 1858: return &select_form($name,$value,\%domains);
1.169 www 1859: }
1860: }
1861:
1.282 albertel 1862: #-------------------------------------------
1863:
1864: =pod
1865:
1.519 raeburn 1866: =head1 Routines for form select boxes
1867:
1868: =over 4
1869:
1.648 raeburn 1870: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1871:
1872: Returns a string containing a <select> element int multiple mode
1873:
1874:
1875: Args:
1876: $name - name of the <select> element
1.506 raeburn 1877: $value - scalar or array ref of values that should already be selected
1.282 albertel 1878: $size - number of rows long the select element is
1.283 albertel 1879: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1880: (shown text should already have been &mt())
1.506 raeburn 1881: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1882:
1.282 albertel 1883: =cut
1884:
1885: #-------------------------------------------
1.169 www 1886: sub multiple_select_form {
1.284 albertel 1887: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1888: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1889: my $output='';
1.191 matthew 1890: if (! defined($size)) {
1891: $size = 4;
1.283 albertel 1892: if (scalar(keys(%$hash))<4) {
1893: $size = scalar(keys(%$hash));
1.191 matthew 1894: }
1895: }
1.734 bisitz 1896: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1897: my @order;
1.506 raeburn 1898: if (ref($order) eq 'ARRAY') {
1899: @order = @{$order};
1900: } else {
1901: @order = sort(keys(%$hash));
1.501 banghart 1902: }
1903: if (exists($$hash{'select_form_order'})) {
1904: @order = @{$$hash{'select_form_order'}};
1905: }
1906:
1.284 albertel 1907: foreach my $key (@order) {
1.356 albertel 1908: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1909: $output.='selected="selected" ' if ($selected{$key});
1910: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1911: }
1912: $output.="</select>\n";
1913: return $output;
1914: }
1915:
1.88 www 1916: #-------------------------------------------
1917:
1918: =pod
1919:
1.948.2.7 raeburn 1920: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1921:
1922: Returns a string containing a <select name='$name' size='1'> form to
1.948.2.7 raeburn 1923: allow a user to select options from a ref to a hash containing:
1924: option_name => displayed text. An optional $onchange can include
1925: a javascript onchange item, e.g., onchange="this.form.submit();"
1926:
1.88 www 1927: See lonrights.pm for an example invocation and use.
1928:
1929: =cut
1930:
1931: #-------------------------------------------
1932: sub select_form {
1.948.2.7 raeburn 1933: my ($def,$name,$hashref,$onchange) = @_;
1934: return unless (ref($hashref) eq 'HASH');
1935: if ($onchange) {
1936: $onchange = ' onchange="'.$onchange.'"';
1937: }
1938: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1939: my @keys;
1.948.2.7 raeburn 1940: if (exists($hashref->{'select_form_order'})) {
1941: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1942: } else {
1.948.2.7 raeburn 1943: @keys=sort(keys(%{$hashref}));
1.128 albertel 1944: }
1.356 albertel 1945: foreach my $key (@keys) {
1946: $selectform.=
1947: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1948: ($key eq $def ? 'selected="selected" ' : '').
1.948.2.7 raeburn 1949: ">".$hashref->{$key}."</option>\n";
1.88 www 1950: }
1951: $selectform.="</select>";
1952: return $selectform;
1953: }
1954:
1.475 www 1955: # For display filters
1956:
1957: sub display_filter {
1958: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1959: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1960: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1961: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1962: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1963: '</label></span> <span class="LC_nobreak">'.
1.475 www 1964: &mt('Filter [_1]',
1.477 www 1965: &select_form($env{'form.displayfilter'},
1966: 'displayfilter',
1.948.2.7 raeburn 1967: {'currentfolder' => 'Current folder/page',
1.477 www 1968: 'containing' => 'Containing phrase',
1.948.2.7 raeburn 1969: 'none' => 'None'})).
1.714 bisitz 1970: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1971: }
1972:
1.167 www 1973: sub gradeleveldescription {
1974: my $gradelevel=shift;
1975: my %gradelevels=(0 => 'Not specified',
1976: 1 => 'Grade 1',
1977: 2 => 'Grade 2',
1978: 3 => 'Grade 3',
1979: 4 => 'Grade 4',
1980: 5 => 'Grade 5',
1981: 6 => 'Grade 6',
1982: 7 => 'Grade 7',
1983: 8 => 'Grade 8',
1984: 9 => 'Grade 9',
1985: 10 => 'Grade 10',
1986: 11 => 'Grade 11',
1987: 12 => 'Grade 12',
1988: 13 => 'Grade 13',
1989: 14 => '100 Level',
1990: 15 => '200 Level',
1991: 16 => '300 Level',
1992: 17 => '400 Level',
1993: 18 => 'Graduate Level');
1994: return &mt($gradelevels{$gradelevel});
1995: }
1996:
1.163 www 1997: sub select_level_form {
1998: my ($deflevel,$name)=@_;
1999: unless ($deflevel) { $deflevel=0; }
1.167 www 2000: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2001: for (my $i=0; $i<=18; $i++) {
2002: $selectform.="<option value=\"$i\" ".
1.253 albertel 2003: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2004: ">".&gradeleveldescription($i)."</option>\n";
2005: }
2006: $selectform.="</select>";
2007: return $selectform;
1.163 www 2008: }
1.167 www 2009:
1.35 matthew 2010: #-------------------------------------------
2011:
1.45 matthew 2012: =pod
2013:
1.910 raeburn 2014: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2015:
2016: Returns a string containing a <select name='$name' size='1'> form to
2017: allow a user to select the domain to preform an operation in.
2018: See loncreateuser.pm for an example invocation and use.
2019:
1.90 www 2020: If the $includeempty flag is set, it also includes an empty choice ("no domain
2021: selected");
2022:
1.743 raeburn 2023: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2024:
1.910 raeburn 2025: 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.
2026:
2027: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2028:
1.35 matthew 2029: =cut
2030:
2031: #-------------------------------------------
1.34 matthew 2032: sub select_dom_form {
1.910 raeburn 2033: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2034: if ($onchange) {
1.874 raeburn 2035: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2036: }
1.910 raeburn 2037: my @domains;
2038: if (ref($incdoms) eq 'ARRAY') {
2039: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2040: } else {
2041: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2042: }
1.90 www 2043: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2044: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2045: foreach my $dom (@domains) {
2046: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2047: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2048: if ($showdomdesc) {
2049: if ($dom ne '') {
2050: my $domdesc = &Apache::lonnet::domain($dom,'description');
2051: if ($domdesc ne '') {
2052: $selectdomain .= ' ('.$domdesc.')';
2053: }
2054: }
2055: }
2056: $selectdomain .= "</option>\n";
1.34 matthew 2057: }
2058: $selectdomain.="</select>";
2059: return $selectdomain;
2060: }
2061:
1.35 matthew 2062: #-------------------------------------------
2063:
1.45 matthew 2064: =pod
2065:
1.648 raeburn 2066: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2067:
1.586 raeburn 2068: input: 4 arguments (two required, two optional) -
2069: $domain - domain of new user
2070: $name - name of form element
2071: $default - Value of 'default' causes a default item to be first
2072: option, and selected by default.
2073: $hide - Value of 'hide' causes hiding of the name of the server,
2074: if 1 server found, or default, if 0 found.
1.594 raeburn 2075: output: returns 2 items:
1.586 raeburn 2076: (a) form element which contains either:
2077: (i) <select name="$name">
2078: <option value="$hostid1">$hostid $servers{$hostid}</option>
2079: <option value="$hostid2">$hostid $servers{$hostid}</option>
2080: </select>
2081: form item if there are multiple library servers in $domain, or
2082: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2083: if there is only one library server in $domain.
2084:
2085: (b) number of library servers found.
2086:
2087: See loncreateuser.pm for example of use.
1.35 matthew 2088:
2089: =cut
2090:
2091: #-------------------------------------------
1.586 raeburn 2092: sub home_server_form_item {
2093: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2094: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2095: my $result;
2096: my $numlib = keys(%servers);
2097: if ($numlib > 1) {
2098: $result .= '<select name="'.$name.'" />'."\n";
2099: if ($default) {
1.804 bisitz 2100: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2101: '</option>'."\n";
2102: }
2103: foreach my $hostid (sort(keys(%servers))) {
2104: $result.= '<option value="'.$hostid.'">'.
2105: $hostid.' '.$servers{$hostid}."</option>\n";
2106: }
2107: $result .= '</select>'."\n";
2108: } elsif ($numlib == 1) {
2109: my $hostid;
2110: foreach my $item (keys(%servers)) {
2111: $hostid = $item;
2112: }
2113: $result .= '<input type="hidden" name="'.$name.'" value="'.
2114: $hostid.'" />';
2115: if (!$hide) {
2116: $result .= $hostid.' '.$servers{$hostid};
2117: }
2118: $result .= "\n";
2119: } elsif ($default) {
2120: $result .= '<input type="hidden" name="'.$name.
2121: '" value="default" />';
2122: if (!$hide) {
2123: $result .= &mt('default');
2124: }
2125: $result .= "\n";
1.33 matthew 2126: }
1.586 raeburn 2127: return ($result,$numlib);
1.33 matthew 2128: }
1.112 bowersj2 2129:
2130: =pod
2131:
1.534 albertel 2132: =back
2133:
1.112 bowersj2 2134: =cut
1.87 matthew 2135:
2136: ###############################################################
1.112 bowersj2 2137: ## Decoding User Agent ##
1.87 matthew 2138: ###############################################################
2139:
2140: =pod
2141:
1.112 bowersj2 2142: =head1 Decoding the User Agent
2143:
2144: =over 4
2145:
2146: =item * &decode_user_agent()
1.87 matthew 2147:
2148: Inputs: $r
2149:
2150: Outputs:
2151:
2152: =over 4
2153:
1.112 bowersj2 2154: =item * $httpbrowser
1.87 matthew 2155:
1.112 bowersj2 2156: =item * $clientbrowser
1.87 matthew 2157:
1.112 bowersj2 2158: =item * $clientversion
1.87 matthew 2159:
1.112 bowersj2 2160: =item * $clientmathml
1.87 matthew 2161:
1.112 bowersj2 2162: =item * $clientunicode
1.87 matthew 2163:
1.112 bowersj2 2164: =item * $clientos
1.87 matthew 2165:
2166: =back
2167:
1.157 matthew 2168: =back
2169:
1.87 matthew 2170: =cut
2171:
2172: ###############################################################
2173: ###############################################################
2174: sub decode_user_agent {
1.247 albertel 2175: my ($r)=@_;
1.87 matthew 2176: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2177: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2178: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2179: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2180: my $clientbrowser='unknown';
2181: my $clientversion='0';
2182: my $clientmathml='';
2183: my $clientunicode='0';
2184: for (my $i=0;$i<=$#browsertype;$i++) {
2185: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2186: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2187: $clientbrowser=$bname;
2188: $httpbrowser=~/$vreg/i;
2189: $clientversion=$1;
2190: $clientmathml=($clientversion>=$minv);
2191: $clientunicode=($clientversion>=$univ);
2192: }
2193: }
2194: my $clientos='unknown';
2195: if (($httpbrowser=~/linux/i) ||
2196: ($httpbrowser=~/unix/i) ||
2197: ($httpbrowser=~/ux/i) ||
2198: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2199: if (($httpbrowser=~/vax/i) ||
2200: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2201: if ($httpbrowser=~/next/i) { $clientos='next'; }
2202: if (($httpbrowser=~/mac/i) ||
2203: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2204: if ($httpbrowser=~/win/i) { $clientos='win'; }
2205: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2206: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2207: $clientunicode,$clientos,);
2208: }
2209:
1.32 matthew 2210: ###############################################################
2211: ## Authentication changing form generation subroutines ##
2212: ###############################################################
2213: ##
2214: ## All of the authform_xxxxxxx subroutines take their inputs in a
2215: ## hash, and have reasonable default values.
2216: ##
2217: ## formname = the name given in the <form> tag.
1.35 matthew 2218: #-------------------------------------------
2219:
1.45 matthew 2220: =pod
2221:
1.112 bowersj2 2222: =head1 Authentication Routines
2223:
2224: =over 4
2225:
1.648 raeburn 2226: =item * &authform_xxxxxx()
1.35 matthew 2227:
2228: The authform_xxxxxx subroutines provide javascript and html forms which
2229: handle some of the conveniences required for authentication forms.
2230: This is not an optimal method, but it works.
2231:
2232: =over 4
2233:
1.112 bowersj2 2234: =item * authform_header
1.35 matthew 2235:
1.112 bowersj2 2236: =item * authform_authorwarning
1.35 matthew 2237:
1.112 bowersj2 2238: =item * authform_nochange
1.35 matthew 2239:
1.112 bowersj2 2240: =item * authform_kerberos
1.35 matthew 2241:
1.112 bowersj2 2242: =item * authform_internal
1.35 matthew 2243:
1.112 bowersj2 2244: =item * authform_filesystem
1.35 matthew 2245:
2246: =back
2247:
1.648 raeburn 2248: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2249:
1.35 matthew 2250: =cut
2251:
2252: #-------------------------------------------
1.32 matthew 2253: sub authform_header{
2254: my %in = (
2255: formname => 'cu',
1.80 albertel 2256: kerb_def_dom => '',
1.32 matthew 2257: @_,
2258: );
2259: $in{'formname'} = 'document.' . $in{'formname'};
2260: my $result='';
1.80 albertel 2261:
2262: #---------------------------------------------- Code for upper case translation
2263: my $Javascript_toUpperCase;
2264: unless ($in{kerb_def_dom}) {
2265: $Javascript_toUpperCase =<<"END";
2266: switch (choice) {
2267: case 'krb': currentform.elements[choicearg].value =
2268: currentform.elements[choicearg].value.toUpperCase();
2269: break;
2270: default:
2271: }
2272: END
2273: } else {
2274: $Javascript_toUpperCase = "";
2275: }
2276:
1.165 raeburn 2277: my $radioval = "'nochange'";
1.591 raeburn 2278: if (defined($in{'curr_authtype'})) {
2279: if ($in{'curr_authtype'} ne '') {
2280: $radioval = "'".$in{'curr_authtype'}."arg'";
2281: }
1.174 matthew 2282: }
1.165 raeburn 2283: my $argfield = 'null';
1.591 raeburn 2284: if (defined($in{'mode'})) {
1.165 raeburn 2285: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2286: if (defined($in{'curr_autharg'})) {
2287: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2288: $argfield = "'$in{'curr_autharg'}'";
2289: }
2290: }
2291: }
2292: }
2293:
1.32 matthew 2294: $result.=<<"END";
2295: var current = new Object();
1.165 raeburn 2296: current.radiovalue = $radioval;
2297: current.argfield = $argfield;
1.32 matthew 2298:
2299: function changed_radio(choice,currentform) {
2300: var choicearg = choice + 'arg';
2301: // If a radio button in changed, we need to change the argfield
2302: if (current.radiovalue != choice) {
2303: current.radiovalue = choice;
2304: if (current.argfield != null) {
2305: currentform.elements[current.argfield].value = '';
2306: }
2307: if (choice == 'nochange') {
2308: current.argfield = null;
2309: } else {
2310: current.argfield = choicearg;
2311: switch(choice) {
2312: case 'krb':
2313: currentform.elements[current.argfield].value =
2314: "$in{'kerb_def_dom'}";
2315: break;
2316: default:
2317: break;
2318: }
2319: }
2320: }
2321: return;
2322: }
1.22 www 2323:
1.32 matthew 2324: function changed_text(choice,currentform) {
2325: var choicearg = choice + 'arg';
2326: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2327: $Javascript_toUpperCase
1.32 matthew 2328: // clear old field
2329: if ((current.argfield != choicearg) && (current.argfield != null)) {
2330: currentform.elements[current.argfield].value = '';
2331: }
2332: current.argfield = choicearg;
2333: }
2334: set_auth_radio_buttons(choice,currentform);
2335: return;
1.20 www 2336: }
1.32 matthew 2337:
2338: function set_auth_radio_buttons(newvalue,currentform) {
1.948.2.13 raeburn 2339: var numauthchoices = currentform.login.length;
2340: if (typeof numauthchoices == "undefined") {
2341: return;
2342: }
1.32 matthew 2343: var i=0;
1.948.2.17 raeburn 2344: while (i < numauthchoices) {
1.32 matthew 2345: if (currentform.login[i].value == newvalue) { break; }
2346: i++;
2347: }
1.948.2.13 raeburn 2348: if (i == numauthchoices) {
1.32 matthew 2349: return;
2350: }
2351: current.radiovalue = newvalue;
2352: currentform.login[i].checked = true;
2353: return;
2354: }
2355: END
2356: return $result;
2357: }
2358:
2359: sub authform_authorwarning{
2360: my $result='';
1.144 matthew 2361: $result='<i>'.
2362: &mt('As a general rule, only authors or co-authors should be '.
2363: 'filesystem authenticated '.
2364: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2365: return $result;
2366: }
2367:
2368: sub authform_nochange{
2369: my %in = (
2370: formname => 'document.cu',
2371: kerb_def_dom => 'MSU.EDU',
2372: @_,
2373: );
1.586 raeburn 2374: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2375: my $result;
2376: if (keys(%can_assign) == 0) {
2377: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2378: } else {
2379: $result = '<label>'.&mt('[_1] Do not change login data',
2380: '<input type="radio" name="login" value="nochange" '.
2381: 'checked="checked" onclick="'.
1.281 albertel 2382: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2383: '</label>';
1.586 raeburn 2384: }
1.32 matthew 2385: return $result;
2386: }
2387:
1.591 raeburn 2388: sub authform_kerberos {
1.32 matthew 2389: my %in = (
2390: formname => 'document.cu',
2391: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2392: kerb_def_auth => 'krb4',
1.32 matthew 2393: @_,
2394: );
1.586 raeburn 2395: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2396: $autharg,$jscall);
2397: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2398: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2399: $check5 = ' checked="checked"';
1.80 albertel 2400: } else {
1.772 bisitz 2401: $check4 = ' checked="checked"';
1.80 albertel 2402: }
1.165 raeburn 2403: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2404: if (defined($in{'curr_authtype'})) {
2405: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2406: $krbcheck = ' checked="checked"';
1.623 raeburn 2407: if (defined($in{'mode'})) {
2408: if ($in{'mode'} eq 'modifyuser') {
2409: $krbcheck = '';
2410: }
2411: }
1.591 raeburn 2412: if (defined($in{'curr_kerb_ver'})) {
2413: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2414: $check5 = ' checked="checked"';
1.591 raeburn 2415: $check4 = '';
2416: } else {
1.772 bisitz 2417: $check4 = ' checked="checked"';
1.591 raeburn 2418: $check5 = '';
2419: }
1.586 raeburn 2420: }
1.591 raeburn 2421: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2422: $krbarg = $in{'curr_autharg'};
2423: }
1.586 raeburn 2424: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2425: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2426: $result =
2427: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2428: $in{'curr_autharg'},$krbver);
2429: } else {
2430: $result =
2431: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2432: }
2433: return $result;
2434: }
2435: }
2436: } else {
2437: if ($authnum == 1) {
1.784 bisitz 2438: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2439: }
2440: }
1.586 raeburn 2441: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2442: return;
1.587 raeburn 2443: } elsif ($authtype eq '') {
1.591 raeburn 2444: if (defined($in{'mode'})) {
1.587 raeburn 2445: if ($in{'mode'} eq 'modifycourse') {
2446: if ($authnum == 1) {
1.784 bisitz 2447: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2448: }
2449: }
2450: }
1.586 raeburn 2451: }
2452: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2453: if ($authtype eq '') {
2454: $authtype = '<input type="radio" name="login" value="krb" '.
2455: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2456: $krbcheck.' />';
2457: }
2458: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2459: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2460: $in{'curr_authtype'} eq 'krb5') ||
2461: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2462: $in{'curr_authtype'} eq 'krb4')) {
2463: $result .= &mt
1.144 matthew 2464: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2465: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2466: '<label>'.$authtype,
1.281 albertel 2467: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2468: 'value="'.$krbarg.'" '.
1.144 matthew 2469: 'onchange="'.$jscall.'" />',
1.281 albertel 2470: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2471: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2472: '</label>');
1.586 raeburn 2473: } elsif ($can_assign{'krb4'}) {
2474: $result .= &mt
2475: ('[_1] Kerberos authenticated with domain [_2] '.
2476: '[_3] Version 4 [_4]',
2477: '<label>'.$authtype,
2478: '</label><input type="text" size="10" name="krbarg" '.
2479: 'value="'.$krbarg.'" '.
2480: 'onchange="'.$jscall.'" />',
2481: '<label><input type="hidden" name="krbver" value="4" />',
2482: '</label>');
2483: } elsif ($can_assign{'krb5'}) {
2484: $result .= &mt
2485: ('[_1] Kerberos authenticated with domain [_2] '.
2486: '[_3] Version 5 [_4]',
2487: '<label>'.$authtype,
2488: '</label><input type="text" size="10" name="krbarg" '.
2489: 'value="'.$krbarg.'" '.
2490: 'onchange="'.$jscall.'" />',
2491: '<label><input type="hidden" name="krbver" value="5" />',
2492: '</label>');
2493: }
1.32 matthew 2494: return $result;
2495: }
2496:
2497: sub authform_internal{
1.586 raeburn 2498: my %in = (
1.32 matthew 2499: formname => 'document.cu',
2500: kerb_def_dom => 'MSU.EDU',
2501: @_,
2502: );
1.586 raeburn 2503: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2504: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2505: if (defined($in{'curr_authtype'})) {
2506: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2507: if ($can_assign{'int'}) {
1.772 bisitz 2508: $intcheck = 'checked="checked" ';
1.623 raeburn 2509: if (defined($in{'mode'})) {
2510: if ($in{'mode'} eq 'modifyuser') {
2511: $intcheck = '';
2512: }
2513: }
1.591 raeburn 2514: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2515: $intarg = $in{'curr_autharg'};
2516: }
2517: } else {
2518: $result = &mt('Currently internally authenticated.');
2519: return $result;
1.165 raeburn 2520: }
2521: }
1.586 raeburn 2522: } else {
2523: if ($authnum == 1) {
1.784 bisitz 2524: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2525: }
2526: }
2527: if (!$can_assign{'int'}) {
2528: return;
1.587 raeburn 2529: } elsif ($authtype eq '') {
1.591 raeburn 2530: if (defined($in{'mode'})) {
1.587 raeburn 2531: if ($in{'mode'} eq 'modifycourse') {
2532: if ($authnum == 1) {
1.784 bisitz 2533: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2534: }
2535: }
2536: }
1.165 raeburn 2537: }
1.586 raeburn 2538: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2539: if ($authtype eq '') {
2540: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2541: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2542: }
1.605 bisitz 2543: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2544: $intarg.'" onchange="'.$jscall.'" />';
2545: $result = &mt
1.144 matthew 2546: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2547: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2548: $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 2549: return $result;
2550: }
2551:
2552: sub authform_local{
2553: my %in = (
2554: formname => 'document.cu',
2555: kerb_def_dom => 'MSU.EDU',
2556: @_,
2557: );
1.586 raeburn 2558: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2559: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2560: if (defined($in{'curr_authtype'})) {
2561: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2562: if ($can_assign{'loc'}) {
1.772 bisitz 2563: $loccheck = 'checked="checked" ';
1.623 raeburn 2564: if (defined($in{'mode'})) {
2565: if ($in{'mode'} eq 'modifyuser') {
2566: $loccheck = '';
2567: }
2568: }
1.591 raeburn 2569: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2570: $locarg = $in{'curr_autharg'};
2571: }
2572: } else {
2573: $result = &mt('Currently using local (institutional) authentication.');
2574: return $result;
1.165 raeburn 2575: }
2576: }
1.586 raeburn 2577: } else {
2578: if ($authnum == 1) {
1.784 bisitz 2579: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2580: }
2581: }
2582: if (!$can_assign{'loc'}) {
2583: return;
1.587 raeburn 2584: } elsif ($authtype eq '') {
1.591 raeburn 2585: if (defined($in{'mode'})) {
1.587 raeburn 2586: if ($in{'mode'} eq 'modifycourse') {
2587: if ($authnum == 1) {
1.784 bisitz 2588: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2589: }
2590: }
2591: }
1.165 raeburn 2592: }
1.586 raeburn 2593: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2594: if ($authtype eq '') {
2595: $authtype = '<input type="radio" name="login" value="loc" '.
2596: $loccheck.' onchange="'.$jscall.'" onclick="'.
2597: $jscall.'" />';
2598: }
2599: $autharg = '<input type="text" size="10" name="locarg" value="'.
2600: $locarg.'" onchange="'.$jscall.'" />';
2601: $result = &mt('[_1] Local Authentication with argument [_2]',
2602: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2603: return $result;
2604: }
2605:
2606: sub authform_filesystem{
2607: my %in = (
2608: formname => 'document.cu',
2609: kerb_def_dom => 'MSU.EDU',
2610: @_,
2611: );
1.586 raeburn 2612: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2613: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2614: if (defined($in{'curr_authtype'})) {
2615: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2616: if ($can_assign{'fsys'}) {
1.772 bisitz 2617: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2618: if (defined($in{'mode'})) {
2619: if ($in{'mode'} eq 'modifyuser') {
2620: $fsyscheck = '';
2621: }
2622: }
1.586 raeburn 2623: } else {
2624: $result = &mt('Currently Filesystem Authenticated.');
2625: return $result;
2626: }
2627: }
2628: } else {
2629: if ($authnum == 1) {
1.784 bisitz 2630: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2631: }
2632: }
2633: if (!$can_assign{'fsys'}) {
2634: return;
1.587 raeburn 2635: } elsif ($authtype eq '') {
1.591 raeburn 2636: if (defined($in{'mode'})) {
1.587 raeburn 2637: if ($in{'mode'} eq 'modifycourse') {
2638: if ($authnum == 1) {
1.784 bisitz 2639: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2640: }
2641: }
2642: }
1.586 raeburn 2643: }
2644: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2645: if ($authtype eq '') {
2646: $authtype = '<input type="radio" name="login" value="fsys" '.
2647: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2648: $jscall.'" />';
2649: }
2650: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2651: ' onchange="'.$jscall.'" />';
2652: $result = &mt
1.144 matthew 2653: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2654: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2655: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2656: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2657: 'onchange="'.$jscall.'" />');
1.32 matthew 2658: return $result;
2659: }
2660:
1.586 raeburn 2661: sub get_assignable_auth {
2662: my ($dom) = @_;
2663: if ($dom eq '') {
2664: $dom = $env{'request.role.domain'};
2665: }
2666: my %can_assign = (
2667: krb4 => 1,
2668: krb5 => 1,
2669: int => 1,
2670: loc => 1,
2671: );
2672: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2673: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2674: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2675: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2676: my $context;
2677: if ($env{'request.role'} =~ /^au/) {
2678: $context = 'author';
2679: } elsif ($env{'request.role'} =~ /^dc/) {
2680: $context = 'domain';
2681: } elsif ($env{'request.course.id'}) {
2682: $context = 'course';
2683: }
2684: if ($context) {
2685: if (ref($authhash->{$context}) eq 'HASH') {
2686: %can_assign = %{$authhash->{$context}};
2687: }
2688: }
2689: }
2690: }
2691: my $authnum = 0;
2692: foreach my $key (keys(%can_assign)) {
2693: if ($can_assign{$key}) {
2694: $authnum ++;
2695: }
2696: }
2697: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2698: $authnum --;
2699: }
2700: return ($authnum,%can_assign);
2701: }
2702:
1.80 albertel 2703: ###############################################################
2704: ## Get Kerberos Defaults for Domain ##
2705: ###############################################################
2706: ##
2707: ## Returns default kerberos version and an associated argument
2708: ## as listed in file domain.tab. If not listed, provides
2709: ## appropriate default domain and kerberos version.
2710: ##
2711: #-------------------------------------------
2712:
2713: =pod
2714:
1.648 raeburn 2715: =item * &get_kerberos_defaults()
1.80 albertel 2716:
2717: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2718: version and domain. If not found, it defaults to version 4 and the
2719: domain of the server.
1.80 albertel 2720:
1.648 raeburn 2721: =over 4
2722:
1.80 albertel 2723: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2724:
1.648 raeburn 2725: =back
2726:
2727: =back
2728:
1.80 albertel 2729: =cut
2730:
2731: #-------------------------------------------
2732: sub get_kerberos_defaults {
2733: my $domain=shift;
1.641 raeburn 2734: my ($krbdef,$krbdefdom);
2735: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2736: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2737: $krbdef = $domdefaults{'auth_def'};
2738: $krbdefdom = $domdefaults{'auth_arg_def'};
2739: } else {
1.80 albertel 2740: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2741: my $krbdefdom=$1;
2742: $krbdefdom=~tr/a-z/A-Z/;
2743: $krbdef = "krb4";
2744: }
2745: return ($krbdef,$krbdefdom);
2746: }
1.112 bowersj2 2747:
1.32 matthew 2748:
1.46 matthew 2749: ###############################################################
2750: ## Thesaurus Functions ##
2751: ###############################################################
1.20 www 2752:
1.46 matthew 2753: =pod
1.20 www 2754:
1.112 bowersj2 2755: =head1 Thesaurus Functions
2756:
2757: =over 4
2758:
1.648 raeburn 2759: =item * &initialize_keywords()
1.46 matthew 2760:
2761: Initializes the package variable %Keywords if it is empty. Uses the
2762: package variable $thesaurus_db_file.
2763:
2764: =cut
2765:
2766: ###################################################
2767:
2768: sub initialize_keywords {
2769: return 1 if (scalar keys(%Keywords));
2770: # If we are here, %Keywords is empty, so fill it up
2771: # Make sure the file we need exists...
2772: if (! -e $thesaurus_db_file) {
2773: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2774: " failed because it does not exist");
2775: return 0;
2776: }
2777: # Set up the hash as a database
2778: my %thesaurus_db;
2779: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2780: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2781: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2782: $thesaurus_db_file);
2783: return 0;
2784: }
2785: # Get the average number of appearances of a word.
2786: my $avecount = $thesaurus_db{'average.count'};
2787: # Put keywords (those that appear > average) into %Keywords
2788: while (my ($word,$data)=each (%thesaurus_db)) {
2789: my ($count,undef) = split /:/,$data;
2790: $Keywords{$word}++ if ($count > $avecount);
2791: }
2792: untie %thesaurus_db;
2793: # Remove special values from %Keywords.
1.356 albertel 2794: foreach my $value ('total.count','average.count') {
2795: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2796: }
1.46 matthew 2797: return 1;
2798: }
2799:
2800: ###################################################
2801:
2802: =pod
2803:
1.648 raeburn 2804: =item * &keyword($word)
1.46 matthew 2805:
2806: Returns true if $word is a keyword. A keyword is a word that appears more
2807: than the average number of times in the thesaurus database. Calls
2808: &initialize_keywords
2809:
2810: =cut
2811:
2812: ###################################################
1.20 www 2813:
2814: sub keyword {
1.46 matthew 2815: return if (!&initialize_keywords());
2816: my $word=lc(shift());
2817: $word=~s/\W//g;
2818: return exists($Keywords{$word});
1.20 www 2819: }
1.46 matthew 2820:
2821: ###############################################################
2822:
2823: =pod
1.20 www 2824:
1.648 raeburn 2825: =item * &get_related_words()
1.46 matthew 2826:
1.160 matthew 2827: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2828: an array of words. If the keyword is not in the thesaurus, an empty array
2829: will be returned. The order of the words returned is determined by the
2830: database which holds them.
2831:
2832: Uses global $thesaurus_db_file.
2833:
2834: =cut
2835:
2836: ###############################################################
2837: sub get_related_words {
2838: my $keyword = shift;
2839: my %thesaurus_db;
2840: if (! -e $thesaurus_db_file) {
2841: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2842: "failed because the file does not exist");
2843: return ();
2844: }
2845: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2846: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2847: return ();
2848: }
2849: my @Words=();
1.429 www 2850: my $count=0;
1.46 matthew 2851: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2852: # The first element is the number of times
2853: # the word appears. We do not need it now.
1.429 www 2854: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2855: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2856: my $threshold=$mostfrequentcount/10;
2857: foreach my $possibleword (@RelatedWords) {
2858: my ($word,$wordcount)=split(/\,/,$possibleword);
2859: if ($wordcount>$threshold) {
2860: push(@Words,$word);
2861: $count++;
2862: if ($count>10) { last; }
2863: }
1.20 www 2864: }
2865: }
1.46 matthew 2866: untie %thesaurus_db;
2867: return @Words;
1.14 harris41 2868: }
1.46 matthew 2869:
1.112 bowersj2 2870: =pod
2871:
2872: =back
2873:
2874: =cut
1.61 www 2875:
2876: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2877: =pod
2878:
1.112 bowersj2 2879: =head1 User Name Functions
2880:
2881: =over 4
2882:
1.648 raeburn 2883: =item * &plainname($uname,$udom,$first)
1.81 albertel 2884:
1.112 bowersj2 2885: Takes a users logon name and returns it as a string in
1.226 albertel 2886: "first middle last generation" form
2887: if $first is set to 'lastname' then it returns it as
2888: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2889:
2890: =cut
1.61 www 2891:
1.295 www 2892:
1.81 albertel 2893: ###############################################################
1.61 www 2894: sub plainname {
1.226 albertel 2895: my ($uname,$udom,$first)=@_;
1.537 albertel 2896: return if (!defined($uname) || !defined($udom));
1.295 www 2897: my %names=&getnames($uname,$udom);
1.226 albertel 2898: my $name=&Apache::lonnet::format_name($names{'firstname'},
2899: $names{'middlename'},
2900: $names{'lastname'},
2901: $names{'generation'},$first);
2902: $name=~s/^\s+//;
1.62 www 2903: $name=~s/\s+$//;
2904: $name=~s/\s+/ /g;
1.353 albertel 2905: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2906: return $name;
1.61 www 2907: }
1.66 www 2908:
2909: # -------------------------------------------------------------------- Nickname
1.81 albertel 2910: =pod
2911:
1.648 raeburn 2912: =item * &nickname($uname,$udom)
1.81 albertel 2913:
2914: Gets a users name and returns it as a string as
2915:
2916: ""nickname""
1.66 www 2917:
1.81 albertel 2918: if the user has a nickname or
2919:
2920: "first middle last generation"
2921:
2922: if the user does not
2923:
2924: =cut
1.66 www 2925:
2926: sub nickname {
2927: my ($uname,$udom)=@_;
1.537 albertel 2928: return if (!defined($uname) || !defined($udom));
1.295 www 2929: my %names=&getnames($uname,$udom);
1.68 albertel 2930: my $name=$names{'nickname'};
1.66 www 2931: if ($name) {
2932: $name='"'.$name.'"';
2933: } else {
2934: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2935: $names{'lastname'}.' '.$names{'generation'};
2936: $name=~s/\s+$//;
2937: $name=~s/\s+/ /g;
2938: }
2939: return $name;
2940: }
2941:
1.295 www 2942: sub getnames {
2943: my ($uname,$udom)=@_;
1.537 albertel 2944: return if (!defined($uname) || !defined($udom));
1.433 albertel 2945: if ($udom eq 'public' && $uname eq 'public') {
2946: return ('lastname' => &mt('Public'));
2947: }
1.295 www 2948: my $id=$uname.':'.$udom;
2949: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2950: if ($cached) {
2951: return %{$names};
2952: } else {
2953: my %loadnames=&Apache::lonnet::get('environment',
2954: ['firstname','middlename','lastname','generation','nickname'],
2955: $udom,$uname);
2956: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2957: return %loadnames;
2958: }
2959: }
1.61 www 2960:
1.542 raeburn 2961: # -------------------------------------------------------------------- getemails
1.648 raeburn 2962:
1.542 raeburn 2963: =pod
2964:
1.648 raeburn 2965: =item * &getemails($uname,$udom)
1.542 raeburn 2966:
2967: Gets a user's email information and returns it as a hash with keys:
2968: notification, critnotification, permanentemail
2969:
2970: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2971: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2972:
1.648 raeburn 2973:
1.542 raeburn 2974: =cut
2975:
1.648 raeburn 2976:
1.466 albertel 2977: sub getemails {
2978: my ($uname,$udom)=@_;
2979: if ($udom eq 'public' && $uname eq 'public') {
2980: return;
2981: }
1.467 www 2982: if (!$udom) { $udom=$env{'user.domain'}; }
2983: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2984: my $id=$uname.':'.$udom;
2985: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2986: if ($cached) {
2987: return %{$names};
2988: } else {
2989: my %loadnames=&Apache::lonnet::get('environment',
2990: ['notification','critnotification',
2991: 'permanentemail'],
2992: $udom,$uname);
2993: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2994: return %loadnames;
2995: }
2996: }
2997:
1.551 albertel 2998: sub flush_email_cache {
2999: my ($uname,$udom)=@_;
3000: if (!$udom) { $udom =$env{'user.domain'}; }
3001: if (!$uname) { $uname=$env{'user.name'}; }
3002: return if ($udom eq 'public' && $uname eq 'public');
3003: my $id=$uname.':'.$udom;
3004: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3005: }
3006:
1.728 raeburn 3007: # -------------------------------------------------------------------- getlangs
3008:
3009: =pod
3010:
3011: =item * &getlangs($uname,$udom)
3012:
3013: Gets a user's language preference and returns it as a hash with key:
3014: language.
3015:
3016: =cut
3017:
3018:
3019: sub getlangs {
3020: my ($uname,$udom) = @_;
3021: if (!$udom) { $udom =$env{'user.domain'}; }
3022: if (!$uname) { $uname=$env{'user.name'}; }
3023: my $id=$uname.':'.$udom;
3024: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3025: if ($cached) {
3026: return %{$langs};
3027: } else {
3028: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3029: $udom,$uname);
3030: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3031: return %loadlangs;
3032: }
3033: }
3034:
3035: sub flush_langs_cache {
3036: my ($uname,$udom)=@_;
3037: if (!$udom) { $udom =$env{'user.domain'}; }
3038: if (!$uname) { $uname=$env{'user.name'}; }
3039: return if ($udom eq 'public' && $uname eq 'public');
3040: my $id=$uname.':'.$udom;
3041: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3042: }
3043:
1.61 www 3044: # ------------------------------------------------------------------ Screenname
1.81 albertel 3045:
3046: =pod
3047:
1.648 raeburn 3048: =item * &screenname($uname,$udom)
1.81 albertel 3049:
3050: Gets a users screenname and returns it as a string
3051:
3052: =cut
1.61 www 3053:
3054: sub screenname {
3055: my ($uname,$udom)=@_;
1.258 albertel 3056: if ($uname eq $env{'user.name'} &&
3057: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3058: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3059: return $names{'screenname'};
1.62 www 3060: }
3061:
1.212 albertel 3062:
1.802 bisitz 3063: # ------------------------------------------------------------- Confirm Wrapper
3064: =pod
3065:
3066: =item confirmwrapper
3067:
3068: Wrap messages about completion of operation in box
3069:
3070: =cut
3071:
3072: sub confirmwrapper {
3073: my ($message)=@_;
3074: if ($message) {
3075: return "\n".'<div class="LC_confirm_box">'."\n"
3076: .$message."\n"
3077: .'</div>'."\n";
3078: } else {
3079: return $message;
3080: }
3081: }
3082:
1.62 www 3083: # ------------------------------------------------------------- Message Wrapper
3084:
3085: sub messagewrapper {
1.369 www 3086: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3087: return
1.441 albertel 3088: '<a href="/adm/email?compose=individual&'.
3089: 'recname='.$username.'&recdom='.$domain.
3090: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3091: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3092: }
1.802 bisitz 3093:
1.74 www 3094: # --------------------------------------------------------------- Notes Wrapper
3095:
3096: sub noteswrapper {
3097: my ($link,$un,$do)=@_;
3098: return
1.896 amueller 3099: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3100: }
1.802 bisitz 3101:
1.62 www 3102: # ------------------------------------------------------------- Aboutme Wrapper
3103:
3104: sub aboutmewrapper {
1.166 www 3105: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3106: if (!defined($username) && !defined($domain)) {
3107: return;
3108: }
1.892 amueller 3109: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3110: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3111: }
3112:
3113: # ------------------------------------------------------------ Syllabus Wrapper
3114:
3115: sub syllabuswrapper {
1.707 bisitz 3116: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3117: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3118: }
1.14 harris41 3119:
1.802 bisitz 3120: # -----------------------------------------------------------------------------
3121:
1.208 matthew 3122: sub track_student_link {
1.887 raeburn 3123: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3124: my $link ="/adm/trackstudent?";
1.208 matthew 3125: my $title = 'View recent activity';
3126: if (defined($sname) && $sname !~ /^\s*$/ &&
3127: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3128: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3129: $title .= ' of this student';
1.268 albertel 3130: }
1.208 matthew 3131: if (defined($target) && $target !~ /^\s*$/) {
3132: $target = qq{target="$target"};
3133: } else {
3134: $target = '';
3135: }
1.268 albertel 3136: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3137: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3138: $title = &mt($title);
3139: $linktext = &mt($linktext);
1.448 albertel 3140: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3141: &help_open_topic('View_recent_activity');
1.208 matthew 3142: }
3143:
1.781 raeburn 3144: sub slot_reservations_link {
3145: my ($linktext,$sname,$sdom,$target) = @_;
3146: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3147: my $title = 'View slot reservation history';
3148: if (defined($sname) && $sname !~ /^\s*$/ &&
3149: defined($sdom) && $sdom !~ /^\s*$/) {
3150: $link .= "&uname=$sname&udom=$sdom";
3151: $title .= ' of this student';
3152: }
3153: if (defined($target) && $target !~ /^\s*$/) {
3154: $target = qq{target="$target"};
3155: } else {
3156: $target = '';
3157: }
3158: $title = &mt($title);
3159: $linktext = &mt($linktext);
3160: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3161: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3162:
3163: }
3164:
1.508 www 3165: # ===================================================== Display a student photo
3166:
3167:
1.509 albertel 3168: sub student_image_tag {
1.508 www 3169: my ($domain,$user)=@_;
3170: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3171: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3172: return '<img src="'.$imgsrc.'" align="right" />';
3173: } else {
3174: return '';
3175: }
3176: }
3177:
1.112 bowersj2 3178: =pod
3179:
3180: =back
3181:
3182: =head1 Access .tab File Data
3183:
3184: =over 4
3185:
1.648 raeburn 3186: =item * &languageids()
1.112 bowersj2 3187:
3188: returns list of all language ids
3189:
3190: =cut
3191:
1.14 harris41 3192: sub languageids {
1.16 harris41 3193: return sort(keys(%language));
1.14 harris41 3194: }
3195:
1.112 bowersj2 3196: =pod
3197:
1.648 raeburn 3198: =item * &languagedescription()
1.112 bowersj2 3199:
3200: returns description of a specified language id
3201:
3202: =cut
3203:
1.14 harris41 3204: sub languagedescription {
1.125 www 3205: my $code=shift;
3206: return ($supported_language{$code}?'* ':'').
3207: $language{$code}.
1.126 www 3208: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3209: }
3210:
3211: sub plainlanguagedescription {
3212: my $code=shift;
3213: return $language{$code};
3214: }
3215:
3216: sub supportedlanguagecode {
3217: my $code=shift;
3218: return $supported_language{$code};
1.97 www 3219: }
3220:
1.112 bowersj2 3221: =pod
3222:
1.648 raeburn 3223: =item * ©rightids()
1.112 bowersj2 3224:
3225: returns list of all copyrights
3226:
3227: =cut
3228:
3229: sub copyrightids {
3230: return sort(keys(%cprtag));
3231: }
3232:
3233: =pod
3234:
1.648 raeburn 3235: =item * ©rightdescription()
1.112 bowersj2 3236:
3237: returns description of a specified copyright id
3238:
3239: =cut
3240:
3241: sub copyrightdescription {
1.166 www 3242: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3243: }
1.197 matthew 3244:
3245: =pod
3246:
1.648 raeburn 3247: =item * &source_copyrightids()
1.192 taceyjo1 3248:
3249: returns list of all source copyrights
3250:
3251: =cut
3252:
3253: sub source_copyrightids {
3254: return sort(keys(%scprtag));
3255: }
3256:
3257: =pod
3258:
1.648 raeburn 3259: =item * &source_copyrightdescription()
1.192 taceyjo1 3260:
3261: returns description of a specified source copyright id
3262:
3263: =cut
3264:
3265: sub source_copyrightdescription {
3266: return &mt($scprtag{shift(@_)});
3267: }
1.112 bowersj2 3268:
3269: =pod
3270:
1.648 raeburn 3271: =item * &filecategories()
1.112 bowersj2 3272:
3273: returns list of all file categories
3274:
3275: =cut
3276:
3277: sub filecategories {
3278: return sort(keys(%category_extensions));
3279: }
3280:
3281: =pod
3282:
1.648 raeburn 3283: =item * &filecategorytypes()
1.112 bowersj2 3284:
3285: returns list of file types belonging to a given file
3286: category
3287:
3288: =cut
3289:
3290: sub filecategorytypes {
1.356 albertel 3291: my ($cat) = @_;
3292: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3293: }
3294:
3295: =pod
3296:
1.648 raeburn 3297: =item * &fileembstyle()
1.112 bowersj2 3298:
3299: returns embedding style for a specified file type
3300:
3301: =cut
3302:
3303: sub fileembstyle {
3304: return $fe{lc(shift(@_))};
1.169 www 3305: }
3306:
1.351 www 3307: sub filemimetype {
3308: return $fm{lc(shift(@_))};
3309: }
3310:
1.169 www 3311:
3312: sub filecategoryselect {
3313: my ($name,$value)=@_;
1.189 matthew 3314: return &select_form($value,$name,
1.948.2.7 raeburn 3315: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3316: }
3317:
3318: =pod
3319:
1.648 raeburn 3320: =item * &filedescription()
1.112 bowersj2 3321:
3322: returns description for a specified file type
3323:
3324: =cut
3325:
3326: sub filedescription {
1.188 matthew 3327: my $file_description = $fd{lc(shift())};
3328: $file_description =~ s:([\[\]]):~$1:g;
3329: return &mt($file_description);
1.112 bowersj2 3330: }
3331:
3332: =pod
3333:
1.648 raeburn 3334: =item * &filedescriptionex()
1.112 bowersj2 3335:
3336: returns description for a specified file type with
3337: extra formatting
3338:
3339: =cut
3340:
3341: sub filedescriptionex {
3342: my $ex=shift;
1.188 matthew 3343: my $file_description = $fd{lc($ex)};
3344: $file_description =~ s:([\[\]]):~$1:g;
3345: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3346: }
3347:
3348: # End of .tab access
3349: =pod
3350:
3351: =back
3352:
3353: =cut
3354:
3355: # ------------------------------------------------------------------ File Types
3356: sub fileextensions {
3357: return sort(keys(%fe));
3358: }
3359:
1.97 www 3360: # ----------------------------------------------------------- Display Languages
3361: # returns a hash with all desired display languages
3362: #
3363:
3364: sub display_languages {
3365: my %languages=();
1.695 raeburn 3366: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3367: $languages{$lang}=1;
1.97 www 3368: }
3369: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3370: if ($env{'form.displaylanguage'}) {
1.356 albertel 3371: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3372: $languages{$lang}=1;
1.97 www 3373: }
3374: }
3375: return %languages;
1.14 harris41 3376: }
3377:
1.582 albertel 3378: sub languages {
3379: my ($possible_langs) = @_;
1.695 raeburn 3380: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3381: if (!ref($possible_langs)) {
3382: if( wantarray ) {
3383: return @preferred_langs;
3384: } else {
3385: return $preferred_langs[0];
3386: }
3387: }
3388: my %possibilities = map { $_ => 1 } (@$possible_langs);
3389: my @preferred_possibilities;
3390: foreach my $preferred_lang (@preferred_langs) {
3391: if (exists($possibilities{$preferred_lang})) {
3392: push(@preferred_possibilities, $preferred_lang);
3393: }
3394: }
3395: if( wantarray ) {
3396: return @preferred_possibilities;
3397: }
3398: return $preferred_possibilities[0];
3399: }
3400:
1.742 raeburn 3401: sub user_lang {
3402: my ($touname,$toudom,$fromcid) = @_;
3403: my @userlangs;
3404: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3405: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3406: $env{'course.'.$fromcid.'.languages'}));
3407: } else {
3408: my %langhash = &getlangs($touname,$toudom);
3409: if ($langhash{'languages'} ne '') {
3410: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3411: } else {
3412: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3413: if ($domdefs{'lang_def'} ne '') {
3414: @userlangs = ($domdefs{'lang_def'});
3415: }
3416: }
3417: }
3418: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3419: my $user_lh = Apache::localize->get_handle(@languages);
3420: return $user_lh;
3421: }
3422:
3423:
1.112 bowersj2 3424: ###############################################################
3425: ## Student Answer Attempts ##
3426: ###############################################################
3427:
3428: =pod
3429:
3430: =head1 Alternate Problem Views
3431:
3432: =over 4
3433:
1.648 raeburn 3434: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3435: $getattempt, $regexp, $gradesub)
3436:
3437: Return string with previous attempt on problem. Arguments:
3438:
3439: =over 4
3440:
3441: =item * $symb: Problem, including path
3442:
3443: =item * $username: username of the desired student
3444:
3445: =item * $domain: domain of the desired student
1.14 harris41 3446:
1.112 bowersj2 3447: =item * $course: Course ID
1.14 harris41 3448:
1.112 bowersj2 3449: =item * $getattempt: Leave blank for all attempts, otherwise put
3450: something
1.14 harris41 3451:
1.112 bowersj2 3452: =item * $regexp: if string matches this regexp, the string will be
3453: sent to $gradesub
1.14 harris41 3454:
1.112 bowersj2 3455: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3456:
1.112 bowersj2 3457: =back
1.14 harris41 3458:
1.112 bowersj2 3459: The output string is a table containing all desired attempts, if any.
1.16 harris41 3460:
1.112 bowersj2 3461: =cut
1.1 albertel 3462:
3463: sub get_previous_attempt {
1.43 ng 3464: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3465: my $prevattempts='';
1.43 ng 3466: no strict 'refs';
1.1 albertel 3467: if ($symb) {
1.3 albertel 3468: my (%returnhash)=
3469: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3470: if ($returnhash{'version'}) {
3471: my %lasthash=();
3472: my $version;
3473: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3474: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3475: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3476: }
1.1 albertel 3477: }
1.596 albertel 3478: $prevattempts=&start_data_table().&start_data_table_header_row();
3479: $prevattempts.='<th>'.&mt('History').'</th>';
1.948.2.8 raeburn 3480: my (%typeparts,%lasthidden);
1.945 raeburn 3481: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3482: foreach my $key (sort(keys(%lasthash))) {
3483: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3484: if ($#parts > 0) {
1.31 albertel 3485: my $data=$parts[-1];
1.948.2.15 raeburn 3486: next if ($data eq 'foilorder');
1.31 albertel 3487: pop(@parts);
1.945 raeburn 3488: if ($data eq 'type') {
3489: unless ($showsurv) {
3490: my $id = join(',',@parts);
3491: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.948.2.8 raeburn 3492: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3493: $lasthidden{$ign.'.'.$id} = 1;
3494: }
1.945 raeburn 3495: }
3496: delete($lasthash{$key});
3497: } else {
3498: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3499: }
1.31 albertel 3500: } else {
1.41 ng 3501: if ($#parts == 0) {
3502: $prevattempts.='<th>'.$parts[0].'</th>';
3503: } else {
3504: $prevattempts.='<th>'.$ign.'</th>';
3505: }
1.31 albertel 3506: }
1.16 harris41 3507: }
1.596 albertel 3508: $prevattempts.=&end_data_table_header_row();
1.40 ng 3509: if ($getattempt eq '') {
3510: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3511: my @hidden;
3512: if (%typeparts) {
3513: foreach my $id (keys(%typeparts)) {
3514: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3515: push(@hidden,$id);
3516: }
3517: }
3518: }
3519: $prevattempts.=&start_data_table_row().
3520: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3521: if (@hidden) {
3522: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3523: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3524: my $hide;
3525: foreach my $id (@hidden) {
3526: if ($key =~ /^\Q$id\E/) {
3527: $hide = 1;
3528: last;
3529: }
3530: }
3531: if ($hide) {
3532: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3533: if (($data eq 'award') || ($data eq 'awarddetail')) {
3534: my $value = &format_previous_attempt_value($key,
3535: $returnhash{$version.':'.$key});
3536: $prevattempts.='<td>'.$value.' </td>';
3537: } else {
3538: $prevattempts.='<td> </td>';
3539: }
3540: } else {
3541: if ($key =~ /\./) {
3542: my $value = &format_previous_attempt_value($key,
3543: $returnhash{$version.':'.$key});
3544: $prevattempts.='<td>'.$value.' </td>';
3545: } else {
3546: $prevattempts.='<td> </td>';
3547: }
3548: }
3549: }
3550: } else {
3551: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3552: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3553: my $value = &format_previous_attempt_value($key,
3554: $returnhash{$version.':'.$key});
3555: $prevattempts.='<td>'.$value.' </td>';
3556: }
3557: }
3558: $prevattempts.=&end_data_table_row();
1.40 ng 3559: }
1.1 albertel 3560: }
1.945 raeburn 3561: my @currhidden = keys(%lasthidden);
1.596 albertel 3562: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3563: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3564: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3565: if (%typeparts) {
3566: my $hidden;
3567: foreach my $id (@currhidden) {
3568: if ($key =~ /^\Q$id\E/) {
3569: $hidden = 1;
3570: last;
3571: }
3572: }
3573: if ($hidden) {
3574: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3575: if (($data eq 'award') || ($data eq 'awarddetail')) {
3576: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3577: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3578: $value = &$gradesub($value);
3579: }
3580: $prevattempts.='<td>'.$value.' </td>';
3581: } else {
3582: $prevattempts.='<td> </td>';
3583: }
3584: } else {
3585: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3586: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3587: $value = &$gradesub($value);
3588: }
3589: $prevattempts.='<td>'.$value.' </td>';
3590: }
3591: } else {
3592: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3593: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3594: $value = &$gradesub($value);
3595: }
3596: $prevattempts.='<td>'.$value.' </td>';
3597: }
1.16 harris41 3598: }
1.596 albertel 3599: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3600: } else {
1.596 albertel 3601: $prevattempts=
3602: &start_data_table().&start_data_table_row().
3603: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3604: &end_data_table_row().&end_data_table();
1.1 albertel 3605: }
3606: } else {
1.596 albertel 3607: $prevattempts=
3608: &start_data_table().&start_data_table_row().
3609: '<td>'.&mt('No data.').'</td>'.
3610: &end_data_table_row().&end_data_table();
1.1 albertel 3611: }
1.10 albertel 3612: }
3613:
1.581 albertel 3614: sub format_previous_attempt_value {
3615: my ($key,$value) = @_;
3616: if ($key =~ /timestamp/) {
3617: $value = &Apache::lonlocal::locallocaltime($value);
3618: } elsif (ref($value) eq 'ARRAY') {
3619: $value = '('.join(', ', @{ $value }).')';
1.948.2.14 raeburn 3620: } elsif ($key =~ /answerstring$/) {
3621: my %answers = &Apache::lonnet::str2hash($value);
3622: my @anskeys = sort(keys(%answers));
3623: if (@anskeys == 1) {
3624: my $answer = $answers{$anskeys[0]};
1.948.2.27 raeburn 3625: if ($answer =~ m{\0}) {
3626: $answer =~ s{\0}{,}g;
1.948.2.14 raeburn 3627: }
3628: my $tag_internal_answer_name = 'INTERNAL';
3629: if ($anskeys[0] eq $tag_internal_answer_name) {
3630: $value = $answer;
3631: } else {
3632: $value = $anskeys[0].'='.$answer;
3633: }
3634: } else {
3635: foreach my $ans (@anskeys) {
3636: my $answer = $answers{$ans};
1.948.2.27 raeburn 3637: if ($answer =~ m{\0}) {
3638: $answer =~ s{\0}{,}g;
1.948.2.14 raeburn 3639: }
3640: $value .= $ans.'='.$answer.'<br />';;
3641: }
3642: }
1.581 albertel 3643: } else {
3644: $value = &unescape($value);
3645: }
3646: return $value;
3647: }
3648:
3649:
1.107 albertel 3650: sub relative_to_absolute {
3651: my ($url,$output)=@_;
3652: my $parser=HTML::TokeParser->new(\$output);
3653: my $token;
3654: my $thisdir=$url;
3655: my @rlinks=();
3656: while ($token=$parser->get_token) {
3657: if ($token->[0] eq 'S') {
3658: if ($token->[1] eq 'a') {
3659: if ($token->[2]->{'href'}) {
3660: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3661: }
3662: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3663: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3664: } elsif ($token->[1] eq 'base') {
3665: $thisdir=$token->[2]->{'href'};
3666: }
3667: }
3668: }
3669: $thisdir=~s-/[^/]*$--;
1.356 albertel 3670: foreach my $link (@rlinks) {
1.726 raeburn 3671: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3672: ($link=~/^\//) ||
3673: ($link=~/^javascript:/i) ||
3674: ($link=~/^mailto:/i) ||
3675: ($link=~/^\#/)) {
3676: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3677: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3678: }
3679: }
3680: # -------------------------------------------------- Deal with Applet codebases
3681: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3682: return $output;
3683: }
3684:
1.112 bowersj2 3685: =pod
3686:
1.648 raeburn 3687: =item * &get_student_view()
1.112 bowersj2 3688:
3689: show a snapshot of what student was looking at
3690:
3691: =cut
3692:
1.10 albertel 3693: sub get_student_view {
1.186 albertel 3694: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3695: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3696: my (%form);
1.10 albertel 3697: my @elements=('symb','courseid','domain','username');
3698: foreach my $element (@elements) {
1.186 albertel 3699: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3700: }
1.186 albertel 3701: if (defined($moreenv)) {
3702: %form=(%form,%{$moreenv});
3703: }
1.236 albertel 3704: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3705: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3706: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3707: $userview=~s/\<body[^\>]*\>//gi;
3708: $userview=~s/\<\/body\>//gi;
3709: $userview=~s/\<html\>//gi;
3710: $userview=~s/\<\/html\>//gi;
3711: $userview=~s/\<head\>//gi;
3712: $userview=~s/\<\/head\>//gi;
3713: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3714: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3715: if (wantarray) {
3716: return ($userview,$response);
3717: } else {
3718: return $userview;
3719: }
3720: }
3721:
3722: sub get_student_view_with_retries {
3723: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3724:
3725: my $ok = 0; # True if we got a good response.
3726: my $content;
3727: my $response;
3728:
3729: # Try to get the student_view done. within the retries count:
3730:
3731: do {
3732: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3733: $ok = $response->is_success;
3734: if (!$ok) {
3735: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3736: }
3737: $retries--;
3738: } while (!$ok && ($retries > 0));
3739:
3740: if (!$ok) {
3741: $content = ''; # On error return an empty content.
3742: }
1.651 www 3743: if (wantarray) {
3744: return ($content, $response);
3745: } else {
3746: return $content;
3747: }
1.11 albertel 3748: }
3749:
1.112 bowersj2 3750: =pod
3751:
1.648 raeburn 3752: =item * &get_student_answers()
1.112 bowersj2 3753:
3754: show a snapshot of how student was answering problem
3755:
3756: =cut
3757:
1.11 albertel 3758: sub get_student_answers {
1.100 sakharuk 3759: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3760: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3761: my (%moreenv);
1.11 albertel 3762: my @elements=('symb','courseid','domain','username');
3763: foreach my $element (@elements) {
1.186 albertel 3764: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3765: }
1.186 albertel 3766: $moreenv{'grade_target'}='answer';
3767: %moreenv=(%form,%moreenv);
1.497 raeburn 3768: $feedurl = &Apache::lonnet::clutter($feedurl);
3769: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3770: return $userview;
1.1 albertel 3771: }
1.116 albertel 3772:
3773: =pod
3774:
3775: =item * &submlink()
3776:
1.242 albertel 3777: Inputs: $text $uname $udom $symb $target
1.116 albertel 3778:
3779: Returns: A link to grades.pm such as to see the SUBM view of a student
3780:
3781: =cut
3782:
3783: ###############################################
3784: sub submlink {
1.242 albertel 3785: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3786: if (!($uname && $udom)) {
3787: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3788: &Apache::lonnet::whichuser($symb);
1.116 albertel 3789: if (!$symb) { $symb=$cursymb; }
3790: }
1.254 matthew 3791: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3792: $symb=&escape($symb);
1.948.2.4 raeburn 3793: if ($target) { $target=" target=\"$target\""; }
3794: return
3795: '<a href="/adm/grades?command=submission'.
3796: '&symb='.$symb.
3797: '&student='.$uname.
3798: '&userdom='.$udom.'"'.
3799: $target.'>'.$text.'</a>';
1.242 albertel 3800: }
3801: ##############################################
3802:
3803: =pod
3804:
3805: =item * &pgrdlink()
3806:
3807: Inputs: $text $uname $udom $symb $target
3808:
3809: Returns: A link to grades.pm such as to see the PGRD view of a student
3810:
3811: =cut
3812:
3813: ###############################################
3814: sub pgrdlink {
3815: my $link=&submlink(@_);
3816: $link=~s/(&command=submission)/$1&showgrading=yes/;
3817: return $link;
3818: }
3819: ##############################################
3820:
3821: =pod
3822:
3823: =item * &pprmlink()
3824:
3825: Inputs: $text $uname $udom $symb $target
3826:
3827: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3828: student and a specific resource
1.242 albertel 3829:
3830: =cut
3831:
3832: ###############################################
3833: sub pprmlink {
3834: my ($text,$uname,$udom,$symb,$target)=@_;
3835: if (!($uname && $udom)) {
3836: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3837: &Apache::lonnet::whichuser($symb);
1.242 albertel 3838: if (!$symb) { $symb=$cursymb; }
3839: }
1.254 matthew 3840: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3841: $symb=&escape($symb);
1.242 albertel 3842: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3843: return '<a href="/adm/parmset?command=set&'.
3844: 'symb='.$symb.'&uname='.$uname.
3845: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3846: }
3847: ##############################################
1.37 matthew 3848:
1.112 bowersj2 3849: =pod
3850:
3851: =back
3852:
3853: =cut
3854:
1.37 matthew 3855: ###############################################
1.51 www 3856:
3857:
3858: sub timehash {
1.687 raeburn 3859: my ($thistime) = @_;
3860: my $timezone = &Apache::lonlocal::gettimezone();
3861: my $dt = DateTime->from_epoch(epoch => $thistime)
3862: ->set_time_zone($timezone);
3863: my $wday = $dt->day_of_week();
3864: if ($wday == 7) { $wday = 0; }
3865: return ( 'second' => $dt->second(),
3866: 'minute' => $dt->minute(),
3867: 'hour' => $dt->hour(),
3868: 'day' => $dt->day_of_month(),
3869: 'month' => $dt->month(),
3870: 'year' => $dt->year(),
3871: 'weekday' => $wday,
3872: 'dayyear' => $dt->day_of_year(),
3873: 'dlsav' => $dt->is_dst() );
1.51 www 3874: }
3875:
1.370 www 3876: sub utc_string {
3877: my ($date)=@_;
1.371 www 3878: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3879: }
3880:
1.51 www 3881: sub maketime {
3882: my %th=@_;
1.687 raeburn 3883: my ($epoch_time,$timezone,$dt);
3884: $timezone = &Apache::lonlocal::gettimezone();
3885: eval {
3886: $dt = DateTime->new( year => $th{'year'},
3887: month => $th{'month'},
3888: day => $th{'day'},
3889: hour => $th{'hour'},
3890: minute => $th{'minute'},
3891: second => $th{'second'},
3892: time_zone => $timezone,
3893: );
3894: };
3895: if (!$@) {
3896: $epoch_time = $dt->epoch;
3897: if ($epoch_time) {
3898: return $epoch_time;
3899: }
3900: }
1.51 www 3901: return POSIX::mktime(
3902: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3903: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3904: }
3905:
3906: #########################################
1.51 www 3907:
3908: sub findallcourses {
1.482 raeburn 3909: my ($roles,$uname,$udom) = @_;
1.355 albertel 3910: my %roles;
3911: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3912: my %courses;
1.51 www 3913: my $now=time;
1.482 raeburn 3914: if (!defined($uname)) {
3915: $uname = $env{'user.name'};
3916: }
3917: if (!defined($udom)) {
3918: $udom = $env{'user.domain'};
3919: }
3920: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.948.2.11 raeburn 3921: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3922: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3923: $extra);
1.482 raeburn 3924: if (!%roles) {
3925: %roles = (
3926: cc => 1,
1.907 raeburn 3927: co => 1,
1.482 raeburn 3928: in => 1,
3929: ep => 1,
3930: ta => 1,
3931: cr => 1,
3932: st => 1,
3933: );
3934: }
3935: foreach my $entry (keys(%roleshash)) {
3936: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3937: if ($trole =~ /^cr/) {
3938: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3939: } else {
3940: next if (!exists($roles{$trole}));
3941: }
3942: if ($tend) {
3943: next if ($tend < $now);
3944: }
3945: if ($tstart) {
3946: next if ($tstart > $now);
3947: }
3948: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3949: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3950: if ($secpart eq '') {
3951: ($cnum,$role) = split(/_/,$cnumpart);
3952: $sec = 'none';
3953: $realsec = '';
3954: } else {
3955: $cnum = $cnumpart;
3956: ($sec,$role) = split(/_/,$secpart);
3957: $realsec = $sec;
1.490 raeburn 3958: }
1.482 raeburn 3959: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3960: }
3961: } else {
3962: foreach my $key (keys(%env)) {
1.483 albertel 3963: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3964: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3965: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3966: next if ($role eq 'ca' || $role eq 'aa');
3967: next if (%roles && !exists($roles{$role}));
3968: my ($starttime,$endtime)=split(/\./,$env{$key});
3969: my $active=1;
3970: if ($starttime) {
3971: if ($now<$starttime) { $active=0; }
3972: }
3973: if ($endtime) {
3974: if ($now>$endtime) { $active=0; }
3975: }
3976: if ($active) {
3977: if ($sec eq '') {
3978: $sec = 'none';
3979: }
3980: $courses{$cdom.'_'.$cnum}{$sec} =
3981: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3982: }
3983: }
1.51 www 3984: }
3985: }
1.474 raeburn 3986: return %courses;
1.51 www 3987: }
1.37 matthew 3988:
1.54 www 3989: ###############################################
1.474 raeburn 3990:
3991: sub blockcheck {
1.482 raeburn 3992: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3993:
3994: if (!defined($udom)) {
3995: $udom = $env{'user.domain'};
3996: }
3997: if (!defined($uname)) {
3998: $uname = $env{'user.name'};
3999: }
4000:
4001: # If uname and udom are for a course, check for blocks in the course.
4002:
4003: if (&Apache::lonnet::is_course($udom,$uname)) {
4004: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 4005: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 4006: return ($startblock,$endblock);
4007: }
1.474 raeburn 4008:
1.502 raeburn 4009: my $startblock = 0;
4010: my $endblock = 0;
1.482 raeburn 4011: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4012:
1.490 raeburn 4013: # If uname is for a user, and activity is course-specific, i.e.,
4014: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4015:
1.490 raeburn 4016: if (($activity eq 'boards' || $activity eq 'chat' ||
4017: $activity eq 'groups') && ($env{'request.course.id'})) {
4018: foreach my $key (keys(%live_courses)) {
4019: if ($key ne $env{'request.course.id'}) {
4020: delete($live_courses{$key});
4021: }
4022: }
4023: }
4024:
4025: my $otheruser = 0;
4026: my %own_courses;
4027: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4028: # Resource belongs to user other than current user.
4029: $otheruser = 1;
4030: # Gather courses for current user
4031: %own_courses =
4032: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4033: }
4034:
4035: # Gather active course roles - course coordinator, instructor,
4036: # exam proctor, ta, student, or custom role.
1.474 raeburn 4037:
4038: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4039: my ($cdom,$cnum);
4040: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4041: $cdom = $env{'course.'.$course.'.domain'};
4042: $cnum = $env{'course.'.$course.'.num'};
4043: } else {
1.490 raeburn 4044: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4045: }
4046: my $no_ownblock = 0;
4047: my $no_userblock = 0;
1.533 raeburn 4048: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4049: # Check if current user has 'evb' priv for this
4050: if (defined($own_courses{$course})) {
4051: foreach my $sec (keys(%{$own_courses{$course}})) {
4052: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4053: if ($sec ne 'none') {
4054: $checkrole .= '/'.$sec;
4055: }
4056: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4057: $no_ownblock = 1;
4058: last;
4059: }
4060: }
4061: }
4062: # if they have 'evb' priv and are currently not playing student
4063: next if (($no_ownblock) &&
4064: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4065: }
1.474 raeburn 4066: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4067: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4068: if ($sec ne 'none') {
1.482 raeburn 4069: $checkrole .= '/'.$sec;
1.474 raeburn 4070: }
1.490 raeburn 4071: if ($otheruser) {
4072: # Resource belongs to user other than current user.
4073: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 4074: my ($trole,$tdom,$tnum,$tsec);
4075: my $entry = $live_courses{$course}{$sec};
4076: if ($entry =~ /^cr/) {
4077: ($trole,$tdom,$tnum,$tsec) =
4078: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4079: } else {
4080: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4081: }
4082: my ($spec,$area,$trest,%allroles,%userroles);
4083: $area = '/'.$tdom.'/'.$tnum;
4084: $trest = $tnum;
4085: if ($tsec ne '') {
4086: $area .= '/'.$tsec;
4087: $trest .= '/'.$tsec;
4088: }
4089: $spec = $trole.'.'.$area;
4090: if ($trole =~ /^cr/) {
4091: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4092: $tdom,$spec,$trest,$area);
4093: } else {
4094: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4095: $tdom,$spec,$trest,$area);
4096: }
4097: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4098: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4099: if ($1) {
4100: $no_userblock = 1;
4101: last;
4102: }
4103: }
1.490 raeburn 4104: } else {
4105: # Resource belongs to current user
4106: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4107: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4108: $no_ownblock = 1;
4109: last;
4110: }
1.474 raeburn 4111: }
4112: }
4113: # if they have the evb priv and are currently not playing student
1.482 raeburn 4114: next if (($no_ownblock) &&
1.491 albertel 4115: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4116: next if ($no_userblock);
1.474 raeburn 4117:
1.866 kalberla 4118: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4119: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4120:
4121: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4122: if (($start != 0) &&
4123: (($startblock == 0) || ($startblock > $start))) {
4124: $startblock = $start;
4125: }
4126: if (($end != 0) &&
4127: (($endblock == 0) || ($endblock < $end))) {
4128: $endblock = $end;
4129: }
1.490 raeburn 4130: }
4131: return ($startblock,$endblock);
4132: }
4133:
4134: sub get_blocks {
4135: my ($setters,$activity,$cdom,$cnum) = @_;
4136: my $startblock = 0;
4137: my $endblock = 0;
4138: my $course = $cdom.'_'.$cnum;
4139: $setters->{$course} = {};
4140: $setters->{$course}{'staff'} = [];
4141: $setters->{$course}{'times'} = [];
4142: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4143: foreach my $record (keys(%records)) {
4144: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4145: if ($start <= time && $end >= time) {
4146: my ($staff_name,$staff_dom,$title,$blocks) =
4147: &parse_block_record($records{$record});
4148: if ($blocks->{$activity} eq 'on') {
4149: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4150: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4151: if ( ($startblock == 0) || ($startblock > $start) ) {
4152: $startblock = $start;
1.490 raeburn 4153: }
1.491 albertel 4154: if ( ($endblock == 0) || ($endblock < $end) ) {
4155: $endblock = $end;
1.474 raeburn 4156: }
4157: }
4158: }
4159: }
4160: return ($startblock,$endblock);
4161: }
4162:
4163: sub parse_block_record {
4164: my ($record) = @_;
4165: my ($setuname,$setudom,$title,$blocks);
4166: if (ref($record) eq 'HASH') {
4167: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4168: $title = &unescape($record->{'event'});
4169: $blocks = $record->{'blocks'};
4170: } else {
4171: my @data = split(/:/,$record,3);
4172: if (scalar(@data) eq 2) {
4173: $title = $data[1];
4174: ($setuname,$setudom) = split(/@/,$data[0]);
4175: } else {
4176: ($setuname,$setudom,$title) = @data;
4177: }
4178: $blocks = { 'com' => 'on' };
4179: }
4180: return ($setuname,$setudom,$title,$blocks);
4181: }
4182:
1.854 kalberla 4183: sub blocking_status {
4184: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4185: my %setters;
1.890 droeschl 4186:
4187: # check for active blocking
1.867 kalberla 4188: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4189:
1.890 droeschl 4190: my $blocked = $startblock && $endblock ? 1 : 0;
4191:
4192: # caller just wants to know whether a block is active
4193: if (!wantarray) { return $blocked; }
4194:
4195: # build a link to a popup window containing the details
4196: my $querystring = "?activity=$activity";
4197: # $uname and $udom decide whose portfolio the user is trying to look at
4198: $querystring .= "&udom=$udom" if $udom;
4199: $querystring .= "&uname=$uname" if $uname;
4200:
4201: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4202: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4203: var options = "width=" + w + ",height=" + h + ",";
4204: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4205: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4206: var newWin = window.open(url, wdwName, options);
4207: newWin.focus();
4208: }
1.890 droeschl 4209: END_MYBLOCK
1.854 kalberla 4210:
1.890 droeschl 4211: $output = Apache::lonhtmlcommon::scripttag($output);
4212:
1.854 kalberla 4213: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4214: my $text = mt('Communication Blocked');
4215:
1.867 kalberla 4216: $output .= <<"END_BLOCK";
4217: <div class='LC_comblock'>
1.869 kalberla 4218: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4219: title='$text'>
4220: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4221: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4222: title='$text'>$text</a>
1.867 kalberla 4223: </div>
4224:
4225: END_BLOCK
1.474 raeburn 4226:
1.854 kalberla 4227: return ($blocked, $output);
4228: }
1.490 raeburn 4229:
1.60 matthew 4230: ###############################################
4231:
1.682 raeburn 4232: sub check_ip_acc {
4233: my ($acc)=@_;
4234: &Apache::lonxml::debug("acc is $acc");
4235: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4236: return 1;
4237: }
4238: my $allowed=0;
4239: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4240:
4241: my $name;
4242: foreach my $pattern (split(',',$acc)) {
4243: $pattern =~ s/^\s*//;
4244: $pattern =~ s/\s*$//;
4245: if ($pattern =~ /\*$/) {
4246: #35.8.*
4247: $pattern=~s/\*//;
4248: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4249: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4250: #35.8.3.[34-56]
4251: my $low=$2;
4252: my $high=$3;
4253: $pattern=$1;
4254: if ($ip =~ /^\Q$pattern\E/) {
4255: my $last=(split(/\./,$ip))[3];
4256: if ($last <=$high && $last >=$low) { $allowed=1; }
4257: }
4258: } elsif ($pattern =~ /^\*/) {
4259: #*.msu.edu
4260: $pattern=~s/\*//;
4261: if (!defined($name)) {
4262: use Socket;
4263: my $netaddr=inet_aton($ip);
4264: ($name)=gethostbyaddr($netaddr,AF_INET);
4265: }
4266: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4267: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4268: #127.0.0.1
4269: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4270: } else {
4271: #some.name.com
4272: if (!defined($name)) {
4273: use Socket;
4274: my $netaddr=inet_aton($ip);
4275: ($name)=gethostbyaddr($netaddr,AF_INET);
4276: }
4277: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4278: }
4279: if ($allowed) { last; }
4280: }
4281: return $allowed;
4282: }
4283:
4284: ###############################################
4285:
1.60 matthew 4286: =pod
4287:
1.112 bowersj2 4288: =head1 Domain Template Functions
4289:
4290: =over 4
4291:
4292: =item * &determinedomain()
1.60 matthew 4293:
4294: Inputs: $domain (usually will be undef)
4295:
1.63 www 4296: Returns: Determines which domain should be used for designs
1.60 matthew 4297:
4298: =cut
1.54 www 4299:
1.60 matthew 4300: ###############################################
1.63 www 4301: sub determinedomain {
4302: my $domain=shift;
1.531 albertel 4303: if (! $domain) {
1.60 matthew 4304: # Determine domain if we have not been given one
1.893 raeburn 4305: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4306: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4307: if ($env{'request.role.domain'}) {
4308: $domain=$env{'request.role.domain'};
1.60 matthew 4309: }
4310: }
1.63 www 4311: return $domain;
4312: }
4313: ###############################################
1.517 raeburn 4314:
1.518 albertel 4315: sub devalidate_domconfig_cache {
4316: my ($udom)=@_;
4317: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4318: }
4319:
4320: # ---------------------- Get domain configuration for a domain
4321: sub get_domainconf {
4322: my ($udom) = @_;
4323: my $cachetime=1800;
4324: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4325: if (defined($cached)) { return %{$result}; }
4326:
4327: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4328: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4329: my (%designhash,%legacy);
1.518 albertel 4330: if (keys(%domconfig) > 0) {
4331: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4332: if (keys(%{$domconfig{'login'}})) {
4333: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4334: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4335: if ($key eq 'loginvia') {
4336: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.948.2.30 raeburn 4337: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4338: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4339: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4340: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4341: $designhash{$udom.'.login.loginvia'} = $server;
4342: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4343:
4344: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4345: } else {
1.948.2.30 raeburn 4346: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4347: }
4348: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4349: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4350: }
1.946 raeburn 4351: }
4352: }
4353: }
4354: }
4355: } else {
4356: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4357: $designhash{$udom.'.login.'.$key.'_'.$img} =
4358: $domconfig{'login'}{$key}{$img};
4359: }
1.699 raeburn 4360: }
4361: } else {
4362: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4363: }
1.632 raeburn 4364: }
4365: } else {
4366: $legacy{'login'} = 1;
1.518 albertel 4367: }
1.632 raeburn 4368: } else {
4369: $legacy{'login'} = 1;
1.518 albertel 4370: }
4371: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4372: if (keys(%{$domconfig{'rolecolors'}})) {
4373: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4374: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4375: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4376: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4377: }
1.518 albertel 4378: }
4379: }
1.632 raeburn 4380: } else {
4381: $legacy{'rolecolors'} = 1;
1.518 albertel 4382: }
1.632 raeburn 4383: } else {
4384: $legacy{'rolecolors'} = 1;
1.518 albertel 4385: }
1.948 raeburn 4386: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4387: if ($domconfig{'autoenroll'}{'co-owners'}) {
4388: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4389: }
4390: }
1.632 raeburn 4391: if (keys(%legacy) > 0) {
4392: my %legacyhash = &get_legacy_domconf($udom);
4393: foreach my $item (keys(%legacyhash)) {
4394: if ($item =~ /^\Q$udom\E\.login/) {
4395: if ($legacy{'login'}) {
4396: $designhash{$item} = $legacyhash{$item};
4397: }
4398: } else {
4399: if ($legacy{'rolecolors'}) {
4400: $designhash{$item} = $legacyhash{$item};
4401: }
1.518 albertel 4402: }
4403: }
4404: }
1.632 raeburn 4405: } else {
4406: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4407: }
4408: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4409: $cachetime);
4410: return %designhash;
4411: }
4412:
1.632 raeburn 4413: sub get_legacy_domconf {
4414: my ($udom) = @_;
4415: my %legacyhash;
4416: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4417: my $designfile = $designdir.'/'.$udom.'.tab';
4418: if (-e $designfile) {
4419: if ( open (my $fh,"<$designfile") ) {
4420: while (my $line = <$fh>) {
4421: next if ($line =~ /^\#/);
4422: chomp($line);
4423: my ($key,$val)=(split(/\=/,$line));
4424: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4425: }
4426: close($fh);
4427: }
4428: }
4429: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4430: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4431: }
4432: return %legacyhash;
4433: }
4434:
1.63 www 4435: =pod
4436:
1.112 bowersj2 4437: =item * &domainlogo()
1.63 www 4438:
4439: Inputs: $domain (usually will be undef)
4440:
4441: Returns: A link to a domain logo, if the domain logo exists.
4442: If the domain logo does not exist, a description of the domain.
4443:
4444: =cut
1.112 bowersj2 4445:
1.63 www 4446: ###############################################
4447: sub domainlogo {
1.517 raeburn 4448: my $domain = &determinedomain(shift);
1.518 albertel 4449: my %designhash = &get_domainconf($domain);
1.517 raeburn 4450: # See if there is a logo
4451: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4452: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4453: if ($imgsrc =~ m{^/(adm|res)/}) {
4454: if ($imgsrc =~ m{^/res/}) {
4455: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4456: &Apache::lonnet::repcopy($local_name);
4457: }
4458: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4459: }
4460: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4461: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4462: return &Apache::lonnet::domain($domain,'description');
1.59 www 4463: } else {
1.60 matthew 4464: return '';
1.59 www 4465: }
4466: }
1.63 www 4467: ##############################################
4468:
4469: =pod
4470:
1.112 bowersj2 4471: =item * &designparm()
1.63 www 4472:
4473: Inputs: $which parameter; $domain (usually will be undef)
4474:
4475: Returns: value of designparamter $which
4476:
4477: =cut
1.112 bowersj2 4478:
1.397 albertel 4479:
1.400 albertel 4480: ##############################################
1.397 albertel 4481: sub designparm {
4482: my ($which,$domain)=@_;
4483: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4484: return $env{'environment.color.'.$which};
1.96 www 4485: }
1.63 www 4486: $domain=&determinedomain($domain);
1.948.2.31 raeburn 4487: my %domdesign;
4488: unless ($domain eq 'public') {
4489: %domdesign = &get_domainconf($domain);
4490: }
1.520 raeburn 4491: my $output;
1.517 raeburn 4492: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4493: $output = $domdesign{$domain.'.'.$which};
1.63 www 4494: } else {
1.520 raeburn 4495: $output = $defaultdesign{$which};
4496: }
4497: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4498: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4499: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4500: if ($output =~ m{^/res/}) {
4501: my $local_name = &Apache::lonnet::filelocation('',$output);
4502: &Apache::lonnet::repcopy($local_name);
4503: }
1.520 raeburn 4504: $output = &lonhttpdurl($output);
4505: }
1.63 www 4506: }
1.520 raeburn 4507: return $output;
1.63 www 4508: }
1.59 www 4509:
1.822 bisitz 4510: ##############################################
4511: =pod
4512:
1.832 bisitz 4513: =item * &authorspace()
4514:
4515: Inputs: ./.
4516:
4517: Returns: Path to the Construction Space of the current user's
4518: accessed author space
4519: The author space will be that of the current user
4520: when accessing the own author space
4521: and that of the co-author/assistent co-author
4522: when accessing the co-author's/assistent co-author's
4523: space
4524:
4525: =cut
4526:
4527: sub authorspace {
4528: my $caname = '';
4529: if ($env{'request.role'} =~ /^ca|^aa/) {
4530: (undef,$caname) =
4531: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4532: } else {
4533: $caname = $env{'user.name'};
4534: }
4535: return '/priv/'.$caname.'/';
4536: }
4537:
4538: ##############################################
4539: =pod
4540:
1.822 bisitz 4541: =item * &head_subbox()
4542:
4543: Inputs: $content (contains HTML code with page functions, etc.)
4544:
4545: Returns: HTML div with $content
4546: To be included in page header
4547:
4548: =cut
4549:
4550: sub head_subbox {
4551: my ($content)=@_;
4552: my $output =
1.948.2.22 raeburn 4553: '<div class="LC_head_subbox">'
1.822 bisitz 4554: .$content
4555: .'</div>'
4556: }
4557:
4558: ##############################################
4559: =pod
4560:
4561: =item * &CSTR_pageheader()
4562:
1.948.2.33 raeburn 4563: Input: (optional) filename from which breadcrumb trail is built.
4564: In most cases no input is needed, as $env{'request.filename'}
4565: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4566:
4567: Returns: HTML div with CSTR path and recent box
4568: To be included on Construction Space pages
4569:
4570: =cut
4571:
4572: sub CSTR_pageheader {
1.948.2.33 raeburn 4573: my ($trailfile) = @_;
4574: if ($trailfile eq '') {
4575: $trailfile = $env{'request.filename'};
4576: }
4577:
4578: # this is for resources; directories have customtitle, and crumbs
4579: # and select recent are created in lonpubdir.pm
4580:
1.822 bisitz 4581: my ($uname,$thisdisfn)=
1.948.2.33 raeburn 4582: ($trailfile =~ m|^/home/([^/]+)/public_html/(.*)|);
1.822 bisitz 4583: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4584: $formaction=~s/\/+/\//g;
4585:
4586: my $parentpath = '';
4587: my $lastitem = '';
4588: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4589: $parentpath = $1;
4590: $lastitem = $2;
4591: } else {
4592: $lastitem = $thisdisfn;
4593: }
1.921 bisitz 4594:
4595: my $output =
1.822 bisitz 4596: '<div>'
4597: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4598: .'<b>'.&mt('Construction Space:').'</b> '
4599: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4600: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4601: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4602:
4603: if ($lastitem) {
4604: $output .=
4605: '<span class="LC_filename">'
4606: .$lastitem
4607: .'</span>';
4608: }
4609: $output .=
4610: '<br />'
1.822 bisitz 4611: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4612: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4613: .'</form>'
4614: .&Apache::lonmenu::constspaceform()
4615: .'</div>';
1.921 bisitz 4616:
4617: return $output;
1.822 bisitz 4618: }
4619:
1.60 matthew 4620: ###############################################
4621: ###############################################
4622:
4623: =pod
4624:
1.112 bowersj2 4625: =back
4626:
1.549 albertel 4627: =head1 HTML Helpers
1.112 bowersj2 4628:
4629: =over 4
4630:
4631: =item * &bodytag()
1.60 matthew 4632:
4633: Returns a uniform header for LON-CAPA web pages.
4634:
4635: Inputs:
4636:
1.112 bowersj2 4637: =over 4
4638:
4639: =item * $title, A title to be displayed on the page.
4640:
4641: =item * $function, the current role (can be undef).
4642:
4643: =item * $addentries, extra parameters for the <body> tag.
4644:
4645: =item * $bodyonly, if defined, only return the <body> tag.
4646:
4647: =item * $domain, if defined, force a given domain.
4648:
4649: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4650: text interface only)
1.60 matthew 4651:
1.814 bisitz 4652: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4653: navigational links
1.317 albertel 4654:
1.338 albertel 4655: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4656:
1.361 albertel 4657: =item * $no_inline_link, if true and in remote mode, don't show the
4658: 'Switch To Inline Menu' link
4659:
1.460 albertel 4660: =item * $args, optional argument valid values are
4661: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4662: inherit_jsmath -> when creating popup window in a page,
4663: should it have jsmath forced on by the
4664: current page
1.460 albertel 4665:
1.112 bowersj2 4666: =back
4667:
1.60 matthew 4668: Returns: A uniform header for LON-CAPA web pages.
4669: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4670: If $bodyonly is undef or zero, an html string containing a <body> tag and
4671: other decorations will be returned.
4672:
4673: =cut
4674:
1.54 www 4675: sub bodytag {
1.831 bisitz 4676: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4677: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4678:
1.948.2.2 raeburn 4679: my $public;
4680: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4681: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4682: $public = 1;
4683: }
1.460 albertel 4684: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4685:
1.183 matthew 4686: $function = &get_users_function() if (!$function);
1.339 albertel 4687: my $img = &designparm($function.'.img',$domain);
4688: my $font = &designparm($function.'.font',$domain);
4689: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4690:
1.803 bisitz 4691: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4692: 'bgcolor' => $pgbg,
1.339 albertel 4693: 'text' => $font,
4694: 'alink' => &designparm($function.'.alink',$domain),
4695: 'vlink' => &designparm($function.'.vlink',$domain),
4696: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4697: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4698:
1.63 www 4699: # role and realm
1.378 raeburn 4700: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4701: if ($role eq 'ca') {
1.479 albertel 4702: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4703: $realm = &plainname($rname,$rdom);
1.378 raeburn 4704: }
1.55 www 4705: # realm
1.258 albertel 4706: if ($env{'request.course.id'}) {
1.378 raeburn 4707: if ($env{'request.role'} !~ /^cr/) {
4708: $role = &Apache::lonnet::plaintext($role,&course_type());
4709: }
1.898 raeburn 4710: if ($env{'request.course.sec'}) {
4711: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4712: }
1.359 albertel 4713: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4714: } else {
4715: $role = &Apache::lonnet::plaintext($role);
1.54 www 4716: }
1.433 albertel 4717:
1.359 albertel 4718: if (!$realm) { $realm=' '; }
1.55 www 4719: # Set messages
1.60 matthew 4720: my $messages=&domainlogo($domain);
1.330 albertel 4721:
1.438 albertel 4722: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4723:
1.101 www 4724: # construct main body tag
1.359 albertel 4725: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4726: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4727:
1.530 albertel 4728: if ($bodyonly) {
1.60 matthew 4729: return $bodytag;
1.798 tempelho 4730: }
1.359 albertel 4731:
1.410 albertel 4732: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.948.2.2 raeburn 4733: if ($public) {
1.433 albertel 4734: undef($role);
1.434 albertel 4735: } else {
4736: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4737: }
1.948.2.2 raeburn 4738:
1.762 bisitz 4739: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4740: #
4741: # Extra info if you are the DC
4742: my $dc_info = '';
4743: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4744: $env{'course.'.$env{'request.course.id'}.
4745: '.domain'}.'/'})) {
4746: my $cid = $env{'request.course.id'};
1.917 raeburn 4747: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4748: $dc_info =~ s/\s+$//;
1.359 albertel 4749: }
4750:
1.898 raeburn 4751: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4752: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4753:
1.948.2.19 raeburn 4754: if ($env{'environment.remote'} ne 'on') {
1.359 albertel 4755: # No Remote
1.916 droeschl 4756: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
1.948.2.19 raeburn 4757: return $bodytag;
4758: }
1.903 droeschl 4759:
4760: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4761:
4762: # if ($env{'request.state'} eq 'construct') {
4763: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4764: # }
4765:
1.359 albertel 4766:
4767:
1.916 droeschl 4768: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4769: if ($dc_info) {
4770: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4771: }
1.916 droeschl 4772: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4773: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4774: return $bodytag;
4775: }
1.948.2.19 raeburn 4776: if (($env{'request.noversionuri'} =~ m{^/adm/navmaps}) &&
4777: ($env{'environment.remotenavmap'} eq 'on')) {
4778: return $bodytag;
4779: }
1.894 droeschl 4780:
1.927 raeburn 4781: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4782: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4783: }
1.916 droeschl 4784:
1.903 droeschl 4785: $bodytag .= Apache::lonhtmlcommon::scripttag(
4786: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4787:
1.903 droeschl 4788: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4789:
1.917 raeburn 4790: if ($dc_info) {
4791: $dc_info = &dc_courseid_toggle($dc_info);
4792: }
4793: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4794:
1.903 droeschl 4795: #don't show menus for public users
1.948.2.2 raeburn 4796: if (!$public){
1.903 droeschl 4797: $bodytag .= Apache::lonmenu::secondary_menu();
4798: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4799: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4800: if ($env{'request.state'} eq 'construct') {
4801: $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
4802: $args->{'bread_crumbs'});
4803: } elsif ($forcereg) {
4804: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4805: }
1.903 droeschl 4806: }else{
4807: # this is to seperate menu from content when there's no secondary
4808: # menu. Especially needed for public accessible ressources.
4809: $bodytag .= '<hr style="clear:both" />';
4810: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4811: }
1.903 droeschl 4812:
1.235 raeburn 4813: return $bodytag;
1.94 www 4814: }
1.95 www 4815:
1.93 www 4816: #
1.95 www 4817: # Top frame rendering, Remote is up
1.93 www 4818: #
1.359 albertel 4819:
1.517 raeburn 4820: my $imgsrc = $img;
4821: if ($img =~ /^\/adm/) {
1.575 albertel 4822: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4823: }
4824: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4825:
1.305 www 4826: # Explicit link to get inline menu
1.361 albertel 4827: my $menu= ($no_inline_link?''
1.883 droeschl 4828: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917 raeburn 4829:
4830: if ($dc_info) {
4831: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
4832: }
4833:
1.948.2.25 raeburn 4834: unless ($env{'form.inhibitmenu'}) {
4835: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
4836: <ol class="LC_primary_menu LC_right">
4837: <li>$menu</li>
4838: </ol><div id="LC_realm"> $realm $dc_info</div>|;
4839: }
4840:
1.94 www 4841: return(<<ENDBODY);
1.60 matthew 4842: $bodytag
1.359 albertel 4843: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4844: <tr><td>$upperleft</td>
4845: <td>$messages </td>
1.54 www 4846: </tr>
1.359 albertel 4847: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4848: </tr>
1.356 albertel 4849: </table>
1.54 www 4850: ENDBODY
1.182 matthew 4851: }
4852:
1.917 raeburn 4853: sub dc_courseid_toggle {
4854: my ($dc_info) = @_;
1.948.2.10 raeburn 4855: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4856: '<a href="javascript:showCourseID();">'.
4857: &mt('(More ...)').'</a></span>'.
4858: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4859: }
4860:
1.330 albertel 4861: sub make_attr_string {
4862: my ($register,$attr_ref) = @_;
4863:
4864: if ($attr_ref && !ref($attr_ref)) {
4865: die("addentries Must be a hash ref ".
4866: join(':',caller(1))." ".
4867: join(':',caller(0))." ");
4868: }
4869:
4870: if ($register) {
1.339 albertel 4871: my ($on_load,$on_unload);
4872: foreach my $key (keys(%{$attr_ref})) {
4873: if (lc($key) eq 'onload') {
4874: $on_load.=$attr_ref->{$key}.';';
4875: delete($attr_ref->{$key});
4876:
4877: } elsif (lc($key) eq 'onunload') {
4878: $on_unload.=$attr_ref->{$key}.';';
4879: delete($attr_ref->{$key});
4880: }
4881: }
4882: $attr_ref->{'onload'} =
4883: &Apache::lonmenu::loadevents(). $on_load;
4884: $attr_ref->{'onunload'}=
4885: &Apache::lonmenu::unloadevents().$on_unload;
4886: }
4887:
4888: # Accessibility font enhance
4889: if ($env{'browser.fontenhance'} eq 'on') {
4890: my $style;
4891: foreach my $key (keys(%{$attr_ref})) {
4892: if (lc($key) eq 'style') {
4893: $style.=$attr_ref->{$key}.';';
4894: delete($attr_ref->{$key});
4895: }
4896: }
4897: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4898: }
1.339 albertel 4899:
1.330 albertel 4900: my $attr_string;
4901: foreach my $attr (keys(%$attr_ref)) {
4902: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4903: }
4904: return $attr_string;
4905: }
4906:
4907:
1.182 matthew 4908: ###############################################
1.251 albertel 4909: ###############################################
4910:
4911: =pod
4912:
4913: =item * &endbodytag()
4914:
4915: Returns a uniform footer for LON-CAPA web pages.
4916:
1.635 raeburn 4917: Inputs: 1 - optional reference to an args hash
4918: If in the hash, key for noredirectlink has a value which evaluates to true,
4919: a 'Continue' link is not displayed if the page contains an
4920: internal redirect in the <head></head> section,
4921: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4922:
4923: =cut
4924:
4925: sub endbodytag {
1.635 raeburn 4926: my ($args) = @_;
1.251 albertel 4927: my $endbodytag='</body>';
1.269 albertel 4928: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4929: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4930: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4931: $endbodytag=
4932: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4933: &mt('Continue').'</a>'.
4934: $endbodytag;
4935: }
1.315 albertel 4936: }
1.251 albertel 4937: return $endbodytag;
4938: }
4939:
1.352 albertel 4940: =pod
4941:
4942: =item * &standard_css()
4943:
4944: Returns a style sheet
4945:
4946: Inputs: (all optional)
4947: domain -> force to color decorate a page for a specific
4948: domain
4949: function -> force usage of a specific rolish color scheme
4950: bgcolor -> override the default page bgcolor
4951:
4952: =cut
4953:
1.343 albertel 4954: sub standard_css {
1.345 albertel 4955: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4956: $function = &get_users_function() if (!$function);
4957: my $img = &designparm($function.'.img', $domain);
4958: my $tabbg = &designparm($function.'.tabbg', $domain);
4959: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4960: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4961: #second colour for later usage
1.345 albertel 4962: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4963: my $pgbg_or_bgcolor =
4964: $bgcolor ||
1.352 albertel 4965: &designparm($function.'.pgbg', $domain);
1.382 albertel 4966: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4967: my $alink = &designparm($function.'.alink', $domain);
4968: my $vlink = &designparm($function.'.vlink', $domain);
4969: my $link = &designparm($function.'.link', $domain);
4970:
1.602 albertel 4971: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4972: my $mono = 'monospace';
1.850 bisitz 4973: my $data_table_head = $sidebg;
4974: my $data_table_light = '#FAFAFA';
4975: my $data_table_dark = '#F0F0F0';
1.470 banghart 4976: my $data_table_darker = '#CCCCCC';
1.349 albertel 4977: my $data_table_highlight = '#FFFF00';
1.352 albertel 4978: my $mail_new = '#FFBB77';
4979: my $mail_new_hover = '#DD9955';
4980: my $mail_read = '#BBBB77';
4981: my $mail_read_hover = '#999944';
4982: my $mail_replied = '#AAAA88';
4983: my $mail_replied_hover = '#888855';
4984: my $mail_other = '#99BBBB';
4985: my $mail_other_hover = '#669999';
1.391 albertel 4986: my $table_header = '#DDDDDD';
1.489 raeburn 4987: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4988: my $lg_border_color = '#C8C8C8';
1.948.2.1 raeburn 4989: my $button_hover = '#BF2317';
1.392 albertel 4990:
1.608 albertel 4991: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4992: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4993: : '0 3px 0 4px';
1.448 albertel 4994:
1.343 albertel 4995: return <<END;
1.947 droeschl 4996:
4997: /* needed for iframe to allow 100% height in FF */
4998: body, html {
4999: margin: 0;
5000: padding: 0 0.5%;
5001: height: 99%; /* to avoid scrollbars */
5002: }
5003:
1.795 www 5004: body {
1.911 bisitz 5005: font-family: $sans;
5006: line-height:130%;
5007: font-size:0.83em;
5008: color:$font;
1.795 www 5009: }
5010:
1.948.2.9 raeburn 5011: a:focus,
5012: a:focus img {
1.795 www 5013: color: red;
1.911 bisitz 5014: background: yellow;
1.795 www 5015: }
1.698 harmsja 5016:
1.911 bisitz 5017: form, .inline {
5018: display: inline;
1.795 www 5019: }
1.721 harmsja 5020:
1.795 www 5021: .LC_right {
1.911 bisitz 5022: text-align:right;
1.795 www 5023: }
5024:
5025: .LC_middle {
1.911 bisitz 5026: vertical-align:middle;
1.795 www 5027: }
1.721 harmsja 5028:
1.911 bisitz 5029: .LC_400Box {
5030: width:400px;
5031: }
1.721 harmsja 5032:
1.947 droeschl 5033: .LC_iframecontainer {
5034: width: 98%;
5035: margin: 0;
5036: position: fixed;
5037: top: 8.5em;
5038: bottom: 0;
5039: }
5040:
5041: .LC_iframecontainer iframe{
5042: border: none;
5043: width: 100%;
5044: height: 100%;
5045: }
5046:
1.778 bisitz 5047: .LC_filename {
5048: font-family: $mono;
5049: white-space:pre;
1.921 bisitz 5050: font-size: 120%;
1.778 bisitz 5051: }
5052:
5053: .LC_fileicon {
5054: border: none;
5055: height: 1.3em;
5056: vertical-align: text-bottom;
5057: margin-right: 0.3em;
5058: text-decoration:none;
5059: }
5060:
1.350 albertel 5061: .LC_error {
5062: color: red;
5063: font-size: larger;
5064: }
1.795 www 5065:
1.457 albertel 5066: .LC_warning,
5067: .LC_diff_removed {
1.733 bisitz 5068: color: red;
1.394 albertel 5069: }
1.532 albertel 5070:
5071: .LC_info,
1.457 albertel 5072: .LC_success,
5073: .LC_diff_added {
1.350 albertel 5074: color: green;
5075: }
1.795 www 5076:
1.802 bisitz 5077: div.LC_confirm_box {
5078: background-color: #FAFAFA;
5079: border: 1px solid $lg_border_color;
5080: margin-right: 0;
5081: padding: 5px;
5082: }
5083:
5084: div.LC_confirm_box .LC_error img,
5085: div.LC_confirm_box .LC_success img {
5086: vertical-align: middle;
5087: }
5088:
1.440 albertel 5089: .LC_icon {
1.771 droeschl 5090: border: none;
1.790 droeschl 5091: vertical-align: middle;
1.771 droeschl 5092: }
5093:
1.543 albertel 5094: .LC_docs_spacer {
5095: width: 25px;
5096: height: 1px;
1.771 droeschl 5097: border: none;
1.543 albertel 5098: }
1.346 albertel 5099:
1.532 albertel 5100: .LC_internal_info {
1.735 bisitz 5101: color: #999999;
1.532 albertel 5102: }
5103:
1.794 www 5104: .LC_discussion {
1.911 bisitz 5105: background: $tabbg;
5106: border: 1px solid black;
5107: margin: 2px;
1.794 www 5108: }
5109:
5110: .LC_disc_action_links_bar {
1.911 bisitz 5111: background: $tabbg;
5112: border: none;
5113: margin: 4px;
1.794 www 5114: }
5115:
5116: .LC_disc_action_left {
1.911 bisitz 5117: text-align: left;
1.794 www 5118: }
5119:
5120: .LC_disc_action_right {
1.911 bisitz 5121: text-align: right;
1.794 www 5122: }
5123:
5124: .LC_disc_new_item {
1.911 bisitz 5125: background: white;
5126: border: 2px solid red;
5127: margin: 2px;
1.794 www 5128: }
5129:
5130: .LC_disc_old_item {
1.911 bisitz 5131: background: white;
5132: border: 1px solid black;
5133: margin: 2px;
1.794 www 5134: }
5135:
1.458 albertel 5136: table.LC_pastsubmission {
5137: border: 1px solid black;
5138: margin: 2px;
5139: }
5140:
1.924 bisitz 5141: table#LC_menubuttons {
1.345 albertel 5142: width: 100%;
5143: background: $pgbg;
1.392 albertel 5144: border: 2px;
1.402 albertel 5145: border-collapse: separate;
1.803 bisitz 5146: padding: 0;
1.345 albertel 5147: }
1.392 albertel 5148:
1.801 tempelho 5149: table#LC_title_bar a {
5150: color: $fontmenu;
5151: }
1.836 bisitz 5152:
1.807 droeschl 5153: table#LC_title_bar {
1.819 tempelho 5154: clear: both;
1.836 bisitz 5155: display: none;
1.807 droeschl 5156: }
5157:
1.795 www 5158: table#LC_title_bar,
1.933 droeschl 5159: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5160: table#LC_title_bar.LC_with_remote {
1.359 albertel 5161: width: 100%;
1.392 albertel 5162: border-color: $pgbg;
5163: border-style: solid;
5164: border-width: $border;
1.379 albertel 5165: background: $pgbg;
1.801 tempelho 5166: color: $fontmenu;
1.392 albertel 5167: border-collapse: collapse;
1.803 bisitz 5168: padding: 0;
1.819 tempelho 5169: margin: 0;
1.359 albertel 5170: }
1.795 www 5171:
1.933 droeschl 5172: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5173: margin: 0;
5174: padding: 0;
1.933 droeschl 5175: position: relative;
5176: list-style: none;
1.913 droeschl 5177: }
1.933 droeschl 5178: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5179: display: inline;
5180: }
1.933 droeschl 5181:
5182: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5183: padding: 0;
1.933 droeschl 5184: margin: 0;
5185: float: left;
1.913 droeschl 5186: }
1.933 droeschl 5187: .LC_breadcrumb_tools_tools {
5188: padding: 0;
5189: margin: 0;
1.913 droeschl 5190: float: right;
5191: }
5192:
1.359 albertel 5193: table#LC_title_bar td {
5194: background: $tabbg;
5195: }
1.795 www 5196:
1.911 bisitz 5197: table#LC_menubuttons img {
1.803 bisitz 5198: border: none;
1.346 albertel 5199: }
1.795 www 5200:
1.842 droeschl 5201: .LC_breadcrumbs_component {
1.911 bisitz 5202: float: right;
5203: margin: 0 1em;
1.357 albertel 5204: }
1.842 droeschl 5205: .LC_breadcrumbs_component img {
1.911 bisitz 5206: vertical-align: middle;
1.777 tempelho 5207: }
1.795 www 5208:
1.383 albertel 5209: td.LC_table_cell_checkbox {
5210: text-align: center;
5211: }
1.795 www 5212:
5213: .LC_fontsize_small {
1.911 bisitz 5214: font-size: 70%;
1.705 tempelho 5215: }
5216:
1.844 bisitz 5217: #LC_breadcrumbs {
1.911 bisitz 5218: clear:both;
5219: background: $sidebg;
5220: border-bottom: 1px solid $lg_border_color;
5221: line-height: 2.5em;
1.933 droeschl 5222: overflow: hidden;
1.911 bisitz 5223: margin: 0;
5224: padding: 0;
1.948.2.24 raeburn 5225: text-align: left;
1.819 tempelho 5226: }
1.862 bisitz 5227:
1.839 droeschl 5228: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 5229: #LC_remote #LC_breadcrumbs {
1.911 bisitz 5230: display:none;
1.839 droeschl 5231: }
1.819 tempelho 5232:
1.948.2.22 raeburn 5233: .LC_head_subbox {
1.911 bisitz 5234: clear:both;
5235: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5236: border: 1px solid $sidebg;
5237: margin: 0 0 10px 0;
1.948.2.6 raeburn 5238: padding: 3px;
1.948.2.24 raeburn 5239: text-align: left;
1.822 bisitz 5240: }
5241:
1.795 www 5242: .LC_fontsize_medium {
1.911 bisitz 5243: font-size: 85%;
1.705 tempelho 5244: }
5245:
1.795 www 5246: .LC_fontsize_large {
1.911 bisitz 5247: font-size: 120%;
1.705 tempelho 5248: }
5249:
1.346 albertel 5250: .LC_menubuttons_inline_text {
5251: color: $font;
1.698 harmsja 5252: font-size: 90%;
1.701 harmsja 5253: padding-left:3px;
1.346 albertel 5254: }
5255:
1.934 droeschl 5256: .LC_menubuttons_inline_text img{
5257: vertical-align: middle;
5258: }
5259:
1.948.2.1 raeburn 5260: li.LC_menubuttons_inline_text img,a {
5261: cursor:pointer;
1.948.2.27 raeburn 5262: text-decoration: none;
1.948.2.1 raeburn 5263: }
5264:
1.526 www 5265: .LC_menubuttons_link {
5266: text-decoration: none;
5267: }
1.795 www 5268:
1.522 albertel 5269: .LC_menubuttons_category {
1.521 www 5270: color: $font;
1.526 www 5271: background: $pgbg;
1.521 www 5272: font-size: larger;
5273: font-weight: bold;
5274: }
5275:
1.346 albertel 5276: td.LC_menubuttons_text {
1.911 bisitz 5277: color: $font;
1.346 albertel 5278: }
1.706 harmsja 5279:
1.346 albertel 5280: .LC_current_location {
5281: background: $tabbg;
5282: }
1.795 www 5283:
1.938 bisitz 5284: table.LC_data_table {
1.347 albertel 5285: border: 1px solid #000000;
1.402 albertel 5286: border-collapse: separate;
1.426 albertel 5287: border-spacing: 1px;
1.610 albertel 5288: background: $pgbg;
1.347 albertel 5289: }
1.795 www 5290:
1.422 albertel 5291: .LC_data_table_dense {
5292: font-size: small;
5293: }
1.795 www 5294:
1.507 raeburn 5295: table.LC_nested_outer {
5296: border: 1px solid #000000;
1.589 raeburn 5297: border-collapse: collapse;
1.803 bisitz 5298: border-spacing: 0;
1.507 raeburn 5299: width: 100%;
5300: }
1.795 www 5301:
1.879 raeburn 5302: table.LC_innerpickbox,
1.507 raeburn 5303: table.LC_nested {
1.803 bisitz 5304: border: none;
1.589 raeburn 5305: border-collapse: collapse;
1.803 bisitz 5306: border-spacing: 0;
1.507 raeburn 5307: width: 100%;
5308: }
1.795 www 5309:
1.930 faziophi 5310: .ui-accordion,
5311: .ui-accordion table.LC_data_table,
5312: .ui-accordion table.LC_nested_outer{
5313: border: 0px;
5314: border-spacing: 0px;
5315: margin: 3px;
5316: }
5317:
1.911 bisitz 5318: table.LC_data_table tr th,
5319: table.LC_calendar tr th,
1.879 raeburn 5320: table.LC_prior_tries tr th,
5321: table.LC_innerpickbox tr th {
1.349 albertel 5322: font-weight: bold;
5323: background-color: $data_table_head;
1.801 tempelho 5324: color:$fontmenu;
1.701 harmsja 5325: font-size:90%;
1.347 albertel 5326: }
1.795 www 5327:
1.879 raeburn 5328: table.LC_innerpickbox tr th,
5329: table.LC_innerpickbox tr td {
5330: vertical-align: top;
5331: }
5332:
1.711 raeburn 5333: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5334: background-color: #CCCCCC;
1.711 raeburn 5335: font-weight: bold;
5336: text-align: left;
5337: }
1.795 www 5338:
1.912 bisitz 5339: table.LC_data_table tr.LC_odd_row > td {
5340: background-color: $data_table_light;
5341: padding: 2px;
5342: vertical-align: top;
5343: }
5344:
1.809 bisitz 5345: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5346: background-color: $data_table_light;
1.912 bisitz 5347: vertical-align: top;
5348: }
5349:
5350: table.LC_data_table tr.LC_even_row > td {
5351: background-color: $data_table_dark;
1.425 albertel 5352: padding: 2px;
1.900 bisitz 5353: vertical-align: top;
1.347 albertel 5354: }
1.795 www 5355:
1.809 bisitz 5356: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5357: background-color: $data_table_dark;
1.900 bisitz 5358: vertical-align: top;
1.347 albertel 5359: }
1.795 www 5360:
1.425 albertel 5361: table.LC_data_table tr.LC_data_table_highlight td {
5362: background-color: $data_table_darker;
5363: }
1.795 www 5364:
1.639 raeburn 5365: table.LC_data_table tr td.LC_leftcol_header {
5366: background-color: $data_table_head;
5367: font-weight: bold;
5368: }
1.795 www 5369:
1.451 albertel 5370: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5371: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5372: font-weight: bold;
5373: font-style: italic;
5374: text-align: center;
5375: padding: 8px;
1.347 albertel 5376: }
1.795 www 5377:
1.940 bisitz 5378: table.LC_data_table tr.LC_empty_row td {
5379: background-color: $sidebg;
5380: }
5381:
5382: table.LC_nested tr.LC_empty_row td {
5383: background-color: #FFFFFF;
5384: }
5385:
1.890 droeschl 5386: table.LC_caption {
5387: }
5388:
1.507 raeburn 5389: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5390: padding: 4ex
5391: }
1.795 www 5392:
1.507 raeburn 5393: table.LC_nested_outer tr th {
5394: font-weight: bold;
1.801 tempelho 5395: color:$fontmenu;
1.507 raeburn 5396: background-color: $data_table_head;
1.701 harmsja 5397: font-size: small;
1.507 raeburn 5398: border-bottom: 1px solid #000000;
5399: }
1.795 www 5400:
1.507 raeburn 5401: table.LC_nested_outer tr td.LC_subheader {
5402: background-color: $data_table_head;
5403: font-weight: bold;
5404: font-size: small;
5405: border-bottom: 1px solid #000000;
5406: text-align: right;
1.451 albertel 5407: }
1.795 www 5408:
1.507 raeburn 5409: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5410: background-color: #CCCCCC;
1.451 albertel 5411: font-weight: bold;
5412: font-size: small;
1.507 raeburn 5413: text-align: center;
5414: }
1.795 www 5415:
1.589 raeburn 5416: table.LC_nested tr.LC_info_row td.LC_left_item,
5417: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5418: text-align: left;
1.451 albertel 5419: }
1.795 www 5420:
1.507 raeburn 5421: table.LC_nested td {
1.735 bisitz 5422: background-color: #FFFFFF;
1.451 albertel 5423: font-size: small;
1.507 raeburn 5424: }
1.795 www 5425:
1.507 raeburn 5426: table.LC_nested_outer tr th.LC_right_item,
5427: table.LC_nested tr.LC_info_row td.LC_right_item,
5428: table.LC_nested tr.LC_odd_row td.LC_right_item,
5429: table.LC_nested tr td.LC_right_item {
1.451 albertel 5430: text-align: right;
5431: }
5432:
1.930 faziophi 5433: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5434: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5435: text-align: right;
5436: width: 40%;
5437: padding-right:10px;
5438: vertical-align: top;
5439: padding: 5px;
5440: }
5441:
5442: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5443: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5444: text-align: left;
5445: width: 60%;
5446: padding: 2px 4px;
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.948.2.8 raeburn 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:
1.421 albertel 5775: table.LC_notify_front_page {
5776: background: white;
5777: border: 1px solid black;
5778: padding: 8px;
5779: }
1.795 www 5780:
1.421 albertel 5781: table.LC_notify_front_page td {
5782: padding: 8px;
5783: }
1.795 www 5784:
1.424 albertel 5785: .LC_navbuttons {
5786: margin: 2ex 0ex 2ex 0ex;
5787: }
1.795 www 5788:
1.423 albertel 5789: .LC_topic_bar {
5790: font-weight: bold;
5791: background: $tabbg;
1.918 wenzelju 5792: margin: 1em 0em 1em 2em;
1.805 bisitz 5793: padding: 3px;
1.918 wenzelju 5794: font-size: 1.2em;
1.423 albertel 5795: }
1.795 www 5796:
1.423 albertel 5797: .LC_topic_bar span {
1.918 wenzelju 5798: left: 0.5em;
5799: position: absolute;
1.423 albertel 5800: vertical-align: middle;
1.918 wenzelju 5801: font-size: 1.2em;
1.423 albertel 5802: }
1.795 www 5803:
1.423 albertel 5804: table.LC_course_group_status {
5805: margin: 20px;
5806: }
1.795 www 5807:
1.423 albertel 5808: table.LC_status_selector td {
5809: vertical-align: top;
5810: text-align: center;
1.424 albertel 5811: padding: 4px;
5812: }
1.795 www 5813:
1.599 albertel 5814: div.LC_feedback_link {
1.616 albertel 5815: clear: both;
1.829 kalberla 5816: background: $sidebg;
1.779 bisitz 5817: width: 100%;
1.829 kalberla 5818: padding-bottom: 10px;
5819: border: 1px $tabbg solid;
1.833 kalberla 5820: height: 22px;
5821: line-height: 22px;
5822: padding-top: 5px;
5823: }
5824:
5825: div.LC_feedback_link img {
5826: height: 22px;
1.867 kalberla 5827: vertical-align:middle;
1.829 kalberla 5828: }
5829:
1.911 bisitz 5830: div.LC_feedback_link a {
1.829 kalberla 5831: text-decoration: none;
1.489 raeburn 5832: }
1.795 www 5833:
1.867 kalberla 5834: div.LC_comblock {
1.911 bisitz 5835: display:inline;
1.867 kalberla 5836: color:$font;
5837: font-size:90%;
5838: }
5839:
5840: div.LC_feedback_link div.LC_comblock {
5841: padding-left:5px;
5842: }
5843:
5844: div.LC_feedback_link div.LC_comblock a {
5845: color:$font;
5846: }
5847:
1.489 raeburn 5848: span.LC_feedback_link {
1.858 bisitz 5849: /* background: $feedback_link_bg; */
1.599 albertel 5850: font-size: larger;
5851: }
1.795 www 5852:
1.599 albertel 5853: span.LC_message_link {
1.858 bisitz 5854: /* background: $feedback_link_bg; */
1.599 albertel 5855: font-size: larger;
5856: position: absolute;
5857: right: 1em;
1.489 raeburn 5858: }
1.421 albertel 5859:
1.515 albertel 5860: table.LC_prior_tries {
1.524 albertel 5861: border: 1px solid #000000;
5862: border-collapse: separate;
5863: border-spacing: 1px;
1.515 albertel 5864: }
1.523 albertel 5865:
1.515 albertel 5866: table.LC_prior_tries td {
1.524 albertel 5867: padding: 2px;
1.515 albertel 5868: }
1.523 albertel 5869:
5870: .LC_answer_correct {
1.795 www 5871: background: lightgreen;
5872: color: darkgreen;
5873: padding: 6px;
1.523 albertel 5874: }
1.795 www 5875:
1.523 albertel 5876: .LC_answer_charged_try {
1.797 www 5877: background: #FFAAAA;
1.795 www 5878: color: darkred;
5879: padding: 6px;
1.523 albertel 5880: }
1.795 www 5881:
1.779 bisitz 5882: .LC_answer_not_charged_try,
1.523 albertel 5883: .LC_answer_no_grade,
5884: .LC_answer_late {
1.795 www 5885: background: lightyellow;
1.523 albertel 5886: color: black;
1.795 www 5887: padding: 6px;
1.523 albertel 5888: }
1.795 www 5889:
1.523 albertel 5890: .LC_answer_previous {
1.795 www 5891: background: lightblue;
5892: color: darkblue;
5893: padding: 6px;
1.523 albertel 5894: }
1.795 www 5895:
1.779 bisitz 5896: .LC_answer_no_message {
1.777 tempelho 5897: background: #FFFFFF;
5898: color: black;
1.795 www 5899: padding: 6px;
1.779 bisitz 5900: }
1.795 www 5901:
1.779 bisitz 5902: .LC_answer_unknown {
5903: background: orange;
5904: color: black;
1.795 www 5905: padding: 6px;
1.777 tempelho 5906: }
1.795 www 5907:
1.529 albertel 5908: span.LC_prior_numerical,
5909: span.LC_prior_string,
5910: span.LC_prior_custom,
5911: span.LC_prior_reaction,
5912: span.LC_prior_math {
1.925 bisitz 5913: font-family: $mono;
1.523 albertel 5914: white-space: pre;
5915: }
5916:
1.525 albertel 5917: span.LC_prior_string {
1.925 bisitz 5918: font-family: $mono;
1.525 albertel 5919: white-space: pre;
5920: }
5921:
1.523 albertel 5922: table.LC_prior_option {
5923: width: 100%;
5924: border-collapse: collapse;
5925: }
1.795 www 5926:
1.911 bisitz 5927: table.LC_prior_rank,
1.795 www 5928: table.LC_prior_match {
1.528 albertel 5929: border-collapse: collapse;
5930: }
1.795 www 5931:
1.528 albertel 5932: table.LC_prior_option tr td,
5933: table.LC_prior_rank tr td,
5934: table.LC_prior_match tr td {
1.524 albertel 5935: border: 1px solid #000000;
1.515 albertel 5936: }
5937:
1.855 bisitz 5938: .LC_nobreak {
1.544 albertel 5939: white-space: nowrap;
1.519 raeburn 5940: }
5941:
1.576 raeburn 5942: span.LC_cusr_emph {
5943: font-style: italic;
5944: }
5945:
1.633 raeburn 5946: span.LC_cusr_subheading {
5947: font-weight: normal;
5948: font-size: 85%;
5949: }
5950:
1.861 bisitz 5951: div.LC_docs_entry_move {
1.859 bisitz 5952: border: 1px solid #BBBBBB;
1.545 albertel 5953: background: #DDDDDD;
1.861 bisitz 5954: width: 22px;
1.859 bisitz 5955: padding: 1px;
5956: margin: 0;
1.545 albertel 5957: }
5958:
1.861 bisitz 5959: table.LC_data_table tr > td.LC_docs_entry_commands,
5960: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5961: background: #DDDDDD;
5962: font-size: x-small;
5963: }
1.795 www 5964:
1.861 bisitz 5965: .LC_docs_entry_parameter {
5966: white-space: nowrap;
5967: }
5968:
1.544 albertel 5969: .LC_docs_copy {
1.545 albertel 5970: color: #000099;
1.544 albertel 5971: }
1.795 www 5972:
1.544 albertel 5973: .LC_docs_cut {
1.545 albertel 5974: color: #550044;
1.544 albertel 5975: }
1.795 www 5976:
1.544 albertel 5977: .LC_docs_rename {
1.545 albertel 5978: color: #009900;
1.544 albertel 5979: }
1.795 www 5980:
1.544 albertel 5981: .LC_docs_remove {
1.545 albertel 5982: color: #990000;
5983: }
5984:
1.547 albertel 5985: .LC_docs_reinit_warn,
5986: .LC_docs_ext_edit {
5987: font-size: x-small;
5988: }
5989:
1.545 albertel 5990: table.LC_docs_adddocs td,
5991: table.LC_docs_adddocs th {
5992: border: 1px solid #BBBBBB;
5993: padding: 4px;
5994: background: #DDDDDD;
1.543 albertel 5995: }
5996:
1.584 albertel 5997: table.LC_sty_begin {
5998: background: #BBFFBB;
5999: }
1.795 www 6000:
1.584 albertel 6001: table.LC_sty_end {
6002: background: #FFBBBB;
6003: }
6004:
1.589 raeburn 6005: table.LC_double_column {
1.803 bisitz 6006: border-width: 0;
1.589 raeburn 6007: border-collapse: collapse;
6008: width: 100%;
6009: padding: 2px;
6010: }
6011:
6012: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6013: top: 2px;
1.589 raeburn 6014: left: 2px;
6015: width: 47%;
6016: vertical-align: top;
6017: }
6018:
6019: table.LC_double_column tr td.LC_right_col {
6020: top: 2px;
1.779 bisitz 6021: right: 2px;
1.589 raeburn 6022: width: 47%;
6023: vertical-align: top;
6024: }
6025:
1.591 raeburn 6026: div.LC_left_float {
6027: float: left;
6028: padding-right: 5%;
1.597 albertel 6029: padding-bottom: 4px;
1.591 raeburn 6030: }
6031:
6032: div.LC_clear_float_header {
1.597 albertel 6033: padding-bottom: 2px;
1.591 raeburn 6034: }
6035:
6036: div.LC_clear_float_footer {
1.597 albertel 6037: padding-top: 10px;
1.591 raeburn 6038: clear: both;
6039: }
6040:
1.597 albertel 6041: div.LC_grade_show_user {
1.941 bisitz 6042: /* border-left: 5px solid $sidebg; */
6043: border-top: 5px solid #000000;
6044: margin: 50px 0 0 0;
1.936 bisitz 6045: padding: 15px 0 5px 10px;
1.597 albertel 6046: }
1.795 www 6047:
1.936 bisitz 6048: div.LC_grade_show_user_odd_row {
1.941 bisitz 6049: /* border-left: 5px solid #000000; */
6050: }
6051:
6052: div.LC_grade_show_user div.LC_Box {
6053: margin-right: 50px;
1.597 albertel 6054: }
6055:
6056: div.LC_grade_submissions,
6057: div.LC_grade_message_center,
1.936 bisitz 6058: div.LC_grade_info_links {
1.597 albertel 6059: margin: 5px;
6060: width: 99%;
6061: background: #FFFFFF;
6062: }
1.795 www 6063:
1.597 albertel 6064: div.LC_grade_submissions_header,
1.936 bisitz 6065: div.LC_grade_message_center_header {
1.705 tempelho 6066: font-weight: bold;
6067: font-size: large;
1.597 albertel 6068: }
1.795 www 6069:
1.597 albertel 6070: div.LC_grade_submissions_body,
1.936 bisitz 6071: div.LC_grade_message_center_body {
1.597 albertel 6072: border: 1px solid black;
6073: width: 99%;
6074: background: #FFFFFF;
6075: }
1.795 www 6076:
1.613 albertel 6077: table.LC_scantron_action {
6078: width: 100%;
6079: }
1.795 www 6080:
1.613 albertel 6081: table.LC_scantron_action tr th {
1.698 harmsja 6082: font-weight:bold;
6083: font-style:normal;
1.613 albertel 6084: }
1.795 www 6085:
1.779 bisitz 6086: .LC_edit_problem_header,
1.614 albertel 6087: div.LC_edit_problem_footer {
1.705 tempelho 6088: font-weight: normal;
6089: font-size: medium;
1.602 albertel 6090: margin: 2px;
1.600 albertel 6091: }
1.795 www 6092:
1.600 albertel 6093: div.LC_edit_problem_header,
1.602 albertel 6094: div.LC_edit_problem_header div,
1.614 albertel 6095: div.LC_edit_problem_footer,
6096: div.LC_edit_problem_footer div,
1.602 albertel 6097: div.LC_edit_problem_editxml_header,
6098: div.LC_edit_problem_editxml_header div {
1.600 albertel 6099: margin-top: 5px;
6100: }
1.795 www 6101:
1.600 albertel 6102: div.LC_edit_problem_header_title {
1.705 tempelho 6103: font-weight: bold;
6104: font-size: larger;
1.602 albertel 6105: background: $tabbg;
6106: padding: 3px;
6107: }
1.795 www 6108:
1.602 albertel 6109: table.LC_edit_problem_header_title {
6110: width: 100%;
1.600 albertel 6111: background: $tabbg;
1.602 albertel 6112: }
6113:
6114: div.LC_edit_problem_discards {
6115: float: left;
6116: padding-bottom: 5px;
6117: }
1.795 www 6118:
1.602 albertel 6119: div.LC_edit_problem_saves {
6120: float: right;
6121: padding-bottom: 5px;
1.600 albertel 6122: }
1.795 www 6123:
1.911 bisitz 6124: img.stift {
1.803 bisitz 6125: border-width: 0;
6126: vertical-align: middle;
1.677 riegler 6127: }
1.680 riegler 6128:
1.923 bisitz 6129: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6130: vertical-align: top;
1.777 tempelho 6131: }
1.795 www 6132:
1.716 raeburn 6133: div.LC_createcourse {
1.911 bisitz 6134: margin: 10px 10px 10px 10px;
1.716 raeburn 6135: }
6136:
1.917 raeburn 6137: .LC_dccid {
6138: margin: 0.2em 0 0 0;
6139: padding: 0;
6140: font-size: 90%;
6141: display:none;
6142: }
6143:
1.698 harmsja 6144: a:hover,
1.897 wenzelju 6145: ol.LC_primary_menu a:hover,
1.721 harmsja 6146: ol#LC_MenuBreadcrumbs a:hover,
6147: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6148: ul#LC_secondary_menu a:hover,
1.721 harmsja 6149: .LC_FormSectionClearButton input:hover
1.795 www 6150: ul.LC_TabContent li:hover a {
1.948.2.1 raeburn 6151: color:$button_hover;
1.911 bisitz 6152: text-decoration:none;
1.693 droeschl 6153: }
6154:
1.779 bisitz 6155: h1 {
1.911 bisitz 6156: padding: 0;
6157: line-height:130%;
1.693 droeschl 6158: }
1.698 harmsja 6159:
1.911 bisitz 6160: h2,
6161: h3,
6162: h4,
6163: h5,
6164: h6 {
6165: margin: 5px 0 5px 0;
6166: padding: 0;
6167: line-height:130%;
1.693 droeschl 6168: }
1.795 www 6169:
6170: .LC_hcell {
1.911 bisitz 6171: padding:3px 15px 3px 15px;
6172: margin: 0;
6173: background-color:$tabbg;
6174: color:$fontmenu;
6175: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6176: }
1.795 www 6177:
1.840 bisitz 6178: .LC_Box > .LC_hcell {
1.911 bisitz 6179: margin: 0 -10px 10px -10px;
1.835 bisitz 6180: }
6181:
1.721 harmsja 6182: .LC_noBorder {
1.911 bisitz 6183: border: 0;
1.698 harmsja 6184: }
1.693 droeschl 6185:
1.721 harmsja 6186: .LC_FormSectionClearButton input {
1.911 bisitz 6187: background-color:transparent;
6188: border: none;
6189: cursor:pointer;
6190: text-decoration:underline;
1.693 droeschl 6191: }
1.763 bisitz 6192:
6193: .LC_help_open_topic {
1.911 bisitz 6194: color: #FFFFFF;
6195: background-color: #EEEEFF;
6196: margin: 1px;
6197: padding: 4px;
6198: border: 1px solid #000033;
6199: white-space: nowrap;
6200: /* vertical-align: middle; */
1.759 neumanie 6201: }
1.693 droeschl 6202:
1.911 bisitz 6203: dl,
6204: ul,
6205: div,
6206: fieldset {
6207: margin: 10px 10px 10px 0;
6208: /* overflow: hidden; */
1.693 droeschl 6209: }
1.795 www 6210:
1.838 bisitz 6211: fieldset > legend {
1.911 bisitz 6212: font-weight: bold;
6213: padding: 0 5px 0 5px;
1.838 bisitz 6214: }
6215:
1.813 bisitz 6216: #LC_nav_bar {
1.911 bisitz 6217: float: left;
1.948.2.24 raeburn 6218: background-color: $pgbg_or_bgcolor;
1.948.2.6 raeburn 6219: margin: 0 0 2px 0;
1.807 droeschl 6220: }
6221:
1.916 droeschl 6222: #LC_realm {
6223: margin: 0.2em 0 0 0;
6224: padding: 0;
6225: font-weight: bold;
6226: text-align: center;
1.948.2.24 raeburn 6227: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6228: }
6229:
1.911 bisitz 6230: #LC_nav_bar em {
6231: font-weight: bold;
6232: font-style: normal;
1.807 droeschl 6233: }
6234:
1.948.2.6 raeburn 6235: /* Preliminary fix to hide nav_bar inside bookmarks window */
6236: #LC_bookmarks #LC_nav_bar {
6237: display:none;
6238: }
6239:
1.897 wenzelju 6240: ol.LC_primary_menu {
1.911 bisitz 6241: float: right;
1.934 droeschl 6242: margin: 0;
1.948.2.24 raeburn 6243: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6244: }
6245:
1.948.2.26 raeburn 6246: ol.LC_primary_menu a.LC_new_message {
1.929 wenzelju 6247: font-weight:bold;
6248: color: darkred;
6249: }
6250:
1.852 droeschl 6251: ol#LC_PathBreadcrumbs {
1.911 bisitz 6252: margin: 0;
1.693 droeschl 6253: }
6254:
1.897 wenzelju 6255: ol.LC_primary_menu li {
1.911 bisitz 6256: display: inline;
6257: padding: 5px 5px 0 10px;
6258: vertical-align: top;
1.693 droeschl 6259: }
6260:
1.897 wenzelju 6261: ol.LC_primary_menu li img {
1.911 bisitz 6262: vertical-align: bottom;
1.934 droeschl 6263: height: 1.1em;
1.693 droeschl 6264: }
6265:
1.897 wenzelju 6266: ol.LC_primary_menu a {
1.911 bisitz 6267: color: RGB(80, 80, 80);
6268: text-decoration: none;
1.693 droeschl 6269: }
1.795 www 6270:
1.948.2.7 raeburn 6271: ol.LC_docs_parameters {
6272: margin-left: 0;
6273: padding: 0;
6274: list-style: none;
6275: }
6276:
6277: ol.LC_docs_parameters li {
6278: margin: 0;
6279: padding-right: 20px;
6280: display: inline;
6281: }
6282:
6283: ol.LC_docs_parameters li:before {
6284: content: "\\002022 \\0020";
6285: }
6286:
6287: li.LC_docs_parameters_title {
6288: font-weight: bold;
6289: }
6290:
6291: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6292: content: "";
6293: }
6294:
1.897 wenzelju 6295: ul#LC_secondary_menu {
1.911 bisitz 6296: clear: both;
6297: color: $fontmenu;
6298: background: $tabbg;
6299: list-style: none;
6300: padding: 0;
6301: margin: 0;
6302: width: 100%;
1.948.2.24 raeburn 6303: text-align: left;
1.808 droeschl 6304: }
6305:
1.897 wenzelju 6306: ul#LC_secondary_menu li {
1.911 bisitz 6307: font-weight: bold;
6308: line-height: 1.8em;
6309: padding: 0 0.8em;
6310: border-right: 1px solid black;
6311: display: inline;
6312: vertical-align: middle;
1.807 droeschl 6313: }
6314:
1.847 tempelho 6315: ul.LC_TabContent {
1.911 bisitz 6316: display:block;
6317: background: $sidebg;
6318: border-bottom: solid 1px $lg_border_color;
6319: list-style:none;
6320: margin: 0 -10px;
6321: padding: 0;
1.693 droeschl 6322: }
6323:
1.795 www 6324: ul.LC_TabContent li,
6325: ul.LC_TabContentBigger li {
1.911 bisitz 6326: float:left;
1.741 harmsja 6327: }
1.795 www 6328:
1.897 wenzelju 6329: ul#LC_secondary_menu li a {
1.911 bisitz 6330: color: $fontmenu;
6331: text-decoration: none;
1.693 droeschl 6332: }
1.795 www 6333:
1.721 harmsja 6334: ul.LC_TabContent {
1.948.2.1 raeburn 6335: min-height:20px;
1.721 harmsja 6336: }
1.795 www 6337:
6338: ul.LC_TabContent li {
1.911 bisitz 6339: vertical-align:middle;
1.948.2.3 raeburn 6340: padding: 0 16px 0 10px;
1.911 bisitz 6341: background-color:$tabbg;
6342: border-bottom:solid 1px $lg_border_color;
1.948.2.1 raeburn 6343: border-right: solid 1px $font;
1.721 harmsja 6344: }
1.795 www 6345:
1.847 tempelho 6346: ul.LC_TabContent .right {
1.911 bisitz 6347: float:right;
1.847 tempelho 6348: }
6349:
1.911 bisitz 6350: ul.LC_TabContent li a,
6351: ul.LC_TabContent li {
6352: color:rgb(47,47,47);
6353: text-decoration:none;
6354: font-size:95%;
6355: font-weight:bold;
1.948.2.1 raeburn 6356: min-height:20px;
6357: }
6358:
1.948.2.3 raeburn 6359: ul.LC_TabContent li a:hover,
6360: ul.LC_TabContent li a:focus {
1.948.2.1 raeburn 6361: color: $button_hover;
1.948.2.3 raeburn 6362: background:none;
6363: outline:none;
1.948.2.1 raeburn 6364: }
6365:
6366: ul.LC_TabContent li:hover {
6367: color: $button_hover;
6368: cursor:pointer;
1.721 harmsja 6369: }
1.795 www 6370:
1.911 bisitz 6371: ul.LC_TabContent li.active {
1.948.2.1 raeburn 6372: color: $font;
1.911 bisitz 6373: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.948.2.1 raeburn 6374: border-bottom:solid 1px #FFFFFF;
6375: cursor: default;
1.744 ehlerst 6376: }
1.795 www 6377:
1.948.2.3 raeburn 6378: ul.LC_TabContent li.active a {
6379: color:$font;
6380: background:#FFFFFF;
6381: outline: none;
6382: }
1.870 tempelho 6383: #maincoursedoc {
1.911 bisitz 6384: clear:both;
1.870 tempelho 6385: }
6386:
6387: ul.LC_TabContentBigger {
1.911 bisitz 6388: display:block;
6389: list-style:none;
6390: padding: 0;
1.870 tempelho 6391: }
6392:
1.795 www 6393: ul.LC_TabContentBigger li {
1.911 bisitz 6394: vertical-align:bottom;
6395: height: 30px;
6396: font-size:110%;
6397: font-weight:bold;
6398: color: #737373;
1.841 tempelho 6399: }
6400:
1.948.2.3 raeburn 6401: ul.LC_TabContentBigger li.active {
6402: position: relative;
6403: top: 1px;
6404: }
1.870 tempelho 6405:
6406: ul.LC_TabContentBigger li a {
1.911 bisitz 6407: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6408: height: 30px;
6409: line-height: 30px;
6410: text-align: center;
6411: display: block;
6412: text-decoration: none;
1.948.2.3 raeburn 6413: outline: none;
1.741 harmsja 6414: }
1.795 www 6415:
1.870 tempelho 6416: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6417: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6418: color:$font;
1.744 ehlerst 6419: }
1.795 www 6420:
1.870 tempelho 6421: ul.LC_TabContentBigger li b {
1.911 bisitz 6422: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6423: display: block;
6424: float: left;
6425: padding: 0 30px;
1.948.2.3 raeburn 6426: border-bottom: 1px solid $lg_border_color;
6427: }
6428:
6429: ul.LC_TabContentBigger li:hover b {
6430: color:$button_hover;
1.870 tempelho 6431: }
6432:
6433: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6434: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6435: color:$font;
1.948.2.3 raeburn 6436: border: 0;
6437: cursor:default;
1.741 harmsja 6438: }
1.693 droeschl 6439:
1.862 bisitz 6440: ul.LC_CourseBreadcrumbs {
6441: background: $sidebg;
6442: line-height: 32px;
6443: padding-left: 10px;
6444: margin: 0 0 10px 0;
6445: list-style-position: inside;
6446:
6447: }
6448:
1.911 bisitz 6449: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6450: ol#LC_PathBreadcrumbs {
1.911 bisitz 6451: padding-left: 10px;
6452: margin: 0;
1.933 droeschl 6453: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6454: }
6455:
1.911 bisitz 6456: ol#LC_MenuBreadcrumbs li,
6457: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6458: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6459: display: inline;
1.933 droeschl 6460: white-space: normal;
1.693 droeschl 6461: }
6462:
1.823 bisitz 6463: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6464: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6465: text-decoration: none;
6466: font-size:90%;
1.693 droeschl 6467: }
1.795 www 6468:
1.948.2.7 raeburn 6469: ol#LC_MenuBreadcrumbs h1 {
6470: display: inline;
6471: font-size: 90%;
6472: line-height: 2.5em;
6473: margin: 0;
6474: padding: 0;
6475: }
6476:
1.795 www 6477: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6478: text-decoration:none;
6479: font-size:100%;
6480: font-weight:bold;
1.693 droeschl 6481: }
1.795 www 6482:
1.840 bisitz 6483: .LC_Box {
1.911 bisitz 6484: border: solid 1px $lg_border_color;
6485: padding: 0 10px 10px 10px;
1.746 neumanie 6486: }
1.795 www 6487:
6488: .LC_AboutMe_Image {
1.911 bisitz 6489: float:left;
6490: margin-right:10px;
1.747 neumanie 6491: }
1.795 www 6492:
6493: .LC_Clear_AboutMe_Image {
1.911 bisitz 6494: clear:left;
1.747 neumanie 6495: }
1.795 www 6496:
1.721 harmsja 6497: dl.LC_ListStyleClean dt {
1.911 bisitz 6498: padding-right: 5px;
6499: display: table-header-group;
1.693 droeschl 6500: }
6501:
1.721 harmsja 6502: dl.LC_ListStyleClean dd {
1.911 bisitz 6503: display: table-row;
1.693 droeschl 6504: }
6505:
1.721 harmsja 6506: .LC_ListStyleClean,
6507: .LC_ListStyleSimple,
6508: .LC_ListStyleNormal,
1.795 www 6509: .LC_ListStyleSpecial {
1.911 bisitz 6510: /* display:block; */
6511: list-style-position: inside;
6512: list-style-type: none;
6513: overflow: hidden;
6514: padding: 0;
1.693 droeschl 6515: }
6516:
1.721 harmsja 6517: .LC_ListStyleSimple li,
6518: .LC_ListStyleSimple dd,
6519: .LC_ListStyleNormal li,
6520: .LC_ListStyleNormal dd,
6521: .LC_ListStyleSpecial li,
1.795 www 6522: .LC_ListStyleSpecial dd {
1.911 bisitz 6523: margin: 0;
6524: padding: 5px 5px 5px 10px;
6525: clear: both;
1.693 droeschl 6526: }
6527:
1.721 harmsja 6528: .LC_ListStyleClean li,
6529: .LC_ListStyleClean dd {
1.911 bisitz 6530: padding-top: 0;
6531: padding-bottom: 0;
1.693 droeschl 6532: }
6533:
1.721 harmsja 6534: .LC_ListStyleSimple dd,
1.795 www 6535: .LC_ListStyleSimple li {
1.911 bisitz 6536: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6537: }
6538:
1.721 harmsja 6539: .LC_ListStyleSpecial li,
6540: .LC_ListStyleSpecial dd {
1.911 bisitz 6541: list-style-type: none;
6542: background-color: RGB(220, 220, 220);
6543: margin-bottom: 4px;
1.693 droeschl 6544: }
6545:
1.721 harmsja 6546: table.LC_SimpleTable {
1.911 bisitz 6547: margin:5px;
6548: border:solid 1px $lg_border_color;
1.795 www 6549: }
1.693 droeschl 6550:
1.721 harmsja 6551: table.LC_SimpleTable tr {
1.911 bisitz 6552: padding: 0;
6553: border:solid 1px $lg_border_color;
1.693 droeschl 6554: }
1.795 www 6555:
6556: table.LC_SimpleTable thead {
1.911 bisitz 6557: background:rgb(220,220,220);
1.693 droeschl 6558: }
6559:
1.721 harmsja 6560: div.LC_columnSection {
1.911 bisitz 6561: display: block;
6562: clear: both;
6563: overflow: hidden;
6564: margin: 0;
1.693 droeschl 6565: }
6566:
1.721 harmsja 6567: div.LC_columnSection>* {
1.911 bisitz 6568: float: left;
6569: margin: 10px 20px 10px 0;
6570: overflow:hidden;
1.693 droeschl 6571: }
1.721 harmsja 6572:
1.795 www 6573: table em {
1.911 bisitz 6574: font-weight: bold;
6575: font-style: normal;
1.748 schulted 6576: }
1.795 www 6577:
1.779 bisitz 6578: table.LC_tableBrowseRes,
1.795 www 6579: table.LC_tableOfContent {
1.911 bisitz 6580: border:none;
6581: border-spacing: 1px;
6582: padding: 3px;
6583: background-color: #FFFFFF;
6584: font-size: 90%;
1.753 droeschl 6585: }
1.789 droeschl 6586:
1.911 bisitz 6587: table.LC_tableOfContent {
6588: border-collapse: collapse;
1.789 droeschl 6589: }
6590:
1.771 droeschl 6591: table.LC_tableBrowseRes a,
1.768 schulted 6592: table.LC_tableOfContent a {
1.911 bisitz 6593: background-color: transparent;
6594: text-decoration: none;
1.753 droeschl 6595: }
6596:
1.795 www 6597: table.LC_tableOfContent img {
1.911 bisitz 6598: border: none;
6599: height: 1.3em;
6600: vertical-align: text-bottom;
6601: margin-right: 0.3em;
1.753 droeschl 6602: }
1.757 schulted 6603:
1.795 www 6604: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6605: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6606: }
6607:
1.795 www 6608: a#LC_content_toolbar_launchnav {
1.911 bisitz 6609: background-image:url(/res/adm/pages/start-navigation.gif);
1.774 ehlerst 6610: }
6611:
1.795 www 6612: a#LC_content_toolbar_closenav {
1.911 bisitz 6613: background-image:url(/res/adm/pages/close-navigation.gif);
1.774 ehlerst 6614: }
6615:
1.795 www 6616: a#LC_content_toolbar_everything {
1.911 bisitz 6617: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6618: }
6619:
1.795 www 6620: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6621: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6622: }
6623:
1.795 www 6624: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6625: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6626: }
6627:
1.795 www 6628: a#LC_content_toolbar_changefolder {
1.911 bisitz 6629: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6630: }
6631:
1.795 www 6632: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6633: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6634: }
6635:
1.795 www 6636: ul#LC_toolbar li a:hover {
1.911 bisitz 6637: background-position: bottom center;
1.757 schulted 6638: }
6639:
1.795 www 6640: ul#LC_toolbar {
1.911 bisitz 6641: padding: 0;
6642: margin: 2px;
6643: list-style:none;
6644: position:relative;
6645: background-color:white;
1.757 schulted 6646: }
6647:
1.795 www 6648: ul#LC_toolbar li {
1.911 bisitz 6649: border:1px solid white;
6650: padding: 0;
6651: margin: 0;
6652: float: left;
6653: display:inline;
6654: vertical-align:middle;
6655: }
1.757 schulted 6656:
1.783 amueller 6657:
1.795 www 6658: a.LC_toolbarItem {
1.911 bisitz 6659: display:block;
6660: padding: 0;
6661: margin: 0;
6662: height: 32px;
6663: width: 32px;
6664: color:white;
6665: border: none;
6666: background-repeat:no-repeat;
6667: background-color:transparent;
1.757 schulted 6668: }
6669:
1.915 droeschl 6670: ul.LC_funclist {
6671: margin: 0;
6672: padding: 0.5em 1em 0.5em 0;
6673: }
6674:
1.933 droeschl 6675: ul.LC_funclist > li:first-child {
6676: font-weight:bold;
6677: margin-left:0.8em;
6678: }
6679:
1.915 droeschl 6680: ul.LC_funclist + ul.LC_funclist {
6681: /*
6682: left border as a seperator if we have more than
6683: one list
6684: */
6685: border-left: 1px solid $sidebg;
6686: /*
6687: this hides the left border behind the border of the
6688: outer box if element is wrapped to the next 'line'
6689: */
6690: margin-left: -1px;
6691: }
6692:
1.843 bisitz 6693: ul.LC_funclist li {
1.915 droeschl 6694: display: inline;
1.782 bisitz 6695: white-space: nowrap;
1.915 droeschl 6696: margin: 0 0 0 25px;
6697: line-height: 150%;
1.782 bisitz 6698: }
6699:
1.930 faziophi 6700: .ui-accordion .LC_advanced_toggle {
6701: float: right;
6702: font-size: 90%;
6703: padding: 0px 4px
6704: }
1.757 schulted 6705:
1.343 albertel 6706: END
6707: }
6708:
1.306 albertel 6709: =pod
6710:
6711: =item * &headtag()
6712:
6713: Returns a uniform footer for LON-CAPA web pages.
6714:
1.307 albertel 6715: Inputs: $title - optional title for the head
6716: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6717: $args - optional arguments
1.319 albertel 6718: force_register - if is true call registerurl so the remote is
6719: informed
1.415 albertel 6720: redirect -> array ref of
6721: 1- seconds before redirect occurs
6722: 2- url to redirect to
6723: 3- whether the side effect should occur
1.315 albertel 6724: (side effect of setting
6725: $env{'internal.head.redirect'} to the url
6726: redirected too)
1.352 albertel 6727: domain -> force to color decorate a page for a specific
6728: domain
6729: function -> force usage of a specific rolish color scheme
6730: bgcolor -> override the default page bgcolor
1.460 albertel 6731: no_auto_mt_title
6732: -> prevent &mt()ing the title arg
1.464 albertel 6733:
1.306 albertel 6734: =cut
6735:
6736: sub headtag {
1.313 albertel 6737: my ($title,$head_extra,$args) = @_;
1.306 albertel 6738:
1.363 albertel 6739: my $function = $args->{'function'} || &get_users_function();
6740: my $domain = $args->{'domain'} || &determinedomain();
6741: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6742: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6743: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6744: #time(),
1.418 albertel 6745: $env{'environment.color.timestamp'},
1.363 albertel 6746: $function,$domain,$bgcolor);
6747:
1.369 www 6748: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6749:
1.308 albertel 6750: my $result =
6751: '<head>'.
1.461 albertel 6752: &font_settings();
1.319 albertel 6753:
1.461 albertel 6754: if (!$args->{'frameset'}) {
6755: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6756: }
1.319 albertel 6757: if ($args->{'force_register'}) {
6758: $result .= &Apache::lonmenu::registerurl(1);
6759: }
1.436 albertel 6760: if (!$args->{'no_nav_bar'}
6761: && !$args->{'only_body'}
6762: && !$args->{'frameset'}) {
6763: $result .= &help_menu_js();
6764: }
1.319 albertel 6765:
1.314 albertel 6766: if (ref($args->{'redirect'})) {
1.414 albertel 6767: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6768: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6769: if (!$inhibit_continue) {
6770: $env{'internal.head.redirect'} = $url;
6771: }
1.313 albertel 6772: $result.=<<ADDMETA
6773: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6774: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6775: ADDMETA
6776: }
1.306 albertel 6777: if (!defined($title)) {
6778: $title = 'The LearningOnline Network with CAPA';
6779: }
1.460 albertel 6780: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6781: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6782: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.948.2.33.2. (raeburn 6783:): .&printstyle()
1.414 albertel 6784: .$head_extra;
1.306 albertel 6785: return $result;
6786: }
6787:
6788: =pod
6789:
1.340 albertel 6790: =item * &font_settings()
6791:
6792: Returns neccessary <meta> to set the proper encoding
6793:
6794: Inputs: none
6795:
6796: =cut
6797:
6798: sub font_settings {
6799: my $headerstring='';
1.647 www 6800: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6801: $headerstring.=
6802: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6803: }
6804: return $headerstring;
6805: }
6806:
1.948.2.33.2. (raeburn 6807:): sub printstyle {
6808:): return <<"ENDSTYLE";
6809:): <style type="text/css" media="print">
6810:): #LC_breadcrumbs,
6811:): .LC_head_subbox,
6812:): #LC_secondary_menu,
6813:): .LC_discussion,
6814:): .LC_feedback_link,
6815:): .LC_primary_menu { display: none; }
6816:): form[name="lonhomework"] { clear: both; display: block; padding-top: 3em !important; }
6817:): </style>
6818:): ENDSTYLE
6819:):
6820:): }
6821:):
1.341 albertel 6822: =pod
6823:
6824: =item * &xml_begin()
6825:
6826: Returns the needed doctype and <html>
6827:
6828: Inputs: none
6829:
6830: =cut
6831:
6832: sub xml_begin {
6833: my $output='';
6834:
6835: if ($env{'browser.mathml'}) {
6836: $output='<?xml version="1.0"?>'
6837: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6838: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6839:
6840: # .'<!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">] >'
6841: .'<!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">'
6842: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6843: .'xmlns="http://www.w3.org/1999/xhtml">';
6844: } else {
1.849 bisitz 6845: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6846: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6847: }
6848: return $output;
6849: }
1.340 albertel 6850:
6851: =pod
6852:
1.306 albertel 6853: =item * &endheadtag()
6854:
6855: Returns a uniform </head> for LON-CAPA web pages.
6856:
6857: Inputs: none
6858:
6859: =cut
6860:
6861: sub endheadtag {
6862: return '</head>';
6863: }
6864:
6865: =pod
6866:
6867: =item * &head()
6868:
6869: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6870:
1.648 raeburn 6871: Inputs:
6872:
6873: =over 4
6874:
6875: $title - optional title for the page
6876:
6877: $head_extra - optional extra HTML to put inside the <head>
6878:
6879: =back
1.405 albertel 6880:
1.306 albertel 6881: =cut
6882:
6883: sub head {
1.325 albertel 6884: my ($title,$head_extra,$args) = @_;
6885: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6886: }
6887:
6888: =pod
6889:
6890: =item * &start_page()
6891:
6892: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6893:
1.648 raeburn 6894: Inputs:
6895:
6896: =over 4
6897:
6898: $title - optional title for the page
6899:
6900: $head_extra - optional extra HTML to incude inside the <head>
6901:
6902: $args - additional optional args supported are:
6903:
6904: =over 8
6905:
6906: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6907: arg on
1.814 bisitz 6908: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6909: add_entries -> additional attributes to add to the <body>
6910: domain -> force to color decorate a page for a
1.317 albertel 6911: specific domain
1.648 raeburn 6912: function -> force usage of a specific rolish color
1.317 albertel 6913: scheme
1.648 raeburn 6914: redirect -> see &headtag()
6915: bgcolor -> override the default page bg color
6916: js_ready -> return a string ready for being used in
1.317 albertel 6917: a javascript writeln
1.648 raeburn 6918: html_encode -> return a string ready for being used in
1.320 albertel 6919: a html attribute
1.648 raeburn 6920: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6921: $forcereg arg
1.648 raeburn 6922: frameset -> if true will start with a <frameset>
1.330 albertel 6923: rather than <body>
1.648 raeburn 6924: skip_phases -> hash ref of
1.338 albertel 6925: head -> skip the <html><head> generation
6926: body -> skip all <body> generation
1.648 raeburn 6927: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6928: 'Switch To Inline Menu' link
1.648 raeburn 6929: no_auto_mt_title -> prevent &mt()ing the title arg
6930: inherit_jsmath -> when creating popup window in a page,
6931: should it have jsmath forced on by the
6932: current page
1.867 kalberla 6933: bread_crumbs -> Array containing breadcrumbs
1.948.2.12 raeburn 6934: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6935:
1.648 raeburn 6936: =back
1.460 albertel 6937:
1.648 raeburn 6938: =back
1.562 albertel 6939:
1.306 albertel 6940: =cut
6941:
6942: sub start_page {
1.309 albertel 6943: my ($title,$head_extra,$args) = @_;
1.318 albertel 6944: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6945: my %head_args;
1.352 albertel 6946: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6947: 'bgcolor','frameset','no_nav_bar','only_body',
6948: 'no_auto_mt_title') {
1.319 albertel 6949: if (defined($args->{$arg})) {
1.324 raeburn 6950: $head_args{$arg} = $args->{$arg};
1.319 albertel 6951: }
1.313 albertel 6952: }
1.319 albertel 6953:
1.315 albertel 6954: $env{'internal.start_page'}++;
1.338 albertel 6955: my $result;
6956: if (! exists($args->{'skip_phases'}{'head'}) ) {
6957: $result.=
1.341 albertel 6958: &xml_begin().
1.338 albertel 6959: &headtag($title,$head_extra,\%head_args).&endheadtag();
6960: }
6961:
6962: if (! exists($args->{'skip_phases'}{'body'}) ) {
6963: if ($args->{'frameset'}) {
6964: my $attr_string = &make_attr_string($args->{'force_register'},
6965: $args->{'add_entries'});
6966: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6967: } else {
6968: $result .=
6969: &bodytag($title,
6970: $args->{'function'}, $args->{'add_entries'},
6971: $args->{'only_body'}, $args->{'domain'},
6972: $args->{'force_register'}, $args->{'no_nav_bar'},
6973: $args->{'bgcolor'}, $args->{'no_inline_link'},
6974: $args);
6975: }
1.330 albertel 6976: }
1.338 albertel 6977:
1.315 albertel 6978: if ($args->{'js_ready'}) {
1.713 kaisler 6979: $result = &js_ready($result);
1.315 albertel 6980: }
1.320 albertel 6981: if ($args->{'html_encode'}) {
1.713 kaisler 6982: $result = &html_encode($result);
6983: }
6984:
1.813 bisitz 6985: # Preparation for new and consistent functionlist at top of screen
6986: # if ($args->{'functionlist'}) {
6987: # $result .= &build_functionlist();
6988: #}
6989:
6990: # Don't add anything more if only_body wanted
6991: return $result if $args->{'only_body'};
6992:
1.920 raeburn 6993: #Breadcrumbs for Construction Space provided by &bodytag.
6994: if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
6995: return $result;
6996: }
6997:
1.813 bisitz 6998: #Breadcrumbs
1.758 kaisler 6999: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7000: &Apache::lonhtmlcommon::clear_breadcrumbs();
7001: #if any br links exists, add them to the breadcrumbs
7002: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7003: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7004: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7005: }
7006: }
7007:
7008: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7009: if(exists($args->{'bread_crumbs_component'})){
7010: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7011: }else{
7012: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7013: }
1.320 albertel 7014: }
1.315 albertel 7015: return $result;
1.306 albertel 7016: }
7017:
1.330 albertel 7018:
1.306 albertel 7019: =pod
7020:
7021: =item * &head()
7022:
7023: Returns a complete </body></html> section for LON-CAPA web pages.
7024:
1.315 albertel 7025: Inputs: $args - additional optional args supported are:
7026: js_ready -> return a string ready for being used in
7027: a javascript writeln
1.320 albertel 7028: html_encode -> return a string ready for being used in
7029: a html attribute
1.330 albertel 7030: frameset -> if true will start with a <frameset>
7031: rather than <body>
1.493 albertel 7032: dicsussion -> if true will get discussion from
7033: lonxml::xmlend
7034: (you can pass the target and parser arguments
7035: through optional 'target' and 'parser' args
7036: to this routine)
1.306 albertel 7037:
7038: =cut
7039:
7040: sub end_page {
1.315 albertel 7041: my ($args) = @_;
7042: $env{'internal.end_page'}++;
1.330 albertel 7043: my $result;
1.335 albertel 7044: if ($args->{'discussion'}) {
7045: my ($target,$parser);
7046: if (ref($args->{'discussion'})) {
7047: ($target,$parser) =($args->{'discussion'}{'target'},
7048: $args->{'discussion'}{'parser'});
7049: }
7050: $result .= &Apache::lonxml::xmlend($target,$parser);
7051: }
7052:
1.330 albertel 7053: if ($args->{'frameset'}) {
7054: $result .= '</frameset>';
7055: } else {
1.635 raeburn 7056: $result .= &endbodytag($args);
1.330 albertel 7057: }
7058: $result .= "\n</html>";
7059:
1.315 albertel 7060: if ($args->{'js_ready'}) {
1.317 albertel 7061: $result = &js_ready($result);
1.315 albertel 7062: }
1.335 albertel 7063:
1.320 albertel 7064: if ($args->{'html_encode'}) {
7065: $result = &html_encode($result);
7066: }
1.335 albertel 7067:
1.315 albertel 7068: return $result;
7069: }
7070:
1.320 albertel 7071: sub html_encode {
7072: my ($result) = @_;
7073:
1.322 albertel 7074: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7075:
7076: return $result;
7077: }
1.317 albertel 7078: sub js_ready {
7079: my ($result) = @_;
7080:
1.323 albertel 7081: $result =~ s/[\n\r]/ /xmsg;
7082: $result =~ s/\\/\\\\/xmsg;
7083: $result =~ s/'/\\'/xmsg;
1.372 albertel 7084: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7085:
7086: return $result;
7087: }
7088:
1.315 albertel 7089: sub validate_page {
7090: if ( exists($env{'internal.start_page'})
1.316 albertel 7091: && $env{'internal.start_page'} > 1) {
7092: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7093: $env{'internal.start_page'}.' '.
1.316 albertel 7094: $ENV{'request.filename'});
1.315 albertel 7095: }
7096: if ( exists($env{'internal.end_page'})
1.316 albertel 7097: && $env{'internal.end_page'} > 1) {
7098: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7099: $env{'internal.end_page'}.' '.
1.316 albertel 7100: $env{'request.filename'});
1.315 albertel 7101: }
7102: if ( exists($env{'internal.start_page'})
7103: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7104: &Apache::lonnet::logthis('start_page called without end_page '.
7105: $env{'request.filename'});
1.315 albertel 7106: }
7107: if ( ! exists($env{'internal.start_page'})
7108: && exists($env{'internal.end_page'})) {
1.316 albertel 7109: &Apache::lonnet::logthis('end_page called without start_page'.
7110: $env{'request.filename'});
1.315 albertel 7111: }
1.306 albertel 7112: }
1.315 albertel 7113:
1.318 albertel 7114: sub simple_error_page {
7115: my ($r,$title,$msg) = @_;
7116: my $page =
7117: &Apache::loncommon::start_page($title).
7118: &mt($msg).
7119: &Apache::loncommon::end_page();
7120: if (ref($r)) {
7121: $r->print($page);
1.327 albertel 7122: return;
1.318 albertel 7123: }
7124: return $page;
7125: }
1.347 albertel 7126:
7127: {
1.610 albertel 7128: my @row_count;
1.948.2.5 raeburn 7129:
7130: sub start_data_table_count {
7131: unshift(@row_count, 0);
7132: return;
7133: }
7134:
7135: sub end_data_table_count {
7136: shift(@row_count);
7137: return;
7138: }
7139:
1.347 albertel 7140: sub start_data_table {
1.422 albertel 7141: my ($add_class) = @_;
7142: my $css_class = (join(' ','LC_data_table',$add_class));
1.948.2.5 raeburn 7143: &start_data_table_count();
1.422 albertel 7144: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 7145: }
7146:
7147: sub end_data_table {
1.948.2.5 raeburn 7148: &end_data_table_count();
1.389 albertel 7149: return '</table>'."\n";;
1.347 albertel 7150: }
7151:
7152: sub start_data_table_row {
1.422 albertel 7153: my ($add_class) = @_;
1.610 albertel 7154: $row_count[0]++;
7155: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7156: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 7157: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 7158: }
1.471 banghart 7159:
7160: sub continue_data_table_row {
7161: my ($add_class) = @_;
1.610 albertel 7162: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.948.2.32 raeburn 7163: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.471 banghart 7164: return '<tr class="'.$css_class.'">'."\n";;
7165: }
1.347 albertel 7166:
7167: sub end_data_table_row {
1.389 albertel 7168: return '</tr>'."\n";;
1.347 albertel 7169: }
1.367 www 7170:
1.421 albertel 7171: sub start_data_table_empty_row {
1.707 bisitz 7172: # $row_count[0]++;
1.421 albertel 7173: return '<tr class="LC_empty_row" >'."\n";;
7174: }
7175:
7176: sub end_data_table_empty_row {
7177: return '</tr>'."\n";;
7178: }
7179:
1.367 www 7180: sub start_data_table_header_row {
1.389 albertel 7181: return '<tr class="LC_header_row">'."\n";;
1.367 www 7182: }
7183:
7184: sub end_data_table_header_row {
1.389 albertel 7185: return '</tr>'."\n";;
1.367 www 7186: }
1.890 droeschl 7187:
7188: sub data_table_caption {
7189: my $caption = shift;
7190: return "<caption class=\"LC_caption\">$caption</caption>";
7191: }
1.347 albertel 7192: }
7193:
1.548 albertel 7194: =pod
7195:
7196: =item * &inhibit_menu_check($arg)
7197:
7198: Checks for a inhibitmenu state and generates output to preserve it
7199:
7200: Inputs: $arg - can be any of
7201: - undef - in which case the return value is a string
7202: to add into arguments list of a uri
7203: - 'input' - in which case the return value is a HTML
7204: <form> <input> field of type hidden to
7205: preserve the value
7206: - a url - in which case the return value is the url with
7207: the neccesary cgi args added to preserve the
7208: inhibitmenu state
7209: - a ref to a url - no return value, but the string is
7210: updated to include the neccessary cgi
7211: args to preserve the inhibitmenu state
7212:
7213: =cut
7214:
7215: sub inhibit_menu_check {
7216: my ($arg) = @_;
7217: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7218: if ($arg eq 'input') {
7219: if ($env{'form.inhibitmenu'}) {
7220: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7221: } else {
7222: return
7223: }
7224: }
7225: if ($env{'form.inhibitmenu'}) {
7226: if (ref($arg)) {
7227: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7228: } elsif ($arg eq '') {
7229: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7230: } else {
7231: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7232: }
7233: }
7234: if (!ref($arg)) {
7235: return $arg;
7236: }
7237: }
7238:
1.251 albertel 7239: ###############################################
1.182 matthew 7240:
7241: =pod
7242:
1.549 albertel 7243: =back
7244:
7245: =head1 User Information Routines
7246:
7247: =over 4
7248:
1.405 albertel 7249: =item * &get_users_function()
1.182 matthew 7250:
7251: Used by &bodytag to determine the current users primary role.
7252: Returns either 'student','coordinator','admin', or 'author'.
7253:
7254: =cut
7255:
7256: ###############################################
7257: sub get_users_function {
1.815 tempelho 7258: my $function = 'norole';
1.818 tempelho 7259: if ($env{'request.role'}=~/^(st)/) {
7260: $function='student';
7261: }
1.907 raeburn 7262: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7263: $function='coordinator';
7264: }
1.258 albertel 7265: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7266: $function='admin';
7267: }
1.826 bisitz 7268: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7269: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7270: $function='author';
7271: }
7272: return $function;
1.54 www 7273: }
1.99 www 7274:
7275: ###############################################
7276:
1.233 raeburn 7277: =pod
7278:
1.821 raeburn 7279: =item * &show_course()
7280:
7281: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7282: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7283:
7284: Inputs:
7285: None
7286:
7287: Outputs:
7288: Scalar: 1 if 'Course' to be used, 0 otherwise.
7289:
7290: =cut
7291:
7292: ###############################################
7293: sub show_course {
7294: my $course = !$env{'user.adv'};
7295: if (!$env{'user.adv'}) {
7296: foreach my $env (keys(%env)) {
7297: next if ($env !~ m/^user\.priv\./);
7298: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7299: $course = 0;
7300: last;
7301: }
7302: }
7303: }
7304: return $course;
7305: }
7306:
7307: ###############################################
7308:
7309: =pod
7310:
1.542 raeburn 7311: =item * &check_user_status()
1.274 raeburn 7312:
7313: Determines current status of supplied role for a
7314: specific user. Roles can be active, previous or future.
7315:
7316: Inputs:
7317: user's domain, user's username, course's domain,
1.375 raeburn 7318: course's number, optional section ID.
1.274 raeburn 7319:
7320: Outputs:
7321: role status: active, previous or future.
7322:
7323: =cut
7324:
7325: sub check_user_status {
1.412 raeburn 7326: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.948.2.11 raeburn 7327: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7328: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7329: my @uroles = keys %userinfo;
7330: my $srchstr;
7331: my $active_chk = 'none';
1.412 raeburn 7332: my $now = time;
1.274 raeburn 7333: if (@uroles > 0) {
1.908 raeburn 7334: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7335: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7336: } else {
1.412 raeburn 7337: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7338: }
7339: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7340: my $role_end = 0;
7341: my $role_start = 0;
7342: $active_chk = 'active';
1.412 raeburn 7343: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7344: $role_end = $1;
7345: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7346: $role_start = $1;
1.274 raeburn 7347: }
7348: }
7349: if ($role_start > 0) {
1.412 raeburn 7350: if ($now < $role_start) {
1.274 raeburn 7351: $active_chk = 'future';
7352: }
7353: }
7354: if ($role_end > 0) {
1.412 raeburn 7355: if ($now > $role_end) {
1.274 raeburn 7356: $active_chk = 'previous';
7357: }
7358: }
7359: }
7360: }
7361: return $active_chk;
7362: }
7363:
7364: ###############################################
7365:
7366: =pod
7367:
1.405 albertel 7368: =item * &get_sections()
1.233 raeburn 7369:
7370: Determines all the sections for a course including
7371: sections with students and sections containing other roles.
1.419 raeburn 7372: Incoming parameters:
7373:
7374: 1. domain
7375: 2. course number
7376: 3. reference to array containing roles for which sections should
7377: be gathered (optional).
7378: 4. reference to array containing status types for which sections
7379: should be gathered (optional).
7380:
7381: If the third argument is undefined, sections are gathered for any role.
7382: If the fourth argument is undefined, sections are gathered for any status.
7383: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7384:
1.374 raeburn 7385: Returns section hash (keys are section IDs, values are
7386: number of users in each section), subject to the
1.419 raeburn 7387: optional roles filter, optional status filter
1.233 raeburn 7388:
7389: =cut
7390:
7391: ###############################################
7392: sub get_sections {
1.419 raeburn 7393: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7394: if (!defined($cdom) || !defined($cnum)) {
7395: my $cid = $env{'request.course.id'};
7396:
7397: return if (!defined($cid));
7398:
7399: $cdom = $env{'course.'.$cid.'.domain'};
7400: $cnum = $env{'course.'.$cid.'.num'};
7401: }
7402:
7403: my %sectioncount;
1.419 raeburn 7404: my $now = time;
1.240 albertel 7405:
1.366 albertel 7406: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7407: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7408: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7409: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7410: my $start_index = &Apache::loncoursedata::CL_START();
7411: my $end_index = &Apache::loncoursedata::CL_END();
7412: my $status;
1.366 albertel 7413: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7414: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7415: $data->[$status_index],
7416: $data->[$start_index],
7417: $data->[$end_index]);
7418: if ($stu_status eq 'Active') {
7419: $status = 'active';
7420: } elsif ($end < $now) {
7421: $status = 'previous';
7422: } elsif ($start > $now) {
7423: $status = 'future';
7424: }
7425: if ($section ne '-1' && $section !~ /^\s*$/) {
7426: if ((!defined($possible_status)) || (($status ne '') &&
7427: (grep/^\Q$status\E$/,@{$possible_status}))) {
7428: $sectioncount{$section}++;
7429: }
1.240 albertel 7430: }
7431: }
7432: }
7433: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7434: foreach my $user (sort(keys(%courseroles))) {
7435: if ($user !~ /^(\w{2})/) { next; }
7436: my ($role) = ($user =~ /^(\w{2})/);
7437: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7438: my ($section,$status);
1.240 albertel 7439: if ($role eq 'cr' &&
7440: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7441: $section=$1;
7442: }
7443: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7444: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7445: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7446: if ($end == -1 && $start == -1) {
7447: next; #deleted role
7448: }
7449: if (!defined($possible_status)) {
7450: $sectioncount{$section}++;
7451: } else {
7452: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7453: $status = 'active';
7454: } elsif ($end < $now) {
7455: $status = 'future';
7456: } elsif ($start > $now) {
7457: $status = 'previous';
7458: }
7459: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7460: $sectioncount{$section}++;
7461: }
7462: }
1.233 raeburn 7463: }
1.366 albertel 7464: return %sectioncount;
1.233 raeburn 7465: }
7466:
1.274 raeburn 7467: ###############################################
1.294 raeburn 7468:
7469: =pod
1.405 albertel 7470:
7471: =item * &get_course_users()
7472:
1.275 raeburn 7473: Retrieves usernames:domains for users in the specified course
7474: with specific role(s), and access status.
7475:
7476: Incoming parameters:
1.277 albertel 7477: 1. course domain
7478: 2. course number
7479: 3. access status: users must have - either active,
1.275 raeburn 7480: previous, future, or all.
1.277 albertel 7481: 4. reference to array of permissible roles
1.288 raeburn 7482: 5. reference to array of section restrictions (optional)
7483: 6. reference to results object (hash of hashes).
7484: 7. reference to optional userdata hash
1.609 raeburn 7485: 8. reference to optional statushash
1.630 raeburn 7486: 9. flag if privileged users (except those set to unhide in
7487: course settings) should be excluded
1.609 raeburn 7488: Keys of top level results hash are roles.
1.275 raeburn 7489: Keys of inner hashes are username:domain, with
7490: values set to access type.
1.288 raeburn 7491: Optional userdata hash returns an array with arguments in the
7492: same order as loncoursedata::get_classlist() for student data.
7493:
1.609 raeburn 7494: Optional statushash returns
7495:
1.288 raeburn 7496: Entries for end, start, section and status are blank because
7497: of the possibility of multiple values for non-student roles.
7498:
1.275 raeburn 7499: =cut
1.405 albertel 7500:
1.275 raeburn 7501: ###############################################
1.405 albertel 7502:
1.275 raeburn 7503: sub get_course_users {
1.630 raeburn 7504: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7505: my %idx = ();
1.419 raeburn 7506: my %seclists;
1.288 raeburn 7507:
7508: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7509: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7510: $idx{end} = &Apache::loncoursedata::CL_END();
7511: $idx{start} = &Apache::loncoursedata::CL_START();
7512: $idx{id} = &Apache::loncoursedata::CL_ID();
7513: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7514: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7515: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7516:
1.290 albertel 7517: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7518: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7519: my $now = time;
1.277 albertel 7520: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7521: my $match = 0;
1.412 raeburn 7522: my $secmatch = 0;
1.419 raeburn 7523: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7524: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7525: if ($section eq '') {
7526: $section = 'none';
7527: }
1.291 albertel 7528: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7529: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7530: $secmatch = 1;
7531: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7532: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7533: $secmatch = 1;
7534: }
7535: } else {
1.419 raeburn 7536: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7537: $secmatch = 1;
7538: }
1.290 albertel 7539: }
1.412 raeburn 7540: if (!$secmatch) {
7541: next;
7542: }
1.419 raeburn 7543: }
1.275 raeburn 7544: if (defined($$types{'active'})) {
1.288 raeburn 7545: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7546: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7547: $match = 1;
1.275 raeburn 7548: }
7549: }
7550: if (defined($$types{'previous'})) {
1.609 raeburn 7551: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7552: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7553: $match = 1;
1.275 raeburn 7554: }
7555: }
7556: if (defined($$types{'future'})) {
1.609 raeburn 7557: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7558: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7559: $match = 1;
1.275 raeburn 7560: }
7561: }
1.609 raeburn 7562: if ($match) {
7563: push(@{$seclists{$student}},$section);
7564: if (ref($userdata) eq 'HASH') {
7565: $$userdata{$student} = $$classlist{$student};
7566: }
7567: if (ref($statushash) eq 'HASH') {
7568: $statushash->{$student}{'st'}{$section} = $status;
7569: }
1.288 raeburn 7570: }
1.275 raeburn 7571: }
7572: }
1.412 raeburn 7573: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7574: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7575: my $now = time;
1.609 raeburn 7576: my %displaystatus = ( previous => 'Expired',
7577: active => 'Active',
7578: future => 'Future',
7579: );
1.630 raeburn 7580: my %nothide;
7581: if ($hidepriv) {
7582: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7583: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7584: if ($user !~ /:/) {
7585: $nothide{join(':',split(/[\@]/,$user))}=1;
7586: } else {
7587: $nothide{$user} = 1;
7588: }
7589: }
7590: }
1.439 raeburn 7591: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7592: my $match = 0;
1.412 raeburn 7593: my $secmatch = 0;
1.439 raeburn 7594: my $status;
1.412 raeburn 7595: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7596: $user =~ s/:$//;
1.439 raeburn 7597: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7598: if ($end == -1 || $start == -1) {
7599: next;
7600: }
7601: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7602: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7603: my ($uname,$udom) = split(/:/,$user);
7604: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7605: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7606: $secmatch = 1;
7607: } elsif ($usec eq '') {
1.420 albertel 7608: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7609: $secmatch = 1;
7610: }
7611: } else {
7612: if (grep(/^\Q$usec\E$/,@{$sections})) {
7613: $secmatch = 1;
7614: }
7615: }
7616: if (!$secmatch) {
7617: next;
7618: }
1.288 raeburn 7619: }
1.419 raeburn 7620: if ($usec eq '') {
7621: $usec = 'none';
7622: }
1.275 raeburn 7623: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7624: if ($hidepriv) {
7625: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7626: (!$nothide{$uname.':'.$udom})) {
7627: next;
7628: }
7629: }
1.503 raeburn 7630: if ($end > 0 && $end < $now) {
1.439 raeburn 7631: $status = 'previous';
7632: } elsif ($start > $now) {
7633: $status = 'future';
7634: } else {
7635: $status = 'active';
7636: }
1.277 albertel 7637: foreach my $type (keys(%{$types})) {
1.275 raeburn 7638: if ($status eq $type) {
1.420 albertel 7639: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7640: push(@{$$users{$role}{$user}},$type);
7641: }
1.288 raeburn 7642: $match = 1;
7643: }
7644: }
1.419 raeburn 7645: if (($match) && (ref($userdata) eq 'HASH')) {
7646: if (!exists($$userdata{$uname.':'.$udom})) {
7647: &get_user_info($udom,$uname,\%idx,$userdata);
7648: }
1.420 albertel 7649: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7650: push(@{$seclists{$uname.':'.$udom}},$usec);
7651: }
1.609 raeburn 7652: if (ref($statushash) eq 'HASH') {
7653: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7654: }
1.275 raeburn 7655: }
7656: }
7657: }
7658: }
1.290 albertel 7659: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7660: if ((defined($cdom)) && (defined($cnum))) {
7661: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7662: if ( defined($csettings{'internal.courseowner'}) ) {
7663: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7664: next if ($owner eq '');
7665: my ($ownername,$ownerdom);
7666: if ($owner =~ /^([^:]+):([^:]+)$/) {
7667: $ownername = $1;
7668: $ownerdom = $2;
7669: } else {
7670: $ownername = $owner;
7671: $ownerdom = $cdom;
7672: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7673: }
7674: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7675: if (defined($userdata) &&
1.609 raeburn 7676: !exists($$userdata{$owner})) {
7677: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7678: if (!grep(/^none$/,@{$seclists{$owner}})) {
7679: push(@{$seclists{$owner}},'none');
7680: }
7681: if (ref($statushash) eq 'HASH') {
7682: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7683: }
1.290 albertel 7684: }
1.279 raeburn 7685: }
7686: }
7687: }
1.419 raeburn 7688: foreach my $user (keys(%seclists)) {
7689: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7690: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7691: }
1.275 raeburn 7692: }
7693: return;
7694: }
7695:
1.288 raeburn 7696: sub get_user_info {
7697: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7698: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7699: &plainname($uname,$udom,'lastname');
1.291 albertel 7700: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7701: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7702: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7703: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7704: return;
7705: }
1.275 raeburn 7706:
1.472 raeburn 7707: ###############################################
7708:
7709: =pod
7710:
7711: =item * &get_user_quota()
7712:
7713: Retrieves quota assigned for storage of portfolio files for a user
7714:
7715: Incoming parameters:
7716: 1. user's username
7717: 2. user's domain
7718:
7719: Returns:
1.536 raeburn 7720: 1. Disk quota (in Mb) assigned to student.
7721: 2. (Optional) Type of setting: custom or default
7722: (individually assigned or default for user's
7723: institutional status).
7724: 3. (Optional) - User's institutional status (e.g., faculty, staff
7725: or student - types as defined in localenroll::inst_usertypes
7726: for user's domain, which determines default quota for user.
7727: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7728:
7729: If a value has been stored in the user's environment,
1.536 raeburn 7730: it will return that, otherwise it returns the maximal default
7731: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7732:
7733: =cut
7734:
7735: ###############################################
7736:
7737:
7738: sub get_user_quota {
7739: my ($uname,$udom) = @_;
1.536 raeburn 7740: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7741: if (!defined($udom)) {
7742: $udom = $env{'user.domain'};
7743: }
7744: if (!defined($uname)) {
7745: $uname = $env{'user.name'};
7746: }
7747: if (($udom eq '' || $uname eq '') ||
7748: ($udom eq 'public') && ($uname eq 'public')) {
7749: $quota = 0;
1.536 raeburn 7750: $quotatype = 'default';
7751: $defquota = 0;
1.472 raeburn 7752: } else {
1.536 raeburn 7753: my $inststatus;
1.472 raeburn 7754: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7755: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7756: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7757: } else {
1.536 raeburn 7758: my %userenv =
7759: &Apache::lonnet::get('environment',['portfolioquota',
7760: 'inststatus'],$udom,$uname);
1.472 raeburn 7761: my ($tmp) = keys(%userenv);
7762: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7763: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7764: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7765: } else {
7766: undef(%userenv);
7767: }
7768: }
1.536 raeburn 7769: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7770: if ($quota eq '') {
1.536 raeburn 7771: $quota = $defquota;
7772: $quotatype = 'default';
7773: } else {
7774: $quotatype = 'custom';
1.472 raeburn 7775: }
7776: }
1.536 raeburn 7777: if (wantarray) {
7778: return ($quota,$quotatype,$settingstatus,$defquota);
7779: } else {
7780: return $quota;
7781: }
1.472 raeburn 7782: }
7783:
7784: ###############################################
7785:
7786: =pod
7787:
7788: =item * &default_quota()
7789:
1.536 raeburn 7790: Retrieves default quota assigned for storage of user portfolio files,
7791: given an (optional) user's institutional status.
1.472 raeburn 7792:
7793: Incoming parameters:
7794: 1. domain
1.536 raeburn 7795: 2. (Optional) institutional status(es). This is a : separated list of
7796: status types (e.g., faculty, staff, student etc.)
7797: which apply to the user for whom the default is being retrieved.
7798: If the institutional status string in undefined, the domain
7799: default quota will be returned.
1.472 raeburn 7800:
7801: Returns:
7802: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7803: 2. (Optional) institutional type which determined the value of the
7804: default quota.
1.472 raeburn 7805:
7806: If a value has been stored in the domain's configuration db,
7807: it will return that, otherwise it returns 20 (for backwards
7808: compatibility with domains which have not set up a configuration
7809: db file; the original statically defined portfolio quota was 20 Mb).
7810:
1.536 raeburn 7811: If the user's status includes multiple types (e.g., staff and student),
7812: the largest default quota which applies to the user determines the
7813: default quota returned.
7814:
1.780 raeburn 7815: =back
7816:
1.472 raeburn 7817: =cut
7818:
7819: ###############################################
7820:
7821:
7822: sub default_quota {
1.536 raeburn 7823: my ($udom,$inststatus) = @_;
7824: my ($defquota,$settingstatus);
7825: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7826: ['quotas'],$udom);
7827: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7828: if ($inststatus ne '') {
1.765 raeburn 7829: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7830: foreach my $item (@statuses) {
1.711 raeburn 7831: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7832: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7833: if ($defquota eq '') {
7834: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7835: $settingstatus = $item;
7836: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7837: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7838: $settingstatus = $item;
7839: }
7840: }
7841: } else {
7842: if ($quotahash{'quotas'}{$item} ne '') {
7843: if ($defquota eq '') {
7844: $defquota = $quotahash{'quotas'}{$item};
7845: $settingstatus = $item;
7846: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7847: $defquota = $quotahash{'quotas'}{$item};
7848: $settingstatus = $item;
7849: }
1.536 raeburn 7850: }
7851: }
7852: }
7853: }
7854: if ($defquota eq '') {
1.711 raeburn 7855: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7856: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7857: } else {
7858: $defquota = $quotahash{'quotas'}{'default'};
7859: }
1.536 raeburn 7860: $settingstatus = 'default';
7861: }
7862: } else {
7863: $settingstatus = 'default';
7864: $defquota = 20;
7865: }
7866: if (wantarray) {
7867: return ($defquota,$settingstatus);
1.472 raeburn 7868: } else {
1.536 raeburn 7869: return $defquota;
1.472 raeburn 7870: }
7871: }
7872:
1.384 raeburn 7873: sub get_secgrprole_info {
7874: my ($cdom,$cnum,$needroles,$type) = @_;
7875: my %sections_count = &get_sections($cdom,$cnum);
7876: my @sections = (sort {$a <=> $b} keys(%sections_count));
7877: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7878: my @groups = sort(keys(%curr_groups));
7879: my $allroles = [];
7880: my $rolehash;
7881: my $accesshash = {
7882: active => 'Currently has access',
7883: future => 'Will have future access',
7884: previous => 'Previously had access',
7885: };
7886: if ($needroles) {
7887: $rolehash = {'all' => 'all'};
1.385 albertel 7888: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7889: if (&Apache::lonnet::error(%user_roles)) {
7890: undef(%user_roles);
7891: }
7892: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7893: my ($role)=split(/\:/,$item,2);
7894: if ($role eq 'cr') { next; }
7895: if ($role =~ /^cr/) {
7896: $$rolehash{$role} = (split('/',$role))[3];
7897: } else {
7898: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7899: }
7900: }
7901: foreach my $key (sort(keys(%{$rolehash}))) {
7902: push(@{$allroles},$key);
7903: }
7904: push (@{$allroles},'st');
7905: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7906: }
7907: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7908: }
7909:
1.555 raeburn 7910: sub user_picker {
1.948.2.23 raeburn 7911: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 7912: my $currdom = $dom;
7913: my %curr_selected = (
7914: srchin => 'dom',
1.580 raeburn 7915: srchby => 'lastname',
1.555 raeburn 7916: );
7917: my $srchterm;
1.625 raeburn 7918: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7919: if ($srch->{'srchby'} ne '') {
7920: $curr_selected{'srchby'} = $srch->{'srchby'};
7921: }
7922: if ($srch->{'srchin'} ne '') {
7923: $curr_selected{'srchin'} = $srch->{'srchin'};
7924: }
7925: if ($srch->{'srchtype'} ne '') {
7926: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7927: }
7928: if ($srch->{'srchdomain'} ne '') {
7929: $currdom = $srch->{'srchdomain'};
7930: }
7931: $srchterm = $srch->{'srchterm'};
7932: }
7933: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7934: 'usr' => 'Search criteria',
1.563 raeburn 7935: 'doma' => 'Domain/institution to search',
1.558 albertel 7936: 'uname' => 'username',
7937: 'lastname' => 'last name',
1.555 raeburn 7938: 'lastfirst' => 'last name, first name',
1.558 albertel 7939: 'crs' => 'in this course',
1.576 raeburn 7940: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7941: 'alc' => 'all LON-CAPA',
1.573 raeburn 7942: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7943: 'exact' => 'is',
7944: 'contains' => 'contains',
1.569 raeburn 7945: 'begins' => 'begins with',
1.571 raeburn 7946: 'youm' => "You must include some text to search for.",
7947: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7948: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7949: 'yomc' => "You must choose a domain when using an institutional directory search.",
7950: 'ymcd' => "You must choose a domain when using a domain search.",
7951: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7952: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7953: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7954: );
1.563 raeburn 7955: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7956: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7957:
7958: my @srchins = ('crs','dom','alc','instd');
7959:
7960: foreach my $option (@srchins) {
7961: # FIXME 'alc' option unavailable until
7962: # loncreateuser::print_user_query_page()
7963: # has been completed.
7964: next if ($option eq 'alc');
1.880 raeburn 7965: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7966: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7967: if ($curr_selected{'srchin'} eq $option) {
7968: $srchinsel .= '
7969: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7970: } else {
7971: $srchinsel .= '
7972: <option value="'.$option.'">'.$lt{$option}.'</option>';
7973: }
1.555 raeburn 7974: }
1.563 raeburn 7975: $srchinsel .= "\n </select>\n";
1.555 raeburn 7976:
7977: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7978: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7979: if ($curr_selected{'srchby'} eq $option) {
7980: $srchbysel .= '
7981: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7982: } else {
7983: $srchbysel .= '
7984: <option value="'.$option.'">'.$lt{$option}.'</option>';
7985: }
7986: }
7987: $srchbysel .= "\n </select>\n";
7988:
7989: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7990: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7991: if ($curr_selected{'srchtype'} eq $option) {
7992: $srchtypesel .= '
7993: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7994: } else {
7995: $srchtypesel .= '
7996: <option value="'.$option.'">'.$lt{$option}.'</option>';
7997: }
7998: }
7999: $srchtypesel .= "\n </select>\n";
8000:
1.558 albertel 8001: my ($newuserscript,$new_user_create);
1.948.2.23 raeburn 8002: my $context_dom = $env{'request.role.domain'};
8003: if ($context eq 'requestcrs') {
8004: if ($env{'form.coursedom'} ne '') {
8005: $context_dom = $env{'form.coursedom'};
8006: }
8007: }
1.556 raeburn 8008: if ($forcenewuser) {
1.576 raeburn 8009: if (ref($srch) eq 'HASH') {
1.948.2.23 raeburn 8010: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 8011: if ($cancreate) {
8012: $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>';
8013: } else {
1.799 bisitz 8014: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 8015: my %usertypetext = (
8016: official => 'institutional',
8017: unofficial => 'non-institutional',
8018: );
1.799 bisitz 8019: $new_user_create = '<p class="LC_warning">'
8020: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.948.2.33.2. (raeburn 8021:): .'<br />'
8022:): .&mt('Enter a valid e-mail address as the username for the new user.').' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.'
8023:): ,'<a href="'.$helplink.'">','</a>')
1.799 bisitz 8024: .'</p><br />';
1.627 raeburn 8025: }
1.576 raeburn 8026: }
8027: }
8028:
1.556 raeburn 8029: $newuserscript = <<"ENDSCRIPT";
8030:
1.570 raeburn 8031: function setSearch(createnew,callingForm) {
1.556 raeburn 8032: if (createnew == 1) {
1.570 raeburn 8033: for (var i=0; i<callingForm.srchby.length; i++) {
8034: if (callingForm.srchby.options[i].value == 'uname') {
8035: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8036: }
8037: }
1.570 raeburn 8038: for (var i=0; i<callingForm.srchin.length; i++) {
8039: if ( callingForm.srchin.options[i].value == 'dom') {
8040: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8041: }
8042: }
1.570 raeburn 8043: for (var i=0; i<callingForm.srchtype.length; i++) {
8044: if (callingForm.srchtype.options[i].value == 'exact') {
8045: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8046: }
8047: }
1.570 raeburn 8048: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.948.2.23 raeburn 8049: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8050: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8051: }
8052: }
8053: }
8054: }
8055: ENDSCRIPT
1.558 albertel 8056:
1.556 raeburn 8057: }
8058:
1.555 raeburn 8059: my $output = <<"END_BLOCK";
1.556 raeburn 8060: <script type="text/javascript">
1.824 bisitz 8061: // <![CDATA[
1.570 raeburn 8062: function validateEntry(callingForm) {
1.558 albertel 8063:
1.556 raeburn 8064: var checkok = 1;
1.558 albertel 8065: var srchin;
1.570 raeburn 8066: for (var i=0; i<callingForm.srchin.length; i++) {
8067: if ( callingForm.srchin[i].checked ) {
8068: srchin = callingForm.srchin[i].value;
1.558 albertel 8069: }
8070: }
8071:
1.570 raeburn 8072: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8073: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8074: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8075: var srchterm = callingForm.srchterm.value;
8076: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8077: var msg = "";
8078:
8079: if (srchterm == "") {
8080: checkok = 0;
1.571 raeburn 8081: msg += "$lt{'youm'}\\n";
1.556 raeburn 8082: }
8083:
1.569 raeburn 8084: if (srchtype== 'begins') {
8085: if (srchterm.length < 2) {
8086: checkok = 0;
1.571 raeburn 8087: msg += "$lt{'thte'}\\n";
1.569 raeburn 8088: }
8089: }
8090:
1.556 raeburn 8091: if (srchtype== 'contains') {
8092: if (srchterm.length < 3) {
8093: checkok = 0;
1.571 raeburn 8094: msg += "$lt{'thet'}\\n";
1.556 raeburn 8095: }
8096: }
8097: if (srchin == 'instd') {
8098: if (srchdomain == '') {
8099: checkok = 0;
1.571 raeburn 8100: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8101: }
8102: }
8103: if (srchin == 'dom') {
8104: if (srchdomain == '') {
8105: checkok = 0;
1.571 raeburn 8106: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8107: }
8108: }
8109: if (srchby == 'lastfirst') {
8110: if (srchterm.indexOf(",") == -1) {
8111: checkok = 0;
1.571 raeburn 8112: msg += "$lt{'whus'}\\n";
1.556 raeburn 8113: }
8114: if (srchterm.indexOf(",") == srchterm.length -1) {
8115: checkok = 0;
1.571 raeburn 8116: msg += "$lt{'whse'}\\n";
1.556 raeburn 8117: }
8118: }
8119: if (checkok == 0) {
1.571 raeburn 8120: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8121: return;
8122: }
8123: if (checkok == 1) {
1.570 raeburn 8124: callingForm.submit();
1.556 raeburn 8125: }
8126: }
8127:
8128: $newuserscript
8129:
1.824 bisitz 8130: // ]]>
1.556 raeburn 8131: </script>
1.558 albertel 8132:
8133: $new_user_create
8134:
1.555 raeburn 8135: END_BLOCK
1.558 albertel 8136:
1.876 raeburn 8137: $output .= &Apache::lonhtmlcommon::start_pick_box().
8138: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8139: $domform.
8140: &Apache::lonhtmlcommon::row_closure().
8141: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8142: $srchbysel.
8143: $srchtypesel.
8144: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8145: $srchinsel.
8146: &Apache::lonhtmlcommon::row_closure(1).
8147: &Apache::lonhtmlcommon::end_pick_box().
8148: '<br />';
1.555 raeburn 8149: return $output;
8150: }
8151:
1.612 raeburn 8152: sub user_rule_check {
1.615 raeburn 8153: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8154: my $response;
8155: if (ref($usershash) eq 'HASH') {
8156: foreach my $user (keys(%{$usershash})) {
8157: my ($uname,$udom) = split(/:/,$user);
8158: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8159: my ($id,$newuser);
1.612 raeburn 8160: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8161: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8162: $id = $usershash->{$user}->{'id'};
8163: }
8164: my $inst_response;
8165: if (ref($checks) eq 'HASH') {
8166: if (defined($checks->{'username'})) {
1.615 raeburn 8167: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8168: &Apache::lonnet::get_instuser($udom,$uname);
8169: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8170: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8171: &Apache::lonnet::get_instuser($udom,undef,$id);
8172: }
1.615 raeburn 8173: } else {
8174: ($inst_response,%{$inst_results->{$user}}) =
8175: &Apache::lonnet::get_instuser($udom,$uname);
8176: return;
1.612 raeburn 8177: }
1.615 raeburn 8178: if (!$got_rules->{$udom}) {
1.612 raeburn 8179: my %domconfig = &Apache::lonnet::get_dom('configuration',
8180: ['usercreation'],$udom);
8181: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8182: foreach my $item ('username','id') {
1.612 raeburn 8183: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8184: $$curr_rules{$udom}{$item} =
8185: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8186: }
8187: }
8188: }
1.615 raeburn 8189: $got_rules->{$udom} = 1;
1.585 raeburn 8190: }
1.612 raeburn 8191: foreach my $item (keys(%{$checks})) {
8192: if (ref($$curr_rules{$udom}) eq 'HASH') {
8193: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8194: if (@{$$curr_rules{$udom}{$item}} > 0) {
8195: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8196: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8197: if ($rule_check{$rule}) {
8198: $$rulematch{$user}{$item} = $rule;
8199: if ($inst_response eq 'ok') {
1.615 raeburn 8200: if (ref($inst_results) eq 'HASH') {
8201: if (ref($inst_results->{$user}) eq 'HASH') {
8202: if (keys(%{$inst_results->{$user}}) == 0) {
8203: $$alerts{$item}{$udom}{$uname} = 1;
8204: }
1.612 raeburn 8205: }
8206: }
1.615 raeburn 8207: }
8208: last;
1.585 raeburn 8209: }
8210: }
8211: }
8212: }
8213: }
8214: }
8215: }
8216: }
1.612 raeburn 8217: return;
8218: }
8219:
8220: sub user_rule_formats {
8221: my ($domain,$domdesc,$curr_rules,$check) = @_;
8222: my %text = (
8223: 'username' => 'Usernames',
8224: 'id' => 'IDs',
8225: );
8226: my $output;
8227: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8228: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8229: if (@{$ruleorder} > 0) {
8230: $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>';
8231: foreach my $rule (@{$ruleorder}) {
8232: if (ref($curr_rules) eq 'ARRAY') {
8233: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8234: if (ref($rules->{$rule}) eq 'HASH') {
8235: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8236: $rules->{$rule}{'desc'}.'</li>';
8237: }
8238: }
8239: }
8240: }
8241: $output .= '</ul>';
8242: }
8243: }
8244: return $output;
8245: }
8246:
8247: sub instrule_disallow_msg {
1.615 raeburn 8248: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8249: my $response;
8250: my %text = (
8251: item => 'username',
8252: items => 'usernames',
8253: match => 'matches',
8254: do => 'does',
8255: action => 'a username',
8256: one => 'one',
8257: );
8258: if ($count > 1) {
8259: $text{'item'} = 'usernames';
8260: $text{'match'} ='match';
8261: $text{'do'} = 'do';
8262: $text{'action'} = 'usernames',
8263: $text{'one'} = 'ones';
8264: }
8265: if ($checkitem eq 'id') {
8266: $text{'items'} = 'IDs';
8267: $text{'item'} = 'ID';
8268: $text{'action'} = 'an ID';
1.615 raeburn 8269: if ($count > 1) {
8270: $text{'item'} = 'IDs';
8271: $text{'action'} = 'IDs';
8272: }
1.612 raeburn 8273: }
1.674 bisitz 8274: $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 8275: if ($mode eq 'upload') {
8276: if ($checkitem eq 'username') {
8277: $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'}.");
8278: } elsif ($checkitem eq 'id') {
1.674 bisitz 8279: $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 8280: }
1.669 raeburn 8281: } elsif ($mode eq 'selfcreate') {
8282: if ($checkitem eq 'id') {
8283: $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.");
8284: }
1.615 raeburn 8285: } else {
8286: if ($checkitem eq 'username') {
8287: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8288: } elsif ($checkitem eq 'id') {
8289: $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.");
8290: }
1.612 raeburn 8291: }
8292: return $response;
1.585 raeburn 8293: }
8294:
1.624 raeburn 8295: sub personal_data_fieldtitles {
8296: my %fieldtitles = &Apache::lonlocal::texthash (
8297: id => 'Student/Employee ID',
8298: permanentemail => 'E-mail address',
8299: lastname => 'Last Name',
8300: firstname => 'First Name',
8301: middlename => 'Middle Name',
8302: generation => 'Generation',
8303: gen => 'Generation',
1.765 raeburn 8304: inststatus => 'Affiliation',
1.624 raeburn 8305: );
8306: return %fieldtitles;
8307: }
8308:
1.642 raeburn 8309: sub sorted_inst_types {
8310: my ($dom) = @_;
8311: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8312: my $othertitle = &mt('All users');
8313: if ($env{'request.course.id'}) {
1.668 raeburn 8314: $othertitle = &mt('Any users');
1.642 raeburn 8315: }
8316: my @types;
8317: if (ref($order) eq 'ARRAY') {
8318: @types = @{$order};
8319: }
8320: if (@types == 0) {
8321: if (ref($usertypes) eq 'HASH') {
8322: @types = sort(keys(%{$usertypes}));
8323: }
8324: }
8325: if (keys(%{$usertypes}) > 0) {
8326: $othertitle = &mt('Other users');
8327: }
8328: return ($othertitle,$usertypes,\@types);
8329: }
8330:
1.645 raeburn 8331: sub get_institutional_codes {
8332: my ($settings,$allcourses,$LC_code) = @_;
8333: # Get complete list of course sections to update
8334: my @currsections = ();
8335: my @currxlists = ();
8336: my $coursecode = $$settings{'internal.coursecode'};
8337:
8338: if ($$settings{'internal.sectionnums'} ne '') {
8339: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8340: }
8341:
8342: if ($$settings{'internal.crosslistings'} ne '') {
8343: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8344: }
8345:
8346: if (@currxlists > 0) {
8347: foreach (@currxlists) {
8348: if (m/^([^:]+):(\w*)$/) {
8349: unless (grep/^$1$/,@{$allcourses}) {
8350: push @{$allcourses},$1;
8351: $$LC_code{$1} = $2;
8352: }
8353: }
8354: }
8355: }
8356:
8357: if (@currsections > 0) {
8358: foreach (@currsections) {
8359: if (m/^(\w+):(\w*)$/) {
8360: my $sec = $coursecode.$1;
8361: my $lc_sec = $2;
8362: unless (grep/^$sec$/,@{$allcourses}) {
8363: push @{$allcourses},$sec;
8364: $$LC_code{$sec} = $lc_sec;
8365: }
8366: }
8367: }
8368: }
8369: return;
8370: }
8371:
1.948.2.7 raeburn 8372: sub get_standard_codeitems {
8373: return ('Year','Semester','Department','Number','Section');
8374: }
8375:
1.112 bowersj2 8376: =pod
8377:
1.780 raeburn 8378: =head1 Slot Helpers
8379:
8380: =over 4
8381:
8382: =item * sorted_slots()
8383:
8384: Sorts an array of slot names in order of slot start time (earliest first).
8385:
8386: Inputs:
8387:
8388: =over 4
8389:
8390: slotsarr - Reference to array of unsorted slot names.
8391:
8392: slots - Reference to hash of hash, where outer hash keys are slot names.
8393:
1.549 albertel 8394: =back
8395:
1.780 raeburn 8396: Returns:
8397:
8398: =over 4
8399:
8400: sorted - An array of slot names sorted by the start time of the slot.
8401:
8402: =back
8403:
8404: =back
8405:
8406: =cut
8407:
8408:
8409: sub sorted_slots {
8410: my ($slotsarr,$slots) = @_;
8411: my @sorted;
8412: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8413: @sorted =
8414: sort {
8415: if (ref($slots->{$a}) && ref($slots->{$b})) {
8416: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8417: }
8418: if (ref($slots->{$a})) { return -1;}
8419: if (ref($slots->{$b})) { return 1;}
8420: return 0;
8421: } @{$slotsarr};
8422: }
8423: return @sorted;
8424: }
8425:
8426:
8427: =pod
8428:
1.549 albertel 8429: =head1 HTTP Helpers
8430:
8431: =over 4
8432:
1.648 raeburn 8433: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8434:
1.258 albertel 8435: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8436: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8437: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8438:
8439: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8440: $possible_names is an ref to an array of form element names. As an example:
8441: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8442: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8443:
8444: =cut
1.1 albertel 8445:
1.6 albertel 8446: sub get_unprocessed_cgi {
1.25 albertel 8447: my ($query,$possible_names)= @_;
1.26 matthew 8448: # $Apache::lonxml::debug=1;
1.356 albertel 8449: foreach my $pair (split(/&/,$query)) {
8450: my ($name, $value) = split(/=/,$pair);
1.369 www 8451: $name = &unescape($name);
1.25 albertel 8452: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8453: $value =~ tr/+/ /;
8454: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8455: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8456: }
1.16 harris41 8457: }
1.6 albertel 8458: }
8459:
1.112 bowersj2 8460: =pod
8461:
1.648 raeburn 8462: =item * &cacheheader()
1.112 bowersj2 8463:
8464: returns cache-controlling header code
8465:
8466: =cut
8467:
1.7 albertel 8468: sub cacheheader {
1.258 albertel 8469: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8470: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8471: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8472: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8473: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8474: return $output;
1.7 albertel 8475: }
8476:
1.112 bowersj2 8477: =pod
8478:
1.648 raeburn 8479: =item * &no_cache($r)
1.112 bowersj2 8480:
8481: specifies header code to not have cache
8482:
8483: =cut
8484:
1.9 albertel 8485: sub no_cache {
1.216 albertel 8486: my ($r) = @_;
8487: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8488: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8489: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8490: $r->no_cache(1);
8491: $r->header_out("Expires" => $date);
8492: $r->header_out("Pragma" => "no-cache");
1.123 www 8493: }
8494:
8495: sub content_type {
1.181 albertel 8496: my ($r,$type,$charset) = @_;
1.299 foxr 8497: if ($r) {
8498: # Note that printout.pl calls this with undef for $r.
8499: &no_cache($r);
8500: }
1.258 albertel 8501: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8502: unless ($charset) {
8503: $charset=&Apache::lonlocal::current_encoding;
8504: }
8505: if ($charset) { $type.='; charset='.$charset; }
8506: if ($r) {
8507: $r->content_type($type);
8508: } else {
8509: print("Content-type: $type\n\n");
8510: }
1.9 albertel 8511: }
1.25 albertel 8512:
1.112 bowersj2 8513: =pod
8514:
1.648 raeburn 8515: =item * &add_to_env($name,$value)
1.112 bowersj2 8516:
1.258 albertel 8517: adds $name to the %env hash with value
1.112 bowersj2 8518: $value, if $name already exists, the entry is converted to an array
8519: reference and $value is added to the array.
8520:
8521: =cut
8522:
1.25 albertel 8523: sub add_to_env {
8524: my ($name,$value)=@_;
1.258 albertel 8525: if (defined($env{$name})) {
8526: if (ref($env{$name})) {
1.25 albertel 8527: #already have multiple values
1.258 albertel 8528: push(@{ $env{$name} },$value);
1.25 albertel 8529: } else {
8530: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8531: my $first=$env{$name};
8532: undef($env{$name});
8533: push(@{ $env{$name} },$first,$value);
1.25 albertel 8534: }
8535: } else {
1.258 albertel 8536: $env{$name}=$value;
1.25 albertel 8537: }
1.31 albertel 8538: }
1.149 albertel 8539:
8540: =pod
8541:
1.648 raeburn 8542: =item * &get_env_multiple($name)
1.149 albertel 8543:
1.258 albertel 8544: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8545: values may be defined and end up as an array ref.
8546:
8547: returns an array of values
8548:
8549: =cut
8550:
8551: sub get_env_multiple {
8552: my ($name) = @_;
8553: my @values;
1.258 albertel 8554: if (defined($env{$name})) {
1.149 albertel 8555: # exists is it an array
1.258 albertel 8556: if (ref($env{$name})) {
8557: @values=@{ $env{$name} };
1.149 albertel 8558: } else {
1.258 albertel 8559: $values[0]=$env{$name};
1.149 albertel 8560: }
8561: }
8562: return(@values);
8563: }
8564:
1.660 raeburn 8565: sub ask_for_embedded_content {
8566: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.948.2.17 raeburn 8567: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660 raeburn 8568: my $num = 0;
1.948.2.17 raeburn 8569: my $numremref = 0;
8570: my $numinvalid = 0;
8571: my $numpathchg = 0;
8572: my $numexisting = 0;
8573: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.948.2.12 raeburn 8574: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8575: my $current_path='/';
8576: if ($env{'form.currentpath'}) {
8577: $current_path = $env{'form.currentpath'};
8578: }
8579: if ($actionurl eq '/adm/coursegrp_portfolio') {
8580: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8581: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8582: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8583: } else {
8584: $udom = $env{'user.domain'};
8585: $uname = $env{'user.name'};
8586: $url = '/userfiles/portfolio';
8587: }
1.948.2.17 raeburn 8588: $toplevel = $url.'/';
1.948.2.12 raeburn 8589: $url .= $current_path;
8590: $getpropath = 1;
1.948.2.17 raeburn 8591: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8592: ($actionurl eq '/adm/imsimport')) {
1.948.2.12 raeburn 8593: ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
1.948.2.17 raeburn 8594: $url = '/home/'.$uname.'/public_html/';
8595: $toplevel = $url;
1.948.2.12 raeburn 8596: if ($rest ne '') {
1.948.2.17 raeburn 8597: $url .= $rest;
8598: }
8599: } elsif ($actionurl eq '/adm/coursedocs') {
8600: if (ref($args) eq 'HASH') {
8601: $url = $args->{'docs_url'};
8602: $toplevel = $url;
8603: }
8604: }
8605: my $now = time();
8606: foreach my $embed_file (keys(%{$allfiles})) {
8607: my $absolutepath;
8608: if ($embed_file =~ m{^\w+://}) {
8609: $newfiles{$embed_file} = 1;
8610: $mapping{$embed_file} = $embed_file;
8611: } else {
8612: if ($embed_file =~ m{^/}) {
8613: $absolutepath = $embed_file;
8614: $embed_file =~ s{^(/+)}{};
8615: }
8616: if ($embed_file =~ m{/}) {
8617: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8618: $path = &check_for_traversal($path,$url,$toplevel);
8619: my $item = $fname;
8620: if ($path ne '') {
8621: $item = $path.'/'.$fname;
8622: $subdependencies{$path}{$fname} = 1;
8623: } else {
8624: $dependencies{$item} = 1;
8625: }
8626: if ($absolutepath) {
8627: $mapping{$item} = $absolutepath;
8628: } else {
8629: $mapping{$item} = $embed_file;
8630: }
8631: } else {
8632: $dependencies{$embed_file} = 1;
8633: if ($absolutepath) {
8634: $mapping{$embed_file} = $absolutepath;
8635: } else {
8636: $mapping{$embed_file} = $embed_file;
8637: }
8638: }
1.948.2.12 raeburn 8639: }
8640: }
8641: foreach my $path (keys(%subdependencies)) {
8642: my %currsubfile;
8643: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8644: my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8645: foreach my $line (@subdir_list) {
8646: my ($file_name,$rest) = split(/\&/,$line,2);
8647: $currsubfile{$file_name} = 1;
8648: }
1.948.2.17 raeburn 8649: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.948.2.12 raeburn 8650: if (opendir(my $dir,$url.'/'.$path)) {
8651: my @subdir_list = grep(!/^\./,readdir($dir));
8652: map {$currsubfile{$_} = 1;} @subdir_list;
8653: }
8654: }
8655: foreach my $file (keys(%{$subdependencies{$path}})) {
1.948.2.17 raeburn 8656: if ($currsubfile{$file}) {
8657: my $item = $path.'/'.$file;
8658: unless ($mapping{$item} eq $item) {
8659: $pathchanges{$item} = 1;
8660: }
8661: $existing{$item} = 1;
8662: $numexisting ++;
8663: } else {
8664: $newfiles{$path.'/'.$file} = 1;
1.948.2.12 raeburn 8665: }
8666: }
8667: }
1.948.2.17 raeburn 8668: my %currfile;
1.948.2.12 raeburn 8669: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8670: my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8671: foreach my $line (@dir_list) {
8672: my ($file_name,$rest) = split(/\&/,$line,2);
8673: $currfile{$file_name} = 1;
8674: }
1.948.2.17 raeburn 8675: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.948.2.12 raeburn 8676: if (opendir(my $dir,$url)) {
1.948.2.17 raeburn 8677: my @dir_list = grep(!/^\./,readdir($dir));
1.948.2.12 raeburn 8678: map {$currfile{$_} = 1;} @dir_list;
8679: }
8680: }
8681: foreach my $file (keys(%dependencies)) {
1.948.2.17 raeburn 8682: if ($currfile{$file}) {
8683: unless ($mapping{$file} eq $file) {
8684: $pathchanges{$file} = 1;
8685: }
8686: $existing{$file} = 1;
8687: $numexisting ++;
8688: } else {
1.948.2.12 raeburn 8689: $newfiles{$file} = 1;
8690: }
8691: }
8692: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8693: $upload_output .= &start_data_table_row().
1.948.2.17 raeburn 8694: '<td><span class="LC_filename">'.$embed_file.'</span>';
8695: unless ($mapping{$embed_file} eq $embed_file) {
8696: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
8697: }
8698: $upload_output .= '</td><td>';
1.660 raeburn 8699: if ($args->{'ignore_remote_references'}
8700: && $embed_file =~ m{^\w+://}) {
8701: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.948.2.17 raeburn 8702: $numremref++;
1.660 raeburn 8703: } elsif ($args->{'error_on_invalid_names'}
8704: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8705:
1.948.2.17 raeburn 8706: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
8707: $numinvalid++;
1.660 raeburn 8708: } else {
1.948.2.17 raeburn 8709: $upload_output .= &embedded_file_element('upload_embedded',$num,
8710: $embed_file,\%mapping,
8711: $allfiles,$codebase);
8712: $num++;
1.660 raeburn 8713: }
1.948.2.12 raeburn 8714: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
1.660 raeburn 8715: }
1.948.2.17 raeburn 8716: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
8717: $upload_output .= &start_data_table_row().
8718: '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
8719: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
8720: &Apache::loncommon::end_data_table_row()."\n";
8721: }
8722: if ($upload_output) {
8723: $upload_output = &start_data_table().
1.948.2.12 raeburn 8724: $upload_output.
1.948.2.17 raeburn 8725: &end_data_table()."\n";
8726: }
8727: my $applies = 0;
8728: if ($numremref) {
8729: $applies ++;
8730: }
8731: if ($numinvalid) {
8732: $applies ++;
8733: }
8734: if ($numexisting) {
8735: $applies ++;
8736: }
8737: if ($num) {
8738: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8739: ' method="post" enctype="multipart/form-data">'."\n".
8740: $state.
8741: '<h3>'.&mt('Upload embedded files').
8742: ':</h3>'.$upload_output.'<br />'."\n".
8743: '<input type ="hidden" name="number_embedded_items" value="'.
8744: $num.'" />'."\n";
8745: if ($actionurl eq '') {
8746: $output .= '<input type="hidden" name="phase" value="three" />';
8747: }
8748: } elsif ($applies) {
8749: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
8750: if ($applies > 1) {
8751: $output .=
8752: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
8753: if ($numremref) {
8754: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
8755: }
8756: if ($numinvalid) {
8757: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
8758: }
8759: if ($numexisting) {
8760: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
8761: }
8762: $output .= '</ul><br />';
8763: } elsif ($numremref) {
8764: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
8765: } elsif ($numinvalid) {
8766: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
8767: } elsif ($numexisting) {
8768: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
8769: }
8770: $output .= $upload_output.'<br />';
8771: }
8772: my ($pathchange_output,$chgcount);
8773: $chgcount = $num;
8774: if (keys(%pathchanges) > 0) {
8775: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
8776: if ($num) {
8777: $output .= &embedded_file_element('pathchange',$chgcount,
8778: $embed_file,\%mapping,
8779: $allfiles,$codebase);
8780: } else {
8781: $pathchange_output .=
8782: &start_data_table_row().
8783: '<td><input type ="checkbox" name="namechange" value="'.
8784: $chgcount.'" checked="checked" /></td>'.
8785: '<td>'.$mapping{$embed_file}.'</td>'.
8786: '<td>'.$embed_file.
8787: &embedded_file_element('pathchange',$numpathchg,$embed_file,
8788: \%mapping,$allfiles,$codebase).
8789: '</td>'.&end_data_table_row();
8790: }
8791: $numpathchg ++;
8792: $chgcount ++;
8793: }
8794: }
8795: if ($num) {
8796: if ($numpathchg) {
8797: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
8798: $numpathchg.'" />'."\n";
8799: }
8800: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8801: ($actionurl eq '/adm/imsimport')) {
8802: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
8803: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
8804: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
8805: }
8806: $output .= '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8807: &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
8808: } elsif ($numpathchg) {
8809: my %pathchange = ();
8810: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
8811: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8812: $output .= '<p>'.&mt('or').'</p>';
8813: }
8814: }
8815: return ($output,$num,$numpathchg);
8816: }
8817:
8818: sub embedded_file_element {
8819: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
8820: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
8821: (ref($codebase) eq 'HASH'));
8822: my $output;
8823: if ($context eq 'upload_embedded') {
8824: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
8825: }
8826: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
8827: &escape($embed_file).'" />';
8828: unless (($context eq 'upload_embedded') &&
8829: ($mapping->{$embed_file} eq $embed_file)) {
8830: $output .='
8831: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
8832: }
8833: my $attrib;
8834: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
8835: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
1.948.2.12 raeburn 8836: }
1.948.2.17 raeburn 8837: $output .=
8838: "\n\t\t".
8839: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8840: $attrib.'" />';
8841: if (exists($codebase->{$mapping->{$embed_file}})) {
8842: $output .=
8843: "\n\t\t".
8844: '<input name="codebase_'.$num.'" type="hidden" value="'.
8845: &escape($codebase->{$mapping->{$embed_file}}).'" />';
8846: }
8847: return $output;
1.660 raeburn 8848: }
8849:
1.661 raeburn 8850: sub upload_embedded {
8851: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.948.2.17 raeburn 8852: $current_disk_usage,$hiddenstate,$actionurl) = @_;
8853: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 8854: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8855: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8856: my $orig_uploaded_filename =
8857: $env{'form.embedded_item_'.$i.'.filename'};
1.948.2.17 raeburn 8858: foreach my $type ('orig','ref','attrib','codebase') {
8859: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
8860: $env{'form.embedded_'.$type.'_'.$i} =
8861: &unescape($env{'form.embedded_'.$type.'_'.$i});
8862: }
8863: }
1.661 raeburn 8864: my ($path,$fname) =
8865: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8866: # no path, whole string is fname
8867: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8868: $fname = &Apache::lonnet::clean_filename($fname);
8869: # See if there is anything left
8870: next if ($fname eq '');
8871:
8872: # Check if file already exists as a file or directory.
8873: my ($state,$msg);
8874: if ($context eq 'portfolio') {
8875: my $port_path = $dirpath;
8876: if ($group ne '') {
8877: $port_path = "groups/$group/$port_path";
8878: }
1.948.2.17 raeburn 8879: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
8880: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 8881: $dir_root,$port_path,$disk_quota,
8882: $current_disk_usage,$uname,$udom);
8883: if ($state eq 'will_exceed_quota'
1.948.2.12 raeburn 8884: || $state eq 'file_locked') {
1.661 raeburn 8885: $output .= $msg;
8886: next;
8887: }
8888: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8889: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8890: if ($state eq 'exists') {
8891: $output .= $msg;
8892: next;
8893: }
8894: }
8895: # Check if extension is valid
8896: if (($fname =~ /\.(\w+)$/) &&
8897: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.948.2.17 raeburn 8898: $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 8899: next;
8900: } elsif (($fname =~ /\.(\w+)$/) &&
8901: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.948.2.17 raeburn 8902: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 8903: next;
8904: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.948.2.17 raeburn 8905: $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 8906: next;
8907: }
8908:
8909: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8910: if ($context eq 'portfolio') {
1.948.2.12 raeburn 8911: my $result;
8912: if ($state eq 'existingfile') {
8913: $result=
8914: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.948.2.17 raeburn 8915: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 8916: } else {
1.948.2.12 raeburn 8917: $result=
8918: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.948.2.17 raeburn 8919: $dirpath.
8920: $env{'form.currentpath'}.$path);
1.948.2.12 raeburn 8921: if ($result !~ m|^/uploaded/|) {
8922: $output .= '<span class="LC_error">'
8923: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8924: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8925: .'</span><br />';
8926: next;
8927: } else {
1.948.2.17 raeburn 8928: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8929: $path.$fname.'</span>').'<br />';
1.948.2.12 raeburn 8930: }
1.661 raeburn 8931: }
1.948.2.17 raeburn 8932: } elsif ($context eq 'coursedoc') {
8933: my $result =
8934: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
8935: $dirpath.'/'.$path);
8936: if ($result !~ m|^/uploaded/|) {
8937: $output .= '<span class="LC_error">'
8938: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8939: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8940: .'</span><br />';
8941: next;
8942: } else {
8943: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8944: $path.$fname.'</span>').'<br />';
8945: }
1.661 raeburn 8946: } else {
8947: # Save the file
8948: my $target = $env{'form.embedded_item_'.$i};
8949: my $fullpath = $dir_root.$dirpath.'/'.$path;
8950: my $dest = $fullpath.$fname;
8951: my $url = $url_root.$dirpath.'/'.$path.$fname;
8952: my @parts=split(/\//,$fullpath);
8953: my $count;
8954: my $filepath = $dir_root;
8955: for ($count=4;$count<=$#parts;$count++) {
8956: $filepath .= "/$parts[$count]";
8957: if ((-e $filepath)!=1) {
8958: mkdir($filepath,0770);
8959: }
8960: }
8961: my $fh;
8962: if (!open($fh,'>'.$dest)) {
8963: &Apache::lonnet::logthis('Failed to create '.$dest);
8964: $output .= '<span class="LC_error">'.
8965: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8966: '</span><br />';
8967: } else {
8968: if (!print $fh $env{'form.embedded_item_'.$i}) {
8969: &Apache::lonnet::logthis('Failed to write to '.$dest);
8970: $output .= '<span class="LC_error">'.
8971: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8972: '</span><br />';
8973: } else {
1.948.2.17 raeburn 8974: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8975: $url.'</span>').'<br />';
8976: unless ($context eq 'testbank') {
8977: $footer .= &mt('View embedded file: [_1]',
8978: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
1.661 raeburn 8979: }
8980: }
8981: close($fh);
8982: }
8983: }
1.948.2.17 raeburn 8984: if ($env{'form.embedded_ref_'.$i}) {
8985: $pathchange{$i} = 1;
8986: }
1.948.2.18 raeburn 8987: }
1.948.2.17 raeburn 8988: if ($output) {
8989: $output = '<p>'.$output.'</p>';
8990: }
8991: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
8992: $returnflag = 'ok';
8993: if (keys(%pathchange) > 0) {
8994: if ($context eq 'portfolio') {
8995: $output .= '<p>'.&mt('or').'</p>';
8996: } elsif ($context eq 'testbank') {
8997: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
8998: $returnflag = 'modify_orightml';
8999: }
9000: }
9001: return ($output.$footer,$returnflag);
9002: }
9003:
9004: sub modify_html_form {
9005: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
9006: my $end = 0;
9007: my $modifyform;
9008: if ($context eq 'upload_embedded') {
9009: return unless (ref($pathchange) eq 'HASH');
9010: if ($env{'form.number_embedded_items'}) {
9011: $end += $env{'form.number_embedded_items'};
9012: }
9013: if ($env{'form.number_pathchange_items'}) {
9014: $end += $env{'form.number_pathchange_items'};
9015: }
9016: if ($end) {
9017: for (my $i=0; $i<$end; $i++) {
9018: if ($i < $env{'form.number_embedded_items'}) {
9019: next unless($pathchange->{$i});
9020: }
9021: $modifyform .=
9022: &start_data_table_row().
9023: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
9024: 'checked="checked" /></td>'.
9025: '<td>'.$env{'form.embedded_ref_'.$i}.
9026: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
9027: &escape($env{'form.embedded_ref_'.$i}).'" />'.
9028: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
9029: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
9030: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
9031: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
9032: '<td>'.$env{'form.embedded_orig_'.$i}.
9033: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
9034: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
9035: &end_data_table_row();
9036: }
9037: }
9038: } else {
9039: $modifyform = $pathchgtable;
9040: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
9041: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
9042: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9043: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
9044: }
9045: }
9046: if ($modifyform) {
9047: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
9048: '<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".
9049: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
9050: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
9051: '</ol></p>'."\n".'<p>'.
9052: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
9053: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
9054: &start_data_table()."\n".
9055: &start_data_table_header_row().
9056: '<th>'.&mt('Change?').'</th>'.
9057: '<th>'.&mt('Current reference').'</th>'.
9058: '<th>'.&mt('Required reference').'</th>'.
9059: &end_data_table_header_row()."\n".
9060: $modifyform.
9061: &end_data_table().'<br />'."\n".$hiddenstate.
9062: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
9063: '</form>'."\n";
9064: }
9065: return;
9066: }
9067:
9068: sub modify_html_refs {
9069: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
9070: my $container;
9071: if ($context eq 'portfolio') {
9072: $container = $env{'form.container'};
9073: } elsif ($context eq 'coursedoc') {
9074: $container = $env{'form.primaryurl'};
9075: } else {
9076: $container = $env{'form.filename'};
9077: $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
9078: }
9079: my (%allfiles,%codebase,$output,$content);
9080: my @changes = &get_env_multiple('form.namechange');
9081: return unless (@changes > 0);
9082: if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
9083: return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
9084: $content = &Apache::lonnet::getfile($container);
9085: return if ($content eq '-1');
9086: } else {
9087: return unless ($container =~ /^\Q$dir_root\E/);
9088: if (open(my $fh,"<$container")) {
9089: $content = join('', <$fh>);
9090: close($fh);
9091: } else {
9092: return;
9093: }
9094: }
9095: my ($count,$codebasecount) = (0,0);
9096: my $mm = new File::MMagic;
9097: my $mime_type = $mm->checktype_contents($content);
9098: if ($mime_type eq 'text/html') {
9099: my $parse_result =
9100: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
9101: \%codebase,\$content);
9102: if ($parse_result eq 'ok') {
9103: foreach my $i (@changes) {
9104: my $orig = &unescape($env{'form.embedded_orig_'.$i});
9105: my $ref = &unescape($env{'form.embedded_ref_'.$i});
9106: if ($allfiles{$ref}) {
9107: my $newname = $orig;
9108: my ($attrib_regexp,$codebase);
1.948.2.28 raeburn 9109: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.948.2.17 raeburn 9110: if ($attrib_regexp =~ /:/) {
9111: $attrib_regexp =~ s/\:/|/g;
9112: }
9113: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
9114: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
9115: $count += $numchg;
9116: }
9117: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.948.2.28 raeburn 9118: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.948.2.17 raeburn 9119: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
9120: $codebasecount ++;
9121: }
9122: }
9123: }
9124: if ($count || $codebasecount) {
9125: my $saveresult;
9126: if ($context eq 'portfolio' || $context eq 'coursedoc') {
9127: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
9128: if ($url eq $container) {
9129: my ($fname) = ($container =~ m{/([^/]+)$});
9130: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9131: $count,'<span class="LC_filename">'.
9132: $fname.'</span>').'</p>';
9133: } else {
9134: $output = '<p class="LC_error">'.
9135: &mt('Error: update failed for: [_1].',
9136: '<span class="LC_filename">'.
9137: $container.'</span>').'</p>';
9138: }
9139: } else {
9140: if (open(my $fh,">$container")) {
9141: print $fh $content;
9142: close($fh);
9143: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9144: $count,'<span class="LC_filename">'.
9145: $container.'</span>').'</p>';
9146: } else {
9147: $output = '<p class="LC_error">'.
9148: &mt('Error: could not update [_1].',
9149: '<span class="LC_filename">'.
9150: $container.'</span>').'</p>';
9151: }
9152: }
9153: }
9154: } else {
9155: &logthis('Failed to parse '.$container.
9156: ' to modify references: '.$parse_result);
9157: }
1.661 raeburn 9158: }
9159: return $output;
9160: }
9161:
9162: sub check_for_existing {
9163: my ($path,$fname,$element) = @_;
9164: my ($state,$msg);
9165: if (-d $path.'/'.$fname) {
9166: $state = 'exists';
9167: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9168: } elsif (-e $path.'/'.$fname) {
9169: $state = 'exists';
9170: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9171: }
9172: if ($state eq 'exists') {
9173: $msg = '<span class="LC_error">'.$msg.'</span><br />';
9174: }
9175: return ($state,$msg);
9176: }
9177:
9178: sub check_for_upload {
9179: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
9180: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.948.2.12 raeburn 9181: my $filesize = length($env{'form.'.$element});
9182: if (!$filesize) {
9183: my $msg = '<span class="LC_error">'.
9184: &mt('Unable to upload [_1]. (size = [_2] bytes)',
9185: '<span class="LC_filename">'.$fname.'</span>',
9186: $filesize).'<br />'.
1.948.2.29 raeburn 9187: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.948.2.12 raeburn 9188: '</span>';
9189: return ('zero_bytes',$msg);
9190: }
9191: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 9192: my $getpropath = 1;
9193: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
9194: $getpropath);
9195: my $found_file = 0;
9196: my $locked_file = 0;
1.948.2.20 raeburn 9197: my @lockers;
9198: my $navmap;
9199: if ($env{'request.course.id'}) {
9200: $navmap = Apache::lonnavmaps::navmap->new();
9201: }
1.661 raeburn 9202: foreach my $line (@dir_list) {
1.948.2.12 raeburn 9203: my ($file_name,$rest)=split(/\&/,$line,2);
1.661 raeburn 9204: if ($file_name eq $fname){
9205: $file_name = $path.$file_name;
9206: if ($group ne '') {
9207: $file_name = $group.$file_name;
9208: }
9209: $found_file = 1;
1.948.2.20 raeburn 9210: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
9211: foreach my $lock (@lockers) {
9212: if (ref($lock) eq 'ARRAY') {
9213: my ($symb,$crsid) = @{$lock};
9214: if ($crsid eq $env{'request.course.id'}) {
9215: if (ref($navmap)) {
9216: my $res = $navmap->getBySymb($symb);
9217: foreach my $part (@{$res->parts()}) {
9218: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
9219: unless (($slot_status == $res->RESERVED) ||
9220: ($slot_status == $res->RESERVED_LOCATION)) {
9221: $locked_file = 1;
9222: }
9223: }
9224: } else {
9225: $locked_file = 1;
9226: }
9227: } else {
9228: $locked_file = 1;
9229: }
9230: }
9231: }
1.948.2.12 raeburn 9232: } else {
9233: my @info = split(/\&/,$rest);
9234: my $currsize = $info[6]/1000;
9235: if ($currsize < $filesize) {
9236: my $extra = $filesize - $currsize;
9237: if (($current_disk_usage + $extra) > $disk_quota) {
9238: my $msg = '<span class="LC_error">'.
9239: &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.',
9240: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
9241: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
9242: $disk_quota,$current_disk_usage);
9243: return ('will_exceed_quota',$msg);
9244: }
9245: }
1.661 raeburn 9246: }
9247: }
9248: }
9249: if (($current_disk_usage + $filesize) > $disk_quota){
9250: my $msg = '<span class="LC_error">'.
9251: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
9252: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
9253: return ('will_exceed_quota',$msg);
9254: } elsif ($found_file) {
9255: if ($locked_file) {
9256: my $msg = '<span class="LC_error">';
9257: $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>');
9258: $msg .= '</span><br />';
9259: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
9260: return ('file_locked',$msg);
9261: } else {
9262: my $msg = '<span class="LC_error">';
1.948.2.12 raeburn 9263: $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 9264: $msg .= '</span>';
1.948.2.12 raeburn 9265: return ('existingfile',$msg);
1.661 raeburn 9266: }
9267: }
9268: }
9269:
1.948.2.17 raeburn 9270: sub check_for_traversal {
9271: my ($path,$url,$toplevel) = @_;
9272: my @parts=split(/\//,$path);
9273: my $cleanpath;
9274: my $fullpath = $url;
9275: for (my $i=0;$i<@parts;$i++) {
9276: next if ($parts[$i] eq '.');
9277: if ($parts[$i] eq '..') {
9278: $fullpath =~ s{([^/]+/)$}{};
9279: } else {
9280: $fullpath .= $parts[$i].'/';
9281: }
9282: }
9283: if ($fullpath =~ /^\Q$url\E(.*)$/) {
9284: $cleanpath = $1;
9285: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
9286: my $curr_toprel = $1;
9287: my @parts = split(/\//,$curr_toprel);
9288: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
9289: my @urlparts = split(/\//,$url_toprel);
9290: my $doubledots;
9291: my $startdiff = -1;
9292: for (my $i=0; $i<@urlparts; $i++) {
9293: if ($startdiff == -1) {
9294: unless ($urlparts[$i] eq $parts[$i]) {
9295: $startdiff = $i;
9296: $doubledots .= '../';
9297: }
9298: } else {
9299: $doubledots .= '../';
9300: }
9301: }
9302: if ($startdiff > -1) {
9303: $cleanpath = $doubledots;
9304: for (my $i=$startdiff; $i<@parts; $i++) {
9305: $cleanpath .= $parts[$i].'/';
9306: }
9307: }
9308: }
9309: $cleanpath =~ s{(/)$}{};
9310: return $cleanpath;
9311: }
1.31 albertel 9312:
1.41 ng 9313: =pod
1.45 matthew 9314:
1.464 albertel 9315: =back
1.41 ng 9316:
1.112 bowersj2 9317: =head1 CSV Upload/Handling functions
1.38 albertel 9318:
1.41 ng 9319: =over 4
9320:
1.648 raeburn 9321: =item * &upfile_store($r)
1.41 ng 9322:
9323: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 9324: needs $env{'form.upfile'}
1.41 ng 9325: returns $datatoken to be put into hidden field
9326:
9327: =cut
1.31 albertel 9328:
9329: sub upfile_store {
9330: my $r=shift;
1.258 albertel 9331: $env{'form.upfile'}=~s/\r/\n/gs;
9332: $env{'form.upfile'}=~s/\f/\n/gs;
9333: $env{'form.upfile'}=~s/\n+/\n/gs;
9334: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 9335:
1.258 albertel 9336: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
9337: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 9338: {
1.158 raeburn 9339: my $datafile = $r->dir_config('lonDaemons').
9340: '/tmp/'.$datatoken.'.tmp';
9341: if ( open(my $fh,">$datafile") ) {
1.258 albertel 9342: print $fh $env{'form.upfile'};
1.158 raeburn 9343: close($fh);
9344: }
1.31 albertel 9345: }
9346: return $datatoken;
9347: }
9348:
1.56 matthew 9349: =pod
9350:
1.648 raeburn 9351: =item * &load_tmp_file($r)
1.41 ng 9352:
9353: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 9354: needs $env{'form.datatoken'},
9355: sets $env{'form.upfile'} to the contents of the file
1.41 ng 9356:
9357: =cut
1.31 albertel 9358:
9359: sub load_tmp_file {
9360: my $r=shift;
9361: my @studentdata=();
9362: {
1.158 raeburn 9363: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 9364: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 9365: if ( open(my $fh,"<$studentfile") ) {
9366: @studentdata=<$fh>;
9367: close($fh);
9368: }
1.31 albertel 9369: }
1.258 albertel 9370: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 9371: }
9372:
1.56 matthew 9373: =pod
9374:
1.648 raeburn 9375: =item * &upfile_record_sep()
1.41 ng 9376:
9377: Separate uploaded file into records
9378: returns array of records,
1.258 albertel 9379: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 9380:
9381: =cut
1.31 albertel 9382:
9383: sub upfile_record_sep {
1.258 albertel 9384: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 9385: } else {
1.248 albertel 9386: my @records;
1.258 albertel 9387: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 9388: if ($line=~/^\s*$/) { next; }
9389: push(@records,$line);
9390: }
9391: return @records;
1.31 albertel 9392: }
9393: }
9394:
1.56 matthew 9395: =pod
9396:
1.648 raeburn 9397: =item * &record_sep($record)
1.41 ng 9398:
1.258 albertel 9399: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 9400:
9401: =cut
9402:
1.263 www 9403: sub takeleft {
9404: my $index=shift;
9405: return substr('0000'.$index,-4,4);
9406: }
9407:
1.31 albertel 9408: sub record_sep {
9409: my $record=shift;
9410: my %components=();
1.258 albertel 9411: if ($env{'form.upfiletype'} eq 'xml') {
9412: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 9413: my $i=0;
1.356 albertel 9414: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 9415: $field=~s/^(\"|\')//;
9416: $field=~s/(\"|\')$//;
1.263 www 9417: $components{&takeleft($i)}=$field;
1.31 albertel 9418: $i++;
9419: }
1.258 albertel 9420: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 9421: my $i=0;
1.356 albertel 9422: foreach my $field (split(/\t/,$record)) {
1.31 albertel 9423: $field=~s/^(\"|\')//;
9424: $field=~s/(\"|\')$//;
1.263 www 9425: $components{&takeleft($i)}=$field;
1.31 albertel 9426: $i++;
9427: }
9428: } else {
1.561 www 9429: my $separator=',';
1.480 banghart 9430: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 9431: $separator=';';
1.480 banghart 9432: }
1.31 albertel 9433: my $i=0;
1.561 www 9434: # the character we are looking for to indicate the end of a quote or a record
9435: my $looking_for=$separator;
9436: # do not add the characters to the fields
9437: my $ignore=0;
9438: # we just encountered a separator (or the beginning of the record)
9439: my $just_found_separator=1;
9440: # store the field we are working on here
9441: my $field='';
9442: # work our way through all characters in record
9443: foreach my $character ($record=~/(.)/g) {
9444: if ($character eq $looking_for) {
9445: if ($character ne $separator) {
9446: # Found the end of a quote, again looking for separator
9447: $looking_for=$separator;
9448: $ignore=1;
9449: } else {
9450: # Found a separator, store away what we got
9451: $components{&takeleft($i)}=$field;
9452: $i++;
9453: $just_found_separator=1;
9454: $ignore=0;
9455: $field='';
9456: }
9457: next;
9458: }
9459: # single or double quotation marks after a separator indicate beginning of a quote
9460: # we are now looking for the end of the quote and need to ignore separators
9461: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
9462: $looking_for=$character;
9463: next;
9464: }
9465: # ignore would be true after we reached the end of a quote
9466: if ($ignore) { next; }
9467: if (($just_found_separator) && ($character=~/\s/)) { next; }
9468: $field.=$character;
9469: $just_found_separator=0;
1.31 albertel 9470: }
1.561 www 9471: # catch the very last entry, since we never encountered the separator
9472: $components{&takeleft($i)}=$field;
1.31 albertel 9473: }
9474: return %components;
9475: }
9476:
1.144 matthew 9477: ######################################################
9478: ######################################################
9479:
1.56 matthew 9480: =pod
9481:
1.648 raeburn 9482: =item * &upfile_select_html()
1.41 ng 9483:
1.144 matthew 9484: Return HTML code to select a file from the users machine and specify
9485: the file type.
1.41 ng 9486:
9487: =cut
9488:
1.144 matthew 9489: ######################################################
9490: ######################################################
1.31 albertel 9491: sub upfile_select_html {
1.144 matthew 9492: my %Types = (
9493: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 9494: semisv => &mt('Semicolon separated values'),
1.144 matthew 9495: space => &mt('Space separated'),
9496: tab => &mt('Tabulator separated'),
9497: # xml => &mt('HTML/XML'),
9498: );
9499: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 9500: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 9501: foreach my $type (sort(keys(%Types))) {
9502: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
9503: }
9504: $Str .= "</select>\n";
9505: return $Str;
1.31 albertel 9506: }
9507:
1.301 albertel 9508: sub get_samples {
9509: my ($records,$toget) = @_;
9510: my @samples=({});
9511: my $got=0;
9512: foreach my $rec (@$records) {
9513: my %temp = &record_sep($rec);
9514: if (! grep(/\S/, values(%temp))) { next; }
9515: if (%temp) {
9516: $samples[$got]=\%temp;
9517: $got++;
9518: if ($got == $toget) { last; }
9519: }
9520: }
9521: return \@samples;
9522: }
9523:
1.144 matthew 9524: ######################################################
9525: ######################################################
9526:
1.56 matthew 9527: =pod
9528:
1.648 raeburn 9529: =item * &csv_print_samples($r,$records)
1.41 ng 9530:
9531: Prints a table of sample values from each column uploaded $r is an
9532: Apache Request ref, $records is an arrayref from
9533: &Apache::loncommon::upfile_record_sep
9534:
9535: =cut
9536:
1.144 matthew 9537: ######################################################
9538: ######################################################
1.31 albertel 9539: sub csv_print_samples {
9540: my ($r,$records) = @_;
1.662 bisitz 9541: my $samples = &get_samples($records,5);
1.301 albertel 9542:
1.594 raeburn 9543: $r->print(&mt('Samples').'<br />'.&start_data_table().
9544: &start_data_table_header_row());
1.356 albertel 9545: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 9546: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 9547: $r->print(&end_data_table_header_row());
1.301 albertel 9548: foreach my $hash (@$samples) {
1.594 raeburn 9549: $r->print(&start_data_table_row());
1.356 albertel 9550: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 9551: $r->print('<td>');
1.356 albertel 9552: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 9553: $r->print('</td>');
9554: }
1.594 raeburn 9555: $r->print(&end_data_table_row());
1.31 albertel 9556: }
1.594 raeburn 9557: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 9558: }
9559:
1.144 matthew 9560: ######################################################
9561: ######################################################
9562:
1.56 matthew 9563: =pod
9564:
1.648 raeburn 9565: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 9566:
9567: Prints a table to create associations between values and table columns.
1.144 matthew 9568:
1.41 ng 9569: $r is an Apache Request ref,
9570: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 9571: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 9572:
9573: =cut
9574:
1.144 matthew 9575: ######################################################
9576: ######################################################
1.31 albertel 9577: sub csv_print_select_table {
9578: my ($r,$records,$d) = @_;
1.301 albertel 9579: my $i=0;
9580: my $samples = &get_samples($records,1);
1.144 matthew 9581: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 9582: &start_data_table().&start_data_table_header_row().
1.144 matthew 9583: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 9584: '<th>'.&mt('Column').'</th>'.
9585: &end_data_table_header_row()."\n");
1.356 albertel 9586: foreach my $array_ref (@$d) {
9587: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 9588: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 9589:
1.875 bisitz 9590: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 9591: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 9592: $r->print('<option value="none"></option>');
1.356 albertel 9593: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
9594: $r->print('<option value="'.$sample.'"'.
9595: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 9596: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 9597: }
1.594 raeburn 9598: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 9599: $i++;
9600: }
1.594 raeburn 9601: $r->print(&end_data_table());
1.31 albertel 9602: $i--;
9603: return $i;
9604: }
1.56 matthew 9605:
1.144 matthew 9606: ######################################################
9607: ######################################################
9608:
1.56 matthew 9609: =pod
1.31 albertel 9610:
1.648 raeburn 9611: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 9612:
9613: Prints a table of sample values from the upload and can make associate samples to internal names.
9614:
9615: $r is an Apache Request ref,
9616: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
9617: $d is an array of 2 element arrays (internal name, displayed name)
9618:
9619: =cut
9620:
1.144 matthew 9621: ######################################################
9622: ######################################################
1.31 albertel 9623: sub csv_samples_select_table {
9624: my ($r,$records,$d) = @_;
9625: my $i=0;
1.144 matthew 9626: #
1.662 bisitz 9627: my $max_samples = 5;
9628: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 9629: $r->print(&start_data_table().
9630: &start_data_table_header_row().'<th>'.
9631: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
9632: &end_data_table_header_row());
1.301 albertel 9633:
9634: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 9635: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 9636: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 9637: foreach my $option (@$d) {
9638: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 9639: $r->print('<option value="'.$value.'"'.
1.253 albertel 9640: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 9641: $display.'</option>');
1.31 albertel 9642: }
9643: $r->print('</select></td><td>');
1.662 bisitz 9644: foreach my $line (0..($max_samples-1)) {
1.301 albertel 9645: if (defined($samples->[$line]{$key})) {
9646: $r->print($samples->[$line]{$key}."<br />\n");
9647: }
9648: }
1.594 raeburn 9649: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9650: $i++;
9651: }
1.594 raeburn 9652: $r->print(&end_data_table());
1.31 albertel 9653: $i--;
9654: return($i);
1.115 matthew 9655: }
9656:
1.144 matthew 9657: ######################################################
9658: ######################################################
9659:
1.115 matthew 9660: =pod
9661:
1.648 raeburn 9662: =item * &clean_excel_name($name)
1.115 matthew 9663:
9664: Returns a replacement for $name which does not contain any illegal characters.
9665:
9666: =cut
9667:
1.144 matthew 9668: ######################################################
9669: ######################################################
1.115 matthew 9670: sub clean_excel_name {
9671: my ($name) = @_;
9672: $name =~ s/[:\*\?\/\\]//g;
9673: if (length($name) > 31) {
9674: $name = substr($name,0,31);
9675: }
9676: return $name;
1.25 albertel 9677: }
1.84 albertel 9678:
1.85 albertel 9679: =pod
9680:
1.648 raeburn 9681: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9682:
9683: Returns either 1 or undef
9684:
9685: 1 if the part is to be hidden, undef if it is to be shown
9686:
9687: Arguments are:
9688:
9689: $id the id of the part to be checked
9690: $symb, optional the symb of the resource to check
9691: $udom, optional the domain of the user to check for
9692: $uname, optional the username of the user to check for
9693:
9694: =cut
1.84 albertel 9695:
9696: sub check_if_partid_hidden {
9697: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9698: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9699: $symb,$udom,$uname);
1.141 albertel 9700: my $truth=1;
9701: #if the string starts with !, then the list is the list to show not hide
9702: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9703: my @hiddenlist=split(/,/,$hiddenparts);
9704: foreach my $checkid (@hiddenlist) {
1.141 albertel 9705: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9706: }
1.141 albertel 9707: return !$truth;
1.84 albertel 9708: }
1.127 matthew 9709:
1.138 matthew 9710:
9711: ############################################################
9712: ############################################################
9713:
9714: =pod
9715:
1.157 matthew 9716: =back
9717:
1.138 matthew 9718: =head1 cgi-bin script and graphing routines
9719:
1.157 matthew 9720: =over 4
9721:
1.648 raeburn 9722: =item * &get_cgi_id()
1.138 matthew 9723:
9724: Inputs: none
9725:
9726: Returns an id which can be used to pass environment variables
9727: to various cgi-bin scripts. These environment variables will
9728: be removed from the users environment after a given time by
9729: the routine &Apache::lonnet::transfer_profile_to_env.
9730:
9731: =cut
9732:
9733: ############################################################
9734: ############################################################
1.152 albertel 9735: my $uniq=0;
1.136 matthew 9736: sub get_cgi_id {
1.154 albertel 9737: $uniq=($uniq+1)%100000;
1.280 albertel 9738: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9739: }
9740:
1.127 matthew 9741: ############################################################
9742: ############################################################
9743:
9744: =pod
9745:
1.648 raeburn 9746: =item * &DrawBarGraph()
1.127 matthew 9747:
1.138 matthew 9748: Facilitates the plotting of data in a (stacked) bar graph.
9749: Puts plot definition data into the users environment in order for
9750: graph.png to plot it. Returns an <img> tag for the plot.
9751: The bars on the plot are labeled '1','2',...,'n'.
9752:
9753: Inputs:
9754:
9755: =over 4
9756:
9757: =item $Title: string, the title of the plot
9758:
9759: =item $xlabel: string, text describing the X-axis of the plot
9760:
9761: =item $ylabel: string, text describing the Y-axis of the plot
9762:
9763: =item $Max: scalar, the maximum Y value to use in the plot
9764: If $Max is < any data point, the graph will not be rendered.
9765:
1.140 matthew 9766: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9767: they are plotted. If undefined, default values will be used.
9768:
1.178 matthew 9769: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9770:
1.138 matthew 9771: =item @Values: An array of array references. Each array reference holds data
9772: to be plotted in a stacked bar chart.
9773:
1.239 matthew 9774: =item If the final element of @Values is a hash reference the key/value
9775: pairs will be added to the graph definition.
9776:
1.138 matthew 9777: =back
9778:
9779: Returns:
9780:
9781: An <img> tag which references graph.png and the appropriate identifying
9782: information for the plot.
9783:
1.127 matthew 9784: =cut
9785:
9786: ############################################################
9787: ############################################################
1.134 matthew 9788: sub DrawBarGraph {
1.178 matthew 9789: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9790: #
9791: if (! defined($colors)) {
9792: $colors = ['#33ff00',
9793: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9794: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9795: ];
9796: }
1.228 matthew 9797: my $extra_settings = {};
9798: if (ref($Values[-1]) eq 'HASH') {
9799: $extra_settings = pop(@Values);
9800: }
1.127 matthew 9801: #
1.136 matthew 9802: my $identifier = &get_cgi_id();
9803: my $id = 'cgi.'.$identifier;
1.129 matthew 9804: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9805: return '';
9806: }
1.225 matthew 9807: #
9808: my @Labels;
9809: if (defined($labels)) {
9810: @Labels = @$labels;
9811: } else {
9812: for (my $i=0;$i<@{$Values[0]};$i++) {
9813: push (@Labels,$i+1);
9814: }
9815: }
9816: #
1.129 matthew 9817: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9818: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9819: my %ValuesHash;
9820: my $NumSets=1;
9821: foreach my $array (@Values) {
9822: next if (! ref($array));
1.136 matthew 9823: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9824: join(',',@$array);
1.129 matthew 9825: }
1.127 matthew 9826: #
1.136 matthew 9827: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9828: if ($NumBars < 3) {
9829: $width = 120+$NumBars*32;
1.220 matthew 9830: $xskip = 1;
1.225 matthew 9831: $bar_width = 30;
9832: } elsif ($NumBars < 5) {
9833: $width = 120+$NumBars*20;
9834: $xskip = 1;
9835: $bar_width = 20;
1.220 matthew 9836: } elsif ($NumBars < 10) {
1.136 matthew 9837: $width = 120+$NumBars*15;
9838: $xskip = 1;
9839: $bar_width = 15;
9840: } elsif ($NumBars <= 25) {
9841: $width = 120+$NumBars*11;
9842: $xskip = 5;
9843: $bar_width = 8;
9844: } elsif ($NumBars <= 50) {
9845: $width = 120+$NumBars*8;
9846: $xskip = 5;
9847: $bar_width = 4;
9848: } else {
9849: $width = 120+$NumBars*8;
9850: $xskip = 5;
9851: $bar_width = 4;
9852: }
9853: #
1.137 matthew 9854: $Max = 1 if ($Max < 1);
9855: if ( int($Max) < $Max ) {
9856: $Max++;
9857: $Max = int($Max);
9858: }
1.127 matthew 9859: $Title = '' if (! defined($Title));
9860: $xlabel = '' if (! defined($xlabel));
9861: $ylabel = '' if (! defined($ylabel));
1.369 www 9862: $ValuesHash{$id.'.title'} = &escape($Title);
9863: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9864: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9865: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9866: $ValuesHash{$id.'.NumBars'} = $NumBars;
9867: $ValuesHash{$id.'.NumSets'} = $NumSets;
9868: $ValuesHash{$id.'.PlotType'} = 'bar';
9869: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9870: $ValuesHash{$id.'.height'} = $height;
9871: $ValuesHash{$id.'.width'} = $width;
9872: $ValuesHash{$id.'.xskip'} = $xskip;
9873: $ValuesHash{$id.'.bar_width'} = $bar_width;
9874: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9875: #
1.228 matthew 9876: # Deal with other parameters
9877: while (my ($key,$value) = each(%$extra_settings)) {
9878: $ValuesHash{$id.'.'.$key} = $value;
9879: }
9880: #
1.646 raeburn 9881: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9882: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9883: }
9884:
9885: ############################################################
9886: ############################################################
9887:
9888: =pod
9889:
1.648 raeburn 9890: =item * &DrawXYGraph()
1.137 matthew 9891:
1.138 matthew 9892: Facilitates the plotting of data in an XY graph.
9893: Puts plot definition data into the users environment in order for
9894: graph.png to plot it. Returns an <img> tag for the plot.
9895:
9896: Inputs:
9897:
9898: =over 4
9899:
9900: =item $Title: string, the title of the plot
9901:
9902: =item $xlabel: string, text describing the X-axis of the plot
9903:
9904: =item $ylabel: string, text describing the Y-axis of the plot
9905:
9906: =item $Max: scalar, the maximum Y value to use in the plot
9907: If $Max is < any data point, the graph will not be rendered.
9908:
9909: =item $colors: Array ref containing the hex color codes for the data to be
9910: plotted in. If undefined, default values will be used.
9911:
9912: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9913:
9914: =item $Ydata: Array ref containing Array refs.
1.185 www 9915: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9916:
9917: =item %Values: hash indicating or overriding any default values which are
9918: passed to graph.png.
9919: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9920:
9921: =back
9922:
9923: Returns:
9924:
9925: An <img> tag which references graph.png and the appropriate identifying
9926: information for the plot.
9927:
1.137 matthew 9928: =cut
9929:
9930: ############################################################
9931: ############################################################
9932: sub DrawXYGraph {
9933: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9934: #
9935: # Create the identifier for the graph
9936: my $identifier = &get_cgi_id();
9937: my $id = 'cgi.'.$identifier;
9938: #
9939: $Title = '' if (! defined($Title));
9940: $xlabel = '' if (! defined($xlabel));
9941: $ylabel = '' if (! defined($ylabel));
9942: my %ValuesHash =
9943: (
1.369 www 9944: $id.'.title' => &escape($Title),
9945: $id.'.xlabel' => &escape($xlabel),
9946: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9947: $id.'.y_max_value'=> $Max,
9948: $id.'.labels' => join(',',@$Xlabels),
9949: $id.'.PlotType' => 'XY',
9950: );
9951: #
9952: if (defined($colors) && ref($colors) eq 'ARRAY') {
9953: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9954: }
9955: #
9956: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9957: return '';
9958: }
9959: my $NumSets=1;
1.138 matthew 9960: foreach my $array (@{$Ydata}){
1.137 matthew 9961: next if (! ref($array));
9962: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9963: }
1.138 matthew 9964: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9965: #
9966: # Deal with other parameters
9967: while (my ($key,$value) = each(%Values)) {
9968: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9969: }
9970: #
1.646 raeburn 9971: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9972: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9973: }
9974:
9975: ############################################################
9976: ############################################################
9977:
9978: =pod
9979:
1.648 raeburn 9980: =item * &DrawXYYGraph()
1.138 matthew 9981:
9982: Facilitates the plotting of data in an XY graph with two Y axes.
9983: Puts plot definition data into the users environment in order for
9984: graph.png to plot it. Returns an <img> tag for the plot.
9985:
9986: Inputs:
9987:
9988: =over 4
9989:
9990: =item $Title: string, the title of the plot
9991:
9992: =item $xlabel: string, text describing the X-axis of the plot
9993:
9994: =item $ylabel: string, text describing the Y-axis of the plot
9995:
9996: =item $colors: Array ref containing the hex color codes for the data to be
9997: plotted in. If undefined, default values will be used.
9998:
9999: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
10000:
10001: =item $Ydata1: The first data set
10002:
10003: =item $Min1: The minimum value of the left Y-axis
10004:
10005: =item $Max1: The maximum value of the left Y-axis
10006:
10007: =item $Ydata2: The second data set
10008:
10009: =item $Min2: The minimum value of the right Y-axis
10010:
10011: =item $Max2: The maximum value of the left Y-axis
10012:
10013: =item %Values: hash indicating or overriding any default values which are
10014: passed to graph.png.
10015: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
10016:
10017: =back
10018:
10019: Returns:
10020:
10021: An <img> tag which references graph.png and the appropriate identifying
10022: information for the plot.
1.136 matthew 10023:
10024: =cut
10025:
10026: ############################################################
10027: ############################################################
1.137 matthew 10028: sub DrawXYYGraph {
10029: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
10030: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 10031: #
10032: # Create the identifier for the graph
10033: my $identifier = &get_cgi_id();
10034: my $id = 'cgi.'.$identifier;
10035: #
10036: $Title = '' if (! defined($Title));
10037: $xlabel = '' if (! defined($xlabel));
10038: $ylabel = '' if (! defined($ylabel));
10039: my %ValuesHash =
10040: (
1.369 www 10041: $id.'.title' => &escape($Title),
10042: $id.'.xlabel' => &escape($xlabel),
10043: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 10044: $id.'.labels' => join(',',@$Xlabels),
10045: $id.'.PlotType' => 'XY',
10046: $id.'.NumSets' => 2,
1.137 matthew 10047: $id.'.two_axes' => 1,
10048: $id.'.y1_max_value' => $Max1,
10049: $id.'.y1_min_value' => $Min1,
10050: $id.'.y2_max_value' => $Max2,
10051: $id.'.y2_min_value' => $Min2,
1.136 matthew 10052: );
10053: #
1.137 matthew 10054: if (defined($colors) && ref($colors) eq 'ARRAY') {
10055: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
10056: }
10057: #
10058: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
10059: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 10060: return '';
10061: }
10062: my $NumSets=1;
1.137 matthew 10063: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 10064: next if (! ref($array));
10065: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 10066: }
10067: #
10068: # Deal with other parameters
10069: while (my ($key,$value) = each(%Values)) {
10070: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 10071: }
10072: #
1.646 raeburn 10073: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 10074: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 10075: }
10076:
10077: ############################################################
10078: ############################################################
10079:
10080: =pod
10081:
1.157 matthew 10082: =back
10083:
1.139 matthew 10084: =head1 Statistics helper routines?
10085:
10086: Bad place for them but what the hell.
10087:
1.157 matthew 10088: =over 4
10089:
1.648 raeburn 10090: =item * &chartlink()
1.139 matthew 10091:
10092: Returns a link to the chart for a specific student.
10093:
10094: Inputs:
10095:
10096: =over 4
10097:
10098: =item $linktext: The text of the link
10099:
10100: =item $sname: The students username
10101:
10102: =item $sdomain: The students domain
10103:
10104: =back
10105:
1.157 matthew 10106: =back
10107:
1.139 matthew 10108: =cut
10109:
10110: ############################################################
10111: ############################################################
10112: sub chartlink {
10113: my ($linktext, $sname, $sdomain) = @_;
10114: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 10115: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 10116: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 10117: '">'.$linktext.'</a>';
1.153 matthew 10118: }
10119:
10120: #######################################################
10121: #######################################################
10122:
10123: =pod
10124:
10125: =head1 Course Environment Routines
1.157 matthew 10126:
10127: =over 4
1.153 matthew 10128:
1.648 raeburn 10129: =item * &restore_course_settings()
1.153 matthew 10130:
1.648 raeburn 10131: =item * &store_course_settings()
1.153 matthew 10132:
10133: Restores/Store indicated form parameters from the course environment.
10134: Will not overwrite existing values of the form parameters.
10135:
10136: Inputs:
10137: a scalar describing the data (e.g. 'chart', 'problem_analysis')
10138:
10139: a hash ref describing the data to be stored. For example:
10140:
10141: %Save_Parameters = ('Status' => 'scalar',
10142: 'chartoutputmode' => 'scalar',
10143: 'chartoutputdata' => 'scalar',
10144: 'Section' => 'array',
1.373 raeburn 10145: 'Group' => 'array',
1.153 matthew 10146: 'StudentData' => 'array',
10147: 'Maps' => 'array');
10148:
10149: Returns: both routines return nothing
10150:
1.631 raeburn 10151: =back
10152:
1.153 matthew 10153: =cut
10154:
10155: #######################################################
10156: #######################################################
10157: sub store_course_settings {
1.496 albertel 10158: return &store_settings($env{'request.course.id'},@_);
10159: }
10160:
10161: sub store_settings {
1.153 matthew 10162: # save to the environment
10163: # appenv the same items, just to be safe
1.300 albertel 10164: my $udom = $env{'user.domain'};
10165: my $uname = $env{'user.name'};
1.496 albertel 10166: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10167: my %SaveHash;
10168: my %AppHash;
10169: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 10170: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 10171: my $envname = 'environment.'.$basename;
1.258 albertel 10172: if (exists($env{'form.'.$setting})) {
1.153 matthew 10173: # Save this value away
10174: if ($type eq 'scalar' &&
1.258 albertel 10175: (! exists($env{$envname}) ||
10176: $env{$envname} ne $env{'form.'.$setting})) {
10177: $SaveHash{$basename} = $env{'form.'.$setting};
10178: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 10179: } elsif ($type eq 'array') {
10180: my $stored_form;
1.258 albertel 10181: if (ref($env{'form.'.$setting})) {
1.153 matthew 10182: $stored_form = join(',',
10183: map {
1.369 www 10184: &escape($_);
1.258 albertel 10185: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 10186: } else {
10187: $stored_form =
1.369 www 10188: &escape($env{'form.'.$setting});
1.153 matthew 10189: }
10190: # Determine if the array contents are the same.
1.258 albertel 10191: if ($stored_form ne $env{$envname}) {
1.153 matthew 10192: $SaveHash{$basename} = $stored_form;
10193: $AppHash{$envname} = $stored_form;
10194: }
10195: }
10196: }
10197: }
10198: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 10199: $udom,$uname);
1.153 matthew 10200: if ($put_result !~ /^(ok|delayed)/) {
10201: &Apache::lonnet::logthis('unable to save form parameters, '.
10202: 'got error:'.$put_result);
10203: }
10204: # Make sure these settings stick around in this session, too
1.646 raeburn 10205: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 10206: return;
10207: }
10208:
10209: sub restore_course_settings {
1.499 albertel 10210: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 10211: }
10212:
10213: sub restore_settings {
10214: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10215: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 10216: next if (exists($env{'form.'.$setting}));
1.496 albertel 10217: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 10218: '.'.$setting;
1.258 albertel 10219: if (exists($env{$envname})) {
1.153 matthew 10220: if ($type eq 'scalar') {
1.258 albertel 10221: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 10222: } elsif ($type eq 'array') {
1.258 albertel 10223: $env{'form.'.$setting} = [
1.153 matthew 10224: map {
1.369 www 10225: &unescape($_);
1.258 albertel 10226: } split(',',$env{$envname})
1.153 matthew 10227: ];
10228: }
10229: }
10230: }
1.127 matthew 10231: }
10232:
1.618 raeburn 10233: #######################################################
10234: #######################################################
10235:
10236: =pod
10237:
10238: =head1 Domain E-mail Routines
10239:
10240: =over 4
10241:
1.648 raeburn 10242: =item * &build_recipient_list()
1.618 raeburn 10243:
1.884 raeburn 10244: Build recipient lists for five types of e-mail:
1.766 raeburn 10245: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 10246: (d) Help requests, (e) Course requests needing approval, generated by
10247: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
10248: loncoursequeueadmin.pm respectively.
1.618 raeburn 10249:
10250: Inputs:
1.619 raeburn 10251: defmail (scalar - email address of default recipient),
1.618 raeburn 10252: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 10253: defdom (domain for which to retrieve configuration settings),
10254: origmail (scalar - email address of recipient from loncapa.conf,
10255: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 10256:
1.655 raeburn 10257: Returns: comma separated list of addresses to which to send e-mail.
10258:
10259: =back
1.618 raeburn 10260:
10261: =cut
10262:
10263: ############################################################
10264: ############################################################
10265: sub build_recipient_list {
1.619 raeburn 10266: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 10267: my @recipients;
10268: my $otheremails;
10269: my %domconfig =
10270: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
10271: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 10272: if (exists($domconfig{'contacts'}{$mailing})) {
10273: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
10274: my @contacts = ('adminemail','supportemail');
10275: foreach my $item (@contacts) {
10276: if ($domconfig{'contacts'}{$mailing}{$item}) {
10277: my $addr = $domconfig{'contacts'}{$item};
10278: if (!grep(/^\Q$addr\E$/,@recipients)) {
10279: push(@recipients,$addr);
10280: }
1.619 raeburn 10281: }
1.766 raeburn 10282: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 10283: }
10284: }
1.766 raeburn 10285: } elsif ($origmail ne '') {
10286: push(@recipients,$origmail);
1.618 raeburn 10287: }
1.619 raeburn 10288: } elsif ($origmail ne '') {
10289: push(@recipients,$origmail);
1.618 raeburn 10290: }
1.688 raeburn 10291: if (defined($defmail)) {
10292: if ($defmail ne '') {
10293: push(@recipients,$defmail);
10294: }
1.618 raeburn 10295: }
10296: if ($otheremails) {
1.619 raeburn 10297: my @others;
10298: if ($otheremails =~ /,/) {
10299: @others = split(/,/,$otheremails);
1.618 raeburn 10300: } else {
1.619 raeburn 10301: push(@others,$otheremails);
10302: }
10303: foreach my $addr (@others) {
10304: if (!grep(/^\Q$addr\E$/,@recipients)) {
10305: push(@recipients,$addr);
10306: }
1.618 raeburn 10307: }
10308: }
1.619 raeburn 10309: my $recipientlist = join(',',@recipients);
1.618 raeburn 10310: return $recipientlist;
10311: }
10312:
1.127 matthew 10313: ############################################################
10314: ############################################################
1.154 albertel 10315:
1.655 raeburn 10316: =pod
10317:
10318: =head1 Course Catalog Routines
10319:
10320: =over 4
10321:
10322: =item * &gather_categories()
10323:
10324: Converts category definitions - keys of categories hash stored in
10325: coursecategories in configuration.db on the primary library server in a
10326: domain - to an array. Also generates javascript and idx hash used to
10327: generate Domain Coordinator interface for editing Course Categories.
10328:
10329: Inputs:
1.663 raeburn 10330:
1.655 raeburn 10331: categories (reference to hash of category definitions).
1.663 raeburn 10332:
1.655 raeburn 10333: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10334: categories and subcategories).
1.663 raeburn 10335:
1.655 raeburn 10336: idx (reference to hash of counters used in Domain Coordinator interface for
10337: editing Course Categories).
1.663 raeburn 10338:
1.655 raeburn 10339: jsarray (reference to array of categories used to create Javascript arrays for
10340: Domain Coordinator interface for editing Course Categories).
10341:
10342: Returns: nothing
10343:
10344: Side effects: populates cats, idx and jsarray.
10345:
10346: =cut
10347:
10348: sub gather_categories {
10349: my ($categories,$cats,$idx,$jsarray) = @_;
10350: my %counters;
10351: my $num = 0;
10352: foreach my $item (keys(%{$categories})) {
10353: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10354: if ($container eq '' && $depth == 0) {
10355: $cats->[$depth][$categories->{$item}] = $cat;
10356: } else {
10357: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
10358: }
10359: my ($escitem,$tail) = split(/:/,$item,2);
10360: if ($counters{$tail} eq '') {
10361: $counters{$tail} = $num;
10362: $num ++;
10363: }
10364: if (ref($idx) eq 'HASH') {
10365: $idx->{$item} = $counters{$tail};
10366: }
10367: if (ref($jsarray) eq 'ARRAY') {
10368: push(@{$jsarray->[$counters{$tail}]},$item);
10369: }
10370: }
10371: return;
10372: }
10373:
10374: =pod
10375:
10376: =item * &extract_categories()
10377:
10378: Used to generate breadcrumb trails for course categories.
10379:
10380: Inputs:
1.663 raeburn 10381:
1.655 raeburn 10382: categories (reference to hash of category definitions).
1.663 raeburn 10383:
1.655 raeburn 10384: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10385: categories and subcategories).
1.663 raeburn 10386:
1.655 raeburn 10387: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 10388:
1.655 raeburn 10389: allitems (reference to hash - key is category key
10390: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10391:
1.655 raeburn 10392: idx (reference to hash of counters used in Domain Coordinator interface for
10393: editing Course Categories).
1.663 raeburn 10394:
1.655 raeburn 10395: jsarray (reference to array of categories used to create Javascript arrays for
10396: Domain Coordinator interface for editing Course Categories).
10397:
1.665 raeburn 10398: subcats (reference to hash of arrays containing all subcategories within each
10399: category, -recursive)
10400:
1.655 raeburn 10401: Returns: nothing
10402:
10403: Side effects: populates trails and allitems hash references.
10404:
10405: =cut
10406:
10407: sub extract_categories {
1.665 raeburn 10408: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 10409: if (ref($categories) eq 'HASH') {
10410: &gather_categories($categories,$cats,$idx,$jsarray);
10411: if (ref($cats->[0]) eq 'ARRAY') {
10412: for (my $i=0; $i<@{$cats->[0]}; $i++) {
10413: my $name = $cats->[0][$i];
10414: my $item = &escape($name).'::0';
10415: my $trailstr;
10416: if ($name eq 'instcode') {
10417: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 10418: } elsif ($name eq 'communities') {
10419: $trailstr = &mt('Communities');
1.655 raeburn 10420: } else {
10421: $trailstr = $name;
10422: }
10423: if ($allitems->{$item} eq '') {
10424: push(@{$trails},$trailstr);
10425: $allitems->{$item} = scalar(@{$trails})-1;
10426: }
10427: my @parents = ($name);
10428: if (ref($cats->[1]{$name}) eq 'ARRAY') {
10429: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
10430: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 10431: if (ref($subcats) eq 'HASH') {
10432: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
10433: }
10434: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
10435: }
10436: } else {
10437: if (ref($subcats) eq 'HASH') {
10438: $subcats->{$item} = [];
1.655 raeburn 10439: }
10440: }
10441: }
10442: }
10443: }
10444: return;
10445: }
10446:
10447: =pod
10448:
10449: =item *&recurse_categories()
10450:
10451: Recursively used to generate breadcrumb trails for course categories.
10452:
10453: Inputs:
1.663 raeburn 10454:
1.655 raeburn 10455: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10456: categories and subcategories).
1.663 raeburn 10457:
1.655 raeburn 10458: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 10459:
10460: category (current course category, for which breadcrumb trail is being generated).
10461:
10462: trails (reference to array of breadcrumb trails for each category).
10463:
1.655 raeburn 10464: allitems (reference to hash - key is category key
10465: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10466:
1.655 raeburn 10467: parents (array containing containers directories for current category,
10468: back to top level).
10469:
10470: Returns: nothing
10471:
10472: Side effects: populates trails and allitems hash references
10473:
10474: =cut
10475:
10476: sub recurse_categories {
1.665 raeburn 10477: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 10478: my $shallower = $depth - 1;
10479: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
10480: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
10481: my $name = $cats->[$depth]{$category}[$k];
10482: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10483: my $trailstr = join(' -> ',(@{$parents},$category));
10484: if ($allitems->{$item} eq '') {
10485: push(@{$trails},$trailstr);
10486: $allitems->{$item} = scalar(@{$trails})-1;
10487: }
10488: my $deeper = $depth+1;
10489: push(@{$parents},$category);
1.665 raeburn 10490: if (ref($subcats) eq 'HASH') {
10491: my $subcat = &escape($name).':'.$category.':'.$depth;
10492: for (my $j=@{$parents}; $j>=0; $j--) {
10493: my $higher;
10494: if ($j > 0) {
10495: $higher = &escape($parents->[$j]).':'.
10496: &escape($parents->[$j-1]).':'.$j;
10497: } else {
10498: $higher = &escape($parents->[$j]).'::'.$j;
10499: }
10500: push(@{$subcats->{$higher}},$subcat);
10501: }
10502: }
10503: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
10504: $subcats);
1.655 raeburn 10505: pop(@{$parents});
10506: }
10507: } else {
10508: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10509: my $trailstr = join(' -> ',(@{$parents},$category));
10510: if ($allitems->{$item} eq '') {
10511: push(@{$trails},$trailstr);
10512: $allitems->{$item} = scalar(@{$trails})-1;
10513: }
10514: }
10515: return;
10516: }
10517:
1.663 raeburn 10518: =pod
10519:
10520: =item *&assign_categories_table()
10521:
10522: Create a datatable for display of hierarchical categories in a domain,
10523: with checkboxes to allow a course to be categorized.
10524:
10525: Inputs:
10526:
10527: cathash - reference to hash of categories defined for the domain (from
10528: configuration.db)
10529:
10530: currcat - scalar with an & separated list of categories assigned to a course.
10531:
1.919 raeburn 10532: type - scalar contains course type (Course or Community).
10533:
1.663 raeburn 10534: Returns: $output (markup to be displayed)
10535:
10536: =cut
10537:
10538: sub assign_categories_table {
1.919 raeburn 10539: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 10540: my $output;
10541: if (ref($cathash) eq 'HASH') {
10542: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
10543: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
10544: $maxdepth = scalar(@cats);
10545: if (@cats > 0) {
10546: my $itemcount = 0;
10547: if (ref($cats[0]) eq 'ARRAY') {
10548: my @currcategories;
10549: if ($currcat ne '') {
10550: @currcategories = split('&',$currcat);
10551: }
1.919 raeburn 10552: my $table;
1.663 raeburn 10553: for (my $i=0; $i<@{$cats[0]}; $i++) {
10554: my $parent = $cats[0][$i];
1.919 raeburn 10555: next if ($parent eq 'instcode');
10556: if ($type eq 'Community') {
10557: next unless ($parent eq 'communities');
10558: } else {
10559: next if ($parent eq 'communities');
10560: }
1.663 raeburn 10561: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10562: my $item = &escape($parent).'::0';
10563: my $checked = '';
10564: if (@currcategories > 0) {
10565: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 10566: $checked = ' checked="checked"';
1.663 raeburn 10567: }
10568: }
1.919 raeburn 10569: my $parent_title = $parent;
10570: if ($parent eq 'communities') {
10571: $parent_title = &mt('Communities');
10572: }
10573: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
10574: '<input type="checkbox" name="usecategory" value="'.
10575: $item.'"'.$checked.' />'.$parent_title.'</span>'.
10576: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 10577: my $depth = 1;
10578: push(@path,$parent);
1.919 raeburn 10579: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 10580: pop(@path);
1.919 raeburn 10581: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 10582: $itemcount ++;
10583: }
1.919 raeburn 10584: if ($itemcount) {
10585: $output = &Apache::loncommon::start_data_table().
10586: $table.
10587: &Apache::loncommon::end_data_table();
10588: }
1.663 raeburn 10589: }
10590: }
10591: }
10592: return $output;
10593: }
10594:
10595: =pod
10596:
10597: =item *&assign_category_rows()
10598:
10599: Create a datatable row for display of nested categories in a domain,
10600: with checkboxes to allow a course to be categorized,called recursively.
10601:
10602: Inputs:
10603:
10604: itemcount - track row number for alternating colors
10605:
10606: cats - reference to array of arrays/hashes which encapsulates hierarchy of
10607: categories and subcategories.
10608:
10609: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
10610:
10611: parent - parent of current category item
10612:
10613: path - Array containing all categories back up through the hierarchy from the
10614: current category to the top level.
10615:
10616: currcategories - reference to array of current categories assigned to the course
10617:
10618: Returns: $output (markup to be displayed).
10619:
10620: =cut
10621:
10622: sub assign_category_rows {
10623: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
10624: my ($text,$name,$item,$chgstr);
10625: if (ref($cats) eq 'ARRAY') {
10626: my $maxdepth = scalar(@{$cats});
10627: if (ref($cats->[$depth]) eq 'HASH') {
10628: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10629: my $numchildren = @{$cats->[$depth]{$parent}};
10630: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10631: $text .= '<td><table class="LC_datatable">';
10632: for (my $j=0; $j<$numchildren; $j++) {
10633: $name = $cats->[$depth]{$parent}[$j];
10634: $item = &escape($name).':'.&escape($parent).':'.$depth;
10635: my $deeper = $depth+1;
10636: my $checked = '';
10637: if (ref($currcategories) eq 'ARRAY') {
10638: if (@{$currcategories} > 0) {
10639: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 10640: $checked = ' checked="checked"';
1.663 raeburn 10641: }
10642: }
10643: }
1.664 raeburn 10644: $text .= '<tr><td><span class="LC_nobreak"><label>'.
10645: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 10646: $item.'"'.$checked.' />'.$name.'</label></span>'.
10647: '<input type="hidden" name="catname" value="'.$name.'" />'.
10648: '</td><td>';
1.663 raeburn 10649: if (ref($path) eq 'ARRAY') {
10650: push(@{$path},$name);
10651: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10652: pop(@{$path});
10653: }
10654: $text .= '</td></tr>';
10655: }
10656: $text .= '</table></td>';
10657: }
10658: }
10659: }
10660: return $text;
10661: }
10662:
1.655 raeburn 10663: ############################################################
10664: ############################################################
10665:
10666:
1.443 albertel 10667: sub commit_customrole {
1.664 raeburn 10668: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10669: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10670: ($start?', '.&mt('starting').' '.localtime($start):'').
10671: ($end?', ending '.localtime($end):'').': <b>'.
10672: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10673: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10674: '</b><br />';
10675: return $output;
10676: }
10677:
10678: sub commit_standardrole {
1.541 raeburn 10679: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10680: my ($output,$logmsg,$linefeed);
10681: if ($context eq 'auto') {
10682: $linefeed = "\n";
10683: } else {
10684: $linefeed = "<br />\n";
10685: }
1.443 albertel 10686: if ($three eq 'st') {
1.541 raeburn 10687: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10688: $one,$two,$sec,$context);
10689: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10690: ($result eq 'unknown_course') || ($result eq 'refused')) {
10691: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10692: } else {
1.541 raeburn 10693: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10694: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10695: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10696: if ($context eq 'auto') {
10697: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10698: } else {
10699: $output .= '<b>'.$result.'</b>'.$linefeed.
10700: &mt('Add to classlist').': <b>ok</b>';
10701: }
10702: $output .= $linefeed;
1.443 albertel 10703: }
10704: } else {
10705: $output = &mt('Assigning').' '.$three.' in '.$url.
10706: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10707: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10708: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10709: if ($context eq 'auto') {
10710: $output .= $result.$linefeed;
10711: } else {
10712: $output .= '<b>'.$result.'</b>'.$linefeed;
10713: }
1.443 albertel 10714: }
10715: return $output;
10716: }
10717:
10718: sub commit_studentrole {
1.541 raeburn 10719: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10720: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10721: if ($context eq 'auto') {
10722: $linefeed = "\n";
10723: } else {
10724: $linefeed = '<br />'."\n";
10725: }
1.443 albertel 10726: if (defined($one) && defined($two)) {
10727: my $cid=$one.'_'.$two;
10728: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10729: my $secchange = 0;
10730: my $expire_role_result;
10731: my $modify_section_result;
1.628 raeburn 10732: if ($oldsec ne '-1') {
10733: if ($oldsec ne $sec) {
1.443 albertel 10734: $secchange = 1;
1.628 raeburn 10735: my $now = time;
1.443 albertel 10736: my $uurl='/'.$cid;
10737: $uurl=~s/\_/\//g;
10738: if ($oldsec) {
10739: $uurl.='/'.$oldsec;
10740: }
1.626 raeburn 10741: $oldsecurl = $uurl;
1.628 raeburn 10742: $expire_role_result =
1.652 raeburn 10743: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10744: if ($env{'request.course.sec'} ne '') {
10745: if ($expire_role_result eq 'refused') {
10746: my @roles = ('st');
10747: my @statuses = ('previous');
10748: my @roledoms = ($one);
10749: my $withsec = 1;
10750: my %roleshash =
10751: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10752: \@statuses,\@roles,\@roledoms,$withsec);
10753: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10754: my ($oldstart,$oldend) =
10755: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10756: if ($oldend > 0 && $oldend <= $now) {
10757: $expire_role_result = 'ok';
10758: }
10759: }
10760: }
10761: }
1.443 albertel 10762: $result = $expire_role_result;
10763: }
10764: }
10765: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10766: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10767: if ($modify_section_result =~ /^ok/) {
10768: if ($secchange == 1) {
1.628 raeburn 10769: if ($sec eq '') {
10770: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10771: } else {
10772: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10773: }
1.443 albertel 10774: } elsif ($oldsec eq '-1') {
1.628 raeburn 10775: if ($sec eq '') {
10776: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10777: } else {
10778: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10779: }
1.443 albertel 10780: } else {
1.628 raeburn 10781: if ($sec eq '') {
10782: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10783: } else {
10784: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10785: }
1.443 albertel 10786: }
10787: } else {
1.628 raeburn 10788: if ($secchange) {
10789: $$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;
10790: } else {
10791: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10792: }
1.443 albertel 10793: }
10794: $result = $modify_section_result;
10795: } elsif ($secchange == 1) {
1.628 raeburn 10796: if ($oldsec eq '') {
10797: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10798: } else {
10799: $$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;
10800: }
1.626 raeburn 10801: if ($expire_role_result eq 'refused') {
10802: my $newsecurl = '/'.$cid;
10803: $newsecurl =~ s/\_/\//g;
10804: if ($sec ne '') {
10805: $newsecurl.='/'.$sec;
10806: }
10807: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10808: if ($sec eq '') {
10809: $$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;
10810: } else {
10811: $$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;
10812: }
10813: }
10814: }
1.443 albertel 10815: }
10816: } else {
1.626 raeburn 10817: $$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 10818: $result = "error: incomplete course id\n";
10819: }
10820: return $result;
10821: }
10822:
10823: ############################################################
10824: ############################################################
10825:
1.566 albertel 10826: sub check_clone {
1.578 raeburn 10827: my ($args,$linefeed) = @_;
1.566 albertel 10828: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10829: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10830: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10831: my $clonemsg;
10832: my $can_clone = 0;
1.944 raeburn 10833: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10834: if ($lctype ne 'community') {
10835: $lctype = 'course';
10836: }
1.566 albertel 10837: if ($clonehome eq 'no_host') {
1.944 raeburn 10838: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10839: $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'});
10840: } else {
10841: $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'});
10842: }
1.566 albertel 10843: } else {
10844: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10845: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10846: if ($clonedesc{'type'} ne 'Community') {
10847: $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'});
10848: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10849: }
10850: }
1.882 raeburn 10851: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10852: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10853: $can_clone = 1;
10854: } else {
10855: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10856: $args->{'clonedomain'},$args->{'clonecourse'});
10857: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10858: if (grep(/^\*$/,@cloners)) {
10859: $can_clone = 1;
10860: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10861: $can_clone = 1;
10862: } else {
1.908 raeburn 10863: my $ccrole = 'cc';
1.944 raeburn 10864: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10865: $ccrole = 'co';
10866: }
1.578 raeburn 10867: my %roleshash =
10868: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10869: $args->{'ccdomain'},
1.908 raeburn 10870: 'userroles',['active'],[$ccrole],
1.578 raeburn 10871: [$args->{'clonedomain'}]);
1.908 raeburn 10872: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10873: $can_clone = 1;
10874: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10875: $can_clone = 1;
10876: } else {
1.944 raeburn 10877: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10878: $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'});
10879: } else {
10880: $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'});
10881: }
1.578 raeburn 10882: }
1.566 albertel 10883: }
1.578 raeburn 10884: }
1.566 albertel 10885: }
10886: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10887: }
10888:
1.444 albertel 10889: sub construct_course {
1.885 raeburn 10890: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10891: my $outcome;
1.541 raeburn 10892: my $linefeed = '<br />'."\n";
10893: if ($context eq 'auto') {
10894: $linefeed = "\n";
10895: }
1.566 albertel 10896:
10897: #
10898: # Are we cloning?
10899: #
10900: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10901: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10902: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10903: if ($context ne 'auto') {
1.578 raeburn 10904: if ($clonemsg ne '') {
10905: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10906: }
1.566 albertel 10907: }
10908: $outcome .= $clonemsg.$linefeed;
10909:
10910: if (!$can_clone) {
10911: return (0,$outcome);
10912: }
10913: }
10914:
1.444 albertel 10915: #
10916: # Open course
10917: #
10918: my $crstype = lc($args->{'crstype'});
10919: my %cenv=();
10920: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10921: $args->{'cdescr'},
10922: $args->{'curl'},
10923: $args->{'course_home'},
10924: $args->{'nonstandard'},
10925: $args->{'crscode'},
10926: $args->{'ccuname'}.':'.
10927: $args->{'ccdomain'},
1.882 raeburn 10928: $args->{'crstype'},
1.885 raeburn 10929: $cnum,$context,$category);
1.444 albertel 10930:
10931: # Note: The testing routines depend on this being output; see
10932: # Utils::Course. This needs to at least be output as a comment
10933: # if anyone ever decides to not show this, and Utils::Course::new
10934: # will need to be suitably modified.
1.541 raeburn 10935: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10936: if ($$courseid =~ /^error:/) {
10937: return (0,$outcome);
10938: }
10939:
1.444 albertel 10940: #
10941: # Check if created correctly
10942: #
1.479 albertel 10943: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10944: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10945: if ($crsuhome eq 'no_host') {
10946: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10947: return (0,$outcome);
10948: }
1.541 raeburn 10949: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10950:
1.444 albertel 10951: #
1.566 albertel 10952: # Do the cloning
10953: #
10954: if ($can_clone && $cloneid) {
10955: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10956: if ($context ne 'auto') {
10957: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10958: }
10959: $outcome .= $clonemsg.$linefeed;
10960: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10961: # Copy all files
1.637 www 10962: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10963: # Restore URL
1.566 albertel 10964: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10965: # Restore title
1.566 albertel 10966: $cenv{'description'}=$oldcenv{'description'};
1.948.2.2 raeburn 10967: # Restore creation date, creator and creation context.
10968: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10969: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10970: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10971: # Mark as cloned
1.566 albertel 10972: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10973: # Need to clone grading mode
10974: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10975: $cenv{'grading'}=$newenv{'grading'};
10976: # Do not clone these environment entries
10977: &Apache::lonnet::del('environment',
10978: ['default_enrollment_start_date',
10979: 'default_enrollment_end_date',
10980: 'question.email',
10981: 'policy.email',
10982: 'comment.email',
10983: 'pch.users.denied',
1.725 raeburn 10984: 'plc.users.denied',
10985: 'hidefromcat',
10986: 'categories'],
1.638 www 10987: $$crsudom,$$crsunum);
1.444 albertel 10988: }
1.566 albertel 10989:
1.444 albertel 10990: #
10991: # Set environment (will override cloned, if existing)
10992: #
10993: my @sections = ();
10994: my @xlists = ();
10995: if ($args->{'crstype'}) {
10996: $cenv{'type'}=$args->{'crstype'};
10997: }
10998: if ($args->{'crsid'}) {
10999: $cenv{'courseid'}=$args->{'crsid'};
11000: }
11001: if ($args->{'crscode'}) {
11002: $cenv{'internal.coursecode'}=$args->{'crscode'};
11003: }
11004: if ($args->{'crsquota'} ne '') {
11005: $cenv{'internal.coursequota'}=$args->{'crsquota'};
11006: } else {
11007: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
11008: }
11009: if ($args->{'ccuname'}) {
11010: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
11011: ':'.$args->{'ccdomain'};
11012: } else {
11013: $cenv{'internal.courseowner'} = $args->{'curruser'};
11014: }
11015: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
11016: if ($args->{'crssections'}) {
11017: $cenv{'internal.sectionnums'} = '';
11018: if ($args->{'crssections'} =~ m/,/) {
11019: @sections = split/,/,$args->{'crssections'};
11020: } else {
11021: $sections[0] = $args->{'crssections'};
11022: }
11023: if (@sections > 0) {
11024: foreach my $item (@sections) {
11025: my ($sec,$gp) = split/:/,$item;
11026: my $class = $args->{'crscode'}.$sec;
11027: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
11028: $cenv{'internal.sectionnums'} .= $item.',';
11029: unless ($addcheck eq 'ok') {
11030: push @badclasses, $class;
11031: }
11032: }
11033: $cenv{'internal.sectionnums'} =~ s/,$//;
11034: }
11035: }
11036: # do not hide course coordinator from staff listing,
11037: # even if privileged
11038: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11039: # add crosslistings
11040: if ($args->{'crsxlist'}) {
11041: $cenv{'internal.crosslistings'}='';
11042: if ($args->{'crsxlist'} =~ m/,/) {
11043: @xlists = split/,/,$args->{'crsxlist'};
11044: } else {
11045: $xlists[0] = $args->{'crsxlist'};
11046: }
11047: if (@xlists > 0) {
11048: foreach my $item (@xlists) {
11049: my ($xl,$gp) = split/:/,$item;
11050: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
11051: $cenv{'internal.crosslistings'} .= $item.',';
11052: unless ($addcheck eq 'ok') {
11053: push @badclasses, $xl;
11054: }
11055: }
11056: $cenv{'internal.crosslistings'} =~ s/,$//;
11057: }
11058: }
11059: if ($args->{'autoadds'}) {
11060: $cenv{'internal.autoadds'}=$args->{'autoadds'};
11061: }
11062: if ($args->{'autodrops'}) {
11063: $cenv{'internal.autodrops'}=$args->{'autodrops'};
11064: }
11065: # check for notification of enrollment changes
11066: my @notified = ();
11067: if ($args->{'notify_owner'}) {
11068: if ($args->{'ccuname'} ne '') {
11069: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
11070: }
11071: }
11072: if ($args->{'notify_dc'}) {
11073: if ($uname ne '') {
1.630 raeburn 11074: push(@notified,$uname.':'.$udom);
1.444 albertel 11075: }
11076: }
11077: if (@notified > 0) {
11078: my $notifylist;
11079: if (@notified > 1) {
11080: $notifylist = join(',',@notified);
11081: } else {
11082: $notifylist = $notified[0];
11083: }
11084: $cenv{'internal.notifylist'} = $notifylist;
11085: }
11086: if (@badclasses > 0) {
11087: my %lt=&Apache::lonlocal::texthash(
11088: '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',
11089: 'dnhr' => 'does not have rights to access enrollment in these classes',
11090: 'adby' => 'as determined by the policies of your institution on access to official classlists'
11091: );
1.541 raeburn 11092: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
11093: ' ('.$lt{'adby'}.')';
11094: if ($context eq 'auto') {
11095: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 11096: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 11097: foreach my $item (@badclasses) {
11098: if ($context eq 'auto') {
11099: $outcome .= " - $item\n";
11100: } else {
11101: $outcome .= "<li>$item</li>\n";
11102: }
11103: }
11104: if ($context eq 'auto') {
11105: $outcome .= $linefeed;
11106: } else {
1.566 albertel 11107: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 11108: }
11109: }
1.444 albertel 11110: }
11111: if ($args->{'no_end_date'}) {
11112: $args->{'endaccess'} = 0;
11113: }
11114: $cenv{'internal.autostart'}=$args->{'enrollstart'};
11115: $cenv{'internal.autoend'}=$args->{'enrollend'};
11116: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
11117: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
11118: if ($args->{'showphotos'}) {
11119: $cenv{'internal.showphotos'}=$args->{'showphotos'};
11120: }
11121: $cenv{'internal.authtype'} = $args->{'authtype'};
11122: $cenv{'internal.autharg'} = $args->{'autharg'};
11123: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
11124: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 11125: 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');
11126: if ($context eq 'auto') {
11127: $outcome .= $krb_msg;
11128: } else {
1.566 albertel 11129: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 11130: }
11131: $outcome .= $linefeed;
1.444 albertel 11132: }
11133: }
11134: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
11135: if ($args->{'setpolicy'}) {
11136: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11137: }
11138: if ($args->{'setcontent'}) {
11139: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11140: }
11141: }
11142: if ($args->{'reshome'}) {
11143: $cenv{'reshome'}=$args->{'reshome'}.'/';
11144: $cenv{'reshome'}=~s/\/+$/\//;
11145: }
11146: #
11147: # course has keyed access
11148: #
11149: if ($args->{'setkeys'}) {
11150: $cenv{'keyaccess'}='yes';
11151: }
11152: # if specified, key authority is not course, but user
11153: # only active if keyaccess is yes
11154: if ($args->{'keyauth'}) {
1.487 albertel 11155: my ($user,$domain) = split(':',$args->{'keyauth'});
11156: $user = &LONCAPA::clean_username($user);
11157: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 11158: if ($user ne '' && $domain ne '') {
1.487 albertel 11159: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 11160: }
11161: }
11162:
11163: if ($args->{'disresdis'}) {
11164: $cenv{'pch.roles.denied'}='st';
11165: }
11166: if ($args->{'disablechat'}) {
11167: $cenv{'plc.roles.denied'}='st';
11168: }
11169:
11170: # Record we've not yet viewed the Course Initialization Helper for this
11171: # course
11172: $cenv{'course.helper.not.run'} = 1;
11173: #
11174: # Use new Randomseed
11175: #
11176: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
11177: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
11178: #
11179: # The encryption code and receipt prefix for this course
11180: #
11181: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
11182: $cenv{'internal.encpref'}=100+int(9*rand(99));
11183: #
11184: # By default, use standard grading
11185: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
11186:
1.541 raeburn 11187: $outcome .= $linefeed.&mt('Setting environment').': '.
11188: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11189: #
11190: # Open all assignments
11191: #
11192: if ($args->{'openall'}) {
11193: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
11194: my %storecontent = ($storeunder => time,
11195: $storeunder.'.type' => 'date_start');
11196:
11197: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 11198: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11199: }
11200: #
11201: # Set first page
11202: #
11203: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
11204: || ($cloneid)) {
1.445 albertel 11205: use LONCAPA::map;
1.444 albertel 11206: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 11207:
11208: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
11209: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
11210:
1.444 albertel 11211: $outcome .= ($fatal?$errtext:'read ok').' - ';
11212: my $title; my $url;
11213: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 11214: $title=&mt('Syllabus');
1.444 albertel 11215: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
11216: } else {
1.948.2.5 raeburn 11217: $title=&mt('Table of Contents');
1.444 albertel 11218: $url='/adm/navmaps';
11219: }
1.445 albertel 11220:
11221: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
11222: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
11223:
11224: if ($errtext) { $fatal=2; }
1.541 raeburn 11225: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 11226: }
1.566 albertel 11227:
11228: return (1,$outcome);
1.444 albertel 11229: }
11230:
11231: ############################################################
11232: ############################################################
11233:
1.378 raeburn 11234: sub course_type {
11235: my ($cid) = @_;
11236: if (!defined($cid)) {
11237: $cid = $env{'request.course.id'};
11238: }
1.404 albertel 11239: if (defined($env{'course.'.$cid.'.type'})) {
11240: return $env{'course.'.$cid.'.type'};
1.378 raeburn 11241: } else {
11242: return 'Course';
1.377 raeburn 11243: }
11244: }
1.156 albertel 11245:
1.406 raeburn 11246: sub group_term {
11247: my $crstype = &course_type();
11248: my %names = (
11249: 'Course' => 'group',
1.865 raeburn 11250: 'Community' => 'group',
1.406 raeburn 11251: );
11252: return $names{$crstype};
11253: }
11254:
1.902 raeburn 11255: sub course_types {
11256: my @types = ('official','unofficial','community');
11257: my %typename = (
11258: official => 'Official course',
11259: unofficial => 'Unofficial course',
11260: community => 'Community',
11261: );
11262: return (\@types,\%typename);
11263: }
11264:
1.156 albertel 11265: sub icon {
11266: my ($file)=@_;
1.505 albertel 11267: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 11268: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 11269: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 11270: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
11271: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
11272: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11273: $curfext.".gif") {
11274: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11275: $curfext.".gif";
11276: }
11277: }
1.249 albertel 11278: return &lonhttpdurl($iconname);
1.154 albertel 11279: }
1.84 albertel 11280:
1.575 albertel 11281: sub lonhttpdurl {
1.692 www 11282: #
11283: # Had been used for "small fry" static images on separate port 8080.
11284: # Modify here if lightweight http functionality desired again.
11285: # Currently eliminated due to increasing firewall issues.
11286: #
1.575 albertel 11287: my ($url)=@_;
1.692 www 11288: return $url;
1.215 albertel 11289: }
11290:
1.213 albertel 11291: sub connection_aborted {
11292: my ($r)=@_;
11293: $r->print(" ");$r->rflush();
11294: my $c = $r->connection;
11295: return $c->aborted();
11296: }
11297:
1.221 foxr 11298: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 11299: # strings as 'strings'.
11300: sub escape_single {
1.221 foxr 11301: my ($input) = @_;
1.223 albertel 11302: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 11303: $input =~ s/\'/\\\'/g; # Esacpe the 's....
11304: return $input;
11305: }
1.223 albertel 11306:
1.222 foxr 11307: # Same as escape_single, but escape's "'s This
11308: # can be used for "strings"
11309: sub escape_double {
11310: my ($input) = @_;
11311: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
11312: $input =~ s/\"/\\\"/g; # Esacpe the "s....
11313: return $input;
11314: }
1.223 albertel 11315:
1.222 foxr 11316: # Escapes the last element of a full URL.
11317: sub escape_url {
11318: my ($url) = @_;
1.238 raeburn 11319: my @urlslices = split(/\//, $url,-1);
1.369 www 11320: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 11321: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 11322: }
1.462 albertel 11323:
1.820 raeburn 11324: sub compare_arrays {
11325: my ($arrayref1,$arrayref2) = @_;
11326: my (@difference,%count);
11327: @difference = ();
11328: %count = ();
11329: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
11330: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
11331: foreach my $element (keys(%count)) {
11332: if ($count{$element} == 1) {
11333: push(@difference,$element);
11334: }
11335: }
11336: }
11337: return @difference;
11338: }
11339:
1.817 bisitz 11340: # -------------------------------------------------------- Initialize user login
1.462 albertel 11341: sub init_user_environment {
1.463 albertel 11342: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 11343: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
11344:
11345: my $public=($username eq 'public' && $domain eq 'public');
11346:
11347: # See if old ID present, if so, remove
11348:
11349: my ($filename,$cookie,$userroles);
11350: my $now=time;
11351:
11352: if ($public) {
11353: my $max_public=100;
11354: my $oldest;
11355: my $oldest_time=0;
11356: for(my $next=1;$next<=$max_public;$next++) {
11357: if (-e $lonids."/publicuser_$next.id") {
11358: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
11359: if ($mtime<$oldest_time || !$oldest_time) {
11360: $oldest_time=$mtime;
11361: $oldest=$next;
11362: }
11363: } else {
11364: $cookie="publicuser_$next";
11365: last;
11366: }
11367: }
11368: if (!$cookie) { $cookie="publicuser_$oldest"; }
11369: } else {
1.463 albertel 11370: # if this isn't a robot, kill any existing non-robot sessions
11371: if (!$args->{'robot'}) {
11372: opendir(DIR,$lonids);
11373: while ($filename=readdir(DIR)) {
11374: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
11375: unlink($lonids.'/'.$filename);
11376: }
1.462 albertel 11377: }
1.463 albertel 11378: closedir(DIR);
1.462 albertel 11379: }
11380: # Give them a new cookie
1.463 albertel 11381: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 11382: : $now.$$.int(rand(10000)));
1.463 albertel 11383: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 11384:
11385: # Initialize roles
11386:
11387: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
11388: }
11389: # ------------------------------------ Check browser type and MathML capability
11390:
11391: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
11392: $clientunicode,$clientos) = &decode_user_agent($r);
11393:
11394: # ------------------------------------------------------------- Get environment
11395:
11396: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
11397: my ($tmp) = keys(%userenv);
11398: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11399: # default remote control to off
11400: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
11401: } else {
11402: undef(%userenv);
11403: }
11404: if (($userenv{'interface'}) && (!$form->{'interface'})) {
11405: $form->{'interface'}=$userenv{'interface'};
11406: }
11407: $env{'environment.remote'}=$userenv{'remote'};
11408: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
11409:
11410: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 11411: foreach my $option ('interface','localpath','localres') {
11412: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 11413: }
11414: # --------------------------------------------------------- Write first profile
11415:
11416: {
11417: my %initial_env =
11418: ("user.name" => $username,
11419: "user.domain" => $domain,
11420: "user.home" => $authhost,
11421: "browser.type" => $clientbrowser,
11422: "browser.version" => $clientversion,
11423: "browser.mathml" => $clientmathml,
11424: "browser.unicode" => $clientunicode,
11425: "browser.os" => $clientos,
11426: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
11427: "request.course.fn" => '',
11428: "request.course.uri" => '',
11429: "request.course.sec" => '',
11430: "request.role" => 'cm',
11431: "request.role.adv" => $env{'user.adv'},
11432: "request.host" => $ENV{'REMOTE_ADDR'},);
11433:
11434: if ($form->{'localpath'}) {
11435: $initial_env{"browser.localpath"} = $form->{'localpath'};
11436: $initial_env{"browser.localres"} = $form->{'localres'};
11437: }
11438:
11439: if ($public) {
11440: $initial_env{"environment.remote"} = "off";
11441: }
11442: if ($form->{'interface'}) {
11443: $form->{'interface'}=~s/\W//gs;
11444: $initial_env{"browser.interface"} = $form->{'interface'};
11445: $env{'browser.interface'}=$form->{'interface'};
11446: }
1.948.2.11 raeburn 11447: my %is_adv = ( is_adv => $env{'user.adv'} );
1.948.2.31 raeburn 11448: my %domdef;
11449: unless ($domain eq 'public') {
11450: %domdef = &Apache::lonnet::get_domain_defaults($domain);
11451: }
1.462 albertel 11452:
1.724 raeburn 11453: foreach my $tool ('aboutme','blog','portfolio') {
11454: $userenv{'availabletools.'.$tool} =
1.948.2.10 raeburn 11455: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
11456: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 11457: }
11458:
1.864 raeburn 11459: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 11460: $userenv{'canrequest.'.$crstype} =
11461: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.948.2.10 raeburn 11462: 'reload','requestcourses',
11463: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 11464: }
11465:
1.462 albertel 11466: $env{'user.environment'} = "$lonids/$cookie.id";
11467:
11468: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
11469: &GDBM_WRCREAT(),0640)) {
11470: &_add_to_env(\%disk_env,\%initial_env);
11471: &_add_to_env(\%disk_env,\%userenv,'environment.');
11472: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 11473: if (ref($args->{'extra_env'})) {
11474: &_add_to_env(\%disk_env,$args->{'extra_env'});
11475: }
1.462 albertel 11476: untie(%disk_env);
11477: } else {
1.705 tempelho 11478: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
11479: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 11480: return 'error: '.$!;
11481: }
11482: }
11483: $env{'request.role'}='cm';
11484: $env{'request.role.adv'}=$env{'user.adv'};
11485: $env{'browser.type'}=$clientbrowser;
11486:
11487: return $cookie;
11488:
11489: }
11490:
11491: sub _add_to_env {
11492: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 11493: if (ref($env_data) eq 'HASH') {
11494: while (my ($key,$value) = each(%$env_data)) {
11495: $idf->{$prefix.$key} = $value;
11496: $env{$prefix.$key} = $value;
11497: }
1.462 albertel 11498: }
11499: }
11500:
1.685 tempelho 11501: # --- Get the symbolic name of a problem and the url
11502: sub get_symb {
11503: my ($request,$silent) = @_;
1.726 raeburn 11504: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 11505: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
11506: if ($symb eq '') {
11507: if (!$silent) {
11508: $request->print("Unable to handle ambiguous references:$url:.");
11509: return ();
11510: }
11511: }
11512: &Apache::lonenc::check_decrypt(\$symb);
11513: return ($symb);
11514: }
11515:
11516: # --------------------------------------------------------------Get annotation
11517:
11518: sub get_annotation {
11519: my ($symb,$enc) = @_;
11520:
11521: my $key = $symb;
11522: if (!$enc) {
11523: $key =
11524: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
11525: }
11526: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
11527: return $annotation{$key};
11528: }
11529:
11530: sub clean_symb {
1.731 raeburn 11531: my ($symb,$delete_enc) = @_;
1.685 tempelho 11532:
11533: &Apache::lonenc::check_decrypt(\$symb);
11534: my $enc = $env{'request.enc'};
1.731 raeburn 11535: if ($delete_enc) {
1.730 raeburn 11536: delete($env{'request.enc'});
11537: }
1.685 tempelho 11538:
11539: return ($symb,$enc);
11540: }
1.462 albertel 11541:
1.948.2.16 raeburn 11542: sub build_release_hashes {
11543: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
11544: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
11545: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
11546: (ref($randomizetry) eq 'HASH'));
11547: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
11548: my ($item,$name,$value) = split(/:/,$key);
11549: if ($item eq 'parameter') {
11550: if (ref($checkparms->{$name}) eq 'ARRAY') {
11551: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
11552: push(@{$checkparms->{$name}},$value);
11553: }
11554: } else {
11555: push(@{$checkparms->{$name}},$value);
11556: }
11557: } elsif ($item eq 'resourcetag') {
11558: if ($name eq 'responsetype') {
11559: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
11560: }
11561: } elsif ($item eq 'course') {
11562: if ($name eq 'crstype') {
11563: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
11564: }
11565: }
11566: }
11567: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
11568: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
11569: return;
11570: }
11571:
1.41 ng 11572: =pod
11573:
11574: =back
11575:
1.112 bowersj2 11576: =cut
1.41 ng 11577:
1.112 bowersj2 11578: 1;
11579: __END__;
1.41 ng 11580:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>