Annotation of loncom/interface/loncommon.pm, revision 1.841
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.841 ! tempelho 4: # $Id: loncommon.pm,v 1.840 2009/06/08 18:04:45 bisitz 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.377 raeburn 486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - 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.377 raeburn 535: if (crstype == 'Course/Group') {
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.490 raeburn 3769: # Retrieve blocking times and identity of blocker for course
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: }
3874:
1.490 raeburn 3875: sub blocking_status {
3876: my ($activity,$uname,$udom) = @_;
3877: my %setters;
3878: my ($blocked,$output,$ownitem,$is_course);
3879: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3880: if ($startblock && $endblock) {
3881: $blocked = 1;
3882: if (wantarray) {
3883: my $category;
3884: if ($activity eq 'boards') {
3885: $category = 'Discussion posts in this course';
3886: } elsif ($activity eq 'blogs') {
3887: $category = 'Blogs';
3888: } elsif ($activity eq 'port') {
3889: if (defined($uname) && defined($udom)) {
3890: if ($uname eq $env{'user.name'} &&
3891: $udom eq $env{'user.domain'}) {
3892: $ownitem = 1;
3893: }
3894: }
3895: $is_course = &Apache::lonnet::is_course($udom,$uname);
3896: if ($ownitem) {
3897: $category = 'Your portfolio files';
3898: } elsif ($is_course) {
3899: my $coursedesc;
3900: foreach my $course (keys(%setters)) {
3901: my %courseinfo =
3902: &Apache::lonnet::coursedescription($course);
3903: $coursedesc = $courseinfo{'description'};
3904: }
1.764 weissno 3905: $category = "Group portfolio in the course '$coursedesc'";
1.490 raeburn 3906: } else {
3907: $category = 'Portfolio files belonging to ';
3908: if ($env{'user.name'} eq 'public' &&
3909: $env{'user.domain'} eq 'public') {
3910: $category .= &plainname($uname,$udom);
3911: } else {
3912: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3913: }
3914: }
3915: } elsif ($activity eq 'groups') {
3916: $category = 'Groups in this course';
3917: }
3918: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3919: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3920: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3921: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3922: $output .= &build_block_table($startblock,$endblock,\%setters);
3923: }
3924: }
3925: }
3926: if (wantarray) {
3927: return ($blocked,$output);
3928: } else {
3929: return $blocked;
3930: }
3931: }
3932:
1.60 matthew 3933: ###############################################
3934:
1.682 raeburn 3935: sub check_ip_acc {
3936: my ($acc)=@_;
3937: &Apache::lonxml::debug("acc is $acc");
3938: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3939: return 1;
3940: }
3941: my $allowed=0;
3942: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3943:
3944: my $name;
3945: foreach my $pattern (split(',',$acc)) {
3946: $pattern =~ s/^\s*//;
3947: $pattern =~ s/\s*$//;
3948: if ($pattern =~ /\*$/) {
3949: #35.8.*
3950: $pattern=~s/\*//;
3951: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3952: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3953: #35.8.3.[34-56]
3954: my $low=$2;
3955: my $high=$3;
3956: $pattern=$1;
3957: if ($ip =~ /^\Q$pattern\E/) {
3958: my $last=(split(/\./,$ip))[3];
3959: if ($last <=$high && $last >=$low) { $allowed=1; }
3960: }
3961: } elsif ($pattern =~ /^\*/) {
3962: #*.msu.edu
3963: $pattern=~s/\*//;
3964: if (!defined($name)) {
3965: use Socket;
3966: my $netaddr=inet_aton($ip);
3967: ($name)=gethostbyaddr($netaddr,AF_INET);
3968: }
3969: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3970: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3971: #127.0.0.1
3972: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3973: } else {
3974: #some.name.com
3975: if (!defined($name)) {
3976: use Socket;
3977: my $netaddr=inet_aton($ip);
3978: ($name)=gethostbyaddr($netaddr,AF_INET);
3979: }
3980: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3981: }
3982: if ($allowed) { last; }
3983: }
3984: return $allowed;
3985: }
3986:
3987: ###############################################
3988:
1.60 matthew 3989: =pod
3990:
1.112 bowersj2 3991: =head1 Domain Template Functions
3992:
3993: =over 4
3994:
3995: =item * &determinedomain()
1.60 matthew 3996:
3997: Inputs: $domain (usually will be undef)
3998:
1.63 www 3999: Returns: Determines which domain should be used for designs
1.60 matthew 4000:
4001: =cut
1.54 www 4002:
1.60 matthew 4003: ###############################################
1.63 www 4004: sub determinedomain {
4005: my $domain=shift;
1.531 albertel 4006: if (! $domain) {
1.60 matthew 4007: # Determine domain if we have not been given one
4008: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 4009: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4010: if ($env{'request.role.domain'}) {
4011: $domain=$env{'request.role.domain'};
1.60 matthew 4012: }
4013: }
1.63 www 4014: return $domain;
4015: }
4016: ###############################################
1.517 raeburn 4017:
1.518 albertel 4018: sub devalidate_domconfig_cache {
4019: my ($udom)=@_;
4020: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4021: }
4022:
4023: # ---------------------- Get domain configuration for a domain
4024: sub get_domainconf {
4025: my ($udom) = @_;
4026: my $cachetime=1800;
4027: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4028: if (defined($cached)) { return %{$result}; }
4029:
4030: my %domconfig = &Apache::lonnet::get_dom('configuration',
4031: ['login','rolecolors'],$udom);
1.632 raeburn 4032: my (%designhash,%legacy);
1.518 albertel 4033: if (keys(%domconfig) > 0) {
4034: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4035: if (keys(%{$domconfig{'login'}})) {
4036: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4037: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4038: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4039: $designhash{$udom.'.login.'.$key.'_'.$img} =
4040: $domconfig{'login'}{$key}{$img};
4041: }
4042: } else {
4043: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4044: }
1.632 raeburn 4045: }
4046: } else {
4047: $legacy{'login'} = 1;
1.518 albertel 4048: }
1.632 raeburn 4049: } else {
4050: $legacy{'login'} = 1;
1.518 albertel 4051: }
4052: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4053: if (keys(%{$domconfig{'rolecolors'}})) {
4054: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4055: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4056: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4057: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4058: }
1.518 albertel 4059: }
4060: }
1.632 raeburn 4061: } else {
4062: $legacy{'rolecolors'} = 1;
1.518 albertel 4063: }
1.632 raeburn 4064: } else {
4065: $legacy{'rolecolors'} = 1;
1.518 albertel 4066: }
1.632 raeburn 4067: if (keys(%legacy) > 0) {
4068: my %legacyhash = &get_legacy_domconf($udom);
4069: foreach my $item (keys(%legacyhash)) {
4070: if ($item =~ /^\Q$udom\E\.login/) {
4071: if ($legacy{'login'}) {
4072: $designhash{$item} = $legacyhash{$item};
4073: }
4074: } else {
4075: if ($legacy{'rolecolors'}) {
4076: $designhash{$item} = $legacyhash{$item};
4077: }
1.518 albertel 4078: }
4079: }
4080: }
1.632 raeburn 4081: } else {
4082: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4083: }
4084: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4085: $cachetime);
4086: return %designhash;
4087: }
4088:
1.632 raeburn 4089: sub get_legacy_domconf {
4090: my ($udom) = @_;
4091: my %legacyhash;
4092: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4093: my $designfile = $designdir.'/'.$udom.'.tab';
4094: if (-e $designfile) {
4095: if ( open (my $fh,"<$designfile") ) {
4096: while (my $line = <$fh>) {
4097: next if ($line =~ /^\#/);
4098: chomp($line);
4099: my ($key,$val)=(split(/\=/,$line));
4100: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4101: }
4102: close($fh);
4103: }
4104: }
4105: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4106: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4107: }
4108: return %legacyhash;
4109: }
4110:
1.63 www 4111: =pod
4112:
1.112 bowersj2 4113: =item * &domainlogo()
1.63 www 4114:
4115: Inputs: $domain (usually will be undef)
4116:
4117: Returns: A link to a domain logo, if the domain logo exists.
4118: If the domain logo does not exist, a description of the domain.
4119:
4120: =cut
1.112 bowersj2 4121:
1.63 www 4122: ###############################################
4123: sub domainlogo {
1.517 raeburn 4124: my $domain = &determinedomain(shift);
1.518 albertel 4125: my %designhash = &get_domainconf($domain);
1.517 raeburn 4126: # See if there is a logo
4127: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4128: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4129: if ($imgsrc =~ m{^/(adm|res)/}) {
4130: if ($imgsrc =~ m{^/res/}) {
4131: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4132: &Apache::lonnet::repcopy($local_name);
4133: }
4134: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4135: }
4136: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4137: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4138: return &Apache::lonnet::domain($domain,'description');
1.59 www 4139: } else {
1.60 matthew 4140: return '';
1.59 www 4141: }
4142: }
1.63 www 4143: ##############################################
4144:
4145: =pod
4146:
1.112 bowersj2 4147: =item * &designparm()
1.63 www 4148:
4149: Inputs: $which parameter; $domain (usually will be undef)
4150:
4151: Returns: value of designparamter $which
4152:
4153: =cut
1.112 bowersj2 4154:
1.397 albertel 4155:
1.400 albertel 4156: ##############################################
1.397 albertel 4157: sub designparm {
4158: my ($which,$domain)=@_;
4159: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4160: return $env{'environment.color.'.$which};
1.96 www 4161: }
1.63 www 4162: $domain=&determinedomain($domain);
1.518 albertel 4163: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4164: my $output;
1.517 raeburn 4165: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4166: $output = $domdesign{$domain.'.'.$which};
1.63 www 4167: } else {
1.520 raeburn 4168: $output = $defaultdesign{$which};
4169: }
4170: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4171: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4172: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4173: if ($output =~ m{^/res/}) {
4174: my $local_name = &Apache::lonnet::filelocation('',$output);
4175: &Apache::lonnet::repcopy($local_name);
4176: }
1.520 raeburn 4177: $output = &lonhttpdurl($output);
4178: }
1.63 www 4179: }
1.520 raeburn 4180: return $output;
1.63 www 4181: }
1.59 www 4182:
1.822 bisitz 4183: ##############################################
4184: =pod
4185:
1.832 bisitz 4186: =item * &authorspace()
4187:
4188: Inputs: ./.
4189:
4190: Returns: Path to the Construction Space of the current user's
4191: accessed author space
4192: The author space will be that of the current user
4193: when accessing the own author space
4194: and that of the co-author/assistent co-author
4195: when accessing the co-author's/assistent co-author's
4196: space
4197:
4198: =cut
4199:
4200: sub authorspace {
4201: my $caname = '';
4202: if ($env{'request.role'} =~ /^ca|^aa/) {
4203: (undef,$caname) =
4204: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4205: } else {
4206: $caname = $env{'user.name'};
4207: }
4208: return '/priv/'.$caname.'/';
4209: }
4210:
4211: ##############################################
4212: =pod
4213:
1.822 bisitz 4214: =item * &head_subbox()
4215:
4216: Inputs: $content (contains HTML code with page functions, etc.)
4217:
4218: Returns: HTML div with $content
4219: To be included in page header
4220:
4221: =cut
4222:
4223: sub head_subbox {
4224: my ($content)=@_;
4225: my $output =
4226: '<div id="LC_head_subbox2">' #FIXME: solve conflicts with lonhtmlcommon:breadcrumbs LC_head_subbox
4227: .$content
4228: .'</div>'
4229: }
4230:
4231: ##############################################
4232: =pod
4233:
4234: =item * &CSTR_pageheader()
4235:
4236: Inputs: ./.
4237:
4238: Returns: HTML div with CSTR path and recent box
4239: To be included on Construction Space pages
4240:
4241: =cut
4242:
4243: sub CSTR_pageheader {
4244: # this is for resources; directories have customtitle, and crumbs
4245: # and select recent are created in lonpubdir.pm
4246: my ($uname,$thisdisfn)=
4247: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4248: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4249: $formaction=~s/\/+/\//g;
4250:
4251: my $parentpath = '';
4252: my $lastitem = '';
4253: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4254: $parentpath = $1;
4255: $lastitem = $2;
4256: } else {
4257: $lastitem = $thisdisfn;
4258: }
4259: return
4260: '<div>'
4261: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4262: .'<b>'.&mt('Construction Space:').'</b> '
4263: .'<form name="dirs" method="post" action="'.$formaction
4264: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4265: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4266: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4267: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4268: .'</form>'
4269: .&Apache::lonmenu::constspaceform()
4270: .'</div>';
4271: }
4272:
1.60 matthew 4273: ###############################################
4274: ###############################################
4275:
4276: =pod
4277:
1.112 bowersj2 4278: =back
4279:
1.549 albertel 4280: =head1 HTML Helpers
1.112 bowersj2 4281:
4282: =over 4
4283:
4284: =item * &bodytag()
1.60 matthew 4285:
4286: Returns a uniform header for LON-CAPA web pages.
4287:
4288: Inputs:
4289:
1.112 bowersj2 4290: =over 4
4291:
4292: =item * $title, A title to be displayed on the page.
4293:
4294: =item * $function, the current role (can be undef).
4295:
4296: =item * $addentries, extra parameters for the <body> tag.
4297:
4298: =item * $bodyonly, if defined, only return the <body> tag.
4299:
4300: =item * $domain, if defined, force a given domain.
4301:
4302: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4303: text interface only)
1.60 matthew 4304:
1.814 bisitz 4305: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4306: navigational links
1.317 albertel 4307:
1.338 albertel 4308: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4309:
1.361 albertel 4310: =item * $no_inline_link, if true and in remote mode, don't show the
4311: 'Switch To Inline Menu' link
4312:
1.460 albertel 4313: =item * $args, optional argument valid values are
4314: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4315: inherit_jsmath -> when creating popup window in a page,
4316: should it have jsmath forced on by the
4317: current page
1.460 albertel 4318:
1.112 bowersj2 4319: =back
4320:
1.60 matthew 4321: Returns: A uniform header for LON-CAPA web pages.
4322: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4323: If $bodyonly is undef or zero, an html string containing a <body> tag and
4324: other decorations will be returned.
4325:
4326: =cut
4327:
1.54 www 4328: sub bodytag {
1.831 bisitz 4329: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4330: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4331:
1.460 albertel 4332: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4333:
1.183 matthew 4334: $function = &get_users_function() if (!$function);
1.339 albertel 4335: my $img = &designparm($function.'.img',$domain);
4336: my $font = &designparm($function.'.font',$domain);
4337: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4338:
1.803 bisitz 4339: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4340: 'bgcolor' => $pgbg,
1.339 albertel 4341: 'text' => $font,
4342: 'alink' => &designparm($function.'.alink',$domain),
4343: 'vlink' => &designparm($function.'.vlink',$domain),
4344: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4345: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4346:
1.63 www 4347: # role and realm
1.378 raeburn 4348: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4349: if ($role eq 'ca') {
1.479 albertel 4350: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4351: $realm = &plainname($rname,$rdom);
1.378 raeburn 4352: }
1.55 www 4353: # realm
1.258 albertel 4354: if ($env{'request.course.id'}) {
1.378 raeburn 4355: if ($env{'request.role'} !~ /^cr/) {
4356: $role = &Apache::lonnet::plaintext($role,&course_type());
4357: }
1.359 albertel 4358: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4359: } else {
4360: $role = &Apache::lonnet::plaintext($role);
1.54 www 4361: }
1.433 albertel 4362:
1.359 albertel 4363: if (!$realm) { $realm=' '; }
1.55 www 4364: # Set messages
1.60 matthew 4365: my $messages=&domainlogo($domain);
1.330 albertel 4366:
1.438 albertel 4367: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4368:
1.101 www 4369: # construct main body tag
1.359 albertel 4370: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4371: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4372:
1.530 albertel 4373: if ($bodyonly) {
1.60 matthew 4374: return $bodytag;
1.798 tempelho 4375: }
1.359 albertel 4376:
1.410 albertel 4377: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4378: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4379: undef($role);
1.434 albertel 4380: } else {
4381: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4382: }
1.359 albertel 4383:
1.762 bisitz 4384: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4385: #
4386: # Extra info if you are the DC
4387: my $dc_info = '';
4388: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4389: $env{'course.'.$env{'request.course.id'}.
4390: '.domain'}.'/'})) {
4391: my $cid = $env{'request.course.id'};
4392: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4393: $dc_info =~ s/\s+$//;
1.359 albertel 4394: $dc_info = '('.$dc_info.')';
4395: }
4396:
1.837 bisitz 4397: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4398: # No Remote
1.258 albertel 4399: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4400: $forcereg=1;
4401: }
4402:
1.836 bisitz 4403: # if ($env{'request.state'} eq 'construct') {
4404: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4405: # }
1.359 albertel 4406:
1.816 bisitz 4407: my $titletable = '<table id="LC_title_bar">'
1.836 bisitz 4408: ."<tr><td> $titleinfo $dc_info</td>"
1.816 bisitz 4409: .'</tr></table>';
4410:
1.814 bisitz 4411: if ($no_nav_bar) {
1.359 albertel 4412: $bodytag .= $titletable;
4413: } else {
1.813 bisitz 4414: $bodytag .= qq|<div id="LC_nav_bar">$name ($role)<br />
4415: <em>$realm</em> $dc_info</div>|;
1.359 albertel 4416: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4417: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4418: $titletable);
1.272 raeburn 4419: } else {
1.336 albertel 4420: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4421: $titletable;
1.272 raeburn 4422: }
1.235 raeburn 4423: }
4424: return $bodytag;
1.94 www 4425: }
1.95 www 4426:
1.93 www 4427: #
1.95 www 4428: # Top frame rendering, Remote is up
1.93 www 4429: #
1.359 albertel 4430:
1.517 raeburn 4431: my $imgsrc = $img;
4432: if ($img =~ /^\/adm/) {
1.575 albertel 4433: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4434: }
4435: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4436:
1.305 www 4437: # Explicit link to get inline menu
1.361 albertel 4438: my $menu= ($no_inline_link?''
4439: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4440: #
1.94 www 4441: return(<<ENDBODY);
1.60 matthew 4442: $bodytag
1.359 albertel 4443: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4444: <tr><td>$upperleft</td>
4445: <td>$messages </td>
1.54 www 4446: </tr>
1.359 albertel 4447: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4448: </tr>
1.356 albertel 4449: </table>
1.54 www 4450: ENDBODY
1.182 matthew 4451: }
4452:
1.330 albertel 4453: sub make_attr_string {
4454: my ($register,$attr_ref) = @_;
4455:
4456: if ($attr_ref && !ref($attr_ref)) {
4457: die("addentries Must be a hash ref ".
4458: join(':',caller(1))." ".
4459: join(':',caller(0))." ");
4460: }
4461:
4462: if ($register) {
1.339 albertel 4463: my ($on_load,$on_unload);
4464: foreach my $key (keys(%{$attr_ref})) {
4465: if (lc($key) eq 'onload') {
4466: $on_load.=$attr_ref->{$key}.';';
4467: delete($attr_ref->{$key});
4468:
4469: } elsif (lc($key) eq 'onunload') {
4470: $on_unload.=$attr_ref->{$key}.';';
4471: delete($attr_ref->{$key});
4472: }
4473: }
4474: $attr_ref->{'onload'} =
4475: &Apache::lonmenu::loadevents(). $on_load;
4476: $attr_ref->{'onunload'}=
4477: &Apache::lonmenu::unloadevents().$on_unload;
4478: }
4479:
4480: # Accessibility font enhance
4481: if ($env{'browser.fontenhance'} eq 'on') {
4482: my $style;
4483: foreach my $key (keys(%{$attr_ref})) {
4484: if (lc($key) eq 'style') {
4485: $style.=$attr_ref->{$key}.';';
4486: delete($attr_ref->{$key});
4487: }
4488: }
4489: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4490: }
1.339 albertel 4491:
1.330 albertel 4492: my $attr_string;
4493: foreach my $attr (keys(%$attr_ref)) {
4494: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4495: }
4496: return $attr_string;
4497: }
4498:
4499:
1.182 matthew 4500: ###############################################
1.251 albertel 4501: ###############################################
4502:
4503: =pod
4504:
4505: =item * &endbodytag()
4506:
4507: Returns a uniform footer for LON-CAPA web pages.
4508:
1.635 raeburn 4509: Inputs: 1 - optional reference to an args hash
4510: If in the hash, key for noredirectlink has a value which evaluates to true,
4511: a 'Continue' link is not displayed if the page contains an
4512: internal redirect in the <head></head> section,
4513: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4514:
4515: =cut
4516:
4517: sub endbodytag {
1.635 raeburn 4518: my ($args) = @_;
1.251 albertel 4519: my $endbodytag='</body>';
1.269 albertel 4520: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4521: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4522: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4523: $endbodytag=
4524: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4525: &mt('Continue').'</a>'.
4526: $endbodytag;
4527: }
1.315 albertel 4528: }
1.251 albertel 4529: return $endbodytag;
4530: }
4531:
1.352 albertel 4532: =pod
4533:
4534: =item * &standard_css()
4535:
4536: Returns a style sheet
4537:
4538: Inputs: (all optional)
4539: domain -> force to color decorate a page for a specific
4540: domain
4541: function -> force usage of a specific rolish color scheme
4542: bgcolor -> override the default page bgcolor
4543:
4544: =cut
4545:
1.343 albertel 4546: sub standard_css {
1.345 albertel 4547: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4548: $function = &get_users_function() if (!$function);
4549: my $img = &designparm($function.'.img', $domain);
4550: my $tabbg = &designparm($function.'.tabbg', $domain);
4551: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4552: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4553: #second colour for later usage
1.345 albertel 4554: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4555: my $pgbg_or_bgcolor =
4556: $bgcolor ||
1.352 albertel 4557: &designparm($function.'.pgbg', $domain);
1.382 albertel 4558: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4559: my $alink = &designparm($function.'.alink', $domain);
4560: my $vlink = &designparm($function.'.vlink', $domain);
4561: my $link = &designparm($function.'.link', $domain);
4562:
1.704 muellerd 4563: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4564: my $bgcol = &designparm('login.bgcol',$domain);
4565: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4566:
1.602 albertel 4567: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4568: my $mono = 'monospace';
1.352 albertel 4569: my $data_table_head = $tabbg;
4570: my $data_table_light = '#EEEEEE';
1.470 banghart 4571: my $data_table_dark = '#DDDDDD';
4572: my $data_table_darker = '#CCCCCC';
1.349 albertel 4573: my $data_table_highlight = '#FFFF00';
1.352 albertel 4574: my $mail_new = '#FFBB77';
4575: my $mail_new_hover = '#DD9955';
4576: my $mail_read = '#BBBB77';
4577: my $mail_read_hover = '#999944';
4578: my $mail_replied = '#AAAA88';
4579: my $mail_replied_hover = '#888855';
4580: my $mail_other = '#99BBBB';
4581: my $mail_other_hover = '#669999';
1.391 albertel 4582: my $table_header = '#DDDDDD';
1.489 raeburn 4583: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4584: my $lg_border_color = '#C8C8C8';
1.392 albertel 4585:
1.608 albertel 4586: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4587: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4588: : '0 3px 0 4px';
1.448 albertel 4589:
1.523 albertel 4590:
1.343 albertel 4591: return <<END;
1.795 www 4592: body {
4593: font-family: $sans;
4594: line-height:130%;
4595: font-size:0.83em;
4596: color:$font;
4597: }
4598:
4599: a:link, a:visited {
4600: font-size:100%;
4601: }
4602:
4603: a:focus {
4604: color: red;
4605: background: yellow
4606: }
1.698 harmsja 4607:
1.795 www 4608: form, .inline {
4609: display: inline;
4610: }
1.721 harmsja 4611:
1.795 www 4612: .LC_right {
4613: text-align:right;
4614: }
4615:
4616: .LC_middle {
4617: vertical-align:middle;
4618: }
1.721 harmsja 4619:
4620: /* just for tests */
1.754 droeschl 4621: .LC_400Box {width:400px; }
1.721 harmsja 4622: /* end */
4623:
1.778 bisitz 4624: .LC_filename {
4625: font-family: $mono;
4626: white-space:pre;
4627: }
4628:
4629: .LC_fileicon {
4630: border: none;
4631: height: 1.3em;
4632: vertical-align: text-bottom;
4633: margin-right: 0.3em;
4634: text-decoration:none;
4635: }
4636:
1.350 albertel 4637: .LC_error {
4638: color: red;
4639: font-size: larger;
4640: }
1.795 www 4641:
1.457 albertel 4642: .LC_warning,
4643: .LC_diff_removed {
1.733 bisitz 4644: color: red;
1.394 albertel 4645: }
1.532 albertel 4646:
4647: .LC_info,
1.457 albertel 4648: .LC_success,
4649: .LC_diff_added {
1.350 albertel 4650: color: green;
4651: }
1.795 www 4652:
1.802 bisitz 4653: div.LC_confirm_box {
4654: background-color: #FAFAFA;
4655: border: 1px solid $lg_border_color;
4656: margin-right: 0;
4657: padding: 5px;
4658: }
4659:
4660: div.LC_confirm_box .LC_error img,
4661: div.LC_confirm_box .LC_success img {
4662: vertical-align: middle;
4663: }
4664:
1.440 albertel 4665: .LC_icon {
1.771 droeschl 4666: border: none;
1.790 droeschl 4667: vertical-align: middle;
1.771 droeschl 4668: }
4669:
1.543 albertel 4670: .LC_docs_spacer {
4671: width: 25px;
4672: height: 1px;
1.771 droeschl 4673: border: none;
1.543 albertel 4674: }
1.346 albertel 4675:
1.532 albertel 4676: .LC_internal_info {
1.735 bisitz 4677: color: #999999;
1.532 albertel 4678: }
4679:
1.794 www 4680: .LC_discussion {
4681: background: $tabbg;
4682: border: 1px solid black;
4683: margin: 2px;
4684: }
4685:
4686: .LC_disc_action_links_bar {
4687: background: $tabbg;
1.803 bisitz 4688: border: none;
1.795 www 4689: margin: 4px;
1.794 www 4690: }
4691:
4692: .LC_disc_action_left {
4693: text-align: left;
4694: }
4695:
4696: .LC_disc_action_right {
4697: text-align: right;
4698: }
4699:
4700: .LC_disc_new_item {
4701: background: white;
4702: border: 2px solid red;
4703: margin: 2px;
4704: }
4705:
4706: .LC_disc_old_item {
4707: background: white;
4708: border: 1px solid black;
4709: margin: 2px;
4710: }
4711:
1.458 albertel 4712: table.LC_pastsubmission {
4713: border: 1px solid black;
4714: margin: 2px;
4715: }
4716:
1.795 www 4717: table#LC_top_nav,
4718: table#LC_menubuttons,
4719: table#LC_nav_location {
1.345 albertel 4720: width: 100%;
4721: background: $pgbg;
1.392 albertel 4722: border: 2px;
1.402 albertel 4723: border-collapse: separate;
1.803 bisitz 4724: padding: 0;
1.345 albertel 4725: }
1.392 albertel 4726:
1.801 tempelho 4727: table#LC_title_bar a {
4728: color: $fontmenu;
4729: }
1.836 bisitz 4730:
1.807 droeschl 4731: table#LC_title_bar {
1.819 tempelho 4732: clear: both;
1.836 bisitz 4733: display: none;
1.807 droeschl 4734: }
4735:
1.795 www 4736: table#LC_title_bar,
4737: table.LC_breadcrumbs,
1.393 albertel 4738: table#LC_title_bar.LC_with_remote {
1.359 albertel 4739: width: 100%;
1.392 albertel 4740: border-color: $pgbg;
4741: border-style: solid;
4742: border-width: $border;
1.379 albertel 4743: background: $pgbg;
1.801 tempelho 4744: color: $fontmenu;
1.392 albertel 4745: border-collapse: collapse;
1.803 bisitz 4746: padding: 0;
1.819 tempelho 4747: margin: 0;
1.359 albertel 4748: }
1.795 www 4749:
1.409 albertel 4750: table.LC_docs_path {
4751: width: 100%;
4752: border: 0;
4753: background: $pgbg;
4754: border-collapse: collapse;
1.803 bisitz 4755: padding: 0;
1.409 albertel 4756: }
4757:
1.359 albertel 4758: table#LC_title_bar td {
4759: background: $tabbg;
4760: }
1.795 www 4761:
1.706 harmsja 4762: table#LC_menubuttons img{
1.803 bisitz 4763: border: none;
1.346 albertel 4764: }
1.795 www 4765:
1.345 albertel 4766: table#LC_top_nav td {
4767: background: $tabbg;
1.803 bisitz 4768: border: none;
1.407 albertel 4769: font-size: small;
1.706 harmsja 4770: vertical-align:top;
4771: padding:2px 5px 2px 5px;
1.345 albertel 4772: }
1.795 www 4773:
4774: table#LC_top_nav td a,
4775: div#LC_top_nav a {
1.345 albertel 4776: color: $font;
4777: }
1.795 www 4778:
1.364 albertel 4779: table#LC_top_nav td.LC_top_nav_logo {
4780: background: $tabbg;
1.432 albertel 4781: text-align: left;
1.408 albertel 4782: white-space: nowrap;
1.432 albertel 4783: width: 31px;
1.408 albertel 4784: }
1.795 www 4785:
1.408 albertel 4786: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4787: border: none;
1.408 albertel 4788: vertical-align: bottom;
1.364 albertel 4789: }
1.795 www 4790:
1.777 tempelho 4791: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4792: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4793: width: 2.0em;
4794: }
1.795 www 4795:
1.442 albertel 4796: table#LC_top_nav td.LC_top_nav_login {
4797: width: 4.0em;
4798: text-align: center;
4799: }
1.795 www 4800:
4801: table.LC_breadcrumbs td,
4802: table.LC_docs_path td {
1.357 albertel 4803: background: $tabbg;
1.801 tempelho 4804: color: $fontmenu;
1.358 albertel 4805: font-size: smaller;
1.357 albertel 4806: }
1.795 www 4807:
1.777 tempelho 4808: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4809: table.LC_docs_path td.LC_docs_path_component {
1.779 bisitz 4810: background: $tabbg;
1.801 tempelho 4811: color: $fontmenu;
1.779 bisitz 4812: font-size: larger;
4813: text-align: right;
1.777 tempelho 4814: }
1.795 www 4815:
1.383 albertel 4816: td.LC_table_cell_checkbox {
4817: text-align: center;
4818: }
1.795 www 4819:
1.779 bisitz 4820: table#LC_mainmenu td.LC_mainmenu_column {
4821: vertical-align: top;
1.777 tempelho 4822: }
1.522 albertel 4823:
1.795 www 4824: .LC_fontsize_small {
1.705 tempelho 4825: font-size: 70%;
4826: }
4827:
1.819 tempelho 4828: #LC_head_subbox {
4829: clear:both;
4830: background: $sidebg;
1.822 bisitz 4831: border-bottom: 1px solid $lg_border_color;
1.819 tempelho 4832: height: 32px;
4833: line-height: 32px;
1.822 bisitz 4834: margin: 0;
1.819 tempelho 4835: padding: 0;
4836: }
1.839 droeschl 4837: /* Preliminary fix to hide breadcrumbs inside remote control window */
4838: #LC_remote #LC_head_subbox {
4839: display:none;
4840: }
1.819 tempelho 4841:
1.822 bisitz 4842: #LC_head_subbox2 { /* FIXME: replace by LC_head_subbox once lonhtmlcommon::breadcrumbs has been fixed */
4843: clear:both;
4844: background: #F8F8F8; /* $sidebg; */
4845: border-bottom: 1px solid $lg_border_color;
4846: margin: 0 0 10px 0;
4847: padding: 5px;
4848: }
4849:
1.795 www 4850: .LC_fontsize_medium {
1.705 tempelho 4851: font-size: 85%;
4852: }
4853:
1.795 www 4854: .LC_fontsize_large {
1.705 tempelho 4855: font-size: 120%;
4856: }
4857:
1.346 albertel 4858: .LC_menubuttons_inline_text {
4859: color: $font;
1.698 harmsja 4860: font-size: 90%;
1.701 harmsja 4861: padding-left:3px;
1.346 albertel 4862: }
4863:
1.526 www 4864: .LC_menubuttons_link {
4865: text-decoration: none;
4866: }
1.795 www 4867:
1.522 albertel 4868: .LC_menubuttons_category {
1.521 www 4869: color: $font;
1.526 www 4870: background: $pgbg;
1.521 www 4871: font-size: larger;
4872: font-weight: bold;
4873: }
4874:
1.346 albertel 4875: td.LC_menubuttons_text {
1.779 bisitz 4876: color: $font;
1.346 albertel 4877: }
1.706 harmsja 4878:
1.346 albertel 4879: .LC_current_location {
4880: background: $tabbg;
4881: }
1.795 www 4882:
1.346 albertel 4883: .LC_new_mail {
1.634 www 4884: background: $tabbg;
1.346 albertel 4885: font-weight: bold;
4886: }
1.347 albertel 4887:
1.666 raeburn 4888: .LC_roleslog_note {
1.701 harmsja 4889: font-size: small;
1.666 raeburn 4890: }
4891:
1.715 raeburn 4892: .LC_mail_functions {
4893: font-weight: bold;
4894: }
4895:
1.795 www 4896: table.LC_data_table,
4897: table.LC_mail_list {
1.347 albertel 4898: border: 1px solid #000000;
1.402 albertel 4899: border-collapse: separate;
1.426 albertel 4900: border-spacing: 1px;
1.610 albertel 4901: background: $pgbg;
1.347 albertel 4902: }
1.795 www 4903:
1.422 albertel 4904: .LC_data_table_dense {
4905: font-size: small;
4906: }
1.795 www 4907:
1.507 raeburn 4908: table.LC_nested_outer {
4909: border: 1px solid #000000;
1.589 raeburn 4910: border-collapse: collapse;
1.803 bisitz 4911: border-spacing: 0;
1.507 raeburn 4912: width: 100%;
4913: }
1.795 www 4914:
1.507 raeburn 4915: table.LC_nested {
1.803 bisitz 4916: border: none;
1.589 raeburn 4917: border-collapse: collapse;
1.803 bisitz 4918: border-spacing: 0;
1.507 raeburn 4919: width: 100%;
4920: }
1.795 www 4921:
4922: table.LC_data_table tr th,
4923: table.LC_calendar tr th,
4924: table.LC_mail_list tr th,
1.523 albertel 4925: table.LC_prior_tries tr th {
1.349 albertel 4926: font-weight: bold;
4927: background-color: $data_table_head;
1.801 tempelho 4928: color:$fontmenu;
1.701 harmsja 4929: font-size:90%;
1.347 albertel 4930: }
1.795 www 4931:
1.711 raeburn 4932: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4933: background-color: #CCCCCC;
1.711 raeburn 4934: font-weight: bold;
4935: text-align: left;
4936: }
1.795 www 4937:
1.779 bisitz 4938: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4939: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4940: background-color: $data_table_light;
1.425 albertel 4941: padding: 2px;
1.347 albertel 4942: }
1.795 www 4943:
1.610 albertel 4944: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4945: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4946: background-color: $data_table_dark;
1.709 bisitz 4947: padding: 2px;
1.347 albertel 4948: }
1.795 www 4949:
1.425 albertel 4950: table.LC_data_table tr.LC_data_table_highlight td {
4951: background-color: $data_table_darker;
4952: }
1.795 www 4953:
1.639 raeburn 4954: table.LC_data_table tr td.LC_leftcol_header {
4955: background-color: $data_table_head;
4956: font-weight: bold;
4957: }
1.795 www 4958:
1.451 albertel 4959: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4960: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4961: background-color: #FFFFFF;
1.421 albertel 4962: font-weight: bold;
4963: font-style: italic;
4964: text-align: center;
4965: padding: 8px;
1.347 albertel 4966: }
1.795 www 4967:
1.507 raeburn 4968: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4969: padding: 4ex
4970: }
1.795 www 4971:
1.507 raeburn 4972: table.LC_nested_outer tr th {
4973: font-weight: bold;
1.801 tempelho 4974: color:$fontmenu;
1.507 raeburn 4975: background-color: $data_table_head;
1.701 harmsja 4976: font-size: small;
1.507 raeburn 4977: border-bottom: 1px solid #000000;
4978: }
1.795 www 4979:
1.507 raeburn 4980: table.LC_nested_outer tr td.LC_subheader {
4981: background-color: $data_table_head;
4982: font-weight: bold;
4983: font-size: small;
4984: border-bottom: 1px solid #000000;
4985: text-align: right;
1.451 albertel 4986: }
1.795 www 4987:
1.507 raeburn 4988: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4989: background-color: #CCCCCC;
1.451 albertel 4990: font-weight: bold;
4991: font-size: small;
1.507 raeburn 4992: text-align: center;
4993: }
1.795 www 4994:
1.589 raeburn 4995: table.LC_nested tr.LC_info_row td.LC_left_item,
4996: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4997: text-align: left;
1.451 albertel 4998: }
1.795 www 4999:
1.507 raeburn 5000: table.LC_nested td {
1.735 bisitz 5001: background-color: #FFFFFF;
1.451 albertel 5002: font-size: small;
1.507 raeburn 5003: }
1.795 www 5004:
1.507 raeburn 5005: table.LC_nested_outer tr th.LC_right_item,
5006: table.LC_nested tr.LC_info_row td.LC_right_item,
5007: table.LC_nested tr.LC_odd_row td.LC_right_item,
5008: table.LC_nested tr td.LC_right_item {
1.451 albertel 5009: text-align: right;
5010: }
5011:
1.507 raeburn 5012: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5013: background-color: #EEEEEE;
1.451 albertel 5014: }
5015:
1.473 raeburn 5016: table.LC_createuser {
5017: }
5018:
5019: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5020: font-size: small;
1.473 raeburn 5021: }
5022:
5023: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5024: background-color: #CCCCCC;
1.473 raeburn 5025: font-weight: bold;
5026: text-align: center;
5027: }
5028:
1.349 albertel 5029: table.LC_calendar {
5030: border: 1px solid #000000;
5031: border-collapse: collapse;
5032: }
1.795 www 5033:
1.349 albertel 5034: table.LC_calendar_pickdate {
5035: font-size: xx-small;
5036: }
1.795 www 5037:
1.349 albertel 5038: table.LC_calendar tr td {
5039: border: 1px solid #000000;
5040: vertical-align: top;
5041: }
1.795 www 5042:
1.349 albertel 5043: table.LC_calendar tr td.LC_calendar_day_empty {
5044: background-color: $data_table_dark;
5045: }
1.795 www 5046:
1.779 bisitz 5047: table.LC_calendar tr td.LC_calendar_day_current {
5048: background-color: $data_table_highlight;
1.777 tempelho 5049: }
1.795 www 5050:
1.349 albertel 5051: table.LC_mail_list tr.LC_mail_new {
5052: background-color: $mail_new;
5053: }
1.795 www 5054:
1.349 albertel 5055: table.LC_mail_list tr.LC_mail_new:hover {
5056: background-color: $mail_new_hover;
5057: }
1.795 www 5058:
5059: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5060: }
1.795 www 5061:
5062: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5063: }
1.795 www 5064:
1.349 albertel 5065: table.LC_mail_list tr.LC_mail_read {
5066: background-color: $mail_read;
5067: }
1.795 www 5068:
1.349 albertel 5069: table.LC_mail_list tr.LC_mail_read:hover {
5070: background-color: $mail_read_hover;
5071: }
1.795 www 5072:
1.349 albertel 5073: table.LC_mail_list tr.LC_mail_replied {
5074: background-color: $mail_replied;
5075: }
1.795 www 5076:
1.349 albertel 5077: table.LC_mail_list tr.LC_mail_replied:hover {
5078: background-color: $mail_replied_hover;
5079: }
1.795 www 5080:
1.349 albertel 5081: table.LC_mail_list tr.LC_mail_other {
5082: background-color: $mail_other;
5083: }
1.795 www 5084:
1.349 albertel 5085: table.LC_mail_list tr.LC_mail_other:hover {
5086: background-color: $mail_other_hover;
5087: }
1.494 raeburn 5088:
1.777 tempelho 5089: table.LC_data_table tr > td.LC_browser_file,
5090: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5091: background: #CCFF88;
5092: }
1.795 www 5093:
1.777 tempelho 5094: table.LC_data_table tr > td.LC_browser_file_locked,
5095: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5096: background: #FFAA99;
1.387 albertel 5097: }
1.795 www 5098:
1.777 tempelho 5099: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5100: background: #AAAAAA;
5101: }
1.795 www 5102:
1.777 tempelho 5103: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5104: table.LC_data_table tr > td.LC_browser_file_metamodified {
5105: background: #FFFF77;
1.777 tempelho 5106: }
1.795 www 5107:
1.696 bisitz 5108: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5109: background: #CCCCFF;
1.387 albertel 5110: }
1.696 bisitz 5111:
1.707 bisitz 5112: table.LC_data_table tr > td.LC_roles_is {
5113: /* background: #77FF77; */
5114: }
1.795 www 5115:
1.707 bisitz 5116: table.LC_data_table tr > td.LC_roles_future {
5117: background: #FFFF77;
5118: }
1.795 www 5119:
1.707 bisitz 5120: table.LC_data_table tr > td.LC_roles_will {
5121: background: #FFAA77;
5122: }
1.795 www 5123:
1.707 bisitz 5124: table.LC_data_table tr > td.LC_roles_expired {
5125: background: #FF7777;
5126: }
1.795 www 5127:
1.707 bisitz 5128: table.LC_data_table tr > td.LC_roles_will_not {
5129: background: #AAFF77;
5130: }
1.795 www 5131:
1.707 bisitz 5132: table.LC_data_table tr > td.LC_roles_selected {
5133: background: #11CC55;
5134: }
5135:
1.388 albertel 5136: span.LC_current_location {
1.701 harmsja 5137: font-size:larger;
1.388 albertel 5138: background: $pgbg;
5139: }
1.387 albertel 5140:
1.395 albertel 5141: span.LC_parm_menu_item {
5142: font-size: larger;
5143: }
1.795 www 5144:
1.395 albertel 5145: span.LC_parm_scope_all {
5146: color: red;
5147: }
1.795 www 5148:
1.395 albertel 5149: span.LC_parm_scope_folder {
5150: color: green;
5151: }
1.795 www 5152:
1.395 albertel 5153: span.LC_parm_scope_resource {
5154: color: orange;
5155: }
1.795 www 5156:
1.395 albertel 5157: span.LC_parm_part {
5158: color: blue;
5159: }
1.795 www 5160:
1.395 albertel 5161: span.LC_parm_folder, span.LC_parm_symb {
5162: font-size: x-small;
5163: font-family: $mono;
5164: color: #AAAAAA;
5165: }
5166:
1.795 www 5167: td.LC_parm_overview_level_menu,
5168: td.LC_parm_overview_map_menu,
5169: td.LC_parm_overview_parm_selectors,
5170: td.LC_parm_overview_restrictions {
1.396 albertel 5171: border: 1px solid black;
5172: border-collapse: collapse;
5173: }
1.795 www 5174:
1.396 albertel 5175: table.LC_parm_overview_restrictions td {
5176: border-width: 1px 4px 1px 4px;
5177: border-style: solid;
5178: border-color: $pgbg;
5179: text-align: center;
5180: }
1.795 www 5181:
1.396 albertel 5182: table.LC_parm_overview_restrictions th {
5183: background: $tabbg;
5184: border-width: 1px 4px 1px 4px;
5185: border-style: solid;
5186: border-color: $pgbg;
5187: }
1.795 www 5188:
1.398 albertel 5189: table#LC_helpmenu {
1.803 bisitz 5190: border: none;
1.398 albertel 5191: height: 55px;
1.803 bisitz 5192: border-spacing: 0;
1.398 albertel 5193: }
5194:
5195: table#LC_helpmenu fieldset legend {
5196: font-size: larger;
5197: }
1.795 www 5198:
1.397 albertel 5199: table#LC_helpmenu_links {
5200: width: 100%;
5201: border: 1px solid black;
5202: background: $pgbg;
1.803 bisitz 5203: padding: 0;
1.397 albertel 5204: border-spacing: 1px;
5205: }
1.795 www 5206:
1.397 albertel 5207: table#LC_helpmenu_links tr td {
5208: padding: 1px;
5209: background: $tabbg;
1.399 albertel 5210: text-align: center;
5211: font-weight: bold;
1.397 albertel 5212: }
1.396 albertel 5213:
1.795 www 5214: table#LC_helpmenu_links a:link,
5215: table#LC_helpmenu_links a:visited,
1.397 albertel 5216: table#LC_helpmenu_links a:active {
5217: text-decoration: none;
5218: color: $font;
5219: }
1.795 www 5220:
1.397 albertel 5221: table#LC_helpmenu_links a:hover {
5222: text-decoration: underline;
5223: color: $vlink;
5224: }
1.396 albertel 5225:
1.417 albertel 5226: .LC_chrt_popup_exists {
5227: border: 1px solid #339933;
5228: margin: -1px;
5229: }
1.795 www 5230:
1.417 albertel 5231: .LC_chrt_popup_up {
5232: border: 1px solid yellow;
5233: margin: -1px;
5234: }
1.795 www 5235:
1.417 albertel 5236: .LC_chrt_popup {
5237: border: 1px solid #8888FF;
5238: background: #CCCCFF;
5239: }
1.795 www 5240:
1.421 albertel 5241: table.LC_pick_box {
5242: border-collapse: separate;
5243: background: white;
5244: border: 1px solid black;
5245: border-spacing: 1px;
5246: }
1.795 www 5247:
1.421 albertel 5248: table.LC_pick_box td.LC_pick_box_title {
5249: background: $tabbg;
5250: font-weight: bold;
5251: text-align: right;
1.740 bisitz 5252: vertical-align: top;
1.421 albertel 5253: width: 184px;
5254: padding: 8px;
5255: }
1.795 www 5256:
1.645 raeburn 5257: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5258: background: $tabbg;
5259: font-weight: bold;
5260: text-align: right;
5261: width: 350px;
5262: padding: 8px;
5263: }
5264:
1.579 raeburn 5265: table.LC_pick_box td.LC_pick_box_value {
5266: text-align: left;
5267: padding: 8px;
5268: }
1.795 www 5269:
1.579 raeburn 5270: table.LC_pick_box td.LC_pick_box_select {
5271: text-align: left;
5272: padding: 8px;
5273: }
1.795 www 5274:
1.424 albertel 5275: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5276: padding: 0;
1.421 albertel 5277: height: 1px;
5278: background: black;
5279: }
1.795 www 5280:
1.421 albertel 5281: table.LC_pick_box td.LC_pick_box_submit {
5282: text-align: right;
5283: }
1.795 www 5284:
1.579 raeburn 5285: table.LC_pick_box td.LC_evenrow_value {
5286: text-align: left;
5287: padding: 8px;
5288: background-color: $data_table_light;
5289: }
1.795 www 5290:
1.579 raeburn 5291: table.LC_pick_box td.LC_oddrow_value {
5292: text-align: left;
5293: padding: 8px;
5294: background-color: $data_table_light;
5295: }
1.795 www 5296:
1.579 raeburn 5297: table.LC_helpform_receipt {
5298: width: 620px;
5299: border-collapse: separate;
5300: background: white;
5301: border: 1px solid black;
5302: border-spacing: 1px;
5303: }
1.795 www 5304:
1.579 raeburn 5305: table.LC_helpform_receipt td.LC_pick_box_title {
5306: background: $tabbg;
5307: font-weight: bold;
5308: text-align: right;
5309: width: 184px;
5310: padding: 8px;
5311: }
1.795 www 5312:
1.579 raeburn 5313: table.LC_helpform_receipt td.LC_evenrow_value {
5314: text-align: left;
5315: padding: 8px;
5316: background-color: $data_table_light;
5317: }
1.795 www 5318:
1.579 raeburn 5319: table.LC_helpform_receipt td.LC_oddrow_value {
5320: text-align: left;
5321: padding: 8px;
5322: background-color: $data_table_light;
5323: }
1.795 www 5324:
1.579 raeburn 5325: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5326: padding: 0;
1.579 raeburn 5327: height: 1px;
5328: background: black;
5329: }
1.795 www 5330:
1.579 raeburn 5331: span.LC_helpform_receipt_cat {
5332: font-weight: bold;
5333: }
1.795 www 5334:
1.424 albertel 5335: table.LC_group_priv_box {
5336: background: white;
5337: border: 1px solid black;
5338: border-spacing: 1px;
5339: }
1.795 www 5340:
1.424 albertel 5341: table.LC_group_priv_box td.LC_pick_box_title {
5342: background: $tabbg;
5343: font-weight: bold;
5344: text-align: right;
5345: width: 184px;
5346: }
1.795 www 5347:
1.424 albertel 5348: table.LC_group_priv_box td.LC_groups_fixed {
5349: background: $data_table_light;
5350: text-align: center;
5351: }
1.795 www 5352:
1.424 albertel 5353: table.LC_group_priv_box td.LC_groups_optional {
5354: background: $data_table_dark;
5355: text-align: center;
5356: }
1.795 www 5357:
1.424 albertel 5358: table.LC_group_priv_box td.LC_groups_functionality {
5359: background: $data_table_darker;
5360: text-align: center;
5361: font-weight: bold;
5362: }
1.795 www 5363:
1.424 albertel 5364: table.LC_group_priv td {
5365: text-align: left;
1.803 bisitz 5366: padding: 0;
1.424 albertel 5367: }
5368:
1.421 albertel 5369: table.LC_notify_front_page {
5370: background: white;
5371: border: 1px solid black;
5372: padding: 8px;
5373: }
1.795 www 5374:
1.421 albertel 5375: table.LC_notify_front_page td {
5376: padding: 8px;
5377: }
1.795 www 5378:
1.424 albertel 5379: .LC_navbuttons {
5380: margin: 2ex 0ex 2ex 0ex;
5381: }
1.795 www 5382:
1.423 albertel 5383: .LC_topic_bar {
5384: font-weight: bold;
5385: width: 100%;
5386: background: $tabbg;
5387: vertical-align: middle;
5388: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5389: padding: 3px;
1.423 albertel 5390: }
1.795 www 5391:
1.423 albertel 5392: .LC_topic_bar span {
5393: vertical-align: middle;
5394: }
1.795 www 5395:
1.423 albertel 5396: .LC_topic_bar img {
5397: vertical-align: bottom;
5398: }
1.795 www 5399:
1.423 albertel 5400: table.LC_course_group_status {
5401: margin: 20px;
5402: }
1.795 www 5403:
1.423 albertel 5404: table.LC_status_selector td {
5405: vertical-align: top;
5406: text-align: center;
1.424 albertel 5407: padding: 4px;
5408: }
1.795 www 5409:
1.599 albertel 5410: div.LC_feedback_link {
1.616 albertel 5411: clear: both;
1.829 kalberla 5412: background: $sidebg;
1.779 bisitz 5413: width: 100%;
1.829 kalberla 5414: padding-bottom: 10px;
5415: border: 1px $tabbg solid;
1.833 kalberla 5416: height: 22px;
5417: line-height: 22px;
5418: padding-top: 5px;
5419: }
5420:
5421: div.LC_feedback_link img {
5422: height: 22px;
1.829 kalberla 5423: }
5424:
5425: div.LC_feedback_link a{
5426: text-decoration: none;
1.489 raeburn 5427: }
1.795 www 5428:
1.489 raeburn 5429: span.LC_feedback_link {
1.829 kalberla 5430: //background: $feedback_link_bg;
1.599 albertel 5431: font-size: larger;
5432: }
1.795 www 5433:
1.599 albertel 5434: span.LC_message_link {
1.829 kalberla 5435: //background: $feedback_link_bg;
1.599 albertel 5436: font-size: larger;
5437: position: absolute;
5438: right: 1em;
1.489 raeburn 5439: }
1.421 albertel 5440:
1.515 albertel 5441: table.LC_prior_tries {
1.524 albertel 5442: border: 1px solid #000000;
5443: border-collapse: separate;
5444: border-spacing: 1px;
1.515 albertel 5445: }
1.523 albertel 5446:
1.515 albertel 5447: table.LC_prior_tries td {
1.524 albertel 5448: padding: 2px;
1.515 albertel 5449: }
1.523 albertel 5450:
5451: .LC_answer_correct {
1.795 www 5452: background: lightgreen;
5453: color: darkgreen;
5454: padding: 6px;
1.523 albertel 5455: }
1.795 www 5456:
1.523 albertel 5457: .LC_answer_charged_try {
1.797 www 5458: background: #FFAAAA;
1.795 www 5459: color: darkred;
5460: padding: 6px;
1.523 albertel 5461: }
1.795 www 5462:
1.779 bisitz 5463: .LC_answer_not_charged_try,
1.523 albertel 5464: .LC_answer_no_grade,
5465: .LC_answer_late {
1.795 www 5466: background: lightyellow;
1.523 albertel 5467: color: black;
1.795 www 5468: padding: 6px;
1.523 albertel 5469: }
1.795 www 5470:
1.523 albertel 5471: .LC_answer_previous {
1.795 www 5472: background: lightblue;
5473: color: darkblue;
5474: padding: 6px;
1.523 albertel 5475: }
1.795 www 5476:
1.779 bisitz 5477: .LC_answer_no_message {
1.777 tempelho 5478: background: #FFFFFF;
5479: color: black;
1.795 www 5480: padding: 6px;
1.779 bisitz 5481: }
1.795 www 5482:
1.779 bisitz 5483: .LC_answer_unknown {
5484: background: orange;
5485: color: black;
1.795 www 5486: padding: 6px;
1.777 tempelho 5487: }
1.795 www 5488:
1.529 albertel 5489: span.LC_prior_numerical,
5490: span.LC_prior_string,
5491: span.LC_prior_custom,
5492: span.LC_prior_reaction,
5493: span.LC_prior_math {
1.523 albertel 5494: font-family: monospace;
5495: white-space: pre;
5496: }
5497:
1.525 albertel 5498: span.LC_prior_string {
5499: font-family: monospace;
5500: white-space: pre;
5501: }
5502:
1.523 albertel 5503: table.LC_prior_option {
5504: width: 100%;
5505: border-collapse: collapse;
5506: }
1.795 www 5507:
5508: table.LC_prior_rank,
5509: table.LC_prior_match {
1.528 albertel 5510: border-collapse: collapse;
5511: }
1.795 www 5512:
1.528 albertel 5513: table.LC_prior_option tr td,
5514: table.LC_prior_rank tr td,
5515: table.LC_prior_match tr td {
1.524 albertel 5516: border: 1px solid #000000;
1.515 albertel 5517: }
5518:
1.770 droeschl 5519: td.LC_nobreak,
1.519 raeburn 5520: span.LC_nobreak {
1.544 albertel 5521: white-space: nowrap;
1.519 raeburn 5522: }
5523:
1.576 raeburn 5524: span.LC_cusr_emph {
5525: font-style: italic;
5526: }
5527:
1.633 raeburn 5528: span.LC_cusr_subheading {
5529: font-weight: normal;
5530: font-size: 85%;
5531: }
5532:
1.545 albertel 5533: table.LC_docs_documents {
5534: background: #BBBBBB;
1.803 bisitz 5535: border-width: 0;
1.545 albertel 5536: border-collapse: collapse;
5537: }
1.795 www 5538:
1.777 tempelho 5539: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5540: border: 2px solid black;
5541: padding: 4px;
1.777 tempelho 5542: }
1.795 www 5543:
1.545 albertel 5544: .LC_docs_entry_move {
1.803 bisitz 5545: border: none;
1.545 albertel 5546: border-collapse: collapse;
1.544 albertel 5547: }
5548:
1.545 albertel 5549: .LC_docs_entry_move td {
5550: border: 2px solid #BBBBBB;
5551: background: #DDDDDD;
5552: }
5553:
5554: .LC_docs_editor td.LC_docs_entry_commands {
5555: background: #DDDDDD;
5556: font-size: x-small;
5557: }
1.795 www 5558:
1.544 albertel 5559: .LC_docs_copy {
1.545 albertel 5560: color: #000099;
1.544 albertel 5561: }
1.795 www 5562:
1.544 albertel 5563: .LC_docs_cut {
1.545 albertel 5564: color: #550044;
1.544 albertel 5565: }
1.795 www 5566:
1.544 albertel 5567: .LC_docs_rename {
1.545 albertel 5568: color: #009900;
1.544 albertel 5569: }
1.795 www 5570:
1.544 albertel 5571: .LC_docs_remove {
1.545 albertel 5572: color: #990000;
5573: }
5574:
1.547 albertel 5575: .LC_docs_reinit_warn,
5576: .LC_docs_ext_edit {
5577: font-size: x-small;
5578: }
5579:
1.545 albertel 5580: .LC_docs_editor td.LC_docs_entry_title,
5581: .LC_docs_editor td.LC_docs_entry_icon {
5582: background: #FFFFBB;
5583: }
1.795 www 5584:
1.545 albertel 5585: .LC_docs_editor td.LC_docs_entry_parameter {
5586: background: #BBBBFF;
5587: font-size: x-small;
5588: white-space: nowrap;
5589: }
5590:
5591: table.LC_docs_adddocs td,
5592: table.LC_docs_adddocs th {
5593: border: 1px solid #BBBBBB;
5594: padding: 4px;
5595: background: #DDDDDD;
1.543 albertel 5596: }
5597:
1.584 albertel 5598: table.LC_sty_begin {
5599: background: #BBFFBB;
5600: }
1.795 www 5601:
1.584 albertel 5602: table.LC_sty_end {
5603: background: #FFBBBB;
5604: }
5605:
1.589 raeburn 5606: table.LC_double_column {
1.803 bisitz 5607: border-width: 0;
1.589 raeburn 5608: border-collapse: collapse;
5609: width: 100%;
5610: padding: 2px;
5611: }
5612:
5613: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5614: top: 2px;
1.589 raeburn 5615: left: 2px;
5616: width: 47%;
5617: vertical-align: top;
5618: }
5619:
5620: table.LC_double_column tr td.LC_right_col {
5621: top: 2px;
1.779 bisitz 5622: right: 2px;
1.589 raeburn 5623: width: 47%;
5624: vertical-align: top;
5625: }
5626:
1.594 raeburn 5627: span.LC_role_level {
5628: font-weight: bold;
5629: }
5630:
1.591 raeburn 5631: div.LC_left_float {
5632: float: left;
5633: padding-right: 5%;
1.597 albertel 5634: padding-bottom: 4px;
1.591 raeburn 5635: }
5636:
5637: div.LC_clear_float_header {
1.597 albertel 5638: padding-bottom: 2px;
1.591 raeburn 5639: }
5640:
5641: div.LC_clear_float_footer {
1.597 albertel 5642: padding-top: 10px;
1.591 raeburn 5643: clear: both;
5644: }
5645:
1.597 albertel 5646: div.LC_grade_show_user {
5647: margin-top: 20px;
5648: border: 1px solid black;
5649: }
1.795 www 5650:
1.597 albertel 5651: div.LC_grade_user_name {
5652: background: #DDDDEE;
5653: border-bottom: 1px solid black;
1.705 tempelho 5654: font-weight: bold;
5655: font-size: large;
1.597 albertel 5656: }
1.795 www 5657:
1.597 albertel 5658: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5659: background: #DDEEDD;
5660: }
5661:
5662: div.LC_grade_show_problem,
5663: div.LC_grade_submissions,
5664: div.LC_grade_message_center,
5665: div.LC_grade_info_links,
5666: div.LC_grade_assign {
5667: margin: 5px;
5668: width: 99%;
5669: background: #FFFFFF;
5670: }
1.795 www 5671:
1.597 albertel 5672: div.LC_grade_show_problem_header,
5673: div.LC_grade_submissions_header,
5674: div.LC_grade_message_center_header,
5675: div.LC_grade_assign_header {
1.705 tempelho 5676: font-weight: bold;
5677: font-size: large;
1.597 albertel 5678: }
1.795 www 5679:
1.597 albertel 5680: div.LC_grade_show_problem_problem,
5681: div.LC_grade_submissions_body,
5682: div.LC_grade_message_center_body,
5683: div.LC_grade_assign_body {
5684: border: 1px solid black;
5685: width: 99%;
5686: background: #FFFFFF;
5687: }
1.795 www 5688:
1.598 albertel 5689: span.LC_grade_check_note {
1.705 tempelho 5690: font-weight: normal;
5691: font-size: medium;
1.598 albertel 5692: display: inline;
5693: position: absolute;
5694: right: 1em;
5695: }
1.597 albertel 5696:
1.613 albertel 5697: table.LC_scantron_action {
5698: width: 100%;
5699: }
1.795 www 5700:
1.613 albertel 5701: table.LC_scantron_action tr th {
1.698 harmsja 5702: font-weight:bold;
5703: font-style:normal;
1.613 albertel 5704: }
1.795 www 5705:
1.779 bisitz 5706: .LC_edit_problem_header,
1.614 albertel 5707: div.LC_edit_problem_footer {
1.705 tempelho 5708: font-weight: normal;
5709: font-size: medium;
1.602 albertel 5710: margin: 2px;
1.600 albertel 5711: }
1.795 www 5712:
1.600 albertel 5713: div.LC_edit_problem_header,
1.602 albertel 5714: div.LC_edit_problem_header div,
1.614 albertel 5715: div.LC_edit_problem_footer,
5716: div.LC_edit_problem_footer div,
1.602 albertel 5717: div.LC_edit_problem_editxml_header,
5718: div.LC_edit_problem_editxml_header div {
1.600 albertel 5719: margin-top: 5px;
5720: }
1.795 www 5721:
1.600 albertel 5722: div.LC_edit_problem_header_title {
1.705 tempelho 5723: font-weight: bold;
5724: font-size: larger;
1.602 albertel 5725: background: $tabbg;
5726: padding: 3px;
5727: }
1.795 www 5728:
1.602 albertel 5729: table.LC_edit_problem_header_title {
1.705 tempelho 5730: font-size: larger;
5731: font-weight: bold;
1.602 albertel 5732: width: 100%;
5733: border-color: $pgbg;
5734: border-style: solid;
5735: border-width: $border;
1.600 albertel 5736: background: $tabbg;
1.602 albertel 5737: border-collapse: collapse;
1.803 bisitz 5738: padding: 0;
1.602 albertel 5739: }
5740:
5741: div.LC_edit_problem_discards {
5742: float: left;
5743: padding-bottom: 5px;
5744: }
1.795 www 5745:
1.602 albertel 5746: div.LC_edit_problem_saves {
5747: float: right;
5748: padding-bottom: 5px;
1.600 albertel 5749: }
1.795 www 5750:
1.600 albertel 5751: hr.LC_edit_problem_divide {
1.602 albertel 5752: clear: both;
1.600 albertel 5753: color: $tabbg;
5754: background-color: $tabbg;
5755: height: 3px;
1.803 bisitz 5756: border: none;
1.600 albertel 5757: }
1.795 www 5758:
1.679 riegler 5759: img.stift{
1.803 bisitz 5760: border-width: 0;
5761: vertical-align: middle;
1.677 riegler 5762: }
1.680 riegler 5763:
1.681 riegler 5764: table#LC_mainmenu{
5765: margin-top:10px;
5766: width:80%;
5767: }
5768:
1.680 riegler 5769: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5770: vertical-align: top;
5771: width: 45%;
5772: }
1.795 www 5773:
1.779 bisitz 5774: .LC_mainmenu_fieldset_category {
5775: color: $font;
5776: background: $pgbg;
5777: font-size: small;
5778: font-weight: bold;
1.777 tempelho 5779: }
1.795 www 5780:
1.716 raeburn 5781: div.LC_createcourse {
5782: margin: 10px 10px 10px 10px;
5783: }
5784:
1.693 droeschl 5785: /* ---- Remove when done ----
5786: # The following styles is part of the redesign of LON-CAPA and are
5787: # subject to change during this project.
5788: # Don't rely on their current functionality as they might be
5789: # changed or removed.
5790: # --------------------------*/
5791:
1.698 harmsja 5792: a:hover,
1.721 harmsja 5793: ol.LC_smallMenu a:hover,
5794: ol#LC_MenuBreadcrumbs a:hover,
5795: ol#LC_PathBreadcrumbs a:hover,
5796: ul#LC_TabMainMenuContent a:hover,
5797: .LC_FormSectionClearButton input:hover
1.795 www 5798: ul.LC_TabContent li:hover a {
1.698 harmsja 5799: color:#BF2317;
5800: text-decoration:none;
1.693 droeschl 5801: }
5802:
1.779 bisitz 5803: h1 {
1.813 bisitz 5804: padding: 0;
1.693 droeschl 5805: line-height:130%;
5806: }
1.698 harmsja 5807:
1.795 www 5808: h2,h3,h4,h5,h6 {
1.803 bisitz 5809: margin: 5px 0 5px 0;
5810: padding: 0;
1.721 harmsja 5811: line-height:130%;
1.693 droeschl 5812: }
1.795 www 5813:
5814: .LC_hcell {
1.698 harmsja 5815: padding:3px 15px 3px 15px;
1.803 bisitz 5816: margin: 0;
1.703 harmsja 5817: background-color:$tabbg;
1.801 tempelho 5818: color:$fontmenu;
1.779 bisitz 5819: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5820: }
1.795 www 5821:
1.840 bisitz 5822: .LC_Box > .LC_hcell {
1.841 ! tempelho 5823: margin: 0 -10px;
1.835 bisitz 5824: }
5825:
1.721 harmsja 5826: .LC_noBorder {
1.803 bisitz 5827: border: 0;
1.698 harmsja 5828: }
1.693 droeschl 5829:
5830:
1.698 harmsja 5831: /* Main Header with discription of Person, Course, etc. */
1.693 droeschl 5832:
1.761 tempelho 5833: .LC_Right {
5834: float: right;
1.803 bisitz 5835: margin: 0;
5836: padding: 0;
1.761 tempelho 5837: }
5838:
1.721 harmsja 5839: .LC_FormSectionClearButton input {
1.779 bisitz 5840: background-color:transparent;
1.803 bisitz 5841: border: none;
1.698 harmsja 5842: cursor:pointer;
5843: text-decoration:underline;
1.693 droeschl 5844: }
1.763 bisitz 5845:
5846: .LC_help_open_topic {
5847: color: #FFFFFF;
5848: background-color: #EEEEFF;
5849: margin: 1px;
5850: padding: 4px;
5851: border: 1px solid #000033;
5852: white-space: nowrap;
1.783 amueller 5853: /* vertical-align: middle; */
1.759 neumanie 5854: }
1.693 droeschl 5855:
1.698 harmsja 5856: dl,ul,div,fieldset {
1.803 bisitz 5857: margin: 10px 10px 10px 0;
1.806 bisitz 5858: /* overflow: hidden; */
1.693 droeschl 5859: }
1.795 www 5860:
1.838 bisitz 5861: fieldset > legend {
5862: font-weight: bold;
5863: padding: 0 5px 0 5px;
5864: }
5865:
1.813 bisitz 5866: #LC_nav_bar {
1.807 droeschl 5867: float: left;
5868: margin: 0;
5869: }
5870:
1.813 bisitz 5871: #LC_nav_bar em{
1.807 droeschl 5872: font-weight: bold;
5873: font-style: normal;
5874: }
5875:
5876: ol.LC_smallMenu {
5877: float: right;
5878: }
5879:
1.721 harmsja 5880: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.803 bisitz 5881: margin: 0;
1.693 droeschl 5882: }
5883:
1.721 harmsja 5884: ol.LC_smallMenu li {
1.693 droeschl 5885: display: inline;
1.803 bisitz 5886: padding: 5px 5px 0 10px;
1.693 droeschl 5887: vertical-align: top;
5888: }
5889:
1.721 harmsja 5890: ol.LC_smallMenu li img {
1.693 droeschl 5891: vertical-align: bottom;
5892: }
5893:
1.721 harmsja 5894: ol.LC_smallMenu a {
1.693 droeschl 5895: font-size: 90%;
5896: color: RGB(80, 80, 80);
5897: text-decoration: none;
5898: }
1.795 www 5899:
1.808 droeschl 5900: ul#LC_TabMainMenuContent {
1.807 droeschl 5901: clear: both;
1.808 droeschl 5902: color: $fontmenu;
5903: background: $tabbg;
5904: list-style: none;
5905: padding: 0;
5906: margin: 0;
5907: float:left;
5908: width: 100%;
5909: }
5910:
5911: ul#LC_TabMainMenuContent li {
5912: float: left;
5913: font-weight: bold;
5914: line-height: 1.8em;
5915: padding: 0 0.8em;
5916: border-right: 1px solid black;
5917: display: inline;
5918: vertical-align: middle;
1.807 droeschl 5919: }
5920:
1.795 www 5921: ul.LC_TabContent ,
1.741 harmsja 5922: ul.LC_TabContentBigger {
1.721 harmsja 5923: display:block;
5924: list-style:none;
1.803 bisitz 5925: margin: 0;
5926: padding: 0;
1.693 droeschl 5927: }
5928:
1.795 www 5929: ul.LC_TabContent li,
5930: ul.LC_TabContentBigger li {
1.693 droeschl 5931: display: inline;
1.741 harmsja 5932: border-right: solid 1px $lg_border_color;
5933: float:left;
5934: line-height:140%;
5935: white-space:nowrap;
5936: }
1.795 www 5937:
1.808 droeschl 5938: ul#LC_TabMainMenuContent li a {
5939: color: $fontmenu;
1.693 droeschl 5940: text-decoration: none;
5941: }
1.795 www 5942:
1.721 harmsja 5943: ul.LC_TabContent {
1.741 harmsja 5944: min-height:1.6em;
1.721 harmsja 5945: }
1.795 www 5946:
5947: ul.LC_TabContent li {
1.741 harmsja 5948: vertical-align:middle;
1.803 bisitz 5949: padding: 0 10px 0 10px;
1.745 ehlerst 5950: background-color:$tabbg;
5951: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5952: }
1.795 www 5953:
5954: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5955: color:rgb(47,47,47);
5956: text-decoration:none;
5957: font-size:95%;
5958: font-weight:bold;
1.761 tempelho 5959: padding-right: 16px;
1.721 harmsja 5960: }
1.795 www 5961:
5962: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5963: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 ! tempelho 5964: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5965: padding-right: 16px;
1.744 ehlerst 5966: }
1.795 www 5967:
5968: ul.LC_TabContentBigger li {
1.741 harmsja 5969: vertical-align:bottom;
5970: border-top:solid 1px $lg_border_color;
5971: border-left:solid 1px $lg_border_color;
5972: padding:5px 10px 5px 10px;
5973: margin-left:2px;
1.841 ! tempelho 5974: background: #d9d9d9;
! 5975: }
! 5976:
! 5977: #maincoursedoc {
! 5978: clear:both;
1.741 harmsja 5979: }
1.795 www 5980:
5981: ul.LC_TabContentBigger li:hover,
5982: ul.LC_TabContentBigger li.active {
1.744 ehlerst 5983: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5984: }
1.795 www 5985:
5986: ul.LC_TabContentBigger li,
5987: ul.LC_TabContentBigger li a {
1.741 harmsja 5988: font-size:110%;
5989: font-weight:bold;
5990: }
1.693 droeschl 5991:
1.795 www 5992: ol#LC_MenuBreadcrumbs,
5993: ol#LC_PathBreadcrumbs,
1.823 bisitz 5994: ul#LC_CourseBreadcrumbs {
1.693 droeschl 5995: padding-left: 10px;
1.819 tempelho 5996: margin: 0;
1.693 droeschl 5997: list-style-position: inside;
5998: }
5999:
1.795 www 6000: ol#LC_MenuBreadcrumbs li,
6001: ol#LC_PathBreadcrumbs li,
1.823 bisitz 6002: ul#LC_CourseBreadcrumbs li {
1.693 droeschl 6003: display: inline;
1.803 bisitz 6004: padding: 0 0 0 10px;
1.693 droeschl 6005: overflow:hidden;
6006: }
6007:
1.823 bisitz 6008: ol#LC_MenuBreadcrumbs li a,
6009: ul#LC_CourseBreadcrumbs li a {
1.693 droeschl 6010: text-decoration: none;
6011: font-size:90%;
6012: }
1.795 www 6013:
6014: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6015: text-decoration:none;
6016: font-size:100%;
6017: font-weight:bold;
1.693 droeschl 6018: }
1.795 www 6019:
1.840 bisitz 6020: .LC_Box {
1.835 bisitz 6021: border: solid 1px $lg_border_color;
6022: padding: 0 10px 10px 10px;
1.746 neumanie 6023: }
1.795 www 6024:
6025: .LC_AboutMe_Image {
1.747 neumanie 6026: float:left;
6027: margin-right:10px;
6028: }
1.795 www 6029:
6030: .LC_Clear_AboutMe_Image {
1.747 neumanie 6031: clear:left;
6032: }
1.795 www 6033:
1.721 harmsja 6034: dl.LC_ListStyleClean dt {
1.693 droeschl 6035: padding-right: 5px;
6036: display: table-header-group;
6037: }
6038:
1.721 harmsja 6039: dl.LC_ListStyleClean dd {
1.693 droeschl 6040: display: table-row;
6041: }
6042:
1.721 harmsja 6043: .LC_ListStyleClean,
6044: .LC_ListStyleSimple,
6045: .LC_ListStyleNormal,
1.777 tempelho 6046: .LC_ListStyle_Border,
1.795 www 6047: .LC_ListStyleSpecial {
1.693 droeschl 6048: /*display:block; */
6049: list-style-position: inside;
6050: list-style-type: none;
6051: overflow: hidden;
1.803 bisitz 6052: padding: 0;
1.693 droeschl 6053: }
6054:
1.721 harmsja 6055: .LC_ListStyleSimple li,
6056: .LC_ListStyleSimple dd,
6057: .LC_ListStyleNormal li,
6058: .LC_ListStyleNormal dd,
6059: .LC_ListStyleSpecial li,
1.795 www 6060: .LC_ListStyleSpecial dd {
1.803 bisitz 6061: margin: 0;
1.693 droeschl 6062: padding: 5px 5px 5px 10px;
6063: clear: both;
6064: }
6065:
1.721 harmsja 6066: .LC_ListStyleClean li,
6067: .LC_ListStyleClean dd {
1.803 bisitz 6068: padding-top: 0;
6069: padding-bottom: 0;
1.693 droeschl 6070: }
6071:
1.721 harmsja 6072: .LC_ListStyleSimple dd,
1.795 www 6073: .LC_ListStyleSimple li {
1.698 harmsja 6074: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6075: }
6076:
1.721 harmsja 6077: .LC_ListStyleSpecial li,
6078: .LC_ListStyleSpecial dd {
1.693 droeschl 6079: list-style-type: none;
6080: background-color: RGB(220, 220, 220);
6081: margin-bottom: 4px;
6082: }
6083:
1.721 harmsja 6084: table.LC_SimpleTable {
1.698 harmsja 6085: margin:5px;
6086: border:solid 1px $lg_border_color;
1.795 www 6087: }
1.693 droeschl 6088:
1.721 harmsja 6089: table.LC_SimpleTable tr {
1.803 bisitz 6090: padding: 0;
1.698 harmsja 6091: border:solid 1px $lg_border_color;
1.693 droeschl 6092: }
1.795 www 6093:
6094: table.LC_SimpleTable thead {
1.698 harmsja 6095: background:rgb(220,220,220);
1.693 droeschl 6096: }
6097:
1.721 harmsja 6098: div.LC_columnSection {
1.693 droeschl 6099: display: block;
6100: clear: both;
6101: overflow: hidden;
1.803 bisitz 6102: margin: 0;
1.693 droeschl 6103: }
6104:
1.721 harmsja 6105: div.LC_columnSection>* {
1.693 droeschl 6106: float: left;
1.803 bisitz 6107: margin: 10px 20px 10px 0;
1.747 neumanie 6108: overflow:hidden;
1.693 droeschl 6109: }
1.721 harmsja 6110:
1.795 www 6111: .clear {
1.720 ehlerst 6112: clear: both;
1.803 bisitz 6113: line-height: 0;
6114: font-size: 0;
6115: height: 0;
1.720 ehlerst 6116: }
1.693 droeschl 6117:
1.694 tempelho 6118: .LC_loginpage_container {
6119: text-align:left;
6120: margin : 0 auto;
1.785 tempelho 6121: width:90%;
1.694 tempelho 6122: padding: 10px;
6123: height: auto;
1.712 muellerd 6124: background-color:#FFFFFF;
1.694 tempelho 6125: border:1px solid #CCCCCC;
6126: }
6127:
6128:
6129: .LC_loginpage_loginContainer {
6130: float:left;
1.712 muellerd 6131: width: 182px;
1.785 tempelho 6132: padding: 2px;
1.712 muellerd 6133: border:1px solid #CCCCCC;
6134: background-color:$loginbg;
1.694 tempelho 6135: }
6136:
1.795 www 6137: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6138: margin-top: 0;
1.712 muellerd 6139: display:block;
6140: background:$bgcol;
6141: color:$textcol;
6142: padding-left:5px;
6143: }
1.785 tempelho 6144:
1.694 tempelho 6145: .LC_loginpage_loginInfo {
6146: float:left;
1.785 tempelho 6147: width:182px;
1.694 tempelho 6148: border:1px solid #CCCCCC;
1.785 tempelho 6149: padding:2px;
1.712 muellerd 6150: }
6151:
1.694 tempelho 6152: .LC_loginpage_space {
1.754 droeschl 6153: clear: both;
6154: margin-bottom: 20px;
1.694 tempelho 6155: border-bottom: 1px solid #CCCCCC;
6156: }
6157:
1.785 tempelho 6158: .LC_loginpage_floatLeft {
6159: float: left;
6160: width: 200px;
6161: margin: 0;
6162: }
6163:
1.795 www 6164: table em {
1.754 droeschl 6165: font-weight: bold;
6166: font-style: normal;
1.748 schulted 6167: }
1.795 www 6168:
1.779 bisitz 6169: table.LC_tableBrowseRes,
1.795 www 6170: table.LC_tableOfContent {
1.769 schulted 6171: border:none;
6172: border-spacing: 1;
1.754 droeschl 6173: padding: 3px;
6174: background-color: #FFFFFF;
6175: font-size: 90%;
1.753 droeschl 6176: }
1.789 droeschl 6177:
6178: table.LC_tableOfContent{
6179: border-collapse: collapse;
6180: }
6181:
1.771 droeschl 6182: table.LC_tableBrowseRes a,
1.768 schulted 6183: table.LC_tableOfContent a {
1.771 droeschl 6184: background-color: transparent;
1.753 droeschl 6185: text-decoration: none;
6186: }
6187:
1.771 droeschl 6188: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6189: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6190: background-color: #EEEEEE;
1.753 droeschl 6191: }
6192:
1.795 www 6193: table.LC_tableOfContent img {
1.753 droeschl 6194: border: none;
6195: height: 1.3em;
6196: vertical-align: text-bottom;
6197: margin-right: 0.3em;
6198: }
1.757 schulted 6199:
1.795 www 6200: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6201: background-image:url(/res/adm/pages/open-first-problem.gif);
6202: }
6203:
1.795 www 6204: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6205: background-image:url(/res/adm/pages/start-navigation.gif);
6206: }
6207:
1.795 www 6208: a#LC_content_toolbar_closenav {
1.774 ehlerst 6209: background-image:url(/res/adm/pages/close-navigation.gif);
6210: }
6211:
1.795 www 6212: a#LC_content_toolbar_everything {
1.774 ehlerst 6213: background-image:url(/res/adm/pages/show-all.gif);
6214: }
6215:
1.795 www 6216: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6217: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6218: }
6219:
1.795 www 6220: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6221: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6222: }
6223:
1.795 www 6224: a#LC_content_toolbar_changefolder {
1.757 schulted 6225: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6226: }
6227:
1.795 www 6228: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6229: background-image:url(/res/adm/pages/open-all-folders.gif);
6230: }
6231:
1.795 www 6232: ul#LC_toolbar li a:hover {
1.757 schulted 6233: background-position: bottom center;
6234: }
6235:
1.795 www 6236: ul#LC_toolbar {
1.803 bisitz 6237: padding: 0;
1.757 schulted 6238: margin: 2px;
6239: list-style:none;
6240: position:relative;
6241: background-color:white;
6242: }
6243:
1.795 www 6244: ul#LC_toolbar li {
1.757 schulted 6245: border:1px solid white;
1.803 bisitz 6246: padding: 0;
1.757 schulted 6247: margin: 0;
1.795 www 6248: float: left;
1.767 droeschl 6249: display:inline;
1.757 schulted 6250: vertical-align:middle;
1.795 www 6251: }
1.757 schulted 6252:
1.783 amueller 6253:
1.795 www 6254: a.LC_toolbarItem {
1.767 droeschl 6255: display:block;
1.803 bisitz 6256: padding: 0;
6257: margin: 0;
1.757 schulted 6258: height: 32px;
6259: width: 32px;
1.779 bisitz 6260: color:white;
1.803 bisitz 6261: border: none;
1.757 schulted 6262: background-repeat:no-repeat;
6263: background-color:transparent;
6264: }
6265:
1.782 bisitz 6266: ul.LC_functionslist li {
6267: float: left;
6268: white-space: nowrap;
6269: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6270: margin: 0 15px 15px 10px;
1.782 bisitz 6271: }
6272:
1.757 schulted 6273:
1.343 albertel 6274: END
6275: }
6276:
1.306 albertel 6277: =pod
6278:
6279: =item * &headtag()
6280:
6281: Returns a uniform footer for LON-CAPA web pages.
6282:
1.307 albertel 6283: Inputs: $title - optional title for the head
6284: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6285: $args - optional arguments
1.319 albertel 6286: force_register - if is true call registerurl so the remote is
6287: informed
1.415 albertel 6288: redirect -> array ref of
6289: 1- seconds before redirect occurs
6290: 2- url to redirect to
6291: 3- whether the side effect should occur
1.315 albertel 6292: (side effect of setting
6293: $env{'internal.head.redirect'} to the url
6294: redirected too)
1.352 albertel 6295: domain -> force to color decorate a page for a specific
6296: domain
6297: function -> force usage of a specific rolish color scheme
6298: bgcolor -> override the default page bgcolor
1.460 albertel 6299: no_auto_mt_title
6300: -> prevent &mt()ing the title arg
1.464 albertel 6301:
1.306 albertel 6302: =cut
6303:
6304: sub headtag {
1.313 albertel 6305: my ($title,$head_extra,$args) = @_;
1.306 albertel 6306:
1.363 albertel 6307: my $function = $args->{'function'} || &get_users_function();
6308: my $domain = $args->{'domain'} || &determinedomain();
6309: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6310: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6311: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6312: #time(),
1.418 albertel 6313: $env{'environment.color.timestamp'},
1.363 albertel 6314: $function,$domain,$bgcolor);
6315:
1.369 www 6316: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6317:
1.308 albertel 6318: my $result =
6319: '<head>'.
1.461 albertel 6320: &font_settings();
1.319 albertel 6321:
1.461 albertel 6322: if (!$args->{'frameset'}) {
6323: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6324: }
1.319 albertel 6325: if ($args->{'force_register'}) {
6326: $result .= &Apache::lonmenu::registerurl(1);
6327: }
1.436 albertel 6328: if (!$args->{'no_nav_bar'}
6329: && !$args->{'only_body'}
6330: && !$args->{'frameset'}) {
6331: $result .= &help_menu_js();
6332: }
1.319 albertel 6333:
1.314 albertel 6334: if (ref($args->{'redirect'})) {
1.414 albertel 6335: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6336: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6337: if (!$inhibit_continue) {
6338: $env{'internal.head.redirect'} = $url;
6339: }
1.313 albertel 6340: $result.=<<ADDMETA
6341: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6342: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6343: ADDMETA
6344: }
1.306 albertel 6345: if (!defined($title)) {
6346: $title = 'The LearningOnline Network with CAPA';
6347: }
1.460 albertel 6348: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6349: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6350: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6351: .$head_extra;
1.306 albertel 6352: return $result;
6353: }
6354:
6355: =pod
6356:
1.340 albertel 6357: =item * &font_settings()
6358:
6359: Returns neccessary <meta> to set the proper encoding
6360:
6361: Inputs: none
6362:
6363: =cut
6364:
6365: sub font_settings {
6366: my $headerstring='';
1.647 www 6367: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6368: $headerstring.=
6369: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6370: }
6371: return $headerstring;
6372: }
6373:
1.341 albertel 6374: =pod
6375:
6376: =item * &xml_begin()
6377:
6378: Returns the needed doctype and <html>
6379:
6380: Inputs: none
6381:
6382: =cut
6383:
6384: sub xml_begin {
6385: my $output='';
6386:
1.592 albertel 6387: if ($env{'internal.start_page'}==1) {
6388: &Apache::lonhtmlcommon::init_htmlareafields();
6389: }
1.342 albertel 6390:
1.341 albertel 6391: if ($env{'browser.mathml'}) {
6392: $output='<?xml version="1.0"?>'
6393: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6394: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6395:
6396: # .'<!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">] >'
6397: .'<!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">'
6398: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6399: .'xmlns="http://www.w3.org/1999/xhtml">';
6400: } else {
6401: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6402: }
6403: return $output;
6404: }
1.340 albertel 6405:
6406: =pod
6407:
1.306 albertel 6408: =item * &endheadtag()
6409:
6410: Returns a uniform </head> for LON-CAPA web pages.
6411:
6412: Inputs: none
6413:
6414: =cut
6415:
6416: sub endheadtag {
6417: return '</head>';
6418: }
6419:
6420: =pod
6421:
6422: =item * &head()
6423:
6424: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6425:
1.648 raeburn 6426: Inputs:
6427:
6428: =over 4
6429:
6430: $title - optional title for the page
6431:
6432: $head_extra - optional extra HTML to put inside the <head>
6433:
6434: =back
1.405 albertel 6435:
1.306 albertel 6436: =cut
6437:
6438: sub head {
1.325 albertel 6439: my ($title,$head_extra,$args) = @_;
6440: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6441: }
6442:
6443: =pod
6444:
6445: =item * &start_page()
6446:
6447: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6448:
1.648 raeburn 6449: Inputs:
6450:
6451: =over 4
6452:
6453: $title - optional title for the page
6454:
6455: $head_extra - optional extra HTML to incude inside the <head>
6456:
6457: $args - additional optional args supported are:
6458:
6459: =over 8
6460:
6461: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6462: arg on
1.814 bisitz 6463: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6464: add_entries -> additional attributes to add to the <body>
6465: domain -> force to color decorate a page for a
1.317 albertel 6466: specific domain
1.648 raeburn 6467: function -> force usage of a specific rolish color
1.317 albertel 6468: scheme
1.648 raeburn 6469: redirect -> see &headtag()
6470: bgcolor -> override the default page bg color
6471: js_ready -> return a string ready for being used in
1.317 albertel 6472: a javascript writeln
1.648 raeburn 6473: html_encode -> return a string ready for being used in
1.320 albertel 6474: a html attribute
1.648 raeburn 6475: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6476: $forcereg arg
1.648 raeburn 6477: frameset -> if true will start with a <frameset>
1.330 albertel 6478: rather than <body>
1.648 raeburn 6479: skip_phases -> hash ref of
1.338 albertel 6480: head -> skip the <html><head> generation
6481: body -> skip all <body> generation
1.648 raeburn 6482: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6483: 'Switch To Inline Menu' link
1.648 raeburn 6484: no_auto_mt_title -> prevent &mt()ing the title arg
6485: inherit_jsmath -> when creating popup window in a page,
6486: should it have jsmath forced on by the
6487: current page
1.361 albertel 6488:
1.648 raeburn 6489: =back
1.460 albertel 6490:
1.648 raeburn 6491: =back
1.562 albertel 6492:
1.306 albertel 6493: =cut
6494:
6495: sub start_page {
1.309 albertel 6496: my ($title,$head_extra,$args) = @_;
1.318 albertel 6497: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6498: my %head_args;
1.352 albertel 6499: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6500: 'bgcolor','frameset','no_nav_bar','only_body',
6501: 'no_auto_mt_title') {
1.319 albertel 6502: if (defined($args->{$arg})) {
1.324 raeburn 6503: $head_args{$arg} = $args->{$arg};
1.319 albertel 6504: }
1.313 albertel 6505: }
1.319 albertel 6506:
1.315 albertel 6507: $env{'internal.start_page'}++;
1.338 albertel 6508: my $result;
6509: if (! exists($args->{'skip_phases'}{'head'}) ) {
6510: $result.=
1.341 albertel 6511: &xml_begin().
1.338 albertel 6512: &headtag($title,$head_extra,\%head_args).&endheadtag();
6513: }
6514:
6515: if (! exists($args->{'skip_phases'}{'body'}) ) {
6516: if ($args->{'frameset'}) {
6517: my $attr_string = &make_attr_string($args->{'force_register'},
6518: $args->{'add_entries'});
6519: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6520: } else {
6521: $result .=
6522: &bodytag($title,
6523: $args->{'function'}, $args->{'add_entries'},
6524: $args->{'only_body'}, $args->{'domain'},
6525: $args->{'force_register'}, $args->{'no_nav_bar'},
6526: $args->{'bgcolor'}, $args->{'no_inline_link'},
6527: $args);
6528: }
1.330 albertel 6529: }
1.338 albertel 6530:
1.315 albertel 6531: if ($args->{'js_ready'}) {
1.713 kaisler 6532: $result = &js_ready($result);
1.315 albertel 6533: }
1.320 albertel 6534: if ($args->{'html_encode'}) {
1.713 kaisler 6535: $result = &html_encode($result);
6536: }
6537:
1.813 bisitz 6538: # Preparation for new and consistent functionlist at top of screen
6539: # if ($args->{'functionlist'}) {
6540: # $result .= &build_functionlist();
6541: #}
6542:
6543: # Don't add anything more if only_body wanted
6544: return $result if $args->{'only_body'};
6545:
6546: #Breadcrumbs
1.758 kaisler 6547: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6548: &Apache::lonhtmlcommon::clear_breadcrumbs();
6549: #if any br links exists, add them to the breadcrumbs
6550: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6551: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6552: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6553: }
6554: }
6555:
6556: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6557: if(exists($args->{'bread_crumbs_component'})){
6558: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6559: }else{
6560: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6561: }
1.320 albertel 6562: }
1.315 albertel 6563: return $result;
1.306 albertel 6564: }
6565:
1.330 albertel 6566:
1.306 albertel 6567: =pod
6568:
6569: =item * &head()
6570:
6571: Returns a complete </body></html> section for LON-CAPA web pages.
6572:
1.315 albertel 6573: Inputs: $args - additional optional args supported are:
6574: js_ready -> return a string ready for being used in
6575: a javascript writeln
1.320 albertel 6576: html_encode -> return a string ready for being used in
6577: a html attribute
1.330 albertel 6578: frameset -> if true will start with a <frameset>
6579: rather than <body>
1.493 albertel 6580: dicsussion -> if true will get discussion from
6581: lonxml::xmlend
6582: (you can pass the target and parser arguments
6583: through optional 'target' and 'parser' args
6584: to this routine)
1.306 albertel 6585:
6586: =cut
6587:
6588: sub end_page {
1.315 albertel 6589: my ($args) = @_;
6590: $env{'internal.end_page'}++;
1.330 albertel 6591: my $result;
1.335 albertel 6592: if ($args->{'discussion'}) {
6593: my ($target,$parser);
6594: if (ref($args->{'discussion'})) {
6595: ($target,$parser) =($args->{'discussion'}{'target'},
6596: $args->{'discussion'}{'parser'});
6597: }
6598: $result .= &Apache::lonxml::xmlend($target,$parser);
6599: }
6600:
1.330 albertel 6601: if ($args->{'frameset'}) {
6602: $result .= '</frameset>';
6603: } else {
1.635 raeburn 6604: $result .= &endbodytag($args);
1.330 albertel 6605: }
6606: $result .= "\n</html>";
6607:
1.315 albertel 6608: if ($args->{'js_ready'}) {
1.317 albertel 6609: $result = &js_ready($result);
1.315 albertel 6610: }
1.335 albertel 6611:
1.320 albertel 6612: if ($args->{'html_encode'}) {
6613: $result = &html_encode($result);
6614: }
1.335 albertel 6615:
1.315 albertel 6616: return $result;
6617: }
6618:
1.320 albertel 6619: sub html_encode {
6620: my ($result) = @_;
6621:
1.322 albertel 6622: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6623:
6624: return $result;
6625: }
1.317 albertel 6626: sub js_ready {
6627: my ($result) = @_;
6628:
1.323 albertel 6629: $result =~ s/[\n\r]/ /xmsg;
6630: $result =~ s/\\/\\\\/xmsg;
6631: $result =~ s/'/\\'/xmsg;
1.372 albertel 6632: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6633:
6634: return $result;
6635: }
6636:
1.315 albertel 6637: sub validate_page {
6638: if ( exists($env{'internal.start_page'})
1.316 albertel 6639: && $env{'internal.start_page'} > 1) {
6640: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6641: $env{'internal.start_page'}.' '.
1.316 albertel 6642: $ENV{'request.filename'});
1.315 albertel 6643: }
6644: if ( exists($env{'internal.end_page'})
1.316 albertel 6645: && $env{'internal.end_page'} > 1) {
6646: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6647: $env{'internal.end_page'}.' '.
1.316 albertel 6648: $env{'request.filename'});
1.315 albertel 6649: }
6650: if ( exists($env{'internal.start_page'})
6651: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6652: &Apache::lonnet::logthis('start_page called without end_page '.
6653: $env{'request.filename'});
1.315 albertel 6654: }
6655: if ( ! exists($env{'internal.start_page'})
6656: && exists($env{'internal.end_page'})) {
1.316 albertel 6657: &Apache::lonnet::logthis('end_page called without start_page'.
6658: $env{'request.filename'});
1.315 albertel 6659: }
1.306 albertel 6660: }
1.315 albertel 6661:
1.318 albertel 6662: sub simple_error_page {
6663: my ($r,$title,$msg) = @_;
6664: my $page =
6665: &Apache::loncommon::start_page($title).
6666: &mt($msg).
6667: &Apache::loncommon::end_page();
6668: if (ref($r)) {
6669: $r->print($page);
1.327 albertel 6670: return;
1.318 albertel 6671: }
6672: return $page;
6673: }
1.347 albertel 6674:
6675: {
1.610 albertel 6676: my @row_count;
1.347 albertel 6677: sub start_data_table {
1.422 albertel 6678: my ($add_class) = @_;
6679: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6680: unshift(@row_count,0);
1.422 albertel 6681: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6682: }
6683:
6684: sub end_data_table {
1.610 albertel 6685: shift(@row_count);
1.389 albertel 6686: return '</table>'."\n";;
1.347 albertel 6687: }
6688:
6689: sub start_data_table_row {
1.422 albertel 6690: my ($add_class) = @_;
1.610 albertel 6691: $row_count[0]++;
6692: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6693: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6694: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6695: }
1.471 banghart 6696:
6697: sub continue_data_table_row {
6698: my ($add_class) = @_;
1.610 albertel 6699: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6700: $css_class = (join(' ',$css_class,$add_class));
6701: return '<tr class="'.$css_class.'">'."\n";;
6702: }
1.347 albertel 6703:
6704: sub end_data_table_row {
1.389 albertel 6705: return '</tr>'."\n";;
1.347 albertel 6706: }
1.367 www 6707:
1.421 albertel 6708: sub start_data_table_empty_row {
1.707 bisitz 6709: # $row_count[0]++;
1.421 albertel 6710: return '<tr class="LC_empty_row" >'."\n";;
6711: }
6712:
6713: sub end_data_table_empty_row {
6714: return '</tr>'."\n";;
6715: }
6716:
1.367 www 6717: sub start_data_table_header_row {
1.389 albertel 6718: return '<tr class="LC_header_row">'."\n";;
1.367 www 6719: }
6720:
6721: sub end_data_table_header_row {
1.389 albertel 6722: return '</tr>'."\n";;
1.367 www 6723: }
1.347 albertel 6724: }
6725:
1.548 albertel 6726: =pod
6727:
6728: =item * &inhibit_menu_check($arg)
6729:
6730: Checks for a inhibitmenu state and generates output to preserve it
6731:
6732: Inputs: $arg - can be any of
6733: - undef - in which case the return value is a string
6734: to add into arguments list of a uri
6735: - 'input' - in which case the return value is a HTML
6736: <form> <input> field of type hidden to
6737: preserve the value
6738: - a url - in which case the return value is the url with
6739: the neccesary cgi args added to preserve the
6740: inhibitmenu state
6741: - a ref to a url - no return value, but the string is
6742: updated to include the neccessary cgi
6743: args to preserve the inhibitmenu state
6744:
6745: =cut
6746:
6747: sub inhibit_menu_check {
6748: my ($arg) = @_;
6749: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6750: if ($arg eq 'input') {
6751: if ($env{'form.inhibitmenu'}) {
6752: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6753: } else {
6754: return
6755: }
6756: }
6757: if ($env{'form.inhibitmenu'}) {
6758: if (ref($arg)) {
6759: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6760: } elsif ($arg eq '') {
6761: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6762: } else {
6763: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6764: }
6765: }
6766: if (!ref($arg)) {
6767: return $arg;
6768: }
6769: }
6770:
1.251 albertel 6771: ###############################################
1.182 matthew 6772:
6773: =pod
6774:
1.549 albertel 6775: =back
6776:
6777: =head1 User Information Routines
6778:
6779: =over 4
6780:
1.405 albertel 6781: =item * &get_users_function()
1.182 matthew 6782:
6783: Used by &bodytag to determine the current users primary role.
6784: Returns either 'student','coordinator','admin', or 'author'.
6785:
6786: =cut
6787:
6788: ###############################################
6789: sub get_users_function {
1.815 tempelho 6790: my $function = 'norole';
1.818 tempelho 6791: if ($env{'request.role'}=~/^(st)/) {
6792: $function='student';
6793: }
1.258 albertel 6794: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6795: $function='coordinator';
6796: }
1.258 albertel 6797: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6798: $function='admin';
6799: }
1.826 bisitz 6800: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6801: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6802: $function='author';
6803: }
6804: return $function;
1.54 www 6805: }
1.99 www 6806:
6807: ###############################################
6808:
1.233 raeburn 6809: =pod
6810:
1.821 raeburn 6811: =item * &show_course()
6812:
6813: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6814: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6815:
6816: Inputs:
6817: None
6818:
6819: Outputs:
6820: Scalar: 1 if 'Course' to be used, 0 otherwise.
6821:
6822: =cut
6823:
6824: ###############################################
6825: sub show_course {
6826: my $course = !$env{'user.adv'};
6827: if (!$env{'user.adv'}) {
6828: foreach my $env (keys(%env)) {
6829: next if ($env !~ m/^user\.priv\./);
6830: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6831: $course = 0;
6832: last;
6833: }
6834: }
6835: }
6836: return $course;
6837: }
6838:
6839: ###############################################
6840:
6841: =pod
6842:
1.542 raeburn 6843: =item * &check_user_status()
1.274 raeburn 6844:
6845: Determines current status of supplied role for a
6846: specific user. Roles can be active, previous or future.
6847:
6848: Inputs:
6849: user's domain, user's username, course's domain,
1.375 raeburn 6850: course's number, optional section ID.
1.274 raeburn 6851:
6852: Outputs:
6853: role status: active, previous or future.
6854:
6855: =cut
6856:
6857: sub check_user_status {
1.412 raeburn 6858: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6859: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6860: my @uroles = keys %userinfo;
6861: my $srchstr;
6862: my $active_chk = 'none';
1.412 raeburn 6863: my $now = time;
1.274 raeburn 6864: if (@uroles > 0) {
1.412 raeburn 6865: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6866: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6867: } else {
1.412 raeburn 6868: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6869: }
6870: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6871: my $role_end = 0;
6872: my $role_start = 0;
6873: $active_chk = 'active';
1.412 raeburn 6874: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6875: $role_end = $1;
6876: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6877: $role_start = $1;
1.274 raeburn 6878: }
6879: }
6880: if ($role_start > 0) {
1.412 raeburn 6881: if ($now < $role_start) {
1.274 raeburn 6882: $active_chk = 'future';
6883: }
6884: }
6885: if ($role_end > 0) {
1.412 raeburn 6886: if ($now > $role_end) {
1.274 raeburn 6887: $active_chk = 'previous';
6888: }
6889: }
6890: }
6891: }
6892: return $active_chk;
6893: }
6894:
6895: ###############################################
6896:
6897: =pod
6898:
1.405 albertel 6899: =item * &get_sections()
1.233 raeburn 6900:
6901: Determines all the sections for a course including
6902: sections with students and sections containing other roles.
1.419 raeburn 6903: Incoming parameters:
6904:
6905: 1. domain
6906: 2. course number
6907: 3. reference to array containing roles for which sections should
6908: be gathered (optional).
6909: 4. reference to array containing status types for which sections
6910: should be gathered (optional).
6911:
6912: If the third argument is undefined, sections are gathered for any role.
6913: If the fourth argument is undefined, sections are gathered for any status.
6914: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6915:
1.374 raeburn 6916: Returns section hash (keys are section IDs, values are
6917: number of users in each section), subject to the
1.419 raeburn 6918: optional roles filter, optional status filter
1.233 raeburn 6919:
6920: =cut
6921:
6922: ###############################################
6923: sub get_sections {
1.419 raeburn 6924: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6925: if (!defined($cdom) || !defined($cnum)) {
6926: my $cid = $env{'request.course.id'};
6927:
6928: return if (!defined($cid));
6929:
6930: $cdom = $env{'course.'.$cid.'.domain'};
6931: $cnum = $env{'course.'.$cid.'.num'};
6932: }
6933:
6934: my %sectioncount;
1.419 raeburn 6935: my $now = time;
1.240 albertel 6936:
1.366 albertel 6937: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6938: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6939: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6940: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6941: my $start_index = &Apache::loncoursedata::CL_START();
6942: my $end_index = &Apache::loncoursedata::CL_END();
6943: my $status;
1.366 albertel 6944: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6945: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6946: $data->[$status_index],
6947: $data->[$start_index],
6948: $data->[$end_index]);
6949: if ($stu_status eq 'Active') {
6950: $status = 'active';
6951: } elsif ($end < $now) {
6952: $status = 'previous';
6953: } elsif ($start > $now) {
6954: $status = 'future';
6955: }
6956: if ($section ne '-1' && $section !~ /^\s*$/) {
6957: if ((!defined($possible_status)) || (($status ne '') &&
6958: (grep/^\Q$status\E$/,@{$possible_status}))) {
6959: $sectioncount{$section}++;
6960: }
1.240 albertel 6961: }
6962: }
6963: }
6964: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6965: foreach my $user (sort(keys(%courseroles))) {
6966: if ($user !~ /^(\w{2})/) { next; }
6967: my ($role) = ($user =~ /^(\w{2})/);
6968: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6969: my ($section,$status);
1.240 albertel 6970: if ($role eq 'cr' &&
6971: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6972: $section=$1;
6973: }
6974: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6975: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6976: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6977: if ($end == -1 && $start == -1) {
6978: next; #deleted role
6979: }
6980: if (!defined($possible_status)) {
6981: $sectioncount{$section}++;
6982: } else {
6983: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6984: $status = 'active';
6985: } elsif ($end < $now) {
6986: $status = 'future';
6987: } elsif ($start > $now) {
6988: $status = 'previous';
6989: }
6990: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6991: $sectioncount{$section}++;
6992: }
6993: }
1.233 raeburn 6994: }
1.366 albertel 6995: return %sectioncount;
1.233 raeburn 6996: }
6997:
1.274 raeburn 6998: ###############################################
1.294 raeburn 6999:
7000: =pod
1.405 albertel 7001:
7002: =item * &get_course_users()
7003:
1.275 raeburn 7004: Retrieves usernames:domains for users in the specified course
7005: with specific role(s), and access status.
7006:
7007: Incoming parameters:
1.277 albertel 7008: 1. course domain
7009: 2. course number
7010: 3. access status: users must have - either active,
1.275 raeburn 7011: previous, future, or all.
1.277 albertel 7012: 4. reference to array of permissible roles
1.288 raeburn 7013: 5. reference to array of section restrictions (optional)
7014: 6. reference to results object (hash of hashes).
7015: 7. reference to optional userdata hash
1.609 raeburn 7016: 8. reference to optional statushash
1.630 raeburn 7017: 9. flag if privileged users (except those set to unhide in
7018: course settings) should be excluded
1.609 raeburn 7019: Keys of top level results hash are roles.
1.275 raeburn 7020: Keys of inner hashes are username:domain, with
7021: values set to access type.
1.288 raeburn 7022: Optional userdata hash returns an array with arguments in the
7023: same order as loncoursedata::get_classlist() for student data.
7024:
1.609 raeburn 7025: Optional statushash returns
7026:
1.288 raeburn 7027: Entries for end, start, section and status are blank because
7028: of the possibility of multiple values for non-student roles.
7029:
1.275 raeburn 7030: =cut
1.405 albertel 7031:
1.275 raeburn 7032: ###############################################
1.405 albertel 7033:
1.275 raeburn 7034: sub get_course_users {
1.630 raeburn 7035: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7036: my %idx = ();
1.419 raeburn 7037: my %seclists;
1.288 raeburn 7038:
7039: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7040: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7041: $idx{end} = &Apache::loncoursedata::CL_END();
7042: $idx{start} = &Apache::loncoursedata::CL_START();
7043: $idx{id} = &Apache::loncoursedata::CL_ID();
7044: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7045: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7046: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7047:
1.290 albertel 7048: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7049: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7050: my $now = time;
1.277 albertel 7051: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7052: my $match = 0;
1.412 raeburn 7053: my $secmatch = 0;
1.419 raeburn 7054: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7055: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7056: if ($section eq '') {
7057: $section = 'none';
7058: }
1.291 albertel 7059: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7060: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7061: $secmatch = 1;
7062: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7063: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7064: $secmatch = 1;
7065: }
7066: } else {
1.419 raeburn 7067: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7068: $secmatch = 1;
7069: }
1.290 albertel 7070: }
1.412 raeburn 7071: if (!$secmatch) {
7072: next;
7073: }
1.419 raeburn 7074: }
1.275 raeburn 7075: if (defined($$types{'active'})) {
1.288 raeburn 7076: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7077: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7078: $match = 1;
1.275 raeburn 7079: }
7080: }
7081: if (defined($$types{'previous'})) {
1.609 raeburn 7082: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7083: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7084: $match = 1;
1.275 raeburn 7085: }
7086: }
7087: if (defined($$types{'future'})) {
1.609 raeburn 7088: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7089: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7090: $match = 1;
1.275 raeburn 7091: }
7092: }
1.609 raeburn 7093: if ($match) {
7094: push(@{$seclists{$student}},$section);
7095: if (ref($userdata) eq 'HASH') {
7096: $$userdata{$student} = $$classlist{$student};
7097: }
7098: if (ref($statushash) eq 'HASH') {
7099: $statushash->{$student}{'st'}{$section} = $status;
7100: }
1.288 raeburn 7101: }
1.275 raeburn 7102: }
7103: }
1.412 raeburn 7104: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7105: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7106: my $now = time;
1.609 raeburn 7107: my %displaystatus = ( previous => 'Expired',
7108: active => 'Active',
7109: future => 'Future',
7110: );
1.630 raeburn 7111: my %nothide;
7112: if ($hidepriv) {
7113: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7114: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7115: if ($user !~ /:/) {
7116: $nothide{join(':',split(/[\@]/,$user))}=1;
7117: } else {
7118: $nothide{$user} = 1;
7119: }
7120: }
7121: }
1.439 raeburn 7122: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7123: my $match = 0;
1.412 raeburn 7124: my $secmatch = 0;
1.439 raeburn 7125: my $status;
1.412 raeburn 7126: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7127: $user =~ s/:$//;
1.439 raeburn 7128: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7129: if ($end == -1 || $start == -1) {
7130: next;
7131: }
7132: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7133: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7134: my ($uname,$udom) = split(/:/,$user);
7135: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7136: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7137: $secmatch = 1;
7138: } elsif ($usec eq '') {
1.420 albertel 7139: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7140: $secmatch = 1;
7141: }
7142: } else {
7143: if (grep(/^\Q$usec\E$/,@{$sections})) {
7144: $secmatch = 1;
7145: }
7146: }
7147: if (!$secmatch) {
7148: next;
7149: }
1.288 raeburn 7150: }
1.419 raeburn 7151: if ($usec eq '') {
7152: $usec = 'none';
7153: }
1.275 raeburn 7154: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7155: if ($hidepriv) {
7156: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7157: (!$nothide{$uname.':'.$udom})) {
7158: next;
7159: }
7160: }
1.503 raeburn 7161: if ($end > 0 && $end < $now) {
1.439 raeburn 7162: $status = 'previous';
7163: } elsif ($start > $now) {
7164: $status = 'future';
7165: } else {
7166: $status = 'active';
7167: }
1.277 albertel 7168: foreach my $type (keys(%{$types})) {
1.275 raeburn 7169: if ($status eq $type) {
1.420 albertel 7170: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7171: push(@{$$users{$role}{$user}},$type);
7172: }
1.288 raeburn 7173: $match = 1;
7174: }
7175: }
1.419 raeburn 7176: if (($match) && (ref($userdata) eq 'HASH')) {
7177: if (!exists($$userdata{$uname.':'.$udom})) {
7178: &get_user_info($udom,$uname,\%idx,$userdata);
7179: }
1.420 albertel 7180: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7181: push(@{$seclists{$uname.':'.$udom}},$usec);
7182: }
1.609 raeburn 7183: if (ref($statushash) eq 'HASH') {
7184: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7185: }
1.275 raeburn 7186: }
7187: }
7188: }
7189: }
1.290 albertel 7190: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7191: if ((defined($cdom)) && (defined($cnum))) {
7192: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7193: if ( defined($csettings{'internal.courseowner'}) ) {
7194: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7195: next if ($owner eq '');
7196: my ($ownername,$ownerdom);
7197: if ($owner =~ /^([^:]+):([^:]+)$/) {
7198: $ownername = $1;
7199: $ownerdom = $2;
7200: } else {
7201: $ownername = $owner;
7202: $ownerdom = $cdom;
7203: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7204: }
7205: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7206: if (defined($userdata) &&
1.609 raeburn 7207: !exists($$userdata{$owner})) {
7208: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7209: if (!grep(/^none$/,@{$seclists{$owner}})) {
7210: push(@{$seclists{$owner}},'none');
7211: }
7212: if (ref($statushash) eq 'HASH') {
7213: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7214: }
1.290 albertel 7215: }
1.279 raeburn 7216: }
7217: }
7218: }
1.419 raeburn 7219: foreach my $user (keys(%seclists)) {
7220: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7221: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7222: }
1.275 raeburn 7223: }
7224: return;
7225: }
7226:
1.288 raeburn 7227: sub get_user_info {
7228: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7229: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7230: &plainname($uname,$udom,'lastname');
1.291 albertel 7231: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7232: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7233: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7234: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7235: return;
7236: }
1.275 raeburn 7237:
1.472 raeburn 7238: ###############################################
7239:
7240: =pod
7241:
7242: =item * &get_user_quota()
7243:
7244: Retrieves quota assigned for storage of portfolio files for a user
7245:
7246: Incoming parameters:
7247: 1. user's username
7248: 2. user's domain
7249:
7250: Returns:
1.536 raeburn 7251: 1. Disk quota (in Mb) assigned to student.
7252: 2. (Optional) Type of setting: custom or default
7253: (individually assigned or default for user's
7254: institutional status).
7255: 3. (Optional) - User's institutional status (e.g., faculty, staff
7256: or student - types as defined in localenroll::inst_usertypes
7257: for user's domain, which determines default quota for user.
7258: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7259:
7260: If a value has been stored in the user's environment,
1.536 raeburn 7261: it will return that, otherwise it returns the maximal default
7262: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7263:
7264: =cut
7265:
7266: ###############################################
7267:
7268:
7269: sub get_user_quota {
7270: my ($uname,$udom) = @_;
1.536 raeburn 7271: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7272: if (!defined($udom)) {
7273: $udom = $env{'user.domain'};
7274: }
7275: if (!defined($uname)) {
7276: $uname = $env{'user.name'};
7277: }
7278: if (($udom eq '' || $uname eq '') ||
7279: ($udom eq 'public') && ($uname eq 'public')) {
7280: $quota = 0;
1.536 raeburn 7281: $quotatype = 'default';
7282: $defquota = 0;
1.472 raeburn 7283: } else {
1.536 raeburn 7284: my $inststatus;
1.472 raeburn 7285: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7286: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7287: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7288: } else {
1.536 raeburn 7289: my %userenv =
7290: &Apache::lonnet::get('environment',['portfolioquota',
7291: 'inststatus'],$udom,$uname);
1.472 raeburn 7292: my ($tmp) = keys(%userenv);
7293: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7294: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7295: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7296: } else {
7297: undef(%userenv);
7298: }
7299: }
1.536 raeburn 7300: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7301: if ($quota eq '') {
1.536 raeburn 7302: $quota = $defquota;
7303: $quotatype = 'default';
7304: } else {
7305: $quotatype = 'custom';
1.472 raeburn 7306: }
7307: }
1.536 raeburn 7308: if (wantarray) {
7309: return ($quota,$quotatype,$settingstatus,$defquota);
7310: } else {
7311: return $quota;
7312: }
1.472 raeburn 7313: }
7314:
7315: ###############################################
7316:
7317: =pod
7318:
7319: =item * &default_quota()
7320:
1.536 raeburn 7321: Retrieves default quota assigned for storage of user portfolio files,
7322: given an (optional) user's institutional status.
1.472 raeburn 7323:
7324: Incoming parameters:
7325: 1. domain
1.536 raeburn 7326: 2. (Optional) institutional status(es). This is a : separated list of
7327: status types (e.g., faculty, staff, student etc.)
7328: which apply to the user for whom the default is being retrieved.
7329: If the institutional status string in undefined, the domain
7330: default quota will be returned.
1.472 raeburn 7331:
7332: Returns:
7333: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7334: 2. (Optional) institutional type which determined the value of the
7335: default quota.
1.472 raeburn 7336:
7337: If a value has been stored in the domain's configuration db,
7338: it will return that, otherwise it returns 20 (for backwards
7339: compatibility with domains which have not set up a configuration
7340: db file; the original statically defined portfolio quota was 20 Mb).
7341:
1.536 raeburn 7342: If the user's status includes multiple types (e.g., staff and student),
7343: the largest default quota which applies to the user determines the
7344: default quota returned.
7345:
1.780 raeburn 7346: =back
7347:
1.472 raeburn 7348: =cut
7349:
7350: ###############################################
7351:
7352:
7353: sub default_quota {
1.536 raeburn 7354: my ($udom,$inststatus) = @_;
7355: my ($defquota,$settingstatus);
7356: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7357: ['quotas'],$udom);
7358: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7359: if ($inststatus ne '') {
1.765 raeburn 7360: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7361: foreach my $item (@statuses) {
1.711 raeburn 7362: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7363: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7364: if ($defquota eq '') {
7365: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7366: $settingstatus = $item;
7367: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7368: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7369: $settingstatus = $item;
7370: }
7371: }
7372: } else {
7373: if ($quotahash{'quotas'}{$item} ne '') {
7374: if ($defquota eq '') {
7375: $defquota = $quotahash{'quotas'}{$item};
7376: $settingstatus = $item;
7377: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7378: $defquota = $quotahash{'quotas'}{$item};
7379: $settingstatus = $item;
7380: }
1.536 raeburn 7381: }
7382: }
7383: }
7384: }
7385: if ($defquota eq '') {
1.711 raeburn 7386: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7387: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7388: } else {
7389: $defquota = $quotahash{'quotas'}{'default'};
7390: }
1.536 raeburn 7391: $settingstatus = 'default';
7392: }
7393: } else {
7394: $settingstatus = 'default';
7395: $defquota = 20;
7396: }
7397: if (wantarray) {
7398: return ($defquota,$settingstatus);
1.472 raeburn 7399: } else {
1.536 raeburn 7400: return $defquota;
1.472 raeburn 7401: }
7402: }
7403:
1.384 raeburn 7404: sub get_secgrprole_info {
7405: my ($cdom,$cnum,$needroles,$type) = @_;
7406: my %sections_count = &get_sections($cdom,$cnum);
7407: my @sections = (sort {$a <=> $b} keys(%sections_count));
7408: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7409: my @groups = sort(keys(%curr_groups));
7410: my $allroles = [];
7411: my $rolehash;
7412: my $accesshash = {
7413: active => 'Currently has access',
7414: future => 'Will have future access',
7415: previous => 'Previously had access',
7416: };
7417: if ($needroles) {
7418: $rolehash = {'all' => 'all'};
1.385 albertel 7419: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7420: if (&Apache::lonnet::error(%user_roles)) {
7421: undef(%user_roles);
7422: }
7423: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7424: my ($role)=split(/\:/,$item,2);
7425: if ($role eq 'cr') { next; }
7426: if ($role =~ /^cr/) {
7427: $$rolehash{$role} = (split('/',$role))[3];
7428: } else {
7429: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7430: }
7431: }
7432: foreach my $key (sort(keys(%{$rolehash}))) {
7433: push(@{$allroles},$key);
7434: }
7435: push (@{$allroles},'st');
7436: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7437: }
7438: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7439: }
7440:
1.555 raeburn 7441: sub user_picker {
1.627 raeburn 7442: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7443: my $currdom = $dom;
7444: my %curr_selected = (
7445: srchin => 'dom',
1.580 raeburn 7446: srchby => 'lastname',
1.555 raeburn 7447: );
7448: my $srchterm;
1.625 raeburn 7449: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7450: if ($srch->{'srchby'} ne '') {
7451: $curr_selected{'srchby'} = $srch->{'srchby'};
7452: }
7453: if ($srch->{'srchin'} ne '') {
7454: $curr_selected{'srchin'} = $srch->{'srchin'};
7455: }
7456: if ($srch->{'srchtype'} ne '') {
7457: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7458: }
7459: if ($srch->{'srchdomain'} ne '') {
7460: $currdom = $srch->{'srchdomain'};
7461: }
7462: $srchterm = $srch->{'srchterm'};
7463: }
7464: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7465: 'usr' => 'Search criteria',
1.563 raeburn 7466: 'doma' => 'Domain/institution to search',
1.558 albertel 7467: 'uname' => 'username',
7468: 'lastname' => 'last name',
1.555 raeburn 7469: 'lastfirst' => 'last name, first name',
1.558 albertel 7470: 'crs' => 'in this course',
1.576 raeburn 7471: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7472: 'alc' => 'all LON-CAPA',
1.573 raeburn 7473: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7474: 'exact' => 'is',
7475: 'contains' => 'contains',
1.569 raeburn 7476: 'begins' => 'begins with',
1.571 raeburn 7477: 'youm' => "You must include some text to search for.",
7478: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7479: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7480: 'yomc' => "You must choose a domain when using an institutional directory search.",
7481: 'ymcd' => "You must choose a domain when using a domain search.",
7482: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7483: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7484: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7485: );
1.563 raeburn 7486: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7487: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7488:
7489: my @srchins = ('crs','dom','alc','instd');
7490:
7491: foreach my $option (@srchins) {
7492: # FIXME 'alc' option unavailable until
7493: # loncreateuser::print_user_query_page()
7494: # has been completed.
7495: next if ($option eq 'alc');
7496: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7497: if ($curr_selected{'srchin'} eq $option) {
7498: $srchinsel .= '
7499: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7500: } else {
7501: $srchinsel .= '
7502: <option value="'.$option.'">'.$lt{$option}.'</option>';
7503: }
1.555 raeburn 7504: }
1.563 raeburn 7505: $srchinsel .= "\n </select>\n";
1.555 raeburn 7506:
7507: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7508: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7509: if ($curr_selected{'srchby'} eq $option) {
7510: $srchbysel .= '
7511: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7512: } else {
7513: $srchbysel .= '
7514: <option value="'.$option.'">'.$lt{$option}.'</option>';
7515: }
7516: }
7517: $srchbysel .= "\n </select>\n";
7518:
7519: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7520: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7521: if ($curr_selected{'srchtype'} eq $option) {
7522: $srchtypesel .= '
7523: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7524: } else {
7525: $srchtypesel .= '
7526: <option value="'.$option.'">'.$lt{$option}.'</option>';
7527: }
7528: }
7529: $srchtypesel .= "\n </select>\n";
7530:
1.558 albertel 7531: my ($newuserscript,$new_user_create);
1.556 raeburn 7532:
7533: if ($forcenewuser) {
1.576 raeburn 7534: if (ref($srch) eq 'HASH') {
7535: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7536: if ($cancreate) {
7537: $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>';
7538: } else {
1.799 bisitz 7539: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7540: my %usertypetext = (
7541: official => 'institutional',
7542: unofficial => 'non-institutional',
7543: );
1.799 bisitz 7544: $new_user_create = '<p class="LC_warning">'
7545: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7546: .' '
7547: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7548: ,'<a href="'.$helplink.'">','</a>')
7549: .'</p><br />';
1.627 raeburn 7550: }
1.576 raeburn 7551: }
7552: }
7553:
1.556 raeburn 7554: $newuserscript = <<"ENDSCRIPT";
7555:
1.570 raeburn 7556: function setSearch(createnew,callingForm) {
1.556 raeburn 7557: if (createnew == 1) {
1.570 raeburn 7558: for (var i=0; i<callingForm.srchby.length; i++) {
7559: if (callingForm.srchby.options[i].value == 'uname') {
7560: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7561: }
7562: }
1.570 raeburn 7563: for (var i=0; i<callingForm.srchin.length; i++) {
7564: if ( callingForm.srchin.options[i].value == 'dom') {
7565: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7566: }
7567: }
1.570 raeburn 7568: for (var i=0; i<callingForm.srchtype.length; i++) {
7569: if (callingForm.srchtype.options[i].value == 'exact') {
7570: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7571: }
7572: }
1.570 raeburn 7573: for (var i=0; i<callingForm.srchdomain.length; i++) {
7574: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7575: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7576: }
7577: }
7578: }
7579: }
7580: ENDSCRIPT
1.558 albertel 7581:
1.556 raeburn 7582: }
7583:
1.555 raeburn 7584: my $output = <<"END_BLOCK";
1.556 raeburn 7585: <script type="text/javascript">
1.824 bisitz 7586: // <![CDATA[
1.570 raeburn 7587: function validateEntry(callingForm) {
1.558 albertel 7588:
1.556 raeburn 7589: var checkok = 1;
1.558 albertel 7590: var srchin;
1.570 raeburn 7591: for (var i=0; i<callingForm.srchin.length; i++) {
7592: if ( callingForm.srchin[i].checked ) {
7593: srchin = callingForm.srchin[i].value;
1.558 albertel 7594: }
7595: }
7596:
1.570 raeburn 7597: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7598: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7599: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7600: var srchterm = callingForm.srchterm.value;
7601: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7602: var msg = "";
7603:
7604: if (srchterm == "") {
7605: checkok = 0;
1.571 raeburn 7606: msg += "$lt{'youm'}\\n";
1.556 raeburn 7607: }
7608:
1.569 raeburn 7609: if (srchtype== 'begins') {
7610: if (srchterm.length < 2) {
7611: checkok = 0;
1.571 raeburn 7612: msg += "$lt{'thte'}\\n";
1.569 raeburn 7613: }
7614: }
7615:
1.556 raeburn 7616: if (srchtype== 'contains') {
7617: if (srchterm.length < 3) {
7618: checkok = 0;
1.571 raeburn 7619: msg += "$lt{'thet'}\\n";
1.556 raeburn 7620: }
7621: }
7622: if (srchin == 'instd') {
7623: if (srchdomain == '') {
7624: checkok = 0;
1.571 raeburn 7625: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7626: }
7627: }
7628: if (srchin == 'dom') {
7629: if (srchdomain == '') {
7630: checkok = 0;
1.571 raeburn 7631: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7632: }
7633: }
7634: if (srchby == 'lastfirst') {
7635: if (srchterm.indexOf(",") == -1) {
7636: checkok = 0;
1.571 raeburn 7637: msg += "$lt{'whus'}\\n";
1.556 raeburn 7638: }
7639: if (srchterm.indexOf(",") == srchterm.length -1) {
7640: checkok = 0;
1.571 raeburn 7641: msg += "$lt{'whse'}\\n";
1.556 raeburn 7642: }
7643: }
7644: if (checkok == 0) {
1.571 raeburn 7645: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7646: return;
7647: }
7648: if (checkok == 1) {
1.570 raeburn 7649: callingForm.submit();
1.556 raeburn 7650: }
7651: }
7652:
7653: $newuserscript
7654:
1.824 bisitz 7655: // ]]>
1.556 raeburn 7656: </script>
1.558 albertel 7657:
7658: $new_user_create
7659:
1.555 raeburn 7660: <table>
1.558 albertel 7661: <tr>
1.573 raeburn 7662: <td>$lt{'doma'}:</td>
7663: <td>$domform</td>
7664: </td>
7665: </tr>
7666: <tr>
7667: <td>$lt{'usr'}:</td>
1.563 raeburn 7668: <td>$srchbysel
7669: $srchtypesel
7670: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7671: $srchinsel
1.563 raeburn 7672: </td>
7673: </tr>
1.555 raeburn 7674: </table>
7675: <br />
7676: END_BLOCK
1.558 albertel 7677:
1.555 raeburn 7678: return $output;
7679: }
7680:
1.612 raeburn 7681: sub user_rule_check {
1.615 raeburn 7682: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7683: my $response;
7684: if (ref($usershash) eq 'HASH') {
7685: foreach my $user (keys(%{$usershash})) {
7686: my ($uname,$udom) = split(/:/,$user);
7687: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7688: my ($id,$newuser);
1.612 raeburn 7689: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7690: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7691: $id = $usershash->{$user}->{'id'};
7692: }
7693: my $inst_response;
7694: if (ref($checks) eq 'HASH') {
7695: if (defined($checks->{'username'})) {
1.615 raeburn 7696: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7697: &Apache::lonnet::get_instuser($udom,$uname);
7698: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7699: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7700: &Apache::lonnet::get_instuser($udom,undef,$id);
7701: }
1.615 raeburn 7702: } else {
7703: ($inst_response,%{$inst_results->{$user}}) =
7704: &Apache::lonnet::get_instuser($udom,$uname);
7705: return;
1.612 raeburn 7706: }
1.615 raeburn 7707: if (!$got_rules->{$udom}) {
1.612 raeburn 7708: my %domconfig = &Apache::lonnet::get_dom('configuration',
7709: ['usercreation'],$udom);
7710: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7711: foreach my $item ('username','id') {
1.612 raeburn 7712: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7713: $$curr_rules{$udom}{$item} =
7714: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7715: }
7716: }
7717: }
1.615 raeburn 7718: $got_rules->{$udom} = 1;
1.585 raeburn 7719: }
1.612 raeburn 7720: foreach my $item (keys(%{$checks})) {
7721: if (ref($$curr_rules{$udom}) eq 'HASH') {
7722: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7723: if (@{$$curr_rules{$udom}{$item}} > 0) {
7724: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7725: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7726: if ($rule_check{$rule}) {
7727: $$rulematch{$user}{$item} = $rule;
7728: if ($inst_response eq 'ok') {
1.615 raeburn 7729: if (ref($inst_results) eq 'HASH') {
7730: if (ref($inst_results->{$user}) eq 'HASH') {
7731: if (keys(%{$inst_results->{$user}}) == 0) {
7732: $$alerts{$item}{$udom}{$uname} = 1;
7733: }
1.612 raeburn 7734: }
7735: }
1.615 raeburn 7736: }
7737: last;
1.585 raeburn 7738: }
7739: }
7740: }
7741: }
7742: }
7743: }
7744: }
7745: }
1.612 raeburn 7746: return;
7747: }
7748:
7749: sub user_rule_formats {
7750: my ($domain,$domdesc,$curr_rules,$check) = @_;
7751: my %text = (
7752: 'username' => 'Usernames',
7753: 'id' => 'IDs',
7754: );
7755: my $output;
7756: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7757: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7758: if (@{$ruleorder} > 0) {
7759: $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>';
7760: foreach my $rule (@{$ruleorder}) {
7761: if (ref($curr_rules) eq 'ARRAY') {
7762: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7763: if (ref($rules->{$rule}) eq 'HASH') {
7764: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7765: $rules->{$rule}{'desc'}.'</li>';
7766: }
7767: }
7768: }
7769: }
7770: $output .= '</ul>';
7771: }
7772: }
7773: return $output;
7774: }
7775:
7776: sub instrule_disallow_msg {
1.615 raeburn 7777: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7778: my $response;
7779: my %text = (
7780: item => 'username',
7781: items => 'usernames',
7782: match => 'matches',
7783: do => 'does',
7784: action => 'a username',
7785: one => 'one',
7786: );
7787: if ($count > 1) {
7788: $text{'item'} = 'usernames';
7789: $text{'match'} ='match';
7790: $text{'do'} = 'do';
7791: $text{'action'} = 'usernames',
7792: $text{'one'} = 'ones';
7793: }
7794: if ($checkitem eq 'id') {
7795: $text{'items'} = 'IDs';
7796: $text{'item'} = 'ID';
7797: $text{'action'} = 'an ID';
1.615 raeburn 7798: if ($count > 1) {
7799: $text{'item'} = 'IDs';
7800: $text{'action'} = 'IDs';
7801: }
1.612 raeburn 7802: }
1.674 bisitz 7803: $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 7804: if ($mode eq 'upload') {
7805: if ($checkitem eq 'username') {
7806: $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'}.");
7807: } elsif ($checkitem eq 'id') {
1.674 bisitz 7808: $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 7809: }
1.669 raeburn 7810: } elsif ($mode eq 'selfcreate') {
7811: if ($checkitem eq 'id') {
7812: $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.");
7813: }
1.615 raeburn 7814: } else {
7815: if ($checkitem eq 'username') {
7816: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7817: } elsif ($checkitem eq 'id') {
7818: $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.");
7819: }
1.612 raeburn 7820: }
7821: return $response;
1.585 raeburn 7822: }
7823:
1.624 raeburn 7824: sub personal_data_fieldtitles {
7825: my %fieldtitles = &Apache::lonlocal::texthash (
7826: id => 'Student/Employee ID',
7827: permanentemail => 'E-mail address',
7828: lastname => 'Last Name',
7829: firstname => 'First Name',
7830: middlename => 'Middle Name',
7831: generation => 'Generation',
7832: gen => 'Generation',
1.765 raeburn 7833: inststatus => 'Affiliation',
1.624 raeburn 7834: );
7835: return %fieldtitles;
7836: }
7837:
1.642 raeburn 7838: sub sorted_inst_types {
7839: my ($dom) = @_;
7840: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7841: my $othertitle = &mt('All users');
7842: if ($env{'request.course.id'}) {
1.668 raeburn 7843: $othertitle = &mt('Any users');
1.642 raeburn 7844: }
7845: my @types;
7846: if (ref($order) eq 'ARRAY') {
7847: @types = @{$order};
7848: }
7849: if (@types == 0) {
7850: if (ref($usertypes) eq 'HASH') {
7851: @types = sort(keys(%{$usertypes}));
7852: }
7853: }
7854: if (keys(%{$usertypes}) > 0) {
7855: $othertitle = &mt('Other users');
7856: }
7857: return ($othertitle,$usertypes,\@types);
7858: }
7859:
1.645 raeburn 7860: sub get_institutional_codes {
7861: my ($settings,$allcourses,$LC_code) = @_;
7862: # Get complete list of course sections to update
7863: my @currsections = ();
7864: my @currxlists = ();
7865: my $coursecode = $$settings{'internal.coursecode'};
7866:
7867: if ($$settings{'internal.sectionnums'} ne '') {
7868: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7869: }
7870:
7871: if ($$settings{'internal.crosslistings'} ne '') {
7872: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7873: }
7874:
7875: if (@currxlists > 0) {
7876: foreach (@currxlists) {
7877: if (m/^([^:]+):(\w*)$/) {
7878: unless (grep/^$1$/,@{$allcourses}) {
7879: push @{$allcourses},$1;
7880: $$LC_code{$1} = $2;
7881: }
7882: }
7883: }
7884: }
7885:
7886: if (@currsections > 0) {
7887: foreach (@currsections) {
7888: if (m/^(\w+):(\w*)$/) {
7889: my $sec = $coursecode.$1;
7890: my $lc_sec = $2;
7891: unless (grep/^$sec$/,@{$allcourses}) {
7892: push @{$allcourses},$sec;
7893: $$LC_code{$sec} = $lc_sec;
7894: }
7895: }
7896: }
7897: }
7898: return;
7899: }
7900:
1.112 bowersj2 7901: =pod
7902:
1.780 raeburn 7903: =head1 Slot Helpers
7904:
7905: =over 4
7906:
7907: =item * sorted_slots()
7908:
7909: Sorts an array of slot names in order of slot start time (earliest first).
7910:
7911: Inputs:
7912:
7913: =over 4
7914:
7915: slotsarr - Reference to array of unsorted slot names.
7916:
7917: slots - Reference to hash of hash, where outer hash keys are slot names.
7918:
1.549 albertel 7919: =back
7920:
1.780 raeburn 7921: Returns:
7922:
7923: =over 4
7924:
7925: sorted - An array of slot names sorted by the start time of the slot.
7926:
7927: =back
7928:
7929: =back
7930:
7931: =cut
7932:
7933:
7934: sub sorted_slots {
7935: my ($slotsarr,$slots) = @_;
7936: my @sorted;
7937: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7938: @sorted =
7939: sort {
7940: if (ref($slots->{$a}) && ref($slots->{$b})) {
7941: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7942: }
7943: if (ref($slots->{$a})) { return -1;}
7944: if (ref($slots->{$b})) { return 1;}
7945: return 0;
7946: } @{$slotsarr};
7947: }
7948: return @sorted;
7949: }
7950:
7951:
7952: =pod
7953:
1.549 albertel 7954: =head1 HTTP Helpers
7955:
7956: =over 4
7957:
1.648 raeburn 7958: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7959:
1.258 albertel 7960: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7961: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7962: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7963:
7964: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7965: $possible_names is an ref to an array of form element names. As an example:
7966: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7967: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7968:
7969: =cut
1.1 albertel 7970:
1.6 albertel 7971: sub get_unprocessed_cgi {
1.25 albertel 7972: my ($query,$possible_names)= @_;
1.26 matthew 7973: # $Apache::lonxml::debug=1;
1.356 albertel 7974: foreach my $pair (split(/&/,$query)) {
7975: my ($name, $value) = split(/=/,$pair);
1.369 www 7976: $name = &unescape($name);
1.25 albertel 7977: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7978: $value =~ tr/+/ /;
7979: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7980: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7981: }
1.16 harris41 7982: }
1.6 albertel 7983: }
7984:
1.112 bowersj2 7985: =pod
7986:
1.648 raeburn 7987: =item * &cacheheader()
1.112 bowersj2 7988:
7989: returns cache-controlling header code
7990:
7991: =cut
7992:
1.7 albertel 7993: sub cacheheader {
1.258 albertel 7994: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7995: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7996: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7997: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7998: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7999: return $output;
1.7 albertel 8000: }
8001:
1.112 bowersj2 8002: =pod
8003:
1.648 raeburn 8004: =item * &no_cache($r)
1.112 bowersj2 8005:
8006: specifies header code to not have cache
8007:
8008: =cut
8009:
1.9 albertel 8010: sub no_cache {
1.216 albertel 8011: my ($r) = @_;
8012: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8013: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8014: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8015: $r->no_cache(1);
8016: $r->header_out("Expires" => $date);
8017: $r->header_out("Pragma" => "no-cache");
1.123 www 8018: }
8019:
8020: sub content_type {
1.181 albertel 8021: my ($r,$type,$charset) = @_;
1.299 foxr 8022: if ($r) {
8023: # Note that printout.pl calls this with undef for $r.
8024: &no_cache($r);
8025: }
1.258 albertel 8026: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8027: unless ($charset) {
8028: $charset=&Apache::lonlocal::current_encoding;
8029: }
8030: if ($charset) { $type.='; charset='.$charset; }
8031: if ($r) {
8032: $r->content_type($type);
8033: } else {
8034: print("Content-type: $type\n\n");
8035: }
1.9 albertel 8036: }
1.25 albertel 8037:
1.112 bowersj2 8038: =pod
8039:
1.648 raeburn 8040: =item * &add_to_env($name,$value)
1.112 bowersj2 8041:
1.258 albertel 8042: adds $name to the %env hash with value
1.112 bowersj2 8043: $value, if $name already exists, the entry is converted to an array
8044: reference and $value is added to the array.
8045:
8046: =cut
8047:
1.25 albertel 8048: sub add_to_env {
8049: my ($name,$value)=@_;
1.258 albertel 8050: if (defined($env{$name})) {
8051: if (ref($env{$name})) {
1.25 albertel 8052: #already have multiple values
1.258 albertel 8053: push(@{ $env{$name} },$value);
1.25 albertel 8054: } else {
8055: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8056: my $first=$env{$name};
8057: undef($env{$name});
8058: push(@{ $env{$name} },$first,$value);
1.25 albertel 8059: }
8060: } else {
1.258 albertel 8061: $env{$name}=$value;
1.25 albertel 8062: }
1.31 albertel 8063: }
1.149 albertel 8064:
8065: =pod
8066:
1.648 raeburn 8067: =item * &get_env_multiple($name)
1.149 albertel 8068:
1.258 albertel 8069: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8070: values may be defined and end up as an array ref.
8071:
8072: returns an array of values
8073:
8074: =cut
8075:
8076: sub get_env_multiple {
8077: my ($name) = @_;
8078: my @values;
1.258 albertel 8079: if (defined($env{$name})) {
1.149 albertel 8080: # exists is it an array
1.258 albertel 8081: if (ref($env{$name})) {
8082: @values=@{ $env{$name} };
1.149 albertel 8083: } else {
1.258 albertel 8084: $values[0]=$env{$name};
1.149 albertel 8085: }
8086: }
8087: return(@values);
8088: }
8089:
1.660 raeburn 8090: sub ask_for_embedded_content {
8091: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8092: my $upload_output = '
8093: <form name="upload_embedded" action="'.$actionurl.'"
8094: method="post" enctype="multipart/form-data">';
8095: $upload_output .= $state;
1.661 raeburn 8096: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8097:
8098: my $num = 0;
8099: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8100: $upload_output .= &start_data_table_row().
8101: '<td>'.$embed_file.'</td><td>';
8102: if ($args->{'ignore_remote_references'}
8103: && $embed_file =~ m{^\w+://}) {
8104: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8105: } elsif ($args->{'error_on_invalid_names'}
8106: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8107:
8108: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8109:
8110: } else {
8111: $upload_output .='
1.661 raeburn 8112: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8113: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8114: my $attrib = join(':',@{$$allfiles{$embed_file}});
8115: $upload_output .=
8116: "\n\t\t".
8117: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8118: $attrib.'" />';
8119: if (exists($$codebase{$embed_file})) {
8120: $upload_output .=
8121: "\n\t\t".
8122: '<input name="codebase_'.$num.'" type="hidden" value="'.
8123: &escape($$codebase{$embed_file}).'" />';
8124: }
8125: }
8126: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8127: $num++;
8128: }
8129: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8130: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8131: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8132: '.&mt('(only files for which a location has been provided will be uploaded)').'
8133: </form>';
8134: return $upload_output;
8135: }
8136:
1.661 raeburn 8137: sub upload_embedded {
8138: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8139: $current_disk_usage) = @_;
8140: my $output;
8141: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8142: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8143: my $orig_uploaded_filename =
8144: $env{'form.embedded_item_'.$i.'.filename'};
8145:
8146: $env{'form.embedded_orig_'.$i} =
8147: &unescape($env{'form.embedded_orig_'.$i});
8148: my ($path,$fname) =
8149: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8150: # no path, whole string is fname
8151: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8152:
8153: $path = $env{'form.currentpath'}.$path;
8154: $fname = &Apache::lonnet::clean_filename($fname);
8155: # See if there is anything left
8156: next if ($fname eq '');
8157:
8158: # Check if file already exists as a file or directory.
8159: my ($state,$msg);
8160: if ($context eq 'portfolio') {
8161: my $port_path = $dirpath;
8162: if ($group ne '') {
8163: $port_path = "groups/$group/$port_path";
8164: }
8165: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8166: $dir_root,$port_path,$disk_quota,
8167: $current_disk_usage,$uname,$udom);
8168: if ($state eq 'will_exceed_quota'
8169: || $state eq 'file_locked'
8170: || $state eq 'file_exists' ) {
8171: $output .= $msg;
8172: next;
8173: }
8174: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8175: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8176: if ($state eq 'exists') {
8177: $output .= $msg;
8178: next;
8179: }
8180: }
8181: # Check if extension is valid
8182: if (($fname =~ /\.(\w+)$/) &&
8183: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8184: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8185: next;
8186: } elsif (($fname =~ /\.(\w+)$/) &&
8187: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8188: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8189: next;
8190: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8191: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8192: next;
8193: }
8194:
8195: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8196: if ($context eq 'portfolio') {
8197: my $result=
8198: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8199: $dirpath.$path);
8200: if ($result !~ m|^/uploaded/|) {
8201: $output .= '<span class="LC_error">'
8202: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8203: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8204: .'</span><br />';
8205: next;
8206: } else {
8207: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8208: $path.$fname.'</span>').'</p>';
8209: }
8210: } else {
8211: # Save the file
8212: my $target = $env{'form.embedded_item_'.$i};
8213: my $fullpath = $dir_root.$dirpath.'/'.$path;
8214: my $dest = $fullpath.$fname;
8215: my $url = $url_root.$dirpath.'/'.$path.$fname;
8216: my @parts=split(/\//,$fullpath);
8217: my $count;
8218: my $filepath = $dir_root;
8219: for ($count=4;$count<=$#parts;$count++) {
8220: $filepath .= "/$parts[$count]";
8221: if ((-e $filepath)!=1) {
8222: mkdir($filepath,0770);
8223: }
8224: }
8225: my $fh;
8226: if (!open($fh,'>'.$dest)) {
8227: &Apache::lonnet::logthis('Failed to create '.$dest);
8228: $output .= '<span class="LC_error">'.
8229: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8230: '</span><br />';
8231: } else {
8232: if (!print $fh $env{'form.embedded_item_'.$i}) {
8233: &Apache::lonnet::logthis('Failed to write to '.$dest);
8234: $output .= '<span class="LC_error">'.
8235: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8236: '</span><br />';
8237: } else {
8238: if ($context eq 'testbank') {
8239: $output .= &mt('Embedded file uploaded successfully:').
8240: ' <a href="'.$url.'">'.
8241: $orig_uploaded_filename.'</a><br />';
8242: } else {
1.705 tempelho 8243: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8244: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8245: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8246: }
8247: }
8248: close($fh);
8249: }
8250: }
8251: }
8252: return $output;
8253: }
8254:
8255: sub check_for_existing {
8256: my ($path,$fname,$element) = @_;
8257: my ($state,$msg);
8258: if (-d $path.'/'.$fname) {
8259: $state = 'exists';
8260: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8261: } elsif (-e $path.'/'.$fname) {
8262: $state = 'exists';
8263: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8264: }
8265: if ($state eq 'exists') {
8266: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8267: }
8268: return ($state,$msg);
8269: }
8270:
8271: sub check_for_upload {
8272: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8273: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8274: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8275: my $getpropath = 1;
8276: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8277: $getpropath);
8278: my $found_file = 0;
8279: my $locked_file = 0;
8280: foreach my $line (@dir_list) {
8281: my ($file_name)=split(/\&/,$line,2);
8282: if ($file_name eq $fname){
8283: $file_name = $path.$file_name;
8284: if ($group ne '') {
8285: $file_name = $group.$file_name;
8286: }
8287: $found_file = 1;
8288: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8289: $locked_file = 1;
8290: }
8291: }
8292: }
8293: if (($current_disk_usage + $filesize) > $disk_quota){
8294: my $msg = '<span class="LC_error">'.
8295: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8296: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8297: return ('will_exceed_quota',$msg);
8298: } elsif ($found_file) {
8299: if ($locked_file) {
8300: my $msg = '<span class="LC_error">';
8301: $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>');
8302: $msg .= '</span><br />';
8303: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8304: return ('file_locked',$msg);
8305: } else {
8306: my $msg = '<span class="LC_error">';
8307: $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'});
8308: $msg .= '</span>';
8309: $msg .= '<br />';
8310: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8311: return ('file_exists',$msg);
8312: }
8313: }
8314: }
8315:
1.31 albertel 8316:
1.41 ng 8317: =pod
1.45 matthew 8318:
1.464 albertel 8319: =back
1.41 ng 8320:
1.112 bowersj2 8321: =head1 CSV Upload/Handling functions
1.38 albertel 8322:
1.41 ng 8323: =over 4
8324:
1.648 raeburn 8325: =item * &upfile_store($r)
1.41 ng 8326:
8327: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8328: needs $env{'form.upfile'}
1.41 ng 8329: returns $datatoken to be put into hidden field
8330:
8331: =cut
1.31 albertel 8332:
8333: sub upfile_store {
8334: my $r=shift;
1.258 albertel 8335: $env{'form.upfile'}=~s/\r/\n/gs;
8336: $env{'form.upfile'}=~s/\f/\n/gs;
8337: $env{'form.upfile'}=~s/\n+/\n/gs;
8338: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8339:
1.258 albertel 8340: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8341: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8342: {
1.158 raeburn 8343: my $datafile = $r->dir_config('lonDaemons').
8344: '/tmp/'.$datatoken.'.tmp';
8345: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8346: print $fh $env{'form.upfile'};
1.158 raeburn 8347: close($fh);
8348: }
1.31 albertel 8349: }
8350: return $datatoken;
8351: }
8352:
1.56 matthew 8353: =pod
8354:
1.648 raeburn 8355: =item * &load_tmp_file($r)
1.41 ng 8356:
8357: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8358: needs $env{'form.datatoken'},
8359: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8360:
8361: =cut
1.31 albertel 8362:
8363: sub load_tmp_file {
8364: my $r=shift;
8365: my @studentdata=();
8366: {
1.158 raeburn 8367: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8368: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8369: if ( open(my $fh,"<$studentfile") ) {
8370: @studentdata=<$fh>;
8371: close($fh);
8372: }
1.31 albertel 8373: }
1.258 albertel 8374: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8375: }
8376:
1.56 matthew 8377: =pod
8378:
1.648 raeburn 8379: =item * &upfile_record_sep()
1.41 ng 8380:
8381: Separate uploaded file into records
8382: returns array of records,
1.258 albertel 8383: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8384:
8385: =cut
1.31 albertel 8386:
8387: sub upfile_record_sep {
1.258 albertel 8388: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8389: } else {
1.248 albertel 8390: my @records;
1.258 albertel 8391: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8392: if ($line=~/^\s*$/) { next; }
8393: push(@records,$line);
8394: }
8395: return @records;
1.31 albertel 8396: }
8397: }
8398:
1.56 matthew 8399: =pod
8400:
1.648 raeburn 8401: =item * &record_sep($record)
1.41 ng 8402:
1.258 albertel 8403: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8404:
8405: =cut
8406:
1.263 www 8407: sub takeleft {
8408: my $index=shift;
8409: return substr('0000'.$index,-4,4);
8410: }
8411:
1.31 albertel 8412: sub record_sep {
8413: my $record=shift;
8414: my %components=();
1.258 albertel 8415: if ($env{'form.upfiletype'} eq 'xml') {
8416: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8417: my $i=0;
1.356 albertel 8418: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8419: $field=~s/^(\"|\')//;
8420: $field=~s/(\"|\')$//;
1.263 www 8421: $components{&takeleft($i)}=$field;
1.31 albertel 8422: $i++;
8423: }
1.258 albertel 8424: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8425: my $i=0;
1.356 albertel 8426: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8427: $field=~s/^(\"|\')//;
8428: $field=~s/(\"|\')$//;
1.263 www 8429: $components{&takeleft($i)}=$field;
1.31 albertel 8430: $i++;
8431: }
8432: } else {
1.561 www 8433: my $separator=',';
1.480 banghart 8434: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8435: $separator=';';
1.480 banghart 8436: }
1.31 albertel 8437: my $i=0;
1.561 www 8438: # the character we are looking for to indicate the end of a quote or a record
8439: my $looking_for=$separator;
8440: # do not add the characters to the fields
8441: my $ignore=0;
8442: # we just encountered a separator (or the beginning of the record)
8443: my $just_found_separator=1;
8444: # store the field we are working on here
8445: my $field='';
8446: # work our way through all characters in record
8447: foreach my $character ($record=~/(.)/g) {
8448: if ($character eq $looking_for) {
8449: if ($character ne $separator) {
8450: # Found the end of a quote, again looking for separator
8451: $looking_for=$separator;
8452: $ignore=1;
8453: } else {
8454: # Found a separator, store away what we got
8455: $components{&takeleft($i)}=$field;
8456: $i++;
8457: $just_found_separator=1;
8458: $ignore=0;
8459: $field='';
8460: }
8461: next;
8462: }
8463: # single or double quotation marks after a separator indicate beginning of a quote
8464: # we are now looking for the end of the quote and need to ignore separators
8465: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8466: $looking_for=$character;
8467: next;
8468: }
8469: # ignore would be true after we reached the end of a quote
8470: if ($ignore) { next; }
8471: if (($just_found_separator) && ($character=~/\s/)) { next; }
8472: $field.=$character;
8473: $just_found_separator=0;
1.31 albertel 8474: }
1.561 www 8475: # catch the very last entry, since we never encountered the separator
8476: $components{&takeleft($i)}=$field;
1.31 albertel 8477: }
8478: return %components;
8479: }
8480:
1.144 matthew 8481: ######################################################
8482: ######################################################
8483:
1.56 matthew 8484: =pod
8485:
1.648 raeburn 8486: =item * &upfile_select_html()
1.41 ng 8487:
1.144 matthew 8488: Return HTML code to select a file from the users machine and specify
8489: the file type.
1.41 ng 8490:
8491: =cut
8492:
1.144 matthew 8493: ######################################################
8494: ######################################################
1.31 albertel 8495: sub upfile_select_html {
1.144 matthew 8496: my %Types = (
8497: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8498: semisv => &mt('Semicolon separated values'),
1.144 matthew 8499: space => &mt('Space separated'),
8500: tab => &mt('Tabulator separated'),
8501: # xml => &mt('HTML/XML'),
8502: );
8503: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8504: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8505: foreach my $type (sort(keys(%Types))) {
8506: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8507: }
8508: $Str .= "</select>\n";
8509: return $Str;
1.31 albertel 8510: }
8511:
1.301 albertel 8512: sub get_samples {
8513: my ($records,$toget) = @_;
8514: my @samples=({});
8515: my $got=0;
8516: foreach my $rec (@$records) {
8517: my %temp = &record_sep($rec);
8518: if (! grep(/\S/, values(%temp))) { next; }
8519: if (%temp) {
8520: $samples[$got]=\%temp;
8521: $got++;
8522: if ($got == $toget) { last; }
8523: }
8524: }
8525: return \@samples;
8526: }
8527:
1.144 matthew 8528: ######################################################
8529: ######################################################
8530:
1.56 matthew 8531: =pod
8532:
1.648 raeburn 8533: =item * &csv_print_samples($r,$records)
1.41 ng 8534:
8535: Prints a table of sample values from each column uploaded $r is an
8536: Apache Request ref, $records is an arrayref from
8537: &Apache::loncommon::upfile_record_sep
8538:
8539: =cut
8540:
1.144 matthew 8541: ######################################################
8542: ######################################################
1.31 albertel 8543: sub csv_print_samples {
8544: my ($r,$records) = @_;
1.662 bisitz 8545: my $samples = &get_samples($records,5);
1.301 albertel 8546:
1.594 raeburn 8547: $r->print(&mt('Samples').'<br />'.&start_data_table().
8548: &start_data_table_header_row());
1.356 albertel 8549: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8550: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8551: $r->print(&end_data_table_header_row());
1.301 albertel 8552: foreach my $hash (@$samples) {
1.594 raeburn 8553: $r->print(&start_data_table_row());
1.356 albertel 8554: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8555: $r->print('<td>');
1.356 albertel 8556: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8557: $r->print('</td>');
8558: }
1.594 raeburn 8559: $r->print(&end_data_table_row());
1.31 albertel 8560: }
1.594 raeburn 8561: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8562: }
8563:
1.144 matthew 8564: ######################################################
8565: ######################################################
8566:
1.56 matthew 8567: =pod
8568:
1.648 raeburn 8569: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8570:
8571: Prints a table to create associations between values and table columns.
1.144 matthew 8572:
1.41 ng 8573: $r is an Apache Request ref,
8574: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8575: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8576:
8577: =cut
8578:
1.144 matthew 8579: ######################################################
8580: ######################################################
1.31 albertel 8581: sub csv_print_select_table {
8582: my ($r,$records,$d) = @_;
1.301 albertel 8583: my $i=0;
8584: my $samples = &get_samples($records,1);
1.144 matthew 8585: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8586: &start_data_table().&start_data_table_header_row().
1.144 matthew 8587: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8588: '<th>'.&mt('Column').'</th>'.
8589: &end_data_table_header_row()."\n");
1.356 albertel 8590: foreach my $array_ref (@$d) {
8591: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8592: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8593:
8594: $r->print('<td><select name=f'.$i.
1.32 matthew 8595: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8596: $r->print('<option value="none"></option>');
1.356 albertel 8597: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8598: $r->print('<option value="'.$sample.'"'.
8599: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8600: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8601: }
1.594 raeburn 8602: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8603: $i++;
8604: }
1.594 raeburn 8605: $r->print(&end_data_table());
1.31 albertel 8606: $i--;
8607: return $i;
8608: }
1.56 matthew 8609:
1.144 matthew 8610: ######################################################
8611: ######################################################
8612:
1.56 matthew 8613: =pod
1.31 albertel 8614:
1.648 raeburn 8615: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8616:
8617: Prints a table of sample values from the upload and can make associate samples to internal names.
8618:
8619: $r is an Apache Request ref,
8620: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8621: $d is an array of 2 element arrays (internal name, displayed name)
8622:
8623: =cut
8624:
1.144 matthew 8625: ######################################################
8626: ######################################################
1.31 albertel 8627: sub csv_samples_select_table {
8628: my ($r,$records,$d) = @_;
8629: my $i=0;
1.144 matthew 8630: #
1.662 bisitz 8631: my $max_samples = 5;
8632: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8633: $r->print(&start_data_table().
8634: &start_data_table_header_row().'<th>'.
8635: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8636: &end_data_table_header_row());
1.301 albertel 8637:
8638: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8639: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8640: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8641: foreach my $option (@$d) {
8642: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8643: $r->print('<option value="'.$value.'"'.
1.253 albertel 8644: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8645: $display.'</option>');
1.31 albertel 8646: }
8647: $r->print('</select></td><td>');
1.662 bisitz 8648: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8649: if (defined($samples->[$line]{$key})) {
8650: $r->print($samples->[$line]{$key}."<br />\n");
8651: }
8652: }
1.594 raeburn 8653: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8654: $i++;
8655: }
1.594 raeburn 8656: $r->print(&end_data_table());
1.31 albertel 8657: $i--;
8658: return($i);
1.115 matthew 8659: }
8660:
1.144 matthew 8661: ######################################################
8662: ######################################################
8663:
1.115 matthew 8664: =pod
8665:
1.648 raeburn 8666: =item * &clean_excel_name($name)
1.115 matthew 8667:
8668: Returns a replacement for $name which does not contain any illegal characters.
8669:
8670: =cut
8671:
1.144 matthew 8672: ######################################################
8673: ######################################################
1.115 matthew 8674: sub clean_excel_name {
8675: my ($name) = @_;
8676: $name =~ s/[:\*\?\/\\]//g;
8677: if (length($name) > 31) {
8678: $name = substr($name,0,31);
8679: }
8680: return $name;
1.25 albertel 8681: }
1.84 albertel 8682:
1.85 albertel 8683: =pod
8684:
1.648 raeburn 8685: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8686:
8687: Returns either 1 or undef
8688:
8689: 1 if the part is to be hidden, undef if it is to be shown
8690:
8691: Arguments are:
8692:
8693: $id the id of the part to be checked
8694: $symb, optional the symb of the resource to check
8695: $udom, optional the domain of the user to check for
8696: $uname, optional the username of the user to check for
8697:
8698: =cut
1.84 albertel 8699:
8700: sub check_if_partid_hidden {
8701: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8702: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8703: $symb,$udom,$uname);
1.141 albertel 8704: my $truth=1;
8705: #if the string starts with !, then the list is the list to show not hide
8706: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8707: my @hiddenlist=split(/,/,$hiddenparts);
8708: foreach my $checkid (@hiddenlist) {
1.141 albertel 8709: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8710: }
1.141 albertel 8711: return !$truth;
1.84 albertel 8712: }
1.127 matthew 8713:
1.138 matthew 8714:
8715: ############################################################
8716: ############################################################
8717:
8718: =pod
8719:
1.157 matthew 8720: =back
8721:
1.138 matthew 8722: =head1 cgi-bin script and graphing routines
8723:
1.157 matthew 8724: =over 4
8725:
1.648 raeburn 8726: =item * &get_cgi_id()
1.138 matthew 8727:
8728: Inputs: none
8729:
8730: Returns an id which can be used to pass environment variables
8731: to various cgi-bin scripts. These environment variables will
8732: be removed from the users environment after a given time by
8733: the routine &Apache::lonnet::transfer_profile_to_env.
8734:
8735: =cut
8736:
8737: ############################################################
8738: ############################################################
1.152 albertel 8739: my $uniq=0;
1.136 matthew 8740: sub get_cgi_id {
1.154 albertel 8741: $uniq=($uniq+1)%100000;
1.280 albertel 8742: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8743: }
8744:
1.127 matthew 8745: ############################################################
8746: ############################################################
8747:
8748: =pod
8749:
1.648 raeburn 8750: =item * &DrawBarGraph()
1.127 matthew 8751:
1.138 matthew 8752: Facilitates the plotting of data in a (stacked) bar graph.
8753: Puts plot definition data into the users environment in order for
8754: graph.png to plot it. Returns an <img> tag for the plot.
8755: The bars on the plot are labeled '1','2',...,'n'.
8756:
8757: Inputs:
8758:
8759: =over 4
8760:
8761: =item $Title: string, the title of the plot
8762:
8763: =item $xlabel: string, text describing the X-axis of the plot
8764:
8765: =item $ylabel: string, text describing the Y-axis of the plot
8766:
8767: =item $Max: scalar, the maximum Y value to use in the plot
8768: If $Max is < any data point, the graph will not be rendered.
8769:
1.140 matthew 8770: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8771: they are plotted. If undefined, default values will be used.
8772:
1.178 matthew 8773: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8774:
1.138 matthew 8775: =item @Values: An array of array references. Each array reference holds data
8776: to be plotted in a stacked bar chart.
8777:
1.239 matthew 8778: =item If the final element of @Values is a hash reference the key/value
8779: pairs will be added to the graph definition.
8780:
1.138 matthew 8781: =back
8782:
8783: Returns:
8784:
8785: An <img> tag which references graph.png and the appropriate identifying
8786: information for the plot.
8787:
1.127 matthew 8788: =cut
8789:
8790: ############################################################
8791: ############################################################
1.134 matthew 8792: sub DrawBarGraph {
1.178 matthew 8793: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8794: #
8795: if (! defined($colors)) {
8796: $colors = ['#33ff00',
8797: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8798: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8799: ];
8800: }
1.228 matthew 8801: my $extra_settings = {};
8802: if (ref($Values[-1]) eq 'HASH') {
8803: $extra_settings = pop(@Values);
8804: }
1.127 matthew 8805: #
1.136 matthew 8806: my $identifier = &get_cgi_id();
8807: my $id = 'cgi.'.$identifier;
1.129 matthew 8808: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8809: return '';
8810: }
1.225 matthew 8811: #
8812: my @Labels;
8813: if (defined($labels)) {
8814: @Labels = @$labels;
8815: } else {
8816: for (my $i=0;$i<@{$Values[0]};$i++) {
8817: push (@Labels,$i+1);
8818: }
8819: }
8820: #
1.129 matthew 8821: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8822: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8823: my %ValuesHash;
8824: my $NumSets=1;
8825: foreach my $array (@Values) {
8826: next if (! ref($array));
1.136 matthew 8827: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8828: join(',',@$array);
1.129 matthew 8829: }
1.127 matthew 8830: #
1.136 matthew 8831: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8832: if ($NumBars < 3) {
8833: $width = 120+$NumBars*32;
1.220 matthew 8834: $xskip = 1;
1.225 matthew 8835: $bar_width = 30;
8836: } elsif ($NumBars < 5) {
8837: $width = 120+$NumBars*20;
8838: $xskip = 1;
8839: $bar_width = 20;
1.220 matthew 8840: } elsif ($NumBars < 10) {
1.136 matthew 8841: $width = 120+$NumBars*15;
8842: $xskip = 1;
8843: $bar_width = 15;
8844: } elsif ($NumBars <= 25) {
8845: $width = 120+$NumBars*11;
8846: $xskip = 5;
8847: $bar_width = 8;
8848: } elsif ($NumBars <= 50) {
8849: $width = 120+$NumBars*8;
8850: $xskip = 5;
8851: $bar_width = 4;
8852: } else {
8853: $width = 120+$NumBars*8;
8854: $xskip = 5;
8855: $bar_width = 4;
8856: }
8857: #
1.137 matthew 8858: $Max = 1 if ($Max < 1);
8859: if ( int($Max) < $Max ) {
8860: $Max++;
8861: $Max = int($Max);
8862: }
1.127 matthew 8863: $Title = '' if (! defined($Title));
8864: $xlabel = '' if (! defined($xlabel));
8865: $ylabel = '' if (! defined($ylabel));
1.369 www 8866: $ValuesHash{$id.'.title'} = &escape($Title);
8867: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8868: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8869: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8870: $ValuesHash{$id.'.NumBars'} = $NumBars;
8871: $ValuesHash{$id.'.NumSets'} = $NumSets;
8872: $ValuesHash{$id.'.PlotType'} = 'bar';
8873: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8874: $ValuesHash{$id.'.height'} = $height;
8875: $ValuesHash{$id.'.width'} = $width;
8876: $ValuesHash{$id.'.xskip'} = $xskip;
8877: $ValuesHash{$id.'.bar_width'} = $bar_width;
8878: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8879: #
1.228 matthew 8880: # Deal with other parameters
8881: while (my ($key,$value) = each(%$extra_settings)) {
8882: $ValuesHash{$id.'.'.$key} = $value;
8883: }
8884: #
1.646 raeburn 8885: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8886: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8887: }
8888:
8889: ############################################################
8890: ############################################################
8891:
8892: =pod
8893:
1.648 raeburn 8894: =item * &DrawXYGraph()
1.137 matthew 8895:
1.138 matthew 8896: Facilitates the plotting of data in an XY graph.
8897: Puts plot definition data into the users environment in order for
8898: graph.png to plot it. Returns an <img> tag for the plot.
8899:
8900: Inputs:
8901:
8902: =over 4
8903:
8904: =item $Title: string, the title of the plot
8905:
8906: =item $xlabel: string, text describing the X-axis of the plot
8907:
8908: =item $ylabel: string, text describing the Y-axis of the plot
8909:
8910: =item $Max: scalar, the maximum Y value to use in the plot
8911: If $Max is < any data point, the graph will not be rendered.
8912:
8913: =item $colors: Array ref containing the hex color codes for the data to be
8914: plotted in. If undefined, default values will be used.
8915:
8916: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8917:
8918: =item $Ydata: Array ref containing Array refs.
1.185 www 8919: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8920:
8921: =item %Values: hash indicating or overriding any default values which are
8922: passed to graph.png.
8923: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8924:
8925: =back
8926:
8927: Returns:
8928:
8929: An <img> tag which references graph.png and the appropriate identifying
8930: information for the plot.
8931:
1.137 matthew 8932: =cut
8933:
8934: ############################################################
8935: ############################################################
8936: sub DrawXYGraph {
8937: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8938: #
8939: # Create the identifier for the graph
8940: my $identifier = &get_cgi_id();
8941: my $id = 'cgi.'.$identifier;
8942: #
8943: $Title = '' if (! defined($Title));
8944: $xlabel = '' if (! defined($xlabel));
8945: $ylabel = '' if (! defined($ylabel));
8946: my %ValuesHash =
8947: (
1.369 www 8948: $id.'.title' => &escape($Title),
8949: $id.'.xlabel' => &escape($xlabel),
8950: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8951: $id.'.y_max_value'=> $Max,
8952: $id.'.labels' => join(',',@$Xlabels),
8953: $id.'.PlotType' => 'XY',
8954: );
8955: #
8956: if (defined($colors) && ref($colors) eq 'ARRAY') {
8957: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8958: }
8959: #
8960: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8961: return '';
8962: }
8963: my $NumSets=1;
1.138 matthew 8964: foreach my $array (@{$Ydata}){
1.137 matthew 8965: next if (! ref($array));
8966: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8967: }
1.138 matthew 8968: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8969: #
8970: # Deal with other parameters
8971: while (my ($key,$value) = each(%Values)) {
8972: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8973: }
8974: #
1.646 raeburn 8975: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8976: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8977: }
8978:
8979: ############################################################
8980: ############################################################
8981:
8982: =pod
8983:
1.648 raeburn 8984: =item * &DrawXYYGraph()
1.138 matthew 8985:
8986: Facilitates the plotting of data in an XY graph with two Y axes.
8987: Puts plot definition data into the users environment in order for
8988: graph.png to plot it. Returns an <img> tag for the plot.
8989:
8990: Inputs:
8991:
8992: =over 4
8993:
8994: =item $Title: string, the title of the plot
8995:
8996: =item $xlabel: string, text describing the X-axis of the plot
8997:
8998: =item $ylabel: string, text describing the Y-axis of the plot
8999:
9000: =item $colors: Array ref containing the hex color codes for the data to be
9001: plotted in. If undefined, default values will be used.
9002:
9003: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9004:
9005: =item $Ydata1: The first data set
9006:
9007: =item $Min1: The minimum value of the left Y-axis
9008:
9009: =item $Max1: The maximum value of the left Y-axis
9010:
9011: =item $Ydata2: The second data set
9012:
9013: =item $Min2: The minimum value of the right Y-axis
9014:
9015: =item $Max2: The maximum value of the left Y-axis
9016:
9017: =item %Values: hash indicating or overriding any default values which are
9018: passed to graph.png.
9019: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9020:
9021: =back
9022:
9023: Returns:
9024:
9025: An <img> tag which references graph.png and the appropriate identifying
9026: information for the plot.
1.136 matthew 9027:
9028: =cut
9029:
9030: ############################################################
9031: ############################################################
1.137 matthew 9032: sub DrawXYYGraph {
9033: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9034: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9035: #
9036: # Create the identifier for the graph
9037: my $identifier = &get_cgi_id();
9038: my $id = 'cgi.'.$identifier;
9039: #
9040: $Title = '' if (! defined($Title));
9041: $xlabel = '' if (! defined($xlabel));
9042: $ylabel = '' if (! defined($ylabel));
9043: my %ValuesHash =
9044: (
1.369 www 9045: $id.'.title' => &escape($Title),
9046: $id.'.xlabel' => &escape($xlabel),
9047: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9048: $id.'.labels' => join(',',@$Xlabels),
9049: $id.'.PlotType' => 'XY',
9050: $id.'.NumSets' => 2,
1.137 matthew 9051: $id.'.two_axes' => 1,
9052: $id.'.y1_max_value' => $Max1,
9053: $id.'.y1_min_value' => $Min1,
9054: $id.'.y2_max_value' => $Max2,
9055: $id.'.y2_min_value' => $Min2,
1.136 matthew 9056: );
9057: #
1.137 matthew 9058: if (defined($colors) && ref($colors) eq 'ARRAY') {
9059: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9060: }
9061: #
9062: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9063: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9064: return '';
9065: }
9066: my $NumSets=1;
1.137 matthew 9067: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9068: next if (! ref($array));
9069: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9070: }
9071: #
9072: # Deal with other parameters
9073: while (my ($key,$value) = each(%Values)) {
9074: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9075: }
9076: #
1.646 raeburn 9077: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9078: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9079: }
9080:
9081: ############################################################
9082: ############################################################
9083:
9084: =pod
9085:
1.157 matthew 9086: =back
9087:
1.139 matthew 9088: =head1 Statistics helper routines?
9089:
9090: Bad place for them but what the hell.
9091:
1.157 matthew 9092: =over 4
9093:
1.648 raeburn 9094: =item * &chartlink()
1.139 matthew 9095:
9096: Returns a link to the chart for a specific student.
9097:
9098: Inputs:
9099:
9100: =over 4
9101:
9102: =item $linktext: The text of the link
9103:
9104: =item $sname: The students username
9105:
9106: =item $sdomain: The students domain
9107:
9108: =back
9109:
1.157 matthew 9110: =back
9111:
1.139 matthew 9112: =cut
9113:
9114: ############################################################
9115: ############################################################
9116: sub chartlink {
9117: my ($linktext, $sname, $sdomain) = @_;
9118: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9119: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9120: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9121: '">'.$linktext.'</a>';
1.153 matthew 9122: }
9123:
9124: #######################################################
9125: #######################################################
9126:
9127: =pod
9128:
9129: =head1 Course Environment Routines
1.157 matthew 9130:
9131: =over 4
1.153 matthew 9132:
1.648 raeburn 9133: =item * &restore_course_settings()
1.153 matthew 9134:
1.648 raeburn 9135: =item * &store_course_settings()
1.153 matthew 9136:
9137: Restores/Store indicated form parameters from the course environment.
9138: Will not overwrite existing values of the form parameters.
9139:
9140: Inputs:
9141: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9142:
9143: a hash ref describing the data to be stored. For example:
9144:
9145: %Save_Parameters = ('Status' => 'scalar',
9146: 'chartoutputmode' => 'scalar',
9147: 'chartoutputdata' => 'scalar',
9148: 'Section' => 'array',
1.373 raeburn 9149: 'Group' => 'array',
1.153 matthew 9150: 'StudentData' => 'array',
9151: 'Maps' => 'array');
9152:
9153: Returns: both routines return nothing
9154:
1.631 raeburn 9155: =back
9156:
1.153 matthew 9157: =cut
9158:
9159: #######################################################
9160: #######################################################
9161: sub store_course_settings {
1.496 albertel 9162: return &store_settings($env{'request.course.id'},@_);
9163: }
9164:
9165: sub store_settings {
1.153 matthew 9166: # save to the environment
9167: # appenv the same items, just to be safe
1.300 albertel 9168: my $udom = $env{'user.domain'};
9169: my $uname = $env{'user.name'};
1.496 albertel 9170: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9171: my %SaveHash;
9172: my %AppHash;
9173: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9174: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9175: my $envname = 'environment.'.$basename;
1.258 albertel 9176: if (exists($env{'form.'.$setting})) {
1.153 matthew 9177: # Save this value away
9178: if ($type eq 'scalar' &&
1.258 albertel 9179: (! exists($env{$envname}) ||
9180: $env{$envname} ne $env{'form.'.$setting})) {
9181: $SaveHash{$basename} = $env{'form.'.$setting};
9182: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9183: } elsif ($type eq 'array') {
9184: my $stored_form;
1.258 albertel 9185: if (ref($env{'form.'.$setting})) {
1.153 matthew 9186: $stored_form = join(',',
9187: map {
1.369 www 9188: &escape($_);
1.258 albertel 9189: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9190: } else {
9191: $stored_form =
1.369 www 9192: &escape($env{'form.'.$setting});
1.153 matthew 9193: }
9194: # Determine if the array contents are the same.
1.258 albertel 9195: if ($stored_form ne $env{$envname}) {
1.153 matthew 9196: $SaveHash{$basename} = $stored_form;
9197: $AppHash{$envname} = $stored_form;
9198: }
9199: }
9200: }
9201: }
9202: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9203: $udom,$uname);
1.153 matthew 9204: if ($put_result !~ /^(ok|delayed)/) {
9205: &Apache::lonnet::logthis('unable to save form parameters, '.
9206: 'got error:'.$put_result);
9207: }
9208: # Make sure these settings stick around in this session, too
1.646 raeburn 9209: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9210: return;
9211: }
9212:
9213: sub restore_course_settings {
1.499 albertel 9214: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9215: }
9216:
9217: sub restore_settings {
9218: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9219: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9220: next if (exists($env{'form.'.$setting}));
1.496 albertel 9221: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9222: '.'.$setting;
1.258 albertel 9223: if (exists($env{$envname})) {
1.153 matthew 9224: if ($type eq 'scalar') {
1.258 albertel 9225: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9226: } elsif ($type eq 'array') {
1.258 albertel 9227: $env{'form.'.$setting} = [
1.153 matthew 9228: map {
1.369 www 9229: &unescape($_);
1.258 albertel 9230: } split(',',$env{$envname})
1.153 matthew 9231: ];
9232: }
9233: }
9234: }
1.127 matthew 9235: }
9236:
1.618 raeburn 9237: #######################################################
9238: #######################################################
9239:
9240: =pod
9241:
9242: =head1 Domain E-mail Routines
9243:
9244: =over 4
9245:
1.648 raeburn 9246: =item * &build_recipient_list()
1.618 raeburn 9247:
1.766 raeburn 9248: Build recipient lists for four types of e-mail:
9249: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9250: (d) Help requests, generated by
9251: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9252:
9253: Inputs:
1.619 raeburn 9254: defmail (scalar - email address of default recipient),
1.618 raeburn 9255: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9256: defdom (domain for which to retrieve configuration settings),
9257: origmail (scalar - email address of recipient from loncapa.conf,
9258: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9259:
1.655 raeburn 9260: Returns: comma separated list of addresses to which to send e-mail.
9261:
9262: =back
1.618 raeburn 9263:
9264: =cut
9265:
9266: ############################################################
9267: ############################################################
9268: sub build_recipient_list {
1.619 raeburn 9269: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9270: my @recipients;
9271: my $otheremails;
9272: my %domconfig =
9273: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9274: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9275: if (exists($domconfig{'contacts'}{$mailing})) {
9276: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9277: my @contacts = ('adminemail','supportemail');
9278: foreach my $item (@contacts) {
9279: if ($domconfig{'contacts'}{$mailing}{$item}) {
9280: my $addr = $domconfig{'contacts'}{$item};
9281: if (!grep(/^\Q$addr\E$/,@recipients)) {
9282: push(@recipients,$addr);
9283: }
1.619 raeburn 9284: }
1.766 raeburn 9285: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9286: }
9287: }
1.766 raeburn 9288: } elsif ($origmail ne '') {
9289: push(@recipients,$origmail);
1.618 raeburn 9290: }
1.619 raeburn 9291: } elsif ($origmail ne '') {
9292: push(@recipients,$origmail);
1.618 raeburn 9293: }
1.688 raeburn 9294: if (defined($defmail)) {
9295: if ($defmail ne '') {
9296: push(@recipients,$defmail);
9297: }
1.618 raeburn 9298: }
9299: if ($otheremails) {
1.619 raeburn 9300: my @others;
9301: if ($otheremails =~ /,/) {
9302: @others = split(/,/,$otheremails);
1.618 raeburn 9303: } else {
1.619 raeburn 9304: push(@others,$otheremails);
9305: }
9306: foreach my $addr (@others) {
9307: if (!grep(/^\Q$addr\E$/,@recipients)) {
9308: push(@recipients,$addr);
9309: }
1.618 raeburn 9310: }
9311: }
1.619 raeburn 9312: my $recipientlist = join(',',@recipients);
1.618 raeburn 9313: return $recipientlist;
9314: }
9315:
1.127 matthew 9316: ############################################################
9317: ############################################################
1.154 albertel 9318:
1.655 raeburn 9319: =pod
9320:
9321: =head1 Course Catalog Routines
9322:
9323: =over 4
9324:
9325: =item * &gather_categories()
9326:
9327: Converts category definitions - keys of categories hash stored in
9328: coursecategories in configuration.db on the primary library server in a
9329: domain - to an array. Also generates javascript and idx hash used to
9330: generate Domain Coordinator interface for editing Course Categories.
9331:
9332: Inputs:
1.663 raeburn 9333:
1.655 raeburn 9334: categories (reference to hash of category definitions).
1.663 raeburn 9335:
1.655 raeburn 9336: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9337: categories and subcategories).
1.663 raeburn 9338:
1.655 raeburn 9339: idx (reference to hash of counters used in Domain Coordinator interface for
9340: editing Course Categories).
1.663 raeburn 9341:
1.655 raeburn 9342: jsarray (reference to array of categories used to create Javascript arrays for
9343: Domain Coordinator interface for editing Course Categories).
9344:
9345: Returns: nothing
9346:
9347: Side effects: populates cats, idx and jsarray.
9348:
9349: =cut
9350:
9351: sub gather_categories {
9352: my ($categories,$cats,$idx,$jsarray) = @_;
9353: my %counters;
9354: my $num = 0;
9355: foreach my $item (keys(%{$categories})) {
9356: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9357: if ($container eq '' && $depth == 0) {
9358: $cats->[$depth][$categories->{$item}] = $cat;
9359: } else {
9360: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9361: }
9362: my ($escitem,$tail) = split(/:/,$item,2);
9363: if ($counters{$tail} eq '') {
9364: $counters{$tail} = $num;
9365: $num ++;
9366: }
9367: if (ref($idx) eq 'HASH') {
9368: $idx->{$item} = $counters{$tail};
9369: }
9370: if (ref($jsarray) eq 'ARRAY') {
9371: push(@{$jsarray->[$counters{$tail}]},$item);
9372: }
9373: }
9374: return;
9375: }
9376:
9377: =pod
9378:
9379: =item * &extract_categories()
9380:
9381: Used to generate breadcrumb trails for course categories.
9382:
9383: Inputs:
1.663 raeburn 9384:
1.655 raeburn 9385: categories (reference to hash of category definitions).
1.663 raeburn 9386:
1.655 raeburn 9387: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9388: categories and subcategories).
1.663 raeburn 9389:
1.655 raeburn 9390: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9391:
1.655 raeburn 9392: allitems (reference to hash - key is category key
9393: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9394:
1.655 raeburn 9395: idx (reference to hash of counters used in Domain Coordinator interface for
9396: editing Course Categories).
1.663 raeburn 9397:
1.655 raeburn 9398: jsarray (reference to array of categories used to create Javascript arrays for
9399: Domain Coordinator interface for editing Course Categories).
9400:
1.665 raeburn 9401: subcats (reference to hash of arrays containing all subcategories within each
9402: category, -recursive)
9403:
1.655 raeburn 9404: Returns: nothing
9405:
9406: Side effects: populates trails and allitems hash references.
9407:
9408: =cut
9409:
9410: sub extract_categories {
1.665 raeburn 9411: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9412: if (ref($categories) eq 'HASH') {
9413: &gather_categories($categories,$cats,$idx,$jsarray);
9414: if (ref($cats->[0]) eq 'ARRAY') {
9415: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9416: my $name = $cats->[0][$i];
9417: my $item = &escape($name).'::0';
9418: my $trailstr;
9419: if ($name eq 'instcode') {
9420: $trailstr = &mt('Official courses (with institutional codes)');
9421: } else {
9422: $trailstr = $name;
9423: }
9424: if ($allitems->{$item} eq '') {
9425: push(@{$trails},$trailstr);
9426: $allitems->{$item} = scalar(@{$trails})-1;
9427: }
9428: my @parents = ($name);
9429: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9430: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9431: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9432: if (ref($subcats) eq 'HASH') {
9433: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9434: }
9435: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9436: }
9437: } else {
9438: if (ref($subcats) eq 'HASH') {
9439: $subcats->{$item} = [];
1.655 raeburn 9440: }
9441: }
9442: }
9443: }
9444: }
9445: return;
9446: }
9447:
9448: =pod
9449:
9450: =item *&recurse_categories()
9451:
9452: Recursively used to generate breadcrumb trails for course categories.
9453:
9454: Inputs:
1.663 raeburn 9455:
1.655 raeburn 9456: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9457: categories and subcategories).
1.663 raeburn 9458:
1.655 raeburn 9459: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9460:
9461: category (current course category, for which breadcrumb trail is being generated).
9462:
9463: trails (reference to array of breadcrumb trails for each category).
9464:
1.655 raeburn 9465: allitems (reference to hash - key is category key
9466: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9467:
1.655 raeburn 9468: parents (array containing containers directories for current category,
9469: back to top level).
9470:
9471: Returns: nothing
9472:
9473: Side effects: populates trails and allitems hash references
9474:
9475: =cut
9476:
9477: sub recurse_categories {
1.665 raeburn 9478: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9479: my $shallower = $depth - 1;
9480: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9481: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9482: my $name = $cats->[$depth]{$category}[$k];
9483: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9484: my $trailstr = join(' -> ',(@{$parents},$category));
9485: if ($allitems->{$item} eq '') {
9486: push(@{$trails},$trailstr);
9487: $allitems->{$item} = scalar(@{$trails})-1;
9488: }
9489: my $deeper = $depth+1;
9490: push(@{$parents},$category);
1.665 raeburn 9491: if (ref($subcats) eq 'HASH') {
9492: my $subcat = &escape($name).':'.$category.':'.$depth;
9493: for (my $j=@{$parents}; $j>=0; $j--) {
9494: my $higher;
9495: if ($j > 0) {
9496: $higher = &escape($parents->[$j]).':'.
9497: &escape($parents->[$j-1]).':'.$j;
9498: } else {
9499: $higher = &escape($parents->[$j]).'::'.$j;
9500: }
9501: push(@{$subcats->{$higher}},$subcat);
9502: }
9503: }
9504: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9505: $subcats);
1.655 raeburn 9506: pop(@{$parents});
9507: }
9508: } else {
9509: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9510: my $trailstr = join(' -> ',(@{$parents},$category));
9511: if ($allitems->{$item} eq '') {
9512: push(@{$trails},$trailstr);
9513: $allitems->{$item} = scalar(@{$trails})-1;
9514: }
9515: }
9516: return;
9517: }
9518:
1.663 raeburn 9519: =pod
9520:
9521: =item *&assign_categories_table()
9522:
9523: Create a datatable for display of hierarchical categories in a domain,
9524: with checkboxes to allow a course to be categorized.
9525:
9526: Inputs:
9527:
9528: cathash - reference to hash of categories defined for the domain (from
9529: configuration.db)
9530:
9531: currcat - scalar with an & separated list of categories assigned to a course.
9532:
9533: Returns: $output (markup to be displayed)
9534:
9535: =cut
9536:
9537: sub assign_categories_table {
9538: my ($cathash,$currcat) = @_;
9539: my $output;
9540: if (ref($cathash) eq 'HASH') {
9541: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9542: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9543: $maxdepth = scalar(@cats);
9544: if (@cats > 0) {
9545: my $itemcount = 0;
9546: if (ref($cats[0]) eq 'ARRAY') {
9547: $output = &Apache::loncommon::start_data_table();
9548: my @currcategories;
9549: if ($currcat ne '') {
9550: @currcategories = split('&',$currcat);
9551: }
9552: for (my $i=0; $i<@{$cats[0]}; $i++) {
9553: my $parent = $cats[0][$i];
9554: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9555: next if ($parent eq 'instcode');
9556: my $item = &escape($parent).'::0';
9557: my $checked = '';
9558: if (@currcategories > 0) {
9559: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9560: $checked = ' checked="checked"';
1.663 raeburn 9561: }
9562: }
1.675 raeburn 9563: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9564: '<input type="checkbox" name="usecategory" value="'.
9565: $item.'"'.$checked.' />'.$parent.'</span>'.
9566: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9567: my $depth = 1;
9568: push(@path,$parent);
9569: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9570: pop(@path);
9571: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9572: $itemcount ++;
9573: }
9574: $output .= &Apache::loncommon::end_data_table();
9575: }
9576: }
9577: }
9578: return $output;
9579: }
9580:
9581: =pod
9582:
9583: =item *&assign_category_rows()
9584:
9585: Create a datatable row for display of nested categories in a domain,
9586: with checkboxes to allow a course to be categorized,called recursively.
9587:
9588: Inputs:
9589:
9590: itemcount - track row number for alternating colors
9591:
9592: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9593: categories and subcategories.
9594:
9595: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9596:
9597: parent - parent of current category item
9598:
9599: path - Array containing all categories back up through the hierarchy from the
9600: current category to the top level.
9601:
9602: currcategories - reference to array of current categories assigned to the course
9603:
9604: Returns: $output (markup to be displayed).
9605:
9606: =cut
9607:
9608: sub assign_category_rows {
9609: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9610: my ($text,$name,$item,$chgstr);
9611: if (ref($cats) eq 'ARRAY') {
9612: my $maxdepth = scalar(@{$cats});
9613: if (ref($cats->[$depth]) eq 'HASH') {
9614: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9615: my $numchildren = @{$cats->[$depth]{$parent}};
9616: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9617: $text .= '<td><table class="LC_datatable">';
9618: for (my $j=0; $j<$numchildren; $j++) {
9619: $name = $cats->[$depth]{$parent}[$j];
9620: $item = &escape($name).':'.&escape($parent).':'.$depth;
9621: my $deeper = $depth+1;
9622: my $checked = '';
9623: if (ref($currcategories) eq 'ARRAY') {
9624: if (@{$currcategories} > 0) {
9625: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9626: $checked = ' checked="checked"';
1.663 raeburn 9627: }
9628: }
9629: }
1.664 raeburn 9630: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9631: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9632: $item.'"'.$checked.' />'.$name.'</label></span>'.
9633: '<input type="hidden" name="catname" value="'.$name.'" />'.
9634: '</td><td>';
1.663 raeburn 9635: if (ref($path) eq 'ARRAY') {
9636: push(@{$path},$name);
9637: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9638: pop(@{$path});
9639: }
9640: $text .= '</td></tr>';
9641: }
9642: $text .= '</table></td>';
9643: }
9644: }
9645: }
9646: return $text;
9647: }
9648:
1.655 raeburn 9649: ############################################################
9650: ############################################################
9651:
9652:
1.443 albertel 9653: sub commit_customrole {
1.664 raeburn 9654: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9655: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9656: ($start?', '.&mt('starting').' '.localtime($start):'').
9657: ($end?', ending '.localtime($end):'').': <b>'.
9658: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9659: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9660: '</b><br />';
9661: return $output;
9662: }
9663:
9664: sub commit_standardrole {
1.541 raeburn 9665: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9666: my ($output,$logmsg,$linefeed);
9667: if ($context eq 'auto') {
9668: $linefeed = "\n";
9669: } else {
9670: $linefeed = "<br />\n";
9671: }
1.443 albertel 9672: if ($three eq 'st') {
1.541 raeburn 9673: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9674: $one,$two,$sec,$context);
9675: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9676: ($result eq 'unknown_course') || ($result eq 'refused')) {
9677: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9678: } else {
1.541 raeburn 9679: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9680: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9681: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9682: if ($context eq 'auto') {
9683: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9684: } else {
9685: $output .= '<b>'.$result.'</b>'.$linefeed.
9686: &mt('Add to classlist').': <b>ok</b>';
9687: }
9688: $output .= $linefeed;
1.443 albertel 9689: }
9690: } else {
9691: $output = &mt('Assigning').' '.$three.' in '.$url.
9692: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9693: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9694: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9695: if ($context eq 'auto') {
9696: $output .= $result.$linefeed;
9697: } else {
9698: $output .= '<b>'.$result.'</b>'.$linefeed;
9699: }
1.443 albertel 9700: }
9701: return $output;
9702: }
9703:
9704: sub commit_studentrole {
1.541 raeburn 9705: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9706: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9707: if ($context eq 'auto') {
9708: $linefeed = "\n";
9709: } else {
9710: $linefeed = '<br />'."\n";
9711: }
1.443 albertel 9712: if (defined($one) && defined($two)) {
9713: my $cid=$one.'_'.$two;
9714: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9715: my $secchange = 0;
9716: my $expire_role_result;
9717: my $modify_section_result;
1.628 raeburn 9718: if ($oldsec ne '-1') {
9719: if ($oldsec ne $sec) {
1.443 albertel 9720: $secchange = 1;
1.628 raeburn 9721: my $now = time;
1.443 albertel 9722: my $uurl='/'.$cid;
9723: $uurl=~s/\_/\//g;
9724: if ($oldsec) {
9725: $uurl.='/'.$oldsec;
9726: }
1.626 raeburn 9727: $oldsecurl = $uurl;
1.628 raeburn 9728: $expire_role_result =
1.652 raeburn 9729: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9730: if ($env{'request.course.sec'} ne '') {
9731: if ($expire_role_result eq 'refused') {
9732: my @roles = ('st');
9733: my @statuses = ('previous');
9734: my @roledoms = ($one);
9735: my $withsec = 1;
9736: my %roleshash =
9737: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9738: \@statuses,\@roles,\@roledoms,$withsec);
9739: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9740: my ($oldstart,$oldend) =
9741: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9742: if ($oldend > 0 && $oldend <= $now) {
9743: $expire_role_result = 'ok';
9744: }
9745: }
9746: }
9747: }
1.443 albertel 9748: $result = $expire_role_result;
9749: }
9750: }
9751: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9752: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9753: if ($modify_section_result =~ /^ok/) {
9754: if ($secchange == 1) {
1.628 raeburn 9755: if ($sec eq '') {
9756: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9757: } else {
9758: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9759: }
1.443 albertel 9760: } elsif ($oldsec eq '-1') {
1.628 raeburn 9761: if ($sec eq '') {
9762: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9763: } else {
9764: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9765: }
1.443 albertel 9766: } else {
1.628 raeburn 9767: if ($sec eq '') {
9768: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9769: } else {
9770: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9771: }
1.443 albertel 9772: }
9773: } else {
1.628 raeburn 9774: if ($secchange) {
9775: $$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;
9776: } else {
9777: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9778: }
1.443 albertel 9779: }
9780: $result = $modify_section_result;
9781: } elsif ($secchange == 1) {
1.628 raeburn 9782: if ($oldsec eq '') {
9783: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9784: } else {
9785: $$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;
9786: }
1.626 raeburn 9787: if ($expire_role_result eq 'refused') {
9788: my $newsecurl = '/'.$cid;
9789: $newsecurl =~ s/\_/\//g;
9790: if ($sec ne '') {
9791: $newsecurl.='/'.$sec;
9792: }
9793: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9794: if ($sec eq '') {
9795: $$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;
9796: } else {
9797: $$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;
9798: }
9799: }
9800: }
1.443 albertel 9801: }
9802: } else {
1.626 raeburn 9803: $$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 9804: $result = "error: incomplete course id\n";
9805: }
9806: return $result;
9807: }
9808:
9809: ############################################################
9810: ############################################################
9811:
1.566 albertel 9812: sub check_clone {
1.578 raeburn 9813: my ($args,$linefeed) = @_;
1.566 albertel 9814: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9815: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9816: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9817: my $clonemsg;
9818: my $can_clone = 0;
9819:
9820: if ($clonehome eq 'no_host') {
1.578 raeburn 9821: $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 9822: } else {
9823: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9824: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9825: $can_clone = 1;
9826: } else {
9827: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9828: $args->{'clonedomain'},$args->{'clonecourse'});
9829: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9830: if (grep(/^\*$/,@cloners)) {
9831: $can_clone = 1;
9832: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9833: $can_clone = 1;
9834: } else {
9835: my %roleshash =
9836: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9837: $args->{'ccdomain'},
9838: 'userroles',['active'],['cc'],
9839: [$args->{'clonedomain'}]);
9840: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9841: $can_clone = 1;
9842: } else {
9843: $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'});
9844: }
1.566 albertel 9845: }
1.578 raeburn 9846: }
1.566 albertel 9847: }
9848: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9849: }
9850:
1.444 albertel 9851: sub construct_course {
1.541 raeburn 9852: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9853: my $outcome;
1.541 raeburn 9854: my $linefeed = '<br />'."\n";
9855: if ($context eq 'auto') {
9856: $linefeed = "\n";
9857: }
1.566 albertel 9858:
9859: #
9860: # Are we cloning?
9861: #
9862: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9863: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9864: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9865: if ($context ne 'auto') {
1.578 raeburn 9866: if ($clonemsg ne '') {
9867: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9868: }
1.566 albertel 9869: }
9870: $outcome .= $clonemsg.$linefeed;
9871:
9872: if (!$can_clone) {
9873: return (0,$outcome);
9874: }
9875: }
9876:
1.444 albertel 9877: #
9878: # Open course
9879: #
9880: my $crstype = lc($args->{'crstype'});
9881: my %cenv=();
9882: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9883: $args->{'cdescr'},
9884: $args->{'curl'},
9885: $args->{'course_home'},
9886: $args->{'nonstandard'},
9887: $args->{'crscode'},
9888: $args->{'ccuname'}.':'.
9889: $args->{'ccdomain'},
9890: $args->{'crstype'});
9891:
9892: # Note: The testing routines depend on this being output; see
9893: # Utils::Course. This needs to at least be output as a comment
9894: # if anyone ever decides to not show this, and Utils::Course::new
9895: # will need to be suitably modified.
1.541 raeburn 9896: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9897: #
9898: # Check if created correctly
9899: #
1.479 albertel 9900: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9901: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9902: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9903:
1.444 albertel 9904: #
1.566 albertel 9905: # Do the cloning
9906: #
9907: if ($can_clone && $cloneid) {
9908: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9909: if ($context ne 'auto') {
9910: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9911: }
9912: $outcome .= $clonemsg.$linefeed;
9913: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9914: # Copy all files
1.637 www 9915: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9916: # Restore URL
1.566 albertel 9917: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9918: # Restore title
1.566 albertel 9919: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9920: # Mark as cloned
1.566 albertel 9921: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9922: # Need to clone grading mode
9923: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9924: $cenv{'grading'}=$newenv{'grading'};
9925: # Do not clone these environment entries
9926: &Apache::lonnet::del('environment',
9927: ['default_enrollment_start_date',
9928: 'default_enrollment_end_date',
9929: 'question.email',
9930: 'policy.email',
9931: 'comment.email',
9932: 'pch.users.denied',
1.725 raeburn 9933: 'plc.users.denied',
9934: 'hidefromcat',
9935: 'categories'],
1.638 www 9936: $$crsudom,$$crsunum);
1.444 albertel 9937: }
1.566 albertel 9938:
1.444 albertel 9939: #
9940: # Set environment (will override cloned, if existing)
9941: #
9942: my @sections = ();
9943: my @xlists = ();
9944: if ($args->{'crstype'}) {
9945: $cenv{'type'}=$args->{'crstype'};
9946: }
9947: if ($args->{'crsid'}) {
9948: $cenv{'courseid'}=$args->{'crsid'};
9949: }
9950: if ($args->{'crscode'}) {
9951: $cenv{'internal.coursecode'}=$args->{'crscode'};
9952: }
9953: if ($args->{'crsquota'} ne '') {
9954: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9955: } else {
9956: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9957: }
9958: if ($args->{'ccuname'}) {
9959: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9960: ':'.$args->{'ccdomain'};
9961: } else {
9962: $cenv{'internal.courseowner'} = $args->{'curruser'};
9963: }
9964: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9965: if ($args->{'crssections'}) {
9966: $cenv{'internal.sectionnums'} = '';
9967: if ($args->{'crssections'} =~ m/,/) {
9968: @sections = split/,/,$args->{'crssections'};
9969: } else {
9970: $sections[0] = $args->{'crssections'};
9971: }
9972: if (@sections > 0) {
9973: foreach my $item (@sections) {
9974: my ($sec,$gp) = split/:/,$item;
9975: my $class = $args->{'crscode'}.$sec;
9976: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9977: $cenv{'internal.sectionnums'} .= $item.',';
9978: unless ($addcheck eq 'ok') {
9979: push @badclasses, $class;
9980: }
9981: }
9982: $cenv{'internal.sectionnums'} =~ s/,$//;
9983: }
9984: }
9985: # do not hide course coordinator from staff listing,
9986: # even if privileged
9987: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9988: # add crosslistings
9989: if ($args->{'crsxlist'}) {
9990: $cenv{'internal.crosslistings'}='';
9991: if ($args->{'crsxlist'} =~ m/,/) {
9992: @xlists = split/,/,$args->{'crsxlist'};
9993: } else {
9994: $xlists[0] = $args->{'crsxlist'};
9995: }
9996: if (@xlists > 0) {
9997: foreach my $item (@xlists) {
9998: my ($xl,$gp) = split/:/,$item;
9999: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10000: $cenv{'internal.crosslistings'} .= $item.',';
10001: unless ($addcheck eq 'ok') {
10002: push @badclasses, $xl;
10003: }
10004: }
10005: $cenv{'internal.crosslistings'} =~ s/,$//;
10006: }
10007: }
10008: if ($args->{'autoadds'}) {
10009: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10010: }
10011: if ($args->{'autodrops'}) {
10012: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10013: }
10014: # check for notification of enrollment changes
10015: my @notified = ();
10016: if ($args->{'notify_owner'}) {
10017: if ($args->{'ccuname'} ne '') {
10018: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10019: }
10020: }
10021: if ($args->{'notify_dc'}) {
10022: if ($uname ne '') {
1.630 raeburn 10023: push(@notified,$uname.':'.$udom);
1.444 albertel 10024: }
10025: }
10026: if (@notified > 0) {
10027: my $notifylist;
10028: if (@notified > 1) {
10029: $notifylist = join(',',@notified);
10030: } else {
10031: $notifylist = $notified[0];
10032: }
10033: $cenv{'internal.notifylist'} = $notifylist;
10034: }
10035: if (@badclasses > 0) {
10036: my %lt=&Apache::lonlocal::texthash(
10037: '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',
10038: 'dnhr' => 'does not have rights to access enrollment in these classes',
10039: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10040: );
1.541 raeburn 10041: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10042: ' ('.$lt{'adby'}.')';
10043: if ($context eq 'auto') {
10044: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10045: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10046: foreach my $item (@badclasses) {
10047: if ($context eq 'auto') {
10048: $outcome .= " - $item\n";
10049: } else {
10050: $outcome .= "<li>$item</li>\n";
10051: }
10052: }
10053: if ($context eq 'auto') {
10054: $outcome .= $linefeed;
10055: } else {
1.566 albertel 10056: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10057: }
10058: }
1.444 albertel 10059: }
10060: if ($args->{'no_end_date'}) {
10061: $args->{'endaccess'} = 0;
10062: }
10063: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10064: $cenv{'internal.autoend'}=$args->{'enrollend'};
10065: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10066: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10067: if ($args->{'showphotos'}) {
10068: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10069: }
10070: $cenv{'internal.authtype'} = $args->{'authtype'};
10071: $cenv{'internal.autharg'} = $args->{'autharg'};
10072: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10073: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10074: 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');
10075: if ($context eq 'auto') {
10076: $outcome .= $krb_msg;
10077: } else {
1.566 albertel 10078: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10079: }
10080: $outcome .= $linefeed;
1.444 albertel 10081: }
10082: }
10083: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10084: if ($args->{'setpolicy'}) {
10085: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10086: }
10087: if ($args->{'setcontent'}) {
10088: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10089: }
10090: }
10091: if ($args->{'reshome'}) {
10092: $cenv{'reshome'}=$args->{'reshome'}.'/';
10093: $cenv{'reshome'}=~s/\/+$/\//;
10094: }
10095: #
10096: # course has keyed access
10097: #
10098: if ($args->{'setkeys'}) {
10099: $cenv{'keyaccess'}='yes';
10100: }
10101: # if specified, key authority is not course, but user
10102: # only active if keyaccess is yes
10103: if ($args->{'keyauth'}) {
1.487 albertel 10104: my ($user,$domain) = split(':',$args->{'keyauth'});
10105: $user = &LONCAPA::clean_username($user);
10106: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10107: if ($user ne '' && $domain ne '') {
1.487 albertel 10108: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10109: }
10110: }
10111:
10112: if ($args->{'disresdis'}) {
10113: $cenv{'pch.roles.denied'}='st';
10114: }
10115: if ($args->{'disablechat'}) {
10116: $cenv{'plc.roles.denied'}='st';
10117: }
10118:
10119: # Record we've not yet viewed the Course Initialization Helper for this
10120: # course
10121: $cenv{'course.helper.not.run'} = 1;
10122: #
10123: # Use new Randomseed
10124: #
10125: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10126: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10127: #
10128: # The encryption code and receipt prefix for this course
10129: #
10130: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10131: $cenv{'internal.encpref'}=100+int(9*rand(99));
10132: #
10133: # By default, use standard grading
10134: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10135:
1.541 raeburn 10136: $outcome .= $linefeed.&mt('Setting environment').': '.
10137: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10138: #
10139: # Open all assignments
10140: #
10141: if ($args->{'openall'}) {
10142: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10143: my %storecontent = ($storeunder => time,
10144: $storeunder.'.type' => 'date_start');
10145:
10146: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10147: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10148: }
10149: #
10150: # Set first page
10151: #
10152: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10153: || ($cloneid)) {
1.445 albertel 10154: use LONCAPA::map;
1.444 albertel 10155: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10156:
10157: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10158: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10159:
1.444 albertel 10160: $outcome .= ($fatal?$errtext:'read ok').' - ';
10161: my $title; my $url;
10162: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10163: $title=&mt('Syllabus');
1.444 albertel 10164: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10165: } else {
1.690 bisitz 10166: $title=&mt('Navigate Contents');
1.444 albertel 10167: $url='/adm/navmaps';
10168: }
1.445 albertel 10169:
10170: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10171: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10172:
10173: if ($errtext) { $fatal=2; }
1.541 raeburn 10174: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10175: }
1.566 albertel 10176:
10177: return (1,$outcome);
1.444 albertel 10178: }
10179:
10180: ############################################################
10181: ############################################################
10182:
1.378 raeburn 10183: sub course_type {
10184: my ($cid) = @_;
10185: if (!defined($cid)) {
10186: $cid = $env{'request.course.id'};
10187: }
1.404 albertel 10188: if (defined($env{'course.'.$cid.'.type'})) {
10189: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10190: } else {
10191: return 'Course';
1.377 raeburn 10192: }
10193: }
1.156 albertel 10194:
1.406 raeburn 10195: sub group_term {
10196: my $crstype = &course_type();
10197: my %names = (
10198: 'Course' => 'group',
10199: 'Group' => 'team',
10200: );
10201: return $names{$crstype};
10202: }
10203:
1.156 albertel 10204: sub icon {
10205: my ($file)=@_;
1.505 albertel 10206: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10207: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10208: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10209: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10210: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10211: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10212: $curfext.".gif") {
10213: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10214: $curfext.".gif";
10215: }
10216: }
1.249 albertel 10217: return &lonhttpdurl($iconname);
1.154 albertel 10218: }
1.84 albertel 10219:
1.575 albertel 10220: sub lonhttpdurl {
1.692 www 10221: #
10222: # Had been used for "small fry" static images on separate port 8080.
10223: # Modify here if lightweight http functionality desired again.
10224: # Currently eliminated due to increasing firewall issues.
10225: #
1.575 albertel 10226: my ($url)=@_;
1.692 www 10227: return $url;
1.215 albertel 10228: }
10229:
1.213 albertel 10230: sub connection_aborted {
10231: my ($r)=@_;
10232: $r->print(" ");$r->rflush();
10233: my $c = $r->connection;
10234: return $c->aborted();
10235: }
10236:
1.221 foxr 10237: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10238: # strings as 'strings'.
10239: sub escape_single {
1.221 foxr 10240: my ($input) = @_;
1.223 albertel 10241: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10242: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10243: return $input;
10244: }
1.223 albertel 10245:
1.222 foxr 10246: # Same as escape_single, but escape's "'s This
10247: # can be used for "strings"
10248: sub escape_double {
10249: my ($input) = @_;
10250: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10251: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10252: return $input;
10253: }
1.223 albertel 10254:
1.222 foxr 10255: # Escapes the last element of a full URL.
10256: sub escape_url {
10257: my ($url) = @_;
1.238 raeburn 10258: my @urlslices = split(/\//, $url,-1);
1.369 www 10259: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10260: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10261: }
1.462 albertel 10262:
1.820 raeburn 10263: sub compare_arrays {
10264: my ($arrayref1,$arrayref2) = @_;
10265: my (@difference,%count);
10266: @difference = ();
10267: %count = ();
10268: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10269: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10270: foreach my $element (keys(%count)) {
10271: if ($count{$element} == 1) {
10272: push(@difference,$element);
10273: }
10274: }
10275: }
10276: return @difference;
10277: }
10278:
1.817 bisitz 10279: # -------------------------------------------------------- Initialize user login
1.462 albertel 10280: sub init_user_environment {
1.463 albertel 10281: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10282: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10283:
10284: my $public=($username eq 'public' && $domain eq 'public');
10285:
10286: # See if old ID present, if so, remove
10287:
10288: my ($filename,$cookie,$userroles);
10289: my $now=time;
10290:
10291: if ($public) {
10292: my $max_public=100;
10293: my $oldest;
10294: my $oldest_time=0;
10295: for(my $next=1;$next<=$max_public;$next++) {
10296: if (-e $lonids."/publicuser_$next.id") {
10297: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10298: if ($mtime<$oldest_time || !$oldest_time) {
10299: $oldest_time=$mtime;
10300: $oldest=$next;
10301: }
10302: } else {
10303: $cookie="publicuser_$next";
10304: last;
10305: }
10306: }
10307: if (!$cookie) { $cookie="publicuser_$oldest"; }
10308: } else {
1.463 albertel 10309: # if this isn't a robot, kill any existing non-robot sessions
10310: if (!$args->{'robot'}) {
10311: opendir(DIR,$lonids);
10312: while ($filename=readdir(DIR)) {
10313: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10314: unlink($lonids.'/'.$filename);
10315: }
1.462 albertel 10316: }
1.463 albertel 10317: closedir(DIR);
1.462 albertel 10318: }
10319: # Give them a new cookie
1.463 albertel 10320: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10321: : $now.$$.int(rand(10000)));
1.463 albertel 10322: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10323:
10324: # Initialize roles
10325:
10326: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10327: }
10328: # ------------------------------------ Check browser type and MathML capability
10329:
10330: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10331: $clientunicode,$clientos) = &decode_user_agent($r);
10332:
10333: # ------------------------------------------------------------- Get environment
10334:
10335: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10336: my ($tmp) = keys(%userenv);
10337: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10338: # default remote control to off
10339: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10340: } else {
10341: undef(%userenv);
10342: }
10343: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10344: $form->{'interface'}=$userenv{'interface'};
10345: }
10346: $env{'environment.remote'}=$userenv{'remote'};
10347: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10348:
10349: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10350: foreach my $option ('interface','localpath','localres') {
10351: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10352: }
10353: # --------------------------------------------------------- Write first profile
10354:
10355: {
10356: my %initial_env =
10357: ("user.name" => $username,
10358: "user.domain" => $domain,
10359: "user.home" => $authhost,
10360: "browser.type" => $clientbrowser,
10361: "browser.version" => $clientversion,
10362: "browser.mathml" => $clientmathml,
10363: "browser.unicode" => $clientunicode,
10364: "browser.os" => $clientos,
10365: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10366: "request.course.fn" => '',
10367: "request.course.uri" => '',
10368: "request.course.sec" => '',
10369: "request.role" => 'cm',
10370: "request.role.adv" => $env{'user.adv'},
10371: "request.host" => $ENV{'REMOTE_ADDR'},);
10372:
10373: if ($form->{'localpath'}) {
10374: $initial_env{"browser.localpath"} = $form->{'localpath'};
10375: $initial_env{"browser.localres"} = $form->{'localres'};
10376: }
10377:
10378: if ($public) {
10379: $initial_env{"environment.remote"} = "off";
10380: }
10381: if ($form->{'interface'}) {
10382: $form->{'interface'}=~s/\W//gs;
10383: $initial_env{"browser.interface"} = $form->{'interface'};
10384: $env{'browser.interface'}=$form->{'interface'};
10385: }
10386:
1.724 raeburn 10387: foreach my $tool ('aboutme','blog','portfolio') {
10388: $userenv{'availabletools.'.$tool} =
10389: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10390: }
10391:
1.765 raeburn 10392: foreach my $crstype ('official','unofficial') {
10393: $userenv{'canrequest.'.$crstype} =
10394: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10395: 'reload','requestcourses');
10396: }
10397:
1.462 albertel 10398: $env{'user.environment'} = "$lonids/$cookie.id";
10399:
10400: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10401: &GDBM_WRCREAT(),0640)) {
10402: &_add_to_env(\%disk_env,\%initial_env);
10403: &_add_to_env(\%disk_env,\%userenv,'environment.');
10404: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10405: if (ref($args->{'extra_env'})) {
10406: &_add_to_env(\%disk_env,$args->{'extra_env'});
10407: }
1.462 albertel 10408: untie(%disk_env);
10409: } else {
1.705 tempelho 10410: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10411: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10412: return 'error: '.$!;
10413: }
10414: }
10415: $env{'request.role'}='cm';
10416: $env{'request.role.adv'}=$env{'user.adv'};
10417: $env{'browser.type'}=$clientbrowser;
10418:
10419: return $cookie;
10420:
10421: }
10422:
10423: sub _add_to_env {
10424: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10425: if (ref($env_data) eq 'HASH') {
10426: while (my ($key,$value) = each(%$env_data)) {
10427: $idf->{$prefix.$key} = $value;
10428: $env{$prefix.$key} = $value;
10429: }
1.462 albertel 10430: }
10431: }
10432:
1.685 tempelho 10433: # --- Get the symbolic name of a problem and the url
10434: sub get_symb {
10435: my ($request,$silent) = @_;
1.726 raeburn 10436: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10437: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10438: if ($symb eq '') {
10439: if (!$silent) {
10440: $request->print("Unable to handle ambiguous references:$url:.");
10441: return ();
10442: }
10443: }
10444: &Apache::lonenc::check_decrypt(\$symb);
10445: return ($symb);
10446: }
10447:
10448: # --------------------------------------------------------------Get annotation
10449:
10450: sub get_annotation {
10451: my ($symb,$enc) = @_;
10452:
10453: my $key = $symb;
10454: if (!$enc) {
10455: $key =
10456: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10457: }
10458: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10459: return $annotation{$key};
10460: }
10461:
10462: sub clean_symb {
1.731 raeburn 10463: my ($symb,$delete_enc) = @_;
1.685 tempelho 10464:
10465: &Apache::lonenc::check_decrypt(\$symb);
10466: my $enc = $env{'request.enc'};
1.731 raeburn 10467: if ($delete_enc) {
1.730 raeburn 10468: delete($env{'request.enc'});
10469: }
1.685 tempelho 10470:
10471: return ($symb,$enc);
10472: }
1.462 albertel 10473:
1.41 ng 10474: =pod
10475:
10476: =back
10477:
1.112 bowersj2 10478: =cut
1.41 ng 10479:
1.112 bowersj2 10480: 1;
10481: __END__;
1.41 ng 10482:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>