Annotation of loncom/interface/loncommon.pm, revision 1.866
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.866 ! kalberla 4: # $Id: loncommon.pm,v 1.865 2009/07/25 23:16:04 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.793 raeburn 412: function openstdbrowser(formname,uname,udom,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+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.468 raeburn 485: my ($domainfilter,$sec_element,$formname)=@_;
1.865 raeburn 486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role');
1.468 raeburn 487: my $output = '
1.776 bisitz 488: <script type="text/javascript" language="JavaScript">
1.824 bisitz 489: // <![CDATA[
1.468 raeburn 490: var stdeditbrowser;'."\n";
491: $output .= <<"ENDSTDBRW";
1.377 raeburn 492: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 493: var url = '/adm/pickcourse?';
1.468 raeburn 494: var domainfilter = '';
495: var formid = getFormIdByName(formname);
496: if (formid > -1) {
497: var domid = getIndexByName(formid,udom);
498: if (domid > -1) {
499: if (document.forms[formid].elements[domid].type == 'select-one') {
500: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
501: }
502: if (document.forms[formid].elements[domid].type == 'hidden') {
503: domainfilter=document.forms[formid].elements[domid].value;
504: }
505: }
1.91 www 506: }
1.128 albertel 507: if (domainfilter != null) {
508: if (domainfilter != '') {
509: url += 'domainfilter='+domainfilter+'&';
510: }
511: }
1.91 www 512: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 513: '&cdomelement='+udom+
514: '&cnameelement='+desc;
1.468 raeburn 515: if (extra_element !=null && extra_element != '') {
1.594 raeburn 516: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 517: url += '&roleelement='+extra_element;
518: if (domainfilter == null || domainfilter == '') {
519: url += '&domainfilter='+extra_element;
520: }
1.234 raeburn 521: }
1.468 raeburn 522: else {
523: if (formname == 'portform') {
524: url += '&setroles='+extra_element;
1.800 raeburn 525: } else {
526: if (formname == 'rules') {
527: url += '&fixeddom='+extra_element;
528: }
1.468 raeburn 529: }
530: }
1.230 raeburn 531: }
1.293 raeburn 532: if (multflag !=null && multflag != '') {
533: url += '&multiple='+multflag;
534: }
1.865 raeburn 535: if (crstype == 'Course/Community') {
1.377 raeburn 536: if (formname == 'cu') {
537: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
538: if (crstype == "") {
539: alert("$crs_or_grp_alert");
540: return;
541: }
542: }
543: }
544: if (crstype !=null && crstype != '') {
545: url += '&type='+crstype;
546: }
1.102 www 547: var title = 'Course_Browser';
1.91 www 548: var options = 'scrollbars=1,resizable=1,menubar=0';
549: options += ',width=700,height=600';
550: stdeditbrowser = open(url,title,options,'1');
551: stdeditbrowser.focus();
552: }
1.468 raeburn 553:
554: function getFormIdByName(formname) {
555: for (var i=0;i<document.forms.length;i++) {
556: if (document.forms[i].name == formname) {
557: return i;
558: }
559: }
560: return -1;
561: }
562:
563: function getIndexByName(formid,item) {
564: for (var i=0;i<document.forms[formid].elements.length;i++) {
565: if (document.forms[formid].elements[i].name == item) {
566: return i;
567: }
568: }
569: return -1;
570: }
1.91 www 571: ENDSTDBRW
1.468 raeburn 572: if ($sec_element ne '') {
573: $output .= &setsec_javascript($sec_element,$formname);
574: }
575: $output .= '
1.824 bisitz 576: // ]]>
1.468 raeburn 577: </script>';
578: return $output;
579: }
580:
581: sub setsec_javascript {
582: my ($sec_element,$formname) = @_;
583: my $setsections = qq|
584: function setSect(sectionlist) {
1.629 raeburn 585: var sectionsArray = new Array();
586: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
587: sectionsArray = sectionlist.split(",");
588: }
1.468 raeburn 589: var numSections = sectionsArray.length;
590: document.$formname.$sec_element.length = 0;
591: if (numSections == 0) {
592: document.$formname.$sec_element.multiple=false;
593: document.$formname.$sec_element.size=1;
594: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
595: } else {
596: if (numSections == 1) {
597: document.$formname.$sec_element.multiple=false;
598: document.$formname.$sec_element.size=1;
599: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
600: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
601: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
602: } else {
603: for (var i=0; i<numSections; i++) {
604: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
605: }
606: document.$formname.$sec_element.multiple=true
607: if (numSections < 3) {
608: document.$formname.$sec_element.size=numSections;
609: } else {
610: document.$formname.$sec_element.size=3;
611: }
612: document.$formname.$sec_element.options[0].selected = false
613: }
614: }
1.91 www 615: }
1.468 raeburn 616: |;
617: return $setsections;
618: }
619:
1.91 www 620:
621: sub selectcourse_link {
1.377 raeburn 622: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787 bisitz 623: return '<span class="LC_nobreak">'
624: ."<a href='"
625: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
626: .'","'.$udomele.'","'.$desc.'","'.$extra_element
627: .'","'.$multflag.'","'.$selecttype.'");'
628: ."'>".&mt('Select Course').'</a>'
629: .'</span>';
1.74 www 630: }
1.42 matthew 631:
1.653 raeburn 632: sub selectauthor_link {
633: my ($form,$udom)=@_;
634: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
635: &mt('Select Author').'</a>';
636: }
637:
1.273 raeburn 638: sub check_uncheck_jscript {
639: my $jscript = <<"ENDSCRT";
640: function checkAll(field) {
641: if (field.length > 0) {
642: for (i = 0; i < field.length; i++) {
643: field[i].checked = true ;
644: }
645: } else {
646: field.checked = true
647: }
648: }
649:
650: function uncheckAll(field) {
651: if (field.length > 0) {
652: for (i = 0; i < field.length; i++) {
653: field[i].checked = false ;
1.543 albertel 654: }
655: } else {
1.273 raeburn 656: field.checked = false ;
657: }
658: }
659: ENDSCRT
660: return $jscript;
661: }
662:
1.656 www 663: sub select_timezone {
1.659 raeburn 664: my ($name,$selected,$onchange,$includeempty)=@_;
665: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
666: if ($includeempty) {
667: $output .= '<option value=""';
668: if (($selected eq '') || ($selected eq 'local')) {
669: $output .= ' selected="selected" ';
670: }
671: $output .= '> </option>';
672: }
1.657 raeburn 673: my @timezones = DateTime::TimeZone->all_names;
674: foreach my $tzone (@timezones) {
675: $output.= '<option value="'.$tzone.'"';
676: if ($tzone eq $selected) {
677: $output.=' selected="selected"';
678: }
679: $output.=">$tzone</option>\n";
1.656 www 680: }
681: $output.="</select>";
682: return $output;
683: }
1.273 raeburn 684:
1.687 raeburn 685: sub select_datelocale {
686: my ($name,$selected,$onchange,$includeempty)=@_;
687: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
688: if ($includeempty) {
689: $output .= '<option value=""';
690: if ($selected eq '') {
691: $output .= ' selected="selected" ';
692: }
693: $output .= '> </option>';
694: }
695: my (@possibles,%locale_names);
696: my @locales = DateTime::Locale::Catalog::Locales;
697: foreach my $locale (@locales) {
698: if (ref($locale) eq 'HASH') {
699: my $id = $locale->{'id'};
700: if ($id ne '') {
701: my $en_terr = $locale->{'en_territory'};
702: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 703: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 704: if (grep(/^en$/,@languages) || !@languages) {
705: if ($en_terr ne '') {
706: $locale_names{$id} = '('.$en_terr.')';
707: } elsif ($native_terr ne '') {
708: $locale_names{$id} = $native_terr;
709: }
710: } else {
711: if ($native_terr ne '') {
712: $locale_names{$id} = $native_terr.' ';
713: } elsif ($en_terr ne '') {
714: $locale_names{$id} = '('.$en_terr.')';
715: }
716: }
717: push (@possibles,$id);
718: }
719: }
720: }
721: foreach my $item (sort(@possibles)) {
722: $output.= '<option value="'.$item.'"';
723: if ($item eq $selected) {
724: $output.=' selected="selected"';
725: }
726: $output.=">$item";
727: if ($locale_names{$item} ne '') {
728: $output.=" $locale_names{$item}</option>\n";
729: }
730: $output.="</option>\n";
731: }
732: $output.="</select>";
733: return $output;
734: }
735:
1.792 raeburn 736: sub select_language {
737: my ($name,$selected,$includeempty) = @_;
738: my %langchoices;
739: if ($includeempty) {
740: %langchoices = ('' => 'No language preference');
741: }
742: foreach my $id (&languageids()) {
743: my $code = &supportedlanguagecode($id);
744: if ($code) {
745: $langchoices{$code} = &plainlanguagedescription($id);
746: }
747: }
748: return &select_form($selected,$name,%langchoices);
749: }
750:
1.42 matthew 751: =pod
1.36 matthew 752:
1.648 raeburn 753: =item * &linked_select_forms(...)
1.36 matthew 754:
755: linked_select_forms returns a string containing a <script></script> block
756: and html for two <select> menus. The select menus will be linked in that
757: changing the value of the first menu will result in new values being placed
758: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 759: order unless a defined order is provided.
1.36 matthew 760:
761: linked_select_forms takes the following ordered inputs:
762:
763: =over 4
764:
1.112 bowersj2 765: =item * $formname, the name of the <form> tag
1.36 matthew 766:
1.112 bowersj2 767: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 768:
1.112 bowersj2 769: =item * $firstdefault, the default value for the first menu
1.36 matthew 770:
1.112 bowersj2 771: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 772:
1.112 bowersj2 773: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 774:
1.112 bowersj2 775: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 776:
1.609 raeburn 777: =item * $menuorder, the order of values in the first menu
778:
1.41 ng 779: =back
780:
1.36 matthew 781: Below is an example of such a hash. Only the 'text', 'default', and
782: 'select2' keys must appear as stated. keys(%menu) are the possible
783: values for the first select menu. The text that coincides with the
1.41 ng 784: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 785: and text for the second menu are given in the hash pointed to by
786: $menu{$choice1}->{'select2'}.
787:
1.112 bowersj2 788: my %menu = ( A1 => { text =>"Choice A1" ,
789: default => "B3",
790: select2 => {
791: B1 => "Choice B1",
792: B2 => "Choice B2",
793: B3 => "Choice B3",
794: B4 => "Choice B4"
1.609 raeburn 795: },
796: order => ['B4','B3','B1','B2'],
1.112 bowersj2 797: },
798: A2 => { text =>"Choice A2" ,
799: default => "C2",
800: select2 => {
801: C1 => "Choice C1",
802: C2 => "Choice C2",
803: C3 => "Choice C3"
1.609 raeburn 804: },
805: order => ['C2','C1','C3'],
1.112 bowersj2 806: },
807: A3 => { text =>"Choice A3" ,
808: default => "D6",
809: select2 => {
810: D1 => "Choice D1",
811: D2 => "Choice D2",
812: D3 => "Choice D3",
813: D4 => "Choice D4",
814: D5 => "Choice D5",
815: D6 => "Choice D6",
816: D7 => "Choice D7"
1.609 raeburn 817: },
818: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 819: }
820: );
1.36 matthew 821:
822: =cut
823:
824: sub linked_select_forms {
825: my ($formname,
826: $middletext,
827: $firstdefault,
828: $firstselectname,
829: $secondselectname,
1.609 raeburn 830: $hashref,
831: $menuorder,
1.36 matthew 832: ) = @_;
833: my $second = "document.$formname.$secondselectname";
834: my $first = "document.$formname.$firstselectname";
835: # output the javascript to do the changing
836: my $result = '';
1.776 bisitz 837: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 838: $result.="// <![CDATA[\n";
1.36 matthew 839: $result.="var select2data = new Object();\n";
840: $" = '","';
841: my $debug = '';
842: foreach my $s1 (sort(keys(%$hashref))) {
843: $result.="select2data.d_$s1 = new Object();\n";
844: $result.="select2data.d_$s1.def = new String('".
845: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 846: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 847: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 848: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
849: @s2values = @{$hashref->{$s1}->{'order'}};
850: }
1.36 matthew 851: $result.="\"@s2values\");\n";
852: $result.="select2data.d_$s1.texts = new Array(";
853: my @s2texts;
854: foreach my $value (@s2values) {
855: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
856: }
857: $result.="\"@s2texts\");\n";
858: }
859: $"=' ';
860: $result.= <<"END";
861:
862: function select1_changed() {
863: // Determine new choice
864: var newvalue = "d_" + $first.value;
865: // update select2
866: var values = select2data[newvalue].values;
867: var texts = select2data[newvalue].texts;
868: var select2def = select2data[newvalue].def;
869: var i;
870: // out with the old
871: for (i = 0; i < $second.options.length; i++) {
872: $second.options[i] = null;
873: }
874: // in with the nuclear
875: for (i=0;i<values.length; i++) {
876: $second.options[i] = new Option(values[i]);
1.143 matthew 877: $second.options[i].value = values[i];
1.36 matthew 878: $second.options[i].text = texts[i];
879: if (values[i] == select2def) {
880: $second.options[i].selected = true;
881: }
882: }
883: }
1.824 bisitz 884: // ]]>
1.36 matthew 885: </script>
886: END
887: # output the initial values for the selection lists
888: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 889: my @order = sort(keys(%{$hashref}));
890: if (ref($menuorder) eq 'ARRAY') {
891: @order = @{$menuorder};
892: }
893: foreach my $value (@order) {
1.36 matthew 894: $result.=" <option value=\"$value\" ";
1.253 albertel 895: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 896: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 897: }
898: $result .= "</select>\n";
899: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
900: $result .= $middletext;
901: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
902: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 903:
904: my @secondorder = sort(keys(%select2));
905: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
906: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
907: }
908: foreach my $value (@secondorder) {
1.36 matthew 909: $result.=" <option value=\"$value\" ";
1.253 albertel 910: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 911: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 912: }
913: $result .= "</select>\n";
914: # return $debug;
915: return $result;
916: } # end of sub linked_select_forms {
917:
1.45 matthew 918: =pod
1.44 bowersj2 919:
1.648 raeburn 920: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 921:
1.112 bowersj2 922: Returns a string corresponding to an HTML link to the given help
923: $topic, where $topic corresponds to the name of a .tex file in
924: /home/httpd/html/adm/help/tex, with underscores replaced by
925: spaces.
926:
927: $text will optionally be linked to the same topic, allowing you to
928: link text in addition to the graphic. If you do not want to link
929: text, but wish to specify one of the later parameters, pass an
930: empty string.
931:
932: $stayOnPage is a value that will be interpreted as a boolean. If true,
933: the link will not open a new window. If false, the link will open
934: a new window using Javascript. (Default is false.)
935:
936: $width and $height are optional numerical parameters that will
937: override the width and height of the popped up window, which may
938: be useful for certain help topics with big pictures included.
1.44 bowersj2 939:
940: =cut
941:
942: sub help_open_topic {
1.48 bowersj2 943: my ($topic, $text, $stayOnPage, $width, $height) = @_;
944: $text = "" if (not defined $text);
1.44 bowersj2 945: $stayOnPage = 0 if (not defined $stayOnPage);
946: $width = 350 if (not defined $width);
947: $height = 400 if (not defined $height);
948: my $filename = $topic;
949: $filename =~ s/ /_/g;
950:
1.48 bowersj2 951: my $template = "";
952: my $link;
1.572 banghart 953:
1.159 www 954: $topic=~s/\W/\_/g;
1.44 bowersj2 955:
1.572 banghart 956: if (!$stayOnPage) {
1.72 bowersj2 957: $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 958: } else {
1.48 bowersj2 959: $link = "/adm/help/${filename}.hlp";
960: }
961:
962: # Add the text
1.755 neumanie 963: if ($text ne "") {
1.763 bisitz 964: $template.='<span class="LC_help_open_topic">'
965: .'<a target="_top" href="'.$link.'">'
966: .$text.'</a>';
1.48 bowersj2 967: }
968:
1.763 bisitz 969: # (Always) Add the graphic
1.179 matthew 970: my $title = &mt('Online Help');
1.667 raeburn 971: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 972: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
973: .'<img src="'.$helpicon.'" border="0"'
974: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 975: .' title="'.$title.'"'
1.763 bisitz 976: .' /></a>';
977: if ($text ne "") {
978: $template.='</span>';
979: }
1.44 bowersj2 980: return $template;
981:
1.106 bowersj2 982: }
983:
984: # This is a quicky function for Latex cheatsheet editing, since it
985: # appears in at least four places
986: sub helpLatexCheatsheet {
1.732 raeburn 987: my ($topic,$text,$not_author) = @_;
988: my $out;
1.106 bowersj2 989: my $addOther = '';
1.732 raeburn 990: if ($topic) {
1.763 bisitz 991: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
992: undef, undef, 600).
993: '</span> ';
994: }
995: $out = '<span>' # Start cheatsheet
996: .$addOther
997: .'<span>'
998: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
999: undef,undef,600)
1000: .'</span> <span>'
1001: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1002: undef,undef,600)
1003: .'</span>';
1.732 raeburn 1004: unless ($not_author) {
1.763 bisitz 1005: $out .= ' <span>'
1006: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1007: undef,undef,600)
1008: .'</span>';
1.732 raeburn 1009: }
1.763 bisitz 1010: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1011: return $out;
1.172 www 1012: }
1013:
1.430 albertel 1014: sub general_help {
1015: my $helptopic='Student_Intro';
1016: if ($env{'request.role'}=~/^(ca|au)/) {
1017: $helptopic='Authoring_Intro';
1018: } elsif ($env{'request.role'}=~/^cc/) {
1019: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1020: } elsif ($env{'request.role'}=~/^dc/) {
1021: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1022: }
1023: return $helptopic;
1024: }
1025:
1026: sub update_help_link {
1027: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1028: my $origurl = $ENV{'REQUEST_URI'};
1029: $origurl=~s|^/~|/priv/|;
1030: my $timestamp = time;
1031: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1032: $$datum = &escape($$datum);
1033: }
1034:
1035: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1036: my $output .= <<"ENDOUTPUT";
1037: <script type="text/javascript">
1.824 bisitz 1038: // <![CDATA[
1.430 albertel 1039: banner_link = '$banner_link';
1.824 bisitz 1040: // ]]>
1.430 albertel 1041: </script>
1042: ENDOUTPUT
1043: return $output;
1044: }
1045:
1046: # now just updates the help link and generates a blue icon
1.193 raeburn 1047: sub help_open_menu {
1.430 albertel 1048: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1049: = @_;
1.430 albertel 1050: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1051: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1052: # if environment.remote is on (using remote control UI)
1.798 tempelho 1053: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1054: $stayOnPage=1;
1.430 albertel 1055: }
1056: my $output;
1057: if ($component_help) {
1058: if (!$text) {
1059: $output=&help_open_topic($component_help,undef,$stayOnPage,
1060: $width,$height);
1061: } else {
1062: my $help_text;
1063: $help_text=&unescape($topic);
1064: $output='<table><tr><td>'.
1065: &help_open_topic($component_help,$help_text,$stayOnPage,
1066: $width,$height).'</td></tr></table>';
1067: }
1068: }
1069: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1070: return $output.$banner_link;
1071: }
1072:
1073: sub top_nav_help {
1074: my ($text) = @_;
1.436 albertel 1075: $text = &mt($text);
1.572 banghart 1076: my $stay_on_page =
1.798 tempelho 1077: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1078: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1079: : "javascript:helpMenu('open')";
1.572 banghart 1080: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1081:
1.201 raeburn 1082: my $title = &mt('Get help');
1.436 albertel 1083:
1084: return <<"END";
1085: $banner_link
1086: <a href="$link" title="$title">$text</a>
1087: END
1088: }
1089:
1090: sub help_menu_js {
1091: my ($text) = @_;
1092:
1093: my $stayOnPage =
1.798 tempelho 1094: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1095:
1096: my $width = 620;
1097: my $height = 600;
1.430 albertel 1098: my $helptopic=&general_help();
1099: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1100: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1101: my $start_page =
1102: &Apache::loncommon::start_page('Help Menu', undef,
1103: {'frameset' => 1,
1104: 'js_ready' => 1,
1105: 'add_entries' => {
1106: 'border' => '0',
1.579 raeburn 1107: 'rows' => "110,*",},});
1.331 albertel 1108: my $end_page =
1109: &Apache::loncommon::end_page({'frameset' => 1,
1110: 'js_ready' => 1,});
1111:
1.436 albertel 1112: my $template .= <<"ENDTEMPLATE";
1113: <script type="text/javascript">
1.253 albertel 1114: // <!-- BEGIN LON-CAPA Internal
1115: // <![CDATA[
1.430 albertel 1116: var banner_link = '';
1.243 raeburn 1117: function helpMenu(target) {
1118: var caller = this;
1119: if (target == 'open') {
1120: var newWindow = null;
1121: try {
1.262 albertel 1122: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1123: }
1124: catch(error) {
1125: writeHelp(caller);
1126: return;
1127: }
1128: if (newWindow) {
1129: caller = newWindow;
1130: }
1.193 raeburn 1131: }
1.243 raeburn 1132: writeHelp(caller);
1133: return;
1134: }
1135: function writeHelp(caller) {
1.430 albertel 1136: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1137: caller.document.close()
1138: caller.focus()
1.193 raeburn 1139: }
1.253 albertel 1140: // ]]>
1.219 albertel 1141: // END LON-CAPA Internal -->
1.436 albertel 1142: </script>
1.193 raeburn 1143: ENDTEMPLATE
1144: return $template;
1145: }
1146:
1.172 www 1147: sub help_open_bug {
1148: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1149: unless ($env{'user.adv'}) { return ''; }
1.172 www 1150: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1151: $text = "" if (not defined $text);
1152: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1153: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1154: $stayOnPage=1;
1155: }
1.184 albertel 1156: $width = 600 if (not defined $width);
1157: $height = 600 if (not defined $height);
1.172 www 1158:
1159: $topic=~s/\W+/\+/g;
1160: my $link='';
1161: my $template='';
1.379 albertel 1162: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1163: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1164: if (!$stayOnPage)
1165: {
1166: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1167: }
1168: else
1169: {
1170: $link = $url;
1171: }
1172: # Add the text
1173: if ($text ne "")
1174: {
1175: $template .=
1176: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1177: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1178: }
1179:
1180: # Add the graphic
1.179 matthew 1181: my $title = &mt('Report a Bug');
1.215 albertel 1182: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1183: $template .= <<"ENDTEMPLATE";
1.436 albertel 1184: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1185: ENDTEMPLATE
1186: if ($text ne '') { $template.='</td></tr></table>' };
1187: return $template;
1188:
1189: }
1190:
1191: sub help_open_faq {
1192: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1193: unless ($env{'user.adv'}) { return ''; }
1.172 www 1194: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1195: $text = "" if (not defined $text);
1196: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1197: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1198: $stayOnPage=1;
1199: }
1200: $width = 350 if (not defined $width);
1201: $height = 400 if (not defined $height);
1202:
1203: $topic=~s/\W+/\+/g;
1204: my $link='';
1205: my $template='';
1206: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1207: if (!$stayOnPage)
1208: {
1209: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1210: }
1211: else
1212: {
1213: $link = $url;
1214: }
1215:
1216: # Add the text
1217: if ($text ne "")
1218: {
1219: $template .=
1.173 www 1220: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1221: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1222: }
1223:
1224: # Add the graphic
1.179 matthew 1225: my $title = &mt('View the FAQ');
1.215 albertel 1226: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1227: $template .= <<"ENDTEMPLATE";
1.436 albertel 1228: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1229: ENDTEMPLATE
1230: if ($text ne '') { $template.='</td></tr></table>' };
1231: return $template;
1232:
1.44 bowersj2 1233: }
1.37 matthew 1234:
1.180 matthew 1235: ###############################################################
1236: ###############################################################
1237:
1.45 matthew 1238: =pod
1239:
1.648 raeburn 1240: =item * &change_content_javascript():
1.256 matthew 1241:
1242: This and the next function allow you to create small sections of an
1243: otherwise static HTML page that you can update on the fly with
1244: Javascript, even in Netscape 4.
1245:
1246: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1247: must be written to the HTML page once. It will prove the Javascript
1248: function "change(name, content)". Calling the change function with the
1249: name of the section
1250: you want to update, matching the name passed to C<changable_area>, and
1251: the new content you want to put in there, will put the content into
1252: that area.
1253:
1254: B<Note>: Netscape 4 only reserves enough space for the changable area
1255: to contain room for the original contents. You need to "make space"
1256: for whatever changes you wish to make, and be B<sure> to check your
1257: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1258: it's adequate for updating a one-line status display, but little more.
1259: This script will set the space to 100% width, so you only need to
1260: worry about height in Netscape 4.
1261:
1262: Modern browsers are much less limiting, and if you can commit to the
1263: user not using Netscape 4, this feature may be used freely with
1264: pretty much any HTML.
1265:
1266: =cut
1267:
1268: sub change_content_javascript {
1269: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1270: if ($env{'browser.type'} eq 'netscape' &&
1271: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1272: return (<<NETSCAPE4);
1273: function change(name, content) {
1274: doc = document.layers[name+"___escape"].layers[0].document;
1275: doc.open();
1276: doc.write(content);
1277: doc.close();
1278: }
1279: NETSCAPE4
1280: } else {
1281: # Otherwise, we need to use semi-standards-compliant code
1282: # (technically, "innerHTML" isn't standard but the equivalent
1283: # is really scary, and every useful browser supports it
1284: return (<<DOMBASED);
1285: function change(name, content) {
1286: element = document.getElementById(name);
1287: element.innerHTML = content;
1288: }
1289: DOMBASED
1290: }
1291: }
1292:
1293: =pod
1294:
1.648 raeburn 1295: =item * &changable_area($name,$origContent):
1.256 matthew 1296:
1297: This provides a "changable area" that can be modified on the fly via
1298: the Javascript code provided in C<change_content_javascript>. $name is
1299: the name you will use to reference the area later; do not repeat the
1300: same name on a given HTML page more then once. $origContent is what
1301: the area will originally contain, which can be left blank.
1302:
1303: =cut
1304:
1305: sub changable_area {
1306: my ($name, $origContent) = @_;
1307:
1.258 albertel 1308: if ($env{'browser.type'} eq 'netscape' &&
1309: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1310: # If this is netscape 4, we need to use the Layer tag
1311: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1312: } else {
1313: return "<span id='$name'>$origContent</span>";
1314: }
1315: }
1316:
1317: =pod
1318:
1.648 raeburn 1319: =item * &viewport_geometry_js
1.590 raeburn 1320:
1321: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1322:
1323: =cut
1324:
1325:
1326: sub viewport_geometry_js {
1327: return <<"GEOMETRY";
1328: var Geometry = {};
1329: function init_geometry() {
1330: if (Geometry.init) { return };
1331: Geometry.init=1;
1332: if (window.innerHeight) {
1333: Geometry.getViewportHeight = function() { return window.innerHeight; };
1334: Geometry.getViewportWidth = function() { return window.innerWidth; };
1335: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1336: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1337: }
1338: else if (document.documentElement && document.documentElement.clientHeight) {
1339: Geometry.getViewportHeight =
1340: function() { return document.documentElement.clientHeight; };
1341: Geometry.getViewportWidth =
1342: function() { return document.documentElement.clientWidth; };
1343:
1344: Geometry.getHorizontalScroll =
1345: function() { return document.documentElement.scrollLeft; };
1346: Geometry.getVerticalScroll =
1347: function() { return document.documentElement.scrollTop; };
1348: }
1349: else if (document.body.clientHeight) {
1350: Geometry.getViewportHeight =
1351: function() { return document.body.clientHeight; };
1352: Geometry.getViewportWidth =
1353: function() { return document.body.clientWidth; };
1354: Geometry.getHorizontalScroll =
1355: function() { return document.body.scrollLeft; };
1356: Geometry.getVerticalScroll =
1357: function() { return document.body.scrollTop; };
1358: }
1359: }
1360:
1361: GEOMETRY
1362: }
1363:
1364: =pod
1365:
1.648 raeburn 1366: =item * &viewport_size_js()
1.590 raeburn 1367:
1368: 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.
1369:
1370: =cut
1371:
1372: sub viewport_size_js {
1373: my $geometry = &viewport_geometry_js();
1374: return <<"DIMS";
1375:
1376: $geometry
1377:
1378: function getViewportDims(width,height) {
1379: init_geometry();
1380: width.value = Geometry.getViewportWidth();
1381: height.value = Geometry.getViewportHeight();
1382: return;
1383: }
1384:
1385: DIMS
1386: }
1387:
1388: =pod
1389:
1.648 raeburn 1390: =item * &resize_textarea_js()
1.565 albertel 1391:
1392: emits the needed javascript to resize a textarea to be as big as possible
1393:
1394: creates a function resize_textrea that takes two IDs first should be
1395: the id of the element to resize, second should be the id of a div that
1396: surrounds everything that comes after the textarea, this routine needs
1397: to be attached to the <body> for the onload and onresize events.
1398:
1.648 raeburn 1399: =back
1.565 albertel 1400:
1401: =cut
1402:
1403: sub resize_textarea_js {
1.590 raeburn 1404: my $geometry = &viewport_geometry_js();
1.565 albertel 1405: return <<"RESIZE";
1406: <script type="text/javascript">
1.824 bisitz 1407: // <![CDATA[
1.590 raeburn 1408: $geometry
1.565 albertel 1409:
1.588 albertel 1410: function getX(element) {
1411: var x = 0;
1412: while (element) {
1413: x += element.offsetLeft;
1414: element = element.offsetParent;
1415: }
1416: return x;
1417: }
1418: function getY(element) {
1419: var y = 0;
1420: while (element) {
1421: y += element.offsetTop;
1422: element = element.offsetParent;
1423: }
1424: return y;
1425: }
1426:
1427:
1.565 albertel 1428: function resize_textarea(textarea_id,bottom_id) {
1429: init_geometry();
1430: var textarea = document.getElementById(textarea_id);
1431: //alert(textarea);
1432:
1.588 albertel 1433: var textarea_top = getY(textarea);
1.565 albertel 1434: var textarea_height = textarea.offsetHeight;
1435: var bottom = document.getElementById(bottom_id);
1.588 albertel 1436: var bottom_top = getY(bottom);
1.565 albertel 1437: var bottom_height = bottom.offsetHeight;
1438: var window_height = Geometry.getViewportHeight();
1.588 albertel 1439: var fudge = 23;
1.565 albertel 1440: var new_height = window_height-fudge-textarea_top-bottom_height;
1441: if (new_height < 300) {
1442: new_height = 300;
1443: }
1444: textarea.style.height=new_height+'px';
1445: }
1.824 bisitz 1446: // ]]>
1.565 albertel 1447: </script>
1448: RESIZE
1449:
1450: }
1451:
1452: =pod
1453:
1.256 matthew 1454: =head1 Excel and CSV file utility routines
1455:
1456: =over 4
1457:
1458: =cut
1459:
1460: ###############################################################
1461: ###############################################################
1462:
1463: =pod
1464:
1.648 raeburn 1465: =item * &csv_translate($text)
1.37 matthew 1466:
1.185 www 1467: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1468: format.
1469:
1470: =cut
1471:
1.180 matthew 1472: ###############################################################
1473: ###############################################################
1.37 matthew 1474: sub csv_translate {
1475: my $text = shift;
1476: $text =~ s/\"/\"\"/g;
1.209 albertel 1477: $text =~ s/\n/ /g;
1.37 matthew 1478: return $text;
1479: }
1.180 matthew 1480:
1481: ###############################################################
1482: ###############################################################
1483:
1484: =pod
1485:
1.648 raeburn 1486: =item * &define_excel_formats()
1.180 matthew 1487:
1488: Define some commonly used Excel cell formats.
1489:
1490: Currently supported formats:
1491:
1492: =over 4
1493:
1494: =item header
1495:
1496: =item bold
1497:
1498: =item h1
1499:
1500: =item h2
1501:
1502: =item h3
1503:
1.256 matthew 1504: =item h4
1505:
1506: =item i
1507:
1.180 matthew 1508: =item date
1509:
1510: =back
1511:
1512: Inputs: $workbook
1513:
1514: Returns: $format, a hash reference.
1515:
1516: =cut
1517:
1518: ###############################################################
1519: ###############################################################
1520: sub define_excel_formats {
1521: my ($workbook) = @_;
1522: my $format;
1523: $format->{'header'} = $workbook->add_format(bold => 1,
1524: bottom => 1,
1525: align => 'center');
1526: $format->{'bold'} = $workbook->add_format(bold=>1);
1527: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1528: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1529: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1530: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1531: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1532: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1533: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1534: return $format;
1535: }
1536:
1537: ###############################################################
1538: ###############################################################
1.113 bowersj2 1539:
1540: =pod
1541:
1.648 raeburn 1542: =item * &create_workbook()
1.255 matthew 1543:
1544: Create an Excel worksheet. If it fails, output message on the
1545: request object and return undefs.
1546:
1547: Inputs: Apache request object
1548:
1549: Returns (undef) on failure,
1550: Excel worksheet object, scalar with filename, and formats
1551: from &Apache::loncommon::define_excel_formats on success
1552:
1553: =cut
1554:
1555: ###############################################################
1556: ###############################################################
1557: sub create_workbook {
1558: my ($r) = @_;
1559: #
1560: # Create the excel spreadsheet
1561: my $filename = '/prtspool/'.
1.258 albertel 1562: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1563: time.'_'.rand(1000000000).'.xls';
1564: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1565: if (! defined($workbook)) {
1566: $r->log_error("Error creating excel spreadsheet $filename: $!");
1567: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1568: "This error has been logged. ".
1569: "Please alert your LON-CAPA administrator").
1570: '</p>');
1571: return (undef);
1572: }
1573: #
1574: $workbook->set_tempdir('/home/httpd/perl/tmp');
1575: #
1576: my $format = &Apache::loncommon::define_excel_formats($workbook);
1577: return ($workbook,$filename,$format);
1578: }
1579:
1580: ###############################################################
1581: ###############################################################
1582:
1583: =pod
1584:
1.648 raeburn 1585: =item * &create_text_file()
1.113 bowersj2 1586:
1.542 raeburn 1587: Create a file to write to and eventually make available to the user.
1.256 matthew 1588: If file creation fails, outputs an error message on the request object and
1589: return undefs.
1.113 bowersj2 1590:
1.256 matthew 1591: Inputs: Apache request object, and file suffix
1.113 bowersj2 1592:
1.256 matthew 1593: Returns (undef) on failure,
1594: Filehandle and filename on success.
1.113 bowersj2 1595:
1596: =cut
1597:
1.256 matthew 1598: ###############################################################
1599: ###############################################################
1600: sub create_text_file {
1601: my ($r,$suffix) = @_;
1602: if (! defined($suffix)) { $suffix = 'txt'; };
1603: my $fh;
1604: my $filename = '/prtspool/'.
1.258 albertel 1605: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1606: time.'_'.rand(1000000000).'.'.$suffix;
1607: $fh = Apache::File->new('>/home/httpd'.$filename);
1608: if (! defined($fh)) {
1609: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1610: $r->print(&mt('Problems occurred in creating the output file. '
1611: .'This error has been logged. '
1612: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1613: }
1.256 matthew 1614: return ($fh,$filename)
1.113 bowersj2 1615: }
1616:
1617:
1.256 matthew 1618: =pod
1.113 bowersj2 1619:
1620: =back
1621:
1622: =cut
1.37 matthew 1623:
1624: ###############################################################
1.33 matthew 1625: ## Home server <option> list generating code ##
1626: ###############################################################
1.35 matthew 1627:
1.169 www 1628: # ------------------------------------------
1629:
1630: sub domain_select {
1631: my ($name,$value,$multiple)=@_;
1632: my %domains=map {
1.514 albertel 1633: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1634: } &Apache::lonnet::all_domains();
1.169 www 1635: if ($multiple) {
1636: $domains{''}=&mt('Any domain');
1.550 albertel 1637: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1638: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1639: } else {
1.550 albertel 1640: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1641: return &select_form($name,$value,%domains);
1642: }
1643: }
1644:
1.282 albertel 1645: #-------------------------------------------
1646:
1647: =pod
1648:
1.519 raeburn 1649: =head1 Routines for form select boxes
1650:
1651: =over 4
1652:
1.648 raeburn 1653: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1654:
1655: Returns a string containing a <select> element int multiple mode
1656:
1657:
1658: Args:
1659: $name - name of the <select> element
1.506 raeburn 1660: $value - scalar or array ref of values that should already be selected
1.282 albertel 1661: $size - number of rows long the select element is
1.283 albertel 1662: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1663: (shown text should already have been &mt())
1.506 raeburn 1664: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1665:
1.282 albertel 1666: =cut
1667:
1668: #-------------------------------------------
1.169 www 1669: sub multiple_select_form {
1.284 albertel 1670: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1671: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1672: my $output='';
1.191 matthew 1673: if (! defined($size)) {
1674: $size = 4;
1.283 albertel 1675: if (scalar(keys(%$hash))<4) {
1676: $size = scalar(keys(%$hash));
1.191 matthew 1677: }
1678: }
1.734 bisitz 1679: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1680: my @order;
1.506 raeburn 1681: if (ref($order) eq 'ARRAY') {
1682: @order = @{$order};
1683: } else {
1684: @order = sort(keys(%$hash));
1.501 banghart 1685: }
1686: if (exists($$hash{'select_form_order'})) {
1687: @order = @{$$hash{'select_form_order'}};
1688: }
1689:
1.284 albertel 1690: foreach my $key (@order) {
1.356 albertel 1691: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1692: $output.='selected="selected" ' if ($selected{$key});
1693: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1694: }
1695: $output.="</select>\n";
1696: return $output;
1697: }
1698:
1.88 www 1699: #-------------------------------------------
1700:
1701: =pod
1702:
1.648 raeburn 1703: =item * &select_form($defdom,$name,%hash)
1.88 www 1704:
1705: Returns a string containing a <select name='$name' size='1'> form to
1706: allow a user to select options from a hash option_name => displayed text.
1707: See lonrights.pm for an example invocation and use.
1708:
1709: =cut
1710:
1711: #-------------------------------------------
1712: sub select_form {
1713: my ($def,$name,%hash) = @_;
1714: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1715: my @keys;
1716: if (exists($hash{'select_form_order'})) {
1717: @keys=@{$hash{'select_form_order'}};
1718: } else {
1719: @keys=sort(keys(%hash));
1720: }
1.356 albertel 1721: foreach my $key (@keys) {
1722: $selectform.=
1723: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1724: ($key eq $def ? 'selected="selected" ' : '').
1725: ">".&mt($hash{$key})."</option>\n";
1.88 www 1726: }
1727: $selectform.="</select>";
1728: return $selectform;
1729: }
1730:
1.475 www 1731: # For display filters
1732:
1733: sub display_filter {
1734: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1735: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1736: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1737: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1738: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1739: '</label></span> <span class="LC_nobreak">'.
1.475 www 1740: &mt('Filter [_1]',
1.477 www 1741: &select_form($env{'form.displayfilter'},
1742: 'displayfilter',
1743: ('currentfolder' => 'Current folder/page',
1744: 'containing' => 'Containing phrase',
1745: 'none' => 'None'))).
1.714 bisitz 1746: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1747: }
1748:
1.167 www 1749: sub gradeleveldescription {
1750: my $gradelevel=shift;
1751: my %gradelevels=(0 => 'Not specified',
1752: 1 => 'Grade 1',
1753: 2 => 'Grade 2',
1754: 3 => 'Grade 3',
1755: 4 => 'Grade 4',
1756: 5 => 'Grade 5',
1757: 6 => 'Grade 6',
1758: 7 => 'Grade 7',
1759: 8 => 'Grade 8',
1760: 9 => 'Grade 9',
1761: 10 => 'Grade 10',
1762: 11 => 'Grade 11',
1763: 12 => 'Grade 12',
1764: 13 => 'Grade 13',
1765: 14 => '100 Level',
1766: 15 => '200 Level',
1767: 16 => '300 Level',
1768: 17 => '400 Level',
1769: 18 => 'Graduate Level');
1770: return &mt($gradelevels{$gradelevel});
1771: }
1772:
1.163 www 1773: sub select_level_form {
1774: my ($deflevel,$name)=@_;
1775: unless ($deflevel) { $deflevel=0; }
1.167 www 1776: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1777: for (my $i=0; $i<=18; $i++) {
1778: $selectform.="<option value=\"$i\" ".
1.253 albertel 1779: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1780: ">".&gradeleveldescription($i)."</option>\n";
1781: }
1782: $selectform.="</select>";
1783: return $selectform;
1.163 www 1784: }
1.167 www 1785:
1.35 matthew 1786: #-------------------------------------------
1787:
1.45 matthew 1788: =pod
1789:
1.743 raeburn 1790: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1791:
1792: Returns a string containing a <select name='$name' size='1'> form to
1793: allow a user to select the domain to preform an operation in.
1794: See loncreateuser.pm for an example invocation and use.
1795:
1.90 www 1796: If the $includeempty flag is set, it also includes an empty choice ("no domain
1797: selected");
1798:
1.743 raeburn 1799: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1800:
1801: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1802:
1.35 matthew 1803: =cut
1804:
1805: #-------------------------------------------
1.34 matthew 1806: sub select_dom_form {
1.743 raeburn 1807: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1808: my $onchange;
1809: if ($autosubmit) {
1810: $onchange = ' onchange="this.form.submit()"';
1811: }
1.550 albertel 1812: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1813: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1814: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1815: foreach my $dom (@domains) {
1816: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1817: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1818: if ($showdomdesc) {
1819: if ($dom ne '') {
1820: my $domdesc = &Apache::lonnet::domain($dom,'description');
1821: if ($domdesc ne '') {
1822: $selectdomain .= ' ('.$domdesc.')';
1823: }
1824: }
1825: }
1826: $selectdomain .= "</option>\n";
1.34 matthew 1827: }
1828: $selectdomain.="</select>";
1829: return $selectdomain;
1830: }
1831:
1.35 matthew 1832: #-------------------------------------------
1833:
1.45 matthew 1834: =pod
1835:
1.648 raeburn 1836: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1837:
1.586 raeburn 1838: input: 4 arguments (two required, two optional) -
1839: $domain - domain of new user
1840: $name - name of form element
1841: $default - Value of 'default' causes a default item to be first
1842: option, and selected by default.
1843: $hide - Value of 'hide' causes hiding of the name of the server,
1844: if 1 server found, or default, if 0 found.
1.594 raeburn 1845: output: returns 2 items:
1.586 raeburn 1846: (a) form element which contains either:
1847: (i) <select name="$name">
1848: <option value="$hostid1">$hostid $servers{$hostid}</option>
1849: <option value="$hostid2">$hostid $servers{$hostid}</option>
1850: </select>
1851: form item if there are multiple library servers in $domain, or
1852: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1853: if there is only one library server in $domain.
1854:
1855: (b) number of library servers found.
1856:
1857: See loncreateuser.pm for example of use.
1.35 matthew 1858:
1859: =cut
1860:
1861: #-------------------------------------------
1.586 raeburn 1862: sub home_server_form_item {
1863: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1864: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1865: my $result;
1866: my $numlib = keys(%servers);
1867: if ($numlib > 1) {
1868: $result .= '<select name="'.$name.'" />'."\n";
1869: if ($default) {
1.804 bisitz 1870: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1871: '</option>'."\n";
1872: }
1873: foreach my $hostid (sort(keys(%servers))) {
1874: $result.= '<option value="'.$hostid.'">'.
1875: $hostid.' '.$servers{$hostid}."</option>\n";
1876: }
1877: $result .= '</select>'."\n";
1878: } elsif ($numlib == 1) {
1879: my $hostid;
1880: foreach my $item (keys(%servers)) {
1881: $hostid = $item;
1882: }
1883: $result .= '<input type="hidden" name="'.$name.'" value="'.
1884: $hostid.'" />';
1885: if (!$hide) {
1886: $result .= $hostid.' '.$servers{$hostid};
1887: }
1888: $result .= "\n";
1889: } elsif ($default) {
1890: $result .= '<input type="hidden" name="'.$name.
1891: '" value="default" />';
1892: if (!$hide) {
1893: $result .= &mt('default');
1894: }
1895: $result .= "\n";
1.33 matthew 1896: }
1.586 raeburn 1897: return ($result,$numlib);
1.33 matthew 1898: }
1.112 bowersj2 1899:
1900: =pod
1901:
1.534 albertel 1902: =back
1903:
1.112 bowersj2 1904: =cut
1.87 matthew 1905:
1906: ###############################################################
1.112 bowersj2 1907: ## Decoding User Agent ##
1.87 matthew 1908: ###############################################################
1909:
1910: =pod
1911:
1.112 bowersj2 1912: =head1 Decoding the User Agent
1913:
1914: =over 4
1915:
1916: =item * &decode_user_agent()
1.87 matthew 1917:
1918: Inputs: $r
1919:
1920: Outputs:
1921:
1922: =over 4
1923:
1.112 bowersj2 1924: =item * $httpbrowser
1.87 matthew 1925:
1.112 bowersj2 1926: =item * $clientbrowser
1.87 matthew 1927:
1.112 bowersj2 1928: =item * $clientversion
1.87 matthew 1929:
1.112 bowersj2 1930: =item * $clientmathml
1.87 matthew 1931:
1.112 bowersj2 1932: =item * $clientunicode
1.87 matthew 1933:
1.112 bowersj2 1934: =item * $clientos
1.87 matthew 1935:
1936: =back
1937:
1.157 matthew 1938: =back
1939:
1.87 matthew 1940: =cut
1941:
1942: ###############################################################
1943: ###############################################################
1944: sub decode_user_agent {
1.247 albertel 1945: my ($r)=@_;
1.87 matthew 1946: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1947: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1948: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1949: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1950: my $clientbrowser='unknown';
1951: my $clientversion='0';
1952: my $clientmathml='';
1953: my $clientunicode='0';
1954: for (my $i=0;$i<=$#browsertype;$i++) {
1955: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1956: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1957: $clientbrowser=$bname;
1958: $httpbrowser=~/$vreg/i;
1959: $clientversion=$1;
1960: $clientmathml=($clientversion>=$minv);
1961: $clientunicode=($clientversion>=$univ);
1962: }
1963: }
1964: my $clientos='unknown';
1965: if (($httpbrowser=~/linux/i) ||
1966: ($httpbrowser=~/unix/i) ||
1967: ($httpbrowser=~/ux/i) ||
1968: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1969: if (($httpbrowser=~/vax/i) ||
1970: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1971: if ($httpbrowser=~/next/i) { $clientos='next'; }
1972: if (($httpbrowser=~/mac/i) ||
1973: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1974: if ($httpbrowser=~/win/i) { $clientos='win'; }
1975: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1976: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1977: $clientunicode,$clientos,);
1978: }
1979:
1.32 matthew 1980: ###############################################################
1981: ## Authentication changing form generation subroutines ##
1982: ###############################################################
1983: ##
1984: ## All of the authform_xxxxxxx subroutines take their inputs in a
1985: ## hash, and have reasonable default values.
1986: ##
1987: ## formname = the name given in the <form> tag.
1.35 matthew 1988: #-------------------------------------------
1989:
1.45 matthew 1990: =pod
1991:
1.112 bowersj2 1992: =head1 Authentication Routines
1993:
1994: =over 4
1995:
1.648 raeburn 1996: =item * &authform_xxxxxx()
1.35 matthew 1997:
1998: The authform_xxxxxx subroutines provide javascript and html forms which
1999: handle some of the conveniences required for authentication forms.
2000: This is not an optimal method, but it works.
2001:
2002: =over 4
2003:
1.112 bowersj2 2004: =item * authform_header
1.35 matthew 2005:
1.112 bowersj2 2006: =item * authform_authorwarning
1.35 matthew 2007:
1.112 bowersj2 2008: =item * authform_nochange
1.35 matthew 2009:
1.112 bowersj2 2010: =item * authform_kerberos
1.35 matthew 2011:
1.112 bowersj2 2012: =item * authform_internal
1.35 matthew 2013:
1.112 bowersj2 2014: =item * authform_filesystem
1.35 matthew 2015:
2016: =back
2017:
1.648 raeburn 2018: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2019:
1.35 matthew 2020: =cut
2021:
2022: #-------------------------------------------
1.32 matthew 2023: sub authform_header{
2024: my %in = (
2025: formname => 'cu',
1.80 albertel 2026: kerb_def_dom => '',
1.32 matthew 2027: @_,
2028: );
2029: $in{'formname'} = 'document.' . $in{'formname'};
2030: my $result='';
1.80 albertel 2031:
2032: #---------------------------------------------- Code for upper case translation
2033: my $Javascript_toUpperCase;
2034: unless ($in{kerb_def_dom}) {
2035: $Javascript_toUpperCase =<<"END";
2036: switch (choice) {
2037: case 'krb': currentform.elements[choicearg].value =
2038: currentform.elements[choicearg].value.toUpperCase();
2039: break;
2040: default:
2041: }
2042: END
2043: } else {
2044: $Javascript_toUpperCase = "";
2045: }
2046:
1.165 raeburn 2047: my $radioval = "'nochange'";
1.591 raeburn 2048: if (defined($in{'curr_authtype'})) {
2049: if ($in{'curr_authtype'} ne '') {
2050: $radioval = "'".$in{'curr_authtype'}."arg'";
2051: }
1.174 matthew 2052: }
1.165 raeburn 2053: my $argfield = 'null';
1.591 raeburn 2054: if (defined($in{'mode'})) {
1.165 raeburn 2055: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2056: if (defined($in{'curr_autharg'})) {
2057: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2058: $argfield = "'$in{'curr_autharg'}'";
2059: }
2060: }
2061: }
2062: }
2063:
1.32 matthew 2064: $result.=<<"END";
2065: var current = new Object();
1.165 raeburn 2066: current.radiovalue = $radioval;
2067: current.argfield = $argfield;
1.32 matthew 2068:
2069: function changed_radio(choice,currentform) {
2070: var choicearg = choice + 'arg';
2071: // If a radio button in changed, we need to change the argfield
2072: if (current.radiovalue != choice) {
2073: current.radiovalue = choice;
2074: if (current.argfield != null) {
2075: currentform.elements[current.argfield].value = '';
2076: }
2077: if (choice == 'nochange') {
2078: current.argfield = null;
2079: } else {
2080: current.argfield = choicearg;
2081: switch(choice) {
2082: case 'krb':
2083: currentform.elements[current.argfield].value =
2084: "$in{'kerb_def_dom'}";
2085: break;
2086: default:
2087: break;
2088: }
2089: }
2090: }
2091: return;
2092: }
1.22 www 2093:
1.32 matthew 2094: function changed_text(choice,currentform) {
2095: var choicearg = choice + 'arg';
2096: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2097: $Javascript_toUpperCase
1.32 matthew 2098: // clear old field
2099: if ((current.argfield != choicearg) && (current.argfield != null)) {
2100: currentform.elements[current.argfield].value = '';
2101: }
2102: current.argfield = choicearg;
2103: }
2104: set_auth_radio_buttons(choice,currentform);
2105: return;
1.20 www 2106: }
1.32 matthew 2107:
2108: function set_auth_radio_buttons(newvalue,currentform) {
2109: var i=0;
2110: while (i < currentform.login.length) {
2111: if (currentform.login[i].value == newvalue) { break; }
2112: i++;
2113: }
2114: if (i == currentform.login.length) {
2115: return;
2116: }
2117: current.radiovalue = newvalue;
2118: currentform.login[i].checked = true;
2119: return;
2120: }
2121: END
2122: return $result;
2123: }
2124:
2125: sub authform_authorwarning{
2126: my $result='';
1.144 matthew 2127: $result='<i>'.
2128: &mt('As a general rule, only authors or co-authors should be '.
2129: 'filesystem authenticated '.
2130: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2131: return $result;
2132: }
2133:
2134: sub authform_nochange{
2135: my %in = (
2136: formname => 'document.cu',
2137: kerb_def_dom => 'MSU.EDU',
2138: @_,
2139: );
1.586 raeburn 2140: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2141: my $result;
2142: if (keys(%can_assign) == 0) {
2143: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2144: } else {
2145: $result = '<label>'.&mt('[_1] Do not change login data',
2146: '<input type="radio" name="login" value="nochange" '.
2147: 'checked="checked" onclick="'.
1.281 albertel 2148: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2149: '</label>';
1.586 raeburn 2150: }
1.32 matthew 2151: return $result;
2152: }
2153:
1.591 raeburn 2154: sub authform_kerberos {
1.32 matthew 2155: my %in = (
2156: formname => 'document.cu',
2157: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2158: kerb_def_auth => 'krb4',
1.32 matthew 2159: @_,
2160: );
1.586 raeburn 2161: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2162: $autharg,$jscall);
2163: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2164: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2165: $check5 = ' checked="checked"';
1.80 albertel 2166: } else {
1.772 bisitz 2167: $check4 = ' checked="checked"';
1.80 albertel 2168: }
1.165 raeburn 2169: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2170: if (defined($in{'curr_authtype'})) {
2171: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2172: $krbcheck = ' checked="checked"';
1.623 raeburn 2173: if (defined($in{'mode'})) {
2174: if ($in{'mode'} eq 'modifyuser') {
2175: $krbcheck = '';
2176: }
2177: }
1.591 raeburn 2178: if (defined($in{'curr_kerb_ver'})) {
2179: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2180: $check5 = ' checked="checked"';
1.591 raeburn 2181: $check4 = '';
2182: } else {
1.772 bisitz 2183: $check4 = ' checked="checked"';
1.591 raeburn 2184: $check5 = '';
2185: }
1.586 raeburn 2186: }
1.591 raeburn 2187: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2188: $krbarg = $in{'curr_autharg'};
2189: }
1.586 raeburn 2190: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2191: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2192: $result =
2193: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2194: $in{'curr_autharg'},$krbver);
2195: } else {
2196: $result =
2197: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2198: }
2199: return $result;
2200: }
2201: }
2202: } else {
2203: if ($authnum == 1) {
1.784 bisitz 2204: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2205: }
2206: }
1.586 raeburn 2207: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2208: return;
1.587 raeburn 2209: } elsif ($authtype eq '') {
1.591 raeburn 2210: if (defined($in{'mode'})) {
1.587 raeburn 2211: if ($in{'mode'} eq 'modifycourse') {
2212: if ($authnum == 1) {
1.784 bisitz 2213: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2214: }
2215: }
2216: }
1.586 raeburn 2217: }
2218: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2219: if ($authtype eq '') {
2220: $authtype = '<input type="radio" name="login" value="krb" '.
2221: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2222: $krbcheck.' />';
2223: }
2224: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2225: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2226: $in{'curr_authtype'} eq 'krb5') ||
2227: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2228: $in{'curr_authtype'} eq 'krb4')) {
2229: $result .= &mt
1.144 matthew 2230: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2231: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2232: '<label>'.$authtype,
1.281 albertel 2233: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2234: 'value="'.$krbarg.'" '.
1.144 matthew 2235: 'onchange="'.$jscall.'" />',
1.281 albertel 2236: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2237: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2238: '</label>');
1.586 raeburn 2239: } elsif ($can_assign{'krb4'}) {
2240: $result .= &mt
2241: ('[_1] Kerberos authenticated with domain [_2] '.
2242: '[_3] Version 4 [_4]',
2243: '<label>'.$authtype,
2244: '</label><input type="text" size="10" name="krbarg" '.
2245: 'value="'.$krbarg.'" '.
2246: 'onchange="'.$jscall.'" />',
2247: '<label><input type="hidden" name="krbver" value="4" />',
2248: '</label>');
2249: } elsif ($can_assign{'krb5'}) {
2250: $result .= &mt
2251: ('[_1] Kerberos authenticated with domain [_2] '.
2252: '[_3] Version 5 [_4]',
2253: '<label>'.$authtype,
2254: '</label><input type="text" size="10" name="krbarg" '.
2255: 'value="'.$krbarg.'" '.
2256: 'onchange="'.$jscall.'" />',
2257: '<label><input type="hidden" name="krbver" value="5" />',
2258: '</label>');
2259: }
1.32 matthew 2260: return $result;
2261: }
2262:
2263: sub authform_internal{
1.586 raeburn 2264: my %in = (
1.32 matthew 2265: formname => 'document.cu',
2266: kerb_def_dom => 'MSU.EDU',
2267: @_,
2268: );
1.586 raeburn 2269: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2270: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2271: if (defined($in{'curr_authtype'})) {
2272: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2273: if ($can_assign{'int'}) {
1.772 bisitz 2274: $intcheck = 'checked="checked" ';
1.623 raeburn 2275: if (defined($in{'mode'})) {
2276: if ($in{'mode'} eq 'modifyuser') {
2277: $intcheck = '';
2278: }
2279: }
1.591 raeburn 2280: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2281: $intarg = $in{'curr_autharg'};
2282: }
2283: } else {
2284: $result = &mt('Currently internally authenticated.');
2285: return $result;
1.165 raeburn 2286: }
2287: }
1.586 raeburn 2288: } else {
2289: if ($authnum == 1) {
1.784 bisitz 2290: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2291: }
2292: }
2293: if (!$can_assign{'int'}) {
2294: return;
1.587 raeburn 2295: } elsif ($authtype eq '') {
1.591 raeburn 2296: if (defined($in{'mode'})) {
1.587 raeburn 2297: if ($in{'mode'} eq 'modifycourse') {
2298: if ($authnum == 1) {
1.784 bisitz 2299: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2300: }
2301: }
2302: }
1.165 raeburn 2303: }
1.586 raeburn 2304: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2305: if ($authtype eq '') {
2306: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2307: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2308: }
1.605 bisitz 2309: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2310: $intarg.'" onchange="'.$jscall.'" />';
2311: $result = &mt
1.144 matthew 2312: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2313: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2314: $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 2315: return $result;
2316: }
2317:
2318: sub authform_local{
2319: my %in = (
2320: formname => 'document.cu',
2321: kerb_def_dom => 'MSU.EDU',
2322: @_,
2323: );
1.586 raeburn 2324: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2325: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2326: if (defined($in{'curr_authtype'})) {
2327: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2328: if ($can_assign{'loc'}) {
1.772 bisitz 2329: $loccheck = 'checked="checked" ';
1.623 raeburn 2330: if (defined($in{'mode'})) {
2331: if ($in{'mode'} eq 'modifyuser') {
2332: $loccheck = '';
2333: }
2334: }
1.591 raeburn 2335: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2336: $locarg = $in{'curr_autharg'};
2337: }
2338: } else {
2339: $result = &mt('Currently using local (institutional) authentication.');
2340: return $result;
1.165 raeburn 2341: }
2342: }
1.586 raeburn 2343: } else {
2344: if ($authnum == 1) {
1.784 bisitz 2345: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2346: }
2347: }
2348: if (!$can_assign{'loc'}) {
2349: return;
1.587 raeburn 2350: } elsif ($authtype eq '') {
1.591 raeburn 2351: if (defined($in{'mode'})) {
1.587 raeburn 2352: if ($in{'mode'} eq 'modifycourse') {
2353: if ($authnum == 1) {
1.784 bisitz 2354: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2355: }
2356: }
2357: }
1.165 raeburn 2358: }
1.586 raeburn 2359: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2360: if ($authtype eq '') {
2361: $authtype = '<input type="radio" name="login" value="loc" '.
2362: $loccheck.' onchange="'.$jscall.'" onclick="'.
2363: $jscall.'" />';
2364: }
2365: $autharg = '<input type="text" size="10" name="locarg" value="'.
2366: $locarg.'" onchange="'.$jscall.'" />';
2367: $result = &mt('[_1] Local Authentication with argument [_2]',
2368: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2369: return $result;
2370: }
2371:
2372: sub authform_filesystem{
2373: my %in = (
2374: formname => 'document.cu',
2375: kerb_def_dom => 'MSU.EDU',
2376: @_,
2377: );
1.586 raeburn 2378: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2379: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2380: if (defined($in{'curr_authtype'})) {
2381: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2382: if ($can_assign{'fsys'}) {
1.772 bisitz 2383: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2384: if (defined($in{'mode'})) {
2385: if ($in{'mode'} eq 'modifyuser') {
2386: $fsyscheck = '';
2387: }
2388: }
1.586 raeburn 2389: } else {
2390: $result = &mt('Currently Filesystem Authenticated.');
2391: return $result;
2392: }
2393: }
2394: } else {
2395: if ($authnum == 1) {
1.784 bisitz 2396: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2397: }
2398: }
2399: if (!$can_assign{'fsys'}) {
2400: return;
1.587 raeburn 2401: } elsif ($authtype eq '') {
1.591 raeburn 2402: if (defined($in{'mode'})) {
1.587 raeburn 2403: if ($in{'mode'} eq 'modifycourse') {
2404: if ($authnum == 1) {
1.784 bisitz 2405: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2406: }
2407: }
2408: }
1.586 raeburn 2409: }
2410: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2411: if ($authtype eq '') {
2412: $authtype = '<input type="radio" name="login" value="fsys" '.
2413: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2414: $jscall.'" />';
2415: }
2416: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2417: ' onchange="'.$jscall.'" />';
2418: $result = &mt
1.144 matthew 2419: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2420: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2421: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2422: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2423: 'onchange="'.$jscall.'" />');
1.32 matthew 2424: return $result;
2425: }
2426:
1.586 raeburn 2427: sub get_assignable_auth {
2428: my ($dom) = @_;
2429: if ($dom eq '') {
2430: $dom = $env{'request.role.domain'};
2431: }
2432: my %can_assign = (
2433: krb4 => 1,
2434: krb5 => 1,
2435: int => 1,
2436: loc => 1,
2437: );
2438: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2439: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2440: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2441: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2442: my $context;
2443: if ($env{'request.role'} =~ /^au/) {
2444: $context = 'author';
2445: } elsif ($env{'request.role'} =~ /^dc/) {
2446: $context = 'domain';
2447: } elsif ($env{'request.course.id'}) {
2448: $context = 'course';
2449: }
2450: if ($context) {
2451: if (ref($authhash->{$context}) eq 'HASH') {
2452: %can_assign = %{$authhash->{$context}};
2453: }
2454: }
2455: }
2456: }
2457: my $authnum = 0;
2458: foreach my $key (keys(%can_assign)) {
2459: if ($can_assign{$key}) {
2460: $authnum ++;
2461: }
2462: }
2463: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2464: $authnum --;
2465: }
2466: return ($authnum,%can_assign);
2467: }
2468:
1.80 albertel 2469: ###############################################################
2470: ## Get Kerberos Defaults for Domain ##
2471: ###############################################################
2472: ##
2473: ## Returns default kerberos version and an associated argument
2474: ## as listed in file domain.tab. If not listed, provides
2475: ## appropriate default domain and kerberos version.
2476: ##
2477: #-------------------------------------------
2478:
2479: =pod
2480:
1.648 raeburn 2481: =item * &get_kerberos_defaults()
1.80 albertel 2482:
2483: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2484: version and domain. If not found, it defaults to version 4 and the
2485: domain of the server.
1.80 albertel 2486:
1.648 raeburn 2487: =over 4
2488:
1.80 albertel 2489: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2490:
1.648 raeburn 2491: =back
2492:
2493: =back
2494:
1.80 albertel 2495: =cut
2496:
2497: #-------------------------------------------
2498: sub get_kerberos_defaults {
2499: my $domain=shift;
1.641 raeburn 2500: my ($krbdef,$krbdefdom);
2501: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2502: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2503: $krbdef = $domdefaults{'auth_def'};
2504: $krbdefdom = $domdefaults{'auth_arg_def'};
2505: } else {
1.80 albertel 2506: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2507: my $krbdefdom=$1;
2508: $krbdefdom=~tr/a-z/A-Z/;
2509: $krbdef = "krb4";
2510: }
2511: return ($krbdef,$krbdefdom);
2512: }
1.112 bowersj2 2513:
1.32 matthew 2514:
1.46 matthew 2515: ###############################################################
2516: ## Thesaurus Functions ##
2517: ###############################################################
1.20 www 2518:
1.46 matthew 2519: =pod
1.20 www 2520:
1.112 bowersj2 2521: =head1 Thesaurus Functions
2522:
2523: =over 4
2524:
1.648 raeburn 2525: =item * &initialize_keywords()
1.46 matthew 2526:
2527: Initializes the package variable %Keywords if it is empty. Uses the
2528: package variable $thesaurus_db_file.
2529:
2530: =cut
2531:
2532: ###################################################
2533:
2534: sub initialize_keywords {
2535: return 1 if (scalar keys(%Keywords));
2536: # If we are here, %Keywords is empty, so fill it up
2537: # Make sure the file we need exists...
2538: if (! -e $thesaurus_db_file) {
2539: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2540: " failed because it does not exist");
2541: return 0;
2542: }
2543: # Set up the hash as a database
2544: my %thesaurus_db;
2545: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2546: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2547: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2548: $thesaurus_db_file);
2549: return 0;
2550: }
2551: # Get the average number of appearances of a word.
2552: my $avecount = $thesaurus_db{'average.count'};
2553: # Put keywords (those that appear > average) into %Keywords
2554: while (my ($word,$data)=each (%thesaurus_db)) {
2555: my ($count,undef) = split /:/,$data;
2556: $Keywords{$word}++ if ($count > $avecount);
2557: }
2558: untie %thesaurus_db;
2559: # Remove special values from %Keywords.
1.356 albertel 2560: foreach my $value ('total.count','average.count') {
2561: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2562: }
1.46 matthew 2563: return 1;
2564: }
2565:
2566: ###################################################
2567:
2568: =pod
2569:
1.648 raeburn 2570: =item * &keyword($word)
1.46 matthew 2571:
2572: Returns true if $word is a keyword. A keyword is a word that appears more
2573: than the average number of times in the thesaurus database. Calls
2574: &initialize_keywords
2575:
2576: =cut
2577:
2578: ###################################################
1.20 www 2579:
2580: sub keyword {
1.46 matthew 2581: return if (!&initialize_keywords());
2582: my $word=lc(shift());
2583: $word=~s/\W//g;
2584: return exists($Keywords{$word});
1.20 www 2585: }
1.46 matthew 2586:
2587: ###############################################################
2588:
2589: =pod
1.20 www 2590:
1.648 raeburn 2591: =item * &get_related_words()
1.46 matthew 2592:
1.160 matthew 2593: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2594: an array of words. If the keyword is not in the thesaurus, an empty array
2595: will be returned. The order of the words returned is determined by the
2596: database which holds them.
2597:
2598: Uses global $thesaurus_db_file.
2599:
2600: =cut
2601:
2602: ###############################################################
2603: sub get_related_words {
2604: my $keyword = shift;
2605: my %thesaurus_db;
2606: if (! -e $thesaurus_db_file) {
2607: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2608: "failed because the file does not exist");
2609: return ();
2610: }
2611: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2612: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2613: return ();
2614: }
2615: my @Words=();
1.429 www 2616: my $count=0;
1.46 matthew 2617: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2618: # The first element is the number of times
2619: # the word appears. We do not need it now.
1.429 www 2620: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2621: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2622: my $threshold=$mostfrequentcount/10;
2623: foreach my $possibleword (@RelatedWords) {
2624: my ($word,$wordcount)=split(/\,/,$possibleword);
2625: if ($wordcount>$threshold) {
2626: push(@Words,$word);
2627: $count++;
2628: if ($count>10) { last; }
2629: }
1.20 www 2630: }
2631: }
1.46 matthew 2632: untie %thesaurus_db;
2633: return @Words;
1.14 harris41 2634: }
1.46 matthew 2635:
1.112 bowersj2 2636: =pod
2637:
2638: =back
2639:
2640: =cut
1.61 www 2641:
2642: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2643: =pod
2644:
1.112 bowersj2 2645: =head1 User Name Functions
2646:
2647: =over 4
2648:
1.648 raeburn 2649: =item * &plainname($uname,$udom,$first)
1.81 albertel 2650:
1.112 bowersj2 2651: Takes a users logon name and returns it as a string in
1.226 albertel 2652: "first middle last generation" form
2653: if $first is set to 'lastname' then it returns it as
2654: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2655:
2656: =cut
1.61 www 2657:
1.295 www 2658:
1.81 albertel 2659: ###############################################################
1.61 www 2660: sub plainname {
1.226 albertel 2661: my ($uname,$udom,$first)=@_;
1.537 albertel 2662: return if (!defined($uname) || !defined($udom));
1.295 www 2663: my %names=&getnames($uname,$udom);
1.226 albertel 2664: my $name=&Apache::lonnet::format_name($names{'firstname'},
2665: $names{'middlename'},
2666: $names{'lastname'},
2667: $names{'generation'},$first);
2668: $name=~s/^\s+//;
1.62 www 2669: $name=~s/\s+$//;
2670: $name=~s/\s+/ /g;
1.353 albertel 2671: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2672: return $name;
1.61 www 2673: }
1.66 www 2674:
2675: # -------------------------------------------------------------------- Nickname
1.81 albertel 2676: =pod
2677:
1.648 raeburn 2678: =item * &nickname($uname,$udom)
1.81 albertel 2679:
2680: Gets a users name and returns it as a string as
2681:
2682: ""nickname""
1.66 www 2683:
1.81 albertel 2684: if the user has a nickname or
2685:
2686: "first middle last generation"
2687:
2688: if the user does not
2689:
2690: =cut
1.66 www 2691:
2692: sub nickname {
2693: my ($uname,$udom)=@_;
1.537 albertel 2694: return if (!defined($uname) || !defined($udom));
1.295 www 2695: my %names=&getnames($uname,$udom);
1.68 albertel 2696: my $name=$names{'nickname'};
1.66 www 2697: if ($name) {
2698: $name='"'.$name.'"';
2699: } else {
2700: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2701: $names{'lastname'}.' '.$names{'generation'};
2702: $name=~s/\s+$//;
2703: $name=~s/\s+/ /g;
2704: }
2705: return $name;
2706: }
2707:
1.295 www 2708: sub getnames {
2709: my ($uname,$udom)=@_;
1.537 albertel 2710: return if (!defined($uname) || !defined($udom));
1.433 albertel 2711: if ($udom eq 'public' && $uname eq 'public') {
2712: return ('lastname' => &mt('Public'));
2713: }
1.295 www 2714: my $id=$uname.':'.$udom;
2715: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2716: if ($cached) {
2717: return %{$names};
2718: } else {
2719: my %loadnames=&Apache::lonnet::get('environment',
2720: ['firstname','middlename','lastname','generation','nickname'],
2721: $udom,$uname);
2722: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2723: return %loadnames;
2724: }
2725: }
1.61 www 2726:
1.542 raeburn 2727: # -------------------------------------------------------------------- getemails
1.648 raeburn 2728:
1.542 raeburn 2729: =pod
2730:
1.648 raeburn 2731: =item * &getemails($uname,$udom)
1.542 raeburn 2732:
2733: Gets a user's email information and returns it as a hash with keys:
2734: notification, critnotification, permanentemail
2735:
2736: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2737: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2738:
1.648 raeburn 2739:
1.542 raeburn 2740: =cut
2741:
1.648 raeburn 2742:
1.466 albertel 2743: sub getemails {
2744: my ($uname,$udom)=@_;
2745: if ($udom eq 'public' && $uname eq 'public') {
2746: return;
2747: }
1.467 www 2748: if (!$udom) { $udom=$env{'user.domain'}; }
2749: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2750: my $id=$uname.':'.$udom;
2751: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2752: if ($cached) {
2753: return %{$names};
2754: } else {
2755: my %loadnames=&Apache::lonnet::get('environment',
2756: ['notification','critnotification',
2757: 'permanentemail'],
2758: $udom,$uname);
2759: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2760: return %loadnames;
2761: }
2762: }
2763:
1.551 albertel 2764: sub flush_email_cache {
2765: my ($uname,$udom)=@_;
2766: if (!$udom) { $udom =$env{'user.domain'}; }
2767: if (!$uname) { $uname=$env{'user.name'}; }
2768: return if ($udom eq 'public' && $uname eq 'public');
2769: my $id=$uname.':'.$udom;
2770: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2771: }
2772:
1.728 raeburn 2773: # -------------------------------------------------------------------- getlangs
2774:
2775: =pod
2776:
2777: =item * &getlangs($uname,$udom)
2778:
2779: Gets a user's language preference and returns it as a hash with key:
2780: language.
2781:
2782: =cut
2783:
2784:
2785: sub getlangs {
2786: my ($uname,$udom) = @_;
2787: if (!$udom) { $udom =$env{'user.domain'}; }
2788: if (!$uname) { $uname=$env{'user.name'}; }
2789: my $id=$uname.':'.$udom;
2790: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2791: if ($cached) {
2792: return %{$langs};
2793: } else {
2794: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2795: $udom,$uname);
2796: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2797: return %loadlangs;
2798: }
2799: }
2800:
2801: sub flush_langs_cache {
2802: my ($uname,$udom)=@_;
2803: if (!$udom) { $udom =$env{'user.domain'}; }
2804: if (!$uname) { $uname=$env{'user.name'}; }
2805: return if ($udom eq 'public' && $uname eq 'public');
2806: my $id=$uname.':'.$udom;
2807: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2808: }
2809:
1.61 www 2810: # ------------------------------------------------------------------ Screenname
1.81 albertel 2811:
2812: =pod
2813:
1.648 raeburn 2814: =item * &screenname($uname,$udom)
1.81 albertel 2815:
2816: Gets a users screenname and returns it as a string
2817:
2818: =cut
1.61 www 2819:
2820: sub screenname {
2821: my ($uname,$udom)=@_;
1.258 albertel 2822: if ($uname eq $env{'user.name'} &&
2823: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2824: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2825: return $names{'screenname'};
1.62 www 2826: }
2827:
1.212 albertel 2828:
1.802 bisitz 2829: # ------------------------------------------------------------- Confirm Wrapper
2830: =pod
2831:
2832: =item confirmwrapper
2833:
2834: Wrap messages about completion of operation in box
2835:
2836: =cut
2837:
2838: sub confirmwrapper {
2839: my ($message)=@_;
2840: if ($message) {
2841: return "\n".'<div class="LC_confirm_box">'."\n"
2842: .$message."\n"
2843: .'</div>'."\n";
2844: } else {
2845: return $message;
2846: }
2847: }
2848:
1.62 www 2849: # ------------------------------------------------------------- Message Wrapper
2850:
2851: sub messagewrapper {
1.369 www 2852: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2853: return
1.441 albertel 2854: '<a href="/adm/email?compose=individual&'.
2855: 'recname='.$username.'&recdom='.$domain.
2856: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2857: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2858: }
1.802 bisitz 2859:
1.74 www 2860: # --------------------------------------------------------------- Notes Wrapper
2861:
2862: sub noteswrapper {
2863: my ($link,$un,$do)=@_;
2864: return
2865: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2866: }
1.802 bisitz 2867:
1.62 www 2868: # ------------------------------------------------------------- Aboutme Wrapper
2869:
2870: sub aboutmewrapper {
1.166 www 2871: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2872: if (!defined($username) && !defined($domain)) {
2873: return;
2874: }
1.205 www 2875: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2876: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2877: }
2878:
2879: # ------------------------------------------------------------ Syllabus Wrapper
2880:
2881: sub syllabuswrapper {
1.707 bisitz 2882: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2883: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2884: }
1.14 harris41 2885:
1.802 bisitz 2886: # -----------------------------------------------------------------------------
2887:
1.208 matthew 2888: sub track_student_link {
1.268 albertel 2889: my ($linktext,$sname,$sdom,$target,$start) = @_;
2890: my $link ="/adm/trackstudent?";
1.208 matthew 2891: my $title = 'View recent activity';
2892: if (defined($sname) && $sname !~ /^\s*$/ &&
2893: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2894: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2895: $title .= ' of this student';
1.268 albertel 2896: }
1.208 matthew 2897: if (defined($target) && $target !~ /^\s*$/) {
2898: $target = qq{target="$target"};
2899: } else {
2900: $target = '';
2901: }
1.268 albertel 2902: if ($start) { $link.='&start='.$start; }
1.554 albertel 2903: $title = &mt($title);
2904: $linktext = &mt($linktext);
1.448 albertel 2905: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2906: &help_open_topic('View_recent_activity');
1.208 matthew 2907: }
2908:
1.781 raeburn 2909: sub slot_reservations_link {
2910: my ($linktext,$sname,$sdom,$target) = @_;
2911: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2912: my $title = 'View slot reservation history';
2913: if (defined($sname) && $sname !~ /^\s*$/ &&
2914: defined($sdom) && $sdom !~ /^\s*$/) {
2915: $link .= "&uname=$sname&udom=$sdom";
2916: $title .= ' of this student';
2917: }
2918: if (defined($target) && $target !~ /^\s*$/) {
2919: $target = qq{target="$target"};
2920: } else {
2921: $target = '';
2922: }
2923: $title = &mt($title);
2924: $linktext = &mt($linktext);
2925: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2926: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2927:
2928: }
2929:
1.508 www 2930: # ===================================================== Display a student photo
2931:
2932:
1.509 albertel 2933: sub student_image_tag {
1.508 www 2934: my ($domain,$user)=@_;
2935: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2936: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2937: return '<img src="'.$imgsrc.'" align="right" />';
2938: } else {
2939: return '';
2940: }
2941: }
2942:
1.112 bowersj2 2943: =pod
2944:
2945: =back
2946:
2947: =head1 Access .tab File Data
2948:
2949: =over 4
2950:
1.648 raeburn 2951: =item * &languageids()
1.112 bowersj2 2952:
2953: returns list of all language ids
2954:
2955: =cut
2956:
1.14 harris41 2957: sub languageids {
1.16 harris41 2958: return sort(keys(%language));
1.14 harris41 2959: }
2960:
1.112 bowersj2 2961: =pod
2962:
1.648 raeburn 2963: =item * &languagedescription()
1.112 bowersj2 2964:
2965: returns description of a specified language id
2966:
2967: =cut
2968:
1.14 harris41 2969: sub languagedescription {
1.125 www 2970: my $code=shift;
2971: return ($supported_language{$code}?'* ':'').
2972: $language{$code}.
1.126 www 2973: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2974: }
2975:
2976: sub plainlanguagedescription {
2977: my $code=shift;
2978: return $language{$code};
2979: }
2980:
2981: sub supportedlanguagecode {
2982: my $code=shift;
2983: return $supported_language{$code};
1.97 www 2984: }
2985:
1.112 bowersj2 2986: =pod
2987:
1.648 raeburn 2988: =item * ©rightids()
1.112 bowersj2 2989:
2990: returns list of all copyrights
2991:
2992: =cut
2993:
2994: sub copyrightids {
2995: return sort(keys(%cprtag));
2996: }
2997:
2998: =pod
2999:
1.648 raeburn 3000: =item * ©rightdescription()
1.112 bowersj2 3001:
3002: returns description of a specified copyright id
3003:
3004: =cut
3005:
3006: sub copyrightdescription {
1.166 www 3007: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3008: }
1.197 matthew 3009:
3010: =pod
3011:
1.648 raeburn 3012: =item * &source_copyrightids()
1.192 taceyjo1 3013:
3014: returns list of all source copyrights
3015:
3016: =cut
3017:
3018: sub source_copyrightids {
3019: return sort(keys(%scprtag));
3020: }
3021:
3022: =pod
3023:
1.648 raeburn 3024: =item * &source_copyrightdescription()
1.192 taceyjo1 3025:
3026: returns description of a specified source copyright id
3027:
3028: =cut
3029:
3030: sub source_copyrightdescription {
3031: return &mt($scprtag{shift(@_)});
3032: }
1.112 bowersj2 3033:
3034: =pod
3035:
1.648 raeburn 3036: =item * &filecategories()
1.112 bowersj2 3037:
3038: returns list of all file categories
3039:
3040: =cut
3041:
3042: sub filecategories {
3043: return sort(keys(%category_extensions));
3044: }
3045:
3046: =pod
3047:
1.648 raeburn 3048: =item * &filecategorytypes()
1.112 bowersj2 3049:
3050: returns list of file types belonging to a given file
3051: category
3052:
3053: =cut
3054:
3055: sub filecategorytypes {
1.356 albertel 3056: my ($cat) = @_;
3057: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3058: }
3059:
3060: =pod
3061:
1.648 raeburn 3062: =item * &fileembstyle()
1.112 bowersj2 3063:
3064: returns embedding style for a specified file type
3065:
3066: =cut
3067:
3068: sub fileembstyle {
3069: return $fe{lc(shift(@_))};
1.169 www 3070: }
3071:
1.351 www 3072: sub filemimetype {
3073: return $fm{lc(shift(@_))};
3074: }
3075:
1.169 www 3076:
3077: sub filecategoryselect {
3078: my ($name,$value)=@_;
1.189 matthew 3079: return &select_form($value,$name,
1.169 www 3080: '' => &mt('Any category'),
3081: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3082: }
3083:
3084: =pod
3085:
1.648 raeburn 3086: =item * &filedescription()
1.112 bowersj2 3087:
3088: returns description for a specified file type
3089:
3090: =cut
3091:
3092: sub filedescription {
1.188 matthew 3093: my $file_description = $fd{lc(shift())};
3094: $file_description =~ s:([\[\]]):~$1:g;
3095: return &mt($file_description);
1.112 bowersj2 3096: }
3097:
3098: =pod
3099:
1.648 raeburn 3100: =item * &filedescriptionex()
1.112 bowersj2 3101:
3102: returns description for a specified file type with
3103: extra formatting
3104:
3105: =cut
3106:
3107: sub filedescriptionex {
3108: my $ex=shift;
1.188 matthew 3109: my $file_description = $fd{lc($ex)};
3110: $file_description =~ s:([\[\]]):~$1:g;
3111: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3112: }
3113:
3114: # End of .tab access
3115: =pod
3116:
3117: =back
3118:
3119: =cut
3120:
3121: # ------------------------------------------------------------------ File Types
3122: sub fileextensions {
3123: return sort(keys(%fe));
3124: }
3125:
1.97 www 3126: # ----------------------------------------------------------- Display Languages
3127: # returns a hash with all desired display languages
3128: #
3129:
3130: sub display_languages {
3131: my %languages=();
1.695 raeburn 3132: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3133: $languages{$lang}=1;
1.97 www 3134: }
3135: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3136: if ($env{'form.displaylanguage'}) {
1.356 albertel 3137: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3138: $languages{$lang}=1;
1.97 www 3139: }
3140: }
3141: return %languages;
1.14 harris41 3142: }
3143:
1.582 albertel 3144: sub languages {
3145: my ($possible_langs) = @_;
1.695 raeburn 3146: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3147: if (!ref($possible_langs)) {
3148: if( wantarray ) {
3149: return @preferred_langs;
3150: } else {
3151: return $preferred_langs[0];
3152: }
3153: }
3154: my %possibilities = map { $_ => 1 } (@$possible_langs);
3155: my @preferred_possibilities;
3156: foreach my $preferred_lang (@preferred_langs) {
3157: if (exists($possibilities{$preferred_lang})) {
3158: push(@preferred_possibilities, $preferred_lang);
3159: }
3160: }
3161: if( wantarray ) {
3162: return @preferred_possibilities;
3163: }
3164: return $preferred_possibilities[0];
3165: }
3166:
1.742 raeburn 3167: sub user_lang {
3168: my ($touname,$toudom,$fromcid) = @_;
3169: my @userlangs;
3170: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3171: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3172: $env{'course.'.$fromcid.'.languages'}));
3173: } else {
3174: my %langhash = &getlangs($touname,$toudom);
3175: if ($langhash{'languages'} ne '') {
3176: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3177: } else {
3178: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3179: if ($domdefs{'lang_def'} ne '') {
3180: @userlangs = ($domdefs{'lang_def'});
3181: }
3182: }
3183: }
3184: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3185: my $user_lh = Apache::localize->get_handle(@languages);
3186: return $user_lh;
3187: }
3188:
3189:
1.112 bowersj2 3190: ###############################################################
3191: ## Student Answer Attempts ##
3192: ###############################################################
3193:
3194: =pod
3195:
3196: =head1 Alternate Problem Views
3197:
3198: =over 4
3199:
1.648 raeburn 3200: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3201: $getattempt, $regexp, $gradesub)
3202:
3203: Return string with previous attempt on problem. Arguments:
3204:
3205: =over 4
3206:
3207: =item * $symb: Problem, including path
3208:
3209: =item * $username: username of the desired student
3210:
3211: =item * $domain: domain of the desired student
1.14 harris41 3212:
1.112 bowersj2 3213: =item * $course: Course ID
1.14 harris41 3214:
1.112 bowersj2 3215: =item * $getattempt: Leave blank for all attempts, otherwise put
3216: something
1.14 harris41 3217:
1.112 bowersj2 3218: =item * $regexp: if string matches this regexp, the string will be
3219: sent to $gradesub
1.14 harris41 3220:
1.112 bowersj2 3221: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3222:
1.112 bowersj2 3223: =back
1.14 harris41 3224:
1.112 bowersj2 3225: The output string is a table containing all desired attempts, if any.
1.16 harris41 3226:
1.112 bowersj2 3227: =cut
1.1 albertel 3228:
3229: sub get_previous_attempt {
1.43 ng 3230: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3231: my $prevattempts='';
1.43 ng 3232: no strict 'refs';
1.1 albertel 3233: if ($symb) {
1.3 albertel 3234: my (%returnhash)=
3235: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3236: if ($returnhash{'version'}) {
3237: my %lasthash=();
3238: my $version;
3239: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3240: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3241: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3242: }
1.1 albertel 3243: }
1.596 albertel 3244: $prevattempts=&start_data_table().&start_data_table_header_row();
3245: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3246: foreach my $key (sort(keys(%lasthash))) {
3247: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3248: if ($#parts > 0) {
1.31 albertel 3249: my $data=$parts[-1];
3250: pop(@parts);
1.596 albertel 3251: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3252: } else {
1.41 ng 3253: if ($#parts == 0) {
3254: $prevattempts.='<th>'.$parts[0].'</th>';
3255: } else {
3256: $prevattempts.='<th>'.$ign.'</th>';
3257: }
1.31 albertel 3258: }
1.16 harris41 3259: }
1.596 albertel 3260: $prevattempts.=&end_data_table_header_row();
1.40 ng 3261: if ($getattempt eq '') {
3262: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3263: $prevattempts.=&start_data_table_row().
3264: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3265: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3266: my $value = &format_previous_attempt_value($key,
3267: $returnhash{$version.':'.$key});
3268: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3269: }
1.596 albertel 3270: $prevattempts.=&end_data_table_row();
1.40 ng 3271: }
1.1 albertel 3272: }
1.596 albertel 3273: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3274: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3275: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3276: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3277: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3278: }
1.596 albertel 3279: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3280: } else {
1.596 albertel 3281: $prevattempts=
3282: &start_data_table().&start_data_table_row().
3283: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3284: &end_data_table_row().&end_data_table();
1.1 albertel 3285: }
3286: } else {
1.596 albertel 3287: $prevattempts=
3288: &start_data_table().&start_data_table_row().
3289: '<td>'.&mt('No data.').'</td>'.
3290: &end_data_table_row().&end_data_table();
1.1 albertel 3291: }
1.10 albertel 3292: }
3293:
1.581 albertel 3294: sub format_previous_attempt_value {
3295: my ($key,$value) = @_;
3296: if ($key =~ /timestamp/) {
3297: $value = &Apache::lonlocal::locallocaltime($value);
3298: } elsif (ref($value) eq 'ARRAY') {
3299: $value = '('.join(', ', @{ $value }).')';
3300: } else {
3301: $value = &unescape($value);
3302: }
3303: return $value;
3304: }
3305:
3306:
1.107 albertel 3307: sub relative_to_absolute {
3308: my ($url,$output)=@_;
3309: my $parser=HTML::TokeParser->new(\$output);
3310: my $token;
3311: my $thisdir=$url;
3312: my @rlinks=();
3313: while ($token=$parser->get_token) {
3314: if ($token->[0] eq 'S') {
3315: if ($token->[1] eq 'a') {
3316: if ($token->[2]->{'href'}) {
3317: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3318: }
3319: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3320: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3321: } elsif ($token->[1] eq 'base') {
3322: $thisdir=$token->[2]->{'href'};
3323: }
3324: }
3325: }
3326: $thisdir=~s-/[^/]*$--;
1.356 albertel 3327: foreach my $link (@rlinks) {
1.726 raeburn 3328: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3329: ($link=~/^\//) ||
3330: ($link=~/^javascript:/i) ||
3331: ($link=~/^mailto:/i) ||
3332: ($link=~/^\#/)) {
3333: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3334: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3335: }
3336: }
3337: # -------------------------------------------------- Deal with Applet codebases
3338: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3339: return $output;
3340: }
3341:
1.112 bowersj2 3342: =pod
3343:
1.648 raeburn 3344: =item * &get_student_view()
1.112 bowersj2 3345:
3346: show a snapshot of what student was looking at
3347:
3348: =cut
3349:
1.10 albertel 3350: sub get_student_view {
1.186 albertel 3351: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3352: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3353: my (%form);
1.10 albertel 3354: my @elements=('symb','courseid','domain','username');
3355: foreach my $element (@elements) {
1.186 albertel 3356: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3357: }
1.186 albertel 3358: if (defined($moreenv)) {
3359: %form=(%form,%{$moreenv});
3360: }
1.236 albertel 3361: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3362: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3363: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3364: $userview=~s/\<body[^\>]*\>//gi;
3365: $userview=~s/\<\/body\>//gi;
3366: $userview=~s/\<html\>//gi;
3367: $userview=~s/\<\/html\>//gi;
3368: $userview=~s/\<head\>//gi;
3369: $userview=~s/\<\/head\>//gi;
3370: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3371: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3372: if (wantarray) {
3373: return ($userview,$response);
3374: } else {
3375: return $userview;
3376: }
3377: }
3378:
3379: sub get_student_view_with_retries {
3380: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3381:
3382: my $ok = 0; # True if we got a good response.
3383: my $content;
3384: my $response;
3385:
3386: # Try to get the student_view done. within the retries count:
3387:
3388: do {
3389: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3390: $ok = $response->is_success;
3391: if (!$ok) {
3392: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3393: }
3394: $retries--;
3395: } while (!$ok && ($retries > 0));
3396:
3397: if (!$ok) {
3398: $content = ''; # On error return an empty content.
3399: }
1.651 www 3400: if (wantarray) {
3401: return ($content, $response);
3402: } else {
3403: return $content;
3404: }
1.11 albertel 3405: }
3406:
1.112 bowersj2 3407: =pod
3408:
1.648 raeburn 3409: =item * &get_student_answers()
1.112 bowersj2 3410:
3411: show a snapshot of how student was answering problem
3412:
3413: =cut
3414:
1.11 albertel 3415: sub get_student_answers {
1.100 sakharuk 3416: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3417: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3418: my (%moreenv);
1.11 albertel 3419: my @elements=('symb','courseid','domain','username');
3420: foreach my $element (@elements) {
1.186 albertel 3421: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3422: }
1.186 albertel 3423: $moreenv{'grade_target'}='answer';
3424: %moreenv=(%form,%moreenv);
1.497 raeburn 3425: $feedurl = &Apache::lonnet::clutter($feedurl);
3426: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3427: return $userview;
1.1 albertel 3428: }
1.116 albertel 3429:
3430: =pod
3431:
3432: =item * &submlink()
3433:
1.242 albertel 3434: Inputs: $text $uname $udom $symb $target
1.116 albertel 3435:
3436: Returns: A link to grades.pm such as to see the SUBM view of a student
3437:
3438: =cut
3439:
3440: ###############################################
3441: sub submlink {
1.242 albertel 3442: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3443: if (!($uname && $udom)) {
3444: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3445: &Apache::lonnet::whichuser($symb);
1.116 albertel 3446: if (!$symb) { $symb=$cursymb; }
3447: }
1.254 matthew 3448: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3449: $symb=&escape($symb);
1.242 albertel 3450: if ($target) { $target="target=\"$target\""; }
3451: return '<a href="/adm/grades?&command=submission&'.
3452: 'symb='.$symb.'&student='.$uname.
3453: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3454: }
3455: ##############################################
3456:
3457: =pod
3458:
3459: =item * &pgrdlink()
3460:
3461: Inputs: $text $uname $udom $symb $target
3462:
3463: Returns: A link to grades.pm such as to see the PGRD view of a student
3464:
3465: =cut
3466:
3467: ###############################################
3468: sub pgrdlink {
3469: my $link=&submlink(@_);
3470: $link=~s/(&command=submission)/$1&showgrading=yes/;
3471: return $link;
3472: }
3473: ##############################################
3474:
3475: =pod
3476:
3477: =item * &pprmlink()
3478:
3479: Inputs: $text $uname $udom $symb $target
3480:
3481: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3482: student and a specific resource
1.242 albertel 3483:
3484: =cut
3485:
3486: ###############################################
3487: sub pprmlink {
3488: my ($text,$uname,$udom,$symb,$target)=@_;
3489: if (!($uname && $udom)) {
3490: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3491: &Apache::lonnet::whichuser($symb);
1.242 albertel 3492: if (!$symb) { $symb=$cursymb; }
3493: }
1.254 matthew 3494: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3495: $symb=&escape($symb);
1.242 albertel 3496: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3497: return '<a href="/adm/parmset?command=set&'.
3498: 'symb='.$symb.'&uname='.$uname.
3499: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3500: }
3501: ##############################################
1.37 matthew 3502:
1.112 bowersj2 3503: =pod
3504:
3505: =back
3506:
3507: =cut
3508:
1.37 matthew 3509: ###############################################
1.51 www 3510:
3511:
3512: sub timehash {
1.687 raeburn 3513: my ($thistime) = @_;
3514: my $timezone = &Apache::lonlocal::gettimezone();
3515: my $dt = DateTime->from_epoch(epoch => $thistime)
3516: ->set_time_zone($timezone);
3517: my $wday = $dt->day_of_week();
3518: if ($wday == 7) { $wday = 0; }
3519: return ( 'second' => $dt->second(),
3520: 'minute' => $dt->minute(),
3521: 'hour' => $dt->hour(),
3522: 'day' => $dt->day_of_month(),
3523: 'month' => $dt->month(),
3524: 'year' => $dt->year(),
3525: 'weekday' => $wday,
3526: 'dayyear' => $dt->day_of_year(),
3527: 'dlsav' => $dt->is_dst() );
1.51 www 3528: }
3529:
1.370 www 3530: sub utc_string {
3531: my ($date)=@_;
1.371 www 3532: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3533: }
3534:
1.51 www 3535: sub maketime {
3536: my %th=@_;
1.687 raeburn 3537: my ($epoch_time,$timezone,$dt);
3538: $timezone = &Apache::lonlocal::gettimezone();
3539: eval {
3540: $dt = DateTime->new( year => $th{'year'},
3541: month => $th{'month'},
3542: day => $th{'day'},
3543: hour => $th{'hour'},
3544: minute => $th{'minute'},
3545: second => $th{'second'},
3546: time_zone => $timezone,
3547: );
3548: };
3549: if (!$@) {
3550: $epoch_time = $dt->epoch;
3551: if ($epoch_time) {
3552: return $epoch_time;
3553: }
3554: }
1.51 www 3555: return POSIX::mktime(
3556: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3557: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3558: }
3559:
3560: #########################################
1.51 www 3561:
3562: sub findallcourses {
1.482 raeburn 3563: my ($roles,$uname,$udom) = @_;
1.355 albertel 3564: my %roles;
3565: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3566: my %courses;
1.51 www 3567: my $now=time;
1.482 raeburn 3568: if (!defined($uname)) {
3569: $uname = $env{'user.name'};
3570: }
3571: if (!defined($udom)) {
3572: $udom = $env{'user.domain'};
3573: }
3574: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3575: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3576: if (!%roles) {
3577: %roles = (
3578: cc => 1,
3579: in => 1,
3580: ep => 1,
3581: ta => 1,
3582: cr => 1,
3583: st => 1,
3584: );
3585: }
3586: foreach my $entry (keys(%roleshash)) {
3587: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3588: if ($trole =~ /^cr/) {
3589: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3590: } else {
3591: next if (!exists($roles{$trole}));
3592: }
3593: if ($tend) {
3594: next if ($tend < $now);
3595: }
3596: if ($tstart) {
3597: next if ($tstart > $now);
3598: }
3599: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3600: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3601: if ($secpart eq '') {
3602: ($cnum,$role) = split(/_/,$cnumpart);
3603: $sec = 'none';
3604: $realsec = '';
3605: } else {
3606: $cnum = $cnumpart;
3607: ($sec,$role) = split(/_/,$secpart);
3608: $realsec = $sec;
1.490 raeburn 3609: }
1.482 raeburn 3610: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3611: }
3612: } else {
3613: foreach my $key (keys(%env)) {
1.483 albertel 3614: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3615: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3616: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3617: next if ($role eq 'ca' || $role eq 'aa');
3618: next if (%roles && !exists($roles{$role}));
3619: my ($starttime,$endtime)=split(/\./,$env{$key});
3620: my $active=1;
3621: if ($starttime) {
3622: if ($now<$starttime) { $active=0; }
3623: }
3624: if ($endtime) {
3625: if ($now>$endtime) { $active=0; }
3626: }
3627: if ($active) {
3628: if ($sec eq '') {
3629: $sec = 'none';
3630: }
3631: $courses{$cdom.'_'.$cnum}{$sec} =
3632: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3633: }
3634: }
1.51 www 3635: }
3636: }
1.474 raeburn 3637: return %courses;
1.51 www 3638: }
1.37 matthew 3639:
1.54 www 3640: ###############################################
1.474 raeburn 3641:
3642: sub blockcheck {
1.482 raeburn 3643: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3644:
3645: if (!defined($udom)) {
3646: $udom = $env{'user.domain'};
3647: }
3648: if (!defined($uname)) {
3649: $uname = $env{'user.name'};
3650: }
3651:
3652: # If uname and udom are for a course, check for blocks in the course.
3653:
3654: if (&Apache::lonnet::is_course($udom,$uname)) {
3655: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3656: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3657: return ($startblock,$endblock);
3658: }
1.474 raeburn 3659:
1.502 raeburn 3660: my $startblock = 0;
3661: my $endblock = 0;
1.482 raeburn 3662: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3663:
1.490 raeburn 3664: # If uname is for a user, and activity is course-specific, i.e.,
3665: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3666:
1.490 raeburn 3667: if (($activity eq 'boards' || $activity eq 'chat' ||
3668: $activity eq 'groups') && ($env{'request.course.id'})) {
3669: foreach my $key (keys(%live_courses)) {
3670: if ($key ne $env{'request.course.id'}) {
3671: delete($live_courses{$key});
3672: }
3673: }
3674: }
3675:
3676: my $otheruser = 0;
3677: my %own_courses;
3678: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3679: # Resource belongs to user other than current user.
3680: $otheruser = 1;
3681: # Gather courses for current user
3682: %own_courses =
3683: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3684: }
3685:
3686: # Gather active course roles - course coordinator, instructor,
3687: # exam proctor, ta, student, or custom role.
1.474 raeburn 3688:
3689: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3690: my ($cdom,$cnum);
3691: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3692: $cdom = $env{'course.'.$course.'.domain'};
3693: $cnum = $env{'course.'.$course.'.num'};
3694: } else {
1.490 raeburn 3695: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3696: }
3697: my $no_ownblock = 0;
3698: my $no_userblock = 0;
1.533 raeburn 3699: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3700: # Check if current user has 'evb' priv for this
3701: if (defined($own_courses{$course})) {
3702: foreach my $sec (keys(%{$own_courses{$course}})) {
3703: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3704: if ($sec ne 'none') {
3705: $checkrole .= '/'.$sec;
3706: }
3707: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3708: $no_ownblock = 1;
3709: last;
3710: }
3711: }
3712: }
3713: # if they have 'evb' priv and are currently not playing student
3714: next if (($no_ownblock) &&
3715: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3716: }
1.474 raeburn 3717: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3718: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3719: if ($sec ne 'none') {
1.482 raeburn 3720: $checkrole .= '/'.$sec;
1.474 raeburn 3721: }
1.490 raeburn 3722: if ($otheruser) {
3723: # Resource belongs to user other than current user.
3724: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3725: my ($trole,$tdom,$tnum,$tsec);
3726: my $entry = $live_courses{$course}{$sec};
3727: if ($entry =~ /^cr/) {
3728: ($trole,$tdom,$tnum,$tsec) =
3729: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3730: } else {
3731: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3732: }
3733: my ($spec,$area,$trest,%allroles,%userroles);
3734: $area = '/'.$tdom.'/'.$tnum;
3735: $trest = $tnum;
3736: if ($tsec ne '') {
3737: $area .= '/'.$tsec;
3738: $trest .= '/'.$tsec;
3739: }
3740: $spec = $trole.'.'.$area;
3741: if ($trole =~ /^cr/) {
3742: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3743: $tdom,$spec,$trest,$area);
3744: } else {
3745: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3746: $tdom,$spec,$trest,$area);
3747: }
3748: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3749: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3750: if ($1) {
3751: $no_userblock = 1;
3752: last;
3753: }
3754: }
1.490 raeburn 3755: } else {
3756: # Resource belongs to current user
3757: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3758: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3759: $no_ownblock = 1;
3760: last;
3761: }
1.474 raeburn 3762: }
3763: }
3764: # if they have the evb priv and are currently not playing student
1.482 raeburn 3765: next if (($no_ownblock) &&
1.491 albertel 3766: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3767: next if ($no_userblock);
1.474 raeburn 3768:
1.866 ! kalberla 3769: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3770: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3771:
3772: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3773: if (($start != 0) &&
3774: (($startblock == 0) || ($startblock > $start))) {
3775: $startblock = $start;
3776: }
3777: if (($end != 0) &&
3778: (($endblock == 0) || ($endblock < $end))) {
3779: $endblock = $end;
3780: }
1.490 raeburn 3781: }
3782: return ($startblock,$endblock);
3783: }
3784:
3785: sub get_blocks {
3786: my ($setters,$activity,$cdom,$cnum) = @_;
3787: my $startblock = 0;
3788: my $endblock = 0;
3789: my $course = $cdom.'_'.$cnum;
3790: $setters->{$course} = {};
3791: $setters->{$course}{'staff'} = [];
3792: $setters->{$course}{'times'} = [];
3793: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3794: foreach my $record (keys(%records)) {
3795: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3796: if ($start <= time && $end >= time) {
3797: my ($staff_name,$staff_dom,$title,$blocks) =
3798: &parse_block_record($records{$record});
3799: if ($blocks->{$activity} eq 'on') {
3800: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3801: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3802: if ( ($startblock == 0) || ($startblock > $start) ) {
3803: $startblock = $start;
1.490 raeburn 3804: }
1.491 albertel 3805: if ( ($endblock == 0) || ($endblock < $end) ) {
3806: $endblock = $end;
1.474 raeburn 3807: }
3808: }
3809: }
3810: }
3811: return ($startblock,$endblock);
3812: }
3813:
3814: sub parse_block_record {
3815: my ($record) = @_;
3816: my ($setuname,$setudom,$title,$blocks);
3817: if (ref($record) eq 'HASH') {
3818: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3819: $title = &unescape($record->{'event'});
3820: $blocks = $record->{'blocks'};
3821: } else {
3822: my @data = split(/:/,$record,3);
3823: if (scalar(@data) eq 2) {
3824: $title = $data[1];
3825: ($setuname,$setudom) = split(/@/,$data[0]);
3826: } else {
3827: ($setuname,$setudom,$title) = @data;
3828: }
3829: $blocks = { 'com' => 'on' };
3830: }
3831: return ($setuname,$setudom,$title,$blocks);
3832: }
3833:
3834: sub build_block_table {
3835: my ($startblock,$endblock,$setters) = @_;
3836: my %lt = &Apache::lonlocal::texthash(
3837: 'cacb' => 'Currently active communication blocks',
3838: 'cour' => 'Course',
3839: 'dura' => 'Duration',
3840: 'blse' => 'Block set by'
3841: );
3842: my $output;
1.476 raeburn 3843: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3844: $output .= &start_data_table();
3845: $output .= '
3846: <tr>
3847: <th>'.$lt{'cour'}.'</th>
3848: <th>'.$lt{'dura'}.'</th>
3849: <th>'.$lt{'blse'}.'</th>
3850: </tr>
3851: ';
3852: foreach my $course (keys(%{$setters})) {
3853: my %courseinfo=&Apache::lonnet::coursedescription($course);
3854: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3855: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3856: my $fullname = &plainname($uname,$udom);
3857: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3858: && $env{'user.name'} ne 'public'
3859: && $env{'user.domain'} ne 'public') {
3860: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3861: }
1.474 raeburn 3862: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3863: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3864: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3865: $output .= &Apache::loncommon::start_data_table_row().
3866: '<td>'.$courseinfo{'description'}.'</td>'.
3867: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3868: '<td>'.$fullname.'</td>'.
1.474 raeburn 3869: &Apache::loncommon::end_data_table_row();
3870: }
3871: }
3872: $output .= &end_data_table();
3873: }
1.854 kalberla 3874: sub blocking_status {
3875: my $blocked = blocking_status_print(@_);
3876: my ($activity,$uname,$udom) = @_;
3877: if(!wantarray) {
3878: return $blocked;
3879: }
3880: my $output;
3881: my $querystring;
3882: $querystring = "?activity=$activity";
3883: if(defined($uname)) {
3884: $querystring .= "&uname=$uname";
3885: }if(defined($udom)) {
3886: $querystring .= "&udom=$udom";
3887: }
3888:
3889: $output .= <<"END_MYBLOCK";
3890: <script type="text/javascript">
3891: // <![CDATA[
3892: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3893: var options = "width=" + w + ",height=" + h + ",";
3894: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3895: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3896: var newWin = window.open(url, wdwName, options);
3897: newWin.focus();
3898: }
3899:
3900: // ]]>
3901: </script>
3902: END_MYBLOCK
3903: my $popupUrl = "/adm/blockingstatus/$querystring";
3904: $output.="\n<img src='/res/adm/pages/emblem-readonly.png' /><a onclick='openWindow(\"$popupUrl\",\"Blocking Table\",600,300,\"no\",\"no\");return false;' href='/adm/blockingstatus/$querystring'>Blocking Table</a>";
1.474 raeburn 3905:
1.854 kalberla 3906: return ($blocked, $output);
3907: }
3908: sub blocking_status_print {
1.490 raeburn 3909: my ($activity,$uname,$udom) = @_;
3910: my %setters;
3911: my ($blocked,$output,$ownitem,$is_course);
3912: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3913: if ($startblock && $endblock) {
3914: $blocked = 1;
3915: if (wantarray) {
3916: my $category;
3917: if ($activity eq 'boards') {
3918: $category = 'Discussion posts in this course';
1.866 ! kalberla 3919: } elsif ($activity eq 'chat') {
! 3920: $category = 'Chat';
! 3921: } elsif ($activity eq 'msgdisplay') {
! 3922: $category = 'This message';
1.490 raeburn 3923: } elsif ($activity eq 'blogs') {
1.866 ! kalberla 3924: $category = 'Blogs';
1.490 raeburn 3925: } elsif ($activity eq 'port') {
3926: if (defined($uname) && defined($udom)) {
3927: if ($uname eq $env{'user.name'} &&
3928: $udom eq $env{'user.domain'}) {
3929: $ownitem = 1;
3930: }
3931: }
3932: $is_course = &Apache::lonnet::is_course($udom,$uname);
3933: if ($ownitem) {
3934: $category = 'Your portfolio files';
3935: } elsif ($is_course) {
3936: my $coursedesc;
3937: foreach my $course (keys(%setters)) {
3938: my %courseinfo =
3939: &Apache::lonnet::coursedescription($course);
3940: $coursedesc = $courseinfo{'description'};
3941: }
1.764 weissno 3942: $category = "Group portfolio in the course '$coursedesc'";
1.490 raeburn 3943: } else {
3944: $category = 'Portfolio files belonging to ';
3945: if ($env{'user.name'} eq 'public' &&
3946: $env{'user.domain'} eq 'public') {
3947: $category .= &plainname($uname,$udom);
3948: } else {
3949: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3950: }
3951: }
3952: } elsif ($activity eq 'groups') {
3953: $category = 'Groups in this course';
1.866 ! kalberla 3954: } else {
! 3955: $category = 'Communication';
1.490 raeburn 3956: }
3957: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3958: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3959: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3960: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3961: $output .= &build_block_table($startblock,$endblock,\%setters);
3962: }
3963: }
3964: }
3965: if (wantarray) {
3966: return ($blocked,$output);
3967: } else {
3968: return $blocked;
3969: }
3970: }
3971:
1.60 matthew 3972: ###############################################
3973:
1.682 raeburn 3974: sub check_ip_acc {
3975: my ($acc)=@_;
3976: &Apache::lonxml::debug("acc is $acc");
3977: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3978: return 1;
3979: }
3980: my $allowed=0;
3981: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3982:
3983: my $name;
3984: foreach my $pattern (split(',',$acc)) {
3985: $pattern =~ s/^\s*//;
3986: $pattern =~ s/\s*$//;
3987: if ($pattern =~ /\*$/) {
3988: #35.8.*
3989: $pattern=~s/\*//;
3990: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3991: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3992: #35.8.3.[34-56]
3993: my $low=$2;
3994: my $high=$3;
3995: $pattern=$1;
3996: if ($ip =~ /^\Q$pattern\E/) {
3997: my $last=(split(/\./,$ip))[3];
3998: if ($last <=$high && $last >=$low) { $allowed=1; }
3999: }
4000: } elsif ($pattern =~ /^\*/) {
4001: #*.msu.edu
4002: $pattern=~s/\*//;
4003: if (!defined($name)) {
4004: use Socket;
4005: my $netaddr=inet_aton($ip);
4006: ($name)=gethostbyaddr($netaddr,AF_INET);
4007: }
4008: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4009: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4010: #127.0.0.1
4011: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4012: } else {
4013: #some.name.com
4014: if (!defined($name)) {
4015: use Socket;
4016: my $netaddr=inet_aton($ip);
4017: ($name)=gethostbyaddr($netaddr,AF_INET);
4018: }
4019: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4020: }
4021: if ($allowed) { last; }
4022: }
4023: return $allowed;
4024: }
4025:
4026: ###############################################
4027:
1.60 matthew 4028: =pod
4029:
1.112 bowersj2 4030: =head1 Domain Template Functions
4031:
4032: =over 4
4033:
4034: =item * &determinedomain()
1.60 matthew 4035:
4036: Inputs: $domain (usually will be undef)
4037:
1.63 www 4038: Returns: Determines which domain should be used for designs
1.60 matthew 4039:
4040: =cut
1.54 www 4041:
1.60 matthew 4042: ###############################################
1.63 www 4043: sub determinedomain {
4044: my $domain=shift;
1.531 albertel 4045: if (! $domain) {
1.60 matthew 4046: # Determine domain if we have not been given one
4047: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 4048: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4049: if ($env{'request.role.domain'}) {
4050: $domain=$env{'request.role.domain'};
1.60 matthew 4051: }
4052: }
1.63 www 4053: return $domain;
4054: }
4055: ###############################################
1.517 raeburn 4056:
1.518 albertel 4057: sub devalidate_domconfig_cache {
4058: my ($udom)=@_;
4059: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4060: }
4061:
4062: # ---------------------- Get domain configuration for a domain
4063: sub get_domainconf {
4064: my ($udom) = @_;
4065: my $cachetime=1800;
4066: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4067: if (defined($cached)) { return %{$result}; }
4068:
4069: my %domconfig = &Apache::lonnet::get_dom('configuration',
4070: ['login','rolecolors'],$udom);
1.632 raeburn 4071: my (%designhash,%legacy);
1.518 albertel 4072: if (keys(%domconfig) > 0) {
4073: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4074: if (keys(%{$domconfig{'login'}})) {
4075: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4076: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4077: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4078: $designhash{$udom.'.login.'.$key.'_'.$img} =
4079: $domconfig{'login'}{$key}{$img};
4080: }
4081: } else {
4082: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4083: }
1.632 raeburn 4084: }
4085: } else {
4086: $legacy{'login'} = 1;
1.518 albertel 4087: }
1.632 raeburn 4088: } else {
4089: $legacy{'login'} = 1;
1.518 albertel 4090: }
4091: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4092: if (keys(%{$domconfig{'rolecolors'}})) {
4093: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4094: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4095: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4096: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4097: }
1.518 albertel 4098: }
4099: }
1.632 raeburn 4100: } else {
4101: $legacy{'rolecolors'} = 1;
1.518 albertel 4102: }
1.632 raeburn 4103: } else {
4104: $legacy{'rolecolors'} = 1;
1.518 albertel 4105: }
1.632 raeburn 4106: if (keys(%legacy) > 0) {
4107: my %legacyhash = &get_legacy_domconf($udom);
4108: foreach my $item (keys(%legacyhash)) {
4109: if ($item =~ /^\Q$udom\E\.login/) {
4110: if ($legacy{'login'}) {
4111: $designhash{$item} = $legacyhash{$item};
4112: }
4113: } else {
4114: if ($legacy{'rolecolors'}) {
4115: $designhash{$item} = $legacyhash{$item};
4116: }
1.518 albertel 4117: }
4118: }
4119: }
1.632 raeburn 4120: } else {
4121: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4122: }
4123: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4124: $cachetime);
4125: return %designhash;
4126: }
4127:
1.632 raeburn 4128: sub get_legacy_domconf {
4129: my ($udom) = @_;
4130: my %legacyhash;
4131: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4132: my $designfile = $designdir.'/'.$udom.'.tab';
4133: if (-e $designfile) {
4134: if ( open (my $fh,"<$designfile") ) {
4135: while (my $line = <$fh>) {
4136: next if ($line =~ /^\#/);
4137: chomp($line);
4138: my ($key,$val)=(split(/\=/,$line));
4139: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4140: }
4141: close($fh);
4142: }
4143: }
4144: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4145: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4146: }
4147: return %legacyhash;
4148: }
4149:
1.63 www 4150: =pod
4151:
1.112 bowersj2 4152: =item * &domainlogo()
1.63 www 4153:
4154: Inputs: $domain (usually will be undef)
4155:
4156: Returns: A link to a domain logo, if the domain logo exists.
4157: If the domain logo does not exist, a description of the domain.
4158:
4159: =cut
1.112 bowersj2 4160:
1.63 www 4161: ###############################################
4162: sub domainlogo {
1.517 raeburn 4163: my $domain = &determinedomain(shift);
1.518 albertel 4164: my %designhash = &get_domainconf($domain);
1.517 raeburn 4165: # See if there is a logo
4166: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4167: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4168: if ($imgsrc =~ m{^/(adm|res)/}) {
4169: if ($imgsrc =~ m{^/res/}) {
4170: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4171: &Apache::lonnet::repcopy($local_name);
4172: }
4173: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4174: }
4175: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4176: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4177: return &Apache::lonnet::domain($domain,'description');
1.59 www 4178: } else {
1.60 matthew 4179: return '';
1.59 www 4180: }
4181: }
1.63 www 4182: ##############################################
4183:
4184: =pod
4185:
1.112 bowersj2 4186: =item * &designparm()
1.63 www 4187:
4188: Inputs: $which parameter; $domain (usually will be undef)
4189:
4190: Returns: value of designparamter $which
4191:
4192: =cut
1.112 bowersj2 4193:
1.397 albertel 4194:
1.400 albertel 4195: ##############################################
1.397 albertel 4196: sub designparm {
4197: my ($which,$domain)=@_;
4198: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4199: return $env{'environment.color.'.$which};
1.96 www 4200: }
1.63 www 4201: $domain=&determinedomain($domain);
1.518 albertel 4202: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4203: my $output;
1.517 raeburn 4204: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4205: $output = $domdesign{$domain.'.'.$which};
1.63 www 4206: } else {
1.520 raeburn 4207: $output = $defaultdesign{$which};
4208: }
4209: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4210: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4211: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4212: if ($output =~ m{^/res/}) {
4213: my $local_name = &Apache::lonnet::filelocation('',$output);
4214: &Apache::lonnet::repcopy($local_name);
4215: }
1.520 raeburn 4216: $output = &lonhttpdurl($output);
4217: }
1.63 www 4218: }
1.520 raeburn 4219: return $output;
1.63 www 4220: }
1.59 www 4221:
1.822 bisitz 4222: ##############################################
4223: =pod
4224:
1.832 bisitz 4225: =item * &authorspace()
4226:
4227: Inputs: ./.
4228:
4229: Returns: Path to the Construction Space of the current user's
4230: accessed author space
4231: The author space will be that of the current user
4232: when accessing the own author space
4233: and that of the co-author/assistent co-author
4234: when accessing the co-author's/assistent co-author's
4235: space
4236:
4237: =cut
4238:
4239: sub authorspace {
4240: my $caname = '';
4241: if ($env{'request.role'} =~ /^ca|^aa/) {
4242: (undef,$caname) =
4243: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4244: } else {
4245: $caname = $env{'user.name'};
4246: }
4247: return '/priv/'.$caname.'/';
4248: }
4249:
4250: ##############################################
4251: =pod
4252:
1.822 bisitz 4253: =item * &head_subbox()
4254:
4255: Inputs: $content (contains HTML code with page functions, etc.)
4256:
4257: Returns: HTML div with $content
4258: To be included in page header
4259:
4260: =cut
4261:
4262: sub head_subbox {
4263: my ($content)=@_;
4264: my $output =
1.844 bisitz 4265: '<div id="LC_head_subbox">'
1.822 bisitz 4266: .$content
4267: .'</div>'
4268: }
4269:
4270: ##############################################
4271: =pod
4272:
4273: =item * &CSTR_pageheader()
4274:
4275: Inputs: ./.
4276:
4277: Returns: HTML div with CSTR path and recent box
4278: To be included on Construction Space pages
4279:
4280: =cut
4281:
4282: sub CSTR_pageheader {
4283: # this is for resources; directories have customtitle, and crumbs
4284: # and select recent are created in lonpubdir.pm
4285: my ($uname,$thisdisfn)=
4286: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4287: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4288: $formaction=~s/\/+/\//g;
4289:
4290: my $parentpath = '';
4291: my $lastitem = '';
4292: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4293: $parentpath = $1;
4294: $lastitem = $2;
4295: } else {
4296: $lastitem = $thisdisfn;
4297: }
4298: return
4299: '<div>'
4300: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4301: .'<b>'.&mt('Construction Space:').'</b> '
4302: .'<form name="dirs" method="post" action="'.$formaction
4303: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4304: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4305: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4306: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4307: .'</form>'
4308: .&Apache::lonmenu::constspaceform()
4309: .'</div>';
4310: }
4311:
1.60 matthew 4312: ###############################################
4313: ###############################################
4314:
4315: =pod
4316:
1.112 bowersj2 4317: =back
4318:
1.549 albertel 4319: =head1 HTML Helpers
1.112 bowersj2 4320:
4321: =over 4
4322:
4323: =item * &bodytag()
1.60 matthew 4324:
4325: Returns a uniform header for LON-CAPA web pages.
4326:
4327: Inputs:
4328:
1.112 bowersj2 4329: =over 4
4330:
4331: =item * $title, A title to be displayed on the page.
4332:
4333: =item * $function, the current role (can be undef).
4334:
4335: =item * $addentries, extra parameters for the <body> tag.
4336:
4337: =item * $bodyonly, if defined, only return the <body> tag.
4338:
4339: =item * $domain, if defined, force a given domain.
4340:
4341: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4342: text interface only)
1.60 matthew 4343:
1.814 bisitz 4344: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4345: navigational links
1.317 albertel 4346:
1.338 albertel 4347: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4348:
1.361 albertel 4349: =item * $no_inline_link, if true and in remote mode, don't show the
4350: 'Switch To Inline Menu' link
4351:
1.460 albertel 4352: =item * $args, optional argument valid values are
4353: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4354: inherit_jsmath -> when creating popup window in a page,
4355: should it have jsmath forced on by the
4356: current page
1.460 albertel 4357:
1.112 bowersj2 4358: =back
4359:
1.60 matthew 4360: Returns: A uniform header for LON-CAPA web pages.
4361: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4362: If $bodyonly is undef or zero, an html string containing a <body> tag and
4363: other decorations will be returned.
4364:
4365: =cut
4366:
1.54 www 4367: sub bodytag {
1.831 bisitz 4368: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4369: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4370:
1.460 albertel 4371: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4372:
1.183 matthew 4373: $function = &get_users_function() if (!$function);
1.339 albertel 4374: my $img = &designparm($function.'.img',$domain);
4375: my $font = &designparm($function.'.font',$domain);
4376: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4377:
1.803 bisitz 4378: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4379: 'bgcolor' => $pgbg,
1.339 albertel 4380: 'text' => $font,
4381: 'alink' => &designparm($function.'.alink',$domain),
4382: 'vlink' => &designparm($function.'.vlink',$domain),
4383: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4384: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4385:
1.63 www 4386: # role and realm
1.378 raeburn 4387: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4388: if ($role eq 'ca') {
1.479 albertel 4389: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4390: $realm = &plainname($rname,$rdom);
1.378 raeburn 4391: }
1.55 www 4392: # realm
1.258 albertel 4393: if ($env{'request.course.id'}) {
1.378 raeburn 4394: if ($env{'request.role'} !~ /^cr/) {
4395: $role = &Apache::lonnet::plaintext($role,&course_type());
4396: }
1.359 albertel 4397: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4398: } else {
4399: $role = &Apache::lonnet::plaintext($role);
1.54 www 4400: }
1.433 albertel 4401:
1.359 albertel 4402: if (!$realm) { $realm=' '; }
1.55 www 4403: # Set messages
1.60 matthew 4404: my $messages=&domainlogo($domain);
1.330 albertel 4405:
1.438 albertel 4406: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4407:
1.101 www 4408: # construct main body tag
1.359 albertel 4409: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4410: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4411:
1.530 albertel 4412: if ($bodyonly) {
1.60 matthew 4413: return $bodytag;
1.798 tempelho 4414: }
1.359 albertel 4415:
1.410 albertel 4416: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4417: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4418: undef($role);
1.434 albertel 4419: } else {
4420: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4421: }
1.359 albertel 4422:
1.762 bisitz 4423: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4424: #
4425: # Extra info if you are the DC
4426: my $dc_info = '';
4427: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4428: $env{'course.'.$env{'request.course.id'}.
4429: '.domain'}.'/'})) {
4430: my $cid = $env{'request.course.id'};
4431: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4432: $dc_info =~ s/\s+$//;
1.359 albertel 4433: $dc_info = '('.$dc_info.')';
4434: }
4435:
1.853 droeschl 4436: $role = "($role)" if $role;
4437: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4438:
1.837 bisitz 4439: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4440: # No Remote
1.258 albertel 4441: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4442: $forcereg=1;
4443: }
4444:
1.836 bisitz 4445: # if ($env{'request.state'} eq 'construct') {
4446: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4447: # }
1.359 albertel 4448:
1.816 bisitz 4449: my $titletable = '<table id="LC_title_bar">'
1.836 bisitz 4450: ."<tr><td> $titleinfo $dc_info</td>"
1.816 bisitz 4451: .'</tr></table>';
4452:
1.814 bisitz 4453: if ($no_nav_bar) {
1.359 albertel 4454: $bodytag .= $titletable;
4455: } else {
1.852 droeschl 4456: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4457: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4458:
1.359 albertel 4459: if ($env{'request.state'} eq 'construct') {
1.863 droeschl 4460: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
1.272 raeburn 4461: } else {
1.863 droeschl 4462: $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
1.272 raeburn 4463: }
1.235 raeburn 4464: }
4465: return $bodytag;
1.94 www 4466: }
1.95 www 4467:
1.93 www 4468: #
1.95 www 4469: # Top frame rendering, Remote is up
1.93 www 4470: #
1.359 albertel 4471:
1.517 raeburn 4472: my $imgsrc = $img;
4473: if ($img =~ /^\/adm/) {
1.575 albertel 4474: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4475: }
4476: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4477:
1.305 www 4478: # Explicit link to get inline menu
1.361 albertel 4479: my $menu= ($no_inline_link?''
1.853 droeschl 4480: :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4481: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4482: <em>$realm</em> $dc_info </div>
4483: <ol class="LC_smallMenu LC_right">
4484: <li>$menu</li>
4485: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4486: #
1.94 www 4487: return(<<ENDBODY);
1.60 matthew 4488: $bodytag
1.359 albertel 4489: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4490: <tr><td>$upperleft</td>
4491: <td>$messages </td>
1.54 www 4492: </tr>
1.359 albertel 4493: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4494: </tr>
1.356 albertel 4495: </table>
1.54 www 4496: ENDBODY
1.182 matthew 4497: }
4498:
1.330 albertel 4499: sub make_attr_string {
4500: my ($register,$attr_ref) = @_;
4501:
4502: if ($attr_ref && !ref($attr_ref)) {
4503: die("addentries Must be a hash ref ".
4504: join(':',caller(1))." ".
4505: join(':',caller(0))." ");
4506: }
4507:
4508: if ($register) {
1.339 albertel 4509: my ($on_load,$on_unload);
4510: foreach my $key (keys(%{$attr_ref})) {
4511: if (lc($key) eq 'onload') {
4512: $on_load.=$attr_ref->{$key}.';';
4513: delete($attr_ref->{$key});
4514:
4515: } elsif (lc($key) eq 'onunload') {
4516: $on_unload.=$attr_ref->{$key}.';';
4517: delete($attr_ref->{$key});
4518: }
4519: }
4520: $attr_ref->{'onload'} =
4521: &Apache::lonmenu::loadevents(). $on_load;
4522: $attr_ref->{'onunload'}=
4523: &Apache::lonmenu::unloadevents().$on_unload;
4524: }
4525:
4526: # Accessibility font enhance
4527: if ($env{'browser.fontenhance'} eq 'on') {
4528: my $style;
4529: foreach my $key (keys(%{$attr_ref})) {
4530: if (lc($key) eq 'style') {
4531: $style.=$attr_ref->{$key}.';';
4532: delete($attr_ref->{$key});
4533: }
4534: }
4535: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4536: }
1.339 albertel 4537:
1.330 albertel 4538: my $attr_string;
4539: foreach my $attr (keys(%$attr_ref)) {
4540: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4541: }
4542: return $attr_string;
4543: }
4544:
4545:
1.182 matthew 4546: ###############################################
1.251 albertel 4547: ###############################################
4548:
4549: =pod
4550:
4551: =item * &endbodytag()
4552:
4553: Returns a uniform footer for LON-CAPA web pages.
4554:
1.635 raeburn 4555: Inputs: 1 - optional reference to an args hash
4556: If in the hash, key for noredirectlink has a value which evaluates to true,
4557: a 'Continue' link is not displayed if the page contains an
4558: internal redirect in the <head></head> section,
4559: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4560:
4561: =cut
4562:
4563: sub endbodytag {
1.635 raeburn 4564: my ($args) = @_;
1.251 albertel 4565: my $endbodytag='</body>';
1.269 albertel 4566: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4567: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4568: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4569: $endbodytag=
4570: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4571: &mt('Continue').'</a>'.
4572: $endbodytag;
4573: }
1.315 albertel 4574: }
1.251 albertel 4575: return $endbodytag;
4576: }
4577:
1.352 albertel 4578: =pod
4579:
4580: =item * &standard_css()
4581:
4582: Returns a style sheet
4583:
4584: Inputs: (all optional)
4585: domain -> force to color decorate a page for a specific
4586: domain
4587: function -> force usage of a specific rolish color scheme
4588: bgcolor -> override the default page bgcolor
4589:
4590: =cut
4591:
1.343 albertel 4592: sub standard_css {
1.345 albertel 4593: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4594: $function = &get_users_function() if (!$function);
4595: my $img = &designparm($function.'.img', $domain);
4596: my $tabbg = &designparm($function.'.tabbg', $domain);
4597: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4598: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4599: #second colour for later usage
1.345 albertel 4600: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4601: my $pgbg_or_bgcolor =
4602: $bgcolor ||
1.352 albertel 4603: &designparm($function.'.pgbg', $domain);
1.382 albertel 4604: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4605: my $alink = &designparm($function.'.alink', $domain);
4606: my $vlink = &designparm($function.'.vlink', $domain);
4607: my $link = &designparm($function.'.link', $domain);
4608:
1.704 muellerd 4609: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4610: my $bgcol = &designparm('login.bgcol',$domain);
4611: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4612:
1.602 albertel 4613: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4614: my $mono = 'monospace';
1.850 bisitz 4615: my $data_table_head = $sidebg;
4616: my $data_table_light = '#FAFAFA';
4617: my $data_table_dark = '#F0F0F0';
1.470 banghart 4618: my $data_table_darker = '#CCCCCC';
1.349 albertel 4619: my $data_table_highlight = '#FFFF00';
1.352 albertel 4620: my $mail_new = '#FFBB77';
4621: my $mail_new_hover = '#DD9955';
4622: my $mail_read = '#BBBB77';
4623: my $mail_read_hover = '#999944';
4624: my $mail_replied = '#AAAA88';
4625: my $mail_replied_hover = '#888855';
4626: my $mail_other = '#99BBBB';
4627: my $mail_other_hover = '#669999';
1.391 albertel 4628: my $table_header = '#DDDDDD';
1.489 raeburn 4629: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4630: my $lg_border_color = '#C8C8C8';
1.392 albertel 4631:
1.608 albertel 4632: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4633: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4634: : '0 3px 0 4px';
1.448 albertel 4635:
1.523 albertel 4636:
1.343 albertel 4637: return <<END;
1.795 www 4638: body {
4639: font-family: $sans;
4640: line-height:130%;
4641: font-size:0.83em;
4642: color:$font;
4643: }
4644:
4645: a:link, a:visited {
4646: font-size:100%;
4647: }
4648:
4649: a:focus {
4650: color: red;
4651: background: yellow
4652: }
1.698 harmsja 4653:
1.846 bisitz 4654: hr {
4655: clear: both;
4656: color: $tabbg;
4657: background-color: $tabbg;
4658: height: 3px;
4659: border: none;
4660: }
4661:
1.795 www 4662: form, .inline {
4663: display: inline;
4664: }
1.721 harmsja 4665:
1.795 www 4666: .LC_right {
4667: text-align:right;
4668: }
4669:
4670: .LC_middle {
4671: vertical-align:middle;
4672: }
1.721 harmsja 4673:
4674: /* just for tests */
1.754 droeschl 4675: .LC_400Box {width:400px; }
1.721 harmsja 4676: /* end */
4677:
1.778 bisitz 4678: .LC_filename {
4679: font-family: $mono;
4680: white-space:pre;
4681: }
4682:
4683: .LC_fileicon {
4684: border: none;
4685: height: 1.3em;
4686: vertical-align: text-bottom;
4687: margin-right: 0.3em;
4688: text-decoration:none;
4689: }
4690:
1.350 albertel 4691: .LC_error {
4692: color: red;
4693: font-size: larger;
4694: }
1.795 www 4695:
1.457 albertel 4696: .LC_warning,
4697: .LC_diff_removed {
1.733 bisitz 4698: color: red;
1.394 albertel 4699: }
1.532 albertel 4700:
4701: .LC_info,
1.457 albertel 4702: .LC_success,
4703: .LC_diff_added {
1.350 albertel 4704: color: green;
4705: }
1.795 www 4706:
1.802 bisitz 4707: div.LC_confirm_box {
4708: background-color: #FAFAFA;
4709: border: 1px solid $lg_border_color;
4710: margin-right: 0;
4711: padding: 5px;
4712: }
4713:
4714: div.LC_confirm_box .LC_error img,
4715: div.LC_confirm_box .LC_success img {
4716: vertical-align: middle;
4717: }
4718:
1.440 albertel 4719: .LC_icon {
1.771 droeschl 4720: border: none;
1.790 droeschl 4721: vertical-align: middle;
1.771 droeschl 4722: }
4723:
1.543 albertel 4724: .LC_docs_spacer {
4725: width: 25px;
4726: height: 1px;
1.771 droeschl 4727: border: none;
1.543 albertel 4728: }
1.346 albertel 4729:
1.532 albertel 4730: .LC_internal_info {
1.735 bisitz 4731: color: #999999;
1.532 albertel 4732: }
4733:
1.794 www 4734: .LC_discussion {
4735: background: $tabbg;
4736: border: 1px solid black;
4737: margin: 2px;
4738: }
4739:
4740: .LC_disc_action_links_bar {
4741: background: $tabbg;
1.803 bisitz 4742: border: none;
1.795 www 4743: margin: 4px;
1.794 www 4744: }
4745:
4746: .LC_disc_action_left {
4747: text-align: left;
4748: }
4749:
4750: .LC_disc_action_right {
4751: text-align: right;
4752: }
4753:
4754: .LC_disc_new_item {
4755: background: white;
4756: border: 2px solid red;
4757: margin: 2px;
4758: }
4759:
4760: .LC_disc_old_item {
4761: background: white;
4762: border: 1px solid black;
4763: margin: 2px;
4764: }
4765:
1.458 albertel 4766: table.LC_pastsubmission {
4767: border: 1px solid black;
4768: margin: 2px;
4769: }
4770:
1.795 www 4771: table#LC_top_nav,
4772: table#LC_menubuttons,
4773: table#LC_nav_location {
1.345 albertel 4774: width: 100%;
4775: background: $pgbg;
1.392 albertel 4776: border: 2px;
1.402 albertel 4777: border-collapse: separate;
1.803 bisitz 4778: padding: 0;
1.345 albertel 4779: }
1.392 albertel 4780:
1.801 tempelho 4781: table#LC_title_bar a {
4782: color: $fontmenu;
4783: }
1.836 bisitz 4784:
1.807 droeschl 4785: table#LC_title_bar {
1.819 tempelho 4786: clear: both;
1.836 bisitz 4787: display: none;
1.807 droeschl 4788: }
4789:
1.795 www 4790: table#LC_title_bar,
4791: table.LC_breadcrumbs,
1.393 albertel 4792: table#LC_title_bar.LC_with_remote {
1.359 albertel 4793: width: 100%;
1.392 albertel 4794: border-color: $pgbg;
4795: border-style: solid;
4796: border-width: $border;
1.379 albertel 4797: background: $pgbg;
1.801 tempelho 4798: color: $fontmenu;
1.392 albertel 4799: border-collapse: collapse;
1.803 bisitz 4800: padding: 0;
1.819 tempelho 4801: margin: 0;
1.359 albertel 4802: }
1.795 www 4803:
1.359 albertel 4804: table#LC_title_bar td {
4805: background: $tabbg;
4806: }
1.795 www 4807:
1.706 harmsja 4808: table#LC_menubuttons img{
1.803 bisitz 4809: border: none;
1.346 albertel 4810: }
1.795 www 4811:
1.345 albertel 4812: table#LC_top_nav td {
4813: background: $tabbg;
1.803 bisitz 4814: border: none;
1.407 albertel 4815: font-size: small;
1.706 harmsja 4816: vertical-align:top;
4817: padding:2px 5px 2px 5px;
1.345 albertel 4818: }
1.795 www 4819:
4820: table#LC_top_nav td a,
4821: div#LC_top_nav a {
1.345 albertel 4822: color: $font;
4823: }
1.795 www 4824:
1.364 albertel 4825: table#LC_top_nav td.LC_top_nav_logo {
4826: background: $tabbg;
1.432 albertel 4827: text-align: left;
1.408 albertel 4828: white-space: nowrap;
1.432 albertel 4829: width: 31px;
1.408 albertel 4830: }
1.795 www 4831:
1.408 albertel 4832: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4833: border: none;
1.408 albertel 4834: vertical-align: bottom;
1.364 albertel 4835: }
1.795 www 4836:
1.777 tempelho 4837: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4838: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4839: width: 2.0em;
4840: }
1.795 www 4841:
1.442 albertel 4842: table#LC_top_nav td.LC_top_nav_login {
4843: width: 4.0em;
4844: text-align: center;
4845: }
1.795 www 4846:
1.842 droeschl 4847: .LC_breadcrumbs_component {
4848: float: right;
4849: margin: 0 1em;
1.357 albertel 4850: }
1.842 droeschl 4851: .LC_breadcrumbs_component img {
4852: vertical-align: middle;
1.777 tempelho 4853: }
1.795 www 4854:
1.383 albertel 4855: td.LC_table_cell_checkbox {
4856: text-align: center;
4857: }
1.795 www 4858:
1.779 bisitz 4859: table#LC_mainmenu td.LC_mainmenu_column {
4860: vertical-align: top;
1.777 tempelho 4861: }
1.522 albertel 4862:
1.795 www 4863: .LC_fontsize_small {
1.705 tempelho 4864: font-size: 70%;
4865: }
4866:
1.844 bisitz 4867: #LC_breadcrumbs {
1.819 tempelho 4868: clear:both;
4869: background: $sidebg;
1.822 bisitz 4870: border-bottom: 1px solid $lg_border_color;
1.819 tempelho 4871: line-height: 32px;
1.822 bisitz 4872: margin: 0;
1.819 tempelho 4873: padding: 0;
4874: }
1.862 bisitz 4875:
1.839 droeschl 4876: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4877: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4878: display:none;
4879: }
1.819 tempelho 4880:
1.844 bisitz 4881: #LC_head_subbox {
1.822 bisitz 4882: clear:both;
4883: background: #F8F8F8; /* $sidebg; */
4884: border-bottom: 1px solid $lg_border_color;
4885: margin: 0 0 10px 0;
4886: padding: 5px;
4887: }
4888:
1.795 www 4889: .LC_fontsize_medium {
1.705 tempelho 4890: font-size: 85%;
4891: }
4892:
1.795 www 4893: .LC_fontsize_large {
1.705 tempelho 4894: font-size: 120%;
4895: }
4896:
1.346 albertel 4897: .LC_menubuttons_inline_text {
4898: color: $font;
1.698 harmsja 4899: font-size: 90%;
1.701 harmsja 4900: padding-left:3px;
1.346 albertel 4901: }
4902:
1.526 www 4903: .LC_menubuttons_link {
4904: text-decoration: none;
4905: }
1.795 www 4906:
1.522 albertel 4907: .LC_menubuttons_category {
1.521 www 4908: color: $font;
1.526 www 4909: background: $pgbg;
1.521 www 4910: font-size: larger;
4911: font-weight: bold;
4912: }
4913:
1.346 albertel 4914: td.LC_menubuttons_text {
1.779 bisitz 4915: color: $font;
1.346 albertel 4916: }
1.706 harmsja 4917:
1.346 albertel 4918: .LC_current_location {
4919: background: $tabbg;
4920: }
1.795 www 4921:
1.346 albertel 4922: .LC_new_mail {
1.634 www 4923: background: $tabbg;
1.346 albertel 4924: font-weight: bold;
4925: }
1.347 albertel 4926:
1.666 raeburn 4927: .LC_roleslog_note {
1.701 harmsja 4928: font-size: small;
1.666 raeburn 4929: }
4930:
1.795 www 4931: table.LC_data_table,
4932: table.LC_mail_list {
1.347 albertel 4933: border: 1px solid #000000;
1.402 albertel 4934: border-collapse: separate;
1.426 albertel 4935: border-spacing: 1px;
1.610 albertel 4936: background: $pgbg;
1.347 albertel 4937: }
1.795 www 4938:
1.422 albertel 4939: .LC_data_table_dense {
4940: font-size: small;
4941: }
1.795 www 4942:
1.507 raeburn 4943: table.LC_nested_outer {
4944: border: 1px solid #000000;
1.589 raeburn 4945: border-collapse: collapse;
1.803 bisitz 4946: border-spacing: 0;
1.507 raeburn 4947: width: 100%;
4948: }
1.795 www 4949:
1.507 raeburn 4950: table.LC_nested {
1.803 bisitz 4951: border: none;
1.589 raeburn 4952: border-collapse: collapse;
1.803 bisitz 4953: border-spacing: 0;
1.507 raeburn 4954: width: 100%;
4955: }
1.795 www 4956:
4957: table.LC_data_table tr th,
4958: table.LC_calendar tr th,
4959: table.LC_mail_list tr th,
1.523 albertel 4960: table.LC_prior_tries tr th {
1.349 albertel 4961: font-weight: bold;
4962: background-color: $data_table_head;
1.801 tempelho 4963: color:$fontmenu;
1.701 harmsja 4964: font-size:90%;
1.347 albertel 4965: }
1.795 www 4966:
1.711 raeburn 4967: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4968: background-color: #CCCCCC;
1.711 raeburn 4969: font-weight: bold;
4970: text-align: left;
4971: }
1.795 www 4972:
1.779 bisitz 4973: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4974: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4975: background-color: $data_table_light;
1.425 albertel 4976: padding: 2px;
1.347 albertel 4977: }
1.795 www 4978:
1.610 albertel 4979: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4980: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4981: background-color: $data_table_dark;
1.709 bisitz 4982: padding: 2px;
1.347 albertel 4983: }
1.795 www 4984:
1.425 albertel 4985: table.LC_data_table tr.LC_data_table_highlight td {
4986: background-color: $data_table_darker;
4987: }
1.795 www 4988:
1.639 raeburn 4989: table.LC_data_table tr td.LC_leftcol_header {
4990: background-color: $data_table_head;
4991: font-weight: bold;
4992: }
1.795 www 4993:
1.451 albertel 4994: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4995: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4996: background-color: #FFFFFF;
1.421 albertel 4997: font-weight: bold;
4998: font-style: italic;
4999: text-align: center;
5000: padding: 8px;
1.347 albertel 5001: }
1.795 www 5002:
1.507 raeburn 5003: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5004: padding: 4ex
5005: }
1.795 www 5006:
1.507 raeburn 5007: table.LC_nested_outer tr th {
5008: font-weight: bold;
1.801 tempelho 5009: color:$fontmenu;
1.507 raeburn 5010: background-color: $data_table_head;
1.701 harmsja 5011: font-size: small;
1.507 raeburn 5012: border-bottom: 1px solid #000000;
5013: }
1.795 www 5014:
1.507 raeburn 5015: table.LC_nested_outer tr td.LC_subheader {
5016: background-color: $data_table_head;
5017: font-weight: bold;
5018: font-size: small;
5019: border-bottom: 1px solid #000000;
5020: text-align: right;
1.451 albertel 5021: }
1.795 www 5022:
1.507 raeburn 5023: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5024: background-color: #CCCCCC;
1.451 albertel 5025: font-weight: bold;
5026: font-size: small;
1.507 raeburn 5027: text-align: center;
5028: }
1.795 www 5029:
1.589 raeburn 5030: table.LC_nested tr.LC_info_row td.LC_left_item,
5031: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5032: text-align: left;
1.451 albertel 5033: }
1.795 www 5034:
1.507 raeburn 5035: table.LC_nested td {
1.735 bisitz 5036: background-color: #FFFFFF;
1.451 albertel 5037: font-size: small;
1.507 raeburn 5038: }
1.795 www 5039:
1.507 raeburn 5040: table.LC_nested_outer tr th.LC_right_item,
5041: table.LC_nested tr.LC_info_row td.LC_right_item,
5042: table.LC_nested tr.LC_odd_row td.LC_right_item,
5043: table.LC_nested tr td.LC_right_item {
1.451 albertel 5044: text-align: right;
5045: }
5046:
1.507 raeburn 5047: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5048: background-color: #EEEEEE;
1.451 albertel 5049: }
5050:
1.473 raeburn 5051: table.LC_createuser {
5052: }
5053:
5054: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5055: font-size: small;
1.473 raeburn 5056: }
5057:
5058: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5059: background-color: #CCCCCC;
1.473 raeburn 5060: font-weight: bold;
5061: text-align: center;
5062: }
5063:
1.349 albertel 5064: table.LC_calendar {
5065: border: 1px solid #000000;
5066: border-collapse: collapse;
5067: }
1.795 www 5068:
1.349 albertel 5069: table.LC_calendar_pickdate {
5070: font-size: xx-small;
5071: }
1.795 www 5072:
1.349 albertel 5073: table.LC_calendar tr td {
5074: border: 1px solid #000000;
5075: vertical-align: top;
5076: }
1.795 www 5077:
1.349 albertel 5078: table.LC_calendar tr td.LC_calendar_day_empty {
5079: background-color: $data_table_dark;
5080: }
1.795 www 5081:
1.779 bisitz 5082: table.LC_calendar tr td.LC_calendar_day_current {
5083: background-color: $data_table_highlight;
1.777 tempelho 5084: }
1.795 www 5085:
1.349 albertel 5086: table.LC_mail_list tr.LC_mail_new {
5087: background-color: $mail_new;
5088: }
1.795 www 5089:
1.349 albertel 5090: table.LC_mail_list tr.LC_mail_new:hover {
5091: background-color: $mail_new_hover;
5092: }
1.795 www 5093:
5094: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5095: }
1.795 www 5096:
5097: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5098: }
1.795 www 5099:
1.349 albertel 5100: table.LC_mail_list tr.LC_mail_read {
5101: background-color: $mail_read;
5102: }
1.795 www 5103:
1.349 albertel 5104: table.LC_mail_list tr.LC_mail_read:hover {
5105: background-color: $mail_read_hover;
5106: }
1.795 www 5107:
1.349 albertel 5108: table.LC_mail_list tr.LC_mail_replied {
5109: background-color: $mail_replied;
5110: }
1.795 www 5111:
1.349 albertel 5112: table.LC_mail_list tr.LC_mail_replied:hover {
5113: background-color: $mail_replied_hover;
5114: }
1.795 www 5115:
1.349 albertel 5116: table.LC_mail_list tr.LC_mail_other {
5117: background-color: $mail_other;
5118: }
1.795 www 5119:
1.349 albertel 5120: table.LC_mail_list tr.LC_mail_other:hover {
5121: background-color: $mail_other_hover;
5122: }
1.494 raeburn 5123:
1.777 tempelho 5124: table.LC_data_table tr > td.LC_browser_file,
5125: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5126: background: #CCFF88;
5127: }
1.795 www 5128:
1.777 tempelho 5129: table.LC_data_table tr > td.LC_browser_file_locked,
5130: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5131: background: #FFAA99;
1.387 albertel 5132: }
1.795 www 5133:
1.777 tempelho 5134: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5135: background: #AAAAAA;
5136: }
1.795 www 5137:
1.777 tempelho 5138: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5139: table.LC_data_table tr > td.LC_browser_file_metamodified {
5140: background: #FFFF77;
1.777 tempelho 5141: }
1.795 www 5142:
1.696 bisitz 5143: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5144: background: #CCCCFF;
1.387 albertel 5145: }
1.696 bisitz 5146:
1.707 bisitz 5147: table.LC_data_table tr > td.LC_roles_is {
5148: /* background: #77FF77; */
5149: }
1.795 www 5150:
1.707 bisitz 5151: table.LC_data_table tr > td.LC_roles_future {
5152: background: #FFFF77;
5153: }
1.795 www 5154:
1.707 bisitz 5155: table.LC_data_table tr > td.LC_roles_will {
5156: background: #FFAA77;
5157: }
1.795 www 5158:
1.707 bisitz 5159: table.LC_data_table tr > td.LC_roles_expired {
5160: background: #FF7777;
5161: }
1.795 www 5162:
1.707 bisitz 5163: table.LC_data_table tr > td.LC_roles_will_not {
5164: background: #AAFF77;
5165: }
1.795 www 5166:
1.707 bisitz 5167: table.LC_data_table tr > td.LC_roles_selected {
5168: background: #11CC55;
5169: }
5170:
1.388 albertel 5171: span.LC_current_location {
1.701 harmsja 5172: font-size:larger;
1.388 albertel 5173: background: $pgbg;
5174: }
1.387 albertel 5175:
1.395 albertel 5176: span.LC_parm_menu_item {
5177: font-size: larger;
5178: }
1.795 www 5179:
1.395 albertel 5180: span.LC_parm_scope_all {
5181: color: red;
5182: }
1.795 www 5183:
1.395 albertel 5184: span.LC_parm_scope_folder {
5185: color: green;
5186: }
1.795 www 5187:
1.395 albertel 5188: span.LC_parm_scope_resource {
5189: color: orange;
5190: }
1.795 www 5191:
1.395 albertel 5192: span.LC_parm_part {
5193: color: blue;
5194: }
1.795 www 5195:
1.395 albertel 5196: span.LC_parm_folder, span.LC_parm_symb {
5197: font-size: x-small;
5198: font-family: $mono;
5199: color: #AAAAAA;
5200: }
5201:
1.795 www 5202: td.LC_parm_overview_level_menu,
5203: td.LC_parm_overview_map_menu,
5204: td.LC_parm_overview_parm_selectors,
5205: td.LC_parm_overview_restrictions {
1.396 albertel 5206: border: 1px solid black;
5207: border-collapse: collapse;
5208: }
1.795 www 5209:
1.396 albertel 5210: table.LC_parm_overview_restrictions td {
5211: border-width: 1px 4px 1px 4px;
5212: border-style: solid;
5213: border-color: $pgbg;
5214: text-align: center;
5215: }
1.795 www 5216:
1.396 albertel 5217: table.LC_parm_overview_restrictions th {
5218: background: $tabbg;
5219: border-width: 1px 4px 1px 4px;
5220: border-style: solid;
5221: border-color: $pgbg;
5222: }
1.795 www 5223:
1.398 albertel 5224: table#LC_helpmenu {
1.803 bisitz 5225: border: none;
1.398 albertel 5226: height: 55px;
1.803 bisitz 5227: border-spacing: 0;
1.398 albertel 5228: }
5229:
5230: table#LC_helpmenu fieldset legend {
5231: font-size: larger;
5232: }
1.795 www 5233:
1.397 albertel 5234: table#LC_helpmenu_links {
5235: width: 100%;
5236: border: 1px solid black;
5237: background: $pgbg;
1.803 bisitz 5238: padding: 0;
1.397 albertel 5239: border-spacing: 1px;
5240: }
1.795 www 5241:
1.397 albertel 5242: table#LC_helpmenu_links tr td {
5243: padding: 1px;
5244: background: $tabbg;
1.399 albertel 5245: text-align: center;
5246: font-weight: bold;
1.397 albertel 5247: }
1.396 albertel 5248:
1.795 www 5249: table#LC_helpmenu_links a:link,
5250: table#LC_helpmenu_links a:visited,
1.397 albertel 5251: table#LC_helpmenu_links a:active {
5252: text-decoration: none;
5253: color: $font;
5254: }
1.795 www 5255:
1.397 albertel 5256: table#LC_helpmenu_links a:hover {
5257: text-decoration: underline;
5258: color: $vlink;
5259: }
1.396 albertel 5260:
1.417 albertel 5261: .LC_chrt_popup_exists {
5262: border: 1px solid #339933;
5263: margin: -1px;
5264: }
1.795 www 5265:
1.417 albertel 5266: .LC_chrt_popup_up {
5267: border: 1px solid yellow;
5268: margin: -1px;
5269: }
1.795 www 5270:
1.417 albertel 5271: .LC_chrt_popup {
5272: border: 1px solid #8888FF;
5273: background: #CCCCFF;
5274: }
1.795 www 5275:
1.421 albertel 5276: table.LC_pick_box {
5277: border-collapse: separate;
5278: background: white;
5279: border: 1px solid black;
5280: border-spacing: 1px;
5281: }
1.795 www 5282:
1.421 albertel 5283: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5284: background: $sidebg;
1.421 albertel 5285: font-weight: bold;
5286: text-align: right;
1.740 bisitz 5287: vertical-align: top;
1.421 albertel 5288: width: 184px;
5289: padding: 8px;
5290: }
1.795 www 5291:
1.579 raeburn 5292: table.LC_pick_box td.LC_pick_box_value {
5293: text-align: left;
5294: padding: 8px;
5295: }
1.795 www 5296:
1.579 raeburn 5297: table.LC_pick_box td.LC_pick_box_select {
5298: text-align: left;
5299: padding: 8px;
5300: }
1.795 www 5301:
1.424 albertel 5302: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5303: padding: 0;
1.421 albertel 5304: height: 1px;
5305: background: black;
5306: }
1.795 www 5307:
1.421 albertel 5308: table.LC_pick_box td.LC_pick_box_submit {
5309: text-align: right;
5310: }
1.795 www 5311:
1.579 raeburn 5312: table.LC_pick_box td.LC_evenrow_value {
5313: text-align: left;
5314: padding: 8px;
5315: background-color: $data_table_light;
5316: }
1.795 www 5317:
1.579 raeburn 5318: table.LC_pick_box td.LC_oddrow_value {
5319: text-align: left;
5320: padding: 8px;
5321: background-color: $data_table_light;
5322: }
1.795 www 5323:
1.579 raeburn 5324: table.LC_helpform_receipt {
5325: width: 620px;
5326: border-collapse: separate;
5327: background: white;
5328: border: 1px solid black;
5329: border-spacing: 1px;
5330: }
1.795 www 5331:
1.579 raeburn 5332: table.LC_helpform_receipt td.LC_pick_box_title {
5333: background: $tabbg;
5334: font-weight: bold;
5335: text-align: right;
5336: width: 184px;
5337: padding: 8px;
5338: }
1.795 www 5339:
1.579 raeburn 5340: table.LC_helpform_receipt td.LC_evenrow_value {
5341: text-align: left;
5342: padding: 8px;
5343: background-color: $data_table_light;
5344: }
1.795 www 5345:
1.579 raeburn 5346: table.LC_helpform_receipt td.LC_oddrow_value {
5347: text-align: left;
5348: padding: 8px;
5349: background-color: $data_table_light;
5350: }
1.795 www 5351:
1.579 raeburn 5352: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5353: padding: 0;
1.579 raeburn 5354: height: 1px;
5355: background: black;
5356: }
1.795 www 5357:
1.579 raeburn 5358: span.LC_helpform_receipt_cat {
5359: font-weight: bold;
5360: }
1.795 www 5361:
1.424 albertel 5362: table.LC_group_priv_box {
5363: background: white;
5364: border: 1px solid black;
5365: border-spacing: 1px;
5366: }
1.795 www 5367:
1.424 albertel 5368: table.LC_group_priv_box td.LC_pick_box_title {
5369: background: $tabbg;
5370: font-weight: bold;
5371: text-align: right;
5372: width: 184px;
5373: }
1.795 www 5374:
1.424 albertel 5375: table.LC_group_priv_box td.LC_groups_fixed {
5376: background: $data_table_light;
5377: text-align: center;
5378: }
1.795 www 5379:
1.424 albertel 5380: table.LC_group_priv_box td.LC_groups_optional {
5381: background: $data_table_dark;
5382: text-align: center;
5383: }
1.795 www 5384:
1.424 albertel 5385: table.LC_group_priv_box td.LC_groups_functionality {
5386: background: $data_table_darker;
5387: text-align: center;
5388: font-weight: bold;
5389: }
1.795 www 5390:
1.424 albertel 5391: table.LC_group_priv td {
5392: text-align: left;
1.803 bisitz 5393: padding: 0;
1.424 albertel 5394: }
5395:
1.421 albertel 5396: table.LC_notify_front_page {
5397: background: white;
5398: border: 1px solid black;
5399: padding: 8px;
5400: }
1.795 www 5401:
1.421 albertel 5402: table.LC_notify_front_page td {
5403: padding: 8px;
5404: }
1.795 www 5405:
1.424 albertel 5406: .LC_navbuttons {
5407: margin: 2ex 0ex 2ex 0ex;
5408: }
1.795 www 5409:
1.423 albertel 5410: .LC_topic_bar {
5411: font-weight: bold;
5412: width: 100%;
5413: background: $tabbg;
5414: vertical-align: middle;
5415: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5416: padding: 3px;
1.423 albertel 5417: }
1.795 www 5418:
1.423 albertel 5419: .LC_topic_bar span {
5420: vertical-align: middle;
5421: }
1.795 www 5422:
1.423 albertel 5423: .LC_topic_bar img {
5424: vertical-align: bottom;
5425: }
1.795 www 5426:
1.423 albertel 5427: table.LC_course_group_status {
5428: margin: 20px;
5429: }
1.795 www 5430:
1.423 albertel 5431: table.LC_status_selector td {
5432: vertical-align: top;
5433: text-align: center;
1.424 albertel 5434: padding: 4px;
5435: }
1.795 www 5436:
1.599 albertel 5437: div.LC_feedback_link {
1.616 albertel 5438: clear: both;
1.829 kalberla 5439: background: $sidebg;
1.779 bisitz 5440: width: 100%;
1.829 kalberla 5441: padding-bottom: 10px;
5442: border: 1px $tabbg solid;
1.833 kalberla 5443: height: 22px;
5444: line-height: 22px;
5445: padding-top: 5px;
5446: }
5447:
5448: div.LC_feedback_link img {
5449: height: 22px;
1.829 kalberla 5450: }
5451:
5452: div.LC_feedback_link a{
5453: text-decoration: none;
1.489 raeburn 5454: }
1.795 www 5455:
1.489 raeburn 5456: span.LC_feedback_link {
1.858 bisitz 5457: /* background: $feedback_link_bg; */
1.599 albertel 5458: font-size: larger;
5459: }
1.795 www 5460:
1.599 albertel 5461: span.LC_message_link {
1.858 bisitz 5462: /* background: $feedback_link_bg; */
1.599 albertel 5463: font-size: larger;
5464: position: absolute;
5465: right: 1em;
1.489 raeburn 5466: }
1.421 albertel 5467:
1.515 albertel 5468: table.LC_prior_tries {
1.524 albertel 5469: border: 1px solid #000000;
5470: border-collapse: separate;
5471: border-spacing: 1px;
1.515 albertel 5472: }
1.523 albertel 5473:
1.515 albertel 5474: table.LC_prior_tries td {
1.524 albertel 5475: padding: 2px;
1.515 albertel 5476: }
1.523 albertel 5477:
5478: .LC_answer_correct {
1.795 www 5479: background: lightgreen;
5480: color: darkgreen;
5481: padding: 6px;
1.523 albertel 5482: }
1.795 www 5483:
1.523 albertel 5484: .LC_answer_charged_try {
1.797 www 5485: background: #FFAAAA;
1.795 www 5486: color: darkred;
5487: padding: 6px;
1.523 albertel 5488: }
1.795 www 5489:
1.779 bisitz 5490: .LC_answer_not_charged_try,
1.523 albertel 5491: .LC_answer_no_grade,
5492: .LC_answer_late {
1.795 www 5493: background: lightyellow;
1.523 albertel 5494: color: black;
1.795 www 5495: padding: 6px;
1.523 albertel 5496: }
1.795 www 5497:
1.523 albertel 5498: .LC_answer_previous {
1.795 www 5499: background: lightblue;
5500: color: darkblue;
5501: padding: 6px;
1.523 albertel 5502: }
1.795 www 5503:
1.779 bisitz 5504: .LC_answer_no_message {
1.777 tempelho 5505: background: #FFFFFF;
5506: color: black;
1.795 www 5507: padding: 6px;
1.779 bisitz 5508: }
1.795 www 5509:
1.779 bisitz 5510: .LC_answer_unknown {
5511: background: orange;
5512: color: black;
1.795 www 5513: padding: 6px;
1.777 tempelho 5514: }
1.795 www 5515:
1.529 albertel 5516: span.LC_prior_numerical,
5517: span.LC_prior_string,
5518: span.LC_prior_custom,
5519: span.LC_prior_reaction,
5520: span.LC_prior_math {
1.523 albertel 5521: font-family: monospace;
5522: white-space: pre;
5523: }
5524:
1.525 albertel 5525: span.LC_prior_string {
5526: font-family: monospace;
5527: white-space: pre;
5528: }
5529:
1.523 albertel 5530: table.LC_prior_option {
5531: width: 100%;
5532: border-collapse: collapse;
5533: }
1.795 www 5534:
5535: table.LC_prior_rank,
5536: table.LC_prior_match {
1.528 albertel 5537: border-collapse: collapse;
5538: }
1.795 www 5539:
1.528 albertel 5540: table.LC_prior_option tr td,
5541: table.LC_prior_rank tr td,
5542: table.LC_prior_match tr td {
1.524 albertel 5543: border: 1px solid #000000;
1.515 albertel 5544: }
5545:
1.855 bisitz 5546: .LC_nobreak {
1.544 albertel 5547: white-space: nowrap;
1.519 raeburn 5548: }
5549:
1.576 raeburn 5550: span.LC_cusr_emph {
5551: font-style: italic;
5552: }
5553:
1.633 raeburn 5554: span.LC_cusr_subheading {
5555: font-weight: normal;
5556: font-size: 85%;
5557: }
5558:
1.545 albertel 5559: table.LC_docs_documents {
5560: background: #BBBBBB;
1.803 bisitz 5561: border-width: 0;
1.545 albertel 5562: border-collapse: collapse;
5563: }
1.795 www 5564:
1.777 tempelho 5565: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5566: border: 2px solid black;
5567: padding: 4px;
1.777 tempelho 5568: }
1.795 www 5569:
1.861 bisitz 5570: div.LC_docs_entry_move {
1.859 bisitz 5571: border: 1px solid #BBBBBB;
1.545 albertel 5572: background: #DDDDDD;
1.861 bisitz 5573: width: 22px;
1.859 bisitz 5574: padding: 1px;
5575: margin: 0;
1.545 albertel 5576: }
5577:
1.861 bisitz 5578: table.LC_data_table tr > td.LC_docs_entry_commands,
5579: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5580: background: #DDDDDD;
5581: font-size: x-small;
5582: }
1.795 www 5583:
1.861 bisitz 5584: .LC_docs_entry_parameter {
5585: white-space: nowrap;
5586: }
5587:
1.544 albertel 5588: .LC_docs_copy {
1.545 albertel 5589: color: #000099;
1.544 albertel 5590: }
1.795 www 5591:
1.544 albertel 5592: .LC_docs_cut {
1.545 albertel 5593: color: #550044;
1.544 albertel 5594: }
1.795 www 5595:
1.544 albertel 5596: .LC_docs_rename {
1.545 albertel 5597: color: #009900;
1.544 albertel 5598: }
1.795 www 5599:
1.544 albertel 5600: .LC_docs_remove {
1.545 albertel 5601: color: #990000;
5602: }
5603:
1.547 albertel 5604: .LC_docs_reinit_warn,
5605: .LC_docs_ext_edit {
5606: font-size: x-small;
5607: }
5608:
1.545 albertel 5609: table.LC_docs_adddocs td,
5610: table.LC_docs_adddocs th {
5611: border: 1px solid #BBBBBB;
5612: padding: 4px;
5613: background: #DDDDDD;
1.543 albertel 5614: }
5615:
1.584 albertel 5616: table.LC_sty_begin {
5617: background: #BBFFBB;
5618: }
1.795 www 5619:
1.584 albertel 5620: table.LC_sty_end {
5621: background: #FFBBBB;
5622: }
5623:
1.589 raeburn 5624: table.LC_double_column {
1.803 bisitz 5625: border-width: 0;
1.589 raeburn 5626: border-collapse: collapse;
5627: width: 100%;
5628: padding: 2px;
5629: }
5630:
5631: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5632: top: 2px;
1.589 raeburn 5633: left: 2px;
5634: width: 47%;
5635: vertical-align: top;
5636: }
5637:
5638: table.LC_double_column tr td.LC_right_col {
5639: top: 2px;
1.779 bisitz 5640: right: 2px;
1.589 raeburn 5641: width: 47%;
5642: vertical-align: top;
5643: }
5644:
1.594 raeburn 5645: span.LC_role_level {
5646: font-weight: bold;
5647: }
5648:
1.591 raeburn 5649: div.LC_left_float {
5650: float: left;
5651: padding-right: 5%;
1.597 albertel 5652: padding-bottom: 4px;
1.591 raeburn 5653: }
5654:
5655: div.LC_clear_float_header {
1.597 albertel 5656: padding-bottom: 2px;
1.591 raeburn 5657: }
5658:
5659: div.LC_clear_float_footer {
1.597 albertel 5660: padding-top: 10px;
1.591 raeburn 5661: clear: both;
5662: }
5663:
1.597 albertel 5664: div.LC_grade_show_user {
5665: margin-top: 20px;
5666: border: 1px solid black;
5667: }
1.795 www 5668:
1.597 albertel 5669: div.LC_grade_user_name {
5670: background: #DDDDEE;
5671: border-bottom: 1px solid black;
1.705 tempelho 5672: font-weight: bold;
5673: font-size: large;
1.597 albertel 5674: }
1.795 www 5675:
1.597 albertel 5676: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5677: background: #DDEEDD;
5678: }
5679:
5680: div.LC_grade_show_problem,
5681: div.LC_grade_submissions,
5682: div.LC_grade_message_center,
5683: div.LC_grade_info_links,
5684: div.LC_grade_assign {
5685: margin: 5px;
5686: width: 99%;
5687: background: #FFFFFF;
5688: }
1.795 www 5689:
1.597 albertel 5690: div.LC_grade_show_problem_header,
5691: div.LC_grade_submissions_header,
5692: div.LC_grade_message_center_header,
5693: div.LC_grade_assign_header {
1.705 tempelho 5694: font-weight: bold;
5695: font-size: large;
1.597 albertel 5696: }
1.795 www 5697:
1.597 albertel 5698: div.LC_grade_show_problem_problem,
5699: div.LC_grade_submissions_body,
5700: div.LC_grade_message_center_body,
5701: div.LC_grade_assign_body {
5702: border: 1px solid black;
5703: width: 99%;
5704: background: #FFFFFF;
5705: }
1.795 www 5706:
1.598 albertel 5707: span.LC_grade_check_note {
1.705 tempelho 5708: font-weight: normal;
5709: font-size: medium;
1.598 albertel 5710: display: inline;
5711: position: absolute;
5712: right: 1em;
5713: }
1.597 albertel 5714:
1.613 albertel 5715: table.LC_scantron_action {
5716: width: 100%;
5717: }
1.795 www 5718:
1.613 albertel 5719: table.LC_scantron_action tr th {
1.698 harmsja 5720: font-weight:bold;
5721: font-style:normal;
1.613 albertel 5722: }
1.795 www 5723:
1.779 bisitz 5724: .LC_edit_problem_header,
1.614 albertel 5725: div.LC_edit_problem_footer {
1.705 tempelho 5726: font-weight: normal;
5727: font-size: medium;
1.602 albertel 5728: margin: 2px;
1.600 albertel 5729: }
1.795 www 5730:
1.600 albertel 5731: div.LC_edit_problem_header,
1.602 albertel 5732: div.LC_edit_problem_header div,
1.614 albertel 5733: div.LC_edit_problem_footer,
5734: div.LC_edit_problem_footer div,
1.602 albertel 5735: div.LC_edit_problem_editxml_header,
5736: div.LC_edit_problem_editxml_header div {
1.600 albertel 5737: margin-top: 5px;
5738: }
1.795 www 5739:
1.600 albertel 5740: div.LC_edit_problem_header_title {
1.705 tempelho 5741: font-weight: bold;
5742: font-size: larger;
1.602 albertel 5743: background: $tabbg;
5744: padding: 3px;
5745: }
1.795 www 5746:
1.602 albertel 5747: table.LC_edit_problem_header_title {
1.705 tempelho 5748: font-size: larger;
5749: font-weight: bold;
1.602 albertel 5750: width: 100%;
5751: border-color: $pgbg;
5752: border-style: solid;
5753: border-width: $border;
1.600 albertel 5754: background: $tabbg;
1.602 albertel 5755: border-collapse: collapse;
1.803 bisitz 5756: padding: 0;
1.602 albertel 5757: }
5758:
5759: div.LC_edit_problem_discards {
5760: float: left;
5761: padding-bottom: 5px;
5762: }
1.795 www 5763:
1.602 albertel 5764: div.LC_edit_problem_saves {
5765: float: right;
5766: padding-bottom: 5px;
1.600 albertel 5767: }
1.795 www 5768:
1.679 riegler 5769: img.stift{
1.803 bisitz 5770: border-width: 0;
5771: vertical-align: middle;
1.677 riegler 5772: }
1.680 riegler 5773:
1.681 riegler 5774: table#LC_mainmenu{
5775: margin-top:10px;
5776: width:80%;
5777: }
5778:
1.680 riegler 5779: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5780: vertical-align: top;
5781: width: 45%;
5782: }
1.795 www 5783:
1.779 bisitz 5784: .LC_mainmenu_fieldset_category {
5785: color: $font;
5786: background: $pgbg;
5787: font-size: small;
5788: font-weight: bold;
1.777 tempelho 5789: }
1.795 www 5790:
1.716 raeburn 5791: div.LC_createcourse {
5792: margin: 10px 10px 10px 10px;
5793: }
5794:
1.693 droeschl 5795: /* ---- Remove when done ----
5796: # The following styles is part of the redesign of LON-CAPA and are
5797: # subject to change during this project.
5798: # Don't rely on their current functionality as they might be
5799: # changed or removed.
5800: # --------------------------*/
5801:
1.698 harmsja 5802: a:hover,
1.721 harmsja 5803: ol.LC_smallMenu a:hover,
5804: ol#LC_MenuBreadcrumbs a:hover,
5805: ol#LC_PathBreadcrumbs a:hover,
5806: ul#LC_TabMainMenuContent a:hover,
5807: .LC_FormSectionClearButton input:hover
1.795 www 5808: ul.LC_TabContent li:hover a {
1.698 harmsja 5809: color:#BF2317;
5810: text-decoration:none;
1.693 droeschl 5811: }
5812:
1.779 bisitz 5813: h1 {
1.813 bisitz 5814: padding: 0;
1.693 droeschl 5815: line-height:130%;
5816: }
1.698 harmsja 5817:
1.795 www 5818: h2,h3,h4,h5,h6 {
1.803 bisitz 5819: margin: 5px 0 5px 0;
5820: padding: 0;
1.721 harmsja 5821: line-height:130%;
1.693 droeschl 5822: }
1.795 www 5823:
5824: .LC_hcell {
1.698 harmsja 5825: padding:3px 15px 3px 15px;
1.803 bisitz 5826: margin: 0;
1.703 harmsja 5827: background-color:$tabbg;
1.801 tempelho 5828: color:$fontmenu;
1.779 bisitz 5829: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5830: }
1.795 www 5831:
1.840 bisitz 5832: .LC_Box > .LC_hcell {
1.847 tempelho 5833: margin: 0 -10px 10px -10px;
1.835 bisitz 5834: }
5835:
1.721 harmsja 5836: .LC_noBorder {
1.803 bisitz 5837: border: 0;
1.698 harmsja 5838: }
1.693 droeschl 5839:
1.761 tempelho 5840: .LC_Right {
5841: float: right;
1.803 bisitz 5842: margin: 0;
5843: padding: 0;
1.761 tempelho 5844: }
5845:
1.721 harmsja 5846: .LC_FormSectionClearButton input {
1.779 bisitz 5847: background-color:transparent;
1.803 bisitz 5848: border: none;
1.698 harmsja 5849: cursor:pointer;
5850: text-decoration:underline;
1.693 droeschl 5851: }
1.763 bisitz 5852:
5853: .LC_help_open_topic {
5854: color: #FFFFFF;
5855: background-color: #EEEEFF;
5856: margin: 1px;
5857: padding: 4px;
5858: border: 1px solid #000033;
5859: white-space: nowrap;
1.783 amueller 5860: /* vertical-align: middle; */
1.759 neumanie 5861: }
1.693 droeschl 5862:
1.698 harmsja 5863: dl,ul,div,fieldset {
1.803 bisitz 5864: margin: 10px 10px 10px 0;
1.806 bisitz 5865: /* overflow: hidden; */
1.693 droeschl 5866: }
1.795 www 5867:
1.838 bisitz 5868: fieldset > legend {
5869: font-weight: bold;
5870: padding: 0 5px 0 5px;
5871: }
5872:
1.813 bisitz 5873: #LC_nav_bar {
1.807 droeschl 5874: float: left;
1.852 droeschl 5875: margin: 0.2em 0 0 0;
1.807 droeschl 5876: }
5877:
1.813 bisitz 5878: #LC_nav_bar em{
1.807 droeschl 5879: font-weight: bold;
5880: font-style: normal;
5881: }
5882:
5883: ol.LC_smallMenu {
5884: float: right;
1.852 droeschl 5885: margin: 0.2em 0 0 0;
1.807 droeschl 5886: }
5887:
1.852 droeschl 5888: ol#LC_PathBreadcrumbs {
1.803 bisitz 5889: margin: 0;
1.693 droeschl 5890: }
5891:
1.721 harmsja 5892: ol.LC_smallMenu li {
1.693 droeschl 5893: display: inline;
1.803 bisitz 5894: padding: 5px 5px 0 10px;
1.693 droeschl 5895: vertical-align: top;
5896: }
5897:
1.721 harmsja 5898: ol.LC_smallMenu li img {
1.693 droeschl 5899: vertical-align: bottom;
5900: }
5901:
1.721 harmsja 5902: ol.LC_smallMenu a {
1.693 droeschl 5903: font-size: 90%;
5904: color: RGB(80, 80, 80);
5905: text-decoration: none;
5906: }
1.795 www 5907:
1.808 droeschl 5908: ul#LC_TabMainMenuContent {
1.807 droeschl 5909: clear: both;
1.808 droeschl 5910: color: $fontmenu;
5911: background: $tabbg;
5912: list-style: none;
5913: padding: 0;
5914: margin: 0;
5915: width: 100%;
5916: }
5917:
5918: ul#LC_TabMainMenuContent li {
5919: font-weight: bold;
5920: line-height: 1.8em;
5921: padding: 0 0.8em;
5922: border-right: 1px solid black;
5923: display: inline;
5924: vertical-align: middle;
1.807 droeschl 5925: }
5926:
1.847 tempelho 5927: ul.LC_TabContent {
1.721 harmsja 5928: display:block;
1.847 tempelho 5929: background: $sidebg;
1.858 bisitz 5930: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5931: list-style:none;
1.847 tempelho 5932: margin: -10px -10px 0 -10px;
1.803 bisitz 5933: padding: 0;
1.693 droeschl 5934: }
5935:
1.847 tempelho 5936: ul.LC_TabContentBigger {
5937: display:block;
5938: list-style:none;
5939: padding: 0;
5940: }
5941:
5942:
1.795 www 5943: ul.LC_TabContent li,
5944: ul.LC_TabContentBigger li {
1.693 droeschl 5945: display: inline;
1.741 harmsja 5946: border-right: solid 1px $lg_border_color;
5947: float:left;
5948: line-height:140%;
5949: white-space:nowrap;
5950: }
1.795 www 5951:
1.808 droeschl 5952: ul#LC_TabMainMenuContent li a {
5953: color: $fontmenu;
1.693 droeschl 5954: text-decoration: none;
5955: }
1.795 www 5956:
1.721 harmsja 5957: ul.LC_TabContent {
1.847 tempelho 5958: min-height:1.5em;
1.721 harmsja 5959: }
1.795 www 5960:
5961: ul.LC_TabContent li {
1.741 harmsja 5962: vertical-align:middle;
1.803 bisitz 5963: padding: 0 10px 0 10px;
1.745 ehlerst 5964: background-color:$tabbg;
5965: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5966: }
1.795 www 5967:
1.847 tempelho 5968: ul.LC_TabContent .right {
5969: float:right;
5970: }
5971:
1.795 www 5972: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5973: color:rgb(47,47,47);
5974: text-decoration:none;
5975: font-size:95%;
5976: font-weight:bold;
1.761 tempelho 5977: padding-right: 16px;
1.721 harmsja 5978: }
1.795 www 5979:
5980: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5981: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5982: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5983: padding-right: 16px;
1.744 ehlerst 5984: }
1.795 www 5985:
5986: ul.LC_TabContentBigger li {
1.741 harmsja 5987: vertical-align:bottom;
5988: border-top:solid 1px $lg_border_color;
5989: border-left:solid 1px $lg_border_color;
5990: padding:5px 10px 5px 10px;
5991: margin-left:2px;
1.841 tempelho 5992: background: #d9d9d9;
5993: }
5994:
5995: #maincoursedoc {
5996: clear:both;
1.741 harmsja 5997: }
1.795 www 5998:
5999: ul.LC_TabContentBigger li:hover,
6000: ul.LC_TabContentBigger li.active {
1.847 tempelho 6001: background: #ffffff;
1.857 tempelho 6002: color:$font;
1.744 ehlerst 6003: }
1.795 www 6004:
6005: ul.LC_TabContentBigger li,
6006: ul.LC_TabContentBigger li a {
1.741 harmsja 6007: font-size:110%;
6008: font-weight:bold;
1.857 tempelho 6009: color: #737373;
1.741 harmsja 6010: }
1.693 droeschl 6011:
1.862 bisitz 6012: ul.LC_CourseBreadcrumbs {
6013: background: $sidebg;
6014: line-height: 32px;
6015: padding-left: 10px;
6016: margin: 0 0 10px 0;
6017: list-style-position: inside;
6018:
6019: }
6020:
1.795 www 6021: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6022: ol#LC_PathBreadcrumbs {
1.693 droeschl 6023: padding-left: 10px;
1.819 tempelho 6024: margin: 0;
1.693 droeschl 6025: list-style-position: inside;
6026: }
6027:
1.795 www 6028: ol#LC_MenuBreadcrumbs li,
6029: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6030: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 6031: display: inline;
6032: white-space: nowrap;
1.693 droeschl 6033: }
6034:
1.823 bisitz 6035: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6036: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 6037: text-decoration: none;
6038: font-size:90%;
6039: }
1.795 www 6040:
6041: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6042: text-decoration:none;
6043: font-size:100%;
6044: font-weight:bold;
1.693 droeschl 6045: }
1.795 www 6046:
1.840 bisitz 6047: .LC_Box {
1.835 bisitz 6048: border: solid 1px $lg_border_color;
6049: padding: 0 10px 10px 10px;
1.746 neumanie 6050: }
1.795 www 6051:
6052: .LC_AboutMe_Image {
1.747 neumanie 6053: float:left;
6054: margin-right:10px;
6055: }
1.795 www 6056:
6057: .LC_Clear_AboutMe_Image {
1.747 neumanie 6058: clear:left;
6059: }
1.795 www 6060:
1.721 harmsja 6061: dl.LC_ListStyleClean dt {
1.693 droeschl 6062: padding-right: 5px;
6063: display: table-header-group;
6064: }
6065:
1.721 harmsja 6066: dl.LC_ListStyleClean dd {
1.693 droeschl 6067: display: table-row;
6068: }
6069:
1.721 harmsja 6070: .LC_ListStyleClean,
6071: .LC_ListStyleSimple,
6072: .LC_ListStyleNormal,
1.777 tempelho 6073: .LC_ListStyle_Border,
1.795 www 6074: .LC_ListStyleSpecial {
1.693 droeschl 6075: /*display:block; */
6076: list-style-position: inside;
6077: list-style-type: none;
6078: overflow: hidden;
1.803 bisitz 6079: padding: 0;
1.693 droeschl 6080: }
6081:
1.721 harmsja 6082: .LC_ListStyleSimple li,
6083: .LC_ListStyleSimple dd,
6084: .LC_ListStyleNormal li,
6085: .LC_ListStyleNormal dd,
6086: .LC_ListStyleSpecial li,
1.795 www 6087: .LC_ListStyleSpecial dd {
1.803 bisitz 6088: margin: 0;
1.693 droeschl 6089: padding: 5px 5px 5px 10px;
6090: clear: both;
6091: }
6092:
1.721 harmsja 6093: .LC_ListStyleClean li,
6094: .LC_ListStyleClean dd {
1.803 bisitz 6095: padding-top: 0;
6096: padding-bottom: 0;
1.693 droeschl 6097: }
6098:
1.721 harmsja 6099: .LC_ListStyleSimple dd,
1.795 www 6100: .LC_ListStyleSimple li {
1.698 harmsja 6101: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6102: }
6103:
1.721 harmsja 6104: .LC_ListStyleSpecial li,
6105: .LC_ListStyleSpecial dd {
1.693 droeschl 6106: list-style-type: none;
6107: background-color: RGB(220, 220, 220);
6108: margin-bottom: 4px;
6109: }
6110:
1.721 harmsja 6111: table.LC_SimpleTable {
1.698 harmsja 6112: margin:5px;
6113: border:solid 1px $lg_border_color;
1.795 www 6114: }
1.693 droeschl 6115:
1.721 harmsja 6116: table.LC_SimpleTable tr {
1.803 bisitz 6117: padding: 0;
1.698 harmsja 6118: border:solid 1px $lg_border_color;
1.693 droeschl 6119: }
1.795 www 6120:
6121: table.LC_SimpleTable thead {
1.698 harmsja 6122: background:rgb(220,220,220);
1.693 droeschl 6123: }
6124:
1.721 harmsja 6125: div.LC_columnSection {
1.693 droeschl 6126: display: block;
6127: clear: both;
6128: overflow: hidden;
1.803 bisitz 6129: margin: 0;
1.693 droeschl 6130: }
6131:
1.721 harmsja 6132: div.LC_columnSection>* {
1.693 droeschl 6133: float: left;
1.803 bisitz 6134: margin: 10px 20px 10px 0;
1.747 neumanie 6135: overflow:hidden;
1.693 droeschl 6136: }
1.721 harmsja 6137:
1.694 tempelho 6138: .LC_loginpage_container {
6139: text-align:left;
6140: margin : 0 auto;
1.785 tempelho 6141: width:90%;
1.694 tempelho 6142: padding: 10px;
6143: height: auto;
1.712 muellerd 6144: background-color:#FFFFFF;
1.694 tempelho 6145: border:1px solid #CCCCCC;
6146: }
6147:
6148:
6149: .LC_loginpage_loginContainer {
6150: float:left;
1.712 muellerd 6151: width: 182px;
1.785 tempelho 6152: padding: 2px;
1.712 muellerd 6153: border:1px solid #CCCCCC;
6154: background-color:$loginbg;
1.694 tempelho 6155: }
6156:
1.795 www 6157: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6158: margin-top: 0;
1.712 muellerd 6159: display:block;
6160: background:$bgcol;
6161: color:$textcol;
6162: padding-left:5px;
6163: }
1.785 tempelho 6164:
1.694 tempelho 6165: .LC_loginpage_loginInfo {
6166: float:left;
1.785 tempelho 6167: width:182px;
1.694 tempelho 6168: border:1px solid #CCCCCC;
1.785 tempelho 6169: padding:2px;
1.712 muellerd 6170: }
6171:
1.694 tempelho 6172: .LC_loginpage_space {
1.754 droeschl 6173: clear: both;
6174: margin-bottom: 20px;
1.694 tempelho 6175: border-bottom: 1px solid #CCCCCC;
6176: }
6177:
1.785 tempelho 6178: .LC_loginpage_floatLeft {
6179: float: left;
6180: width: 200px;
6181: margin: 0;
6182: }
6183:
1.795 www 6184: table em {
1.754 droeschl 6185: font-weight: bold;
6186: font-style: normal;
1.748 schulted 6187: }
1.795 www 6188:
1.779 bisitz 6189: table.LC_tableBrowseRes,
1.795 www 6190: table.LC_tableOfContent {
1.769 schulted 6191: border:none;
1.858 bisitz 6192: border-spacing: 1px;
1.754 droeschl 6193: padding: 3px;
6194: background-color: #FFFFFF;
6195: font-size: 90%;
1.753 droeschl 6196: }
1.789 droeschl 6197:
6198: table.LC_tableOfContent{
6199: border-collapse: collapse;
6200: }
6201:
1.771 droeschl 6202: table.LC_tableBrowseRes a,
1.768 schulted 6203: table.LC_tableOfContent a {
1.771 droeschl 6204: background-color: transparent;
1.753 droeschl 6205: text-decoration: none;
6206: }
6207:
1.771 droeschl 6208: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6209: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6210: background-color: #EEEEEE;
1.753 droeschl 6211: }
6212:
1.795 www 6213: table.LC_tableOfContent img {
1.753 droeschl 6214: border: none;
6215: height: 1.3em;
6216: vertical-align: text-bottom;
6217: margin-right: 0.3em;
6218: }
1.757 schulted 6219:
1.795 www 6220: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6221: background-image:url(/res/adm/pages/open-first-problem.gif);
6222: }
6223:
1.795 www 6224: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6225: background-image:url(/res/adm/pages/start-navigation.gif);
6226: }
6227:
1.795 www 6228: a#LC_content_toolbar_closenav {
1.774 ehlerst 6229: background-image:url(/res/adm/pages/close-navigation.gif);
6230: }
6231:
1.795 www 6232: a#LC_content_toolbar_everything {
1.774 ehlerst 6233: background-image:url(/res/adm/pages/show-all.gif);
6234: }
6235:
1.795 www 6236: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6237: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6238: }
6239:
1.795 www 6240: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6241: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6242: }
6243:
1.795 www 6244: a#LC_content_toolbar_changefolder {
1.757 schulted 6245: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6246: }
6247:
1.795 www 6248: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6249: background-image:url(/res/adm/pages/open-all-folders.gif);
6250: }
6251:
1.795 www 6252: ul#LC_toolbar li a:hover {
1.757 schulted 6253: background-position: bottom center;
6254: }
6255:
1.795 www 6256: ul#LC_toolbar {
1.803 bisitz 6257: padding: 0;
1.757 schulted 6258: margin: 2px;
6259: list-style:none;
6260: position:relative;
6261: background-color:white;
6262: }
6263:
1.795 www 6264: ul#LC_toolbar li {
1.757 schulted 6265: border:1px solid white;
1.803 bisitz 6266: padding: 0;
1.757 schulted 6267: margin: 0;
1.795 www 6268: float: left;
1.767 droeschl 6269: display:inline;
1.757 schulted 6270: vertical-align:middle;
1.795 www 6271: }
1.757 schulted 6272:
1.783 amueller 6273:
1.795 www 6274: a.LC_toolbarItem {
1.767 droeschl 6275: display:block;
1.803 bisitz 6276: padding: 0;
6277: margin: 0;
1.757 schulted 6278: height: 32px;
6279: width: 32px;
1.779 bisitz 6280: color:white;
1.803 bisitz 6281: border: none;
1.757 schulted 6282: background-repeat:no-repeat;
6283: background-color:transparent;
6284: }
6285:
1.843 bisitz 6286: ul.LC_funclist li {
1.782 bisitz 6287: float: left;
6288: white-space: nowrap;
6289: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6290: margin: 0 15px 15px 10px;
1.782 bisitz 6291: }
6292:
1.757 schulted 6293:
1.343 albertel 6294: END
6295: }
6296:
1.306 albertel 6297: =pod
6298:
6299: =item * &headtag()
6300:
6301: Returns a uniform footer for LON-CAPA web pages.
6302:
1.307 albertel 6303: Inputs: $title - optional title for the head
6304: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6305: $args - optional arguments
1.319 albertel 6306: force_register - if is true call registerurl so the remote is
6307: informed
1.415 albertel 6308: redirect -> array ref of
6309: 1- seconds before redirect occurs
6310: 2- url to redirect to
6311: 3- whether the side effect should occur
1.315 albertel 6312: (side effect of setting
6313: $env{'internal.head.redirect'} to the url
6314: redirected too)
1.352 albertel 6315: domain -> force to color decorate a page for a specific
6316: domain
6317: function -> force usage of a specific rolish color scheme
6318: bgcolor -> override the default page bgcolor
1.460 albertel 6319: no_auto_mt_title
6320: -> prevent &mt()ing the title arg
1.464 albertel 6321:
1.306 albertel 6322: =cut
6323:
6324: sub headtag {
1.313 albertel 6325: my ($title,$head_extra,$args) = @_;
1.306 albertel 6326:
1.363 albertel 6327: my $function = $args->{'function'} || &get_users_function();
6328: my $domain = $args->{'domain'} || &determinedomain();
6329: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6330: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6331: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6332: #time(),
1.418 albertel 6333: $env{'environment.color.timestamp'},
1.363 albertel 6334: $function,$domain,$bgcolor);
6335:
1.369 www 6336: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6337:
1.308 albertel 6338: my $result =
6339: '<head>'.
1.461 albertel 6340: &font_settings();
1.319 albertel 6341:
1.461 albertel 6342: if (!$args->{'frameset'}) {
6343: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6344: }
1.319 albertel 6345: if ($args->{'force_register'}) {
6346: $result .= &Apache::lonmenu::registerurl(1);
6347: }
1.436 albertel 6348: if (!$args->{'no_nav_bar'}
6349: && !$args->{'only_body'}
6350: && !$args->{'frameset'}) {
6351: $result .= &help_menu_js();
6352: }
1.319 albertel 6353:
1.314 albertel 6354: if (ref($args->{'redirect'})) {
1.414 albertel 6355: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6356: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6357: if (!$inhibit_continue) {
6358: $env{'internal.head.redirect'} = $url;
6359: }
1.313 albertel 6360: $result.=<<ADDMETA
6361: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6362: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6363: ADDMETA
6364: }
1.306 albertel 6365: if (!defined($title)) {
6366: $title = 'The LearningOnline Network with CAPA';
6367: }
1.460 albertel 6368: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6369: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6370: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6371: .$head_extra;
1.306 albertel 6372: return $result;
6373: }
6374:
6375: =pod
6376:
1.340 albertel 6377: =item * &font_settings()
6378:
6379: Returns neccessary <meta> to set the proper encoding
6380:
6381: Inputs: none
6382:
6383: =cut
6384:
6385: sub font_settings {
6386: my $headerstring='';
1.647 www 6387: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6388: $headerstring.=
6389: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6390: }
6391: return $headerstring;
6392: }
6393:
1.341 albertel 6394: =pod
6395:
6396: =item * &xml_begin()
6397:
6398: Returns the needed doctype and <html>
6399:
6400: Inputs: none
6401:
6402: =cut
6403:
6404: sub xml_begin {
6405: my $output='';
6406:
1.592 albertel 6407: if ($env{'internal.start_page'}==1) {
6408: &Apache::lonhtmlcommon::init_htmlareafields();
6409: }
1.342 albertel 6410:
1.341 albertel 6411: if ($env{'browser.mathml'}) {
6412: $output='<?xml version="1.0"?>'
6413: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6414: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6415:
6416: # .'<!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">] >'
6417: .'<!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">'
6418: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6419: .'xmlns="http://www.w3.org/1999/xhtml">';
6420: } else {
1.849 bisitz 6421: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6422: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6423: }
6424: return $output;
6425: }
1.340 albertel 6426:
6427: =pod
6428:
1.306 albertel 6429: =item * &endheadtag()
6430:
6431: Returns a uniform </head> for LON-CAPA web pages.
6432:
6433: Inputs: none
6434:
6435: =cut
6436:
6437: sub endheadtag {
6438: return '</head>';
6439: }
6440:
6441: =pod
6442:
6443: =item * &head()
6444:
6445: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6446:
1.648 raeburn 6447: Inputs:
6448:
6449: =over 4
6450:
6451: $title - optional title for the page
6452:
6453: $head_extra - optional extra HTML to put inside the <head>
6454:
6455: =back
1.405 albertel 6456:
1.306 albertel 6457: =cut
6458:
6459: sub head {
1.325 albertel 6460: my ($title,$head_extra,$args) = @_;
6461: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6462: }
6463:
6464: =pod
6465:
6466: =item * &start_page()
6467:
6468: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6469:
1.648 raeburn 6470: Inputs:
6471:
6472: =over 4
6473:
6474: $title - optional title for the page
6475:
6476: $head_extra - optional extra HTML to incude inside the <head>
6477:
6478: $args - additional optional args supported are:
6479:
6480: =over 8
6481:
6482: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6483: arg on
1.814 bisitz 6484: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6485: add_entries -> additional attributes to add to the <body>
6486: domain -> force to color decorate a page for a
1.317 albertel 6487: specific domain
1.648 raeburn 6488: function -> force usage of a specific rolish color
1.317 albertel 6489: scheme
1.648 raeburn 6490: redirect -> see &headtag()
6491: bgcolor -> override the default page bg color
6492: js_ready -> return a string ready for being used in
1.317 albertel 6493: a javascript writeln
1.648 raeburn 6494: html_encode -> return a string ready for being used in
1.320 albertel 6495: a html attribute
1.648 raeburn 6496: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6497: $forcereg arg
1.648 raeburn 6498: frameset -> if true will start with a <frameset>
1.330 albertel 6499: rather than <body>
1.648 raeburn 6500: skip_phases -> hash ref of
1.338 albertel 6501: head -> skip the <html><head> generation
6502: body -> skip all <body> generation
1.648 raeburn 6503: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6504: 'Switch To Inline Menu' link
1.648 raeburn 6505: no_auto_mt_title -> prevent &mt()ing the title arg
6506: inherit_jsmath -> when creating popup window in a page,
6507: should it have jsmath forced on by the
6508: current page
1.361 albertel 6509:
1.648 raeburn 6510: =back
1.460 albertel 6511:
1.648 raeburn 6512: =back
1.562 albertel 6513:
1.306 albertel 6514: =cut
6515:
6516: sub start_page {
1.309 albertel 6517: my ($title,$head_extra,$args) = @_;
1.318 albertel 6518: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6519: my %head_args;
1.352 albertel 6520: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6521: 'bgcolor','frameset','no_nav_bar','only_body',
6522: 'no_auto_mt_title') {
1.319 albertel 6523: if (defined($args->{$arg})) {
1.324 raeburn 6524: $head_args{$arg} = $args->{$arg};
1.319 albertel 6525: }
1.313 albertel 6526: }
1.319 albertel 6527:
1.315 albertel 6528: $env{'internal.start_page'}++;
1.338 albertel 6529: my $result;
6530: if (! exists($args->{'skip_phases'}{'head'}) ) {
6531: $result.=
1.341 albertel 6532: &xml_begin().
1.338 albertel 6533: &headtag($title,$head_extra,\%head_args).&endheadtag();
6534: }
6535:
6536: if (! exists($args->{'skip_phases'}{'body'}) ) {
6537: if ($args->{'frameset'}) {
6538: my $attr_string = &make_attr_string($args->{'force_register'},
6539: $args->{'add_entries'});
6540: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6541: } else {
6542: $result .=
6543: &bodytag($title,
6544: $args->{'function'}, $args->{'add_entries'},
6545: $args->{'only_body'}, $args->{'domain'},
6546: $args->{'force_register'}, $args->{'no_nav_bar'},
6547: $args->{'bgcolor'}, $args->{'no_inline_link'},
6548: $args);
6549: }
1.330 albertel 6550: }
1.338 albertel 6551:
1.315 albertel 6552: if ($args->{'js_ready'}) {
1.713 kaisler 6553: $result = &js_ready($result);
1.315 albertel 6554: }
1.320 albertel 6555: if ($args->{'html_encode'}) {
1.713 kaisler 6556: $result = &html_encode($result);
6557: }
6558:
1.813 bisitz 6559: # Preparation for new and consistent functionlist at top of screen
6560: # if ($args->{'functionlist'}) {
6561: # $result .= &build_functionlist();
6562: #}
6563:
6564: # Don't add anything more if only_body wanted
6565: return $result if $args->{'only_body'};
6566:
6567: #Breadcrumbs
1.758 kaisler 6568: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6569: &Apache::lonhtmlcommon::clear_breadcrumbs();
6570: #if any br links exists, add them to the breadcrumbs
6571: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6572: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6573: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6574: }
6575: }
6576:
6577: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6578: if(exists($args->{'bread_crumbs_component'})){
6579: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6580: }else{
6581: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6582: }
1.320 albertel 6583: }
1.315 albertel 6584: return $result;
1.306 albertel 6585: }
6586:
1.330 albertel 6587:
1.306 albertel 6588: =pod
6589:
6590: =item * &head()
6591:
6592: Returns a complete </body></html> section for LON-CAPA web pages.
6593:
1.315 albertel 6594: Inputs: $args - additional optional args supported are:
6595: js_ready -> return a string ready for being used in
6596: a javascript writeln
1.320 albertel 6597: html_encode -> return a string ready for being used in
6598: a html attribute
1.330 albertel 6599: frameset -> if true will start with a <frameset>
6600: rather than <body>
1.493 albertel 6601: dicsussion -> if true will get discussion from
6602: lonxml::xmlend
6603: (you can pass the target and parser arguments
6604: through optional 'target' and 'parser' args
6605: to this routine)
1.306 albertel 6606:
6607: =cut
6608:
6609: sub end_page {
1.315 albertel 6610: my ($args) = @_;
6611: $env{'internal.end_page'}++;
1.330 albertel 6612: my $result;
1.335 albertel 6613: if ($args->{'discussion'}) {
6614: my ($target,$parser);
6615: if (ref($args->{'discussion'})) {
6616: ($target,$parser) =($args->{'discussion'}{'target'},
6617: $args->{'discussion'}{'parser'});
6618: }
6619: $result .= &Apache::lonxml::xmlend($target,$parser);
6620: }
6621:
1.330 albertel 6622: if ($args->{'frameset'}) {
6623: $result .= '</frameset>';
6624: } else {
1.635 raeburn 6625: $result .= &endbodytag($args);
1.330 albertel 6626: }
6627: $result .= "\n</html>";
6628:
1.315 albertel 6629: if ($args->{'js_ready'}) {
1.317 albertel 6630: $result = &js_ready($result);
1.315 albertel 6631: }
1.335 albertel 6632:
1.320 albertel 6633: if ($args->{'html_encode'}) {
6634: $result = &html_encode($result);
6635: }
1.335 albertel 6636:
1.315 albertel 6637: return $result;
6638: }
6639:
1.320 albertel 6640: sub html_encode {
6641: my ($result) = @_;
6642:
1.322 albertel 6643: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6644:
6645: return $result;
6646: }
1.317 albertel 6647: sub js_ready {
6648: my ($result) = @_;
6649:
1.323 albertel 6650: $result =~ s/[\n\r]/ /xmsg;
6651: $result =~ s/\\/\\\\/xmsg;
6652: $result =~ s/'/\\'/xmsg;
1.372 albertel 6653: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6654:
6655: return $result;
6656: }
6657:
1.315 albertel 6658: sub validate_page {
6659: if ( exists($env{'internal.start_page'})
1.316 albertel 6660: && $env{'internal.start_page'} > 1) {
6661: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6662: $env{'internal.start_page'}.' '.
1.316 albertel 6663: $ENV{'request.filename'});
1.315 albertel 6664: }
6665: if ( exists($env{'internal.end_page'})
1.316 albertel 6666: && $env{'internal.end_page'} > 1) {
6667: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6668: $env{'internal.end_page'}.' '.
1.316 albertel 6669: $env{'request.filename'});
1.315 albertel 6670: }
6671: if ( exists($env{'internal.start_page'})
6672: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6673: &Apache::lonnet::logthis('start_page called without end_page '.
6674: $env{'request.filename'});
1.315 albertel 6675: }
6676: if ( ! exists($env{'internal.start_page'})
6677: && exists($env{'internal.end_page'})) {
1.316 albertel 6678: &Apache::lonnet::logthis('end_page called without start_page'.
6679: $env{'request.filename'});
1.315 albertel 6680: }
1.306 albertel 6681: }
1.315 albertel 6682:
1.318 albertel 6683: sub simple_error_page {
6684: my ($r,$title,$msg) = @_;
6685: my $page =
6686: &Apache::loncommon::start_page($title).
6687: &mt($msg).
6688: &Apache::loncommon::end_page();
6689: if (ref($r)) {
6690: $r->print($page);
1.327 albertel 6691: return;
1.318 albertel 6692: }
6693: return $page;
6694: }
1.347 albertel 6695:
6696: {
1.610 albertel 6697: my @row_count;
1.347 albertel 6698: sub start_data_table {
1.422 albertel 6699: my ($add_class) = @_;
6700: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6701: unshift(@row_count,0);
1.422 albertel 6702: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6703: }
6704:
6705: sub end_data_table {
1.610 albertel 6706: shift(@row_count);
1.389 albertel 6707: return '</table>'."\n";;
1.347 albertel 6708: }
6709:
6710: sub start_data_table_row {
1.422 albertel 6711: my ($add_class) = @_;
1.610 albertel 6712: $row_count[0]++;
6713: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6714: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6715: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6716: }
1.471 banghart 6717:
6718: sub continue_data_table_row {
6719: my ($add_class) = @_;
1.610 albertel 6720: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6721: $css_class = (join(' ',$css_class,$add_class));
6722: return '<tr class="'.$css_class.'">'."\n";;
6723: }
1.347 albertel 6724:
6725: sub end_data_table_row {
1.389 albertel 6726: return '</tr>'."\n";;
1.347 albertel 6727: }
1.367 www 6728:
1.421 albertel 6729: sub start_data_table_empty_row {
1.707 bisitz 6730: # $row_count[0]++;
1.421 albertel 6731: return '<tr class="LC_empty_row" >'."\n";;
6732: }
6733:
6734: sub end_data_table_empty_row {
6735: return '</tr>'."\n";;
6736: }
6737:
1.367 www 6738: sub start_data_table_header_row {
1.389 albertel 6739: return '<tr class="LC_header_row">'."\n";;
1.367 www 6740: }
6741:
6742: sub end_data_table_header_row {
1.389 albertel 6743: return '</tr>'."\n";;
1.367 www 6744: }
1.347 albertel 6745: }
6746:
1.548 albertel 6747: =pod
6748:
6749: =item * &inhibit_menu_check($arg)
6750:
6751: Checks for a inhibitmenu state and generates output to preserve it
6752:
6753: Inputs: $arg - can be any of
6754: - undef - in which case the return value is a string
6755: to add into arguments list of a uri
6756: - 'input' - in which case the return value is a HTML
6757: <form> <input> field of type hidden to
6758: preserve the value
6759: - a url - in which case the return value is the url with
6760: the neccesary cgi args added to preserve the
6761: inhibitmenu state
6762: - a ref to a url - no return value, but the string is
6763: updated to include the neccessary cgi
6764: args to preserve the inhibitmenu state
6765:
6766: =cut
6767:
6768: sub inhibit_menu_check {
6769: my ($arg) = @_;
6770: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6771: if ($arg eq 'input') {
6772: if ($env{'form.inhibitmenu'}) {
6773: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6774: } else {
6775: return
6776: }
6777: }
6778: if ($env{'form.inhibitmenu'}) {
6779: if (ref($arg)) {
6780: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6781: } elsif ($arg eq '') {
6782: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6783: } else {
6784: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6785: }
6786: }
6787: if (!ref($arg)) {
6788: return $arg;
6789: }
6790: }
6791:
1.251 albertel 6792: ###############################################
1.182 matthew 6793:
6794: =pod
6795:
1.549 albertel 6796: =back
6797:
6798: =head1 User Information Routines
6799:
6800: =over 4
6801:
1.405 albertel 6802: =item * &get_users_function()
1.182 matthew 6803:
6804: Used by &bodytag to determine the current users primary role.
6805: Returns either 'student','coordinator','admin', or 'author'.
6806:
6807: =cut
6808:
6809: ###############################################
6810: sub get_users_function {
1.815 tempelho 6811: my $function = 'norole';
1.818 tempelho 6812: if ($env{'request.role'}=~/^(st)/) {
6813: $function='student';
6814: }
1.258 albertel 6815: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6816: $function='coordinator';
6817: }
1.258 albertel 6818: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6819: $function='admin';
6820: }
1.826 bisitz 6821: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6822: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6823: $function='author';
6824: }
6825: return $function;
1.54 www 6826: }
1.99 www 6827:
6828: ###############################################
6829:
1.233 raeburn 6830: =pod
6831:
1.821 raeburn 6832: =item * &show_course()
6833:
6834: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6835: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6836:
6837: Inputs:
6838: None
6839:
6840: Outputs:
6841: Scalar: 1 if 'Course' to be used, 0 otherwise.
6842:
6843: =cut
6844:
6845: ###############################################
6846: sub show_course {
6847: my $course = !$env{'user.adv'};
6848: if (!$env{'user.adv'}) {
6849: foreach my $env (keys(%env)) {
6850: next if ($env !~ m/^user\.priv\./);
6851: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6852: $course = 0;
6853: last;
6854: }
6855: }
6856: }
6857: return $course;
6858: }
6859:
6860: ###############################################
6861:
6862: =pod
6863:
1.542 raeburn 6864: =item * &check_user_status()
1.274 raeburn 6865:
6866: Determines current status of supplied role for a
6867: specific user. Roles can be active, previous or future.
6868:
6869: Inputs:
6870: user's domain, user's username, course's domain,
1.375 raeburn 6871: course's number, optional section ID.
1.274 raeburn 6872:
6873: Outputs:
6874: role status: active, previous or future.
6875:
6876: =cut
6877:
6878: sub check_user_status {
1.412 raeburn 6879: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6880: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6881: my @uroles = keys %userinfo;
6882: my $srchstr;
6883: my $active_chk = 'none';
1.412 raeburn 6884: my $now = time;
1.274 raeburn 6885: if (@uroles > 0) {
1.412 raeburn 6886: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6887: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6888: } else {
1.412 raeburn 6889: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6890: }
6891: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6892: my $role_end = 0;
6893: my $role_start = 0;
6894: $active_chk = 'active';
1.412 raeburn 6895: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6896: $role_end = $1;
6897: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6898: $role_start = $1;
1.274 raeburn 6899: }
6900: }
6901: if ($role_start > 0) {
1.412 raeburn 6902: if ($now < $role_start) {
1.274 raeburn 6903: $active_chk = 'future';
6904: }
6905: }
6906: if ($role_end > 0) {
1.412 raeburn 6907: if ($now > $role_end) {
1.274 raeburn 6908: $active_chk = 'previous';
6909: }
6910: }
6911: }
6912: }
6913: return $active_chk;
6914: }
6915:
6916: ###############################################
6917:
6918: =pod
6919:
1.405 albertel 6920: =item * &get_sections()
1.233 raeburn 6921:
6922: Determines all the sections for a course including
6923: sections with students and sections containing other roles.
1.419 raeburn 6924: Incoming parameters:
6925:
6926: 1. domain
6927: 2. course number
6928: 3. reference to array containing roles for which sections should
6929: be gathered (optional).
6930: 4. reference to array containing status types for which sections
6931: should be gathered (optional).
6932:
6933: If the third argument is undefined, sections are gathered for any role.
6934: If the fourth argument is undefined, sections are gathered for any status.
6935: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6936:
1.374 raeburn 6937: Returns section hash (keys are section IDs, values are
6938: number of users in each section), subject to the
1.419 raeburn 6939: optional roles filter, optional status filter
1.233 raeburn 6940:
6941: =cut
6942:
6943: ###############################################
6944: sub get_sections {
1.419 raeburn 6945: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6946: if (!defined($cdom) || !defined($cnum)) {
6947: my $cid = $env{'request.course.id'};
6948:
6949: return if (!defined($cid));
6950:
6951: $cdom = $env{'course.'.$cid.'.domain'};
6952: $cnum = $env{'course.'.$cid.'.num'};
6953: }
6954:
6955: my %sectioncount;
1.419 raeburn 6956: my $now = time;
1.240 albertel 6957:
1.366 albertel 6958: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6959: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6960: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6961: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6962: my $start_index = &Apache::loncoursedata::CL_START();
6963: my $end_index = &Apache::loncoursedata::CL_END();
6964: my $status;
1.366 albertel 6965: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6966: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6967: $data->[$status_index],
6968: $data->[$start_index],
6969: $data->[$end_index]);
6970: if ($stu_status eq 'Active') {
6971: $status = 'active';
6972: } elsif ($end < $now) {
6973: $status = 'previous';
6974: } elsif ($start > $now) {
6975: $status = 'future';
6976: }
6977: if ($section ne '-1' && $section !~ /^\s*$/) {
6978: if ((!defined($possible_status)) || (($status ne '') &&
6979: (grep/^\Q$status\E$/,@{$possible_status}))) {
6980: $sectioncount{$section}++;
6981: }
1.240 albertel 6982: }
6983: }
6984: }
6985: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6986: foreach my $user (sort(keys(%courseroles))) {
6987: if ($user !~ /^(\w{2})/) { next; }
6988: my ($role) = ($user =~ /^(\w{2})/);
6989: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6990: my ($section,$status);
1.240 albertel 6991: if ($role eq 'cr' &&
6992: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6993: $section=$1;
6994: }
6995: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6996: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6997: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6998: if ($end == -1 && $start == -1) {
6999: next; #deleted role
7000: }
7001: if (!defined($possible_status)) {
7002: $sectioncount{$section}++;
7003: } else {
7004: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7005: $status = 'active';
7006: } elsif ($end < $now) {
7007: $status = 'future';
7008: } elsif ($start > $now) {
7009: $status = 'previous';
7010: }
7011: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7012: $sectioncount{$section}++;
7013: }
7014: }
1.233 raeburn 7015: }
1.366 albertel 7016: return %sectioncount;
1.233 raeburn 7017: }
7018:
1.274 raeburn 7019: ###############################################
1.294 raeburn 7020:
7021: =pod
1.405 albertel 7022:
7023: =item * &get_course_users()
7024:
1.275 raeburn 7025: Retrieves usernames:domains for users in the specified course
7026: with specific role(s), and access status.
7027:
7028: Incoming parameters:
1.277 albertel 7029: 1. course domain
7030: 2. course number
7031: 3. access status: users must have - either active,
1.275 raeburn 7032: previous, future, or all.
1.277 albertel 7033: 4. reference to array of permissible roles
1.288 raeburn 7034: 5. reference to array of section restrictions (optional)
7035: 6. reference to results object (hash of hashes).
7036: 7. reference to optional userdata hash
1.609 raeburn 7037: 8. reference to optional statushash
1.630 raeburn 7038: 9. flag if privileged users (except those set to unhide in
7039: course settings) should be excluded
1.609 raeburn 7040: Keys of top level results hash are roles.
1.275 raeburn 7041: Keys of inner hashes are username:domain, with
7042: values set to access type.
1.288 raeburn 7043: Optional userdata hash returns an array with arguments in the
7044: same order as loncoursedata::get_classlist() for student data.
7045:
1.609 raeburn 7046: Optional statushash returns
7047:
1.288 raeburn 7048: Entries for end, start, section and status are blank because
7049: of the possibility of multiple values for non-student roles.
7050:
1.275 raeburn 7051: =cut
1.405 albertel 7052:
1.275 raeburn 7053: ###############################################
1.405 albertel 7054:
1.275 raeburn 7055: sub get_course_users {
1.630 raeburn 7056: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7057: my %idx = ();
1.419 raeburn 7058: my %seclists;
1.288 raeburn 7059:
7060: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7061: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7062: $idx{end} = &Apache::loncoursedata::CL_END();
7063: $idx{start} = &Apache::loncoursedata::CL_START();
7064: $idx{id} = &Apache::loncoursedata::CL_ID();
7065: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7066: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7067: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7068:
1.290 albertel 7069: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7070: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7071: my $now = time;
1.277 albertel 7072: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7073: my $match = 0;
1.412 raeburn 7074: my $secmatch = 0;
1.419 raeburn 7075: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7076: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7077: if ($section eq '') {
7078: $section = 'none';
7079: }
1.291 albertel 7080: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7081: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7082: $secmatch = 1;
7083: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7084: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7085: $secmatch = 1;
7086: }
7087: } else {
1.419 raeburn 7088: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7089: $secmatch = 1;
7090: }
1.290 albertel 7091: }
1.412 raeburn 7092: if (!$secmatch) {
7093: next;
7094: }
1.419 raeburn 7095: }
1.275 raeburn 7096: if (defined($$types{'active'})) {
1.288 raeburn 7097: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7098: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7099: $match = 1;
1.275 raeburn 7100: }
7101: }
7102: if (defined($$types{'previous'})) {
1.609 raeburn 7103: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7104: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7105: $match = 1;
1.275 raeburn 7106: }
7107: }
7108: if (defined($$types{'future'})) {
1.609 raeburn 7109: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7110: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7111: $match = 1;
1.275 raeburn 7112: }
7113: }
1.609 raeburn 7114: if ($match) {
7115: push(@{$seclists{$student}},$section);
7116: if (ref($userdata) eq 'HASH') {
7117: $$userdata{$student} = $$classlist{$student};
7118: }
7119: if (ref($statushash) eq 'HASH') {
7120: $statushash->{$student}{'st'}{$section} = $status;
7121: }
1.288 raeburn 7122: }
1.275 raeburn 7123: }
7124: }
1.412 raeburn 7125: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7126: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7127: my $now = time;
1.609 raeburn 7128: my %displaystatus = ( previous => 'Expired',
7129: active => 'Active',
7130: future => 'Future',
7131: );
1.630 raeburn 7132: my %nothide;
7133: if ($hidepriv) {
7134: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7135: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7136: if ($user !~ /:/) {
7137: $nothide{join(':',split(/[\@]/,$user))}=1;
7138: } else {
7139: $nothide{$user} = 1;
7140: }
7141: }
7142: }
1.439 raeburn 7143: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7144: my $match = 0;
1.412 raeburn 7145: my $secmatch = 0;
1.439 raeburn 7146: my $status;
1.412 raeburn 7147: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7148: $user =~ s/:$//;
1.439 raeburn 7149: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7150: if ($end == -1 || $start == -1) {
7151: next;
7152: }
7153: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7154: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7155: my ($uname,$udom) = split(/:/,$user);
7156: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7157: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7158: $secmatch = 1;
7159: } elsif ($usec eq '') {
1.420 albertel 7160: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7161: $secmatch = 1;
7162: }
7163: } else {
7164: if (grep(/^\Q$usec\E$/,@{$sections})) {
7165: $secmatch = 1;
7166: }
7167: }
7168: if (!$secmatch) {
7169: next;
7170: }
1.288 raeburn 7171: }
1.419 raeburn 7172: if ($usec eq '') {
7173: $usec = 'none';
7174: }
1.275 raeburn 7175: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7176: if ($hidepriv) {
7177: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7178: (!$nothide{$uname.':'.$udom})) {
7179: next;
7180: }
7181: }
1.503 raeburn 7182: if ($end > 0 && $end < $now) {
1.439 raeburn 7183: $status = 'previous';
7184: } elsif ($start > $now) {
7185: $status = 'future';
7186: } else {
7187: $status = 'active';
7188: }
1.277 albertel 7189: foreach my $type (keys(%{$types})) {
1.275 raeburn 7190: if ($status eq $type) {
1.420 albertel 7191: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7192: push(@{$$users{$role}{$user}},$type);
7193: }
1.288 raeburn 7194: $match = 1;
7195: }
7196: }
1.419 raeburn 7197: if (($match) && (ref($userdata) eq 'HASH')) {
7198: if (!exists($$userdata{$uname.':'.$udom})) {
7199: &get_user_info($udom,$uname,\%idx,$userdata);
7200: }
1.420 albertel 7201: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7202: push(@{$seclists{$uname.':'.$udom}},$usec);
7203: }
1.609 raeburn 7204: if (ref($statushash) eq 'HASH') {
7205: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7206: }
1.275 raeburn 7207: }
7208: }
7209: }
7210: }
1.290 albertel 7211: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7212: if ((defined($cdom)) && (defined($cnum))) {
7213: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7214: if ( defined($csettings{'internal.courseowner'}) ) {
7215: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7216: next if ($owner eq '');
7217: my ($ownername,$ownerdom);
7218: if ($owner =~ /^([^:]+):([^:]+)$/) {
7219: $ownername = $1;
7220: $ownerdom = $2;
7221: } else {
7222: $ownername = $owner;
7223: $ownerdom = $cdom;
7224: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7225: }
7226: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7227: if (defined($userdata) &&
1.609 raeburn 7228: !exists($$userdata{$owner})) {
7229: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7230: if (!grep(/^none$/,@{$seclists{$owner}})) {
7231: push(@{$seclists{$owner}},'none');
7232: }
7233: if (ref($statushash) eq 'HASH') {
7234: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7235: }
1.290 albertel 7236: }
1.279 raeburn 7237: }
7238: }
7239: }
1.419 raeburn 7240: foreach my $user (keys(%seclists)) {
7241: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7242: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7243: }
1.275 raeburn 7244: }
7245: return;
7246: }
7247:
1.288 raeburn 7248: sub get_user_info {
7249: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7250: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7251: &plainname($uname,$udom,'lastname');
1.291 albertel 7252: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7253: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7254: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7255: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7256: return;
7257: }
1.275 raeburn 7258:
1.472 raeburn 7259: ###############################################
7260:
7261: =pod
7262:
7263: =item * &get_user_quota()
7264:
7265: Retrieves quota assigned for storage of portfolio files for a user
7266:
7267: Incoming parameters:
7268: 1. user's username
7269: 2. user's domain
7270:
7271: Returns:
1.536 raeburn 7272: 1. Disk quota (in Mb) assigned to student.
7273: 2. (Optional) Type of setting: custom or default
7274: (individually assigned or default for user's
7275: institutional status).
7276: 3. (Optional) - User's institutional status (e.g., faculty, staff
7277: or student - types as defined in localenroll::inst_usertypes
7278: for user's domain, which determines default quota for user.
7279: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7280:
7281: If a value has been stored in the user's environment,
1.536 raeburn 7282: it will return that, otherwise it returns the maximal default
7283: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7284:
7285: =cut
7286:
7287: ###############################################
7288:
7289:
7290: sub get_user_quota {
7291: my ($uname,$udom) = @_;
1.536 raeburn 7292: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7293: if (!defined($udom)) {
7294: $udom = $env{'user.domain'};
7295: }
7296: if (!defined($uname)) {
7297: $uname = $env{'user.name'};
7298: }
7299: if (($udom eq '' || $uname eq '') ||
7300: ($udom eq 'public') && ($uname eq 'public')) {
7301: $quota = 0;
1.536 raeburn 7302: $quotatype = 'default';
7303: $defquota = 0;
1.472 raeburn 7304: } else {
1.536 raeburn 7305: my $inststatus;
1.472 raeburn 7306: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7307: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7308: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7309: } else {
1.536 raeburn 7310: my %userenv =
7311: &Apache::lonnet::get('environment',['portfolioquota',
7312: 'inststatus'],$udom,$uname);
1.472 raeburn 7313: my ($tmp) = keys(%userenv);
7314: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7315: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7316: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7317: } else {
7318: undef(%userenv);
7319: }
7320: }
1.536 raeburn 7321: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7322: if ($quota eq '') {
1.536 raeburn 7323: $quota = $defquota;
7324: $quotatype = 'default';
7325: } else {
7326: $quotatype = 'custom';
1.472 raeburn 7327: }
7328: }
1.536 raeburn 7329: if (wantarray) {
7330: return ($quota,$quotatype,$settingstatus,$defquota);
7331: } else {
7332: return $quota;
7333: }
1.472 raeburn 7334: }
7335:
7336: ###############################################
7337:
7338: =pod
7339:
7340: =item * &default_quota()
7341:
1.536 raeburn 7342: Retrieves default quota assigned for storage of user portfolio files,
7343: given an (optional) user's institutional status.
1.472 raeburn 7344:
7345: Incoming parameters:
7346: 1. domain
1.536 raeburn 7347: 2. (Optional) institutional status(es). This is a : separated list of
7348: status types (e.g., faculty, staff, student etc.)
7349: which apply to the user for whom the default is being retrieved.
7350: If the institutional status string in undefined, the domain
7351: default quota will be returned.
1.472 raeburn 7352:
7353: Returns:
7354: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7355: 2. (Optional) institutional type which determined the value of the
7356: default quota.
1.472 raeburn 7357:
7358: If a value has been stored in the domain's configuration db,
7359: it will return that, otherwise it returns 20 (for backwards
7360: compatibility with domains which have not set up a configuration
7361: db file; the original statically defined portfolio quota was 20 Mb).
7362:
1.536 raeburn 7363: If the user's status includes multiple types (e.g., staff and student),
7364: the largest default quota which applies to the user determines the
7365: default quota returned.
7366:
1.780 raeburn 7367: =back
7368:
1.472 raeburn 7369: =cut
7370:
7371: ###############################################
7372:
7373:
7374: sub default_quota {
1.536 raeburn 7375: my ($udom,$inststatus) = @_;
7376: my ($defquota,$settingstatus);
7377: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7378: ['quotas'],$udom);
7379: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7380: if ($inststatus ne '') {
1.765 raeburn 7381: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7382: foreach my $item (@statuses) {
1.711 raeburn 7383: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7384: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7385: if ($defquota eq '') {
7386: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7387: $settingstatus = $item;
7388: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7389: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7390: $settingstatus = $item;
7391: }
7392: }
7393: } else {
7394: if ($quotahash{'quotas'}{$item} ne '') {
7395: if ($defquota eq '') {
7396: $defquota = $quotahash{'quotas'}{$item};
7397: $settingstatus = $item;
7398: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7399: $defquota = $quotahash{'quotas'}{$item};
7400: $settingstatus = $item;
7401: }
1.536 raeburn 7402: }
7403: }
7404: }
7405: }
7406: if ($defquota eq '') {
1.711 raeburn 7407: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7408: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7409: } else {
7410: $defquota = $quotahash{'quotas'}{'default'};
7411: }
1.536 raeburn 7412: $settingstatus = 'default';
7413: }
7414: } else {
7415: $settingstatus = 'default';
7416: $defquota = 20;
7417: }
7418: if (wantarray) {
7419: return ($defquota,$settingstatus);
1.472 raeburn 7420: } else {
1.536 raeburn 7421: return $defquota;
1.472 raeburn 7422: }
7423: }
7424:
1.384 raeburn 7425: sub get_secgrprole_info {
7426: my ($cdom,$cnum,$needroles,$type) = @_;
7427: my %sections_count = &get_sections($cdom,$cnum);
7428: my @sections = (sort {$a <=> $b} keys(%sections_count));
7429: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7430: my @groups = sort(keys(%curr_groups));
7431: my $allroles = [];
7432: my $rolehash;
7433: my $accesshash = {
7434: active => 'Currently has access',
7435: future => 'Will have future access',
7436: previous => 'Previously had access',
7437: };
7438: if ($needroles) {
7439: $rolehash = {'all' => 'all'};
1.385 albertel 7440: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7441: if (&Apache::lonnet::error(%user_roles)) {
7442: undef(%user_roles);
7443: }
7444: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7445: my ($role)=split(/\:/,$item,2);
7446: if ($role eq 'cr') { next; }
7447: if ($role =~ /^cr/) {
7448: $$rolehash{$role} = (split('/',$role))[3];
7449: } else {
7450: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7451: }
7452: }
7453: foreach my $key (sort(keys(%{$rolehash}))) {
7454: push(@{$allroles},$key);
7455: }
7456: push (@{$allroles},'st');
7457: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7458: }
7459: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7460: }
7461:
1.555 raeburn 7462: sub user_picker {
1.627 raeburn 7463: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7464: my $currdom = $dom;
7465: my %curr_selected = (
7466: srchin => 'dom',
1.580 raeburn 7467: srchby => 'lastname',
1.555 raeburn 7468: );
7469: my $srchterm;
1.625 raeburn 7470: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7471: if ($srch->{'srchby'} ne '') {
7472: $curr_selected{'srchby'} = $srch->{'srchby'};
7473: }
7474: if ($srch->{'srchin'} ne '') {
7475: $curr_selected{'srchin'} = $srch->{'srchin'};
7476: }
7477: if ($srch->{'srchtype'} ne '') {
7478: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7479: }
7480: if ($srch->{'srchdomain'} ne '') {
7481: $currdom = $srch->{'srchdomain'};
7482: }
7483: $srchterm = $srch->{'srchterm'};
7484: }
7485: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7486: 'usr' => 'Search criteria',
1.563 raeburn 7487: 'doma' => 'Domain/institution to search',
1.558 albertel 7488: 'uname' => 'username',
7489: 'lastname' => 'last name',
1.555 raeburn 7490: 'lastfirst' => 'last name, first name',
1.558 albertel 7491: 'crs' => 'in this course',
1.576 raeburn 7492: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7493: 'alc' => 'all LON-CAPA',
1.573 raeburn 7494: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7495: 'exact' => 'is',
7496: 'contains' => 'contains',
1.569 raeburn 7497: 'begins' => 'begins with',
1.571 raeburn 7498: 'youm' => "You must include some text to search for.",
7499: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7500: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7501: 'yomc' => "You must choose a domain when using an institutional directory search.",
7502: 'ymcd' => "You must choose a domain when using a domain search.",
7503: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7504: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7505: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7506: );
1.563 raeburn 7507: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7508: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7509:
7510: my @srchins = ('crs','dom','alc','instd');
7511:
7512: foreach my $option (@srchins) {
7513: # FIXME 'alc' option unavailable until
7514: # loncreateuser::print_user_query_page()
7515: # has been completed.
7516: next if ($option eq 'alc');
7517: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7518: if ($curr_selected{'srchin'} eq $option) {
7519: $srchinsel .= '
7520: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7521: } else {
7522: $srchinsel .= '
7523: <option value="'.$option.'">'.$lt{$option}.'</option>';
7524: }
1.555 raeburn 7525: }
1.563 raeburn 7526: $srchinsel .= "\n </select>\n";
1.555 raeburn 7527:
7528: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7529: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7530: if ($curr_selected{'srchby'} eq $option) {
7531: $srchbysel .= '
7532: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7533: } else {
7534: $srchbysel .= '
7535: <option value="'.$option.'">'.$lt{$option}.'</option>';
7536: }
7537: }
7538: $srchbysel .= "\n </select>\n";
7539:
7540: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7541: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7542: if ($curr_selected{'srchtype'} eq $option) {
7543: $srchtypesel .= '
7544: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7545: } else {
7546: $srchtypesel .= '
7547: <option value="'.$option.'">'.$lt{$option}.'</option>';
7548: }
7549: }
7550: $srchtypesel .= "\n </select>\n";
7551:
1.558 albertel 7552: my ($newuserscript,$new_user_create);
1.556 raeburn 7553:
7554: if ($forcenewuser) {
1.576 raeburn 7555: if (ref($srch) eq 'HASH') {
7556: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7557: if ($cancreate) {
7558: $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>';
7559: } else {
1.799 bisitz 7560: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7561: my %usertypetext = (
7562: official => 'institutional',
7563: unofficial => 'non-institutional',
7564: );
1.799 bisitz 7565: $new_user_create = '<p class="LC_warning">'
7566: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7567: .' '
7568: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7569: ,'<a href="'.$helplink.'">','</a>')
7570: .'</p><br />';
1.627 raeburn 7571: }
1.576 raeburn 7572: }
7573: }
7574:
1.556 raeburn 7575: $newuserscript = <<"ENDSCRIPT";
7576:
1.570 raeburn 7577: function setSearch(createnew,callingForm) {
1.556 raeburn 7578: if (createnew == 1) {
1.570 raeburn 7579: for (var i=0; i<callingForm.srchby.length; i++) {
7580: if (callingForm.srchby.options[i].value == 'uname') {
7581: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7582: }
7583: }
1.570 raeburn 7584: for (var i=0; i<callingForm.srchin.length; i++) {
7585: if ( callingForm.srchin.options[i].value == 'dom') {
7586: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7587: }
7588: }
1.570 raeburn 7589: for (var i=0; i<callingForm.srchtype.length; i++) {
7590: if (callingForm.srchtype.options[i].value == 'exact') {
7591: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7592: }
7593: }
1.570 raeburn 7594: for (var i=0; i<callingForm.srchdomain.length; i++) {
7595: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7596: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7597: }
7598: }
7599: }
7600: }
7601: ENDSCRIPT
1.558 albertel 7602:
1.556 raeburn 7603: }
7604:
1.555 raeburn 7605: my $output = <<"END_BLOCK";
1.556 raeburn 7606: <script type="text/javascript">
1.824 bisitz 7607: // <![CDATA[
1.570 raeburn 7608: function validateEntry(callingForm) {
1.558 albertel 7609:
1.556 raeburn 7610: var checkok = 1;
1.558 albertel 7611: var srchin;
1.570 raeburn 7612: for (var i=0; i<callingForm.srchin.length; i++) {
7613: if ( callingForm.srchin[i].checked ) {
7614: srchin = callingForm.srchin[i].value;
1.558 albertel 7615: }
7616: }
7617:
1.570 raeburn 7618: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7619: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7620: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7621: var srchterm = callingForm.srchterm.value;
7622: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7623: var msg = "";
7624:
7625: if (srchterm == "") {
7626: checkok = 0;
1.571 raeburn 7627: msg += "$lt{'youm'}\\n";
1.556 raeburn 7628: }
7629:
1.569 raeburn 7630: if (srchtype== 'begins') {
7631: if (srchterm.length < 2) {
7632: checkok = 0;
1.571 raeburn 7633: msg += "$lt{'thte'}\\n";
1.569 raeburn 7634: }
7635: }
7636:
1.556 raeburn 7637: if (srchtype== 'contains') {
7638: if (srchterm.length < 3) {
7639: checkok = 0;
1.571 raeburn 7640: msg += "$lt{'thet'}\\n";
1.556 raeburn 7641: }
7642: }
7643: if (srchin == 'instd') {
7644: if (srchdomain == '') {
7645: checkok = 0;
1.571 raeburn 7646: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7647: }
7648: }
7649: if (srchin == 'dom') {
7650: if (srchdomain == '') {
7651: checkok = 0;
1.571 raeburn 7652: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7653: }
7654: }
7655: if (srchby == 'lastfirst') {
7656: if (srchterm.indexOf(",") == -1) {
7657: checkok = 0;
1.571 raeburn 7658: msg += "$lt{'whus'}\\n";
1.556 raeburn 7659: }
7660: if (srchterm.indexOf(",") == srchterm.length -1) {
7661: checkok = 0;
1.571 raeburn 7662: msg += "$lt{'whse'}\\n";
1.556 raeburn 7663: }
7664: }
7665: if (checkok == 0) {
1.571 raeburn 7666: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7667: return;
7668: }
7669: if (checkok == 1) {
1.570 raeburn 7670: callingForm.submit();
1.556 raeburn 7671: }
7672: }
7673:
7674: $newuserscript
7675:
1.824 bisitz 7676: // ]]>
1.556 raeburn 7677: </script>
1.558 albertel 7678:
7679: $new_user_create
7680:
1.555 raeburn 7681: <table>
1.558 albertel 7682: <tr>
1.573 raeburn 7683: <td>$lt{'doma'}:</td>
7684: <td>$domform</td>
7685: </td>
7686: </tr>
7687: <tr>
7688: <td>$lt{'usr'}:</td>
1.563 raeburn 7689: <td>$srchbysel
7690: $srchtypesel
7691: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7692: $srchinsel
1.563 raeburn 7693: </td>
7694: </tr>
1.555 raeburn 7695: </table>
7696: <br />
7697: END_BLOCK
1.558 albertel 7698:
1.555 raeburn 7699: return $output;
7700: }
7701:
1.612 raeburn 7702: sub user_rule_check {
1.615 raeburn 7703: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7704: my $response;
7705: if (ref($usershash) eq 'HASH') {
7706: foreach my $user (keys(%{$usershash})) {
7707: my ($uname,$udom) = split(/:/,$user);
7708: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7709: my ($id,$newuser);
1.612 raeburn 7710: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7711: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7712: $id = $usershash->{$user}->{'id'};
7713: }
7714: my $inst_response;
7715: if (ref($checks) eq 'HASH') {
7716: if (defined($checks->{'username'})) {
1.615 raeburn 7717: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7718: &Apache::lonnet::get_instuser($udom,$uname);
7719: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7720: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7721: &Apache::lonnet::get_instuser($udom,undef,$id);
7722: }
1.615 raeburn 7723: } else {
7724: ($inst_response,%{$inst_results->{$user}}) =
7725: &Apache::lonnet::get_instuser($udom,$uname);
7726: return;
1.612 raeburn 7727: }
1.615 raeburn 7728: if (!$got_rules->{$udom}) {
1.612 raeburn 7729: my %domconfig = &Apache::lonnet::get_dom('configuration',
7730: ['usercreation'],$udom);
7731: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7732: foreach my $item ('username','id') {
1.612 raeburn 7733: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7734: $$curr_rules{$udom}{$item} =
7735: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7736: }
7737: }
7738: }
1.615 raeburn 7739: $got_rules->{$udom} = 1;
1.585 raeburn 7740: }
1.612 raeburn 7741: foreach my $item (keys(%{$checks})) {
7742: if (ref($$curr_rules{$udom}) eq 'HASH') {
7743: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7744: if (@{$$curr_rules{$udom}{$item}} > 0) {
7745: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7746: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7747: if ($rule_check{$rule}) {
7748: $$rulematch{$user}{$item} = $rule;
7749: if ($inst_response eq 'ok') {
1.615 raeburn 7750: if (ref($inst_results) eq 'HASH') {
7751: if (ref($inst_results->{$user}) eq 'HASH') {
7752: if (keys(%{$inst_results->{$user}}) == 0) {
7753: $$alerts{$item}{$udom}{$uname} = 1;
7754: }
1.612 raeburn 7755: }
7756: }
1.615 raeburn 7757: }
7758: last;
1.585 raeburn 7759: }
7760: }
7761: }
7762: }
7763: }
7764: }
7765: }
7766: }
1.612 raeburn 7767: return;
7768: }
7769:
7770: sub user_rule_formats {
7771: my ($domain,$domdesc,$curr_rules,$check) = @_;
7772: my %text = (
7773: 'username' => 'Usernames',
7774: 'id' => 'IDs',
7775: );
7776: my $output;
7777: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7778: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7779: if (@{$ruleorder} > 0) {
7780: $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>';
7781: foreach my $rule (@{$ruleorder}) {
7782: if (ref($curr_rules) eq 'ARRAY') {
7783: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7784: if (ref($rules->{$rule}) eq 'HASH') {
7785: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7786: $rules->{$rule}{'desc'}.'</li>';
7787: }
7788: }
7789: }
7790: }
7791: $output .= '</ul>';
7792: }
7793: }
7794: return $output;
7795: }
7796:
7797: sub instrule_disallow_msg {
1.615 raeburn 7798: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7799: my $response;
7800: my %text = (
7801: item => 'username',
7802: items => 'usernames',
7803: match => 'matches',
7804: do => 'does',
7805: action => 'a username',
7806: one => 'one',
7807: );
7808: if ($count > 1) {
7809: $text{'item'} = 'usernames';
7810: $text{'match'} ='match';
7811: $text{'do'} = 'do';
7812: $text{'action'} = 'usernames',
7813: $text{'one'} = 'ones';
7814: }
7815: if ($checkitem eq 'id') {
7816: $text{'items'} = 'IDs';
7817: $text{'item'} = 'ID';
7818: $text{'action'} = 'an ID';
1.615 raeburn 7819: if ($count > 1) {
7820: $text{'item'} = 'IDs';
7821: $text{'action'} = 'IDs';
7822: }
1.612 raeburn 7823: }
1.674 bisitz 7824: $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 7825: if ($mode eq 'upload') {
7826: if ($checkitem eq 'username') {
7827: $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'}.");
7828: } elsif ($checkitem eq 'id') {
1.674 bisitz 7829: $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 7830: }
1.669 raeburn 7831: } elsif ($mode eq 'selfcreate') {
7832: if ($checkitem eq 'id') {
7833: $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.");
7834: }
1.615 raeburn 7835: } else {
7836: if ($checkitem eq 'username') {
7837: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7838: } elsif ($checkitem eq 'id') {
7839: $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.");
7840: }
1.612 raeburn 7841: }
7842: return $response;
1.585 raeburn 7843: }
7844:
1.624 raeburn 7845: sub personal_data_fieldtitles {
7846: my %fieldtitles = &Apache::lonlocal::texthash (
7847: id => 'Student/Employee ID',
7848: permanentemail => 'E-mail address',
7849: lastname => 'Last Name',
7850: firstname => 'First Name',
7851: middlename => 'Middle Name',
7852: generation => 'Generation',
7853: gen => 'Generation',
1.765 raeburn 7854: inststatus => 'Affiliation',
1.624 raeburn 7855: );
7856: return %fieldtitles;
7857: }
7858:
1.642 raeburn 7859: sub sorted_inst_types {
7860: my ($dom) = @_;
7861: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7862: my $othertitle = &mt('All users');
7863: if ($env{'request.course.id'}) {
1.668 raeburn 7864: $othertitle = &mt('Any users');
1.642 raeburn 7865: }
7866: my @types;
7867: if (ref($order) eq 'ARRAY') {
7868: @types = @{$order};
7869: }
7870: if (@types == 0) {
7871: if (ref($usertypes) eq 'HASH') {
7872: @types = sort(keys(%{$usertypes}));
7873: }
7874: }
7875: if (keys(%{$usertypes}) > 0) {
7876: $othertitle = &mt('Other users');
7877: }
7878: return ($othertitle,$usertypes,\@types);
7879: }
7880:
1.645 raeburn 7881: sub get_institutional_codes {
7882: my ($settings,$allcourses,$LC_code) = @_;
7883: # Get complete list of course sections to update
7884: my @currsections = ();
7885: my @currxlists = ();
7886: my $coursecode = $$settings{'internal.coursecode'};
7887:
7888: if ($$settings{'internal.sectionnums'} ne '') {
7889: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7890: }
7891:
7892: if ($$settings{'internal.crosslistings'} ne '') {
7893: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7894: }
7895:
7896: if (@currxlists > 0) {
7897: foreach (@currxlists) {
7898: if (m/^([^:]+):(\w*)$/) {
7899: unless (grep/^$1$/,@{$allcourses}) {
7900: push @{$allcourses},$1;
7901: $$LC_code{$1} = $2;
7902: }
7903: }
7904: }
7905: }
7906:
7907: if (@currsections > 0) {
7908: foreach (@currsections) {
7909: if (m/^(\w+):(\w*)$/) {
7910: my $sec = $coursecode.$1;
7911: my $lc_sec = $2;
7912: unless (grep/^$sec$/,@{$allcourses}) {
7913: push @{$allcourses},$sec;
7914: $$LC_code{$sec} = $lc_sec;
7915: }
7916: }
7917: }
7918: }
7919: return;
7920: }
7921:
1.112 bowersj2 7922: =pod
7923:
1.780 raeburn 7924: =head1 Slot Helpers
7925:
7926: =over 4
7927:
7928: =item * sorted_slots()
7929:
7930: Sorts an array of slot names in order of slot start time (earliest first).
7931:
7932: Inputs:
7933:
7934: =over 4
7935:
7936: slotsarr - Reference to array of unsorted slot names.
7937:
7938: slots - Reference to hash of hash, where outer hash keys are slot names.
7939:
1.549 albertel 7940: =back
7941:
1.780 raeburn 7942: Returns:
7943:
7944: =over 4
7945:
7946: sorted - An array of slot names sorted by the start time of the slot.
7947:
7948: =back
7949:
7950: =back
7951:
7952: =cut
7953:
7954:
7955: sub sorted_slots {
7956: my ($slotsarr,$slots) = @_;
7957: my @sorted;
7958: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7959: @sorted =
7960: sort {
7961: if (ref($slots->{$a}) && ref($slots->{$b})) {
7962: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7963: }
7964: if (ref($slots->{$a})) { return -1;}
7965: if (ref($slots->{$b})) { return 1;}
7966: return 0;
7967: } @{$slotsarr};
7968: }
7969: return @sorted;
7970: }
7971:
7972:
7973: =pod
7974:
1.549 albertel 7975: =head1 HTTP Helpers
7976:
7977: =over 4
7978:
1.648 raeburn 7979: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7980:
1.258 albertel 7981: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7982: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7983: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7984:
7985: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7986: $possible_names is an ref to an array of form element names. As an example:
7987: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7988: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7989:
7990: =cut
1.1 albertel 7991:
1.6 albertel 7992: sub get_unprocessed_cgi {
1.25 albertel 7993: my ($query,$possible_names)= @_;
1.26 matthew 7994: # $Apache::lonxml::debug=1;
1.356 albertel 7995: foreach my $pair (split(/&/,$query)) {
7996: my ($name, $value) = split(/=/,$pair);
1.369 www 7997: $name = &unescape($name);
1.25 albertel 7998: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7999: $value =~ tr/+/ /;
8000: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8001: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8002: }
1.16 harris41 8003: }
1.6 albertel 8004: }
8005:
1.112 bowersj2 8006: =pod
8007:
1.648 raeburn 8008: =item * &cacheheader()
1.112 bowersj2 8009:
8010: returns cache-controlling header code
8011:
8012: =cut
8013:
1.7 albertel 8014: sub cacheheader {
1.258 albertel 8015: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8016: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8017: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8018: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8019: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8020: return $output;
1.7 albertel 8021: }
8022:
1.112 bowersj2 8023: =pod
8024:
1.648 raeburn 8025: =item * &no_cache($r)
1.112 bowersj2 8026:
8027: specifies header code to not have cache
8028:
8029: =cut
8030:
1.9 albertel 8031: sub no_cache {
1.216 albertel 8032: my ($r) = @_;
8033: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8034: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8035: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8036: $r->no_cache(1);
8037: $r->header_out("Expires" => $date);
8038: $r->header_out("Pragma" => "no-cache");
1.123 www 8039: }
8040:
8041: sub content_type {
1.181 albertel 8042: my ($r,$type,$charset) = @_;
1.299 foxr 8043: if ($r) {
8044: # Note that printout.pl calls this with undef for $r.
8045: &no_cache($r);
8046: }
1.258 albertel 8047: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8048: unless ($charset) {
8049: $charset=&Apache::lonlocal::current_encoding;
8050: }
8051: if ($charset) { $type.='; charset='.$charset; }
8052: if ($r) {
8053: $r->content_type($type);
8054: } else {
8055: print("Content-type: $type\n\n");
8056: }
1.9 albertel 8057: }
1.25 albertel 8058:
1.112 bowersj2 8059: =pod
8060:
1.648 raeburn 8061: =item * &add_to_env($name,$value)
1.112 bowersj2 8062:
1.258 albertel 8063: adds $name to the %env hash with value
1.112 bowersj2 8064: $value, if $name already exists, the entry is converted to an array
8065: reference and $value is added to the array.
8066:
8067: =cut
8068:
1.25 albertel 8069: sub add_to_env {
8070: my ($name,$value)=@_;
1.258 albertel 8071: if (defined($env{$name})) {
8072: if (ref($env{$name})) {
1.25 albertel 8073: #already have multiple values
1.258 albertel 8074: push(@{ $env{$name} },$value);
1.25 albertel 8075: } else {
8076: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8077: my $first=$env{$name};
8078: undef($env{$name});
8079: push(@{ $env{$name} },$first,$value);
1.25 albertel 8080: }
8081: } else {
1.258 albertel 8082: $env{$name}=$value;
1.25 albertel 8083: }
1.31 albertel 8084: }
1.149 albertel 8085:
8086: =pod
8087:
1.648 raeburn 8088: =item * &get_env_multiple($name)
1.149 albertel 8089:
1.258 albertel 8090: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8091: values may be defined and end up as an array ref.
8092:
8093: returns an array of values
8094:
8095: =cut
8096:
8097: sub get_env_multiple {
8098: my ($name) = @_;
8099: my @values;
1.258 albertel 8100: if (defined($env{$name})) {
1.149 albertel 8101: # exists is it an array
1.258 albertel 8102: if (ref($env{$name})) {
8103: @values=@{ $env{$name} };
1.149 albertel 8104: } else {
1.258 albertel 8105: $values[0]=$env{$name};
1.149 albertel 8106: }
8107: }
8108: return(@values);
8109: }
8110:
1.660 raeburn 8111: sub ask_for_embedded_content {
8112: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8113: my $upload_output = '
8114: <form name="upload_embedded" action="'.$actionurl.'"
8115: method="post" enctype="multipart/form-data">';
8116: $upload_output .= $state;
1.661 raeburn 8117: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8118:
8119: my $num = 0;
8120: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8121: $upload_output .= &start_data_table_row().
8122: '<td>'.$embed_file.'</td><td>';
8123: if ($args->{'ignore_remote_references'}
8124: && $embed_file =~ m{^\w+://}) {
8125: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8126: } elsif ($args->{'error_on_invalid_names'}
8127: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8128:
8129: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8130:
8131: } else {
8132: $upload_output .='
1.661 raeburn 8133: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8134: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8135: my $attrib = join(':',@{$$allfiles{$embed_file}});
8136: $upload_output .=
8137: "\n\t\t".
8138: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8139: $attrib.'" />';
8140: if (exists($$codebase{$embed_file})) {
8141: $upload_output .=
8142: "\n\t\t".
8143: '<input name="codebase_'.$num.'" type="hidden" value="'.
8144: &escape($$codebase{$embed_file}).'" />';
8145: }
8146: }
8147: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8148: $num++;
8149: }
8150: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8151: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8152: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8153: '.&mt('(only files for which a location has been provided will be uploaded)').'
8154: </form>';
8155: return $upload_output;
8156: }
8157:
1.661 raeburn 8158: sub upload_embedded {
8159: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8160: $current_disk_usage) = @_;
8161: my $output;
8162: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8163: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8164: my $orig_uploaded_filename =
8165: $env{'form.embedded_item_'.$i.'.filename'};
8166:
8167: $env{'form.embedded_orig_'.$i} =
8168: &unescape($env{'form.embedded_orig_'.$i});
8169: my ($path,$fname) =
8170: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8171: # no path, whole string is fname
8172: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8173:
8174: $path = $env{'form.currentpath'}.$path;
8175: $fname = &Apache::lonnet::clean_filename($fname);
8176: # See if there is anything left
8177: next if ($fname eq '');
8178:
8179: # Check if file already exists as a file or directory.
8180: my ($state,$msg);
8181: if ($context eq 'portfolio') {
8182: my $port_path = $dirpath;
8183: if ($group ne '') {
8184: $port_path = "groups/$group/$port_path";
8185: }
8186: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8187: $dir_root,$port_path,$disk_quota,
8188: $current_disk_usage,$uname,$udom);
8189: if ($state eq 'will_exceed_quota'
8190: || $state eq 'file_locked'
8191: || $state eq 'file_exists' ) {
8192: $output .= $msg;
8193: next;
8194: }
8195: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8196: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8197: if ($state eq 'exists') {
8198: $output .= $msg;
8199: next;
8200: }
8201: }
8202: # Check if extension is valid
8203: if (($fname =~ /\.(\w+)$/) &&
8204: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8205: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8206: next;
8207: } elsif (($fname =~ /\.(\w+)$/) &&
8208: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8209: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8210: next;
8211: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8212: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8213: next;
8214: }
8215:
8216: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8217: if ($context eq 'portfolio') {
8218: my $result=
8219: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8220: $dirpath.$path);
8221: if ($result !~ m|^/uploaded/|) {
8222: $output .= '<span class="LC_error">'
8223: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8224: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8225: .'</span><br />';
8226: next;
8227: } else {
8228: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8229: $path.$fname.'</span>').'</p>';
8230: }
8231: } else {
8232: # Save the file
8233: my $target = $env{'form.embedded_item_'.$i};
8234: my $fullpath = $dir_root.$dirpath.'/'.$path;
8235: my $dest = $fullpath.$fname;
8236: my $url = $url_root.$dirpath.'/'.$path.$fname;
8237: my @parts=split(/\//,$fullpath);
8238: my $count;
8239: my $filepath = $dir_root;
8240: for ($count=4;$count<=$#parts;$count++) {
8241: $filepath .= "/$parts[$count]";
8242: if ((-e $filepath)!=1) {
8243: mkdir($filepath,0770);
8244: }
8245: }
8246: my $fh;
8247: if (!open($fh,'>'.$dest)) {
8248: &Apache::lonnet::logthis('Failed to create '.$dest);
8249: $output .= '<span class="LC_error">'.
8250: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8251: '</span><br />';
8252: } else {
8253: if (!print $fh $env{'form.embedded_item_'.$i}) {
8254: &Apache::lonnet::logthis('Failed to write to '.$dest);
8255: $output .= '<span class="LC_error">'.
8256: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8257: '</span><br />';
8258: } else {
8259: if ($context eq 'testbank') {
8260: $output .= &mt('Embedded file uploaded successfully:').
8261: ' <a href="'.$url.'">'.
8262: $orig_uploaded_filename.'</a><br />';
8263: } else {
1.705 tempelho 8264: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8265: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8266: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8267: }
8268: }
8269: close($fh);
8270: }
8271: }
8272: }
8273: return $output;
8274: }
8275:
8276: sub check_for_existing {
8277: my ($path,$fname,$element) = @_;
8278: my ($state,$msg);
8279: if (-d $path.'/'.$fname) {
8280: $state = 'exists';
8281: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8282: } elsif (-e $path.'/'.$fname) {
8283: $state = 'exists';
8284: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8285: }
8286: if ($state eq 'exists') {
8287: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8288: }
8289: return ($state,$msg);
8290: }
8291:
8292: sub check_for_upload {
8293: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8294: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8295: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8296: my $getpropath = 1;
8297: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8298: $getpropath);
8299: my $found_file = 0;
8300: my $locked_file = 0;
8301: foreach my $line (@dir_list) {
8302: my ($file_name)=split(/\&/,$line,2);
8303: if ($file_name eq $fname){
8304: $file_name = $path.$file_name;
8305: if ($group ne '') {
8306: $file_name = $group.$file_name;
8307: }
8308: $found_file = 1;
8309: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8310: $locked_file = 1;
8311: }
8312: }
8313: }
8314: if (($current_disk_usage + $filesize) > $disk_quota){
8315: my $msg = '<span class="LC_error">'.
8316: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8317: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8318: return ('will_exceed_quota',$msg);
8319: } elsif ($found_file) {
8320: if ($locked_file) {
8321: my $msg = '<span class="LC_error">';
8322: $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>');
8323: $msg .= '</span><br />';
8324: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8325: return ('file_locked',$msg);
8326: } else {
8327: my $msg = '<span class="LC_error">';
8328: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
8329: $msg .= '</span>';
8330: $msg .= '<br />';
8331: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8332: return ('file_exists',$msg);
8333: }
8334: }
8335: }
8336:
1.31 albertel 8337:
1.41 ng 8338: =pod
1.45 matthew 8339:
1.464 albertel 8340: =back
1.41 ng 8341:
1.112 bowersj2 8342: =head1 CSV Upload/Handling functions
1.38 albertel 8343:
1.41 ng 8344: =over 4
8345:
1.648 raeburn 8346: =item * &upfile_store($r)
1.41 ng 8347:
8348: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8349: needs $env{'form.upfile'}
1.41 ng 8350: returns $datatoken to be put into hidden field
8351:
8352: =cut
1.31 albertel 8353:
8354: sub upfile_store {
8355: my $r=shift;
1.258 albertel 8356: $env{'form.upfile'}=~s/\r/\n/gs;
8357: $env{'form.upfile'}=~s/\f/\n/gs;
8358: $env{'form.upfile'}=~s/\n+/\n/gs;
8359: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8360:
1.258 albertel 8361: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8362: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8363: {
1.158 raeburn 8364: my $datafile = $r->dir_config('lonDaemons').
8365: '/tmp/'.$datatoken.'.tmp';
8366: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8367: print $fh $env{'form.upfile'};
1.158 raeburn 8368: close($fh);
8369: }
1.31 albertel 8370: }
8371: return $datatoken;
8372: }
8373:
1.56 matthew 8374: =pod
8375:
1.648 raeburn 8376: =item * &load_tmp_file($r)
1.41 ng 8377:
8378: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8379: needs $env{'form.datatoken'},
8380: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8381:
8382: =cut
1.31 albertel 8383:
8384: sub load_tmp_file {
8385: my $r=shift;
8386: my @studentdata=();
8387: {
1.158 raeburn 8388: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8389: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8390: if ( open(my $fh,"<$studentfile") ) {
8391: @studentdata=<$fh>;
8392: close($fh);
8393: }
1.31 albertel 8394: }
1.258 albertel 8395: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8396: }
8397:
1.56 matthew 8398: =pod
8399:
1.648 raeburn 8400: =item * &upfile_record_sep()
1.41 ng 8401:
8402: Separate uploaded file into records
8403: returns array of records,
1.258 albertel 8404: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8405:
8406: =cut
1.31 albertel 8407:
8408: sub upfile_record_sep {
1.258 albertel 8409: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8410: } else {
1.248 albertel 8411: my @records;
1.258 albertel 8412: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8413: if ($line=~/^\s*$/) { next; }
8414: push(@records,$line);
8415: }
8416: return @records;
1.31 albertel 8417: }
8418: }
8419:
1.56 matthew 8420: =pod
8421:
1.648 raeburn 8422: =item * &record_sep($record)
1.41 ng 8423:
1.258 albertel 8424: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8425:
8426: =cut
8427:
1.263 www 8428: sub takeleft {
8429: my $index=shift;
8430: return substr('0000'.$index,-4,4);
8431: }
8432:
1.31 albertel 8433: sub record_sep {
8434: my $record=shift;
8435: my %components=();
1.258 albertel 8436: if ($env{'form.upfiletype'} eq 'xml') {
8437: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8438: my $i=0;
1.356 albertel 8439: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8440: $field=~s/^(\"|\')//;
8441: $field=~s/(\"|\')$//;
1.263 www 8442: $components{&takeleft($i)}=$field;
1.31 albertel 8443: $i++;
8444: }
1.258 albertel 8445: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8446: my $i=0;
1.356 albertel 8447: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8448: $field=~s/^(\"|\')//;
8449: $field=~s/(\"|\')$//;
1.263 www 8450: $components{&takeleft($i)}=$field;
1.31 albertel 8451: $i++;
8452: }
8453: } else {
1.561 www 8454: my $separator=',';
1.480 banghart 8455: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8456: $separator=';';
1.480 banghart 8457: }
1.31 albertel 8458: my $i=0;
1.561 www 8459: # the character we are looking for to indicate the end of a quote or a record
8460: my $looking_for=$separator;
8461: # do not add the characters to the fields
8462: my $ignore=0;
8463: # we just encountered a separator (or the beginning of the record)
8464: my $just_found_separator=1;
8465: # store the field we are working on here
8466: my $field='';
8467: # work our way through all characters in record
8468: foreach my $character ($record=~/(.)/g) {
8469: if ($character eq $looking_for) {
8470: if ($character ne $separator) {
8471: # Found the end of a quote, again looking for separator
8472: $looking_for=$separator;
8473: $ignore=1;
8474: } else {
8475: # Found a separator, store away what we got
8476: $components{&takeleft($i)}=$field;
8477: $i++;
8478: $just_found_separator=1;
8479: $ignore=0;
8480: $field='';
8481: }
8482: next;
8483: }
8484: # single or double quotation marks after a separator indicate beginning of a quote
8485: # we are now looking for the end of the quote and need to ignore separators
8486: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8487: $looking_for=$character;
8488: next;
8489: }
8490: # ignore would be true after we reached the end of a quote
8491: if ($ignore) { next; }
8492: if (($just_found_separator) && ($character=~/\s/)) { next; }
8493: $field.=$character;
8494: $just_found_separator=0;
1.31 albertel 8495: }
1.561 www 8496: # catch the very last entry, since we never encountered the separator
8497: $components{&takeleft($i)}=$field;
1.31 albertel 8498: }
8499: return %components;
8500: }
8501:
1.144 matthew 8502: ######################################################
8503: ######################################################
8504:
1.56 matthew 8505: =pod
8506:
1.648 raeburn 8507: =item * &upfile_select_html()
1.41 ng 8508:
1.144 matthew 8509: Return HTML code to select a file from the users machine and specify
8510: the file type.
1.41 ng 8511:
8512: =cut
8513:
1.144 matthew 8514: ######################################################
8515: ######################################################
1.31 albertel 8516: sub upfile_select_html {
1.144 matthew 8517: my %Types = (
8518: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8519: semisv => &mt('Semicolon separated values'),
1.144 matthew 8520: space => &mt('Space separated'),
8521: tab => &mt('Tabulator separated'),
8522: # xml => &mt('HTML/XML'),
8523: );
8524: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8525: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8526: foreach my $type (sort(keys(%Types))) {
8527: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8528: }
8529: $Str .= "</select>\n";
8530: return $Str;
1.31 albertel 8531: }
8532:
1.301 albertel 8533: sub get_samples {
8534: my ($records,$toget) = @_;
8535: my @samples=({});
8536: my $got=0;
8537: foreach my $rec (@$records) {
8538: my %temp = &record_sep($rec);
8539: if (! grep(/\S/, values(%temp))) { next; }
8540: if (%temp) {
8541: $samples[$got]=\%temp;
8542: $got++;
8543: if ($got == $toget) { last; }
8544: }
8545: }
8546: return \@samples;
8547: }
8548:
1.144 matthew 8549: ######################################################
8550: ######################################################
8551:
1.56 matthew 8552: =pod
8553:
1.648 raeburn 8554: =item * &csv_print_samples($r,$records)
1.41 ng 8555:
8556: Prints a table of sample values from each column uploaded $r is an
8557: Apache Request ref, $records is an arrayref from
8558: &Apache::loncommon::upfile_record_sep
8559:
8560: =cut
8561:
1.144 matthew 8562: ######################################################
8563: ######################################################
1.31 albertel 8564: sub csv_print_samples {
8565: my ($r,$records) = @_;
1.662 bisitz 8566: my $samples = &get_samples($records,5);
1.301 albertel 8567:
1.594 raeburn 8568: $r->print(&mt('Samples').'<br />'.&start_data_table().
8569: &start_data_table_header_row());
1.356 albertel 8570: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8571: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8572: $r->print(&end_data_table_header_row());
1.301 albertel 8573: foreach my $hash (@$samples) {
1.594 raeburn 8574: $r->print(&start_data_table_row());
1.356 albertel 8575: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8576: $r->print('<td>');
1.356 albertel 8577: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8578: $r->print('</td>');
8579: }
1.594 raeburn 8580: $r->print(&end_data_table_row());
1.31 albertel 8581: }
1.594 raeburn 8582: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8583: }
8584:
1.144 matthew 8585: ######################################################
8586: ######################################################
8587:
1.56 matthew 8588: =pod
8589:
1.648 raeburn 8590: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8591:
8592: Prints a table to create associations between values and table columns.
1.144 matthew 8593:
1.41 ng 8594: $r is an Apache Request ref,
8595: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8596: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8597:
8598: =cut
8599:
1.144 matthew 8600: ######################################################
8601: ######################################################
1.31 albertel 8602: sub csv_print_select_table {
8603: my ($r,$records,$d) = @_;
1.301 albertel 8604: my $i=0;
8605: my $samples = &get_samples($records,1);
1.144 matthew 8606: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8607: &start_data_table().&start_data_table_header_row().
1.144 matthew 8608: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8609: '<th>'.&mt('Column').'</th>'.
8610: &end_data_table_header_row()."\n");
1.356 albertel 8611: foreach my $array_ref (@$d) {
8612: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8613: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8614:
8615: $r->print('<td><select name=f'.$i.
1.32 matthew 8616: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8617: $r->print('<option value="none"></option>');
1.356 albertel 8618: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8619: $r->print('<option value="'.$sample.'"'.
8620: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8621: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8622: }
1.594 raeburn 8623: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8624: $i++;
8625: }
1.594 raeburn 8626: $r->print(&end_data_table());
1.31 albertel 8627: $i--;
8628: return $i;
8629: }
1.56 matthew 8630:
1.144 matthew 8631: ######################################################
8632: ######################################################
8633:
1.56 matthew 8634: =pod
1.31 albertel 8635:
1.648 raeburn 8636: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8637:
8638: Prints a table of sample values from the upload and can make associate samples to internal names.
8639:
8640: $r is an Apache Request ref,
8641: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8642: $d is an array of 2 element arrays (internal name, displayed name)
8643:
8644: =cut
8645:
1.144 matthew 8646: ######################################################
8647: ######################################################
1.31 albertel 8648: sub csv_samples_select_table {
8649: my ($r,$records,$d) = @_;
8650: my $i=0;
1.144 matthew 8651: #
1.662 bisitz 8652: my $max_samples = 5;
8653: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8654: $r->print(&start_data_table().
8655: &start_data_table_header_row().'<th>'.
8656: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8657: &end_data_table_header_row());
1.301 albertel 8658:
8659: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8660: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8661: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8662: foreach my $option (@$d) {
8663: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8664: $r->print('<option value="'.$value.'"'.
1.253 albertel 8665: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8666: $display.'</option>');
1.31 albertel 8667: }
8668: $r->print('</select></td><td>');
1.662 bisitz 8669: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8670: if (defined($samples->[$line]{$key})) {
8671: $r->print($samples->[$line]{$key}."<br />\n");
8672: }
8673: }
1.594 raeburn 8674: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8675: $i++;
8676: }
1.594 raeburn 8677: $r->print(&end_data_table());
1.31 albertel 8678: $i--;
8679: return($i);
1.115 matthew 8680: }
8681:
1.144 matthew 8682: ######################################################
8683: ######################################################
8684:
1.115 matthew 8685: =pod
8686:
1.648 raeburn 8687: =item * &clean_excel_name($name)
1.115 matthew 8688:
8689: Returns a replacement for $name which does not contain any illegal characters.
8690:
8691: =cut
8692:
1.144 matthew 8693: ######################################################
8694: ######################################################
1.115 matthew 8695: sub clean_excel_name {
8696: my ($name) = @_;
8697: $name =~ s/[:\*\?\/\\]//g;
8698: if (length($name) > 31) {
8699: $name = substr($name,0,31);
8700: }
8701: return $name;
1.25 albertel 8702: }
1.84 albertel 8703:
1.85 albertel 8704: =pod
8705:
1.648 raeburn 8706: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8707:
8708: Returns either 1 or undef
8709:
8710: 1 if the part is to be hidden, undef if it is to be shown
8711:
8712: Arguments are:
8713:
8714: $id the id of the part to be checked
8715: $symb, optional the symb of the resource to check
8716: $udom, optional the domain of the user to check for
8717: $uname, optional the username of the user to check for
8718:
8719: =cut
1.84 albertel 8720:
8721: sub check_if_partid_hidden {
8722: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8723: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8724: $symb,$udom,$uname);
1.141 albertel 8725: my $truth=1;
8726: #if the string starts with !, then the list is the list to show not hide
8727: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8728: my @hiddenlist=split(/,/,$hiddenparts);
8729: foreach my $checkid (@hiddenlist) {
1.141 albertel 8730: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8731: }
1.141 albertel 8732: return !$truth;
1.84 albertel 8733: }
1.127 matthew 8734:
1.138 matthew 8735:
8736: ############################################################
8737: ############################################################
8738:
8739: =pod
8740:
1.157 matthew 8741: =back
8742:
1.138 matthew 8743: =head1 cgi-bin script and graphing routines
8744:
1.157 matthew 8745: =over 4
8746:
1.648 raeburn 8747: =item * &get_cgi_id()
1.138 matthew 8748:
8749: Inputs: none
8750:
8751: Returns an id which can be used to pass environment variables
8752: to various cgi-bin scripts. These environment variables will
8753: be removed from the users environment after a given time by
8754: the routine &Apache::lonnet::transfer_profile_to_env.
8755:
8756: =cut
8757:
8758: ############################################################
8759: ############################################################
1.152 albertel 8760: my $uniq=0;
1.136 matthew 8761: sub get_cgi_id {
1.154 albertel 8762: $uniq=($uniq+1)%100000;
1.280 albertel 8763: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8764: }
8765:
1.127 matthew 8766: ############################################################
8767: ############################################################
8768:
8769: =pod
8770:
1.648 raeburn 8771: =item * &DrawBarGraph()
1.127 matthew 8772:
1.138 matthew 8773: Facilitates the plotting of data in a (stacked) bar graph.
8774: Puts plot definition data into the users environment in order for
8775: graph.png to plot it. Returns an <img> tag for the plot.
8776: The bars on the plot are labeled '1','2',...,'n'.
8777:
8778: Inputs:
8779:
8780: =over 4
8781:
8782: =item $Title: string, the title of the plot
8783:
8784: =item $xlabel: string, text describing the X-axis of the plot
8785:
8786: =item $ylabel: string, text describing the Y-axis of the plot
8787:
8788: =item $Max: scalar, the maximum Y value to use in the plot
8789: If $Max is < any data point, the graph will not be rendered.
8790:
1.140 matthew 8791: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8792: they are plotted. If undefined, default values will be used.
8793:
1.178 matthew 8794: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8795:
1.138 matthew 8796: =item @Values: An array of array references. Each array reference holds data
8797: to be plotted in a stacked bar chart.
8798:
1.239 matthew 8799: =item If the final element of @Values is a hash reference the key/value
8800: pairs will be added to the graph definition.
8801:
1.138 matthew 8802: =back
8803:
8804: Returns:
8805:
8806: An <img> tag which references graph.png and the appropriate identifying
8807: information for the plot.
8808:
1.127 matthew 8809: =cut
8810:
8811: ############################################################
8812: ############################################################
1.134 matthew 8813: sub DrawBarGraph {
1.178 matthew 8814: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8815: #
8816: if (! defined($colors)) {
8817: $colors = ['#33ff00',
8818: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8819: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8820: ];
8821: }
1.228 matthew 8822: my $extra_settings = {};
8823: if (ref($Values[-1]) eq 'HASH') {
8824: $extra_settings = pop(@Values);
8825: }
1.127 matthew 8826: #
1.136 matthew 8827: my $identifier = &get_cgi_id();
8828: my $id = 'cgi.'.$identifier;
1.129 matthew 8829: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8830: return '';
8831: }
1.225 matthew 8832: #
8833: my @Labels;
8834: if (defined($labels)) {
8835: @Labels = @$labels;
8836: } else {
8837: for (my $i=0;$i<@{$Values[0]};$i++) {
8838: push (@Labels,$i+1);
8839: }
8840: }
8841: #
1.129 matthew 8842: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8843: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8844: my %ValuesHash;
8845: my $NumSets=1;
8846: foreach my $array (@Values) {
8847: next if (! ref($array));
1.136 matthew 8848: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8849: join(',',@$array);
1.129 matthew 8850: }
1.127 matthew 8851: #
1.136 matthew 8852: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8853: if ($NumBars < 3) {
8854: $width = 120+$NumBars*32;
1.220 matthew 8855: $xskip = 1;
1.225 matthew 8856: $bar_width = 30;
8857: } elsif ($NumBars < 5) {
8858: $width = 120+$NumBars*20;
8859: $xskip = 1;
8860: $bar_width = 20;
1.220 matthew 8861: } elsif ($NumBars < 10) {
1.136 matthew 8862: $width = 120+$NumBars*15;
8863: $xskip = 1;
8864: $bar_width = 15;
8865: } elsif ($NumBars <= 25) {
8866: $width = 120+$NumBars*11;
8867: $xskip = 5;
8868: $bar_width = 8;
8869: } elsif ($NumBars <= 50) {
8870: $width = 120+$NumBars*8;
8871: $xskip = 5;
8872: $bar_width = 4;
8873: } else {
8874: $width = 120+$NumBars*8;
8875: $xskip = 5;
8876: $bar_width = 4;
8877: }
8878: #
1.137 matthew 8879: $Max = 1 if ($Max < 1);
8880: if ( int($Max) < $Max ) {
8881: $Max++;
8882: $Max = int($Max);
8883: }
1.127 matthew 8884: $Title = '' if (! defined($Title));
8885: $xlabel = '' if (! defined($xlabel));
8886: $ylabel = '' if (! defined($ylabel));
1.369 www 8887: $ValuesHash{$id.'.title'} = &escape($Title);
8888: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8889: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8890: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8891: $ValuesHash{$id.'.NumBars'} = $NumBars;
8892: $ValuesHash{$id.'.NumSets'} = $NumSets;
8893: $ValuesHash{$id.'.PlotType'} = 'bar';
8894: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8895: $ValuesHash{$id.'.height'} = $height;
8896: $ValuesHash{$id.'.width'} = $width;
8897: $ValuesHash{$id.'.xskip'} = $xskip;
8898: $ValuesHash{$id.'.bar_width'} = $bar_width;
8899: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8900: #
1.228 matthew 8901: # Deal with other parameters
8902: while (my ($key,$value) = each(%$extra_settings)) {
8903: $ValuesHash{$id.'.'.$key} = $value;
8904: }
8905: #
1.646 raeburn 8906: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8907: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8908: }
8909:
8910: ############################################################
8911: ############################################################
8912:
8913: =pod
8914:
1.648 raeburn 8915: =item * &DrawXYGraph()
1.137 matthew 8916:
1.138 matthew 8917: Facilitates the plotting of data in an XY graph.
8918: Puts plot definition data into the users environment in order for
8919: graph.png to plot it. Returns an <img> tag for the plot.
8920:
8921: Inputs:
8922:
8923: =over 4
8924:
8925: =item $Title: string, the title of the plot
8926:
8927: =item $xlabel: string, text describing the X-axis of the plot
8928:
8929: =item $ylabel: string, text describing the Y-axis of the plot
8930:
8931: =item $Max: scalar, the maximum Y value to use in the plot
8932: If $Max is < any data point, the graph will not be rendered.
8933:
8934: =item $colors: Array ref containing the hex color codes for the data to be
8935: plotted in. If undefined, default values will be used.
8936:
8937: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8938:
8939: =item $Ydata: Array ref containing Array refs.
1.185 www 8940: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8941:
8942: =item %Values: hash indicating or overriding any default values which are
8943: passed to graph.png.
8944: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8945:
8946: =back
8947:
8948: Returns:
8949:
8950: An <img> tag which references graph.png and the appropriate identifying
8951: information for the plot.
8952:
1.137 matthew 8953: =cut
8954:
8955: ############################################################
8956: ############################################################
8957: sub DrawXYGraph {
8958: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8959: #
8960: # Create the identifier for the graph
8961: my $identifier = &get_cgi_id();
8962: my $id = 'cgi.'.$identifier;
8963: #
8964: $Title = '' if (! defined($Title));
8965: $xlabel = '' if (! defined($xlabel));
8966: $ylabel = '' if (! defined($ylabel));
8967: my %ValuesHash =
8968: (
1.369 www 8969: $id.'.title' => &escape($Title),
8970: $id.'.xlabel' => &escape($xlabel),
8971: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8972: $id.'.y_max_value'=> $Max,
8973: $id.'.labels' => join(',',@$Xlabels),
8974: $id.'.PlotType' => 'XY',
8975: );
8976: #
8977: if (defined($colors) && ref($colors) eq 'ARRAY') {
8978: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8979: }
8980: #
8981: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8982: return '';
8983: }
8984: my $NumSets=1;
1.138 matthew 8985: foreach my $array (@{$Ydata}){
1.137 matthew 8986: next if (! ref($array));
8987: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8988: }
1.138 matthew 8989: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8990: #
8991: # Deal with other parameters
8992: while (my ($key,$value) = each(%Values)) {
8993: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8994: }
8995: #
1.646 raeburn 8996: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8997: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8998: }
8999:
9000: ############################################################
9001: ############################################################
9002:
9003: =pod
9004:
1.648 raeburn 9005: =item * &DrawXYYGraph()
1.138 matthew 9006:
9007: Facilitates the plotting of data in an XY graph with two Y axes.
9008: Puts plot definition data into the users environment in order for
9009: graph.png to plot it. Returns an <img> tag for the plot.
9010:
9011: Inputs:
9012:
9013: =over 4
9014:
9015: =item $Title: string, the title of the plot
9016:
9017: =item $xlabel: string, text describing the X-axis of the plot
9018:
9019: =item $ylabel: string, text describing the Y-axis of the plot
9020:
9021: =item $colors: Array ref containing the hex color codes for the data to be
9022: plotted in. If undefined, default values will be used.
9023:
9024: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9025:
9026: =item $Ydata1: The first data set
9027:
9028: =item $Min1: The minimum value of the left Y-axis
9029:
9030: =item $Max1: The maximum value of the left Y-axis
9031:
9032: =item $Ydata2: The second data set
9033:
9034: =item $Min2: The minimum value of the right Y-axis
9035:
9036: =item $Max2: The maximum value of the left Y-axis
9037:
9038: =item %Values: hash indicating or overriding any default values which are
9039: passed to graph.png.
9040: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9041:
9042: =back
9043:
9044: Returns:
9045:
9046: An <img> tag which references graph.png and the appropriate identifying
9047: information for the plot.
1.136 matthew 9048:
9049: =cut
9050:
9051: ############################################################
9052: ############################################################
1.137 matthew 9053: sub DrawXYYGraph {
9054: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9055: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9056: #
9057: # Create the identifier for the graph
9058: my $identifier = &get_cgi_id();
9059: my $id = 'cgi.'.$identifier;
9060: #
9061: $Title = '' if (! defined($Title));
9062: $xlabel = '' if (! defined($xlabel));
9063: $ylabel = '' if (! defined($ylabel));
9064: my %ValuesHash =
9065: (
1.369 www 9066: $id.'.title' => &escape($Title),
9067: $id.'.xlabel' => &escape($xlabel),
9068: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9069: $id.'.labels' => join(',',@$Xlabels),
9070: $id.'.PlotType' => 'XY',
9071: $id.'.NumSets' => 2,
1.137 matthew 9072: $id.'.two_axes' => 1,
9073: $id.'.y1_max_value' => $Max1,
9074: $id.'.y1_min_value' => $Min1,
9075: $id.'.y2_max_value' => $Max2,
9076: $id.'.y2_min_value' => $Min2,
1.136 matthew 9077: );
9078: #
1.137 matthew 9079: if (defined($colors) && ref($colors) eq 'ARRAY') {
9080: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9081: }
9082: #
9083: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9084: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9085: return '';
9086: }
9087: my $NumSets=1;
1.137 matthew 9088: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9089: next if (! ref($array));
9090: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9091: }
9092: #
9093: # Deal with other parameters
9094: while (my ($key,$value) = each(%Values)) {
9095: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9096: }
9097: #
1.646 raeburn 9098: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9099: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9100: }
9101:
9102: ############################################################
9103: ############################################################
9104:
9105: =pod
9106:
1.157 matthew 9107: =back
9108:
1.139 matthew 9109: =head1 Statistics helper routines?
9110:
9111: Bad place for them but what the hell.
9112:
1.157 matthew 9113: =over 4
9114:
1.648 raeburn 9115: =item * &chartlink()
1.139 matthew 9116:
9117: Returns a link to the chart for a specific student.
9118:
9119: Inputs:
9120:
9121: =over 4
9122:
9123: =item $linktext: The text of the link
9124:
9125: =item $sname: The students username
9126:
9127: =item $sdomain: The students domain
9128:
9129: =back
9130:
1.157 matthew 9131: =back
9132:
1.139 matthew 9133: =cut
9134:
9135: ############################################################
9136: ############################################################
9137: sub chartlink {
9138: my ($linktext, $sname, $sdomain) = @_;
9139: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9140: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9141: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9142: '">'.$linktext.'</a>';
1.153 matthew 9143: }
9144:
9145: #######################################################
9146: #######################################################
9147:
9148: =pod
9149:
9150: =head1 Course Environment Routines
1.157 matthew 9151:
9152: =over 4
1.153 matthew 9153:
1.648 raeburn 9154: =item * &restore_course_settings()
1.153 matthew 9155:
1.648 raeburn 9156: =item * &store_course_settings()
1.153 matthew 9157:
9158: Restores/Store indicated form parameters from the course environment.
9159: Will not overwrite existing values of the form parameters.
9160:
9161: Inputs:
9162: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9163:
9164: a hash ref describing the data to be stored. For example:
9165:
9166: %Save_Parameters = ('Status' => 'scalar',
9167: 'chartoutputmode' => 'scalar',
9168: 'chartoutputdata' => 'scalar',
9169: 'Section' => 'array',
1.373 raeburn 9170: 'Group' => 'array',
1.153 matthew 9171: 'StudentData' => 'array',
9172: 'Maps' => 'array');
9173:
9174: Returns: both routines return nothing
9175:
1.631 raeburn 9176: =back
9177:
1.153 matthew 9178: =cut
9179:
9180: #######################################################
9181: #######################################################
9182: sub store_course_settings {
1.496 albertel 9183: return &store_settings($env{'request.course.id'},@_);
9184: }
9185:
9186: sub store_settings {
1.153 matthew 9187: # save to the environment
9188: # appenv the same items, just to be safe
1.300 albertel 9189: my $udom = $env{'user.domain'};
9190: my $uname = $env{'user.name'};
1.496 albertel 9191: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9192: my %SaveHash;
9193: my %AppHash;
9194: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9195: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9196: my $envname = 'environment.'.$basename;
1.258 albertel 9197: if (exists($env{'form.'.$setting})) {
1.153 matthew 9198: # Save this value away
9199: if ($type eq 'scalar' &&
1.258 albertel 9200: (! exists($env{$envname}) ||
9201: $env{$envname} ne $env{'form.'.$setting})) {
9202: $SaveHash{$basename} = $env{'form.'.$setting};
9203: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9204: } elsif ($type eq 'array') {
9205: my $stored_form;
1.258 albertel 9206: if (ref($env{'form.'.$setting})) {
1.153 matthew 9207: $stored_form = join(',',
9208: map {
1.369 www 9209: &escape($_);
1.258 albertel 9210: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9211: } else {
9212: $stored_form =
1.369 www 9213: &escape($env{'form.'.$setting});
1.153 matthew 9214: }
9215: # Determine if the array contents are the same.
1.258 albertel 9216: if ($stored_form ne $env{$envname}) {
1.153 matthew 9217: $SaveHash{$basename} = $stored_form;
9218: $AppHash{$envname} = $stored_form;
9219: }
9220: }
9221: }
9222: }
9223: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9224: $udom,$uname);
1.153 matthew 9225: if ($put_result !~ /^(ok|delayed)/) {
9226: &Apache::lonnet::logthis('unable to save form parameters, '.
9227: 'got error:'.$put_result);
9228: }
9229: # Make sure these settings stick around in this session, too
1.646 raeburn 9230: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9231: return;
9232: }
9233:
9234: sub restore_course_settings {
1.499 albertel 9235: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9236: }
9237:
9238: sub restore_settings {
9239: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9240: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9241: next if (exists($env{'form.'.$setting}));
1.496 albertel 9242: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9243: '.'.$setting;
1.258 albertel 9244: if (exists($env{$envname})) {
1.153 matthew 9245: if ($type eq 'scalar') {
1.258 albertel 9246: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9247: } elsif ($type eq 'array') {
1.258 albertel 9248: $env{'form.'.$setting} = [
1.153 matthew 9249: map {
1.369 www 9250: &unescape($_);
1.258 albertel 9251: } split(',',$env{$envname})
1.153 matthew 9252: ];
9253: }
9254: }
9255: }
1.127 matthew 9256: }
9257:
1.618 raeburn 9258: #######################################################
9259: #######################################################
9260:
9261: =pod
9262:
9263: =head1 Domain E-mail Routines
9264:
9265: =over 4
9266:
1.648 raeburn 9267: =item * &build_recipient_list()
1.618 raeburn 9268:
1.766 raeburn 9269: Build recipient lists for four types of e-mail:
9270: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9271: (d) Help requests, generated by
9272: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9273:
9274: Inputs:
1.619 raeburn 9275: defmail (scalar - email address of default recipient),
1.618 raeburn 9276: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9277: defdom (domain for which to retrieve configuration settings),
9278: origmail (scalar - email address of recipient from loncapa.conf,
9279: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9280:
1.655 raeburn 9281: Returns: comma separated list of addresses to which to send e-mail.
9282:
9283: =back
1.618 raeburn 9284:
9285: =cut
9286:
9287: ############################################################
9288: ############################################################
9289: sub build_recipient_list {
1.619 raeburn 9290: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9291: my @recipients;
9292: my $otheremails;
9293: my %domconfig =
9294: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9295: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9296: if (exists($domconfig{'contacts'}{$mailing})) {
9297: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9298: my @contacts = ('adminemail','supportemail');
9299: foreach my $item (@contacts) {
9300: if ($domconfig{'contacts'}{$mailing}{$item}) {
9301: my $addr = $domconfig{'contacts'}{$item};
9302: if (!grep(/^\Q$addr\E$/,@recipients)) {
9303: push(@recipients,$addr);
9304: }
1.619 raeburn 9305: }
1.766 raeburn 9306: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9307: }
9308: }
1.766 raeburn 9309: } elsif ($origmail ne '') {
9310: push(@recipients,$origmail);
1.618 raeburn 9311: }
1.619 raeburn 9312: } elsif ($origmail ne '') {
9313: push(@recipients,$origmail);
1.618 raeburn 9314: }
1.688 raeburn 9315: if (defined($defmail)) {
9316: if ($defmail ne '') {
9317: push(@recipients,$defmail);
9318: }
1.618 raeburn 9319: }
9320: if ($otheremails) {
1.619 raeburn 9321: my @others;
9322: if ($otheremails =~ /,/) {
9323: @others = split(/,/,$otheremails);
1.618 raeburn 9324: } else {
1.619 raeburn 9325: push(@others,$otheremails);
9326: }
9327: foreach my $addr (@others) {
9328: if (!grep(/^\Q$addr\E$/,@recipients)) {
9329: push(@recipients,$addr);
9330: }
1.618 raeburn 9331: }
9332: }
1.619 raeburn 9333: my $recipientlist = join(',',@recipients);
1.618 raeburn 9334: return $recipientlist;
9335: }
9336:
1.127 matthew 9337: ############################################################
9338: ############################################################
1.154 albertel 9339:
1.655 raeburn 9340: =pod
9341:
9342: =head1 Course Catalog Routines
9343:
9344: =over 4
9345:
9346: =item * &gather_categories()
9347:
9348: Converts category definitions - keys of categories hash stored in
9349: coursecategories in configuration.db on the primary library server in a
9350: domain - to an array. Also generates javascript and idx hash used to
9351: generate Domain Coordinator interface for editing Course Categories.
9352:
9353: Inputs:
1.663 raeburn 9354:
1.655 raeburn 9355: categories (reference to hash of category definitions).
1.663 raeburn 9356:
1.655 raeburn 9357: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9358: categories and subcategories).
1.663 raeburn 9359:
1.655 raeburn 9360: idx (reference to hash of counters used in Domain Coordinator interface for
9361: editing Course Categories).
1.663 raeburn 9362:
1.655 raeburn 9363: jsarray (reference to array of categories used to create Javascript arrays for
9364: Domain Coordinator interface for editing Course Categories).
9365:
9366: Returns: nothing
9367:
9368: Side effects: populates cats, idx and jsarray.
9369:
9370: =cut
9371:
9372: sub gather_categories {
9373: my ($categories,$cats,$idx,$jsarray) = @_;
9374: my %counters;
9375: my $num = 0;
9376: foreach my $item (keys(%{$categories})) {
9377: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9378: if ($container eq '' && $depth == 0) {
9379: $cats->[$depth][$categories->{$item}] = $cat;
9380: } else {
9381: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9382: }
9383: my ($escitem,$tail) = split(/:/,$item,2);
9384: if ($counters{$tail} eq '') {
9385: $counters{$tail} = $num;
9386: $num ++;
9387: }
9388: if (ref($idx) eq 'HASH') {
9389: $idx->{$item} = $counters{$tail};
9390: }
9391: if (ref($jsarray) eq 'ARRAY') {
9392: push(@{$jsarray->[$counters{$tail}]},$item);
9393: }
9394: }
9395: return;
9396: }
9397:
9398: =pod
9399:
9400: =item * &extract_categories()
9401:
9402: Used to generate breadcrumb trails for course categories.
9403:
9404: Inputs:
1.663 raeburn 9405:
1.655 raeburn 9406: categories (reference to hash of category definitions).
1.663 raeburn 9407:
1.655 raeburn 9408: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9409: categories and subcategories).
1.663 raeburn 9410:
1.655 raeburn 9411: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9412:
1.655 raeburn 9413: allitems (reference to hash - key is category key
9414: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9415:
1.655 raeburn 9416: idx (reference to hash of counters used in Domain Coordinator interface for
9417: editing Course Categories).
1.663 raeburn 9418:
1.655 raeburn 9419: jsarray (reference to array of categories used to create Javascript arrays for
9420: Domain Coordinator interface for editing Course Categories).
9421:
1.665 raeburn 9422: subcats (reference to hash of arrays containing all subcategories within each
9423: category, -recursive)
9424:
1.655 raeburn 9425: Returns: nothing
9426:
9427: Side effects: populates trails and allitems hash references.
9428:
9429: =cut
9430:
9431: sub extract_categories {
1.665 raeburn 9432: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9433: if (ref($categories) eq 'HASH') {
9434: &gather_categories($categories,$cats,$idx,$jsarray);
9435: if (ref($cats->[0]) eq 'ARRAY') {
9436: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9437: my $name = $cats->[0][$i];
9438: my $item = &escape($name).'::0';
9439: my $trailstr;
9440: if ($name eq 'instcode') {
9441: $trailstr = &mt('Official courses (with institutional codes)');
9442: } else {
9443: $trailstr = $name;
9444: }
9445: if ($allitems->{$item} eq '') {
9446: push(@{$trails},$trailstr);
9447: $allitems->{$item} = scalar(@{$trails})-1;
9448: }
9449: my @parents = ($name);
9450: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9451: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9452: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9453: if (ref($subcats) eq 'HASH') {
9454: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9455: }
9456: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9457: }
9458: } else {
9459: if (ref($subcats) eq 'HASH') {
9460: $subcats->{$item} = [];
1.655 raeburn 9461: }
9462: }
9463: }
9464: }
9465: }
9466: return;
9467: }
9468:
9469: =pod
9470:
9471: =item *&recurse_categories()
9472:
9473: Recursively used to generate breadcrumb trails for course categories.
9474:
9475: Inputs:
1.663 raeburn 9476:
1.655 raeburn 9477: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9478: categories and subcategories).
1.663 raeburn 9479:
1.655 raeburn 9480: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9481:
9482: category (current course category, for which breadcrumb trail is being generated).
9483:
9484: trails (reference to array of breadcrumb trails for each category).
9485:
1.655 raeburn 9486: allitems (reference to hash - key is category key
9487: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9488:
1.655 raeburn 9489: parents (array containing containers directories for current category,
9490: back to top level).
9491:
9492: Returns: nothing
9493:
9494: Side effects: populates trails and allitems hash references
9495:
9496: =cut
9497:
9498: sub recurse_categories {
1.665 raeburn 9499: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9500: my $shallower = $depth - 1;
9501: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9502: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9503: my $name = $cats->[$depth]{$category}[$k];
9504: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9505: my $trailstr = join(' -> ',(@{$parents},$category));
9506: if ($allitems->{$item} eq '') {
9507: push(@{$trails},$trailstr);
9508: $allitems->{$item} = scalar(@{$trails})-1;
9509: }
9510: my $deeper = $depth+1;
9511: push(@{$parents},$category);
1.665 raeburn 9512: if (ref($subcats) eq 'HASH') {
9513: my $subcat = &escape($name).':'.$category.':'.$depth;
9514: for (my $j=@{$parents}; $j>=0; $j--) {
9515: my $higher;
9516: if ($j > 0) {
9517: $higher = &escape($parents->[$j]).':'.
9518: &escape($parents->[$j-1]).':'.$j;
9519: } else {
9520: $higher = &escape($parents->[$j]).'::'.$j;
9521: }
9522: push(@{$subcats->{$higher}},$subcat);
9523: }
9524: }
9525: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9526: $subcats);
1.655 raeburn 9527: pop(@{$parents});
9528: }
9529: } else {
9530: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9531: my $trailstr = join(' -> ',(@{$parents},$category));
9532: if ($allitems->{$item} eq '') {
9533: push(@{$trails},$trailstr);
9534: $allitems->{$item} = scalar(@{$trails})-1;
9535: }
9536: }
9537: return;
9538: }
9539:
1.663 raeburn 9540: =pod
9541:
9542: =item *&assign_categories_table()
9543:
9544: Create a datatable for display of hierarchical categories in a domain,
9545: with checkboxes to allow a course to be categorized.
9546:
9547: Inputs:
9548:
9549: cathash - reference to hash of categories defined for the domain (from
9550: configuration.db)
9551:
9552: currcat - scalar with an & separated list of categories assigned to a course.
9553:
9554: Returns: $output (markup to be displayed)
9555:
9556: =cut
9557:
9558: sub assign_categories_table {
9559: my ($cathash,$currcat) = @_;
9560: my $output;
9561: if (ref($cathash) eq 'HASH') {
9562: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9563: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9564: $maxdepth = scalar(@cats);
9565: if (@cats > 0) {
9566: my $itemcount = 0;
9567: if (ref($cats[0]) eq 'ARRAY') {
9568: $output = &Apache::loncommon::start_data_table();
9569: my @currcategories;
9570: if ($currcat ne '') {
9571: @currcategories = split('&',$currcat);
9572: }
9573: for (my $i=0; $i<@{$cats[0]}; $i++) {
9574: my $parent = $cats[0][$i];
9575: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9576: next if ($parent eq 'instcode');
9577: my $item = &escape($parent).'::0';
9578: my $checked = '';
9579: if (@currcategories > 0) {
9580: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9581: $checked = ' checked="checked"';
1.663 raeburn 9582: }
9583: }
1.675 raeburn 9584: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9585: '<input type="checkbox" name="usecategory" value="'.
9586: $item.'"'.$checked.' />'.$parent.'</span>'.
9587: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9588: my $depth = 1;
9589: push(@path,$parent);
9590: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9591: pop(@path);
9592: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9593: $itemcount ++;
9594: }
9595: $output .= &Apache::loncommon::end_data_table();
9596: }
9597: }
9598: }
9599: return $output;
9600: }
9601:
9602: =pod
9603:
9604: =item *&assign_category_rows()
9605:
9606: Create a datatable row for display of nested categories in a domain,
9607: with checkboxes to allow a course to be categorized,called recursively.
9608:
9609: Inputs:
9610:
9611: itemcount - track row number for alternating colors
9612:
9613: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9614: categories and subcategories.
9615:
9616: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9617:
9618: parent - parent of current category item
9619:
9620: path - Array containing all categories back up through the hierarchy from the
9621: current category to the top level.
9622:
9623: currcategories - reference to array of current categories assigned to the course
9624:
9625: Returns: $output (markup to be displayed).
9626:
9627: =cut
9628:
9629: sub assign_category_rows {
9630: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9631: my ($text,$name,$item,$chgstr);
9632: if (ref($cats) eq 'ARRAY') {
9633: my $maxdepth = scalar(@{$cats});
9634: if (ref($cats->[$depth]) eq 'HASH') {
9635: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9636: my $numchildren = @{$cats->[$depth]{$parent}};
9637: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9638: $text .= '<td><table class="LC_datatable">';
9639: for (my $j=0; $j<$numchildren; $j++) {
9640: $name = $cats->[$depth]{$parent}[$j];
9641: $item = &escape($name).':'.&escape($parent).':'.$depth;
9642: my $deeper = $depth+1;
9643: my $checked = '';
9644: if (ref($currcategories) eq 'ARRAY') {
9645: if (@{$currcategories} > 0) {
9646: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9647: $checked = ' checked="checked"';
1.663 raeburn 9648: }
9649: }
9650: }
1.664 raeburn 9651: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9652: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9653: $item.'"'.$checked.' />'.$name.'</label></span>'.
9654: '<input type="hidden" name="catname" value="'.$name.'" />'.
9655: '</td><td>';
1.663 raeburn 9656: if (ref($path) eq 'ARRAY') {
9657: push(@{$path},$name);
9658: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9659: pop(@{$path});
9660: }
9661: $text .= '</td></tr>';
9662: }
9663: $text .= '</table></td>';
9664: }
9665: }
9666: }
9667: return $text;
9668: }
9669:
1.655 raeburn 9670: ############################################################
9671: ############################################################
9672:
9673:
1.443 albertel 9674: sub commit_customrole {
1.664 raeburn 9675: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9676: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9677: ($start?', '.&mt('starting').' '.localtime($start):'').
9678: ($end?', ending '.localtime($end):'').': <b>'.
9679: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9680: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9681: '</b><br />';
9682: return $output;
9683: }
9684:
9685: sub commit_standardrole {
1.541 raeburn 9686: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9687: my ($output,$logmsg,$linefeed);
9688: if ($context eq 'auto') {
9689: $linefeed = "\n";
9690: } else {
9691: $linefeed = "<br />\n";
9692: }
1.443 albertel 9693: if ($three eq 'st') {
1.541 raeburn 9694: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9695: $one,$two,$sec,$context);
9696: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9697: ($result eq 'unknown_course') || ($result eq 'refused')) {
9698: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9699: } else {
1.541 raeburn 9700: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9701: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9702: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9703: if ($context eq 'auto') {
9704: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9705: } else {
9706: $output .= '<b>'.$result.'</b>'.$linefeed.
9707: &mt('Add to classlist').': <b>ok</b>';
9708: }
9709: $output .= $linefeed;
1.443 albertel 9710: }
9711: } else {
9712: $output = &mt('Assigning').' '.$three.' in '.$url.
9713: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9714: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9715: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9716: if ($context eq 'auto') {
9717: $output .= $result.$linefeed;
9718: } else {
9719: $output .= '<b>'.$result.'</b>'.$linefeed;
9720: }
1.443 albertel 9721: }
9722: return $output;
9723: }
9724:
9725: sub commit_studentrole {
1.541 raeburn 9726: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9727: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9728: if ($context eq 'auto') {
9729: $linefeed = "\n";
9730: } else {
9731: $linefeed = '<br />'."\n";
9732: }
1.443 albertel 9733: if (defined($one) && defined($two)) {
9734: my $cid=$one.'_'.$two;
9735: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9736: my $secchange = 0;
9737: my $expire_role_result;
9738: my $modify_section_result;
1.628 raeburn 9739: if ($oldsec ne '-1') {
9740: if ($oldsec ne $sec) {
1.443 albertel 9741: $secchange = 1;
1.628 raeburn 9742: my $now = time;
1.443 albertel 9743: my $uurl='/'.$cid;
9744: $uurl=~s/\_/\//g;
9745: if ($oldsec) {
9746: $uurl.='/'.$oldsec;
9747: }
1.626 raeburn 9748: $oldsecurl = $uurl;
1.628 raeburn 9749: $expire_role_result =
1.652 raeburn 9750: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9751: if ($env{'request.course.sec'} ne '') {
9752: if ($expire_role_result eq 'refused') {
9753: my @roles = ('st');
9754: my @statuses = ('previous');
9755: my @roledoms = ($one);
9756: my $withsec = 1;
9757: my %roleshash =
9758: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9759: \@statuses,\@roles,\@roledoms,$withsec);
9760: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9761: my ($oldstart,$oldend) =
9762: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9763: if ($oldend > 0 && $oldend <= $now) {
9764: $expire_role_result = 'ok';
9765: }
9766: }
9767: }
9768: }
1.443 albertel 9769: $result = $expire_role_result;
9770: }
9771: }
9772: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9773: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9774: if ($modify_section_result =~ /^ok/) {
9775: if ($secchange == 1) {
1.628 raeburn 9776: if ($sec eq '') {
9777: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9778: } else {
9779: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9780: }
1.443 albertel 9781: } elsif ($oldsec eq '-1') {
1.628 raeburn 9782: if ($sec eq '') {
9783: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9784: } else {
9785: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9786: }
1.443 albertel 9787: } else {
1.628 raeburn 9788: if ($sec eq '') {
9789: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9790: } else {
9791: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9792: }
1.443 albertel 9793: }
9794: } else {
1.628 raeburn 9795: if ($secchange) {
9796: $$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;
9797: } else {
9798: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9799: }
1.443 albertel 9800: }
9801: $result = $modify_section_result;
9802: } elsif ($secchange == 1) {
1.628 raeburn 9803: if ($oldsec eq '') {
9804: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9805: } else {
9806: $$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;
9807: }
1.626 raeburn 9808: if ($expire_role_result eq 'refused') {
9809: my $newsecurl = '/'.$cid;
9810: $newsecurl =~ s/\_/\//g;
9811: if ($sec ne '') {
9812: $newsecurl.='/'.$sec;
9813: }
9814: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9815: if ($sec eq '') {
9816: $$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;
9817: } else {
9818: $$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;
9819: }
9820: }
9821: }
1.443 albertel 9822: }
9823: } else {
1.626 raeburn 9824: $$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 9825: $result = "error: incomplete course id\n";
9826: }
9827: return $result;
9828: }
9829:
9830: ############################################################
9831: ############################################################
9832:
1.566 albertel 9833: sub check_clone {
1.578 raeburn 9834: my ($args,$linefeed) = @_;
1.566 albertel 9835: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9836: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9837: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9838: my $clonemsg;
9839: my $can_clone = 0;
9840:
9841: if ($clonehome eq 'no_host') {
1.578 raeburn 9842: $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'});
1.566 albertel 9843: } else {
9844: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9845: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9846: $can_clone = 1;
9847: } else {
9848: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9849: $args->{'clonedomain'},$args->{'clonecourse'});
9850: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9851: if (grep(/^\*$/,@cloners)) {
9852: $can_clone = 1;
9853: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9854: $can_clone = 1;
9855: } else {
9856: my %roleshash =
9857: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9858: $args->{'ccdomain'},
9859: 'userroles',['active'],['cc'],
9860: [$args->{'clonedomain'}]);
9861: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9862: $can_clone = 1;
9863: } else {
9864: $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'});
9865: }
1.566 albertel 9866: }
1.578 raeburn 9867: }
1.566 albertel 9868: }
9869: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9870: }
9871:
1.444 albertel 9872: sub construct_course {
1.541 raeburn 9873: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9874: my $outcome;
1.541 raeburn 9875: my $linefeed = '<br />'."\n";
9876: if ($context eq 'auto') {
9877: $linefeed = "\n";
9878: }
1.566 albertel 9879:
9880: #
9881: # Are we cloning?
9882: #
9883: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9884: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9885: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9886: if ($context ne 'auto') {
1.578 raeburn 9887: if ($clonemsg ne '') {
9888: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9889: }
1.566 albertel 9890: }
9891: $outcome .= $clonemsg.$linefeed;
9892:
9893: if (!$can_clone) {
9894: return (0,$outcome);
9895: }
9896: }
9897:
1.444 albertel 9898: #
9899: # Open course
9900: #
9901: my $crstype = lc($args->{'crstype'});
9902: my %cenv=();
9903: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9904: $args->{'cdescr'},
9905: $args->{'curl'},
9906: $args->{'course_home'},
9907: $args->{'nonstandard'},
9908: $args->{'crscode'},
9909: $args->{'ccuname'}.':'.
9910: $args->{'ccdomain'},
9911: $args->{'crstype'});
9912:
9913: # Note: The testing routines depend on this being output; see
9914: # Utils::Course. This needs to at least be output as a comment
9915: # if anyone ever decides to not show this, and Utils::Course::new
9916: # will need to be suitably modified.
1.541 raeburn 9917: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9918: #
9919: # Check if created correctly
9920: #
1.479 albertel 9921: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9922: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9923: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9924:
1.444 albertel 9925: #
1.566 albertel 9926: # Do the cloning
9927: #
9928: if ($can_clone && $cloneid) {
9929: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9930: if ($context ne 'auto') {
9931: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9932: }
9933: $outcome .= $clonemsg.$linefeed;
9934: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9935: # Copy all files
1.637 www 9936: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9937: # Restore URL
1.566 albertel 9938: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9939: # Restore title
1.566 albertel 9940: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9941: # Mark as cloned
1.566 albertel 9942: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9943: # Need to clone grading mode
9944: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9945: $cenv{'grading'}=$newenv{'grading'};
9946: # Do not clone these environment entries
9947: &Apache::lonnet::del('environment',
9948: ['default_enrollment_start_date',
9949: 'default_enrollment_end_date',
9950: 'question.email',
9951: 'policy.email',
9952: 'comment.email',
9953: 'pch.users.denied',
1.725 raeburn 9954: 'plc.users.denied',
9955: 'hidefromcat',
9956: 'categories'],
1.638 www 9957: $$crsudom,$$crsunum);
1.444 albertel 9958: }
1.566 albertel 9959:
1.444 albertel 9960: #
9961: # Set environment (will override cloned, if existing)
9962: #
9963: my @sections = ();
9964: my @xlists = ();
9965: if ($args->{'crstype'}) {
9966: $cenv{'type'}=$args->{'crstype'};
9967: }
9968: if ($args->{'crsid'}) {
9969: $cenv{'courseid'}=$args->{'crsid'};
9970: }
9971: if ($args->{'crscode'}) {
9972: $cenv{'internal.coursecode'}=$args->{'crscode'};
9973: }
9974: if ($args->{'crsquota'} ne '') {
9975: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9976: } else {
9977: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9978: }
9979: if ($args->{'ccuname'}) {
9980: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9981: ':'.$args->{'ccdomain'};
9982: } else {
9983: $cenv{'internal.courseowner'} = $args->{'curruser'};
9984: }
9985: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9986: if ($args->{'crssections'}) {
9987: $cenv{'internal.sectionnums'} = '';
9988: if ($args->{'crssections'} =~ m/,/) {
9989: @sections = split/,/,$args->{'crssections'};
9990: } else {
9991: $sections[0] = $args->{'crssections'};
9992: }
9993: if (@sections > 0) {
9994: foreach my $item (@sections) {
9995: my ($sec,$gp) = split/:/,$item;
9996: my $class = $args->{'crscode'}.$sec;
9997: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9998: $cenv{'internal.sectionnums'} .= $item.',';
9999: unless ($addcheck eq 'ok') {
10000: push @badclasses, $class;
10001: }
10002: }
10003: $cenv{'internal.sectionnums'} =~ s/,$//;
10004: }
10005: }
10006: # do not hide course coordinator from staff listing,
10007: # even if privileged
10008: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10009: # add crosslistings
10010: if ($args->{'crsxlist'}) {
10011: $cenv{'internal.crosslistings'}='';
10012: if ($args->{'crsxlist'} =~ m/,/) {
10013: @xlists = split/,/,$args->{'crsxlist'};
10014: } else {
10015: $xlists[0] = $args->{'crsxlist'};
10016: }
10017: if (@xlists > 0) {
10018: foreach my $item (@xlists) {
10019: my ($xl,$gp) = split/:/,$item;
10020: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10021: $cenv{'internal.crosslistings'} .= $item.',';
10022: unless ($addcheck eq 'ok') {
10023: push @badclasses, $xl;
10024: }
10025: }
10026: $cenv{'internal.crosslistings'} =~ s/,$//;
10027: }
10028: }
10029: if ($args->{'autoadds'}) {
10030: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10031: }
10032: if ($args->{'autodrops'}) {
10033: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10034: }
10035: # check for notification of enrollment changes
10036: my @notified = ();
10037: if ($args->{'notify_owner'}) {
10038: if ($args->{'ccuname'} ne '') {
10039: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10040: }
10041: }
10042: if ($args->{'notify_dc'}) {
10043: if ($uname ne '') {
1.630 raeburn 10044: push(@notified,$uname.':'.$udom);
1.444 albertel 10045: }
10046: }
10047: if (@notified > 0) {
10048: my $notifylist;
10049: if (@notified > 1) {
10050: $notifylist = join(',',@notified);
10051: } else {
10052: $notifylist = $notified[0];
10053: }
10054: $cenv{'internal.notifylist'} = $notifylist;
10055: }
10056: if (@badclasses > 0) {
10057: my %lt=&Apache::lonlocal::texthash(
10058: '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',
10059: 'dnhr' => 'does not have rights to access enrollment in these classes',
10060: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10061: );
1.541 raeburn 10062: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10063: ' ('.$lt{'adby'}.')';
10064: if ($context eq 'auto') {
10065: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10066: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10067: foreach my $item (@badclasses) {
10068: if ($context eq 'auto') {
10069: $outcome .= " - $item\n";
10070: } else {
10071: $outcome .= "<li>$item</li>\n";
10072: }
10073: }
10074: if ($context eq 'auto') {
10075: $outcome .= $linefeed;
10076: } else {
1.566 albertel 10077: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10078: }
10079: }
1.444 albertel 10080: }
10081: if ($args->{'no_end_date'}) {
10082: $args->{'endaccess'} = 0;
10083: }
10084: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10085: $cenv{'internal.autoend'}=$args->{'enrollend'};
10086: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10087: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10088: if ($args->{'showphotos'}) {
10089: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10090: }
10091: $cenv{'internal.authtype'} = $args->{'authtype'};
10092: $cenv{'internal.autharg'} = $args->{'autharg'};
10093: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10094: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10095: 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');
10096: if ($context eq 'auto') {
10097: $outcome .= $krb_msg;
10098: } else {
1.566 albertel 10099: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10100: }
10101: $outcome .= $linefeed;
1.444 albertel 10102: }
10103: }
10104: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10105: if ($args->{'setpolicy'}) {
10106: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10107: }
10108: if ($args->{'setcontent'}) {
10109: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10110: }
10111: }
10112: if ($args->{'reshome'}) {
10113: $cenv{'reshome'}=$args->{'reshome'}.'/';
10114: $cenv{'reshome'}=~s/\/+$/\//;
10115: }
10116: #
10117: # course has keyed access
10118: #
10119: if ($args->{'setkeys'}) {
10120: $cenv{'keyaccess'}='yes';
10121: }
10122: # if specified, key authority is not course, but user
10123: # only active if keyaccess is yes
10124: if ($args->{'keyauth'}) {
1.487 albertel 10125: my ($user,$domain) = split(':',$args->{'keyauth'});
10126: $user = &LONCAPA::clean_username($user);
10127: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10128: if ($user ne '' && $domain ne '') {
1.487 albertel 10129: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10130: }
10131: }
10132:
10133: if ($args->{'disresdis'}) {
10134: $cenv{'pch.roles.denied'}='st';
10135: }
10136: if ($args->{'disablechat'}) {
10137: $cenv{'plc.roles.denied'}='st';
10138: }
10139:
10140: # Record we've not yet viewed the Course Initialization Helper for this
10141: # course
10142: $cenv{'course.helper.not.run'} = 1;
10143: #
10144: # Use new Randomseed
10145: #
10146: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10147: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10148: #
10149: # The encryption code and receipt prefix for this course
10150: #
10151: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10152: $cenv{'internal.encpref'}=100+int(9*rand(99));
10153: #
10154: # By default, use standard grading
10155: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10156:
1.541 raeburn 10157: $outcome .= $linefeed.&mt('Setting environment').': '.
10158: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10159: #
10160: # Open all assignments
10161: #
10162: if ($args->{'openall'}) {
10163: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10164: my %storecontent = ($storeunder => time,
10165: $storeunder.'.type' => 'date_start');
10166:
10167: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10168: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10169: }
10170: #
10171: # Set first page
10172: #
10173: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10174: || ($cloneid)) {
1.445 albertel 10175: use LONCAPA::map;
1.444 albertel 10176: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10177:
10178: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10179: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10180:
1.444 albertel 10181: $outcome .= ($fatal?$errtext:'read ok').' - ';
10182: my $title; my $url;
10183: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10184: $title=&mt('Syllabus');
1.444 albertel 10185: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10186: } else {
1.690 bisitz 10187: $title=&mt('Navigate Contents');
1.444 albertel 10188: $url='/adm/navmaps';
10189: }
1.445 albertel 10190:
10191: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10192: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10193:
10194: if ($errtext) { $fatal=2; }
1.541 raeburn 10195: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10196: }
1.566 albertel 10197:
10198: return (1,$outcome);
1.444 albertel 10199: }
10200:
10201: ############################################################
10202: ############################################################
10203:
1.378 raeburn 10204: sub course_type {
10205: my ($cid) = @_;
10206: if (!defined($cid)) {
10207: $cid = $env{'request.course.id'};
10208: }
1.404 albertel 10209: if (defined($env{'course.'.$cid.'.type'})) {
10210: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10211: } else {
10212: return 'Course';
1.377 raeburn 10213: }
10214: }
1.156 albertel 10215:
1.406 raeburn 10216: sub group_term {
10217: my $crstype = &course_type();
10218: my %names = (
10219: 'Course' => 'group',
1.865 raeburn 10220: 'Community' => 'group',
1.406 raeburn 10221: );
10222: return $names{$crstype};
10223: }
10224:
1.156 albertel 10225: sub icon {
10226: my ($file)=@_;
1.505 albertel 10227: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10228: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10229: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10230: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10231: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10232: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10233: $curfext.".gif") {
10234: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10235: $curfext.".gif";
10236: }
10237: }
1.249 albertel 10238: return &lonhttpdurl($iconname);
1.154 albertel 10239: }
1.84 albertel 10240:
1.575 albertel 10241: sub lonhttpdurl {
1.692 www 10242: #
10243: # Had been used for "small fry" static images on separate port 8080.
10244: # Modify here if lightweight http functionality desired again.
10245: # Currently eliminated due to increasing firewall issues.
10246: #
1.575 albertel 10247: my ($url)=@_;
1.692 www 10248: return $url;
1.215 albertel 10249: }
10250:
1.213 albertel 10251: sub connection_aborted {
10252: my ($r)=@_;
10253: $r->print(" ");$r->rflush();
10254: my $c = $r->connection;
10255: return $c->aborted();
10256: }
10257:
1.221 foxr 10258: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10259: # strings as 'strings'.
10260: sub escape_single {
1.221 foxr 10261: my ($input) = @_;
1.223 albertel 10262: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10263: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10264: return $input;
10265: }
1.223 albertel 10266:
1.222 foxr 10267: # Same as escape_single, but escape's "'s This
10268: # can be used for "strings"
10269: sub escape_double {
10270: my ($input) = @_;
10271: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10272: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10273: return $input;
10274: }
1.223 albertel 10275:
1.222 foxr 10276: # Escapes the last element of a full URL.
10277: sub escape_url {
10278: my ($url) = @_;
1.238 raeburn 10279: my @urlslices = split(/\//, $url,-1);
1.369 www 10280: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10281: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10282: }
1.462 albertel 10283:
1.820 raeburn 10284: sub compare_arrays {
10285: my ($arrayref1,$arrayref2) = @_;
10286: my (@difference,%count);
10287: @difference = ();
10288: %count = ();
10289: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10290: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10291: foreach my $element (keys(%count)) {
10292: if ($count{$element} == 1) {
10293: push(@difference,$element);
10294: }
10295: }
10296: }
10297: return @difference;
10298: }
10299:
1.817 bisitz 10300: # -------------------------------------------------------- Initialize user login
1.462 albertel 10301: sub init_user_environment {
1.463 albertel 10302: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10303: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10304:
10305: my $public=($username eq 'public' && $domain eq 'public');
10306:
10307: # See if old ID present, if so, remove
10308:
10309: my ($filename,$cookie,$userroles);
10310: my $now=time;
10311:
10312: if ($public) {
10313: my $max_public=100;
10314: my $oldest;
10315: my $oldest_time=0;
10316: for(my $next=1;$next<=$max_public;$next++) {
10317: if (-e $lonids."/publicuser_$next.id") {
10318: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10319: if ($mtime<$oldest_time || !$oldest_time) {
10320: $oldest_time=$mtime;
10321: $oldest=$next;
10322: }
10323: } else {
10324: $cookie="publicuser_$next";
10325: last;
10326: }
10327: }
10328: if (!$cookie) { $cookie="publicuser_$oldest"; }
10329: } else {
1.463 albertel 10330: # if this isn't a robot, kill any existing non-robot sessions
10331: if (!$args->{'robot'}) {
10332: opendir(DIR,$lonids);
10333: while ($filename=readdir(DIR)) {
10334: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10335: unlink($lonids.'/'.$filename);
10336: }
1.462 albertel 10337: }
1.463 albertel 10338: closedir(DIR);
1.462 albertel 10339: }
10340: # Give them a new cookie
1.463 albertel 10341: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10342: : $now.$$.int(rand(10000)));
1.463 albertel 10343: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10344:
10345: # Initialize roles
10346:
10347: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10348: }
10349: # ------------------------------------ Check browser type and MathML capability
10350:
10351: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10352: $clientunicode,$clientos) = &decode_user_agent($r);
10353:
10354: # ------------------------------------------------------------- Get environment
10355:
10356: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10357: my ($tmp) = keys(%userenv);
10358: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10359: # default remote control to off
10360: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10361: } else {
10362: undef(%userenv);
10363: }
10364: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10365: $form->{'interface'}=$userenv{'interface'};
10366: }
10367: $env{'environment.remote'}=$userenv{'remote'};
10368: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10369:
10370: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10371: foreach my $option ('interface','localpath','localres') {
10372: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10373: }
10374: # --------------------------------------------------------- Write first profile
10375:
10376: {
10377: my %initial_env =
10378: ("user.name" => $username,
10379: "user.domain" => $domain,
10380: "user.home" => $authhost,
10381: "browser.type" => $clientbrowser,
10382: "browser.version" => $clientversion,
10383: "browser.mathml" => $clientmathml,
10384: "browser.unicode" => $clientunicode,
10385: "browser.os" => $clientos,
10386: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10387: "request.course.fn" => '',
10388: "request.course.uri" => '',
10389: "request.course.sec" => '',
10390: "request.role" => 'cm',
10391: "request.role.adv" => $env{'user.adv'},
10392: "request.host" => $ENV{'REMOTE_ADDR'},);
10393:
10394: if ($form->{'localpath'}) {
10395: $initial_env{"browser.localpath"} = $form->{'localpath'};
10396: $initial_env{"browser.localres"} = $form->{'localres'};
10397: }
10398:
10399: if ($public) {
10400: $initial_env{"environment.remote"} = "off";
10401: }
10402: if ($form->{'interface'}) {
10403: $form->{'interface'}=~s/\W//gs;
10404: $initial_env{"browser.interface"} = $form->{'interface'};
10405: $env{'browser.interface'}=$form->{'interface'};
10406: }
10407:
1.724 raeburn 10408: foreach my $tool ('aboutme','blog','portfolio') {
10409: $userenv{'availabletools.'.$tool} =
10410: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10411: }
10412:
1.864 raeburn 10413: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10414: $userenv{'canrequest.'.$crstype} =
10415: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10416: 'reload','requestcourses');
10417: }
10418:
1.462 albertel 10419: $env{'user.environment'} = "$lonids/$cookie.id";
10420:
10421: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10422: &GDBM_WRCREAT(),0640)) {
10423: &_add_to_env(\%disk_env,\%initial_env);
10424: &_add_to_env(\%disk_env,\%userenv,'environment.');
10425: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10426: if (ref($args->{'extra_env'})) {
10427: &_add_to_env(\%disk_env,$args->{'extra_env'});
10428: }
1.462 albertel 10429: untie(%disk_env);
10430: } else {
1.705 tempelho 10431: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10432: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10433: return 'error: '.$!;
10434: }
10435: }
10436: $env{'request.role'}='cm';
10437: $env{'request.role.adv'}=$env{'user.adv'};
10438: $env{'browser.type'}=$clientbrowser;
10439:
10440: return $cookie;
10441:
10442: }
10443:
10444: sub _add_to_env {
10445: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10446: if (ref($env_data) eq 'HASH') {
10447: while (my ($key,$value) = each(%$env_data)) {
10448: $idf->{$prefix.$key} = $value;
10449: $env{$prefix.$key} = $value;
10450: }
1.462 albertel 10451: }
10452: }
10453:
1.685 tempelho 10454: # --- Get the symbolic name of a problem and the url
10455: sub get_symb {
10456: my ($request,$silent) = @_;
1.726 raeburn 10457: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10458: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10459: if ($symb eq '') {
10460: if (!$silent) {
10461: $request->print("Unable to handle ambiguous references:$url:.");
10462: return ();
10463: }
10464: }
10465: &Apache::lonenc::check_decrypt(\$symb);
10466: return ($symb);
10467: }
10468:
10469: # --------------------------------------------------------------Get annotation
10470:
10471: sub get_annotation {
10472: my ($symb,$enc) = @_;
10473:
10474: my $key = $symb;
10475: if (!$enc) {
10476: $key =
10477: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10478: }
10479: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10480: return $annotation{$key};
10481: }
10482:
10483: sub clean_symb {
1.731 raeburn 10484: my ($symb,$delete_enc) = @_;
1.685 tempelho 10485:
10486: &Apache::lonenc::check_decrypt(\$symb);
10487: my $enc = $env{'request.enc'};
1.731 raeburn 10488: if ($delete_enc) {
1.730 raeburn 10489: delete($env{'request.enc'});
10490: }
1.685 tempelho 10491:
10492: return ($symb,$enc);
10493: }
1.462 albertel 10494:
1.41 ng 10495: =pod
10496:
10497: =back
10498:
1.112 bowersj2 10499: =cut
1.41 ng 10500:
1.112 bowersj2 10501: 1;
10502: __END__;
1.41 ng 10503:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>