Annotation of loncom/interface/loncommon.pm, revision 1.871
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.871 ! raeburn 4: # $Id: loncommon.pm,v 1.870 2009/07/27 20:35:40 tempelho Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.468 raeburn 485: my ($domainfilter,$sec_element,$formname)=@_;
1.865 raeburn 486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role');
1.468 raeburn 487: my $output = '
1.776 bisitz 488: <script type="text/javascript" language="JavaScript">
1.824 bisitz 489: // <![CDATA[
1.468 raeburn 490: var stdeditbrowser;'."\n";
491: $output .= <<"ENDSTDBRW";
1.377 raeburn 492: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 493: var url = '/adm/pickcourse?';
1.468 raeburn 494: var domainfilter = '';
495: var formid = getFormIdByName(formname);
496: if (formid > -1) {
497: var domid = getIndexByName(formid,udom);
498: if (domid > -1) {
499: if (document.forms[formid].elements[domid].type == 'select-one') {
500: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
501: }
502: if (document.forms[formid].elements[domid].type == 'hidden') {
503: domainfilter=document.forms[formid].elements[domid].value;
504: }
505: }
1.91 www 506: }
1.128 albertel 507: if (domainfilter != null) {
508: if (domainfilter != '') {
509: url += 'domainfilter='+domainfilter+'&';
510: }
511: }
1.91 www 512: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 513: '&cdomelement='+udom+
514: '&cnameelement='+desc;
1.468 raeburn 515: if (extra_element !=null && extra_element != '') {
1.594 raeburn 516: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 517: url += '&roleelement='+extra_element;
518: if (domainfilter == null || domainfilter == '') {
519: url += '&domainfilter='+extra_element;
520: }
1.234 raeburn 521: }
1.468 raeburn 522: else {
523: if (formname == 'portform') {
524: url += '&setroles='+extra_element;
1.800 raeburn 525: } else {
526: if (formname == 'rules') {
527: url += '&fixeddom='+extra_element;
528: }
1.468 raeburn 529: }
530: }
1.230 raeburn 531: }
1.293 raeburn 532: if (multflag !=null && multflag != '') {
533: url += '&multiple='+multflag;
534: }
1.865 raeburn 535: if (crstype == 'Course/Community') {
1.377 raeburn 536: if (formname == 'cu') {
537: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
538: if (crstype == "") {
539: alert("$crs_or_grp_alert");
540: return;
541: }
542: }
543: }
544: if (crstype !=null && crstype != '') {
545: url += '&type='+crstype;
546: }
1.102 www 547: var title = 'Course_Browser';
1.91 www 548: var options = 'scrollbars=1,resizable=1,menubar=0';
549: options += ',width=700,height=600';
550: stdeditbrowser = open(url,title,options,'1');
551: stdeditbrowser.focus();
552: }
1.468 raeburn 553:
554: function getFormIdByName(formname) {
555: for (var i=0;i<document.forms.length;i++) {
556: if (document.forms[i].name == formname) {
557: return i;
558: }
559: }
560: return -1;
561: }
562:
563: function getIndexByName(formid,item) {
564: for (var i=0;i<document.forms[formid].elements.length;i++) {
565: if (document.forms[formid].elements[i].name == item) {
566: return i;
567: }
568: }
569: return -1;
570: }
1.91 www 571: ENDSTDBRW
1.468 raeburn 572: if ($sec_element ne '') {
573: $output .= &setsec_javascript($sec_element,$formname);
574: }
575: $output .= '
1.824 bisitz 576: // ]]>
1.468 raeburn 577: </script>';
578: return $output;
579: }
580:
581: sub setsec_javascript {
582: my ($sec_element,$formname) = @_;
583: my $setsections = qq|
584: function setSect(sectionlist) {
1.629 raeburn 585: var sectionsArray = new Array();
586: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
587: sectionsArray = sectionlist.split(",");
588: }
1.468 raeburn 589: var numSections = sectionsArray.length;
590: document.$formname.$sec_element.length = 0;
591: if (numSections == 0) {
592: document.$formname.$sec_element.multiple=false;
593: document.$formname.$sec_element.size=1;
594: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
595: } else {
596: if (numSections == 1) {
597: document.$formname.$sec_element.multiple=false;
598: document.$formname.$sec_element.size=1;
599: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
600: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
601: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
602: } else {
603: for (var i=0; i<numSections; i++) {
604: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
605: }
606: document.$formname.$sec_element.multiple=true
607: if (numSections < 3) {
608: document.$formname.$sec_element.size=numSections;
609: } else {
610: document.$formname.$sec_element.size=3;
611: }
612: document.$formname.$sec_element.options[0].selected = false
613: }
614: }
1.91 www 615: }
1.468 raeburn 616: |;
617: return $setsections;
618: }
619:
1.91 www 620:
621: sub selectcourse_link {
1.377 raeburn 622: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.871 ! raeburn 623: my $linktext = &mt('Select Course');
! 624: if ($selecttype eq 'Community') {
! 625: $linktext = &mt('Select Community');
! 626: }
1.787 bisitz 627: return '<span class="LC_nobreak">'
628: ."<a href='"
629: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
630: .'","'.$udomele.'","'.$desc.'","'.$extra_element
631: .'","'.$multflag.'","'.$selecttype.'");'
1.871 ! raeburn 632: ."'>".$linktext.'</a>'
1.787 bisitz 633: .'</span>';
1.74 www 634: }
1.42 matthew 635:
1.653 raeburn 636: sub selectauthor_link {
637: my ($form,$udom)=@_;
638: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
639: &mt('Select Author').'</a>';
640: }
641:
1.273 raeburn 642: sub check_uncheck_jscript {
643: my $jscript = <<"ENDSCRT";
644: function checkAll(field) {
645: if (field.length > 0) {
646: for (i = 0; i < field.length; i++) {
647: field[i].checked = true ;
648: }
649: } else {
650: field.checked = true
651: }
652: }
653:
654: function uncheckAll(field) {
655: if (field.length > 0) {
656: for (i = 0; i < field.length; i++) {
657: field[i].checked = false ;
1.543 albertel 658: }
659: } else {
1.273 raeburn 660: field.checked = false ;
661: }
662: }
663: ENDSCRT
664: return $jscript;
665: }
666:
1.656 www 667: sub select_timezone {
1.659 raeburn 668: my ($name,$selected,$onchange,$includeempty)=@_;
669: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
670: if ($includeempty) {
671: $output .= '<option value=""';
672: if (($selected eq '') || ($selected eq 'local')) {
673: $output .= ' selected="selected" ';
674: }
675: $output .= '> </option>';
676: }
1.657 raeburn 677: my @timezones = DateTime::TimeZone->all_names;
678: foreach my $tzone (@timezones) {
679: $output.= '<option value="'.$tzone.'"';
680: if ($tzone eq $selected) {
681: $output.=' selected="selected"';
682: }
683: $output.=">$tzone</option>\n";
1.656 www 684: }
685: $output.="</select>";
686: return $output;
687: }
1.273 raeburn 688:
1.687 raeburn 689: sub select_datelocale {
690: my ($name,$selected,$onchange,$includeempty)=@_;
691: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
692: if ($includeempty) {
693: $output .= '<option value=""';
694: if ($selected eq '') {
695: $output .= ' selected="selected" ';
696: }
697: $output .= '> </option>';
698: }
699: my (@possibles,%locale_names);
700: my @locales = DateTime::Locale::Catalog::Locales;
701: foreach my $locale (@locales) {
702: if (ref($locale) eq 'HASH') {
703: my $id = $locale->{'id'};
704: if ($id ne '') {
705: my $en_terr = $locale->{'en_territory'};
706: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 707: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 708: if (grep(/^en$/,@languages) || !@languages) {
709: if ($en_terr ne '') {
710: $locale_names{$id} = '('.$en_terr.')';
711: } elsif ($native_terr ne '') {
712: $locale_names{$id} = $native_terr;
713: }
714: } else {
715: if ($native_terr ne '') {
716: $locale_names{$id} = $native_terr.' ';
717: } elsif ($en_terr ne '') {
718: $locale_names{$id} = '('.$en_terr.')';
719: }
720: }
721: push (@possibles,$id);
722: }
723: }
724: }
725: foreach my $item (sort(@possibles)) {
726: $output.= '<option value="'.$item.'"';
727: if ($item eq $selected) {
728: $output.=' selected="selected"';
729: }
730: $output.=">$item";
731: if ($locale_names{$item} ne '') {
732: $output.=" $locale_names{$item}</option>\n";
733: }
734: $output.="</option>\n";
735: }
736: $output.="</select>";
737: return $output;
738: }
739:
1.792 raeburn 740: sub select_language {
741: my ($name,$selected,$includeempty) = @_;
742: my %langchoices;
743: if ($includeempty) {
744: %langchoices = ('' => 'No language preference');
745: }
746: foreach my $id (&languageids()) {
747: my $code = &supportedlanguagecode($id);
748: if ($code) {
749: $langchoices{$code} = &plainlanguagedescription($id);
750: }
751: }
752: return &select_form($selected,$name,%langchoices);
753: }
754:
1.42 matthew 755: =pod
1.36 matthew 756:
1.648 raeburn 757: =item * &linked_select_forms(...)
1.36 matthew 758:
759: linked_select_forms returns a string containing a <script></script> block
760: and html for two <select> menus. The select menus will be linked in that
761: changing the value of the first menu will result in new values being placed
762: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 763: order unless a defined order is provided.
1.36 matthew 764:
765: linked_select_forms takes the following ordered inputs:
766:
767: =over 4
768:
1.112 bowersj2 769: =item * $formname, the name of the <form> tag
1.36 matthew 770:
1.112 bowersj2 771: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 772:
1.112 bowersj2 773: =item * $firstdefault, the default value for the first menu
1.36 matthew 774:
1.112 bowersj2 775: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 776:
1.112 bowersj2 777: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 778:
1.112 bowersj2 779: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 780:
1.609 raeburn 781: =item * $menuorder, the order of values in the first menu
782:
1.41 ng 783: =back
784:
1.36 matthew 785: Below is an example of such a hash. Only the 'text', 'default', and
786: 'select2' keys must appear as stated. keys(%menu) are the possible
787: values for the first select menu. The text that coincides with the
1.41 ng 788: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 789: and text for the second menu are given in the hash pointed to by
790: $menu{$choice1}->{'select2'}.
791:
1.112 bowersj2 792: my %menu = ( A1 => { text =>"Choice A1" ,
793: default => "B3",
794: select2 => {
795: B1 => "Choice B1",
796: B2 => "Choice B2",
797: B3 => "Choice B3",
798: B4 => "Choice B4"
1.609 raeburn 799: },
800: order => ['B4','B3','B1','B2'],
1.112 bowersj2 801: },
802: A2 => { text =>"Choice A2" ,
803: default => "C2",
804: select2 => {
805: C1 => "Choice C1",
806: C2 => "Choice C2",
807: C3 => "Choice C3"
1.609 raeburn 808: },
809: order => ['C2','C1','C3'],
1.112 bowersj2 810: },
811: A3 => { text =>"Choice A3" ,
812: default => "D6",
813: select2 => {
814: D1 => "Choice D1",
815: D2 => "Choice D2",
816: D3 => "Choice D3",
817: D4 => "Choice D4",
818: D5 => "Choice D5",
819: D6 => "Choice D6",
820: D7 => "Choice D7"
1.609 raeburn 821: },
822: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 823: }
824: );
1.36 matthew 825:
826: =cut
827:
828: sub linked_select_forms {
829: my ($formname,
830: $middletext,
831: $firstdefault,
832: $firstselectname,
833: $secondselectname,
1.609 raeburn 834: $hashref,
835: $menuorder,
1.36 matthew 836: ) = @_;
837: my $second = "document.$formname.$secondselectname";
838: my $first = "document.$formname.$firstselectname";
839: # output the javascript to do the changing
840: my $result = '';
1.776 bisitz 841: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 842: $result.="// <![CDATA[\n";
1.36 matthew 843: $result.="var select2data = new Object();\n";
844: $" = '","';
845: my $debug = '';
846: foreach my $s1 (sort(keys(%$hashref))) {
847: $result.="select2data.d_$s1 = new Object();\n";
848: $result.="select2data.d_$s1.def = new String('".
849: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 850: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 851: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 852: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
853: @s2values = @{$hashref->{$s1}->{'order'}};
854: }
1.36 matthew 855: $result.="\"@s2values\");\n";
856: $result.="select2data.d_$s1.texts = new Array(";
857: my @s2texts;
858: foreach my $value (@s2values) {
859: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
860: }
861: $result.="\"@s2texts\");\n";
862: }
863: $"=' ';
864: $result.= <<"END";
865:
866: function select1_changed() {
867: // Determine new choice
868: var newvalue = "d_" + $first.value;
869: // update select2
870: var values = select2data[newvalue].values;
871: var texts = select2data[newvalue].texts;
872: var select2def = select2data[newvalue].def;
873: var i;
874: // out with the old
875: for (i = 0; i < $second.options.length; i++) {
876: $second.options[i] = null;
877: }
878: // in with the nuclear
879: for (i=0;i<values.length; i++) {
880: $second.options[i] = new Option(values[i]);
1.143 matthew 881: $second.options[i].value = values[i];
1.36 matthew 882: $second.options[i].text = texts[i];
883: if (values[i] == select2def) {
884: $second.options[i].selected = true;
885: }
886: }
887: }
1.824 bisitz 888: // ]]>
1.36 matthew 889: </script>
890: END
891: # output the initial values for the selection lists
892: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 893: my @order = sort(keys(%{$hashref}));
894: if (ref($menuorder) eq 'ARRAY') {
895: @order = @{$menuorder};
896: }
897: foreach my $value (@order) {
1.36 matthew 898: $result.=" <option value=\"$value\" ";
1.253 albertel 899: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 900: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 901: }
902: $result .= "</select>\n";
903: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
904: $result .= $middletext;
905: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
906: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 907:
908: my @secondorder = sort(keys(%select2));
909: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
910: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
911: }
912: foreach my $value (@secondorder) {
1.36 matthew 913: $result.=" <option value=\"$value\" ";
1.253 albertel 914: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 915: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 916: }
917: $result .= "</select>\n";
918: # return $debug;
919: return $result;
920: } # end of sub linked_select_forms {
921:
1.45 matthew 922: =pod
1.44 bowersj2 923:
1.648 raeburn 924: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 925:
1.112 bowersj2 926: Returns a string corresponding to an HTML link to the given help
927: $topic, where $topic corresponds to the name of a .tex file in
928: /home/httpd/html/adm/help/tex, with underscores replaced by
929: spaces.
930:
931: $text will optionally be linked to the same topic, allowing you to
932: link text in addition to the graphic. If you do not want to link
933: text, but wish to specify one of the later parameters, pass an
934: empty string.
935:
936: $stayOnPage is a value that will be interpreted as a boolean. If true,
937: the link will not open a new window. If false, the link will open
938: a new window using Javascript. (Default is false.)
939:
940: $width and $height are optional numerical parameters that will
941: override the width and height of the popped up window, which may
942: be useful for certain help topics with big pictures included.
1.44 bowersj2 943:
944: =cut
945:
946: sub help_open_topic {
1.48 bowersj2 947: my ($topic, $text, $stayOnPage, $width, $height) = @_;
948: $text = "" if (not defined $text);
1.44 bowersj2 949: $stayOnPage = 0 if (not defined $stayOnPage);
950: $width = 350 if (not defined $width);
951: $height = 400 if (not defined $height);
952: my $filename = $topic;
953: $filename =~ s/ /_/g;
954:
1.48 bowersj2 955: my $template = "";
956: my $link;
1.572 banghart 957:
1.159 www 958: $topic=~s/\W/\_/g;
1.44 bowersj2 959:
1.572 banghart 960: if (!$stayOnPage) {
1.72 bowersj2 961: $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 962: } else {
1.48 bowersj2 963: $link = "/adm/help/${filename}.hlp";
964: }
965:
966: # Add the text
1.755 neumanie 967: if ($text ne "") {
1.763 bisitz 968: $template.='<span class="LC_help_open_topic">'
969: .'<a target="_top" href="'.$link.'">'
970: .$text.'</a>';
1.48 bowersj2 971: }
972:
1.763 bisitz 973: # (Always) Add the graphic
1.179 matthew 974: my $title = &mt('Online Help');
1.667 raeburn 975: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 976: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
977: .'<img src="'.$helpicon.'" border="0"'
978: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 979: .' title="'.$title.'"'
1.763 bisitz 980: .' /></a>';
981: if ($text ne "") {
982: $template.='</span>';
983: }
1.44 bowersj2 984: return $template;
985:
1.106 bowersj2 986: }
987:
988: # This is a quicky function for Latex cheatsheet editing, since it
989: # appears in at least four places
990: sub helpLatexCheatsheet {
1.732 raeburn 991: my ($topic,$text,$not_author) = @_;
992: my $out;
1.106 bowersj2 993: my $addOther = '';
1.732 raeburn 994: if ($topic) {
1.763 bisitz 995: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
996: undef, undef, 600).
997: '</span> ';
998: }
999: $out = '<span>' # Start cheatsheet
1000: .$addOther
1001: .'<span>'
1002: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1003: undef,undef,600)
1004: .'</span> <span>'
1005: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1006: undef,undef,600)
1007: .'</span>';
1.732 raeburn 1008: unless ($not_author) {
1.763 bisitz 1009: $out .= ' <span>'
1010: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1011: undef,undef,600)
1012: .'</span>';
1.732 raeburn 1013: }
1.763 bisitz 1014: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1015: return $out;
1.172 www 1016: }
1017:
1.430 albertel 1018: sub general_help {
1019: my $helptopic='Student_Intro';
1020: if ($env{'request.role'}=~/^(ca|au)/) {
1021: $helptopic='Authoring_Intro';
1022: } elsif ($env{'request.role'}=~/^cc/) {
1023: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1024: } elsif ($env{'request.role'}=~/^dc/) {
1025: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1026: }
1027: return $helptopic;
1028: }
1029:
1030: sub update_help_link {
1031: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1032: my $origurl = $ENV{'REQUEST_URI'};
1033: $origurl=~s|^/~|/priv/|;
1034: my $timestamp = time;
1035: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1036: $$datum = &escape($$datum);
1037: }
1038:
1039: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1040: my $output .= <<"ENDOUTPUT";
1041: <script type="text/javascript">
1.824 bisitz 1042: // <![CDATA[
1.430 albertel 1043: banner_link = '$banner_link';
1.824 bisitz 1044: // ]]>
1.430 albertel 1045: </script>
1046: ENDOUTPUT
1047: return $output;
1048: }
1049:
1050: # now just updates the help link and generates a blue icon
1.193 raeburn 1051: sub help_open_menu {
1.430 albertel 1052: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1053: = @_;
1.430 albertel 1054: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1055: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1056: # if environment.remote is on (using remote control UI)
1.798 tempelho 1057: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1058: $stayOnPage=1;
1.430 albertel 1059: }
1060: my $output;
1061: if ($component_help) {
1062: if (!$text) {
1063: $output=&help_open_topic($component_help,undef,$stayOnPage,
1064: $width,$height);
1065: } else {
1066: my $help_text;
1067: $help_text=&unescape($topic);
1068: $output='<table><tr><td>'.
1069: &help_open_topic($component_help,$help_text,$stayOnPage,
1070: $width,$height).'</td></tr></table>';
1071: }
1072: }
1073: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1074: return $output.$banner_link;
1075: }
1076:
1077: sub top_nav_help {
1078: my ($text) = @_;
1.436 albertel 1079: $text = &mt($text);
1.572 banghart 1080: my $stay_on_page =
1.798 tempelho 1081: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1082: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1083: : "javascript:helpMenu('open')";
1.572 banghart 1084: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1085:
1.201 raeburn 1086: my $title = &mt('Get help');
1.436 albertel 1087:
1088: return <<"END";
1089: $banner_link
1090: <a href="$link" title="$title">$text</a>
1091: END
1092: }
1093:
1094: sub help_menu_js {
1095: my ($text) = @_;
1096:
1097: my $stayOnPage =
1.798 tempelho 1098: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1099:
1100: my $width = 620;
1101: my $height = 600;
1.430 albertel 1102: my $helptopic=&general_help();
1103: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1104: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1105: my $start_page =
1106: &Apache::loncommon::start_page('Help Menu', undef,
1107: {'frameset' => 1,
1108: 'js_ready' => 1,
1109: 'add_entries' => {
1110: 'border' => '0',
1.579 raeburn 1111: 'rows' => "110,*",},});
1.331 albertel 1112: my $end_page =
1113: &Apache::loncommon::end_page({'frameset' => 1,
1114: 'js_ready' => 1,});
1115:
1.436 albertel 1116: my $template .= <<"ENDTEMPLATE";
1117: <script type="text/javascript">
1.253 albertel 1118: // <!-- BEGIN LON-CAPA Internal
1119: // <![CDATA[
1.430 albertel 1120: var banner_link = '';
1.243 raeburn 1121: function helpMenu(target) {
1122: var caller = this;
1123: if (target == 'open') {
1124: var newWindow = null;
1125: try {
1.262 albertel 1126: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1127: }
1128: catch(error) {
1129: writeHelp(caller);
1130: return;
1131: }
1132: if (newWindow) {
1133: caller = newWindow;
1134: }
1.193 raeburn 1135: }
1.243 raeburn 1136: writeHelp(caller);
1137: return;
1138: }
1139: function writeHelp(caller) {
1.430 albertel 1140: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1141: caller.document.close()
1142: caller.focus()
1.193 raeburn 1143: }
1.253 albertel 1144: // ]]>
1.219 albertel 1145: // END LON-CAPA Internal -->
1.436 albertel 1146: </script>
1.193 raeburn 1147: ENDTEMPLATE
1148: return $template;
1149: }
1150:
1.172 www 1151: sub help_open_bug {
1152: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1153: unless ($env{'user.adv'}) { return ''; }
1.172 www 1154: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1155: $text = "" if (not defined $text);
1156: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1157: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1158: $stayOnPage=1;
1159: }
1.184 albertel 1160: $width = 600 if (not defined $width);
1161: $height = 600 if (not defined $height);
1.172 www 1162:
1163: $topic=~s/\W+/\+/g;
1164: my $link='';
1165: my $template='';
1.379 albertel 1166: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1167: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1168: if (!$stayOnPage)
1169: {
1170: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1171: }
1172: else
1173: {
1174: $link = $url;
1175: }
1176: # Add the text
1177: if ($text ne "")
1178: {
1179: $template .=
1180: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1181: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1182: }
1183:
1184: # Add the graphic
1.179 matthew 1185: my $title = &mt('Report a Bug');
1.215 albertel 1186: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1187: $template .= <<"ENDTEMPLATE";
1.436 albertel 1188: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1189: ENDTEMPLATE
1190: if ($text ne '') { $template.='</td></tr></table>' };
1191: return $template;
1192:
1193: }
1194:
1195: sub help_open_faq {
1196: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1197: unless ($env{'user.adv'}) { return ''; }
1.172 www 1198: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1199: $text = "" if (not defined $text);
1200: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1201: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1202: $stayOnPage=1;
1203: }
1204: $width = 350 if (not defined $width);
1205: $height = 400 if (not defined $height);
1206:
1207: $topic=~s/\W+/\+/g;
1208: my $link='';
1209: my $template='';
1210: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1211: if (!$stayOnPage)
1212: {
1213: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1214: }
1215: else
1216: {
1217: $link = $url;
1218: }
1219:
1220: # Add the text
1221: if ($text ne "")
1222: {
1223: $template .=
1.173 www 1224: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1225: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1226: }
1227:
1228: # Add the graphic
1.179 matthew 1229: my $title = &mt('View the FAQ');
1.215 albertel 1230: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1231: $template .= <<"ENDTEMPLATE";
1.436 albertel 1232: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1233: ENDTEMPLATE
1234: if ($text ne '') { $template.='</td></tr></table>' };
1235: return $template;
1236:
1.44 bowersj2 1237: }
1.37 matthew 1238:
1.180 matthew 1239: ###############################################################
1240: ###############################################################
1241:
1.45 matthew 1242: =pod
1243:
1.648 raeburn 1244: =item * &change_content_javascript():
1.256 matthew 1245:
1246: This and the next function allow you to create small sections of an
1247: otherwise static HTML page that you can update on the fly with
1248: Javascript, even in Netscape 4.
1249:
1250: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1251: must be written to the HTML page once. It will prove the Javascript
1252: function "change(name, content)". Calling the change function with the
1253: name of the section
1254: you want to update, matching the name passed to C<changable_area>, and
1255: the new content you want to put in there, will put the content into
1256: that area.
1257:
1258: B<Note>: Netscape 4 only reserves enough space for the changable area
1259: to contain room for the original contents. You need to "make space"
1260: for whatever changes you wish to make, and be B<sure> to check your
1261: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1262: it's adequate for updating a one-line status display, but little more.
1263: This script will set the space to 100% width, so you only need to
1264: worry about height in Netscape 4.
1265:
1266: Modern browsers are much less limiting, and if you can commit to the
1267: user not using Netscape 4, this feature may be used freely with
1268: pretty much any HTML.
1269:
1270: =cut
1271:
1272: sub change_content_javascript {
1273: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1274: if ($env{'browser.type'} eq 'netscape' &&
1275: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1276: return (<<NETSCAPE4);
1277: function change(name, content) {
1278: doc = document.layers[name+"___escape"].layers[0].document;
1279: doc.open();
1280: doc.write(content);
1281: doc.close();
1282: }
1283: NETSCAPE4
1284: } else {
1285: # Otherwise, we need to use semi-standards-compliant code
1286: # (technically, "innerHTML" isn't standard but the equivalent
1287: # is really scary, and every useful browser supports it
1288: return (<<DOMBASED);
1289: function change(name, content) {
1290: element = document.getElementById(name);
1291: element.innerHTML = content;
1292: }
1293: DOMBASED
1294: }
1295: }
1296:
1297: =pod
1298:
1.648 raeburn 1299: =item * &changable_area($name,$origContent):
1.256 matthew 1300:
1301: This provides a "changable area" that can be modified on the fly via
1302: the Javascript code provided in C<change_content_javascript>. $name is
1303: the name you will use to reference the area later; do not repeat the
1304: same name on a given HTML page more then once. $origContent is what
1305: the area will originally contain, which can be left blank.
1306:
1307: =cut
1308:
1309: sub changable_area {
1310: my ($name, $origContent) = @_;
1311:
1.258 albertel 1312: if ($env{'browser.type'} eq 'netscape' &&
1313: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1314: # If this is netscape 4, we need to use the Layer tag
1315: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1316: } else {
1317: return "<span id='$name'>$origContent</span>";
1318: }
1319: }
1320:
1321: =pod
1322:
1.648 raeburn 1323: =item * &viewport_geometry_js
1.590 raeburn 1324:
1325: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1326:
1327: =cut
1328:
1329:
1330: sub viewport_geometry_js {
1331: return <<"GEOMETRY";
1332: var Geometry = {};
1333: function init_geometry() {
1334: if (Geometry.init) { return };
1335: Geometry.init=1;
1336: if (window.innerHeight) {
1337: Geometry.getViewportHeight = function() { return window.innerHeight; };
1338: Geometry.getViewportWidth = function() { return window.innerWidth; };
1339: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1340: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1341: }
1342: else if (document.documentElement && document.documentElement.clientHeight) {
1343: Geometry.getViewportHeight =
1344: function() { return document.documentElement.clientHeight; };
1345: Geometry.getViewportWidth =
1346: function() { return document.documentElement.clientWidth; };
1347:
1348: Geometry.getHorizontalScroll =
1349: function() { return document.documentElement.scrollLeft; };
1350: Geometry.getVerticalScroll =
1351: function() { return document.documentElement.scrollTop; };
1352: }
1353: else if (document.body.clientHeight) {
1354: Geometry.getViewportHeight =
1355: function() { return document.body.clientHeight; };
1356: Geometry.getViewportWidth =
1357: function() { return document.body.clientWidth; };
1358: Geometry.getHorizontalScroll =
1359: function() { return document.body.scrollLeft; };
1360: Geometry.getVerticalScroll =
1361: function() { return document.body.scrollTop; };
1362: }
1363: }
1364:
1365: GEOMETRY
1366: }
1367:
1368: =pod
1369:
1.648 raeburn 1370: =item * &viewport_size_js()
1.590 raeburn 1371:
1372: 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.
1373:
1374: =cut
1375:
1376: sub viewport_size_js {
1377: my $geometry = &viewport_geometry_js();
1378: return <<"DIMS";
1379:
1380: $geometry
1381:
1382: function getViewportDims(width,height) {
1383: init_geometry();
1384: width.value = Geometry.getViewportWidth();
1385: height.value = Geometry.getViewportHeight();
1386: return;
1387: }
1388:
1389: DIMS
1390: }
1391:
1392: =pod
1393:
1.648 raeburn 1394: =item * &resize_textarea_js()
1.565 albertel 1395:
1396: emits the needed javascript to resize a textarea to be as big as possible
1397:
1398: creates a function resize_textrea that takes two IDs first should be
1399: the id of the element to resize, second should be the id of a div that
1400: surrounds everything that comes after the textarea, this routine needs
1401: to be attached to the <body> for the onload and onresize events.
1402:
1.648 raeburn 1403: =back
1.565 albertel 1404:
1405: =cut
1406:
1407: sub resize_textarea_js {
1.590 raeburn 1408: my $geometry = &viewport_geometry_js();
1.565 albertel 1409: return <<"RESIZE";
1410: <script type="text/javascript">
1.824 bisitz 1411: // <![CDATA[
1.590 raeburn 1412: $geometry
1.565 albertel 1413:
1.588 albertel 1414: function getX(element) {
1415: var x = 0;
1416: while (element) {
1417: x += element.offsetLeft;
1418: element = element.offsetParent;
1419: }
1420: return x;
1421: }
1422: function getY(element) {
1423: var y = 0;
1424: while (element) {
1425: y += element.offsetTop;
1426: element = element.offsetParent;
1427: }
1428: return y;
1429: }
1430:
1431:
1.565 albertel 1432: function resize_textarea(textarea_id,bottom_id) {
1433: init_geometry();
1434: var textarea = document.getElementById(textarea_id);
1435: //alert(textarea);
1436:
1.588 albertel 1437: var textarea_top = getY(textarea);
1.565 albertel 1438: var textarea_height = textarea.offsetHeight;
1439: var bottom = document.getElementById(bottom_id);
1.588 albertel 1440: var bottom_top = getY(bottom);
1.565 albertel 1441: var bottom_height = bottom.offsetHeight;
1442: var window_height = Geometry.getViewportHeight();
1.588 albertel 1443: var fudge = 23;
1.565 albertel 1444: var new_height = window_height-fudge-textarea_top-bottom_height;
1445: if (new_height < 300) {
1446: new_height = 300;
1447: }
1448: textarea.style.height=new_height+'px';
1449: }
1.824 bisitz 1450: // ]]>
1.565 albertel 1451: </script>
1452: RESIZE
1453:
1454: }
1455:
1456: =pod
1457:
1.256 matthew 1458: =head1 Excel and CSV file utility routines
1459:
1460: =over 4
1461:
1462: =cut
1463:
1464: ###############################################################
1465: ###############################################################
1466:
1467: =pod
1468:
1.648 raeburn 1469: =item * &csv_translate($text)
1.37 matthew 1470:
1.185 www 1471: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1472: format.
1473:
1474: =cut
1475:
1.180 matthew 1476: ###############################################################
1477: ###############################################################
1.37 matthew 1478: sub csv_translate {
1479: my $text = shift;
1480: $text =~ s/\"/\"\"/g;
1.209 albertel 1481: $text =~ s/\n/ /g;
1.37 matthew 1482: return $text;
1483: }
1.180 matthew 1484:
1485: ###############################################################
1486: ###############################################################
1487:
1488: =pod
1489:
1.648 raeburn 1490: =item * &define_excel_formats()
1.180 matthew 1491:
1492: Define some commonly used Excel cell formats.
1493:
1494: Currently supported formats:
1495:
1496: =over 4
1497:
1498: =item header
1499:
1500: =item bold
1501:
1502: =item h1
1503:
1504: =item h2
1505:
1506: =item h3
1507:
1.256 matthew 1508: =item h4
1509:
1510: =item i
1511:
1.180 matthew 1512: =item date
1513:
1514: =back
1515:
1516: Inputs: $workbook
1517:
1518: Returns: $format, a hash reference.
1519:
1520: =cut
1521:
1522: ###############################################################
1523: ###############################################################
1524: sub define_excel_formats {
1525: my ($workbook) = @_;
1526: my $format;
1527: $format->{'header'} = $workbook->add_format(bold => 1,
1528: bottom => 1,
1529: align => 'center');
1530: $format->{'bold'} = $workbook->add_format(bold=>1);
1531: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1532: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1533: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1534: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1535: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1536: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1537: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1538: return $format;
1539: }
1540:
1541: ###############################################################
1542: ###############################################################
1.113 bowersj2 1543:
1544: =pod
1545:
1.648 raeburn 1546: =item * &create_workbook()
1.255 matthew 1547:
1548: Create an Excel worksheet. If it fails, output message on the
1549: request object and return undefs.
1550:
1551: Inputs: Apache request object
1552:
1553: Returns (undef) on failure,
1554: Excel worksheet object, scalar with filename, and formats
1555: from &Apache::loncommon::define_excel_formats on success
1556:
1557: =cut
1558:
1559: ###############################################################
1560: ###############################################################
1561: sub create_workbook {
1562: my ($r) = @_;
1563: #
1564: # Create the excel spreadsheet
1565: my $filename = '/prtspool/'.
1.258 albertel 1566: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1567: time.'_'.rand(1000000000).'.xls';
1568: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1569: if (! defined($workbook)) {
1570: $r->log_error("Error creating excel spreadsheet $filename: $!");
1571: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1572: "This error has been logged. ".
1573: "Please alert your LON-CAPA administrator").
1574: '</p>');
1575: return (undef);
1576: }
1577: #
1578: $workbook->set_tempdir('/home/httpd/perl/tmp');
1579: #
1580: my $format = &Apache::loncommon::define_excel_formats($workbook);
1581: return ($workbook,$filename,$format);
1582: }
1583:
1584: ###############################################################
1585: ###############################################################
1586:
1587: =pod
1588:
1.648 raeburn 1589: =item * &create_text_file()
1.113 bowersj2 1590:
1.542 raeburn 1591: Create a file to write to and eventually make available to the user.
1.256 matthew 1592: If file creation fails, outputs an error message on the request object and
1593: return undefs.
1.113 bowersj2 1594:
1.256 matthew 1595: Inputs: Apache request object, and file suffix
1.113 bowersj2 1596:
1.256 matthew 1597: Returns (undef) on failure,
1598: Filehandle and filename on success.
1.113 bowersj2 1599:
1600: =cut
1601:
1.256 matthew 1602: ###############################################################
1603: ###############################################################
1604: sub create_text_file {
1605: my ($r,$suffix) = @_;
1606: if (! defined($suffix)) { $suffix = 'txt'; };
1607: my $fh;
1608: my $filename = '/prtspool/'.
1.258 albertel 1609: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1610: time.'_'.rand(1000000000).'.'.$suffix;
1611: $fh = Apache::File->new('>/home/httpd'.$filename);
1612: if (! defined($fh)) {
1613: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1614: $r->print(&mt('Problems occurred in creating the output file. '
1615: .'This error has been logged. '
1616: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1617: }
1.256 matthew 1618: return ($fh,$filename)
1.113 bowersj2 1619: }
1620:
1621:
1.256 matthew 1622: =pod
1.113 bowersj2 1623:
1624: =back
1625:
1626: =cut
1.37 matthew 1627:
1628: ###############################################################
1.33 matthew 1629: ## Home server <option> list generating code ##
1630: ###############################################################
1.35 matthew 1631:
1.169 www 1632: # ------------------------------------------
1633:
1634: sub domain_select {
1635: my ($name,$value,$multiple)=@_;
1636: my %domains=map {
1.514 albertel 1637: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1638: } &Apache::lonnet::all_domains();
1.169 www 1639: if ($multiple) {
1640: $domains{''}=&mt('Any domain');
1.550 albertel 1641: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1642: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1643: } else {
1.550 albertel 1644: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1645: return &select_form($name,$value,%domains);
1646: }
1647: }
1648:
1.282 albertel 1649: #-------------------------------------------
1650:
1651: =pod
1652:
1.519 raeburn 1653: =head1 Routines for form select boxes
1654:
1655: =over 4
1656:
1.648 raeburn 1657: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1658:
1659: Returns a string containing a <select> element int multiple mode
1660:
1661:
1662: Args:
1663: $name - name of the <select> element
1.506 raeburn 1664: $value - scalar or array ref of values that should already be selected
1.282 albertel 1665: $size - number of rows long the select element is
1.283 albertel 1666: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1667: (shown text should already have been &mt())
1.506 raeburn 1668: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1669:
1.282 albertel 1670: =cut
1671:
1672: #-------------------------------------------
1.169 www 1673: sub multiple_select_form {
1.284 albertel 1674: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1675: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1676: my $output='';
1.191 matthew 1677: if (! defined($size)) {
1678: $size = 4;
1.283 albertel 1679: if (scalar(keys(%$hash))<4) {
1680: $size = scalar(keys(%$hash));
1.191 matthew 1681: }
1682: }
1.734 bisitz 1683: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1684: my @order;
1.506 raeburn 1685: if (ref($order) eq 'ARRAY') {
1686: @order = @{$order};
1687: } else {
1688: @order = sort(keys(%$hash));
1.501 banghart 1689: }
1690: if (exists($$hash{'select_form_order'})) {
1691: @order = @{$$hash{'select_form_order'}};
1692: }
1693:
1.284 albertel 1694: foreach my $key (@order) {
1.356 albertel 1695: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1696: $output.='selected="selected" ' if ($selected{$key});
1697: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1698: }
1699: $output.="</select>\n";
1700: return $output;
1701: }
1702:
1.88 www 1703: #-------------------------------------------
1704:
1705: =pod
1706:
1.648 raeburn 1707: =item * &select_form($defdom,$name,%hash)
1.88 www 1708:
1709: Returns a string containing a <select name='$name' size='1'> form to
1710: allow a user to select options from a hash option_name => displayed text.
1711: See lonrights.pm for an example invocation and use.
1712:
1713: =cut
1714:
1715: #-------------------------------------------
1716: sub select_form {
1717: my ($def,$name,%hash) = @_;
1718: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1719: my @keys;
1720: if (exists($hash{'select_form_order'})) {
1721: @keys=@{$hash{'select_form_order'}};
1722: } else {
1723: @keys=sort(keys(%hash));
1724: }
1.356 albertel 1725: foreach my $key (@keys) {
1726: $selectform.=
1727: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1728: ($key eq $def ? 'selected="selected" ' : '').
1729: ">".&mt($hash{$key})."</option>\n";
1.88 www 1730: }
1731: $selectform.="</select>";
1732: return $selectform;
1733: }
1734:
1.475 www 1735: # For display filters
1736:
1737: sub display_filter {
1738: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1739: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1740: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1741: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1742: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1743: '</label></span> <span class="LC_nobreak">'.
1.475 www 1744: &mt('Filter [_1]',
1.477 www 1745: &select_form($env{'form.displayfilter'},
1746: 'displayfilter',
1747: ('currentfolder' => 'Current folder/page',
1748: 'containing' => 'Containing phrase',
1749: 'none' => 'None'))).
1.714 bisitz 1750: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1751: }
1752:
1.167 www 1753: sub gradeleveldescription {
1754: my $gradelevel=shift;
1755: my %gradelevels=(0 => 'Not specified',
1756: 1 => 'Grade 1',
1757: 2 => 'Grade 2',
1758: 3 => 'Grade 3',
1759: 4 => 'Grade 4',
1760: 5 => 'Grade 5',
1761: 6 => 'Grade 6',
1762: 7 => 'Grade 7',
1763: 8 => 'Grade 8',
1764: 9 => 'Grade 9',
1765: 10 => 'Grade 10',
1766: 11 => 'Grade 11',
1767: 12 => 'Grade 12',
1768: 13 => 'Grade 13',
1769: 14 => '100 Level',
1770: 15 => '200 Level',
1771: 16 => '300 Level',
1772: 17 => '400 Level',
1773: 18 => 'Graduate Level');
1774: return &mt($gradelevels{$gradelevel});
1775: }
1776:
1.163 www 1777: sub select_level_form {
1778: my ($deflevel,$name)=@_;
1779: unless ($deflevel) { $deflevel=0; }
1.167 www 1780: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1781: for (my $i=0; $i<=18; $i++) {
1782: $selectform.="<option value=\"$i\" ".
1.253 albertel 1783: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1784: ">".&gradeleveldescription($i)."</option>\n";
1785: }
1786: $selectform.="</select>";
1787: return $selectform;
1.163 www 1788: }
1.167 www 1789:
1.35 matthew 1790: #-------------------------------------------
1791:
1.45 matthew 1792: =pod
1793:
1.743 raeburn 1794: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1795:
1796: Returns a string containing a <select name='$name' size='1'> form to
1797: allow a user to select the domain to preform an operation in.
1798: See loncreateuser.pm for an example invocation and use.
1799:
1.90 www 1800: If the $includeempty flag is set, it also includes an empty choice ("no domain
1801: selected");
1802:
1.743 raeburn 1803: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1804:
1805: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1806:
1.35 matthew 1807: =cut
1808:
1809: #-------------------------------------------
1.34 matthew 1810: sub select_dom_form {
1.743 raeburn 1811: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1812: my $onchange;
1813: if ($autosubmit) {
1814: $onchange = ' onchange="this.form.submit()"';
1815: }
1.550 albertel 1816: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1817: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1818: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1819: foreach my $dom (@domains) {
1820: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1821: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1822: if ($showdomdesc) {
1823: if ($dom ne '') {
1824: my $domdesc = &Apache::lonnet::domain($dom,'description');
1825: if ($domdesc ne '') {
1826: $selectdomain .= ' ('.$domdesc.')';
1827: }
1828: }
1829: }
1830: $selectdomain .= "</option>\n";
1.34 matthew 1831: }
1832: $selectdomain.="</select>";
1833: return $selectdomain;
1834: }
1835:
1.35 matthew 1836: #-------------------------------------------
1837:
1.45 matthew 1838: =pod
1839:
1.648 raeburn 1840: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1841:
1.586 raeburn 1842: input: 4 arguments (two required, two optional) -
1843: $domain - domain of new user
1844: $name - name of form element
1845: $default - Value of 'default' causes a default item to be first
1846: option, and selected by default.
1847: $hide - Value of 'hide' causes hiding of the name of the server,
1848: if 1 server found, or default, if 0 found.
1.594 raeburn 1849: output: returns 2 items:
1.586 raeburn 1850: (a) form element which contains either:
1851: (i) <select name="$name">
1852: <option value="$hostid1">$hostid $servers{$hostid}</option>
1853: <option value="$hostid2">$hostid $servers{$hostid}</option>
1854: </select>
1855: form item if there are multiple library servers in $domain, or
1856: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1857: if there is only one library server in $domain.
1858:
1859: (b) number of library servers found.
1860:
1861: See loncreateuser.pm for example of use.
1.35 matthew 1862:
1863: =cut
1864:
1865: #-------------------------------------------
1.586 raeburn 1866: sub home_server_form_item {
1867: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1868: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1869: my $result;
1870: my $numlib = keys(%servers);
1871: if ($numlib > 1) {
1872: $result .= '<select name="'.$name.'" />'."\n";
1873: if ($default) {
1.804 bisitz 1874: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1875: '</option>'."\n";
1876: }
1877: foreach my $hostid (sort(keys(%servers))) {
1878: $result.= '<option value="'.$hostid.'">'.
1879: $hostid.' '.$servers{$hostid}."</option>\n";
1880: }
1881: $result .= '</select>'."\n";
1882: } elsif ($numlib == 1) {
1883: my $hostid;
1884: foreach my $item (keys(%servers)) {
1885: $hostid = $item;
1886: }
1887: $result .= '<input type="hidden" name="'.$name.'" value="'.
1888: $hostid.'" />';
1889: if (!$hide) {
1890: $result .= $hostid.' '.$servers{$hostid};
1891: }
1892: $result .= "\n";
1893: } elsif ($default) {
1894: $result .= '<input type="hidden" name="'.$name.
1895: '" value="default" />';
1896: if (!$hide) {
1897: $result .= &mt('default');
1898: }
1899: $result .= "\n";
1.33 matthew 1900: }
1.586 raeburn 1901: return ($result,$numlib);
1.33 matthew 1902: }
1.112 bowersj2 1903:
1904: =pod
1905:
1.534 albertel 1906: =back
1907:
1.112 bowersj2 1908: =cut
1.87 matthew 1909:
1910: ###############################################################
1.112 bowersj2 1911: ## Decoding User Agent ##
1.87 matthew 1912: ###############################################################
1913:
1914: =pod
1915:
1.112 bowersj2 1916: =head1 Decoding the User Agent
1917:
1918: =over 4
1919:
1920: =item * &decode_user_agent()
1.87 matthew 1921:
1922: Inputs: $r
1923:
1924: Outputs:
1925:
1926: =over 4
1927:
1.112 bowersj2 1928: =item * $httpbrowser
1.87 matthew 1929:
1.112 bowersj2 1930: =item * $clientbrowser
1.87 matthew 1931:
1.112 bowersj2 1932: =item * $clientversion
1.87 matthew 1933:
1.112 bowersj2 1934: =item * $clientmathml
1.87 matthew 1935:
1.112 bowersj2 1936: =item * $clientunicode
1.87 matthew 1937:
1.112 bowersj2 1938: =item * $clientos
1.87 matthew 1939:
1940: =back
1941:
1.157 matthew 1942: =back
1943:
1.87 matthew 1944: =cut
1945:
1946: ###############################################################
1947: ###############################################################
1948: sub decode_user_agent {
1.247 albertel 1949: my ($r)=@_;
1.87 matthew 1950: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1951: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1952: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1953: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1954: my $clientbrowser='unknown';
1955: my $clientversion='0';
1956: my $clientmathml='';
1957: my $clientunicode='0';
1958: for (my $i=0;$i<=$#browsertype;$i++) {
1959: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1960: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1961: $clientbrowser=$bname;
1962: $httpbrowser=~/$vreg/i;
1963: $clientversion=$1;
1964: $clientmathml=($clientversion>=$minv);
1965: $clientunicode=($clientversion>=$univ);
1966: }
1967: }
1968: my $clientos='unknown';
1969: if (($httpbrowser=~/linux/i) ||
1970: ($httpbrowser=~/unix/i) ||
1971: ($httpbrowser=~/ux/i) ||
1972: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1973: if (($httpbrowser=~/vax/i) ||
1974: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1975: if ($httpbrowser=~/next/i) { $clientos='next'; }
1976: if (($httpbrowser=~/mac/i) ||
1977: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1978: if ($httpbrowser=~/win/i) { $clientos='win'; }
1979: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1980: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1981: $clientunicode,$clientos,);
1982: }
1983:
1.32 matthew 1984: ###############################################################
1985: ## Authentication changing form generation subroutines ##
1986: ###############################################################
1987: ##
1988: ## All of the authform_xxxxxxx subroutines take their inputs in a
1989: ## hash, and have reasonable default values.
1990: ##
1991: ## formname = the name given in the <form> tag.
1.35 matthew 1992: #-------------------------------------------
1993:
1.45 matthew 1994: =pod
1995:
1.112 bowersj2 1996: =head1 Authentication Routines
1997:
1998: =over 4
1999:
1.648 raeburn 2000: =item * &authform_xxxxxx()
1.35 matthew 2001:
2002: The authform_xxxxxx subroutines provide javascript and html forms which
2003: handle some of the conveniences required for authentication forms.
2004: This is not an optimal method, but it works.
2005:
2006: =over 4
2007:
1.112 bowersj2 2008: =item * authform_header
1.35 matthew 2009:
1.112 bowersj2 2010: =item * authform_authorwarning
1.35 matthew 2011:
1.112 bowersj2 2012: =item * authform_nochange
1.35 matthew 2013:
1.112 bowersj2 2014: =item * authform_kerberos
1.35 matthew 2015:
1.112 bowersj2 2016: =item * authform_internal
1.35 matthew 2017:
1.112 bowersj2 2018: =item * authform_filesystem
1.35 matthew 2019:
2020: =back
2021:
1.648 raeburn 2022: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2023:
1.35 matthew 2024: =cut
2025:
2026: #-------------------------------------------
1.32 matthew 2027: sub authform_header{
2028: my %in = (
2029: formname => 'cu',
1.80 albertel 2030: kerb_def_dom => '',
1.32 matthew 2031: @_,
2032: );
2033: $in{'formname'} = 'document.' . $in{'formname'};
2034: my $result='';
1.80 albertel 2035:
2036: #---------------------------------------------- Code for upper case translation
2037: my $Javascript_toUpperCase;
2038: unless ($in{kerb_def_dom}) {
2039: $Javascript_toUpperCase =<<"END";
2040: switch (choice) {
2041: case 'krb': currentform.elements[choicearg].value =
2042: currentform.elements[choicearg].value.toUpperCase();
2043: break;
2044: default:
2045: }
2046: END
2047: } else {
2048: $Javascript_toUpperCase = "";
2049: }
2050:
1.165 raeburn 2051: my $radioval = "'nochange'";
1.591 raeburn 2052: if (defined($in{'curr_authtype'})) {
2053: if ($in{'curr_authtype'} ne '') {
2054: $radioval = "'".$in{'curr_authtype'}."arg'";
2055: }
1.174 matthew 2056: }
1.165 raeburn 2057: my $argfield = 'null';
1.591 raeburn 2058: if (defined($in{'mode'})) {
1.165 raeburn 2059: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2060: if (defined($in{'curr_autharg'})) {
2061: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2062: $argfield = "'$in{'curr_autharg'}'";
2063: }
2064: }
2065: }
2066: }
2067:
1.32 matthew 2068: $result.=<<"END";
2069: var current = new Object();
1.165 raeburn 2070: current.radiovalue = $radioval;
2071: current.argfield = $argfield;
1.32 matthew 2072:
2073: function changed_radio(choice,currentform) {
2074: var choicearg = choice + 'arg';
2075: // If a radio button in changed, we need to change the argfield
2076: if (current.radiovalue != choice) {
2077: current.radiovalue = choice;
2078: if (current.argfield != null) {
2079: currentform.elements[current.argfield].value = '';
2080: }
2081: if (choice == 'nochange') {
2082: current.argfield = null;
2083: } else {
2084: current.argfield = choicearg;
2085: switch(choice) {
2086: case 'krb':
2087: currentform.elements[current.argfield].value =
2088: "$in{'kerb_def_dom'}";
2089: break;
2090: default:
2091: break;
2092: }
2093: }
2094: }
2095: return;
2096: }
1.22 www 2097:
1.32 matthew 2098: function changed_text(choice,currentform) {
2099: var choicearg = choice + 'arg';
2100: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2101: $Javascript_toUpperCase
1.32 matthew 2102: // clear old field
2103: if ((current.argfield != choicearg) && (current.argfield != null)) {
2104: currentform.elements[current.argfield].value = '';
2105: }
2106: current.argfield = choicearg;
2107: }
2108: set_auth_radio_buttons(choice,currentform);
2109: return;
1.20 www 2110: }
1.32 matthew 2111:
2112: function set_auth_radio_buttons(newvalue,currentform) {
2113: var i=0;
2114: while (i < currentform.login.length) {
2115: if (currentform.login[i].value == newvalue) { break; }
2116: i++;
2117: }
2118: if (i == currentform.login.length) {
2119: return;
2120: }
2121: current.radiovalue = newvalue;
2122: currentform.login[i].checked = true;
2123: return;
2124: }
2125: END
2126: return $result;
2127: }
2128:
2129: sub authform_authorwarning{
2130: my $result='';
1.144 matthew 2131: $result='<i>'.
2132: &mt('As a general rule, only authors or co-authors should be '.
2133: 'filesystem authenticated '.
2134: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2135: return $result;
2136: }
2137:
2138: sub authform_nochange{
2139: my %in = (
2140: formname => 'document.cu',
2141: kerb_def_dom => 'MSU.EDU',
2142: @_,
2143: );
1.586 raeburn 2144: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2145: my $result;
2146: if (keys(%can_assign) == 0) {
2147: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2148: } else {
2149: $result = '<label>'.&mt('[_1] Do not change login data',
2150: '<input type="radio" name="login" value="nochange" '.
2151: 'checked="checked" onclick="'.
1.281 albertel 2152: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2153: '</label>';
1.586 raeburn 2154: }
1.32 matthew 2155: return $result;
2156: }
2157:
1.591 raeburn 2158: sub authform_kerberos {
1.32 matthew 2159: my %in = (
2160: formname => 'document.cu',
2161: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2162: kerb_def_auth => 'krb4',
1.32 matthew 2163: @_,
2164: );
1.586 raeburn 2165: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2166: $autharg,$jscall);
2167: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2168: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2169: $check5 = ' checked="checked"';
1.80 albertel 2170: } else {
1.772 bisitz 2171: $check4 = ' checked="checked"';
1.80 albertel 2172: }
1.165 raeburn 2173: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2174: if (defined($in{'curr_authtype'})) {
2175: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2176: $krbcheck = ' checked="checked"';
1.623 raeburn 2177: if (defined($in{'mode'})) {
2178: if ($in{'mode'} eq 'modifyuser') {
2179: $krbcheck = '';
2180: }
2181: }
1.591 raeburn 2182: if (defined($in{'curr_kerb_ver'})) {
2183: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2184: $check5 = ' checked="checked"';
1.591 raeburn 2185: $check4 = '';
2186: } else {
1.772 bisitz 2187: $check4 = ' checked="checked"';
1.591 raeburn 2188: $check5 = '';
2189: }
1.586 raeburn 2190: }
1.591 raeburn 2191: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2192: $krbarg = $in{'curr_autharg'};
2193: }
1.586 raeburn 2194: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2195: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2196: $result =
2197: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2198: $in{'curr_autharg'},$krbver);
2199: } else {
2200: $result =
2201: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2202: }
2203: return $result;
2204: }
2205: }
2206: } else {
2207: if ($authnum == 1) {
1.784 bisitz 2208: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2209: }
2210: }
1.586 raeburn 2211: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2212: return;
1.587 raeburn 2213: } elsif ($authtype eq '') {
1.591 raeburn 2214: if (defined($in{'mode'})) {
1.587 raeburn 2215: if ($in{'mode'} eq 'modifycourse') {
2216: if ($authnum == 1) {
1.784 bisitz 2217: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2218: }
2219: }
2220: }
1.586 raeburn 2221: }
2222: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2223: if ($authtype eq '') {
2224: $authtype = '<input type="radio" name="login" value="krb" '.
2225: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2226: $krbcheck.' />';
2227: }
2228: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2229: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2230: $in{'curr_authtype'} eq 'krb5') ||
2231: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2232: $in{'curr_authtype'} eq 'krb4')) {
2233: $result .= &mt
1.144 matthew 2234: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2235: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2236: '<label>'.$authtype,
1.281 albertel 2237: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2238: 'value="'.$krbarg.'" '.
1.144 matthew 2239: 'onchange="'.$jscall.'" />',
1.281 albertel 2240: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2241: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2242: '</label>');
1.586 raeburn 2243: } elsif ($can_assign{'krb4'}) {
2244: $result .= &mt
2245: ('[_1] Kerberos authenticated with domain [_2] '.
2246: '[_3] Version 4 [_4]',
2247: '<label>'.$authtype,
2248: '</label><input type="text" size="10" name="krbarg" '.
2249: 'value="'.$krbarg.'" '.
2250: 'onchange="'.$jscall.'" />',
2251: '<label><input type="hidden" name="krbver" value="4" />',
2252: '</label>');
2253: } elsif ($can_assign{'krb5'}) {
2254: $result .= &mt
2255: ('[_1] Kerberos authenticated with domain [_2] '.
2256: '[_3] Version 5 [_4]',
2257: '<label>'.$authtype,
2258: '</label><input type="text" size="10" name="krbarg" '.
2259: 'value="'.$krbarg.'" '.
2260: 'onchange="'.$jscall.'" />',
2261: '<label><input type="hidden" name="krbver" value="5" />',
2262: '</label>');
2263: }
1.32 matthew 2264: return $result;
2265: }
2266:
2267: sub authform_internal{
1.586 raeburn 2268: my %in = (
1.32 matthew 2269: formname => 'document.cu',
2270: kerb_def_dom => 'MSU.EDU',
2271: @_,
2272: );
1.586 raeburn 2273: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2274: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2275: if (defined($in{'curr_authtype'})) {
2276: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2277: if ($can_assign{'int'}) {
1.772 bisitz 2278: $intcheck = 'checked="checked" ';
1.623 raeburn 2279: if (defined($in{'mode'})) {
2280: if ($in{'mode'} eq 'modifyuser') {
2281: $intcheck = '';
2282: }
2283: }
1.591 raeburn 2284: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2285: $intarg = $in{'curr_autharg'};
2286: }
2287: } else {
2288: $result = &mt('Currently internally authenticated.');
2289: return $result;
1.165 raeburn 2290: }
2291: }
1.586 raeburn 2292: } else {
2293: if ($authnum == 1) {
1.784 bisitz 2294: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2295: }
2296: }
2297: if (!$can_assign{'int'}) {
2298: return;
1.587 raeburn 2299: } elsif ($authtype eq '') {
1.591 raeburn 2300: if (defined($in{'mode'})) {
1.587 raeburn 2301: if ($in{'mode'} eq 'modifycourse') {
2302: if ($authnum == 1) {
1.784 bisitz 2303: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2304: }
2305: }
2306: }
1.165 raeburn 2307: }
1.586 raeburn 2308: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2309: if ($authtype eq '') {
2310: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2311: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2312: }
1.605 bisitz 2313: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2314: $intarg.'" onchange="'.$jscall.'" />';
2315: $result = &mt
1.144 matthew 2316: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2317: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2318: $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 2319: return $result;
2320: }
2321:
2322: sub authform_local{
2323: my %in = (
2324: formname => 'document.cu',
2325: kerb_def_dom => 'MSU.EDU',
2326: @_,
2327: );
1.586 raeburn 2328: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2329: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2330: if (defined($in{'curr_authtype'})) {
2331: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2332: if ($can_assign{'loc'}) {
1.772 bisitz 2333: $loccheck = 'checked="checked" ';
1.623 raeburn 2334: if (defined($in{'mode'})) {
2335: if ($in{'mode'} eq 'modifyuser') {
2336: $loccheck = '';
2337: }
2338: }
1.591 raeburn 2339: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2340: $locarg = $in{'curr_autharg'};
2341: }
2342: } else {
2343: $result = &mt('Currently using local (institutional) authentication.');
2344: return $result;
1.165 raeburn 2345: }
2346: }
1.586 raeburn 2347: } else {
2348: if ($authnum == 1) {
1.784 bisitz 2349: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2350: }
2351: }
2352: if (!$can_assign{'loc'}) {
2353: return;
1.587 raeburn 2354: } elsif ($authtype eq '') {
1.591 raeburn 2355: if (defined($in{'mode'})) {
1.587 raeburn 2356: if ($in{'mode'} eq 'modifycourse') {
2357: if ($authnum == 1) {
1.784 bisitz 2358: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2359: }
2360: }
2361: }
1.165 raeburn 2362: }
1.586 raeburn 2363: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2364: if ($authtype eq '') {
2365: $authtype = '<input type="radio" name="login" value="loc" '.
2366: $loccheck.' onchange="'.$jscall.'" onclick="'.
2367: $jscall.'" />';
2368: }
2369: $autharg = '<input type="text" size="10" name="locarg" value="'.
2370: $locarg.'" onchange="'.$jscall.'" />';
2371: $result = &mt('[_1] Local Authentication with argument [_2]',
2372: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2373: return $result;
2374: }
2375:
2376: sub authform_filesystem{
2377: my %in = (
2378: formname => 'document.cu',
2379: kerb_def_dom => 'MSU.EDU',
2380: @_,
2381: );
1.586 raeburn 2382: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2383: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2384: if (defined($in{'curr_authtype'})) {
2385: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2386: if ($can_assign{'fsys'}) {
1.772 bisitz 2387: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2388: if (defined($in{'mode'})) {
2389: if ($in{'mode'} eq 'modifyuser') {
2390: $fsyscheck = '';
2391: }
2392: }
1.586 raeburn 2393: } else {
2394: $result = &mt('Currently Filesystem Authenticated.');
2395: return $result;
2396: }
2397: }
2398: } else {
2399: if ($authnum == 1) {
1.784 bisitz 2400: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2401: }
2402: }
2403: if (!$can_assign{'fsys'}) {
2404: return;
1.587 raeburn 2405: } elsif ($authtype eq '') {
1.591 raeburn 2406: if (defined($in{'mode'})) {
1.587 raeburn 2407: if ($in{'mode'} eq 'modifycourse') {
2408: if ($authnum == 1) {
1.784 bisitz 2409: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2410: }
2411: }
2412: }
1.586 raeburn 2413: }
2414: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2415: if ($authtype eq '') {
2416: $authtype = '<input type="radio" name="login" value="fsys" '.
2417: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2418: $jscall.'" />';
2419: }
2420: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2421: ' onchange="'.$jscall.'" />';
2422: $result = &mt
1.144 matthew 2423: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2424: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2425: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2426: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2427: 'onchange="'.$jscall.'" />');
1.32 matthew 2428: return $result;
2429: }
2430:
1.586 raeburn 2431: sub get_assignable_auth {
2432: my ($dom) = @_;
2433: if ($dom eq '') {
2434: $dom = $env{'request.role.domain'};
2435: }
2436: my %can_assign = (
2437: krb4 => 1,
2438: krb5 => 1,
2439: int => 1,
2440: loc => 1,
2441: );
2442: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2443: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2444: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2445: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2446: my $context;
2447: if ($env{'request.role'} =~ /^au/) {
2448: $context = 'author';
2449: } elsif ($env{'request.role'} =~ /^dc/) {
2450: $context = 'domain';
2451: } elsif ($env{'request.course.id'}) {
2452: $context = 'course';
2453: }
2454: if ($context) {
2455: if (ref($authhash->{$context}) eq 'HASH') {
2456: %can_assign = %{$authhash->{$context}};
2457: }
2458: }
2459: }
2460: }
2461: my $authnum = 0;
2462: foreach my $key (keys(%can_assign)) {
2463: if ($can_assign{$key}) {
2464: $authnum ++;
2465: }
2466: }
2467: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2468: $authnum --;
2469: }
2470: return ($authnum,%can_assign);
2471: }
2472:
1.80 albertel 2473: ###############################################################
2474: ## Get Kerberos Defaults for Domain ##
2475: ###############################################################
2476: ##
2477: ## Returns default kerberos version and an associated argument
2478: ## as listed in file domain.tab. If not listed, provides
2479: ## appropriate default domain and kerberos version.
2480: ##
2481: #-------------------------------------------
2482:
2483: =pod
2484:
1.648 raeburn 2485: =item * &get_kerberos_defaults()
1.80 albertel 2486:
2487: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2488: version and domain. If not found, it defaults to version 4 and the
2489: domain of the server.
1.80 albertel 2490:
1.648 raeburn 2491: =over 4
2492:
1.80 albertel 2493: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2494:
1.648 raeburn 2495: =back
2496:
2497: =back
2498:
1.80 albertel 2499: =cut
2500:
2501: #-------------------------------------------
2502: sub get_kerberos_defaults {
2503: my $domain=shift;
1.641 raeburn 2504: my ($krbdef,$krbdefdom);
2505: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2506: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2507: $krbdef = $domdefaults{'auth_def'};
2508: $krbdefdom = $domdefaults{'auth_arg_def'};
2509: } else {
1.80 albertel 2510: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2511: my $krbdefdom=$1;
2512: $krbdefdom=~tr/a-z/A-Z/;
2513: $krbdef = "krb4";
2514: }
2515: return ($krbdef,$krbdefdom);
2516: }
1.112 bowersj2 2517:
1.32 matthew 2518:
1.46 matthew 2519: ###############################################################
2520: ## Thesaurus Functions ##
2521: ###############################################################
1.20 www 2522:
1.46 matthew 2523: =pod
1.20 www 2524:
1.112 bowersj2 2525: =head1 Thesaurus Functions
2526:
2527: =over 4
2528:
1.648 raeburn 2529: =item * &initialize_keywords()
1.46 matthew 2530:
2531: Initializes the package variable %Keywords if it is empty. Uses the
2532: package variable $thesaurus_db_file.
2533:
2534: =cut
2535:
2536: ###################################################
2537:
2538: sub initialize_keywords {
2539: return 1 if (scalar keys(%Keywords));
2540: # If we are here, %Keywords is empty, so fill it up
2541: # Make sure the file we need exists...
2542: if (! -e $thesaurus_db_file) {
2543: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2544: " failed because it does not exist");
2545: return 0;
2546: }
2547: # Set up the hash as a database
2548: my %thesaurus_db;
2549: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2550: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2551: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2552: $thesaurus_db_file);
2553: return 0;
2554: }
2555: # Get the average number of appearances of a word.
2556: my $avecount = $thesaurus_db{'average.count'};
2557: # Put keywords (those that appear > average) into %Keywords
2558: while (my ($word,$data)=each (%thesaurus_db)) {
2559: my ($count,undef) = split /:/,$data;
2560: $Keywords{$word}++ if ($count > $avecount);
2561: }
2562: untie %thesaurus_db;
2563: # Remove special values from %Keywords.
1.356 albertel 2564: foreach my $value ('total.count','average.count') {
2565: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2566: }
1.46 matthew 2567: return 1;
2568: }
2569:
2570: ###################################################
2571:
2572: =pod
2573:
1.648 raeburn 2574: =item * &keyword($word)
1.46 matthew 2575:
2576: Returns true if $word is a keyword. A keyword is a word that appears more
2577: than the average number of times in the thesaurus database. Calls
2578: &initialize_keywords
2579:
2580: =cut
2581:
2582: ###################################################
1.20 www 2583:
2584: sub keyword {
1.46 matthew 2585: return if (!&initialize_keywords());
2586: my $word=lc(shift());
2587: $word=~s/\W//g;
2588: return exists($Keywords{$word});
1.20 www 2589: }
1.46 matthew 2590:
2591: ###############################################################
2592:
2593: =pod
1.20 www 2594:
1.648 raeburn 2595: =item * &get_related_words()
1.46 matthew 2596:
1.160 matthew 2597: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2598: an array of words. If the keyword is not in the thesaurus, an empty array
2599: will be returned. The order of the words returned is determined by the
2600: database which holds them.
2601:
2602: Uses global $thesaurus_db_file.
2603:
2604: =cut
2605:
2606: ###############################################################
2607: sub get_related_words {
2608: my $keyword = shift;
2609: my %thesaurus_db;
2610: if (! -e $thesaurus_db_file) {
2611: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2612: "failed because the file does not exist");
2613: return ();
2614: }
2615: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2616: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2617: return ();
2618: }
2619: my @Words=();
1.429 www 2620: my $count=0;
1.46 matthew 2621: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2622: # The first element is the number of times
2623: # the word appears. We do not need it now.
1.429 www 2624: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2625: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2626: my $threshold=$mostfrequentcount/10;
2627: foreach my $possibleword (@RelatedWords) {
2628: my ($word,$wordcount)=split(/\,/,$possibleword);
2629: if ($wordcount>$threshold) {
2630: push(@Words,$word);
2631: $count++;
2632: if ($count>10) { last; }
2633: }
1.20 www 2634: }
2635: }
1.46 matthew 2636: untie %thesaurus_db;
2637: return @Words;
1.14 harris41 2638: }
1.46 matthew 2639:
1.112 bowersj2 2640: =pod
2641:
2642: =back
2643:
2644: =cut
1.61 www 2645:
2646: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2647: =pod
2648:
1.112 bowersj2 2649: =head1 User Name Functions
2650:
2651: =over 4
2652:
1.648 raeburn 2653: =item * &plainname($uname,$udom,$first)
1.81 albertel 2654:
1.112 bowersj2 2655: Takes a users logon name and returns it as a string in
1.226 albertel 2656: "first middle last generation" form
2657: if $first is set to 'lastname' then it returns it as
2658: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2659:
2660: =cut
1.61 www 2661:
1.295 www 2662:
1.81 albertel 2663: ###############################################################
1.61 www 2664: sub plainname {
1.226 albertel 2665: my ($uname,$udom,$first)=@_;
1.537 albertel 2666: return if (!defined($uname) || !defined($udom));
1.295 www 2667: my %names=&getnames($uname,$udom);
1.226 albertel 2668: my $name=&Apache::lonnet::format_name($names{'firstname'},
2669: $names{'middlename'},
2670: $names{'lastname'},
2671: $names{'generation'},$first);
2672: $name=~s/^\s+//;
1.62 www 2673: $name=~s/\s+$//;
2674: $name=~s/\s+/ /g;
1.353 albertel 2675: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2676: return $name;
1.61 www 2677: }
1.66 www 2678:
2679: # -------------------------------------------------------------------- Nickname
1.81 albertel 2680: =pod
2681:
1.648 raeburn 2682: =item * &nickname($uname,$udom)
1.81 albertel 2683:
2684: Gets a users name and returns it as a string as
2685:
2686: ""nickname""
1.66 www 2687:
1.81 albertel 2688: if the user has a nickname or
2689:
2690: "first middle last generation"
2691:
2692: if the user does not
2693:
2694: =cut
1.66 www 2695:
2696: sub nickname {
2697: my ($uname,$udom)=@_;
1.537 albertel 2698: return if (!defined($uname) || !defined($udom));
1.295 www 2699: my %names=&getnames($uname,$udom);
1.68 albertel 2700: my $name=$names{'nickname'};
1.66 www 2701: if ($name) {
2702: $name='"'.$name.'"';
2703: } else {
2704: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2705: $names{'lastname'}.' '.$names{'generation'};
2706: $name=~s/\s+$//;
2707: $name=~s/\s+/ /g;
2708: }
2709: return $name;
2710: }
2711:
1.295 www 2712: sub getnames {
2713: my ($uname,$udom)=@_;
1.537 albertel 2714: return if (!defined($uname) || !defined($udom));
1.433 albertel 2715: if ($udom eq 'public' && $uname eq 'public') {
2716: return ('lastname' => &mt('Public'));
2717: }
1.295 www 2718: my $id=$uname.':'.$udom;
2719: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2720: if ($cached) {
2721: return %{$names};
2722: } else {
2723: my %loadnames=&Apache::lonnet::get('environment',
2724: ['firstname','middlename','lastname','generation','nickname'],
2725: $udom,$uname);
2726: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2727: return %loadnames;
2728: }
2729: }
1.61 www 2730:
1.542 raeburn 2731: # -------------------------------------------------------------------- getemails
1.648 raeburn 2732:
1.542 raeburn 2733: =pod
2734:
1.648 raeburn 2735: =item * &getemails($uname,$udom)
1.542 raeburn 2736:
2737: Gets a user's email information and returns it as a hash with keys:
2738: notification, critnotification, permanentemail
2739:
2740: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2741: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2742:
1.648 raeburn 2743:
1.542 raeburn 2744: =cut
2745:
1.648 raeburn 2746:
1.466 albertel 2747: sub getemails {
2748: my ($uname,$udom)=@_;
2749: if ($udom eq 'public' && $uname eq 'public') {
2750: return;
2751: }
1.467 www 2752: if (!$udom) { $udom=$env{'user.domain'}; }
2753: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2754: my $id=$uname.':'.$udom;
2755: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2756: if ($cached) {
2757: return %{$names};
2758: } else {
2759: my %loadnames=&Apache::lonnet::get('environment',
2760: ['notification','critnotification',
2761: 'permanentemail'],
2762: $udom,$uname);
2763: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2764: return %loadnames;
2765: }
2766: }
2767:
1.551 albertel 2768: sub flush_email_cache {
2769: my ($uname,$udom)=@_;
2770: if (!$udom) { $udom =$env{'user.domain'}; }
2771: if (!$uname) { $uname=$env{'user.name'}; }
2772: return if ($udom eq 'public' && $uname eq 'public');
2773: my $id=$uname.':'.$udom;
2774: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2775: }
2776:
1.728 raeburn 2777: # -------------------------------------------------------------------- getlangs
2778:
2779: =pod
2780:
2781: =item * &getlangs($uname,$udom)
2782:
2783: Gets a user's language preference and returns it as a hash with key:
2784: language.
2785:
2786: =cut
2787:
2788:
2789: sub getlangs {
2790: my ($uname,$udom) = @_;
2791: if (!$udom) { $udom =$env{'user.domain'}; }
2792: if (!$uname) { $uname=$env{'user.name'}; }
2793: my $id=$uname.':'.$udom;
2794: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2795: if ($cached) {
2796: return %{$langs};
2797: } else {
2798: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2799: $udom,$uname);
2800: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2801: return %loadlangs;
2802: }
2803: }
2804:
2805: sub flush_langs_cache {
2806: my ($uname,$udom)=@_;
2807: if (!$udom) { $udom =$env{'user.domain'}; }
2808: if (!$uname) { $uname=$env{'user.name'}; }
2809: return if ($udom eq 'public' && $uname eq 'public');
2810: my $id=$uname.':'.$udom;
2811: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2812: }
2813:
1.61 www 2814: # ------------------------------------------------------------------ Screenname
1.81 albertel 2815:
2816: =pod
2817:
1.648 raeburn 2818: =item * &screenname($uname,$udom)
1.81 albertel 2819:
2820: Gets a users screenname and returns it as a string
2821:
2822: =cut
1.61 www 2823:
2824: sub screenname {
2825: my ($uname,$udom)=@_;
1.258 albertel 2826: if ($uname eq $env{'user.name'} &&
2827: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2828: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2829: return $names{'screenname'};
1.62 www 2830: }
2831:
1.212 albertel 2832:
1.802 bisitz 2833: # ------------------------------------------------------------- Confirm Wrapper
2834: =pod
2835:
2836: =item confirmwrapper
2837:
2838: Wrap messages about completion of operation in box
2839:
2840: =cut
2841:
2842: sub confirmwrapper {
2843: my ($message)=@_;
2844: if ($message) {
2845: return "\n".'<div class="LC_confirm_box">'."\n"
2846: .$message."\n"
2847: .'</div>'."\n";
2848: } else {
2849: return $message;
2850: }
2851: }
2852:
1.62 www 2853: # ------------------------------------------------------------- Message Wrapper
2854:
2855: sub messagewrapper {
1.369 www 2856: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2857: return
1.441 albertel 2858: '<a href="/adm/email?compose=individual&'.
2859: 'recname='.$username.'&recdom='.$domain.
2860: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2861: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2862: }
1.802 bisitz 2863:
1.74 www 2864: # --------------------------------------------------------------- Notes Wrapper
2865:
2866: sub noteswrapper {
2867: my ($link,$un,$do)=@_;
2868: return
2869: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2870: }
1.802 bisitz 2871:
1.62 www 2872: # ------------------------------------------------------------- Aboutme Wrapper
2873:
2874: sub aboutmewrapper {
1.166 www 2875: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2876: if (!defined($username) && !defined($domain)) {
2877: return;
2878: }
1.205 www 2879: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2880: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2881: }
2882:
2883: # ------------------------------------------------------------ Syllabus Wrapper
2884:
2885: sub syllabuswrapper {
1.707 bisitz 2886: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2887: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2888: }
1.14 harris41 2889:
1.802 bisitz 2890: # -----------------------------------------------------------------------------
2891:
1.208 matthew 2892: sub track_student_link {
1.268 albertel 2893: my ($linktext,$sname,$sdom,$target,$start) = @_;
2894: my $link ="/adm/trackstudent?";
1.208 matthew 2895: my $title = 'View recent activity';
2896: if (defined($sname) && $sname !~ /^\s*$/ &&
2897: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2898: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2899: $title .= ' of this student';
1.268 albertel 2900: }
1.208 matthew 2901: if (defined($target) && $target !~ /^\s*$/) {
2902: $target = qq{target="$target"};
2903: } else {
2904: $target = '';
2905: }
1.268 albertel 2906: if ($start) { $link.='&start='.$start; }
1.554 albertel 2907: $title = &mt($title);
2908: $linktext = &mt($linktext);
1.448 albertel 2909: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2910: &help_open_topic('View_recent_activity');
1.208 matthew 2911: }
2912:
1.781 raeburn 2913: sub slot_reservations_link {
2914: my ($linktext,$sname,$sdom,$target) = @_;
2915: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2916: my $title = 'View slot reservation history';
2917: if (defined($sname) && $sname !~ /^\s*$/ &&
2918: defined($sdom) && $sdom !~ /^\s*$/) {
2919: $link .= "&uname=$sname&udom=$sdom";
2920: $title .= ' of this student';
2921: }
2922: if (defined($target) && $target !~ /^\s*$/) {
2923: $target = qq{target="$target"};
2924: } else {
2925: $target = '';
2926: }
2927: $title = &mt($title);
2928: $linktext = &mt($linktext);
2929: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2930: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2931:
2932: }
2933:
1.508 www 2934: # ===================================================== Display a student photo
2935:
2936:
1.509 albertel 2937: sub student_image_tag {
1.508 www 2938: my ($domain,$user)=@_;
2939: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2940: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2941: return '<img src="'.$imgsrc.'" align="right" />';
2942: } else {
2943: return '';
2944: }
2945: }
2946:
1.112 bowersj2 2947: =pod
2948:
2949: =back
2950:
2951: =head1 Access .tab File Data
2952:
2953: =over 4
2954:
1.648 raeburn 2955: =item * &languageids()
1.112 bowersj2 2956:
2957: returns list of all language ids
2958:
2959: =cut
2960:
1.14 harris41 2961: sub languageids {
1.16 harris41 2962: return sort(keys(%language));
1.14 harris41 2963: }
2964:
1.112 bowersj2 2965: =pod
2966:
1.648 raeburn 2967: =item * &languagedescription()
1.112 bowersj2 2968:
2969: returns description of a specified language id
2970:
2971: =cut
2972:
1.14 harris41 2973: sub languagedescription {
1.125 www 2974: my $code=shift;
2975: return ($supported_language{$code}?'* ':'').
2976: $language{$code}.
1.126 www 2977: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2978: }
2979:
2980: sub plainlanguagedescription {
2981: my $code=shift;
2982: return $language{$code};
2983: }
2984:
2985: sub supportedlanguagecode {
2986: my $code=shift;
2987: return $supported_language{$code};
1.97 www 2988: }
2989:
1.112 bowersj2 2990: =pod
2991:
1.648 raeburn 2992: =item * ©rightids()
1.112 bowersj2 2993:
2994: returns list of all copyrights
2995:
2996: =cut
2997:
2998: sub copyrightids {
2999: return sort(keys(%cprtag));
3000: }
3001:
3002: =pod
3003:
1.648 raeburn 3004: =item * ©rightdescription()
1.112 bowersj2 3005:
3006: returns description of a specified copyright id
3007:
3008: =cut
3009:
3010: sub copyrightdescription {
1.166 www 3011: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3012: }
1.197 matthew 3013:
3014: =pod
3015:
1.648 raeburn 3016: =item * &source_copyrightids()
1.192 taceyjo1 3017:
3018: returns list of all source copyrights
3019:
3020: =cut
3021:
3022: sub source_copyrightids {
3023: return sort(keys(%scprtag));
3024: }
3025:
3026: =pod
3027:
1.648 raeburn 3028: =item * &source_copyrightdescription()
1.192 taceyjo1 3029:
3030: returns description of a specified source copyright id
3031:
3032: =cut
3033:
3034: sub source_copyrightdescription {
3035: return &mt($scprtag{shift(@_)});
3036: }
1.112 bowersj2 3037:
3038: =pod
3039:
1.648 raeburn 3040: =item * &filecategories()
1.112 bowersj2 3041:
3042: returns list of all file categories
3043:
3044: =cut
3045:
3046: sub filecategories {
3047: return sort(keys(%category_extensions));
3048: }
3049:
3050: =pod
3051:
1.648 raeburn 3052: =item * &filecategorytypes()
1.112 bowersj2 3053:
3054: returns list of file types belonging to a given file
3055: category
3056:
3057: =cut
3058:
3059: sub filecategorytypes {
1.356 albertel 3060: my ($cat) = @_;
3061: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3062: }
3063:
3064: =pod
3065:
1.648 raeburn 3066: =item * &fileembstyle()
1.112 bowersj2 3067:
3068: returns embedding style for a specified file type
3069:
3070: =cut
3071:
3072: sub fileembstyle {
3073: return $fe{lc(shift(@_))};
1.169 www 3074: }
3075:
1.351 www 3076: sub filemimetype {
3077: return $fm{lc(shift(@_))};
3078: }
3079:
1.169 www 3080:
3081: sub filecategoryselect {
3082: my ($name,$value)=@_;
1.189 matthew 3083: return &select_form($value,$name,
1.169 www 3084: '' => &mt('Any category'),
3085: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3086: }
3087:
3088: =pod
3089:
1.648 raeburn 3090: =item * &filedescription()
1.112 bowersj2 3091:
3092: returns description for a specified file type
3093:
3094: =cut
3095:
3096: sub filedescription {
1.188 matthew 3097: my $file_description = $fd{lc(shift())};
3098: $file_description =~ s:([\[\]]):~$1:g;
3099: return &mt($file_description);
1.112 bowersj2 3100: }
3101:
3102: =pod
3103:
1.648 raeburn 3104: =item * &filedescriptionex()
1.112 bowersj2 3105:
3106: returns description for a specified file type with
3107: extra formatting
3108:
3109: =cut
3110:
3111: sub filedescriptionex {
3112: my $ex=shift;
1.188 matthew 3113: my $file_description = $fd{lc($ex)};
3114: $file_description =~ s:([\[\]]):~$1:g;
3115: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3116: }
3117:
3118: # End of .tab access
3119: =pod
3120:
3121: =back
3122:
3123: =cut
3124:
3125: # ------------------------------------------------------------------ File Types
3126: sub fileextensions {
3127: return sort(keys(%fe));
3128: }
3129:
1.97 www 3130: # ----------------------------------------------------------- Display Languages
3131: # returns a hash with all desired display languages
3132: #
3133:
3134: sub display_languages {
3135: my %languages=();
1.695 raeburn 3136: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3137: $languages{$lang}=1;
1.97 www 3138: }
3139: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3140: if ($env{'form.displaylanguage'}) {
1.356 albertel 3141: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3142: $languages{$lang}=1;
1.97 www 3143: }
3144: }
3145: return %languages;
1.14 harris41 3146: }
3147:
1.582 albertel 3148: sub languages {
3149: my ($possible_langs) = @_;
1.695 raeburn 3150: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3151: if (!ref($possible_langs)) {
3152: if( wantarray ) {
3153: return @preferred_langs;
3154: } else {
3155: return $preferred_langs[0];
3156: }
3157: }
3158: my %possibilities = map { $_ => 1 } (@$possible_langs);
3159: my @preferred_possibilities;
3160: foreach my $preferred_lang (@preferred_langs) {
3161: if (exists($possibilities{$preferred_lang})) {
3162: push(@preferred_possibilities, $preferred_lang);
3163: }
3164: }
3165: if( wantarray ) {
3166: return @preferred_possibilities;
3167: }
3168: return $preferred_possibilities[0];
3169: }
3170:
1.742 raeburn 3171: sub user_lang {
3172: my ($touname,$toudom,$fromcid) = @_;
3173: my @userlangs;
3174: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3175: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3176: $env{'course.'.$fromcid.'.languages'}));
3177: } else {
3178: my %langhash = &getlangs($touname,$toudom);
3179: if ($langhash{'languages'} ne '') {
3180: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3181: } else {
3182: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3183: if ($domdefs{'lang_def'} ne '') {
3184: @userlangs = ($domdefs{'lang_def'});
3185: }
3186: }
3187: }
3188: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3189: my $user_lh = Apache::localize->get_handle(@languages);
3190: return $user_lh;
3191: }
3192:
3193:
1.112 bowersj2 3194: ###############################################################
3195: ## Student Answer Attempts ##
3196: ###############################################################
3197:
3198: =pod
3199:
3200: =head1 Alternate Problem Views
3201:
3202: =over 4
3203:
1.648 raeburn 3204: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3205: $getattempt, $regexp, $gradesub)
3206:
3207: Return string with previous attempt on problem. Arguments:
3208:
3209: =over 4
3210:
3211: =item * $symb: Problem, including path
3212:
3213: =item * $username: username of the desired student
3214:
3215: =item * $domain: domain of the desired student
1.14 harris41 3216:
1.112 bowersj2 3217: =item * $course: Course ID
1.14 harris41 3218:
1.112 bowersj2 3219: =item * $getattempt: Leave blank for all attempts, otherwise put
3220: something
1.14 harris41 3221:
1.112 bowersj2 3222: =item * $regexp: if string matches this regexp, the string will be
3223: sent to $gradesub
1.14 harris41 3224:
1.112 bowersj2 3225: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3226:
1.112 bowersj2 3227: =back
1.14 harris41 3228:
1.112 bowersj2 3229: The output string is a table containing all desired attempts, if any.
1.16 harris41 3230:
1.112 bowersj2 3231: =cut
1.1 albertel 3232:
3233: sub get_previous_attempt {
1.43 ng 3234: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3235: my $prevattempts='';
1.43 ng 3236: no strict 'refs';
1.1 albertel 3237: if ($symb) {
1.3 albertel 3238: my (%returnhash)=
3239: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3240: if ($returnhash{'version'}) {
3241: my %lasthash=();
3242: my $version;
3243: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3244: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3245: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3246: }
1.1 albertel 3247: }
1.596 albertel 3248: $prevattempts=&start_data_table().&start_data_table_header_row();
3249: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3250: foreach my $key (sort(keys(%lasthash))) {
3251: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3252: if ($#parts > 0) {
1.31 albertel 3253: my $data=$parts[-1];
3254: pop(@parts);
1.596 albertel 3255: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3256: } else {
1.41 ng 3257: if ($#parts == 0) {
3258: $prevattempts.='<th>'.$parts[0].'</th>';
3259: } else {
3260: $prevattempts.='<th>'.$ign.'</th>';
3261: }
1.31 albertel 3262: }
1.16 harris41 3263: }
1.596 albertel 3264: $prevattempts.=&end_data_table_header_row();
1.40 ng 3265: if ($getattempt eq '') {
3266: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3267: $prevattempts.=&start_data_table_row().
3268: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3269: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3270: my $value = &format_previous_attempt_value($key,
3271: $returnhash{$version.':'.$key});
3272: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3273: }
1.596 albertel 3274: $prevattempts.=&end_data_table_row();
1.40 ng 3275: }
1.1 albertel 3276: }
1.596 albertel 3277: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3278: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3279: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3280: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3281: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3282: }
1.596 albertel 3283: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3284: } else {
1.596 albertel 3285: $prevattempts=
3286: &start_data_table().&start_data_table_row().
3287: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3288: &end_data_table_row().&end_data_table();
1.1 albertel 3289: }
3290: } else {
1.596 albertel 3291: $prevattempts=
3292: &start_data_table().&start_data_table_row().
3293: '<td>'.&mt('No data.').'</td>'.
3294: &end_data_table_row().&end_data_table();
1.1 albertel 3295: }
1.10 albertel 3296: }
3297:
1.581 albertel 3298: sub format_previous_attempt_value {
3299: my ($key,$value) = @_;
3300: if ($key =~ /timestamp/) {
3301: $value = &Apache::lonlocal::locallocaltime($value);
3302: } elsif (ref($value) eq 'ARRAY') {
3303: $value = '('.join(', ', @{ $value }).')';
3304: } else {
3305: $value = &unescape($value);
3306: }
3307: return $value;
3308: }
3309:
3310:
1.107 albertel 3311: sub relative_to_absolute {
3312: my ($url,$output)=@_;
3313: my $parser=HTML::TokeParser->new(\$output);
3314: my $token;
3315: my $thisdir=$url;
3316: my @rlinks=();
3317: while ($token=$parser->get_token) {
3318: if ($token->[0] eq 'S') {
3319: if ($token->[1] eq 'a') {
3320: if ($token->[2]->{'href'}) {
3321: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3322: }
3323: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3324: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3325: } elsif ($token->[1] eq 'base') {
3326: $thisdir=$token->[2]->{'href'};
3327: }
3328: }
3329: }
3330: $thisdir=~s-/[^/]*$--;
1.356 albertel 3331: foreach my $link (@rlinks) {
1.726 raeburn 3332: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3333: ($link=~/^\//) ||
3334: ($link=~/^javascript:/i) ||
3335: ($link=~/^mailto:/i) ||
3336: ($link=~/^\#/)) {
3337: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3338: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3339: }
3340: }
3341: # -------------------------------------------------- Deal with Applet codebases
3342: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3343: return $output;
3344: }
3345:
1.112 bowersj2 3346: =pod
3347:
1.648 raeburn 3348: =item * &get_student_view()
1.112 bowersj2 3349:
3350: show a snapshot of what student was looking at
3351:
3352: =cut
3353:
1.10 albertel 3354: sub get_student_view {
1.186 albertel 3355: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3356: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3357: my (%form);
1.10 albertel 3358: my @elements=('symb','courseid','domain','username');
3359: foreach my $element (@elements) {
1.186 albertel 3360: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3361: }
1.186 albertel 3362: if (defined($moreenv)) {
3363: %form=(%form,%{$moreenv});
3364: }
1.236 albertel 3365: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3366: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3367: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3368: $userview=~s/\<body[^\>]*\>//gi;
3369: $userview=~s/\<\/body\>//gi;
3370: $userview=~s/\<html\>//gi;
3371: $userview=~s/\<\/html\>//gi;
3372: $userview=~s/\<head\>//gi;
3373: $userview=~s/\<\/head\>//gi;
3374: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3375: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3376: if (wantarray) {
3377: return ($userview,$response);
3378: } else {
3379: return $userview;
3380: }
3381: }
3382:
3383: sub get_student_view_with_retries {
3384: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3385:
3386: my $ok = 0; # True if we got a good response.
3387: my $content;
3388: my $response;
3389:
3390: # Try to get the student_view done. within the retries count:
3391:
3392: do {
3393: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3394: $ok = $response->is_success;
3395: if (!$ok) {
3396: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3397: }
3398: $retries--;
3399: } while (!$ok && ($retries > 0));
3400:
3401: if (!$ok) {
3402: $content = ''; # On error return an empty content.
3403: }
1.651 www 3404: if (wantarray) {
3405: return ($content, $response);
3406: } else {
3407: return $content;
3408: }
1.11 albertel 3409: }
3410:
1.112 bowersj2 3411: =pod
3412:
1.648 raeburn 3413: =item * &get_student_answers()
1.112 bowersj2 3414:
3415: show a snapshot of how student was answering problem
3416:
3417: =cut
3418:
1.11 albertel 3419: sub get_student_answers {
1.100 sakharuk 3420: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3421: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3422: my (%moreenv);
1.11 albertel 3423: my @elements=('symb','courseid','domain','username');
3424: foreach my $element (@elements) {
1.186 albertel 3425: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3426: }
1.186 albertel 3427: $moreenv{'grade_target'}='answer';
3428: %moreenv=(%form,%moreenv);
1.497 raeburn 3429: $feedurl = &Apache::lonnet::clutter($feedurl);
3430: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3431: return $userview;
1.1 albertel 3432: }
1.116 albertel 3433:
3434: =pod
3435:
3436: =item * &submlink()
3437:
1.242 albertel 3438: Inputs: $text $uname $udom $symb $target
1.116 albertel 3439:
3440: Returns: A link to grades.pm such as to see the SUBM view of a student
3441:
3442: =cut
3443:
3444: ###############################################
3445: sub submlink {
1.242 albertel 3446: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3447: if (!($uname && $udom)) {
3448: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3449: &Apache::lonnet::whichuser($symb);
1.116 albertel 3450: if (!$symb) { $symb=$cursymb; }
3451: }
1.254 matthew 3452: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3453: $symb=&escape($symb);
1.242 albertel 3454: if ($target) { $target="target=\"$target\""; }
3455: return '<a href="/adm/grades?&command=submission&'.
3456: 'symb='.$symb.'&student='.$uname.
3457: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3458: }
3459: ##############################################
3460:
3461: =pod
3462:
3463: =item * &pgrdlink()
3464:
3465: Inputs: $text $uname $udom $symb $target
3466:
3467: Returns: A link to grades.pm such as to see the PGRD view of a student
3468:
3469: =cut
3470:
3471: ###############################################
3472: sub pgrdlink {
3473: my $link=&submlink(@_);
3474: $link=~s/(&command=submission)/$1&showgrading=yes/;
3475: return $link;
3476: }
3477: ##############################################
3478:
3479: =pod
3480:
3481: =item * &pprmlink()
3482:
3483: Inputs: $text $uname $udom $symb $target
3484:
3485: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3486: student and a specific resource
1.242 albertel 3487:
3488: =cut
3489:
3490: ###############################################
3491: sub pprmlink {
3492: my ($text,$uname,$udom,$symb,$target)=@_;
3493: if (!($uname && $udom)) {
3494: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3495: &Apache::lonnet::whichuser($symb);
1.242 albertel 3496: if (!$symb) { $symb=$cursymb; }
3497: }
1.254 matthew 3498: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3499: $symb=&escape($symb);
1.242 albertel 3500: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3501: return '<a href="/adm/parmset?command=set&'.
3502: 'symb='.$symb.'&uname='.$uname.
3503: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3504: }
3505: ##############################################
1.37 matthew 3506:
1.112 bowersj2 3507: =pod
3508:
3509: =back
3510:
3511: =cut
3512:
1.37 matthew 3513: ###############################################
1.51 www 3514:
3515:
3516: sub timehash {
1.687 raeburn 3517: my ($thistime) = @_;
3518: my $timezone = &Apache::lonlocal::gettimezone();
3519: my $dt = DateTime->from_epoch(epoch => $thistime)
3520: ->set_time_zone($timezone);
3521: my $wday = $dt->day_of_week();
3522: if ($wday == 7) { $wday = 0; }
3523: return ( 'second' => $dt->second(),
3524: 'minute' => $dt->minute(),
3525: 'hour' => $dt->hour(),
3526: 'day' => $dt->day_of_month(),
3527: 'month' => $dt->month(),
3528: 'year' => $dt->year(),
3529: 'weekday' => $wday,
3530: 'dayyear' => $dt->day_of_year(),
3531: 'dlsav' => $dt->is_dst() );
1.51 www 3532: }
3533:
1.370 www 3534: sub utc_string {
3535: my ($date)=@_;
1.371 www 3536: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3537: }
3538:
1.51 www 3539: sub maketime {
3540: my %th=@_;
1.687 raeburn 3541: my ($epoch_time,$timezone,$dt);
3542: $timezone = &Apache::lonlocal::gettimezone();
3543: eval {
3544: $dt = DateTime->new( year => $th{'year'},
3545: month => $th{'month'},
3546: day => $th{'day'},
3547: hour => $th{'hour'},
3548: minute => $th{'minute'},
3549: second => $th{'second'},
3550: time_zone => $timezone,
3551: );
3552: };
3553: if (!$@) {
3554: $epoch_time = $dt->epoch;
3555: if ($epoch_time) {
3556: return $epoch_time;
3557: }
3558: }
1.51 www 3559: return POSIX::mktime(
3560: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3561: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3562: }
3563:
3564: #########################################
1.51 www 3565:
3566: sub findallcourses {
1.482 raeburn 3567: my ($roles,$uname,$udom) = @_;
1.355 albertel 3568: my %roles;
3569: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3570: my %courses;
1.51 www 3571: my $now=time;
1.482 raeburn 3572: if (!defined($uname)) {
3573: $uname = $env{'user.name'};
3574: }
3575: if (!defined($udom)) {
3576: $udom = $env{'user.domain'};
3577: }
3578: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3579: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3580: if (!%roles) {
3581: %roles = (
3582: cc => 1,
3583: in => 1,
3584: ep => 1,
3585: ta => 1,
3586: cr => 1,
3587: st => 1,
3588: );
3589: }
3590: foreach my $entry (keys(%roleshash)) {
3591: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3592: if ($trole =~ /^cr/) {
3593: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3594: } else {
3595: next if (!exists($roles{$trole}));
3596: }
3597: if ($tend) {
3598: next if ($tend < $now);
3599: }
3600: if ($tstart) {
3601: next if ($tstart > $now);
3602: }
3603: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3604: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3605: if ($secpart eq '') {
3606: ($cnum,$role) = split(/_/,$cnumpart);
3607: $sec = 'none';
3608: $realsec = '';
3609: } else {
3610: $cnum = $cnumpart;
3611: ($sec,$role) = split(/_/,$secpart);
3612: $realsec = $sec;
1.490 raeburn 3613: }
1.482 raeburn 3614: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3615: }
3616: } else {
3617: foreach my $key (keys(%env)) {
1.483 albertel 3618: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3619: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3620: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3621: next if ($role eq 'ca' || $role eq 'aa');
3622: next if (%roles && !exists($roles{$role}));
3623: my ($starttime,$endtime)=split(/\./,$env{$key});
3624: my $active=1;
3625: if ($starttime) {
3626: if ($now<$starttime) { $active=0; }
3627: }
3628: if ($endtime) {
3629: if ($now>$endtime) { $active=0; }
3630: }
3631: if ($active) {
3632: if ($sec eq '') {
3633: $sec = 'none';
3634: }
3635: $courses{$cdom.'_'.$cnum}{$sec} =
3636: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3637: }
3638: }
1.51 www 3639: }
3640: }
1.474 raeburn 3641: return %courses;
1.51 www 3642: }
1.37 matthew 3643:
1.54 www 3644: ###############################################
1.474 raeburn 3645:
3646: sub blockcheck {
1.482 raeburn 3647: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3648:
3649: if (!defined($udom)) {
3650: $udom = $env{'user.domain'};
3651: }
3652: if (!defined($uname)) {
3653: $uname = $env{'user.name'};
3654: }
3655:
3656: # If uname and udom are for a course, check for blocks in the course.
3657:
3658: if (&Apache::lonnet::is_course($udom,$uname)) {
3659: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3660: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3661: return ($startblock,$endblock);
3662: }
1.474 raeburn 3663:
1.502 raeburn 3664: my $startblock = 0;
3665: my $endblock = 0;
1.482 raeburn 3666: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3667:
1.490 raeburn 3668: # If uname is for a user, and activity is course-specific, i.e.,
3669: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3670:
1.490 raeburn 3671: if (($activity eq 'boards' || $activity eq 'chat' ||
3672: $activity eq 'groups') && ($env{'request.course.id'})) {
3673: foreach my $key (keys(%live_courses)) {
3674: if ($key ne $env{'request.course.id'}) {
3675: delete($live_courses{$key});
3676: }
3677: }
3678: }
3679:
3680: my $otheruser = 0;
3681: my %own_courses;
3682: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3683: # Resource belongs to user other than current user.
3684: $otheruser = 1;
3685: # Gather courses for current user
3686: %own_courses =
3687: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3688: }
3689:
3690: # Gather active course roles - course coordinator, instructor,
3691: # exam proctor, ta, student, or custom role.
1.474 raeburn 3692:
3693: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3694: my ($cdom,$cnum);
3695: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3696: $cdom = $env{'course.'.$course.'.domain'};
3697: $cnum = $env{'course.'.$course.'.num'};
3698: } else {
1.490 raeburn 3699: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3700: }
3701: my $no_ownblock = 0;
3702: my $no_userblock = 0;
1.533 raeburn 3703: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3704: # Check if current user has 'evb' priv for this
3705: if (defined($own_courses{$course})) {
3706: foreach my $sec (keys(%{$own_courses{$course}})) {
3707: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3708: if ($sec ne 'none') {
3709: $checkrole .= '/'.$sec;
3710: }
3711: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3712: $no_ownblock = 1;
3713: last;
3714: }
3715: }
3716: }
3717: # if they have 'evb' priv and are currently not playing student
3718: next if (($no_ownblock) &&
3719: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3720: }
1.474 raeburn 3721: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3722: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3723: if ($sec ne 'none') {
1.482 raeburn 3724: $checkrole .= '/'.$sec;
1.474 raeburn 3725: }
1.490 raeburn 3726: if ($otheruser) {
3727: # Resource belongs to user other than current user.
3728: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3729: my ($trole,$tdom,$tnum,$tsec);
3730: my $entry = $live_courses{$course}{$sec};
3731: if ($entry =~ /^cr/) {
3732: ($trole,$tdom,$tnum,$tsec) =
3733: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3734: } else {
3735: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3736: }
3737: my ($spec,$area,$trest,%allroles,%userroles);
3738: $area = '/'.$tdom.'/'.$tnum;
3739: $trest = $tnum;
3740: if ($tsec ne '') {
3741: $area .= '/'.$tsec;
3742: $trest .= '/'.$tsec;
3743: }
3744: $spec = $trole.'.'.$area;
3745: if ($trole =~ /^cr/) {
3746: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3747: $tdom,$spec,$trest,$area);
3748: } else {
3749: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3750: $tdom,$spec,$trest,$area);
3751: }
3752: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3753: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3754: if ($1) {
3755: $no_userblock = 1;
3756: last;
3757: }
3758: }
1.490 raeburn 3759: } else {
3760: # Resource belongs to current user
3761: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3762: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3763: $no_ownblock = 1;
3764: last;
3765: }
1.474 raeburn 3766: }
3767: }
3768: # if they have the evb priv and are currently not playing student
1.482 raeburn 3769: next if (($no_ownblock) &&
1.491 albertel 3770: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3771: next if ($no_userblock);
1.474 raeburn 3772:
1.866 kalberla 3773: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3774: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3775:
3776: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3777: if (($start != 0) &&
3778: (($startblock == 0) || ($startblock > $start))) {
3779: $startblock = $start;
3780: }
3781: if (($end != 0) &&
3782: (($endblock == 0) || ($endblock < $end))) {
3783: $endblock = $end;
3784: }
1.490 raeburn 3785: }
3786: return ($startblock,$endblock);
3787: }
3788:
3789: sub get_blocks {
3790: my ($setters,$activity,$cdom,$cnum) = @_;
3791: my $startblock = 0;
3792: my $endblock = 0;
3793: my $course = $cdom.'_'.$cnum;
3794: $setters->{$course} = {};
3795: $setters->{$course}{'staff'} = [];
3796: $setters->{$course}{'times'} = [];
3797: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3798: foreach my $record (keys(%records)) {
3799: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3800: if ($start <= time && $end >= time) {
3801: my ($staff_name,$staff_dom,$title,$blocks) =
3802: &parse_block_record($records{$record});
3803: if ($blocks->{$activity} eq 'on') {
3804: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3805: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3806: if ( ($startblock == 0) || ($startblock > $start) ) {
3807: $startblock = $start;
1.490 raeburn 3808: }
1.491 albertel 3809: if ( ($endblock == 0) || ($endblock < $end) ) {
3810: $endblock = $end;
1.474 raeburn 3811: }
3812: }
3813: }
3814: }
3815: return ($startblock,$endblock);
3816: }
3817:
3818: sub parse_block_record {
3819: my ($record) = @_;
3820: my ($setuname,$setudom,$title,$blocks);
3821: if (ref($record) eq 'HASH') {
3822: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3823: $title = &unescape($record->{'event'});
3824: $blocks = $record->{'blocks'};
3825: } else {
3826: my @data = split(/:/,$record,3);
3827: if (scalar(@data) eq 2) {
3828: $title = $data[1];
3829: ($setuname,$setudom) = split(/@/,$data[0]);
3830: } else {
3831: ($setuname,$setudom,$title) = @data;
3832: }
3833: $blocks = { 'com' => 'on' };
3834: }
3835: return ($setuname,$setudom,$title,$blocks);
3836: }
3837:
1.854 kalberla 3838: sub blocking_status {
1.867 kalberla 3839: my $blocked;
1.854 kalberla 3840: my ($activity,$uname,$udom) = @_;
1.867 kalberla 3841: my %setters;
3842: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3843: if ($startblock && $endblock) {
3844: $blocked = 1;
3845: }
1.854 kalberla 3846: if(!wantarray) {
3847: return $blocked;
3848: }
3849: my $output;
3850: my $querystring;
3851: $querystring = "?activity=$activity";
3852:
3853: $output .= <<"END_MYBLOCK";
3854: <script type="text/javascript">
3855: // <![CDATA[
3856: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3857: var options = "width=" + w + ",height=" + h + ",";
3858: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3859: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3860: var newWin = window.open(url, wdwName, options);
3861: newWin.focus();
3862: }
3863:
3864: // ]]>
3865: </script>
3866: END_MYBLOCK
3867: my $popupUrl = "/adm/blockingstatus/$querystring";
1.867 kalberla 3868: $output .= <<"END_BLOCK";
3869: <div class='LC_comblock'>
1.869 kalberla 3870: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
3871: title='Communication Blocked'>
3872: <img class='LC_noBorder LC_middle' title='Communication Blocked' src='/res/adm/pages/comblock.png' alt='Communication Blocked'/></a>
3873: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
3874: title='Communication Blocked'>Communication Blocked</a>
1.867 kalberla 3875: </div>
3876:
3877: END_BLOCK
1.474 raeburn 3878:
1.854 kalberla 3879: return ($blocked, $output);
3880: }
1.490 raeburn 3881:
1.60 matthew 3882: ###############################################
3883:
1.682 raeburn 3884: sub check_ip_acc {
3885: my ($acc)=@_;
3886: &Apache::lonxml::debug("acc is $acc");
3887: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3888: return 1;
3889: }
3890: my $allowed=0;
3891: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3892:
3893: my $name;
3894: foreach my $pattern (split(',',$acc)) {
3895: $pattern =~ s/^\s*//;
3896: $pattern =~ s/\s*$//;
3897: if ($pattern =~ /\*$/) {
3898: #35.8.*
3899: $pattern=~s/\*//;
3900: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3901: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3902: #35.8.3.[34-56]
3903: my $low=$2;
3904: my $high=$3;
3905: $pattern=$1;
3906: if ($ip =~ /^\Q$pattern\E/) {
3907: my $last=(split(/\./,$ip))[3];
3908: if ($last <=$high && $last >=$low) { $allowed=1; }
3909: }
3910: } elsif ($pattern =~ /^\*/) {
3911: #*.msu.edu
3912: $pattern=~s/\*//;
3913: if (!defined($name)) {
3914: use Socket;
3915: my $netaddr=inet_aton($ip);
3916: ($name)=gethostbyaddr($netaddr,AF_INET);
3917: }
3918: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3919: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3920: #127.0.0.1
3921: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3922: } else {
3923: #some.name.com
3924: if (!defined($name)) {
3925: use Socket;
3926: my $netaddr=inet_aton($ip);
3927: ($name)=gethostbyaddr($netaddr,AF_INET);
3928: }
3929: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3930: }
3931: if ($allowed) { last; }
3932: }
3933: return $allowed;
3934: }
3935:
3936: ###############################################
3937:
1.60 matthew 3938: =pod
3939:
1.112 bowersj2 3940: =head1 Domain Template Functions
3941:
3942: =over 4
3943:
3944: =item * &determinedomain()
1.60 matthew 3945:
3946: Inputs: $domain (usually will be undef)
3947:
1.63 www 3948: Returns: Determines which domain should be used for designs
1.60 matthew 3949:
3950: =cut
1.54 www 3951:
1.60 matthew 3952: ###############################################
1.63 www 3953: sub determinedomain {
3954: my $domain=shift;
1.531 albertel 3955: if (! $domain) {
1.60 matthew 3956: # Determine domain if we have not been given one
3957: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3958: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3959: if ($env{'request.role.domain'}) {
3960: $domain=$env{'request.role.domain'};
1.60 matthew 3961: }
3962: }
1.63 www 3963: return $domain;
3964: }
3965: ###############################################
1.517 raeburn 3966:
1.518 albertel 3967: sub devalidate_domconfig_cache {
3968: my ($udom)=@_;
3969: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3970: }
3971:
3972: # ---------------------- Get domain configuration for a domain
3973: sub get_domainconf {
3974: my ($udom) = @_;
3975: my $cachetime=1800;
3976: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3977: if (defined($cached)) { return %{$result}; }
3978:
3979: my %domconfig = &Apache::lonnet::get_dom('configuration',
3980: ['login','rolecolors'],$udom);
1.632 raeburn 3981: my (%designhash,%legacy);
1.518 albertel 3982: if (keys(%domconfig) > 0) {
3983: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3984: if (keys(%{$domconfig{'login'}})) {
3985: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3986: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3987: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3988: $designhash{$udom.'.login.'.$key.'_'.$img} =
3989: $domconfig{'login'}{$key}{$img};
3990: }
3991: } else {
3992: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3993: }
1.632 raeburn 3994: }
3995: } else {
3996: $legacy{'login'} = 1;
1.518 albertel 3997: }
1.632 raeburn 3998: } else {
3999: $legacy{'login'} = 1;
1.518 albertel 4000: }
4001: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4002: if (keys(%{$domconfig{'rolecolors'}})) {
4003: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4004: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4005: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4006: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4007: }
1.518 albertel 4008: }
4009: }
1.632 raeburn 4010: } else {
4011: $legacy{'rolecolors'} = 1;
1.518 albertel 4012: }
1.632 raeburn 4013: } else {
4014: $legacy{'rolecolors'} = 1;
1.518 albertel 4015: }
1.632 raeburn 4016: if (keys(%legacy) > 0) {
4017: my %legacyhash = &get_legacy_domconf($udom);
4018: foreach my $item (keys(%legacyhash)) {
4019: if ($item =~ /^\Q$udom\E\.login/) {
4020: if ($legacy{'login'}) {
4021: $designhash{$item} = $legacyhash{$item};
4022: }
4023: } else {
4024: if ($legacy{'rolecolors'}) {
4025: $designhash{$item} = $legacyhash{$item};
4026: }
1.518 albertel 4027: }
4028: }
4029: }
1.632 raeburn 4030: } else {
4031: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4032: }
4033: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4034: $cachetime);
4035: return %designhash;
4036: }
4037:
1.632 raeburn 4038: sub get_legacy_domconf {
4039: my ($udom) = @_;
4040: my %legacyhash;
4041: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4042: my $designfile = $designdir.'/'.$udom.'.tab';
4043: if (-e $designfile) {
4044: if ( open (my $fh,"<$designfile") ) {
4045: while (my $line = <$fh>) {
4046: next if ($line =~ /^\#/);
4047: chomp($line);
4048: my ($key,$val)=(split(/\=/,$line));
4049: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4050: }
4051: close($fh);
4052: }
4053: }
4054: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4055: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4056: }
4057: return %legacyhash;
4058: }
4059:
1.63 www 4060: =pod
4061:
1.112 bowersj2 4062: =item * &domainlogo()
1.63 www 4063:
4064: Inputs: $domain (usually will be undef)
4065:
4066: Returns: A link to a domain logo, if the domain logo exists.
4067: If the domain logo does not exist, a description of the domain.
4068:
4069: =cut
1.112 bowersj2 4070:
1.63 www 4071: ###############################################
4072: sub domainlogo {
1.517 raeburn 4073: my $domain = &determinedomain(shift);
1.518 albertel 4074: my %designhash = &get_domainconf($domain);
1.517 raeburn 4075: # See if there is a logo
4076: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4077: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4078: if ($imgsrc =~ m{^/(adm|res)/}) {
4079: if ($imgsrc =~ m{^/res/}) {
4080: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4081: &Apache::lonnet::repcopy($local_name);
4082: }
4083: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4084: }
4085: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4086: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4087: return &Apache::lonnet::domain($domain,'description');
1.59 www 4088: } else {
1.60 matthew 4089: return '';
1.59 www 4090: }
4091: }
1.63 www 4092: ##############################################
4093:
4094: =pod
4095:
1.112 bowersj2 4096: =item * &designparm()
1.63 www 4097:
4098: Inputs: $which parameter; $domain (usually will be undef)
4099:
4100: Returns: value of designparamter $which
4101:
4102: =cut
1.112 bowersj2 4103:
1.397 albertel 4104:
1.400 albertel 4105: ##############################################
1.397 albertel 4106: sub designparm {
4107: my ($which,$domain)=@_;
4108: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4109: return $env{'environment.color.'.$which};
1.96 www 4110: }
1.63 www 4111: $domain=&determinedomain($domain);
1.518 albertel 4112: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4113: my $output;
1.517 raeburn 4114: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4115: $output = $domdesign{$domain.'.'.$which};
1.63 www 4116: } else {
1.520 raeburn 4117: $output = $defaultdesign{$which};
4118: }
4119: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4120: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4121: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4122: if ($output =~ m{^/res/}) {
4123: my $local_name = &Apache::lonnet::filelocation('',$output);
4124: &Apache::lonnet::repcopy($local_name);
4125: }
1.520 raeburn 4126: $output = &lonhttpdurl($output);
4127: }
1.63 www 4128: }
1.520 raeburn 4129: return $output;
1.63 www 4130: }
1.59 www 4131:
1.822 bisitz 4132: ##############################################
4133: =pod
4134:
1.832 bisitz 4135: =item * &authorspace()
4136:
4137: Inputs: ./.
4138:
4139: Returns: Path to the Construction Space of the current user's
4140: accessed author space
4141: The author space will be that of the current user
4142: when accessing the own author space
4143: and that of the co-author/assistent co-author
4144: when accessing the co-author's/assistent co-author's
4145: space
4146:
4147: =cut
4148:
4149: sub authorspace {
4150: my $caname = '';
4151: if ($env{'request.role'} =~ /^ca|^aa/) {
4152: (undef,$caname) =
4153: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4154: } else {
4155: $caname = $env{'user.name'};
4156: }
4157: return '/priv/'.$caname.'/';
4158: }
4159:
4160: ##############################################
4161: =pod
4162:
1.822 bisitz 4163: =item * &head_subbox()
4164:
4165: Inputs: $content (contains HTML code with page functions, etc.)
4166:
4167: Returns: HTML div with $content
4168: To be included in page header
4169:
4170: =cut
4171:
4172: sub head_subbox {
4173: my ($content)=@_;
4174: my $output =
1.844 bisitz 4175: '<div id="LC_head_subbox">'
1.822 bisitz 4176: .$content
4177: .'</div>'
4178: }
4179:
4180: ##############################################
4181: =pod
4182:
4183: =item * &CSTR_pageheader()
4184:
4185: Inputs: ./.
4186:
4187: Returns: HTML div with CSTR path and recent box
4188: To be included on Construction Space pages
4189:
4190: =cut
4191:
4192: sub CSTR_pageheader {
4193: # this is for resources; directories have customtitle, and crumbs
4194: # and select recent are created in lonpubdir.pm
4195: my ($uname,$thisdisfn)=
4196: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4197: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4198: $formaction=~s/\/+/\//g;
4199:
4200: my $parentpath = '';
4201: my $lastitem = '';
4202: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4203: $parentpath = $1;
4204: $lastitem = $2;
4205: } else {
4206: $lastitem = $thisdisfn;
4207: }
4208: return
4209: '<div>'
4210: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4211: .'<b>'.&mt('Construction Space:').'</b> '
4212: .'<form name="dirs" method="post" action="'.$formaction
4213: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4214: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4215: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4216: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4217: .'</form>'
4218: .&Apache::lonmenu::constspaceform()
4219: .'</div>';
4220: }
4221:
1.60 matthew 4222: ###############################################
4223: ###############################################
4224:
4225: =pod
4226:
1.112 bowersj2 4227: =back
4228:
1.549 albertel 4229: =head1 HTML Helpers
1.112 bowersj2 4230:
4231: =over 4
4232:
4233: =item * &bodytag()
1.60 matthew 4234:
4235: Returns a uniform header for LON-CAPA web pages.
4236:
4237: Inputs:
4238:
1.112 bowersj2 4239: =over 4
4240:
4241: =item * $title, A title to be displayed on the page.
4242:
4243: =item * $function, the current role (can be undef).
4244:
4245: =item * $addentries, extra parameters for the <body> tag.
4246:
4247: =item * $bodyonly, if defined, only return the <body> tag.
4248:
4249: =item * $domain, if defined, force a given domain.
4250:
4251: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4252: text interface only)
1.60 matthew 4253:
1.814 bisitz 4254: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4255: navigational links
1.317 albertel 4256:
1.338 albertel 4257: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4258:
1.361 albertel 4259: =item * $no_inline_link, if true and in remote mode, don't show the
4260: 'Switch To Inline Menu' link
4261:
1.460 albertel 4262: =item * $args, optional argument valid values are
4263: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4264: inherit_jsmath -> when creating popup window in a page,
4265: should it have jsmath forced on by the
4266: current page
1.460 albertel 4267:
1.112 bowersj2 4268: =back
4269:
1.60 matthew 4270: Returns: A uniform header for LON-CAPA web pages.
4271: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4272: If $bodyonly is undef or zero, an html string containing a <body> tag and
4273: other decorations will be returned.
4274:
4275: =cut
4276:
1.54 www 4277: sub bodytag {
1.831 bisitz 4278: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4279: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4280:
1.460 albertel 4281: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4282:
1.183 matthew 4283: $function = &get_users_function() if (!$function);
1.339 albertel 4284: my $img = &designparm($function.'.img',$domain);
4285: my $font = &designparm($function.'.font',$domain);
4286: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4287:
1.803 bisitz 4288: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4289: 'bgcolor' => $pgbg,
1.339 albertel 4290: 'text' => $font,
4291: 'alink' => &designparm($function.'.alink',$domain),
4292: 'vlink' => &designparm($function.'.vlink',$domain),
4293: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4294: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4295:
1.63 www 4296: # role and realm
1.378 raeburn 4297: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4298: if ($role eq 'ca') {
1.479 albertel 4299: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4300: $realm = &plainname($rname,$rdom);
1.378 raeburn 4301: }
1.55 www 4302: # realm
1.258 albertel 4303: if ($env{'request.course.id'}) {
1.378 raeburn 4304: if ($env{'request.role'} !~ /^cr/) {
4305: $role = &Apache::lonnet::plaintext($role,&course_type());
4306: }
1.359 albertel 4307: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4308: } else {
4309: $role = &Apache::lonnet::plaintext($role);
1.54 www 4310: }
1.433 albertel 4311:
1.359 albertel 4312: if (!$realm) { $realm=' '; }
1.55 www 4313: # Set messages
1.60 matthew 4314: my $messages=&domainlogo($domain);
1.330 albertel 4315:
1.438 albertel 4316: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4317:
1.101 www 4318: # construct main body tag
1.359 albertel 4319: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4320: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4321:
1.530 albertel 4322: if ($bodyonly) {
1.60 matthew 4323: return $bodytag;
1.798 tempelho 4324: }
1.359 albertel 4325:
1.410 albertel 4326: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4327: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4328: undef($role);
1.434 albertel 4329: } else {
4330: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4331: }
1.359 albertel 4332:
1.762 bisitz 4333: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4334: #
4335: # Extra info if you are the DC
4336: my $dc_info = '';
4337: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4338: $env{'course.'.$env{'request.course.id'}.
4339: '.domain'}.'/'})) {
4340: my $cid = $env{'request.course.id'};
4341: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4342: $dc_info =~ s/\s+$//;
1.359 albertel 4343: $dc_info = '('.$dc_info.')';
4344: }
4345:
1.853 droeschl 4346: $role = "($role)" if $role;
4347: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4348:
1.837 bisitz 4349: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4350: # No Remote
1.258 albertel 4351: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4352: $forcereg=1;
4353: }
4354:
1.836 bisitz 4355: # if ($env{'request.state'} eq 'construct') {
4356: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4357: # }
1.359 albertel 4358:
1.816 bisitz 4359: my $titletable = '<table id="LC_title_bar">'
1.836 bisitz 4360: ."<tr><td> $titleinfo $dc_info</td>"
1.816 bisitz 4361: .'</tr></table>';
4362:
1.814 bisitz 4363: if ($no_nav_bar) {
1.359 albertel 4364: $bodytag .= $titletable;
4365: } else {
1.852 droeschl 4366: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4367: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4368:
1.359 albertel 4369: if ($env{'request.state'} eq 'construct') {
1.863 droeschl 4370: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
1.272 raeburn 4371: } else {
1.863 droeschl 4372: $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
1.272 raeburn 4373: }
1.235 raeburn 4374: }
4375: return $bodytag;
1.94 www 4376: }
1.95 www 4377:
1.93 www 4378: #
1.95 www 4379: # Top frame rendering, Remote is up
1.93 www 4380: #
1.359 albertel 4381:
1.517 raeburn 4382: my $imgsrc = $img;
4383: if ($img =~ /^\/adm/) {
1.575 albertel 4384: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4385: }
4386: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4387:
1.305 www 4388: # Explicit link to get inline menu
1.361 albertel 4389: my $menu= ($no_inline_link?''
1.853 droeschl 4390: :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4391: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4392: <em>$realm</em> $dc_info </div>
4393: <ol class="LC_smallMenu LC_right">
4394: <li>$menu</li>
4395: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4396: #
1.94 www 4397: return(<<ENDBODY);
1.60 matthew 4398: $bodytag
1.359 albertel 4399: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4400: <tr><td>$upperleft</td>
4401: <td>$messages </td>
1.54 www 4402: </tr>
1.359 albertel 4403: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4404: </tr>
1.356 albertel 4405: </table>
1.54 www 4406: ENDBODY
1.182 matthew 4407: }
4408:
1.330 albertel 4409: sub make_attr_string {
4410: my ($register,$attr_ref) = @_;
4411:
4412: if ($attr_ref && !ref($attr_ref)) {
4413: die("addentries Must be a hash ref ".
4414: join(':',caller(1))." ".
4415: join(':',caller(0))." ");
4416: }
4417:
4418: if ($register) {
1.339 albertel 4419: my ($on_load,$on_unload);
4420: foreach my $key (keys(%{$attr_ref})) {
4421: if (lc($key) eq 'onload') {
4422: $on_load.=$attr_ref->{$key}.';';
4423: delete($attr_ref->{$key});
4424:
4425: } elsif (lc($key) eq 'onunload') {
4426: $on_unload.=$attr_ref->{$key}.';';
4427: delete($attr_ref->{$key});
4428: }
4429: }
4430: $attr_ref->{'onload'} =
4431: &Apache::lonmenu::loadevents(). $on_load;
4432: $attr_ref->{'onunload'}=
4433: &Apache::lonmenu::unloadevents().$on_unload;
4434: }
4435:
4436: # Accessibility font enhance
4437: if ($env{'browser.fontenhance'} eq 'on') {
4438: my $style;
4439: foreach my $key (keys(%{$attr_ref})) {
4440: if (lc($key) eq 'style') {
4441: $style.=$attr_ref->{$key}.';';
4442: delete($attr_ref->{$key});
4443: }
4444: }
4445: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4446: }
1.339 albertel 4447:
1.330 albertel 4448: my $attr_string;
4449: foreach my $attr (keys(%$attr_ref)) {
4450: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4451: }
4452: return $attr_string;
4453: }
4454:
4455:
1.182 matthew 4456: ###############################################
1.251 albertel 4457: ###############################################
4458:
4459: =pod
4460:
4461: =item * &endbodytag()
4462:
4463: Returns a uniform footer for LON-CAPA web pages.
4464:
1.635 raeburn 4465: Inputs: 1 - optional reference to an args hash
4466: If in the hash, key for noredirectlink has a value which evaluates to true,
4467: a 'Continue' link is not displayed if the page contains an
4468: internal redirect in the <head></head> section,
4469: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4470:
4471: =cut
4472:
4473: sub endbodytag {
1.635 raeburn 4474: my ($args) = @_;
1.251 albertel 4475: my $endbodytag='</body>';
1.269 albertel 4476: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4477: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4478: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4479: $endbodytag=
4480: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4481: &mt('Continue').'</a>'.
4482: $endbodytag;
4483: }
1.315 albertel 4484: }
1.251 albertel 4485: return $endbodytag;
4486: }
4487:
1.352 albertel 4488: =pod
4489:
4490: =item * &standard_css()
4491:
4492: Returns a style sheet
4493:
4494: Inputs: (all optional)
4495: domain -> force to color decorate a page for a specific
4496: domain
4497: function -> force usage of a specific rolish color scheme
4498: bgcolor -> override the default page bgcolor
4499:
4500: =cut
4501:
1.343 albertel 4502: sub standard_css {
1.345 albertel 4503: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4504: $function = &get_users_function() if (!$function);
4505: my $img = &designparm($function.'.img', $domain);
4506: my $tabbg = &designparm($function.'.tabbg', $domain);
4507: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4508: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4509: #second colour for later usage
1.345 albertel 4510: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4511: my $pgbg_or_bgcolor =
4512: $bgcolor ||
1.352 albertel 4513: &designparm($function.'.pgbg', $domain);
1.382 albertel 4514: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4515: my $alink = &designparm($function.'.alink', $domain);
4516: my $vlink = &designparm($function.'.vlink', $domain);
4517: my $link = &designparm($function.'.link', $domain);
4518:
1.704 muellerd 4519: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4520: my $bgcol = &designparm('login.bgcol',$domain);
4521: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4522:
1.602 albertel 4523: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4524: my $mono = 'monospace';
1.850 bisitz 4525: my $data_table_head = $sidebg;
4526: my $data_table_light = '#FAFAFA';
4527: my $data_table_dark = '#F0F0F0';
1.470 banghart 4528: my $data_table_darker = '#CCCCCC';
1.349 albertel 4529: my $data_table_highlight = '#FFFF00';
1.352 albertel 4530: my $mail_new = '#FFBB77';
4531: my $mail_new_hover = '#DD9955';
4532: my $mail_read = '#BBBB77';
4533: my $mail_read_hover = '#999944';
4534: my $mail_replied = '#AAAA88';
4535: my $mail_replied_hover = '#888855';
4536: my $mail_other = '#99BBBB';
4537: my $mail_other_hover = '#669999';
1.391 albertel 4538: my $table_header = '#DDDDDD';
1.489 raeburn 4539: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4540: my $lg_border_color = '#C8C8C8';
1.392 albertel 4541:
1.608 albertel 4542: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4543: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4544: : '0 3px 0 4px';
1.448 albertel 4545:
1.523 albertel 4546:
1.343 albertel 4547: return <<END;
1.795 www 4548: body {
4549: font-family: $sans;
4550: line-height:130%;
4551: font-size:0.83em;
4552: color:$font;
4553: }
4554:
4555: a:link, a:visited {
4556: font-size:100%;
4557: }
4558:
4559: a:focus {
4560: color: red;
4561: background: yellow
4562: }
1.698 harmsja 4563:
1.846 bisitz 4564: hr {
4565: clear: both;
4566: color: $tabbg;
4567: background-color: $tabbg;
4568: height: 3px;
4569: border: none;
4570: }
4571:
1.795 www 4572: form, .inline {
4573: display: inline;
4574: }
1.721 harmsja 4575:
1.795 www 4576: .LC_right {
4577: text-align:right;
4578: }
4579:
4580: .LC_middle {
4581: vertical-align:middle;
4582: }
1.721 harmsja 4583:
4584: /* just for tests */
1.754 droeschl 4585: .LC_400Box {width:400px; }
1.721 harmsja 4586: /* end */
4587:
1.778 bisitz 4588: .LC_filename {
4589: font-family: $mono;
4590: white-space:pre;
4591: }
4592:
4593: .LC_fileicon {
4594: border: none;
4595: height: 1.3em;
4596: vertical-align: text-bottom;
4597: margin-right: 0.3em;
4598: text-decoration:none;
4599: }
4600:
1.350 albertel 4601: .LC_error {
4602: color: red;
4603: font-size: larger;
4604: }
1.795 www 4605:
1.457 albertel 4606: .LC_warning,
4607: .LC_diff_removed {
1.733 bisitz 4608: color: red;
1.394 albertel 4609: }
1.532 albertel 4610:
4611: .LC_info,
1.457 albertel 4612: .LC_success,
4613: .LC_diff_added {
1.350 albertel 4614: color: green;
4615: }
1.795 www 4616:
1.802 bisitz 4617: div.LC_confirm_box {
4618: background-color: #FAFAFA;
4619: border: 1px solid $lg_border_color;
4620: margin-right: 0;
4621: padding: 5px;
4622: }
4623:
4624: div.LC_confirm_box .LC_error img,
4625: div.LC_confirm_box .LC_success img {
4626: vertical-align: middle;
4627: }
4628:
1.440 albertel 4629: .LC_icon {
1.771 droeschl 4630: border: none;
1.790 droeschl 4631: vertical-align: middle;
1.771 droeschl 4632: }
4633:
1.543 albertel 4634: .LC_docs_spacer {
4635: width: 25px;
4636: height: 1px;
1.771 droeschl 4637: border: none;
1.543 albertel 4638: }
1.346 albertel 4639:
1.532 albertel 4640: .LC_internal_info {
1.735 bisitz 4641: color: #999999;
1.532 albertel 4642: }
4643:
1.794 www 4644: .LC_discussion {
4645: background: $tabbg;
4646: border: 1px solid black;
4647: margin: 2px;
4648: }
4649:
4650: .LC_disc_action_links_bar {
4651: background: $tabbg;
1.803 bisitz 4652: border: none;
1.795 www 4653: margin: 4px;
1.794 www 4654: }
4655:
4656: .LC_disc_action_left {
4657: text-align: left;
4658: }
4659:
4660: .LC_disc_action_right {
4661: text-align: right;
4662: }
4663:
4664: .LC_disc_new_item {
4665: background: white;
4666: border: 2px solid red;
4667: margin: 2px;
4668: }
4669:
4670: .LC_disc_old_item {
4671: background: white;
4672: border: 1px solid black;
4673: margin: 2px;
4674: }
4675:
1.458 albertel 4676: table.LC_pastsubmission {
4677: border: 1px solid black;
4678: margin: 2px;
4679: }
4680:
1.795 www 4681: table#LC_top_nav,
4682: table#LC_menubuttons,
4683: table#LC_nav_location {
1.345 albertel 4684: width: 100%;
4685: background: $pgbg;
1.392 albertel 4686: border: 2px;
1.402 albertel 4687: border-collapse: separate;
1.803 bisitz 4688: padding: 0;
1.345 albertel 4689: }
1.392 albertel 4690:
1.801 tempelho 4691: table#LC_title_bar a {
4692: color: $fontmenu;
4693: }
1.836 bisitz 4694:
1.807 droeschl 4695: table#LC_title_bar {
1.819 tempelho 4696: clear: both;
1.836 bisitz 4697: display: none;
1.807 droeschl 4698: }
4699:
1.795 www 4700: table#LC_title_bar,
4701: table.LC_breadcrumbs,
1.393 albertel 4702: table#LC_title_bar.LC_with_remote {
1.359 albertel 4703: width: 100%;
1.392 albertel 4704: border-color: $pgbg;
4705: border-style: solid;
4706: border-width: $border;
1.379 albertel 4707: background: $pgbg;
1.801 tempelho 4708: color: $fontmenu;
1.392 albertel 4709: border-collapse: collapse;
1.803 bisitz 4710: padding: 0;
1.819 tempelho 4711: margin: 0;
1.359 albertel 4712: }
1.795 www 4713:
1.359 albertel 4714: table#LC_title_bar td {
4715: background: $tabbg;
4716: }
1.795 www 4717:
1.706 harmsja 4718: table#LC_menubuttons img{
1.803 bisitz 4719: border: none;
1.346 albertel 4720: }
1.795 www 4721:
1.345 albertel 4722: table#LC_top_nav td {
4723: background: $tabbg;
1.803 bisitz 4724: border: none;
1.407 albertel 4725: font-size: small;
1.706 harmsja 4726: vertical-align:top;
4727: padding:2px 5px 2px 5px;
1.345 albertel 4728: }
1.795 www 4729:
4730: table#LC_top_nav td a,
4731: div#LC_top_nav a {
1.345 albertel 4732: color: $font;
4733: }
1.795 www 4734:
1.364 albertel 4735: table#LC_top_nav td.LC_top_nav_logo {
4736: background: $tabbg;
1.432 albertel 4737: text-align: left;
1.408 albertel 4738: white-space: nowrap;
1.432 albertel 4739: width: 31px;
1.408 albertel 4740: }
1.795 www 4741:
1.408 albertel 4742: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4743: border: none;
1.408 albertel 4744: vertical-align: bottom;
1.364 albertel 4745: }
1.795 www 4746:
1.777 tempelho 4747: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4748: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4749: width: 2.0em;
4750: }
1.795 www 4751:
1.442 albertel 4752: table#LC_top_nav td.LC_top_nav_login {
4753: width: 4.0em;
4754: text-align: center;
4755: }
1.795 www 4756:
1.842 droeschl 4757: .LC_breadcrumbs_component {
4758: float: right;
4759: margin: 0 1em;
1.357 albertel 4760: }
1.842 droeschl 4761: .LC_breadcrumbs_component img {
4762: vertical-align: middle;
1.777 tempelho 4763: }
1.795 www 4764:
1.383 albertel 4765: td.LC_table_cell_checkbox {
4766: text-align: center;
4767: }
1.795 www 4768:
1.779 bisitz 4769: table#LC_mainmenu td.LC_mainmenu_column {
4770: vertical-align: top;
1.777 tempelho 4771: }
1.522 albertel 4772:
1.795 www 4773: .LC_fontsize_small {
1.705 tempelho 4774: font-size: 70%;
4775: }
4776:
1.844 bisitz 4777: #LC_breadcrumbs {
1.819 tempelho 4778: clear:both;
4779: background: $sidebg;
1.822 bisitz 4780: border-bottom: 1px solid $lg_border_color;
1.819 tempelho 4781: line-height: 32px;
1.822 bisitz 4782: margin: 0;
1.819 tempelho 4783: padding: 0;
4784: }
1.862 bisitz 4785:
1.839 droeschl 4786: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4787: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4788: display:none;
4789: }
1.819 tempelho 4790:
1.844 bisitz 4791: #LC_head_subbox {
1.822 bisitz 4792: clear:both;
4793: background: #F8F8F8; /* $sidebg; */
4794: border-bottom: 1px solid $lg_border_color;
4795: margin: 0 0 10px 0;
4796: padding: 5px;
4797: }
4798:
1.795 www 4799: .LC_fontsize_medium {
1.705 tempelho 4800: font-size: 85%;
4801: }
4802:
1.795 www 4803: .LC_fontsize_large {
1.705 tempelho 4804: font-size: 120%;
4805: }
4806:
1.346 albertel 4807: .LC_menubuttons_inline_text {
4808: color: $font;
1.698 harmsja 4809: font-size: 90%;
1.701 harmsja 4810: padding-left:3px;
1.346 albertel 4811: }
4812:
1.526 www 4813: .LC_menubuttons_link {
4814: text-decoration: none;
4815: }
1.795 www 4816:
1.522 albertel 4817: .LC_menubuttons_category {
1.521 www 4818: color: $font;
1.526 www 4819: background: $pgbg;
1.521 www 4820: font-size: larger;
4821: font-weight: bold;
4822: }
4823:
1.346 albertel 4824: td.LC_menubuttons_text {
1.779 bisitz 4825: color: $font;
1.346 albertel 4826: }
1.706 harmsja 4827:
1.346 albertel 4828: .LC_current_location {
4829: background: $tabbg;
4830: }
1.795 www 4831:
1.346 albertel 4832: .LC_new_mail {
1.634 www 4833: background: $tabbg;
1.346 albertel 4834: font-weight: bold;
4835: }
1.347 albertel 4836:
1.666 raeburn 4837: .LC_roleslog_note {
1.701 harmsja 4838: font-size: small;
1.666 raeburn 4839: }
4840:
1.795 www 4841: table.LC_data_table,
4842: table.LC_mail_list {
1.347 albertel 4843: border: 1px solid #000000;
1.402 albertel 4844: border-collapse: separate;
1.426 albertel 4845: border-spacing: 1px;
1.610 albertel 4846: background: $pgbg;
1.347 albertel 4847: }
1.795 www 4848:
1.422 albertel 4849: .LC_data_table_dense {
4850: font-size: small;
4851: }
1.795 www 4852:
1.507 raeburn 4853: table.LC_nested_outer {
4854: border: 1px solid #000000;
1.589 raeburn 4855: border-collapse: collapse;
1.803 bisitz 4856: border-spacing: 0;
1.507 raeburn 4857: width: 100%;
4858: }
1.795 www 4859:
1.507 raeburn 4860: table.LC_nested {
1.803 bisitz 4861: border: none;
1.589 raeburn 4862: border-collapse: collapse;
1.803 bisitz 4863: border-spacing: 0;
1.507 raeburn 4864: width: 100%;
4865: }
1.795 www 4866:
4867: table.LC_data_table tr th,
4868: table.LC_calendar tr th,
4869: table.LC_mail_list tr th,
1.523 albertel 4870: table.LC_prior_tries tr th {
1.349 albertel 4871: font-weight: bold;
4872: background-color: $data_table_head;
1.801 tempelho 4873: color:$fontmenu;
1.701 harmsja 4874: font-size:90%;
1.347 albertel 4875: }
1.795 www 4876:
1.711 raeburn 4877: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4878: background-color: #CCCCCC;
1.711 raeburn 4879: font-weight: bold;
4880: text-align: left;
4881: }
1.795 www 4882:
1.779 bisitz 4883: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4884: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4885: background-color: $data_table_light;
1.425 albertel 4886: padding: 2px;
1.347 albertel 4887: }
1.795 www 4888:
1.610 albertel 4889: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4890: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4891: background-color: $data_table_dark;
1.709 bisitz 4892: padding: 2px;
1.347 albertel 4893: }
1.795 www 4894:
1.425 albertel 4895: table.LC_data_table tr.LC_data_table_highlight td {
4896: background-color: $data_table_darker;
4897: }
1.795 www 4898:
1.639 raeburn 4899: table.LC_data_table tr td.LC_leftcol_header {
4900: background-color: $data_table_head;
4901: font-weight: bold;
4902: }
1.795 www 4903:
1.451 albertel 4904: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4905: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4906: background-color: #FFFFFF;
1.421 albertel 4907: font-weight: bold;
4908: font-style: italic;
4909: text-align: center;
4910: padding: 8px;
1.347 albertel 4911: }
1.795 www 4912:
1.507 raeburn 4913: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4914: padding: 4ex
4915: }
1.795 www 4916:
1.507 raeburn 4917: table.LC_nested_outer tr th {
4918: font-weight: bold;
1.801 tempelho 4919: color:$fontmenu;
1.507 raeburn 4920: background-color: $data_table_head;
1.701 harmsja 4921: font-size: small;
1.507 raeburn 4922: border-bottom: 1px solid #000000;
4923: }
1.795 www 4924:
1.507 raeburn 4925: table.LC_nested_outer tr td.LC_subheader {
4926: background-color: $data_table_head;
4927: font-weight: bold;
4928: font-size: small;
4929: border-bottom: 1px solid #000000;
4930: text-align: right;
1.451 albertel 4931: }
1.795 www 4932:
1.507 raeburn 4933: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4934: background-color: #CCCCCC;
1.451 albertel 4935: font-weight: bold;
4936: font-size: small;
1.507 raeburn 4937: text-align: center;
4938: }
1.795 www 4939:
1.589 raeburn 4940: table.LC_nested tr.LC_info_row td.LC_left_item,
4941: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4942: text-align: left;
1.451 albertel 4943: }
1.795 www 4944:
1.507 raeburn 4945: table.LC_nested td {
1.735 bisitz 4946: background-color: #FFFFFF;
1.451 albertel 4947: font-size: small;
1.507 raeburn 4948: }
1.795 www 4949:
1.507 raeburn 4950: table.LC_nested_outer tr th.LC_right_item,
4951: table.LC_nested tr.LC_info_row td.LC_right_item,
4952: table.LC_nested tr.LC_odd_row td.LC_right_item,
4953: table.LC_nested tr td.LC_right_item {
1.451 albertel 4954: text-align: right;
4955: }
4956:
1.507 raeburn 4957: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4958: background-color: #EEEEEE;
1.451 albertel 4959: }
4960:
1.473 raeburn 4961: table.LC_createuser {
4962: }
4963:
4964: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4965: font-size: small;
1.473 raeburn 4966: }
4967:
4968: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4969: background-color: #CCCCCC;
1.473 raeburn 4970: font-weight: bold;
4971: text-align: center;
4972: }
4973:
1.349 albertel 4974: table.LC_calendar {
4975: border: 1px solid #000000;
4976: border-collapse: collapse;
4977: }
1.795 www 4978:
1.349 albertel 4979: table.LC_calendar_pickdate {
4980: font-size: xx-small;
4981: }
1.795 www 4982:
1.349 albertel 4983: table.LC_calendar tr td {
4984: border: 1px solid #000000;
4985: vertical-align: top;
4986: }
1.795 www 4987:
1.349 albertel 4988: table.LC_calendar tr td.LC_calendar_day_empty {
4989: background-color: $data_table_dark;
4990: }
1.795 www 4991:
1.779 bisitz 4992: table.LC_calendar tr td.LC_calendar_day_current {
4993: background-color: $data_table_highlight;
1.777 tempelho 4994: }
1.795 www 4995:
1.349 albertel 4996: table.LC_mail_list tr.LC_mail_new {
4997: background-color: $mail_new;
4998: }
1.795 www 4999:
1.349 albertel 5000: table.LC_mail_list tr.LC_mail_new:hover {
5001: background-color: $mail_new_hover;
5002: }
1.795 www 5003:
5004: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5005: }
1.795 www 5006:
5007: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5008: }
1.795 www 5009:
1.349 albertel 5010: table.LC_mail_list tr.LC_mail_read {
5011: background-color: $mail_read;
5012: }
1.795 www 5013:
1.349 albertel 5014: table.LC_mail_list tr.LC_mail_read:hover {
5015: background-color: $mail_read_hover;
5016: }
1.795 www 5017:
1.349 albertel 5018: table.LC_mail_list tr.LC_mail_replied {
5019: background-color: $mail_replied;
5020: }
1.795 www 5021:
1.349 albertel 5022: table.LC_mail_list tr.LC_mail_replied:hover {
5023: background-color: $mail_replied_hover;
5024: }
1.795 www 5025:
1.349 albertel 5026: table.LC_mail_list tr.LC_mail_other {
5027: background-color: $mail_other;
5028: }
1.795 www 5029:
1.349 albertel 5030: table.LC_mail_list tr.LC_mail_other:hover {
5031: background-color: $mail_other_hover;
5032: }
1.494 raeburn 5033:
1.777 tempelho 5034: table.LC_data_table tr > td.LC_browser_file,
5035: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5036: background: #CCFF88;
5037: }
1.795 www 5038:
1.777 tempelho 5039: table.LC_data_table tr > td.LC_browser_file_locked,
5040: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5041: background: #FFAA99;
1.387 albertel 5042: }
1.795 www 5043:
1.777 tempelho 5044: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5045: background: #AAAAAA;
5046: }
1.795 www 5047:
1.777 tempelho 5048: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5049: table.LC_data_table tr > td.LC_browser_file_metamodified {
5050: background: #FFFF77;
1.777 tempelho 5051: }
1.795 www 5052:
1.696 bisitz 5053: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5054: background: #CCCCFF;
1.387 albertel 5055: }
1.696 bisitz 5056:
1.707 bisitz 5057: table.LC_data_table tr > td.LC_roles_is {
5058: /* background: #77FF77; */
5059: }
1.795 www 5060:
1.707 bisitz 5061: table.LC_data_table tr > td.LC_roles_future {
5062: background: #FFFF77;
5063: }
1.795 www 5064:
1.707 bisitz 5065: table.LC_data_table tr > td.LC_roles_will {
5066: background: #FFAA77;
5067: }
1.795 www 5068:
1.707 bisitz 5069: table.LC_data_table tr > td.LC_roles_expired {
5070: background: #FF7777;
5071: }
1.795 www 5072:
1.707 bisitz 5073: table.LC_data_table tr > td.LC_roles_will_not {
5074: background: #AAFF77;
5075: }
1.795 www 5076:
1.707 bisitz 5077: table.LC_data_table tr > td.LC_roles_selected {
5078: background: #11CC55;
5079: }
5080:
1.388 albertel 5081: span.LC_current_location {
1.701 harmsja 5082: font-size:larger;
1.388 albertel 5083: background: $pgbg;
5084: }
1.387 albertel 5085:
1.395 albertel 5086: span.LC_parm_menu_item {
5087: font-size: larger;
5088: }
1.795 www 5089:
1.395 albertel 5090: span.LC_parm_scope_all {
5091: color: red;
5092: }
1.795 www 5093:
1.395 albertel 5094: span.LC_parm_scope_folder {
5095: color: green;
5096: }
1.795 www 5097:
1.395 albertel 5098: span.LC_parm_scope_resource {
5099: color: orange;
5100: }
1.795 www 5101:
1.395 albertel 5102: span.LC_parm_part {
5103: color: blue;
5104: }
1.795 www 5105:
1.395 albertel 5106: span.LC_parm_folder, span.LC_parm_symb {
5107: font-size: x-small;
5108: font-family: $mono;
5109: color: #AAAAAA;
5110: }
5111:
1.795 www 5112: td.LC_parm_overview_level_menu,
5113: td.LC_parm_overview_map_menu,
5114: td.LC_parm_overview_parm_selectors,
5115: td.LC_parm_overview_restrictions {
1.396 albertel 5116: border: 1px solid black;
5117: border-collapse: collapse;
5118: }
1.795 www 5119:
1.396 albertel 5120: table.LC_parm_overview_restrictions td {
5121: border-width: 1px 4px 1px 4px;
5122: border-style: solid;
5123: border-color: $pgbg;
5124: text-align: center;
5125: }
1.795 www 5126:
1.396 albertel 5127: table.LC_parm_overview_restrictions th {
5128: background: $tabbg;
5129: border-width: 1px 4px 1px 4px;
5130: border-style: solid;
5131: border-color: $pgbg;
5132: }
1.795 www 5133:
1.398 albertel 5134: table#LC_helpmenu {
1.803 bisitz 5135: border: none;
1.398 albertel 5136: height: 55px;
1.803 bisitz 5137: border-spacing: 0;
1.398 albertel 5138: }
5139:
5140: table#LC_helpmenu fieldset legend {
5141: font-size: larger;
5142: }
1.795 www 5143:
1.397 albertel 5144: table#LC_helpmenu_links {
5145: width: 100%;
5146: border: 1px solid black;
5147: background: $pgbg;
1.803 bisitz 5148: padding: 0;
1.397 albertel 5149: border-spacing: 1px;
5150: }
1.795 www 5151:
1.397 albertel 5152: table#LC_helpmenu_links tr td {
5153: padding: 1px;
5154: background: $tabbg;
1.399 albertel 5155: text-align: center;
5156: font-weight: bold;
1.397 albertel 5157: }
1.396 albertel 5158:
1.795 www 5159: table#LC_helpmenu_links a:link,
5160: table#LC_helpmenu_links a:visited,
1.397 albertel 5161: table#LC_helpmenu_links a:active {
5162: text-decoration: none;
5163: color: $font;
5164: }
1.795 www 5165:
1.397 albertel 5166: table#LC_helpmenu_links a:hover {
5167: text-decoration: underline;
5168: color: $vlink;
5169: }
1.396 albertel 5170:
1.417 albertel 5171: .LC_chrt_popup_exists {
5172: border: 1px solid #339933;
5173: margin: -1px;
5174: }
1.795 www 5175:
1.417 albertel 5176: .LC_chrt_popup_up {
5177: border: 1px solid yellow;
5178: margin: -1px;
5179: }
1.795 www 5180:
1.417 albertel 5181: .LC_chrt_popup {
5182: border: 1px solid #8888FF;
5183: background: #CCCCFF;
5184: }
1.795 www 5185:
1.421 albertel 5186: table.LC_pick_box {
5187: border-collapse: separate;
5188: background: white;
5189: border: 1px solid black;
5190: border-spacing: 1px;
5191: }
1.795 www 5192:
1.421 albertel 5193: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5194: background: $sidebg;
1.421 albertel 5195: font-weight: bold;
5196: text-align: right;
1.740 bisitz 5197: vertical-align: top;
1.421 albertel 5198: width: 184px;
5199: padding: 8px;
5200: }
1.795 www 5201:
1.579 raeburn 5202: table.LC_pick_box td.LC_pick_box_value {
5203: text-align: left;
5204: padding: 8px;
5205: }
1.795 www 5206:
1.579 raeburn 5207: table.LC_pick_box td.LC_pick_box_select {
5208: text-align: left;
5209: padding: 8px;
5210: }
1.795 www 5211:
1.424 albertel 5212: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5213: padding: 0;
1.421 albertel 5214: height: 1px;
5215: background: black;
5216: }
1.795 www 5217:
1.421 albertel 5218: table.LC_pick_box td.LC_pick_box_submit {
5219: text-align: right;
5220: }
1.795 www 5221:
1.579 raeburn 5222: table.LC_pick_box td.LC_evenrow_value {
5223: text-align: left;
5224: padding: 8px;
5225: background-color: $data_table_light;
5226: }
1.795 www 5227:
1.579 raeburn 5228: table.LC_pick_box td.LC_oddrow_value {
5229: text-align: left;
5230: padding: 8px;
5231: background-color: $data_table_light;
5232: }
1.795 www 5233:
1.579 raeburn 5234: table.LC_helpform_receipt {
5235: width: 620px;
5236: border-collapse: separate;
5237: background: white;
5238: border: 1px solid black;
5239: border-spacing: 1px;
5240: }
1.795 www 5241:
1.579 raeburn 5242: table.LC_helpform_receipt td.LC_pick_box_title {
5243: background: $tabbg;
5244: font-weight: bold;
5245: text-align: right;
5246: width: 184px;
5247: padding: 8px;
5248: }
1.795 www 5249:
1.579 raeburn 5250: table.LC_helpform_receipt td.LC_evenrow_value {
5251: text-align: left;
5252: padding: 8px;
5253: background-color: $data_table_light;
5254: }
1.795 www 5255:
1.579 raeburn 5256: table.LC_helpform_receipt td.LC_oddrow_value {
5257: text-align: left;
5258: padding: 8px;
5259: background-color: $data_table_light;
5260: }
1.795 www 5261:
1.579 raeburn 5262: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5263: padding: 0;
1.579 raeburn 5264: height: 1px;
5265: background: black;
5266: }
1.795 www 5267:
1.579 raeburn 5268: span.LC_helpform_receipt_cat {
5269: font-weight: bold;
5270: }
1.795 www 5271:
1.424 albertel 5272: table.LC_group_priv_box {
5273: background: white;
5274: border: 1px solid black;
5275: border-spacing: 1px;
5276: }
1.795 www 5277:
1.424 albertel 5278: table.LC_group_priv_box td.LC_pick_box_title {
5279: background: $tabbg;
5280: font-weight: bold;
5281: text-align: right;
5282: width: 184px;
5283: }
1.795 www 5284:
1.424 albertel 5285: table.LC_group_priv_box td.LC_groups_fixed {
5286: background: $data_table_light;
5287: text-align: center;
5288: }
1.795 www 5289:
1.424 albertel 5290: table.LC_group_priv_box td.LC_groups_optional {
5291: background: $data_table_dark;
5292: text-align: center;
5293: }
1.795 www 5294:
1.424 albertel 5295: table.LC_group_priv_box td.LC_groups_functionality {
5296: background: $data_table_darker;
5297: text-align: center;
5298: font-weight: bold;
5299: }
1.795 www 5300:
1.424 albertel 5301: table.LC_group_priv td {
5302: text-align: left;
1.803 bisitz 5303: padding: 0;
1.424 albertel 5304: }
5305:
1.421 albertel 5306: table.LC_notify_front_page {
5307: background: white;
5308: border: 1px solid black;
5309: padding: 8px;
5310: }
1.795 www 5311:
1.421 albertel 5312: table.LC_notify_front_page td {
5313: padding: 8px;
5314: }
1.795 www 5315:
1.424 albertel 5316: .LC_navbuttons {
5317: margin: 2ex 0ex 2ex 0ex;
5318: }
1.795 www 5319:
1.423 albertel 5320: .LC_topic_bar {
5321: font-weight: bold;
5322: width: 100%;
5323: background: $tabbg;
5324: vertical-align: middle;
5325: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5326: padding: 3px;
1.423 albertel 5327: }
1.795 www 5328:
1.423 albertel 5329: .LC_topic_bar span {
5330: vertical-align: middle;
5331: }
1.795 www 5332:
1.423 albertel 5333: .LC_topic_bar img {
5334: vertical-align: bottom;
5335: }
1.795 www 5336:
1.423 albertel 5337: table.LC_course_group_status {
5338: margin: 20px;
5339: }
1.795 www 5340:
1.423 albertel 5341: table.LC_status_selector td {
5342: vertical-align: top;
5343: text-align: center;
1.424 albertel 5344: padding: 4px;
5345: }
1.795 www 5346:
1.599 albertel 5347: div.LC_feedback_link {
1.616 albertel 5348: clear: both;
1.829 kalberla 5349: background: $sidebg;
1.779 bisitz 5350: width: 100%;
1.829 kalberla 5351: padding-bottom: 10px;
5352: border: 1px $tabbg solid;
1.833 kalberla 5353: height: 22px;
5354: line-height: 22px;
5355: padding-top: 5px;
5356: }
5357:
5358: div.LC_feedback_link img {
5359: height: 22px;
1.867 kalberla 5360: vertical-align:middle;
1.829 kalberla 5361: }
5362:
5363: div.LC_feedback_link a{
5364: text-decoration: none;
1.489 raeburn 5365: }
1.795 www 5366:
1.867 kalberla 5367: div.LC_comblock {
5368: display:inline;
5369: color:$font;
5370: font-size:90%;
5371: }
5372:
5373: div.LC_feedback_link div.LC_comblock {
5374: padding-left:5px;
5375: }
5376:
5377: div.LC_feedback_link div.LC_comblock a {
5378: color:$font;
5379: }
5380:
1.489 raeburn 5381: span.LC_feedback_link {
1.858 bisitz 5382: /* background: $feedback_link_bg; */
1.599 albertel 5383: font-size: larger;
5384: }
1.795 www 5385:
1.599 albertel 5386: span.LC_message_link {
1.858 bisitz 5387: /* background: $feedback_link_bg; */
1.599 albertel 5388: font-size: larger;
5389: position: absolute;
5390: right: 1em;
1.489 raeburn 5391: }
1.421 albertel 5392:
1.515 albertel 5393: table.LC_prior_tries {
1.524 albertel 5394: border: 1px solid #000000;
5395: border-collapse: separate;
5396: border-spacing: 1px;
1.515 albertel 5397: }
1.523 albertel 5398:
1.515 albertel 5399: table.LC_prior_tries td {
1.524 albertel 5400: padding: 2px;
1.515 albertel 5401: }
1.523 albertel 5402:
5403: .LC_answer_correct {
1.795 www 5404: background: lightgreen;
5405: color: darkgreen;
5406: padding: 6px;
1.523 albertel 5407: }
1.795 www 5408:
1.523 albertel 5409: .LC_answer_charged_try {
1.797 www 5410: background: #FFAAAA;
1.795 www 5411: color: darkred;
5412: padding: 6px;
1.523 albertel 5413: }
1.795 www 5414:
1.779 bisitz 5415: .LC_answer_not_charged_try,
1.523 albertel 5416: .LC_answer_no_grade,
5417: .LC_answer_late {
1.795 www 5418: background: lightyellow;
1.523 albertel 5419: color: black;
1.795 www 5420: padding: 6px;
1.523 albertel 5421: }
1.795 www 5422:
1.523 albertel 5423: .LC_answer_previous {
1.795 www 5424: background: lightblue;
5425: color: darkblue;
5426: padding: 6px;
1.523 albertel 5427: }
1.795 www 5428:
1.779 bisitz 5429: .LC_answer_no_message {
1.777 tempelho 5430: background: #FFFFFF;
5431: color: black;
1.795 www 5432: padding: 6px;
1.779 bisitz 5433: }
1.795 www 5434:
1.779 bisitz 5435: .LC_answer_unknown {
5436: background: orange;
5437: color: black;
1.795 www 5438: padding: 6px;
1.777 tempelho 5439: }
1.795 www 5440:
1.529 albertel 5441: span.LC_prior_numerical,
5442: span.LC_prior_string,
5443: span.LC_prior_custom,
5444: span.LC_prior_reaction,
5445: span.LC_prior_math {
1.523 albertel 5446: font-family: monospace;
5447: white-space: pre;
5448: }
5449:
1.525 albertel 5450: span.LC_prior_string {
5451: font-family: monospace;
5452: white-space: pre;
5453: }
5454:
1.523 albertel 5455: table.LC_prior_option {
5456: width: 100%;
5457: border-collapse: collapse;
5458: }
1.795 www 5459:
5460: table.LC_prior_rank,
5461: table.LC_prior_match {
1.528 albertel 5462: border-collapse: collapse;
5463: }
1.795 www 5464:
1.528 albertel 5465: table.LC_prior_option tr td,
5466: table.LC_prior_rank tr td,
5467: table.LC_prior_match tr td {
1.524 albertel 5468: border: 1px solid #000000;
1.515 albertel 5469: }
5470:
1.855 bisitz 5471: .LC_nobreak {
1.544 albertel 5472: white-space: nowrap;
1.519 raeburn 5473: }
5474:
1.576 raeburn 5475: span.LC_cusr_emph {
5476: font-style: italic;
5477: }
5478:
1.633 raeburn 5479: span.LC_cusr_subheading {
5480: font-weight: normal;
5481: font-size: 85%;
5482: }
5483:
1.545 albertel 5484: table.LC_docs_documents {
5485: background: #BBBBBB;
1.803 bisitz 5486: border-width: 0;
1.545 albertel 5487: border-collapse: collapse;
5488: }
1.795 www 5489:
1.777 tempelho 5490: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5491: border: 2px solid black;
5492: padding: 4px;
1.777 tempelho 5493: }
1.795 www 5494:
1.861 bisitz 5495: div.LC_docs_entry_move {
1.859 bisitz 5496: border: 1px solid #BBBBBB;
1.545 albertel 5497: background: #DDDDDD;
1.861 bisitz 5498: width: 22px;
1.859 bisitz 5499: padding: 1px;
5500: margin: 0;
1.545 albertel 5501: }
5502:
1.861 bisitz 5503: table.LC_data_table tr > td.LC_docs_entry_commands,
5504: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5505: background: #DDDDDD;
5506: font-size: x-small;
5507: }
1.795 www 5508:
1.861 bisitz 5509: .LC_docs_entry_parameter {
5510: white-space: nowrap;
5511: }
5512:
1.544 albertel 5513: .LC_docs_copy {
1.545 albertel 5514: color: #000099;
1.544 albertel 5515: }
1.795 www 5516:
1.544 albertel 5517: .LC_docs_cut {
1.545 albertel 5518: color: #550044;
1.544 albertel 5519: }
1.795 www 5520:
1.544 albertel 5521: .LC_docs_rename {
1.545 albertel 5522: color: #009900;
1.544 albertel 5523: }
1.795 www 5524:
1.544 albertel 5525: .LC_docs_remove {
1.545 albertel 5526: color: #990000;
5527: }
5528:
1.547 albertel 5529: .LC_docs_reinit_warn,
5530: .LC_docs_ext_edit {
5531: font-size: x-small;
5532: }
5533:
1.545 albertel 5534: table.LC_docs_adddocs td,
5535: table.LC_docs_adddocs th {
5536: border: 1px solid #BBBBBB;
5537: padding: 4px;
5538: background: #DDDDDD;
1.543 albertel 5539: }
5540:
1.584 albertel 5541: table.LC_sty_begin {
5542: background: #BBFFBB;
5543: }
1.795 www 5544:
1.584 albertel 5545: table.LC_sty_end {
5546: background: #FFBBBB;
5547: }
5548:
1.589 raeburn 5549: table.LC_double_column {
1.803 bisitz 5550: border-width: 0;
1.589 raeburn 5551: border-collapse: collapse;
5552: width: 100%;
5553: padding: 2px;
5554: }
5555:
5556: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5557: top: 2px;
1.589 raeburn 5558: left: 2px;
5559: width: 47%;
5560: vertical-align: top;
5561: }
5562:
5563: table.LC_double_column tr td.LC_right_col {
5564: top: 2px;
1.779 bisitz 5565: right: 2px;
1.589 raeburn 5566: width: 47%;
5567: vertical-align: top;
5568: }
5569:
1.594 raeburn 5570: span.LC_role_level {
5571: font-weight: bold;
5572: }
5573:
1.591 raeburn 5574: div.LC_left_float {
5575: float: left;
5576: padding-right: 5%;
1.597 albertel 5577: padding-bottom: 4px;
1.591 raeburn 5578: }
5579:
5580: div.LC_clear_float_header {
1.597 albertel 5581: padding-bottom: 2px;
1.591 raeburn 5582: }
5583:
5584: div.LC_clear_float_footer {
1.597 albertel 5585: padding-top: 10px;
1.591 raeburn 5586: clear: both;
5587: }
5588:
1.597 albertel 5589: div.LC_grade_show_user {
5590: margin-top: 20px;
5591: border: 1px solid black;
5592: }
1.795 www 5593:
1.597 albertel 5594: div.LC_grade_user_name {
5595: background: #DDDDEE;
5596: border-bottom: 1px solid black;
1.705 tempelho 5597: font-weight: bold;
5598: font-size: large;
1.597 albertel 5599: }
1.795 www 5600:
1.597 albertel 5601: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5602: background: #DDEEDD;
5603: }
5604:
5605: div.LC_grade_show_problem,
5606: div.LC_grade_submissions,
5607: div.LC_grade_message_center,
5608: div.LC_grade_info_links,
5609: div.LC_grade_assign {
5610: margin: 5px;
5611: width: 99%;
5612: background: #FFFFFF;
5613: }
1.795 www 5614:
1.597 albertel 5615: div.LC_grade_show_problem_header,
5616: div.LC_grade_submissions_header,
5617: div.LC_grade_message_center_header,
5618: div.LC_grade_assign_header {
1.705 tempelho 5619: font-weight: bold;
5620: font-size: large;
1.597 albertel 5621: }
1.795 www 5622:
1.597 albertel 5623: div.LC_grade_show_problem_problem,
5624: div.LC_grade_submissions_body,
5625: div.LC_grade_message_center_body,
5626: div.LC_grade_assign_body {
5627: border: 1px solid black;
5628: width: 99%;
5629: background: #FFFFFF;
5630: }
1.795 www 5631:
1.598 albertel 5632: span.LC_grade_check_note {
1.705 tempelho 5633: font-weight: normal;
5634: font-size: medium;
1.598 albertel 5635: display: inline;
5636: position: absolute;
5637: right: 1em;
5638: }
1.597 albertel 5639:
1.613 albertel 5640: table.LC_scantron_action {
5641: width: 100%;
5642: }
1.795 www 5643:
1.613 albertel 5644: table.LC_scantron_action tr th {
1.698 harmsja 5645: font-weight:bold;
5646: font-style:normal;
1.613 albertel 5647: }
1.795 www 5648:
1.779 bisitz 5649: .LC_edit_problem_header,
1.614 albertel 5650: div.LC_edit_problem_footer {
1.705 tempelho 5651: font-weight: normal;
5652: font-size: medium;
1.602 albertel 5653: margin: 2px;
1.600 albertel 5654: }
1.795 www 5655:
1.600 albertel 5656: div.LC_edit_problem_header,
1.602 albertel 5657: div.LC_edit_problem_header div,
1.614 albertel 5658: div.LC_edit_problem_footer,
5659: div.LC_edit_problem_footer div,
1.602 albertel 5660: div.LC_edit_problem_editxml_header,
5661: div.LC_edit_problem_editxml_header div {
1.600 albertel 5662: margin-top: 5px;
5663: }
1.795 www 5664:
1.600 albertel 5665: div.LC_edit_problem_header_title {
1.705 tempelho 5666: font-weight: bold;
5667: font-size: larger;
1.602 albertel 5668: background: $tabbg;
5669: padding: 3px;
5670: }
1.795 www 5671:
1.602 albertel 5672: table.LC_edit_problem_header_title {
1.705 tempelho 5673: font-size: larger;
5674: font-weight: bold;
1.602 albertel 5675: width: 100%;
5676: border-color: $pgbg;
5677: border-style: solid;
5678: border-width: $border;
1.600 albertel 5679: background: $tabbg;
1.602 albertel 5680: border-collapse: collapse;
1.803 bisitz 5681: padding: 0;
1.602 albertel 5682: }
5683:
5684: div.LC_edit_problem_discards {
5685: float: left;
5686: padding-bottom: 5px;
5687: }
1.795 www 5688:
1.602 albertel 5689: div.LC_edit_problem_saves {
5690: float: right;
5691: padding-bottom: 5px;
1.600 albertel 5692: }
1.795 www 5693:
1.679 riegler 5694: img.stift{
1.803 bisitz 5695: border-width: 0;
5696: vertical-align: middle;
1.677 riegler 5697: }
1.680 riegler 5698:
1.681 riegler 5699: table#LC_mainmenu{
5700: margin-top:10px;
5701: width:80%;
5702: }
5703:
1.680 riegler 5704: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5705: vertical-align: top;
5706: width: 45%;
5707: }
1.795 www 5708:
1.779 bisitz 5709: .LC_mainmenu_fieldset_category {
5710: color: $font;
5711: background: $pgbg;
5712: font-size: small;
5713: font-weight: bold;
1.777 tempelho 5714: }
1.795 www 5715:
1.716 raeburn 5716: div.LC_createcourse {
5717: margin: 10px 10px 10px 10px;
5718: }
5719:
1.693 droeschl 5720: /* ---- Remove when done ----
5721: # The following styles is part of the redesign of LON-CAPA and are
5722: # subject to change during this project.
5723: # Don't rely on their current functionality as they might be
5724: # changed or removed.
5725: # --------------------------*/
5726:
1.698 harmsja 5727: a:hover,
1.721 harmsja 5728: ol.LC_smallMenu a:hover,
5729: ol#LC_MenuBreadcrumbs a:hover,
5730: ol#LC_PathBreadcrumbs a:hover,
5731: ul#LC_TabMainMenuContent a:hover,
5732: .LC_FormSectionClearButton input:hover
1.795 www 5733: ul.LC_TabContent li:hover a {
1.698 harmsja 5734: color:#BF2317;
5735: text-decoration:none;
1.693 droeschl 5736: }
5737:
1.779 bisitz 5738: h1 {
1.813 bisitz 5739: padding: 0;
1.693 droeschl 5740: line-height:130%;
5741: }
1.698 harmsja 5742:
1.795 www 5743: h2,h3,h4,h5,h6 {
1.803 bisitz 5744: margin: 5px 0 5px 0;
5745: padding: 0;
1.721 harmsja 5746: line-height:130%;
1.693 droeschl 5747: }
1.795 www 5748:
5749: .LC_hcell {
1.698 harmsja 5750: padding:3px 15px 3px 15px;
1.803 bisitz 5751: margin: 0;
1.703 harmsja 5752: background-color:$tabbg;
1.801 tempelho 5753: color:$fontmenu;
1.779 bisitz 5754: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5755: }
1.795 www 5756:
1.840 bisitz 5757: .LC_Box > .LC_hcell {
1.847 tempelho 5758: margin: 0 -10px 10px -10px;
1.835 bisitz 5759: }
5760:
1.721 harmsja 5761: .LC_noBorder {
1.803 bisitz 5762: border: 0;
1.698 harmsja 5763: }
1.693 droeschl 5764:
1.761 tempelho 5765: .LC_Right {
5766: float: right;
1.803 bisitz 5767: margin: 0;
5768: padding: 0;
1.761 tempelho 5769: }
5770:
1.721 harmsja 5771: .LC_FormSectionClearButton input {
1.779 bisitz 5772: background-color:transparent;
1.803 bisitz 5773: border: none;
1.698 harmsja 5774: cursor:pointer;
5775: text-decoration:underline;
1.693 droeschl 5776: }
1.763 bisitz 5777:
5778: .LC_help_open_topic {
5779: color: #FFFFFF;
5780: background-color: #EEEEFF;
5781: margin: 1px;
5782: padding: 4px;
5783: border: 1px solid #000033;
5784: white-space: nowrap;
1.783 amueller 5785: /* vertical-align: middle; */
1.759 neumanie 5786: }
1.693 droeschl 5787:
1.698 harmsja 5788: dl,ul,div,fieldset {
1.803 bisitz 5789: margin: 10px 10px 10px 0;
1.806 bisitz 5790: /* overflow: hidden; */
1.693 droeschl 5791: }
1.795 www 5792:
1.838 bisitz 5793: fieldset > legend {
5794: font-weight: bold;
5795: padding: 0 5px 0 5px;
5796: }
5797:
1.813 bisitz 5798: #LC_nav_bar {
1.807 droeschl 5799: float: left;
1.852 droeschl 5800: margin: 0.2em 0 0 0;
1.807 droeschl 5801: }
5802:
1.813 bisitz 5803: #LC_nav_bar em{
1.807 droeschl 5804: font-weight: bold;
5805: font-style: normal;
5806: }
5807:
5808: ol.LC_smallMenu {
5809: float: right;
1.852 droeschl 5810: margin: 0.2em 0 0 0;
1.807 droeschl 5811: }
5812:
1.852 droeschl 5813: ol#LC_PathBreadcrumbs {
1.803 bisitz 5814: margin: 0;
1.693 droeschl 5815: }
5816:
1.721 harmsja 5817: ol.LC_smallMenu li {
1.693 droeschl 5818: display: inline;
1.803 bisitz 5819: padding: 5px 5px 0 10px;
1.693 droeschl 5820: vertical-align: top;
5821: }
5822:
1.721 harmsja 5823: ol.LC_smallMenu li img {
1.693 droeschl 5824: vertical-align: bottom;
5825: }
5826:
1.721 harmsja 5827: ol.LC_smallMenu a {
1.693 droeschl 5828: font-size: 90%;
5829: color: RGB(80, 80, 80);
5830: text-decoration: none;
5831: }
1.795 www 5832:
1.808 droeschl 5833: ul#LC_TabMainMenuContent {
1.807 droeschl 5834: clear: both;
1.808 droeschl 5835: color: $fontmenu;
5836: background: $tabbg;
5837: list-style: none;
5838: padding: 0;
5839: margin: 0;
5840: width: 100%;
5841: }
5842:
5843: ul#LC_TabMainMenuContent li {
5844: font-weight: bold;
5845: line-height: 1.8em;
5846: padding: 0 0.8em;
5847: border-right: 1px solid black;
5848: display: inline;
5849: vertical-align: middle;
1.807 droeschl 5850: }
5851:
1.847 tempelho 5852: ul.LC_TabContent {
1.721 harmsja 5853: display:block;
1.847 tempelho 5854: background: $sidebg;
1.858 bisitz 5855: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5856: list-style:none;
1.870 tempelho 5857: margin: 0 -10px;
1.803 bisitz 5858: padding: 0;
1.693 droeschl 5859: }
5860:
1.795 www 5861: ul.LC_TabContent li,
5862: ul.LC_TabContentBigger li {
1.741 harmsja 5863: float:left;
5864: }
1.795 www 5865:
1.808 droeschl 5866: ul#LC_TabMainMenuContent li a {
5867: color: $fontmenu;
1.693 droeschl 5868: text-decoration: none;
5869: }
1.795 www 5870:
1.721 harmsja 5871: ul.LC_TabContent {
1.847 tempelho 5872: min-height:1.5em;
1.721 harmsja 5873: }
1.795 www 5874:
5875: ul.LC_TabContent li {
1.741 harmsja 5876: vertical-align:middle;
1.803 bisitz 5877: padding: 0 10px 0 10px;
1.745 ehlerst 5878: background-color:$tabbg;
5879: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5880: }
1.795 www 5881:
1.847 tempelho 5882: ul.LC_TabContent .right {
5883: float:right;
5884: }
5885:
1.795 www 5886: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5887: color:rgb(47,47,47);
5888: text-decoration:none;
5889: font-size:95%;
5890: font-weight:bold;
1.761 tempelho 5891: padding-right: 16px;
1.721 harmsja 5892: }
1.795 www 5893:
5894: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5895: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5896: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5897: padding-right: 16px;
1.744 ehlerst 5898: }
1.795 www 5899:
1.870 tempelho 5900: #maincoursedoc {
5901: clear:both;
5902: }
5903:
5904: ul.LC_TabContentBigger {
5905: display:block;
5906: list-style:none;
5907: padding: 0;
5908: }
5909:
1.795 www 5910: ul.LC_TabContentBigger li {
1.870 tempelho 5911: vertical-align:bottom;
5912: height: 30px;
5913: font-size:110%;
5914: font-weight:bold;
5915: color: #737373;
1.841 tempelho 5916: }
5917:
1.870 tempelho 5918:
5919: ul.LC_TabContentBigger li a {
5920: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
5921: height: 30px;
5922: line-height: 30px;
5923: text-align: center;
5924: display: block;
5925: text-decoration: none;
1.741 harmsja 5926: }
1.795 www 5927:
1.870 tempelho 5928: ul.LC_TabContentBigger li:hover a,
5929: ul.LC_TabContentBigger li.active a {
5930: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857 tempelho 5931: color:$font;
1.870 tempelho 5932: text-decoration: underline;
1.744 ehlerst 5933: }
1.795 www 5934:
1.870 tempelho 5935:
5936: ul.LC_TabContentBigger li b {
5937: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
5938: display: block;
5939: float: left;
5940: padding: 0 30px;
5941: }
5942:
5943: ul.LC_TabContentBigger li:hover b,
5944: ul.LC_TabContentBigger li.active b {
5945: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
5946: color:$font;
5947: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 5948: }
1.693 droeschl 5949:
1.870 tempelho 5950:
1.862 bisitz 5951: ul.LC_CourseBreadcrumbs {
5952: background: $sidebg;
5953: line-height: 32px;
5954: padding-left: 10px;
5955: margin: 0 0 10px 0;
5956: list-style-position: inside;
5957:
5958: }
5959:
1.795 www 5960: ol#LC_MenuBreadcrumbs,
1.862 bisitz 5961: ol#LC_PathBreadcrumbs {
1.693 droeschl 5962: padding-left: 10px;
1.819 tempelho 5963: margin: 0;
1.693 droeschl 5964: list-style-position: inside;
5965: }
5966:
1.795 www 5967: ol#LC_MenuBreadcrumbs li,
5968: ol#LC_PathBreadcrumbs li,
1.862 bisitz 5969: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 5970: display: inline;
5971: white-space: nowrap;
1.693 droeschl 5972: }
5973:
1.823 bisitz 5974: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 5975: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 5976: text-decoration: none;
5977: font-size:90%;
5978: }
1.795 www 5979:
5980: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 5981: text-decoration:none;
5982: font-size:100%;
5983: font-weight:bold;
1.693 droeschl 5984: }
1.795 www 5985:
1.840 bisitz 5986: .LC_Box {
1.835 bisitz 5987: border: solid 1px $lg_border_color;
5988: padding: 0 10px 10px 10px;
1.746 neumanie 5989: }
1.795 www 5990:
5991: .LC_AboutMe_Image {
1.747 neumanie 5992: float:left;
5993: margin-right:10px;
5994: }
1.795 www 5995:
5996: .LC_Clear_AboutMe_Image {
1.747 neumanie 5997: clear:left;
5998: }
1.795 www 5999:
1.721 harmsja 6000: dl.LC_ListStyleClean dt {
1.693 droeschl 6001: padding-right: 5px;
6002: display: table-header-group;
6003: }
6004:
1.721 harmsja 6005: dl.LC_ListStyleClean dd {
1.693 droeschl 6006: display: table-row;
6007: }
6008:
1.721 harmsja 6009: .LC_ListStyleClean,
6010: .LC_ListStyleSimple,
6011: .LC_ListStyleNormal,
1.777 tempelho 6012: .LC_ListStyle_Border,
1.795 www 6013: .LC_ListStyleSpecial {
1.693 droeschl 6014: /*display:block; */
6015: list-style-position: inside;
6016: list-style-type: none;
6017: overflow: hidden;
1.803 bisitz 6018: padding: 0;
1.693 droeschl 6019: }
6020:
1.721 harmsja 6021: .LC_ListStyleSimple li,
6022: .LC_ListStyleSimple dd,
6023: .LC_ListStyleNormal li,
6024: .LC_ListStyleNormal dd,
6025: .LC_ListStyleSpecial li,
1.795 www 6026: .LC_ListStyleSpecial dd {
1.803 bisitz 6027: margin: 0;
1.693 droeschl 6028: padding: 5px 5px 5px 10px;
6029: clear: both;
6030: }
6031:
1.721 harmsja 6032: .LC_ListStyleClean li,
6033: .LC_ListStyleClean dd {
1.803 bisitz 6034: padding-top: 0;
6035: padding-bottom: 0;
1.693 droeschl 6036: }
6037:
1.721 harmsja 6038: .LC_ListStyleSimple dd,
1.795 www 6039: .LC_ListStyleSimple li {
1.698 harmsja 6040: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6041: }
6042:
1.721 harmsja 6043: .LC_ListStyleSpecial li,
6044: .LC_ListStyleSpecial dd {
1.693 droeschl 6045: list-style-type: none;
6046: background-color: RGB(220, 220, 220);
6047: margin-bottom: 4px;
6048: }
6049:
1.721 harmsja 6050: table.LC_SimpleTable {
1.698 harmsja 6051: margin:5px;
6052: border:solid 1px $lg_border_color;
1.795 www 6053: }
1.693 droeschl 6054:
1.721 harmsja 6055: table.LC_SimpleTable tr {
1.803 bisitz 6056: padding: 0;
1.698 harmsja 6057: border:solid 1px $lg_border_color;
1.693 droeschl 6058: }
1.795 www 6059:
6060: table.LC_SimpleTable thead {
1.698 harmsja 6061: background:rgb(220,220,220);
1.693 droeschl 6062: }
6063:
1.721 harmsja 6064: div.LC_columnSection {
1.693 droeschl 6065: display: block;
6066: clear: both;
6067: overflow: hidden;
1.803 bisitz 6068: margin: 0;
1.693 droeschl 6069: }
6070:
1.721 harmsja 6071: div.LC_columnSection>* {
1.693 droeschl 6072: float: left;
1.803 bisitz 6073: margin: 10px 20px 10px 0;
1.747 neumanie 6074: overflow:hidden;
1.693 droeschl 6075: }
1.721 harmsja 6076:
1.694 tempelho 6077: .LC_loginpage_container {
6078: text-align:left;
6079: margin : 0 auto;
1.785 tempelho 6080: width:90%;
1.694 tempelho 6081: padding: 10px;
6082: height: auto;
1.712 muellerd 6083: background-color:#FFFFFF;
1.694 tempelho 6084: border:1px solid #CCCCCC;
6085: }
6086:
6087:
6088: .LC_loginpage_loginContainer {
6089: float:left;
1.712 muellerd 6090: width: 182px;
1.785 tempelho 6091: padding: 2px;
1.712 muellerd 6092: border:1px solid #CCCCCC;
6093: background-color:$loginbg;
1.694 tempelho 6094: }
6095:
1.795 www 6096: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6097: margin-top: 0;
1.712 muellerd 6098: display:block;
6099: background:$bgcol;
6100: color:$textcol;
6101: padding-left:5px;
6102: }
1.785 tempelho 6103:
1.694 tempelho 6104: .LC_loginpage_loginInfo {
6105: float:left;
1.785 tempelho 6106: width:182px;
1.694 tempelho 6107: border:1px solid #CCCCCC;
1.785 tempelho 6108: padding:2px;
1.712 muellerd 6109: }
6110:
1.694 tempelho 6111: .LC_loginpage_space {
1.754 droeschl 6112: clear: both;
6113: margin-bottom: 20px;
1.694 tempelho 6114: border-bottom: 1px solid #CCCCCC;
6115: }
6116:
1.785 tempelho 6117: .LC_loginpage_floatLeft {
6118: float: left;
6119: width: 200px;
6120: margin: 0;
6121: }
6122:
1.795 www 6123: table em {
1.754 droeschl 6124: font-weight: bold;
6125: font-style: normal;
1.748 schulted 6126: }
1.795 www 6127:
1.779 bisitz 6128: table.LC_tableBrowseRes,
1.795 www 6129: table.LC_tableOfContent {
1.769 schulted 6130: border:none;
1.858 bisitz 6131: border-spacing: 1px;
1.754 droeschl 6132: padding: 3px;
6133: background-color: #FFFFFF;
6134: font-size: 90%;
1.753 droeschl 6135: }
1.789 droeschl 6136:
6137: table.LC_tableOfContent{
6138: border-collapse: collapse;
6139: }
6140:
1.771 droeschl 6141: table.LC_tableBrowseRes a,
1.768 schulted 6142: table.LC_tableOfContent a {
1.771 droeschl 6143: background-color: transparent;
1.753 droeschl 6144: text-decoration: none;
6145: }
6146:
1.771 droeschl 6147: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6148: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6149: background-color: #EEEEEE;
1.753 droeschl 6150: }
6151:
1.795 www 6152: table.LC_tableOfContent img {
1.753 droeschl 6153: border: none;
6154: height: 1.3em;
6155: vertical-align: text-bottom;
6156: margin-right: 0.3em;
6157: }
1.757 schulted 6158:
1.795 www 6159: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6160: background-image:url(/res/adm/pages/open-first-problem.gif);
6161: }
6162:
1.795 www 6163: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6164: background-image:url(/res/adm/pages/start-navigation.gif);
6165: }
6166:
1.795 www 6167: a#LC_content_toolbar_closenav {
1.774 ehlerst 6168: background-image:url(/res/adm/pages/close-navigation.gif);
6169: }
6170:
1.795 www 6171: a#LC_content_toolbar_everything {
1.774 ehlerst 6172: background-image:url(/res/adm/pages/show-all.gif);
6173: }
6174:
1.795 www 6175: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6176: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6177: }
6178:
1.795 www 6179: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6180: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6181: }
6182:
1.795 www 6183: a#LC_content_toolbar_changefolder {
1.757 schulted 6184: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6185: }
6186:
1.795 www 6187: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6188: background-image:url(/res/adm/pages/open-all-folders.gif);
6189: }
6190:
1.795 www 6191: ul#LC_toolbar li a:hover {
1.757 schulted 6192: background-position: bottom center;
6193: }
6194:
1.795 www 6195: ul#LC_toolbar {
1.803 bisitz 6196: padding: 0;
1.757 schulted 6197: margin: 2px;
6198: list-style:none;
6199: position:relative;
6200: background-color:white;
6201: }
6202:
1.795 www 6203: ul#LC_toolbar li {
1.757 schulted 6204: border:1px solid white;
1.803 bisitz 6205: padding: 0;
1.757 schulted 6206: margin: 0;
1.795 www 6207: float: left;
1.767 droeschl 6208: display:inline;
1.757 schulted 6209: vertical-align:middle;
1.795 www 6210: }
1.757 schulted 6211:
1.783 amueller 6212:
1.795 www 6213: a.LC_toolbarItem {
1.767 droeschl 6214: display:block;
1.803 bisitz 6215: padding: 0;
6216: margin: 0;
1.757 schulted 6217: height: 32px;
6218: width: 32px;
1.779 bisitz 6219: color:white;
1.803 bisitz 6220: border: none;
1.757 schulted 6221: background-repeat:no-repeat;
6222: background-color:transparent;
6223: }
6224:
1.843 bisitz 6225: ul.LC_funclist li {
1.782 bisitz 6226: float: left;
6227: white-space: nowrap;
6228: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6229: margin: 0 15px 15px 10px;
1.782 bisitz 6230: }
6231:
1.757 schulted 6232:
1.343 albertel 6233: END
6234: }
6235:
1.306 albertel 6236: =pod
6237:
6238: =item * &headtag()
6239:
6240: Returns a uniform footer for LON-CAPA web pages.
6241:
1.307 albertel 6242: Inputs: $title - optional title for the head
6243: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6244: $args - optional arguments
1.319 albertel 6245: force_register - if is true call registerurl so the remote is
6246: informed
1.415 albertel 6247: redirect -> array ref of
6248: 1- seconds before redirect occurs
6249: 2- url to redirect to
6250: 3- whether the side effect should occur
1.315 albertel 6251: (side effect of setting
6252: $env{'internal.head.redirect'} to the url
6253: redirected too)
1.352 albertel 6254: domain -> force to color decorate a page for a specific
6255: domain
6256: function -> force usage of a specific rolish color scheme
6257: bgcolor -> override the default page bgcolor
1.460 albertel 6258: no_auto_mt_title
6259: -> prevent &mt()ing the title arg
1.464 albertel 6260:
1.306 albertel 6261: =cut
6262:
6263: sub headtag {
1.313 albertel 6264: my ($title,$head_extra,$args) = @_;
1.306 albertel 6265:
1.363 albertel 6266: my $function = $args->{'function'} || &get_users_function();
6267: my $domain = $args->{'domain'} || &determinedomain();
6268: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6269: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6270: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6271: #time(),
1.418 albertel 6272: $env{'environment.color.timestamp'},
1.363 albertel 6273: $function,$domain,$bgcolor);
6274:
1.369 www 6275: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6276:
1.308 albertel 6277: my $result =
6278: '<head>'.
1.461 albertel 6279: &font_settings();
1.319 albertel 6280:
1.461 albertel 6281: if (!$args->{'frameset'}) {
6282: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6283: }
1.319 albertel 6284: if ($args->{'force_register'}) {
6285: $result .= &Apache::lonmenu::registerurl(1);
6286: }
1.436 albertel 6287: if (!$args->{'no_nav_bar'}
6288: && !$args->{'only_body'}
6289: && !$args->{'frameset'}) {
6290: $result .= &help_menu_js();
6291: }
1.319 albertel 6292:
1.314 albertel 6293: if (ref($args->{'redirect'})) {
1.414 albertel 6294: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6295: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6296: if (!$inhibit_continue) {
6297: $env{'internal.head.redirect'} = $url;
6298: }
1.313 albertel 6299: $result.=<<ADDMETA
6300: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6301: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6302: ADDMETA
6303: }
1.306 albertel 6304: if (!defined($title)) {
6305: $title = 'The LearningOnline Network with CAPA';
6306: }
1.460 albertel 6307: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6308: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6309: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6310: .$head_extra;
1.306 albertel 6311: return $result;
6312: }
6313:
6314: =pod
6315:
1.340 albertel 6316: =item * &font_settings()
6317:
6318: Returns neccessary <meta> to set the proper encoding
6319:
6320: Inputs: none
6321:
6322: =cut
6323:
6324: sub font_settings {
6325: my $headerstring='';
1.647 www 6326: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6327: $headerstring.=
6328: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6329: }
6330: return $headerstring;
6331: }
6332:
1.341 albertel 6333: =pod
6334:
6335: =item * &xml_begin()
6336:
6337: Returns the needed doctype and <html>
6338:
6339: Inputs: none
6340:
6341: =cut
6342:
6343: sub xml_begin {
6344: my $output='';
6345:
1.592 albertel 6346: if ($env{'internal.start_page'}==1) {
6347: &Apache::lonhtmlcommon::init_htmlareafields();
6348: }
1.342 albertel 6349:
1.341 albertel 6350: if ($env{'browser.mathml'}) {
6351: $output='<?xml version="1.0"?>'
6352: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6353: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6354:
6355: # .'<!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">] >'
6356: .'<!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">'
6357: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6358: .'xmlns="http://www.w3.org/1999/xhtml">';
6359: } else {
1.849 bisitz 6360: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6361: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6362: }
6363: return $output;
6364: }
1.340 albertel 6365:
6366: =pod
6367:
1.306 albertel 6368: =item * &endheadtag()
6369:
6370: Returns a uniform </head> for LON-CAPA web pages.
6371:
6372: Inputs: none
6373:
6374: =cut
6375:
6376: sub endheadtag {
6377: return '</head>';
6378: }
6379:
6380: =pod
6381:
6382: =item * &head()
6383:
6384: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6385:
1.648 raeburn 6386: Inputs:
6387:
6388: =over 4
6389:
6390: $title - optional title for the page
6391:
6392: $head_extra - optional extra HTML to put inside the <head>
6393:
6394: =back
1.405 albertel 6395:
1.306 albertel 6396: =cut
6397:
6398: sub head {
1.325 albertel 6399: my ($title,$head_extra,$args) = @_;
6400: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6401: }
6402:
6403: =pod
6404:
6405: =item * &start_page()
6406:
6407: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6408:
1.648 raeburn 6409: Inputs:
6410:
6411: =over 4
6412:
6413: $title - optional title for the page
6414:
6415: $head_extra - optional extra HTML to incude inside the <head>
6416:
6417: $args - additional optional args supported are:
6418:
6419: =over 8
6420:
6421: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6422: arg on
1.814 bisitz 6423: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6424: add_entries -> additional attributes to add to the <body>
6425: domain -> force to color decorate a page for a
1.317 albertel 6426: specific domain
1.648 raeburn 6427: function -> force usage of a specific rolish color
1.317 albertel 6428: scheme
1.648 raeburn 6429: redirect -> see &headtag()
6430: bgcolor -> override the default page bg color
6431: js_ready -> return a string ready for being used in
1.317 albertel 6432: a javascript writeln
1.648 raeburn 6433: html_encode -> return a string ready for being used in
1.320 albertel 6434: a html attribute
1.648 raeburn 6435: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6436: $forcereg arg
1.648 raeburn 6437: frameset -> if true will start with a <frameset>
1.330 albertel 6438: rather than <body>
1.648 raeburn 6439: skip_phases -> hash ref of
1.338 albertel 6440: head -> skip the <html><head> generation
6441: body -> skip all <body> generation
1.648 raeburn 6442: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6443: 'Switch To Inline Menu' link
1.648 raeburn 6444: no_auto_mt_title -> prevent &mt()ing the title arg
6445: inherit_jsmath -> when creating popup window in a page,
6446: should it have jsmath forced on by the
6447: current page
1.867 kalberla 6448: bread_crumbs -> Array containing breadcrumbs
6449: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6450:
1.648 raeburn 6451: =back
1.460 albertel 6452:
1.648 raeburn 6453: =back
1.562 albertel 6454:
1.306 albertel 6455: =cut
6456:
6457: sub start_page {
1.309 albertel 6458: my ($title,$head_extra,$args) = @_;
1.318 albertel 6459: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6460: my %head_args;
1.352 albertel 6461: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6462: 'bgcolor','frameset','no_nav_bar','only_body',
6463: 'no_auto_mt_title') {
1.319 albertel 6464: if (defined($args->{$arg})) {
1.324 raeburn 6465: $head_args{$arg} = $args->{$arg};
1.319 albertel 6466: }
1.313 albertel 6467: }
1.319 albertel 6468:
1.315 albertel 6469: $env{'internal.start_page'}++;
1.338 albertel 6470: my $result;
6471: if (! exists($args->{'skip_phases'}{'head'}) ) {
6472: $result.=
1.341 albertel 6473: &xml_begin().
1.338 albertel 6474: &headtag($title,$head_extra,\%head_args).&endheadtag();
6475: }
6476:
6477: if (! exists($args->{'skip_phases'}{'body'}) ) {
6478: if ($args->{'frameset'}) {
6479: my $attr_string = &make_attr_string($args->{'force_register'},
6480: $args->{'add_entries'});
6481: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6482: } else {
6483: $result .=
6484: &bodytag($title,
6485: $args->{'function'}, $args->{'add_entries'},
6486: $args->{'only_body'}, $args->{'domain'},
6487: $args->{'force_register'}, $args->{'no_nav_bar'},
6488: $args->{'bgcolor'}, $args->{'no_inline_link'},
6489: $args);
6490: }
1.330 albertel 6491: }
1.338 albertel 6492:
1.315 albertel 6493: if ($args->{'js_ready'}) {
1.713 kaisler 6494: $result = &js_ready($result);
1.315 albertel 6495: }
1.320 albertel 6496: if ($args->{'html_encode'}) {
1.713 kaisler 6497: $result = &html_encode($result);
6498: }
6499:
1.813 bisitz 6500: # Preparation for new and consistent functionlist at top of screen
6501: # if ($args->{'functionlist'}) {
6502: # $result .= &build_functionlist();
6503: #}
6504:
6505: # Don't add anything more if only_body wanted
6506: return $result if $args->{'only_body'};
6507:
6508: #Breadcrumbs
1.758 kaisler 6509: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6510: &Apache::lonhtmlcommon::clear_breadcrumbs();
6511: #if any br links exists, add them to the breadcrumbs
6512: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6513: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6514: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6515: }
6516: }
6517:
6518: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6519: if(exists($args->{'bread_crumbs_component'})){
6520: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6521: }else{
6522: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6523: }
1.320 albertel 6524: }
1.315 albertel 6525: return $result;
1.306 albertel 6526: }
6527:
1.330 albertel 6528:
1.306 albertel 6529: =pod
6530:
6531: =item * &head()
6532:
6533: Returns a complete </body></html> section for LON-CAPA web pages.
6534:
1.315 albertel 6535: Inputs: $args - additional optional args supported are:
6536: js_ready -> return a string ready for being used in
6537: a javascript writeln
1.320 albertel 6538: html_encode -> return a string ready for being used in
6539: a html attribute
1.330 albertel 6540: frameset -> if true will start with a <frameset>
6541: rather than <body>
1.493 albertel 6542: dicsussion -> if true will get discussion from
6543: lonxml::xmlend
6544: (you can pass the target and parser arguments
6545: through optional 'target' and 'parser' args
6546: to this routine)
1.306 albertel 6547:
6548: =cut
6549:
6550: sub end_page {
1.315 albertel 6551: my ($args) = @_;
6552: $env{'internal.end_page'}++;
1.330 albertel 6553: my $result;
1.335 albertel 6554: if ($args->{'discussion'}) {
6555: my ($target,$parser);
6556: if (ref($args->{'discussion'})) {
6557: ($target,$parser) =($args->{'discussion'}{'target'},
6558: $args->{'discussion'}{'parser'});
6559: }
6560: $result .= &Apache::lonxml::xmlend($target,$parser);
6561: }
6562:
1.330 albertel 6563: if ($args->{'frameset'}) {
6564: $result .= '</frameset>';
6565: } else {
1.635 raeburn 6566: $result .= &endbodytag($args);
1.330 albertel 6567: }
6568: $result .= "\n</html>";
6569:
1.315 albertel 6570: if ($args->{'js_ready'}) {
1.317 albertel 6571: $result = &js_ready($result);
1.315 albertel 6572: }
1.335 albertel 6573:
1.320 albertel 6574: if ($args->{'html_encode'}) {
6575: $result = &html_encode($result);
6576: }
1.335 albertel 6577:
1.315 albertel 6578: return $result;
6579: }
6580:
1.320 albertel 6581: sub html_encode {
6582: my ($result) = @_;
6583:
1.322 albertel 6584: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6585:
6586: return $result;
6587: }
1.317 albertel 6588: sub js_ready {
6589: my ($result) = @_;
6590:
1.323 albertel 6591: $result =~ s/[\n\r]/ /xmsg;
6592: $result =~ s/\\/\\\\/xmsg;
6593: $result =~ s/'/\\'/xmsg;
1.372 albertel 6594: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6595:
6596: return $result;
6597: }
6598:
1.315 albertel 6599: sub validate_page {
6600: if ( exists($env{'internal.start_page'})
1.316 albertel 6601: && $env{'internal.start_page'} > 1) {
6602: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6603: $env{'internal.start_page'}.' '.
1.316 albertel 6604: $ENV{'request.filename'});
1.315 albertel 6605: }
6606: if ( exists($env{'internal.end_page'})
1.316 albertel 6607: && $env{'internal.end_page'} > 1) {
6608: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6609: $env{'internal.end_page'}.' '.
1.316 albertel 6610: $env{'request.filename'});
1.315 albertel 6611: }
6612: if ( exists($env{'internal.start_page'})
6613: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6614: &Apache::lonnet::logthis('start_page called without end_page '.
6615: $env{'request.filename'});
1.315 albertel 6616: }
6617: if ( ! exists($env{'internal.start_page'})
6618: && exists($env{'internal.end_page'})) {
1.316 albertel 6619: &Apache::lonnet::logthis('end_page called without start_page'.
6620: $env{'request.filename'});
1.315 albertel 6621: }
1.306 albertel 6622: }
1.315 albertel 6623:
1.318 albertel 6624: sub simple_error_page {
6625: my ($r,$title,$msg) = @_;
6626: my $page =
6627: &Apache::loncommon::start_page($title).
6628: &mt($msg).
6629: &Apache::loncommon::end_page();
6630: if (ref($r)) {
6631: $r->print($page);
1.327 albertel 6632: return;
1.318 albertel 6633: }
6634: return $page;
6635: }
1.347 albertel 6636:
6637: {
1.610 albertel 6638: my @row_count;
1.347 albertel 6639: sub start_data_table {
1.422 albertel 6640: my ($add_class) = @_;
6641: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6642: unshift(@row_count,0);
1.422 albertel 6643: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6644: }
6645:
6646: sub end_data_table {
1.610 albertel 6647: shift(@row_count);
1.389 albertel 6648: return '</table>'."\n";;
1.347 albertel 6649: }
6650:
6651: sub start_data_table_row {
1.422 albertel 6652: my ($add_class) = @_;
1.610 albertel 6653: $row_count[0]++;
6654: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6655: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6656: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6657: }
1.471 banghart 6658:
6659: sub continue_data_table_row {
6660: my ($add_class) = @_;
1.610 albertel 6661: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6662: $css_class = (join(' ',$css_class,$add_class));
6663: return '<tr class="'.$css_class.'">'."\n";;
6664: }
1.347 albertel 6665:
6666: sub end_data_table_row {
1.389 albertel 6667: return '</tr>'."\n";;
1.347 albertel 6668: }
1.367 www 6669:
1.421 albertel 6670: sub start_data_table_empty_row {
1.707 bisitz 6671: # $row_count[0]++;
1.421 albertel 6672: return '<tr class="LC_empty_row" >'."\n";;
6673: }
6674:
6675: sub end_data_table_empty_row {
6676: return '</tr>'."\n";;
6677: }
6678:
1.367 www 6679: sub start_data_table_header_row {
1.389 albertel 6680: return '<tr class="LC_header_row">'."\n";;
1.367 www 6681: }
6682:
6683: sub end_data_table_header_row {
1.389 albertel 6684: return '</tr>'."\n";;
1.367 www 6685: }
1.347 albertel 6686: }
6687:
1.548 albertel 6688: =pod
6689:
6690: =item * &inhibit_menu_check($arg)
6691:
6692: Checks for a inhibitmenu state and generates output to preserve it
6693:
6694: Inputs: $arg - can be any of
6695: - undef - in which case the return value is a string
6696: to add into arguments list of a uri
6697: - 'input' - in which case the return value is a HTML
6698: <form> <input> field of type hidden to
6699: preserve the value
6700: - a url - in which case the return value is the url with
6701: the neccesary cgi args added to preserve the
6702: inhibitmenu state
6703: - a ref to a url - no return value, but the string is
6704: updated to include the neccessary cgi
6705: args to preserve the inhibitmenu state
6706:
6707: =cut
6708:
6709: sub inhibit_menu_check {
6710: my ($arg) = @_;
6711: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6712: if ($arg eq 'input') {
6713: if ($env{'form.inhibitmenu'}) {
6714: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6715: } else {
6716: return
6717: }
6718: }
6719: if ($env{'form.inhibitmenu'}) {
6720: if (ref($arg)) {
6721: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6722: } elsif ($arg eq '') {
6723: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6724: } else {
6725: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6726: }
6727: }
6728: if (!ref($arg)) {
6729: return $arg;
6730: }
6731: }
6732:
1.251 albertel 6733: ###############################################
1.182 matthew 6734:
6735: =pod
6736:
1.549 albertel 6737: =back
6738:
6739: =head1 User Information Routines
6740:
6741: =over 4
6742:
1.405 albertel 6743: =item * &get_users_function()
1.182 matthew 6744:
6745: Used by &bodytag to determine the current users primary role.
6746: Returns either 'student','coordinator','admin', or 'author'.
6747:
6748: =cut
6749:
6750: ###############################################
6751: sub get_users_function {
1.815 tempelho 6752: my $function = 'norole';
1.818 tempelho 6753: if ($env{'request.role'}=~/^(st)/) {
6754: $function='student';
6755: }
1.258 albertel 6756: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6757: $function='coordinator';
6758: }
1.258 albertel 6759: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6760: $function='admin';
6761: }
1.826 bisitz 6762: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6763: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6764: $function='author';
6765: }
6766: return $function;
1.54 www 6767: }
1.99 www 6768:
6769: ###############################################
6770:
1.233 raeburn 6771: =pod
6772:
1.821 raeburn 6773: =item * &show_course()
6774:
6775: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6776: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6777:
6778: Inputs:
6779: None
6780:
6781: Outputs:
6782: Scalar: 1 if 'Course' to be used, 0 otherwise.
6783:
6784: =cut
6785:
6786: ###############################################
6787: sub show_course {
6788: my $course = !$env{'user.adv'};
6789: if (!$env{'user.adv'}) {
6790: foreach my $env (keys(%env)) {
6791: next if ($env !~ m/^user\.priv\./);
6792: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6793: $course = 0;
6794: last;
6795: }
6796: }
6797: }
6798: return $course;
6799: }
6800:
6801: ###############################################
6802:
6803: =pod
6804:
1.542 raeburn 6805: =item * &check_user_status()
1.274 raeburn 6806:
6807: Determines current status of supplied role for a
6808: specific user. Roles can be active, previous or future.
6809:
6810: Inputs:
6811: user's domain, user's username, course's domain,
1.375 raeburn 6812: course's number, optional section ID.
1.274 raeburn 6813:
6814: Outputs:
6815: role status: active, previous or future.
6816:
6817: =cut
6818:
6819: sub check_user_status {
1.412 raeburn 6820: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6821: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6822: my @uroles = keys %userinfo;
6823: my $srchstr;
6824: my $active_chk = 'none';
1.412 raeburn 6825: my $now = time;
1.274 raeburn 6826: if (@uroles > 0) {
1.412 raeburn 6827: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6828: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6829: } else {
1.412 raeburn 6830: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6831: }
6832: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6833: my $role_end = 0;
6834: my $role_start = 0;
6835: $active_chk = 'active';
1.412 raeburn 6836: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6837: $role_end = $1;
6838: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6839: $role_start = $1;
1.274 raeburn 6840: }
6841: }
6842: if ($role_start > 0) {
1.412 raeburn 6843: if ($now < $role_start) {
1.274 raeburn 6844: $active_chk = 'future';
6845: }
6846: }
6847: if ($role_end > 0) {
1.412 raeburn 6848: if ($now > $role_end) {
1.274 raeburn 6849: $active_chk = 'previous';
6850: }
6851: }
6852: }
6853: }
6854: return $active_chk;
6855: }
6856:
6857: ###############################################
6858:
6859: =pod
6860:
1.405 albertel 6861: =item * &get_sections()
1.233 raeburn 6862:
6863: Determines all the sections for a course including
6864: sections with students and sections containing other roles.
1.419 raeburn 6865: Incoming parameters:
6866:
6867: 1. domain
6868: 2. course number
6869: 3. reference to array containing roles for which sections should
6870: be gathered (optional).
6871: 4. reference to array containing status types for which sections
6872: should be gathered (optional).
6873:
6874: If the third argument is undefined, sections are gathered for any role.
6875: If the fourth argument is undefined, sections are gathered for any status.
6876: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6877:
1.374 raeburn 6878: Returns section hash (keys are section IDs, values are
6879: number of users in each section), subject to the
1.419 raeburn 6880: optional roles filter, optional status filter
1.233 raeburn 6881:
6882: =cut
6883:
6884: ###############################################
6885: sub get_sections {
1.419 raeburn 6886: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6887: if (!defined($cdom) || !defined($cnum)) {
6888: my $cid = $env{'request.course.id'};
6889:
6890: return if (!defined($cid));
6891:
6892: $cdom = $env{'course.'.$cid.'.domain'};
6893: $cnum = $env{'course.'.$cid.'.num'};
6894: }
6895:
6896: my %sectioncount;
1.419 raeburn 6897: my $now = time;
1.240 albertel 6898:
1.366 albertel 6899: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6900: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6901: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6902: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6903: my $start_index = &Apache::loncoursedata::CL_START();
6904: my $end_index = &Apache::loncoursedata::CL_END();
6905: my $status;
1.366 albertel 6906: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6907: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6908: $data->[$status_index],
6909: $data->[$start_index],
6910: $data->[$end_index]);
6911: if ($stu_status eq 'Active') {
6912: $status = 'active';
6913: } elsif ($end < $now) {
6914: $status = 'previous';
6915: } elsif ($start > $now) {
6916: $status = 'future';
6917: }
6918: if ($section ne '-1' && $section !~ /^\s*$/) {
6919: if ((!defined($possible_status)) || (($status ne '') &&
6920: (grep/^\Q$status\E$/,@{$possible_status}))) {
6921: $sectioncount{$section}++;
6922: }
1.240 albertel 6923: }
6924: }
6925: }
6926: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6927: foreach my $user (sort(keys(%courseroles))) {
6928: if ($user !~ /^(\w{2})/) { next; }
6929: my ($role) = ($user =~ /^(\w{2})/);
6930: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6931: my ($section,$status);
1.240 albertel 6932: if ($role eq 'cr' &&
6933: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6934: $section=$1;
6935: }
6936: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6937: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6938: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6939: if ($end == -1 && $start == -1) {
6940: next; #deleted role
6941: }
6942: if (!defined($possible_status)) {
6943: $sectioncount{$section}++;
6944: } else {
6945: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6946: $status = 'active';
6947: } elsif ($end < $now) {
6948: $status = 'future';
6949: } elsif ($start > $now) {
6950: $status = 'previous';
6951: }
6952: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6953: $sectioncount{$section}++;
6954: }
6955: }
1.233 raeburn 6956: }
1.366 albertel 6957: return %sectioncount;
1.233 raeburn 6958: }
6959:
1.274 raeburn 6960: ###############################################
1.294 raeburn 6961:
6962: =pod
1.405 albertel 6963:
6964: =item * &get_course_users()
6965:
1.275 raeburn 6966: Retrieves usernames:domains for users in the specified course
6967: with specific role(s), and access status.
6968:
6969: Incoming parameters:
1.277 albertel 6970: 1. course domain
6971: 2. course number
6972: 3. access status: users must have - either active,
1.275 raeburn 6973: previous, future, or all.
1.277 albertel 6974: 4. reference to array of permissible roles
1.288 raeburn 6975: 5. reference to array of section restrictions (optional)
6976: 6. reference to results object (hash of hashes).
6977: 7. reference to optional userdata hash
1.609 raeburn 6978: 8. reference to optional statushash
1.630 raeburn 6979: 9. flag if privileged users (except those set to unhide in
6980: course settings) should be excluded
1.609 raeburn 6981: Keys of top level results hash are roles.
1.275 raeburn 6982: Keys of inner hashes are username:domain, with
6983: values set to access type.
1.288 raeburn 6984: Optional userdata hash returns an array with arguments in the
6985: same order as loncoursedata::get_classlist() for student data.
6986:
1.609 raeburn 6987: Optional statushash returns
6988:
1.288 raeburn 6989: Entries for end, start, section and status are blank because
6990: of the possibility of multiple values for non-student roles.
6991:
1.275 raeburn 6992: =cut
1.405 albertel 6993:
1.275 raeburn 6994: ###############################################
1.405 albertel 6995:
1.275 raeburn 6996: sub get_course_users {
1.630 raeburn 6997: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6998: my %idx = ();
1.419 raeburn 6999: my %seclists;
1.288 raeburn 7000:
7001: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7002: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7003: $idx{end} = &Apache::loncoursedata::CL_END();
7004: $idx{start} = &Apache::loncoursedata::CL_START();
7005: $idx{id} = &Apache::loncoursedata::CL_ID();
7006: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7007: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7008: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7009:
1.290 albertel 7010: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7011: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7012: my $now = time;
1.277 albertel 7013: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7014: my $match = 0;
1.412 raeburn 7015: my $secmatch = 0;
1.419 raeburn 7016: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7017: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7018: if ($section eq '') {
7019: $section = 'none';
7020: }
1.291 albertel 7021: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7022: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7023: $secmatch = 1;
7024: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7025: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7026: $secmatch = 1;
7027: }
7028: } else {
1.419 raeburn 7029: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7030: $secmatch = 1;
7031: }
1.290 albertel 7032: }
1.412 raeburn 7033: if (!$secmatch) {
7034: next;
7035: }
1.419 raeburn 7036: }
1.275 raeburn 7037: if (defined($$types{'active'})) {
1.288 raeburn 7038: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7039: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7040: $match = 1;
1.275 raeburn 7041: }
7042: }
7043: if (defined($$types{'previous'})) {
1.609 raeburn 7044: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7045: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7046: $match = 1;
1.275 raeburn 7047: }
7048: }
7049: if (defined($$types{'future'})) {
1.609 raeburn 7050: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7051: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7052: $match = 1;
1.275 raeburn 7053: }
7054: }
1.609 raeburn 7055: if ($match) {
7056: push(@{$seclists{$student}},$section);
7057: if (ref($userdata) eq 'HASH') {
7058: $$userdata{$student} = $$classlist{$student};
7059: }
7060: if (ref($statushash) eq 'HASH') {
7061: $statushash->{$student}{'st'}{$section} = $status;
7062: }
1.288 raeburn 7063: }
1.275 raeburn 7064: }
7065: }
1.412 raeburn 7066: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7067: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7068: my $now = time;
1.609 raeburn 7069: my %displaystatus = ( previous => 'Expired',
7070: active => 'Active',
7071: future => 'Future',
7072: );
1.630 raeburn 7073: my %nothide;
7074: if ($hidepriv) {
7075: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7076: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7077: if ($user !~ /:/) {
7078: $nothide{join(':',split(/[\@]/,$user))}=1;
7079: } else {
7080: $nothide{$user} = 1;
7081: }
7082: }
7083: }
1.439 raeburn 7084: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7085: my $match = 0;
1.412 raeburn 7086: my $secmatch = 0;
1.439 raeburn 7087: my $status;
1.412 raeburn 7088: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7089: $user =~ s/:$//;
1.439 raeburn 7090: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7091: if ($end == -1 || $start == -1) {
7092: next;
7093: }
7094: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7095: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7096: my ($uname,$udom) = split(/:/,$user);
7097: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7098: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7099: $secmatch = 1;
7100: } elsif ($usec eq '') {
1.420 albertel 7101: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7102: $secmatch = 1;
7103: }
7104: } else {
7105: if (grep(/^\Q$usec\E$/,@{$sections})) {
7106: $secmatch = 1;
7107: }
7108: }
7109: if (!$secmatch) {
7110: next;
7111: }
1.288 raeburn 7112: }
1.419 raeburn 7113: if ($usec eq '') {
7114: $usec = 'none';
7115: }
1.275 raeburn 7116: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7117: if ($hidepriv) {
7118: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7119: (!$nothide{$uname.':'.$udom})) {
7120: next;
7121: }
7122: }
1.503 raeburn 7123: if ($end > 0 && $end < $now) {
1.439 raeburn 7124: $status = 'previous';
7125: } elsif ($start > $now) {
7126: $status = 'future';
7127: } else {
7128: $status = 'active';
7129: }
1.277 albertel 7130: foreach my $type (keys(%{$types})) {
1.275 raeburn 7131: if ($status eq $type) {
1.420 albertel 7132: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7133: push(@{$$users{$role}{$user}},$type);
7134: }
1.288 raeburn 7135: $match = 1;
7136: }
7137: }
1.419 raeburn 7138: if (($match) && (ref($userdata) eq 'HASH')) {
7139: if (!exists($$userdata{$uname.':'.$udom})) {
7140: &get_user_info($udom,$uname,\%idx,$userdata);
7141: }
1.420 albertel 7142: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7143: push(@{$seclists{$uname.':'.$udom}},$usec);
7144: }
1.609 raeburn 7145: if (ref($statushash) eq 'HASH') {
7146: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7147: }
1.275 raeburn 7148: }
7149: }
7150: }
7151: }
1.290 albertel 7152: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7153: if ((defined($cdom)) && (defined($cnum))) {
7154: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7155: if ( defined($csettings{'internal.courseowner'}) ) {
7156: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7157: next if ($owner eq '');
7158: my ($ownername,$ownerdom);
7159: if ($owner =~ /^([^:]+):([^:]+)$/) {
7160: $ownername = $1;
7161: $ownerdom = $2;
7162: } else {
7163: $ownername = $owner;
7164: $ownerdom = $cdom;
7165: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7166: }
7167: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7168: if (defined($userdata) &&
1.609 raeburn 7169: !exists($$userdata{$owner})) {
7170: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7171: if (!grep(/^none$/,@{$seclists{$owner}})) {
7172: push(@{$seclists{$owner}},'none');
7173: }
7174: if (ref($statushash) eq 'HASH') {
7175: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7176: }
1.290 albertel 7177: }
1.279 raeburn 7178: }
7179: }
7180: }
1.419 raeburn 7181: foreach my $user (keys(%seclists)) {
7182: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7183: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7184: }
1.275 raeburn 7185: }
7186: return;
7187: }
7188:
1.288 raeburn 7189: sub get_user_info {
7190: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7191: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7192: &plainname($uname,$udom,'lastname');
1.291 albertel 7193: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7194: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7195: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7196: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7197: return;
7198: }
1.275 raeburn 7199:
1.472 raeburn 7200: ###############################################
7201:
7202: =pod
7203:
7204: =item * &get_user_quota()
7205:
7206: Retrieves quota assigned for storage of portfolio files for a user
7207:
7208: Incoming parameters:
7209: 1. user's username
7210: 2. user's domain
7211:
7212: Returns:
1.536 raeburn 7213: 1. Disk quota (in Mb) assigned to student.
7214: 2. (Optional) Type of setting: custom or default
7215: (individually assigned or default for user's
7216: institutional status).
7217: 3. (Optional) - User's institutional status (e.g., faculty, staff
7218: or student - types as defined in localenroll::inst_usertypes
7219: for user's domain, which determines default quota for user.
7220: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7221:
7222: If a value has been stored in the user's environment,
1.536 raeburn 7223: it will return that, otherwise it returns the maximal default
7224: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7225:
7226: =cut
7227:
7228: ###############################################
7229:
7230:
7231: sub get_user_quota {
7232: my ($uname,$udom) = @_;
1.536 raeburn 7233: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7234: if (!defined($udom)) {
7235: $udom = $env{'user.domain'};
7236: }
7237: if (!defined($uname)) {
7238: $uname = $env{'user.name'};
7239: }
7240: if (($udom eq '' || $uname eq '') ||
7241: ($udom eq 'public') && ($uname eq 'public')) {
7242: $quota = 0;
1.536 raeburn 7243: $quotatype = 'default';
7244: $defquota = 0;
1.472 raeburn 7245: } else {
1.536 raeburn 7246: my $inststatus;
1.472 raeburn 7247: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7248: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7249: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7250: } else {
1.536 raeburn 7251: my %userenv =
7252: &Apache::lonnet::get('environment',['portfolioquota',
7253: 'inststatus'],$udom,$uname);
1.472 raeburn 7254: my ($tmp) = keys(%userenv);
7255: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7256: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7257: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7258: } else {
7259: undef(%userenv);
7260: }
7261: }
1.536 raeburn 7262: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7263: if ($quota eq '') {
1.536 raeburn 7264: $quota = $defquota;
7265: $quotatype = 'default';
7266: } else {
7267: $quotatype = 'custom';
1.472 raeburn 7268: }
7269: }
1.536 raeburn 7270: if (wantarray) {
7271: return ($quota,$quotatype,$settingstatus,$defquota);
7272: } else {
7273: return $quota;
7274: }
1.472 raeburn 7275: }
7276:
7277: ###############################################
7278:
7279: =pod
7280:
7281: =item * &default_quota()
7282:
1.536 raeburn 7283: Retrieves default quota assigned for storage of user portfolio files,
7284: given an (optional) user's institutional status.
1.472 raeburn 7285:
7286: Incoming parameters:
7287: 1. domain
1.536 raeburn 7288: 2. (Optional) institutional status(es). This is a : separated list of
7289: status types (e.g., faculty, staff, student etc.)
7290: which apply to the user for whom the default is being retrieved.
7291: If the institutional status string in undefined, the domain
7292: default quota will be returned.
1.472 raeburn 7293:
7294: Returns:
7295: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7296: 2. (Optional) institutional type which determined the value of the
7297: default quota.
1.472 raeburn 7298:
7299: If a value has been stored in the domain's configuration db,
7300: it will return that, otherwise it returns 20 (for backwards
7301: compatibility with domains which have not set up a configuration
7302: db file; the original statically defined portfolio quota was 20 Mb).
7303:
1.536 raeburn 7304: If the user's status includes multiple types (e.g., staff and student),
7305: the largest default quota which applies to the user determines the
7306: default quota returned.
7307:
1.780 raeburn 7308: =back
7309:
1.472 raeburn 7310: =cut
7311:
7312: ###############################################
7313:
7314:
7315: sub default_quota {
1.536 raeburn 7316: my ($udom,$inststatus) = @_;
7317: my ($defquota,$settingstatus);
7318: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7319: ['quotas'],$udom);
7320: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7321: if ($inststatus ne '') {
1.765 raeburn 7322: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7323: foreach my $item (@statuses) {
1.711 raeburn 7324: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7325: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7326: if ($defquota eq '') {
7327: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7328: $settingstatus = $item;
7329: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7330: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7331: $settingstatus = $item;
7332: }
7333: }
7334: } else {
7335: if ($quotahash{'quotas'}{$item} ne '') {
7336: if ($defquota eq '') {
7337: $defquota = $quotahash{'quotas'}{$item};
7338: $settingstatus = $item;
7339: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7340: $defquota = $quotahash{'quotas'}{$item};
7341: $settingstatus = $item;
7342: }
1.536 raeburn 7343: }
7344: }
7345: }
7346: }
7347: if ($defquota eq '') {
1.711 raeburn 7348: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7349: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7350: } else {
7351: $defquota = $quotahash{'quotas'}{'default'};
7352: }
1.536 raeburn 7353: $settingstatus = 'default';
7354: }
7355: } else {
7356: $settingstatus = 'default';
7357: $defquota = 20;
7358: }
7359: if (wantarray) {
7360: return ($defquota,$settingstatus);
1.472 raeburn 7361: } else {
1.536 raeburn 7362: return $defquota;
1.472 raeburn 7363: }
7364: }
7365:
1.384 raeburn 7366: sub get_secgrprole_info {
7367: my ($cdom,$cnum,$needroles,$type) = @_;
7368: my %sections_count = &get_sections($cdom,$cnum);
7369: my @sections = (sort {$a <=> $b} keys(%sections_count));
7370: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7371: my @groups = sort(keys(%curr_groups));
7372: my $allroles = [];
7373: my $rolehash;
7374: my $accesshash = {
7375: active => 'Currently has access',
7376: future => 'Will have future access',
7377: previous => 'Previously had access',
7378: };
7379: if ($needroles) {
7380: $rolehash = {'all' => 'all'};
1.385 albertel 7381: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7382: if (&Apache::lonnet::error(%user_roles)) {
7383: undef(%user_roles);
7384: }
7385: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7386: my ($role)=split(/\:/,$item,2);
7387: if ($role eq 'cr') { next; }
7388: if ($role =~ /^cr/) {
7389: $$rolehash{$role} = (split('/',$role))[3];
7390: } else {
7391: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7392: }
7393: }
7394: foreach my $key (sort(keys(%{$rolehash}))) {
7395: push(@{$allroles},$key);
7396: }
7397: push (@{$allroles},'st');
7398: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7399: }
7400: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7401: }
7402:
1.555 raeburn 7403: sub user_picker {
1.627 raeburn 7404: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7405: my $currdom = $dom;
7406: my %curr_selected = (
7407: srchin => 'dom',
1.580 raeburn 7408: srchby => 'lastname',
1.555 raeburn 7409: );
7410: my $srchterm;
1.625 raeburn 7411: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7412: if ($srch->{'srchby'} ne '') {
7413: $curr_selected{'srchby'} = $srch->{'srchby'};
7414: }
7415: if ($srch->{'srchin'} ne '') {
7416: $curr_selected{'srchin'} = $srch->{'srchin'};
7417: }
7418: if ($srch->{'srchtype'} ne '') {
7419: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7420: }
7421: if ($srch->{'srchdomain'} ne '') {
7422: $currdom = $srch->{'srchdomain'};
7423: }
7424: $srchterm = $srch->{'srchterm'};
7425: }
7426: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7427: 'usr' => 'Search criteria',
1.563 raeburn 7428: 'doma' => 'Domain/institution to search',
1.558 albertel 7429: 'uname' => 'username',
7430: 'lastname' => 'last name',
1.555 raeburn 7431: 'lastfirst' => 'last name, first name',
1.558 albertel 7432: 'crs' => 'in this course',
1.576 raeburn 7433: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7434: 'alc' => 'all LON-CAPA',
1.573 raeburn 7435: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7436: 'exact' => 'is',
7437: 'contains' => 'contains',
1.569 raeburn 7438: 'begins' => 'begins with',
1.571 raeburn 7439: 'youm' => "You must include some text to search for.",
7440: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7441: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7442: 'yomc' => "You must choose a domain when using an institutional directory search.",
7443: 'ymcd' => "You must choose a domain when using a domain search.",
7444: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7445: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7446: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7447: );
1.563 raeburn 7448: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7449: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7450:
7451: my @srchins = ('crs','dom','alc','instd');
7452:
7453: foreach my $option (@srchins) {
7454: # FIXME 'alc' option unavailable until
7455: # loncreateuser::print_user_query_page()
7456: # has been completed.
7457: next if ($option eq 'alc');
7458: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7459: if ($curr_selected{'srchin'} eq $option) {
7460: $srchinsel .= '
7461: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7462: } else {
7463: $srchinsel .= '
7464: <option value="'.$option.'">'.$lt{$option}.'</option>';
7465: }
1.555 raeburn 7466: }
1.563 raeburn 7467: $srchinsel .= "\n </select>\n";
1.555 raeburn 7468:
7469: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7470: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7471: if ($curr_selected{'srchby'} eq $option) {
7472: $srchbysel .= '
7473: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7474: } else {
7475: $srchbysel .= '
7476: <option value="'.$option.'">'.$lt{$option}.'</option>';
7477: }
7478: }
7479: $srchbysel .= "\n </select>\n";
7480:
7481: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7482: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7483: if ($curr_selected{'srchtype'} eq $option) {
7484: $srchtypesel .= '
7485: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7486: } else {
7487: $srchtypesel .= '
7488: <option value="'.$option.'">'.$lt{$option}.'</option>';
7489: }
7490: }
7491: $srchtypesel .= "\n </select>\n";
7492:
1.558 albertel 7493: my ($newuserscript,$new_user_create);
1.556 raeburn 7494:
7495: if ($forcenewuser) {
1.576 raeburn 7496: if (ref($srch) eq 'HASH') {
7497: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7498: if ($cancreate) {
7499: $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>';
7500: } else {
1.799 bisitz 7501: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7502: my %usertypetext = (
7503: official => 'institutional',
7504: unofficial => 'non-institutional',
7505: );
1.799 bisitz 7506: $new_user_create = '<p class="LC_warning">'
7507: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7508: .' '
7509: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7510: ,'<a href="'.$helplink.'">','</a>')
7511: .'</p><br />';
1.627 raeburn 7512: }
1.576 raeburn 7513: }
7514: }
7515:
1.556 raeburn 7516: $newuserscript = <<"ENDSCRIPT";
7517:
1.570 raeburn 7518: function setSearch(createnew,callingForm) {
1.556 raeburn 7519: if (createnew == 1) {
1.570 raeburn 7520: for (var i=0; i<callingForm.srchby.length; i++) {
7521: if (callingForm.srchby.options[i].value == 'uname') {
7522: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7523: }
7524: }
1.570 raeburn 7525: for (var i=0; i<callingForm.srchin.length; i++) {
7526: if ( callingForm.srchin.options[i].value == 'dom') {
7527: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7528: }
7529: }
1.570 raeburn 7530: for (var i=0; i<callingForm.srchtype.length; i++) {
7531: if (callingForm.srchtype.options[i].value == 'exact') {
7532: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7533: }
7534: }
1.570 raeburn 7535: for (var i=0; i<callingForm.srchdomain.length; i++) {
7536: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7537: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7538: }
7539: }
7540: }
7541: }
7542: ENDSCRIPT
1.558 albertel 7543:
1.556 raeburn 7544: }
7545:
1.555 raeburn 7546: my $output = <<"END_BLOCK";
1.556 raeburn 7547: <script type="text/javascript">
1.824 bisitz 7548: // <![CDATA[
1.570 raeburn 7549: function validateEntry(callingForm) {
1.558 albertel 7550:
1.556 raeburn 7551: var checkok = 1;
1.558 albertel 7552: var srchin;
1.570 raeburn 7553: for (var i=0; i<callingForm.srchin.length; i++) {
7554: if ( callingForm.srchin[i].checked ) {
7555: srchin = callingForm.srchin[i].value;
1.558 albertel 7556: }
7557: }
7558:
1.570 raeburn 7559: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7560: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7561: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7562: var srchterm = callingForm.srchterm.value;
7563: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7564: var msg = "";
7565:
7566: if (srchterm == "") {
7567: checkok = 0;
1.571 raeburn 7568: msg += "$lt{'youm'}\\n";
1.556 raeburn 7569: }
7570:
1.569 raeburn 7571: if (srchtype== 'begins') {
7572: if (srchterm.length < 2) {
7573: checkok = 0;
1.571 raeburn 7574: msg += "$lt{'thte'}\\n";
1.569 raeburn 7575: }
7576: }
7577:
1.556 raeburn 7578: if (srchtype== 'contains') {
7579: if (srchterm.length < 3) {
7580: checkok = 0;
1.571 raeburn 7581: msg += "$lt{'thet'}\\n";
1.556 raeburn 7582: }
7583: }
7584: if (srchin == 'instd') {
7585: if (srchdomain == '') {
7586: checkok = 0;
1.571 raeburn 7587: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7588: }
7589: }
7590: if (srchin == 'dom') {
7591: if (srchdomain == '') {
7592: checkok = 0;
1.571 raeburn 7593: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7594: }
7595: }
7596: if (srchby == 'lastfirst') {
7597: if (srchterm.indexOf(",") == -1) {
7598: checkok = 0;
1.571 raeburn 7599: msg += "$lt{'whus'}\\n";
1.556 raeburn 7600: }
7601: if (srchterm.indexOf(",") == srchterm.length -1) {
7602: checkok = 0;
1.571 raeburn 7603: msg += "$lt{'whse'}\\n";
1.556 raeburn 7604: }
7605: }
7606: if (checkok == 0) {
1.571 raeburn 7607: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7608: return;
7609: }
7610: if (checkok == 1) {
1.570 raeburn 7611: callingForm.submit();
1.556 raeburn 7612: }
7613: }
7614:
7615: $newuserscript
7616:
1.824 bisitz 7617: // ]]>
1.556 raeburn 7618: </script>
1.558 albertel 7619:
7620: $new_user_create
7621:
1.555 raeburn 7622: <table>
1.558 albertel 7623: <tr>
1.573 raeburn 7624: <td>$lt{'doma'}:</td>
7625: <td>$domform</td>
7626: </td>
7627: </tr>
7628: <tr>
7629: <td>$lt{'usr'}:</td>
1.563 raeburn 7630: <td>$srchbysel
7631: $srchtypesel
7632: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7633: $srchinsel
1.563 raeburn 7634: </td>
7635: </tr>
1.555 raeburn 7636: </table>
7637: <br />
7638: END_BLOCK
1.558 albertel 7639:
1.555 raeburn 7640: return $output;
7641: }
7642:
1.612 raeburn 7643: sub user_rule_check {
1.615 raeburn 7644: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7645: my $response;
7646: if (ref($usershash) eq 'HASH') {
7647: foreach my $user (keys(%{$usershash})) {
7648: my ($uname,$udom) = split(/:/,$user);
7649: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7650: my ($id,$newuser);
1.612 raeburn 7651: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7652: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7653: $id = $usershash->{$user}->{'id'};
7654: }
7655: my $inst_response;
7656: if (ref($checks) eq 'HASH') {
7657: if (defined($checks->{'username'})) {
1.615 raeburn 7658: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7659: &Apache::lonnet::get_instuser($udom,$uname);
7660: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7661: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7662: &Apache::lonnet::get_instuser($udom,undef,$id);
7663: }
1.615 raeburn 7664: } else {
7665: ($inst_response,%{$inst_results->{$user}}) =
7666: &Apache::lonnet::get_instuser($udom,$uname);
7667: return;
1.612 raeburn 7668: }
1.615 raeburn 7669: if (!$got_rules->{$udom}) {
1.612 raeburn 7670: my %domconfig = &Apache::lonnet::get_dom('configuration',
7671: ['usercreation'],$udom);
7672: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7673: foreach my $item ('username','id') {
1.612 raeburn 7674: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7675: $$curr_rules{$udom}{$item} =
7676: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7677: }
7678: }
7679: }
1.615 raeburn 7680: $got_rules->{$udom} = 1;
1.585 raeburn 7681: }
1.612 raeburn 7682: foreach my $item (keys(%{$checks})) {
7683: if (ref($$curr_rules{$udom}) eq 'HASH') {
7684: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7685: if (@{$$curr_rules{$udom}{$item}} > 0) {
7686: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7687: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7688: if ($rule_check{$rule}) {
7689: $$rulematch{$user}{$item} = $rule;
7690: if ($inst_response eq 'ok') {
1.615 raeburn 7691: if (ref($inst_results) eq 'HASH') {
7692: if (ref($inst_results->{$user}) eq 'HASH') {
7693: if (keys(%{$inst_results->{$user}}) == 0) {
7694: $$alerts{$item}{$udom}{$uname} = 1;
7695: }
1.612 raeburn 7696: }
7697: }
1.615 raeburn 7698: }
7699: last;
1.585 raeburn 7700: }
7701: }
7702: }
7703: }
7704: }
7705: }
7706: }
7707: }
1.612 raeburn 7708: return;
7709: }
7710:
7711: sub user_rule_formats {
7712: my ($domain,$domdesc,$curr_rules,$check) = @_;
7713: my %text = (
7714: 'username' => 'Usernames',
7715: 'id' => 'IDs',
7716: );
7717: my $output;
7718: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7719: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7720: if (@{$ruleorder} > 0) {
7721: $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>';
7722: foreach my $rule (@{$ruleorder}) {
7723: if (ref($curr_rules) eq 'ARRAY') {
7724: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7725: if (ref($rules->{$rule}) eq 'HASH') {
7726: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7727: $rules->{$rule}{'desc'}.'</li>';
7728: }
7729: }
7730: }
7731: }
7732: $output .= '</ul>';
7733: }
7734: }
7735: return $output;
7736: }
7737:
7738: sub instrule_disallow_msg {
1.615 raeburn 7739: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7740: my $response;
7741: my %text = (
7742: item => 'username',
7743: items => 'usernames',
7744: match => 'matches',
7745: do => 'does',
7746: action => 'a username',
7747: one => 'one',
7748: );
7749: if ($count > 1) {
7750: $text{'item'} = 'usernames';
7751: $text{'match'} ='match';
7752: $text{'do'} = 'do';
7753: $text{'action'} = 'usernames',
7754: $text{'one'} = 'ones';
7755: }
7756: if ($checkitem eq 'id') {
7757: $text{'items'} = 'IDs';
7758: $text{'item'} = 'ID';
7759: $text{'action'} = 'an ID';
1.615 raeburn 7760: if ($count > 1) {
7761: $text{'item'} = 'IDs';
7762: $text{'action'} = 'IDs';
7763: }
1.612 raeburn 7764: }
1.674 bisitz 7765: $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 7766: if ($mode eq 'upload') {
7767: if ($checkitem eq 'username') {
7768: $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'}.");
7769: } elsif ($checkitem eq 'id') {
1.674 bisitz 7770: $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 7771: }
1.669 raeburn 7772: } elsif ($mode eq 'selfcreate') {
7773: if ($checkitem eq 'id') {
7774: $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.");
7775: }
1.615 raeburn 7776: } else {
7777: if ($checkitem eq 'username') {
7778: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7779: } elsif ($checkitem eq 'id') {
7780: $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.");
7781: }
1.612 raeburn 7782: }
7783: return $response;
1.585 raeburn 7784: }
7785:
1.624 raeburn 7786: sub personal_data_fieldtitles {
7787: my %fieldtitles = &Apache::lonlocal::texthash (
7788: id => 'Student/Employee ID',
7789: permanentemail => 'E-mail address',
7790: lastname => 'Last Name',
7791: firstname => 'First Name',
7792: middlename => 'Middle Name',
7793: generation => 'Generation',
7794: gen => 'Generation',
1.765 raeburn 7795: inststatus => 'Affiliation',
1.624 raeburn 7796: );
7797: return %fieldtitles;
7798: }
7799:
1.642 raeburn 7800: sub sorted_inst_types {
7801: my ($dom) = @_;
7802: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7803: my $othertitle = &mt('All users');
7804: if ($env{'request.course.id'}) {
1.668 raeburn 7805: $othertitle = &mt('Any users');
1.642 raeburn 7806: }
7807: my @types;
7808: if (ref($order) eq 'ARRAY') {
7809: @types = @{$order};
7810: }
7811: if (@types == 0) {
7812: if (ref($usertypes) eq 'HASH') {
7813: @types = sort(keys(%{$usertypes}));
7814: }
7815: }
7816: if (keys(%{$usertypes}) > 0) {
7817: $othertitle = &mt('Other users');
7818: }
7819: return ($othertitle,$usertypes,\@types);
7820: }
7821:
1.645 raeburn 7822: sub get_institutional_codes {
7823: my ($settings,$allcourses,$LC_code) = @_;
7824: # Get complete list of course sections to update
7825: my @currsections = ();
7826: my @currxlists = ();
7827: my $coursecode = $$settings{'internal.coursecode'};
7828:
7829: if ($$settings{'internal.sectionnums'} ne '') {
7830: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7831: }
7832:
7833: if ($$settings{'internal.crosslistings'} ne '') {
7834: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7835: }
7836:
7837: if (@currxlists > 0) {
7838: foreach (@currxlists) {
7839: if (m/^([^:]+):(\w*)$/) {
7840: unless (grep/^$1$/,@{$allcourses}) {
7841: push @{$allcourses},$1;
7842: $$LC_code{$1} = $2;
7843: }
7844: }
7845: }
7846: }
7847:
7848: if (@currsections > 0) {
7849: foreach (@currsections) {
7850: if (m/^(\w+):(\w*)$/) {
7851: my $sec = $coursecode.$1;
7852: my $lc_sec = $2;
7853: unless (grep/^$sec$/,@{$allcourses}) {
7854: push @{$allcourses},$sec;
7855: $$LC_code{$sec} = $lc_sec;
7856: }
7857: }
7858: }
7859: }
7860: return;
7861: }
7862:
1.112 bowersj2 7863: =pod
7864:
1.780 raeburn 7865: =head1 Slot Helpers
7866:
7867: =over 4
7868:
7869: =item * sorted_slots()
7870:
7871: Sorts an array of slot names in order of slot start time (earliest first).
7872:
7873: Inputs:
7874:
7875: =over 4
7876:
7877: slotsarr - Reference to array of unsorted slot names.
7878:
7879: slots - Reference to hash of hash, where outer hash keys are slot names.
7880:
1.549 albertel 7881: =back
7882:
1.780 raeburn 7883: Returns:
7884:
7885: =over 4
7886:
7887: sorted - An array of slot names sorted by the start time of the slot.
7888:
7889: =back
7890:
7891: =back
7892:
7893: =cut
7894:
7895:
7896: sub sorted_slots {
7897: my ($slotsarr,$slots) = @_;
7898: my @sorted;
7899: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7900: @sorted =
7901: sort {
7902: if (ref($slots->{$a}) && ref($slots->{$b})) {
7903: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7904: }
7905: if (ref($slots->{$a})) { return -1;}
7906: if (ref($slots->{$b})) { return 1;}
7907: return 0;
7908: } @{$slotsarr};
7909: }
7910: return @sorted;
7911: }
7912:
7913:
7914: =pod
7915:
1.549 albertel 7916: =head1 HTTP Helpers
7917:
7918: =over 4
7919:
1.648 raeburn 7920: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7921:
1.258 albertel 7922: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7923: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7924: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7925:
7926: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7927: $possible_names is an ref to an array of form element names. As an example:
7928: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7929: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7930:
7931: =cut
1.1 albertel 7932:
1.6 albertel 7933: sub get_unprocessed_cgi {
1.25 albertel 7934: my ($query,$possible_names)= @_;
1.26 matthew 7935: # $Apache::lonxml::debug=1;
1.356 albertel 7936: foreach my $pair (split(/&/,$query)) {
7937: my ($name, $value) = split(/=/,$pair);
1.369 www 7938: $name = &unescape($name);
1.25 albertel 7939: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7940: $value =~ tr/+/ /;
7941: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7942: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7943: }
1.16 harris41 7944: }
1.6 albertel 7945: }
7946:
1.112 bowersj2 7947: =pod
7948:
1.648 raeburn 7949: =item * &cacheheader()
1.112 bowersj2 7950:
7951: returns cache-controlling header code
7952:
7953: =cut
7954:
1.7 albertel 7955: sub cacheheader {
1.258 albertel 7956: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7957: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7958: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7959: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7960: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7961: return $output;
1.7 albertel 7962: }
7963:
1.112 bowersj2 7964: =pod
7965:
1.648 raeburn 7966: =item * &no_cache($r)
1.112 bowersj2 7967:
7968: specifies header code to not have cache
7969:
7970: =cut
7971:
1.9 albertel 7972: sub no_cache {
1.216 albertel 7973: my ($r) = @_;
7974: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7975: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7976: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7977: $r->no_cache(1);
7978: $r->header_out("Expires" => $date);
7979: $r->header_out("Pragma" => "no-cache");
1.123 www 7980: }
7981:
7982: sub content_type {
1.181 albertel 7983: my ($r,$type,$charset) = @_;
1.299 foxr 7984: if ($r) {
7985: # Note that printout.pl calls this with undef for $r.
7986: &no_cache($r);
7987: }
1.258 albertel 7988: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7989: unless ($charset) {
7990: $charset=&Apache::lonlocal::current_encoding;
7991: }
7992: if ($charset) { $type.='; charset='.$charset; }
7993: if ($r) {
7994: $r->content_type($type);
7995: } else {
7996: print("Content-type: $type\n\n");
7997: }
1.9 albertel 7998: }
1.25 albertel 7999:
1.112 bowersj2 8000: =pod
8001:
1.648 raeburn 8002: =item * &add_to_env($name,$value)
1.112 bowersj2 8003:
1.258 albertel 8004: adds $name to the %env hash with value
1.112 bowersj2 8005: $value, if $name already exists, the entry is converted to an array
8006: reference and $value is added to the array.
8007:
8008: =cut
8009:
1.25 albertel 8010: sub add_to_env {
8011: my ($name,$value)=@_;
1.258 albertel 8012: if (defined($env{$name})) {
8013: if (ref($env{$name})) {
1.25 albertel 8014: #already have multiple values
1.258 albertel 8015: push(@{ $env{$name} },$value);
1.25 albertel 8016: } else {
8017: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8018: my $first=$env{$name};
8019: undef($env{$name});
8020: push(@{ $env{$name} },$first,$value);
1.25 albertel 8021: }
8022: } else {
1.258 albertel 8023: $env{$name}=$value;
1.25 albertel 8024: }
1.31 albertel 8025: }
1.149 albertel 8026:
8027: =pod
8028:
1.648 raeburn 8029: =item * &get_env_multiple($name)
1.149 albertel 8030:
1.258 albertel 8031: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8032: values may be defined and end up as an array ref.
8033:
8034: returns an array of values
8035:
8036: =cut
8037:
8038: sub get_env_multiple {
8039: my ($name) = @_;
8040: my @values;
1.258 albertel 8041: if (defined($env{$name})) {
1.149 albertel 8042: # exists is it an array
1.258 albertel 8043: if (ref($env{$name})) {
8044: @values=@{ $env{$name} };
1.149 albertel 8045: } else {
1.258 albertel 8046: $values[0]=$env{$name};
1.149 albertel 8047: }
8048: }
8049: return(@values);
8050: }
8051:
1.660 raeburn 8052: sub ask_for_embedded_content {
8053: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8054: my $upload_output = '
8055: <form name="upload_embedded" action="'.$actionurl.'"
8056: method="post" enctype="multipart/form-data">';
8057: $upload_output .= $state;
1.661 raeburn 8058: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8059:
8060: my $num = 0;
8061: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8062: $upload_output .= &start_data_table_row().
8063: '<td>'.$embed_file.'</td><td>';
8064: if ($args->{'ignore_remote_references'}
8065: && $embed_file =~ m{^\w+://}) {
8066: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8067: } elsif ($args->{'error_on_invalid_names'}
8068: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8069:
8070: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8071:
8072: } else {
8073: $upload_output .='
1.661 raeburn 8074: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8075: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8076: my $attrib = join(':',@{$$allfiles{$embed_file}});
8077: $upload_output .=
8078: "\n\t\t".
8079: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8080: $attrib.'" />';
8081: if (exists($$codebase{$embed_file})) {
8082: $upload_output .=
8083: "\n\t\t".
8084: '<input name="codebase_'.$num.'" type="hidden" value="'.
8085: &escape($$codebase{$embed_file}).'" />';
8086: }
8087: }
8088: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8089: $num++;
8090: }
8091: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8092: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8093: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8094: '.&mt('(only files for which a location has been provided will be uploaded)').'
8095: </form>';
8096: return $upload_output;
8097: }
8098:
1.661 raeburn 8099: sub upload_embedded {
8100: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8101: $current_disk_usage) = @_;
8102: my $output;
8103: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8104: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8105: my $orig_uploaded_filename =
8106: $env{'form.embedded_item_'.$i.'.filename'};
8107:
8108: $env{'form.embedded_orig_'.$i} =
8109: &unescape($env{'form.embedded_orig_'.$i});
8110: my ($path,$fname) =
8111: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8112: # no path, whole string is fname
8113: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8114:
8115: $path = $env{'form.currentpath'}.$path;
8116: $fname = &Apache::lonnet::clean_filename($fname);
8117: # See if there is anything left
8118: next if ($fname eq '');
8119:
8120: # Check if file already exists as a file or directory.
8121: my ($state,$msg);
8122: if ($context eq 'portfolio') {
8123: my $port_path = $dirpath;
8124: if ($group ne '') {
8125: $port_path = "groups/$group/$port_path";
8126: }
8127: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8128: $dir_root,$port_path,$disk_quota,
8129: $current_disk_usage,$uname,$udom);
8130: if ($state eq 'will_exceed_quota'
8131: || $state eq 'file_locked'
8132: || $state eq 'file_exists' ) {
8133: $output .= $msg;
8134: next;
8135: }
8136: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8137: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8138: if ($state eq 'exists') {
8139: $output .= $msg;
8140: next;
8141: }
8142: }
8143: # Check if extension is valid
8144: if (($fname =~ /\.(\w+)$/) &&
8145: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8146: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8147: next;
8148: } elsif (($fname =~ /\.(\w+)$/) &&
8149: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8150: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8151: next;
8152: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8153: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8154: next;
8155: }
8156:
8157: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8158: if ($context eq 'portfolio') {
8159: my $result=
8160: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8161: $dirpath.$path);
8162: if ($result !~ m|^/uploaded/|) {
8163: $output .= '<span class="LC_error">'
8164: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8165: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8166: .'</span><br />';
8167: next;
8168: } else {
8169: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8170: $path.$fname.'</span>').'</p>';
8171: }
8172: } else {
8173: # Save the file
8174: my $target = $env{'form.embedded_item_'.$i};
8175: my $fullpath = $dir_root.$dirpath.'/'.$path;
8176: my $dest = $fullpath.$fname;
8177: my $url = $url_root.$dirpath.'/'.$path.$fname;
8178: my @parts=split(/\//,$fullpath);
8179: my $count;
8180: my $filepath = $dir_root;
8181: for ($count=4;$count<=$#parts;$count++) {
8182: $filepath .= "/$parts[$count]";
8183: if ((-e $filepath)!=1) {
8184: mkdir($filepath,0770);
8185: }
8186: }
8187: my $fh;
8188: if (!open($fh,'>'.$dest)) {
8189: &Apache::lonnet::logthis('Failed to create '.$dest);
8190: $output .= '<span class="LC_error">'.
8191: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8192: '</span><br />';
8193: } else {
8194: if (!print $fh $env{'form.embedded_item_'.$i}) {
8195: &Apache::lonnet::logthis('Failed to write to '.$dest);
8196: $output .= '<span class="LC_error">'.
8197: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8198: '</span><br />';
8199: } else {
8200: if ($context eq 'testbank') {
8201: $output .= &mt('Embedded file uploaded successfully:').
8202: ' <a href="'.$url.'">'.
8203: $orig_uploaded_filename.'</a><br />';
8204: } else {
1.705 tempelho 8205: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8206: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8207: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8208: }
8209: }
8210: close($fh);
8211: }
8212: }
8213: }
8214: return $output;
8215: }
8216:
8217: sub check_for_existing {
8218: my ($path,$fname,$element) = @_;
8219: my ($state,$msg);
8220: if (-d $path.'/'.$fname) {
8221: $state = 'exists';
8222: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8223: } elsif (-e $path.'/'.$fname) {
8224: $state = 'exists';
8225: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8226: }
8227: if ($state eq 'exists') {
8228: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8229: }
8230: return ($state,$msg);
8231: }
8232:
8233: sub check_for_upload {
8234: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8235: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8236: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8237: my $getpropath = 1;
8238: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8239: $getpropath);
8240: my $found_file = 0;
8241: my $locked_file = 0;
8242: foreach my $line (@dir_list) {
8243: my ($file_name)=split(/\&/,$line,2);
8244: if ($file_name eq $fname){
8245: $file_name = $path.$file_name;
8246: if ($group ne '') {
8247: $file_name = $group.$file_name;
8248: }
8249: $found_file = 1;
8250: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8251: $locked_file = 1;
8252: }
8253: }
8254: }
8255: if (($current_disk_usage + $filesize) > $disk_quota){
8256: my $msg = '<span class="LC_error">'.
8257: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8258: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8259: return ('will_exceed_quota',$msg);
8260: } elsif ($found_file) {
8261: if ($locked_file) {
8262: my $msg = '<span class="LC_error">';
8263: $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>');
8264: $msg .= '</span><br />';
8265: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8266: return ('file_locked',$msg);
8267: } else {
8268: my $msg = '<span class="LC_error">';
8269: $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'});
8270: $msg .= '</span>';
8271: $msg .= '<br />';
8272: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8273: return ('file_exists',$msg);
8274: }
8275: }
8276: }
8277:
1.31 albertel 8278:
1.41 ng 8279: =pod
1.45 matthew 8280:
1.464 albertel 8281: =back
1.41 ng 8282:
1.112 bowersj2 8283: =head1 CSV Upload/Handling functions
1.38 albertel 8284:
1.41 ng 8285: =over 4
8286:
1.648 raeburn 8287: =item * &upfile_store($r)
1.41 ng 8288:
8289: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8290: needs $env{'form.upfile'}
1.41 ng 8291: returns $datatoken to be put into hidden field
8292:
8293: =cut
1.31 albertel 8294:
8295: sub upfile_store {
8296: my $r=shift;
1.258 albertel 8297: $env{'form.upfile'}=~s/\r/\n/gs;
8298: $env{'form.upfile'}=~s/\f/\n/gs;
8299: $env{'form.upfile'}=~s/\n+/\n/gs;
8300: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8301:
1.258 albertel 8302: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8303: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8304: {
1.158 raeburn 8305: my $datafile = $r->dir_config('lonDaemons').
8306: '/tmp/'.$datatoken.'.tmp';
8307: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8308: print $fh $env{'form.upfile'};
1.158 raeburn 8309: close($fh);
8310: }
1.31 albertel 8311: }
8312: return $datatoken;
8313: }
8314:
1.56 matthew 8315: =pod
8316:
1.648 raeburn 8317: =item * &load_tmp_file($r)
1.41 ng 8318:
8319: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8320: needs $env{'form.datatoken'},
8321: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8322:
8323: =cut
1.31 albertel 8324:
8325: sub load_tmp_file {
8326: my $r=shift;
8327: my @studentdata=();
8328: {
1.158 raeburn 8329: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8330: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8331: if ( open(my $fh,"<$studentfile") ) {
8332: @studentdata=<$fh>;
8333: close($fh);
8334: }
1.31 albertel 8335: }
1.258 albertel 8336: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8337: }
8338:
1.56 matthew 8339: =pod
8340:
1.648 raeburn 8341: =item * &upfile_record_sep()
1.41 ng 8342:
8343: Separate uploaded file into records
8344: returns array of records,
1.258 albertel 8345: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8346:
8347: =cut
1.31 albertel 8348:
8349: sub upfile_record_sep {
1.258 albertel 8350: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8351: } else {
1.248 albertel 8352: my @records;
1.258 albertel 8353: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8354: if ($line=~/^\s*$/) { next; }
8355: push(@records,$line);
8356: }
8357: return @records;
1.31 albertel 8358: }
8359: }
8360:
1.56 matthew 8361: =pod
8362:
1.648 raeburn 8363: =item * &record_sep($record)
1.41 ng 8364:
1.258 albertel 8365: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8366:
8367: =cut
8368:
1.263 www 8369: sub takeleft {
8370: my $index=shift;
8371: return substr('0000'.$index,-4,4);
8372: }
8373:
1.31 albertel 8374: sub record_sep {
8375: my $record=shift;
8376: my %components=();
1.258 albertel 8377: if ($env{'form.upfiletype'} eq 'xml') {
8378: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8379: my $i=0;
1.356 albertel 8380: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8381: $field=~s/^(\"|\')//;
8382: $field=~s/(\"|\')$//;
1.263 www 8383: $components{&takeleft($i)}=$field;
1.31 albertel 8384: $i++;
8385: }
1.258 albertel 8386: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8387: my $i=0;
1.356 albertel 8388: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8389: $field=~s/^(\"|\')//;
8390: $field=~s/(\"|\')$//;
1.263 www 8391: $components{&takeleft($i)}=$field;
1.31 albertel 8392: $i++;
8393: }
8394: } else {
1.561 www 8395: my $separator=',';
1.480 banghart 8396: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8397: $separator=';';
1.480 banghart 8398: }
1.31 albertel 8399: my $i=0;
1.561 www 8400: # the character we are looking for to indicate the end of a quote or a record
8401: my $looking_for=$separator;
8402: # do not add the characters to the fields
8403: my $ignore=0;
8404: # we just encountered a separator (or the beginning of the record)
8405: my $just_found_separator=1;
8406: # store the field we are working on here
8407: my $field='';
8408: # work our way through all characters in record
8409: foreach my $character ($record=~/(.)/g) {
8410: if ($character eq $looking_for) {
8411: if ($character ne $separator) {
8412: # Found the end of a quote, again looking for separator
8413: $looking_for=$separator;
8414: $ignore=1;
8415: } else {
8416: # Found a separator, store away what we got
8417: $components{&takeleft($i)}=$field;
8418: $i++;
8419: $just_found_separator=1;
8420: $ignore=0;
8421: $field='';
8422: }
8423: next;
8424: }
8425: # single or double quotation marks after a separator indicate beginning of a quote
8426: # we are now looking for the end of the quote and need to ignore separators
8427: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8428: $looking_for=$character;
8429: next;
8430: }
8431: # ignore would be true after we reached the end of a quote
8432: if ($ignore) { next; }
8433: if (($just_found_separator) && ($character=~/\s/)) { next; }
8434: $field.=$character;
8435: $just_found_separator=0;
1.31 albertel 8436: }
1.561 www 8437: # catch the very last entry, since we never encountered the separator
8438: $components{&takeleft($i)}=$field;
1.31 albertel 8439: }
8440: return %components;
8441: }
8442:
1.144 matthew 8443: ######################################################
8444: ######################################################
8445:
1.56 matthew 8446: =pod
8447:
1.648 raeburn 8448: =item * &upfile_select_html()
1.41 ng 8449:
1.144 matthew 8450: Return HTML code to select a file from the users machine and specify
8451: the file type.
1.41 ng 8452:
8453: =cut
8454:
1.144 matthew 8455: ######################################################
8456: ######################################################
1.31 albertel 8457: sub upfile_select_html {
1.144 matthew 8458: my %Types = (
8459: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8460: semisv => &mt('Semicolon separated values'),
1.144 matthew 8461: space => &mt('Space separated'),
8462: tab => &mt('Tabulator separated'),
8463: # xml => &mt('HTML/XML'),
8464: );
8465: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8466: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8467: foreach my $type (sort(keys(%Types))) {
8468: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8469: }
8470: $Str .= "</select>\n";
8471: return $Str;
1.31 albertel 8472: }
8473:
1.301 albertel 8474: sub get_samples {
8475: my ($records,$toget) = @_;
8476: my @samples=({});
8477: my $got=0;
8478: foreach my $rec (@$records) {
8479: my %temp = &record_sep($rec);
8480: if (! grep(/\S/, values(%temp))) { next; }
8481: if (%temp) {
8482: $samples[$got]=\%temp;
8483: $got++;
8484: if ($got == $toget) { last; }
8485: }
8486: }
8487: return \@samples;
8488: }
8489:
1.144 matthew 8490: ######################################################
8491: ######################################################
8492:
1.56 matthew 8493: =pod
8494:
1.648 raeburn 8495: =item * &csv_print_samples($r,$records)
1.41 ng 8496:
8497: Prints a table of sample values from each column uploaded $r is an
8498: Apache Request ref, $records is an arrayref from
8499: &Apache::loncommon::upfile_record_sep
8500:
8501: =cut
8502:
1.144 matthew 8503: ######################################################
8504: ######################################################
1.31 albertel 8505: sub csv_print_samples {
8506: my ($r,$records) = @_;
1.662 bisitz 8507: my $samples = &get_samples($records,5);
1.301 albertel 8508:
1.594 raeburn 8509: $r->print(&mt('Samples').'<br />'.&start_data_table().
8510: &start_data_table_header_row());
1.356 albertel 8511: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8512: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8513: $r->print(&end_data_table_header_row());
1.301 albertel 8514: foreach my $hash (@$samples) {
1.594 raeburn 8515: $r->print(&start_data_table_row());
1.356 albertel 8516: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8517: $r->print('<td>');
1.356 albertel 8518: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8519: $r->print('</td>');
8520: }
1.594 raeburn 8521: $r->print(&end_data_table_row());
1.31 albertel 8522: }
1.594 raeburn 8523: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8524: }
8525:
1.144 matthew 8526: ######################################################
8527: ######################################################
8528:
1.56 matthew 8529: =pod
8530:
1.648 raeburn 8531: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8532:
8533: Prints a table to create associations between values and table columns.
1.144 matthew 8534:
1.41 ng 8535: $r is an Apache Request ref,
8536: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8537: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8538:
8539: =cut
8540:
1.144 matthew 8541: ######################################################
8542: ######################################################
1.31 albertel 8543: sub csv_print_select_table {
8544: my ($r,$records,$d) = @_;
1.301 albertel 8545: my $i=0;
8546: my $samples = &get_samples($records,1);
1.144 matthew 8547: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8548: &start_data_table().&start_data_table_header_row().
1.144 matthew 8549: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8550: '<th>'.&mt('Column').'</th>'.
8551: &end_data_table_header_row()."\n");
1.356 albertel 8552: foreach my $array_ref (@$d) {
8553: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8554: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8555:
8556: $r->print('<td><select name=f'.$i.
1.32 matthew 8557: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8558: $r->print('<option value="none"></option>');
1.356 albertel 8559: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8560: $r->print('<option value="'.$sample.'"'.
8561: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8562: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8563: }
1.594 raeburn 8564: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8565: $i++;
8566: }
1.594 raeburn 8567: $r->print(&end_data_table());
1.31 albertel 8568: $i--;
8569: return $i;
8570: }
1.56 matthew 8571:
1.144 matthew 8572: ######################################################
8573: ######################################################
8574:
1.56 matthew 8575: =pod
1.31 albertel 8576:
1.648 raeburn 8577: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8578:
8579: Prints a table of sample values from the upload and can make associate samples to internal names.
8580:
8581: $r is an Apache Request ref,
8582: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8583: $d is an array of 2 element arrays (internal name, displayed name)
8584:
8585: =cut
8586:
1.144 matthew 8587: ######################################################
8588: ######################################################
1.31 albertel 8589: sub csv_samples_select_table {
8590: my ($r,$records,$d) = @_;
8591: my $i=0;
1.144 matthew 8592: #
1.662 bisitz 8593: my $max_samples = 5;
8594: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8595: $r->print(&start_data_table().
8596: &start_data_table_header_row().'<th>'.
8597: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8598: &end_data_table_header_row());
1.301 albertel 8599:
8600: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8601: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8602: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8603: foreach my $option (@$d) {
8604: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8605: $r->print('<option value="'.$value.'"'.
1.253 albertel 8606: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8607: $display.'</option>');
1.31 albertel 8608: }
8609: $r->print('</select></td><td>');
1.662 bisitz 8610: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8611: if (defined($samples->[$line]{$key})) {
8612: $r->print($samples->[$line]{$key}."<br />\n");
8613: }
8614: }
1.594 raeburn 8615: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8616: $i++;
8617: }
1.594 raeburn 8618: $r->print(&end_data_table());
1.31 albertel 8619: $i--;
8620: return($i);
1.115 matthew 8621: }
8622:
1.144 matthew 8623: ######################################################
8624: ######################################################
8625:
1.115 matthew 8626: =pod
8627:
1.648 raeburn 8628: =item * &clean_excel_name($name)
1.115 matthew 8629:
8630: Returns a replacement for $name which does not contain any illegal characters.
8631:
8632: =cut
8633:
1.144 matthew 8634: ######################################################
8635: ######################################################
1.115 matthew 8636: sub clean_excel_name {
8637: my ($name) = @_;
8638: $name =~ s/[:\*\?\/\\]//g;
8639: if (length($name) > 31) {
8640: $name = substr($name,0,31);
8641: }
8642: return $name;
1.25 albertel 8643: }
1.84 albertel 8644:
1.85 albertel 8645: =pod
8646:
1.648 raeburn 8647: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8648:
8649: Returns either 1 or undef
8650:
8651: 1 if the part is to be hidden, undef if it is to be shown
8652:
8653: Arguments are:
8654:
8655: $id the id of the part to be checked
8656: $symb, optional the symb of the resource to check
8657: $udom, optional the domain of the user to check for
8658: $uname, optional the username of the user to check for
8659:
8660: =cut
1.84 albertel 8661:
8662: sub check_if_partid_hidden {
8663: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8664: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8665: $symb,$udom,$uname);
1.141 albertel 8666: my $truth=1;
8667: #if the string starts with !, then the list is the list to show not hide
8668: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8669: my @hiddenlist=split(/,/,$hiddenparts);
8670: foreach my $checkid (@hiddenlist) {
1.141 albertel 8671: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8672: }
1.141 albertel 8673: return !$truth;
1.84 albertel 8674: }
1.127 matthew 8675:
1.138 matthew 8676:
8677: ############################################################
8678: ############################################################
8679:
8680: =pod
8681:
1.157 matthew 8682: =back
8683:
1.138 matthew 8684: =head1 cgi-bin script and graphing routines
8685:
1.157 matthew 8686: =over 4
8687:
1.648 raeburn 8688: =item * &get_cgi_id()
1.138 matthew 8689:
8690: Inputs: none
8691:
8692: Returns an id which can be used to pass environment variables
8693: to various cgi-bin scripts. These environment variables will
8694: be removed from the users environment after a given time by
8695: the routine &Apache::lonnet::transfer_profile_to_env.
8696:
8697: =cut
8698:
8699: ############################################################
8700: ############################################################
1.152 albertel 8701: my $uniq=0;
1.136 matthew 8702: sub get_cgi_id {
1.154 albertel 8703: $uniq=($uniq+1)%100000;
1.280 albertel 8704: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8705: }
8706:
1.127 matthew 8707: ############################################################
8708: ############################################################
8709:
8710: =pod
8711:
1.648 raeburn 8712: =item * &DrawBarGraph()
1.127 matthew 8713:
1.138 matthew 8714: Facilitates the plotting of data in a (stacked) bar graph.
8715: Puts plot definition data into the users environment in order for
8716: graph.png to plot it. Returns an <img> tag for the plot.
8717: The bars on the plot are labeled '1','2',...,'n'.
8718:
8719: Inputs:
8720:
8721: =over 4
8722:
8723: =item $Title: string, the title of the plot
8724:
8725: =item $xlabel: string, text describing the X-axis of the plot
8726:
8727: =item $ylabel: string, text describing the Y-axis of the plot
8728:
8729: =item $Max: scalar, the maximum Y value to use in the plot
8730: If $Max is < any data point, the graph will not be rendered.
8731:
1.140 matthew 8732: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8733: they are plotted. If undefined, default values will be used.
8734:
1.178 matthew 8735: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8736:
1.138 matthew 8737: =item @Values: An array of array references. Each array reference holds data
8738: to be plotted in a stacked bar chart.
8739:
1.239 matthew 8740: =item If the final element of @Values is a hash reference the key/value
8741: pairs will be added to the graph definition.
8742:
1.138 matthew 8743: =back
8744:
8745: Returns:
8746:
8747: An <img> tag which references graph.png and the appropriate identifying
8748: information for the plot.
8749:
1.127 matthew 8750: =cut
8751:
8752: ############################################################
8753: ############################################################
1.134 matthew 8754: sub DrawBarGraph {
1.178 matthew 8755: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8756: #
8757: if (! defined($colors)) {
8758: $colors = ['#33ff00',
8759: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8760: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8761: ];
8762: }
1.228 matthew 8763: my $extra_settings = {};
8764: if (ref($Values[-1]) eq 'HASH') {
8765: $extra_settings = pop(@Values);
8766: }
1.127 matthew 8767: #
1.136 matthew 8768: my $identifier = &get_cgi_id();
8769: my $id = 'cgi.'.$identifier;
1.129 matthew 8770: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8771: return '';
8772: }
1.225 matthew 8773: #
8774: my @Labels;
8775: if (defined($labels)) {
8776: @Labels = @$labels;
8777: } else {
8778: for (my $i=0;$i<@{$Values[0]};$i++) {
8779: push (@Labels,$i+1);
8780: }
8781: }
8782: #
1.129 matthew 8783: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8784: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8785: my %ValuesHash;
8786: my $NumSets=1;
8787: foreach my $array (@Values) {
8788: next if (! ref($array));
1.136 matthew 8789: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8790: join(',',@$array);
1.129 matthew 8791: }
1.127 matthew 8792: #
1.136 matthew 8793: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8794: if ($NumBars < 3) {
8795: $width = 120+$NumBars*32;
1.220 matthew 8796: $xskip = 1;
1.225 matthew 8797: $bar_width = 30;
8798: } elsif ($NumBars < 5) {
8799: $width = 120+$NumBars*20;
8800: $xskip = 1;
8801: $bar_width = 20;
1.220 matthew 8802: } elsif ($NumBars < 10) {
1.136 matthew 8803: $width = 120+$NumBars*15;
8804: $xskip = 1;
8805: $bar_width = 15;
8806: } elsif ($NumBars <= 25) {
8807: $width = 120+$NumBars*11;
8808: $xskip = 5;
8809: $bar_width = 8;
8810: } elsif ($NumBars <= 50) {
8811: $width = 120+$NumBars*8;
8812: $xskip = 5;
8813: $bar_width = 4;
8814: } else {
8815: $width = 120+$NumBars*8;
8816: $xskip = 5;
8817: $bar_width = 4;
8818: }
8819: #
1.137 matthew 8820: $Max = 1 if ($Max < 1);
8821: if ( int($Max) < $Max ) {
8822: $Max++;
8823: $Max = int($Max);
8824: }
1.127 matthew 8825: $Title = '' if (! defined($Title));
8826: $xlabel = '' if (! defined($xlabel));
8827: $ylabel = '' if (! defined($ylabel));
1.369 www 8828: $ValuesHash{$id.'.title'} = &escape($Title);
8829: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8830: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8831: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8832: $ValuesHash{$id.'.NumBars'} = $NumBars;
8833: $ValuesHash{$id.'.NumSets'} = $NumSets;
8834: $ValuesHash{$id.'.PlotType'} = 'bar';
8835: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8836: $ValuesHash{$id.'.height'} = $height;
8837: $ValuesHash{$id.'.width'} = $width;
8838: $ValuesHash{$id.'.xskip'} = $xskip;
8839: $ValuesHash{$id.'.bar_width'} = $bar_width;
8840: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8841: #
1.228 matthew 8842: # Deal with other parameters
8843: while (my ($key,$value) = each(%$extra_settings)) {
8844: $ValuesHash{$id.'.'.$key} = $value;
8845: }
8846: #
1.646 raeburn 8847: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8848: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8849: }
8850:
8851: ############################################################
8852: ############################################################
8853:
8854: =pod
8855:
1.648 raeburn 8856: =item * &DrawXYGraph()
1.137 matthew 8857:
1.138 matthew 8858: Facilitates the plotting of data in an XY graph.
8859: Puts plot definition data into the users environment in order for
8860: graph.png to plot it. Returns an <img> tag for the plot.
8861:
8862: Inputs:
8863:
8864: =over 4
8865:
8866: =item $Title: string, the title of the plot
8867:
8868: =item $xlabel: string, text describing the X-axis of the plot
8869:
8870: =item $ylabel: string, text describing the Y-axis of the plot
8871:
8872: =item $Max: scalar, the maximum Y value to use in the plot
8873: If $Max is < any data point, the graph will not be rendered.
8874:
8875: =item $colors: Array ref containing the hex color codes for the data to be
8876: plotted in. If undefined, default values will be used.
8877:
8878: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8879:
8880: =item $Ydata: Array ref containing Array refs.
1.185 www 8881: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8882:
8883: =item %Values: hash indicating or overriding any default values which are
8884: passed to graph.png.
8885: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8886:
8887: =back
8888:
8889: Returns:
8890:
8891: An <img> tag which references graph.png and the appropriate identifying
8892: information for the plot.
8893:
1.137 matthew 8894: =cut
8895:
8896: ############################################################
8897: ############################################################
8898: sub DrawXYGraph {
8899: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8900: #
8901: # Create the identifier for the graph
8902: my $identifier = &get_cgi_id();
8903: my $id = 'cgi.'.$identifier;
8904: #
8905: $Title = '' if (! defined($Title));
8906: $xlabel = '' if (! defined($xlabel));
8907: $ylabel = '' if (! defined($ylabel));
8908: my %ValuesHash =
8909: (
1.369 www 8910: $id.'.title' => &escape($Title),
8911: $id.'.xlabel' => &escape($xlabel),
8912: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8913: $id.'.y_max_value'=> $Max,
8914: $id.'.labels' => join(',',@$Xlabels),
8915: $id.'.PlotType' => 'XY',
8916: );
8917: #
8918: if (defined($colors) && ref($colors) eq 'ARRAY') {
8919: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8920: }
8921: #
8922: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8923: return '';
8924: }
8925: my $NumSets=1;
1.138 matthew 8926: foreach my $array (@{$Ydata}){
1.137 matthew 8927: next if (! ref($array));
8928: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8929: }
1.138 matthew 8930: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8931: #
8932: # Deal with other parameters
8933: while (my ($key,$value) = each(%Values)) {
8934: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8935: }
8936: #
1.646 raeburn 8937: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8938: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8939: }
8940:
8941: ############################################################
8942: ############################################################
8943:
8944: =pod
8945:
1.648 raeburn 8946: =item * &DrawXYYGraph()
1.138 matthew 8947:
8948: Facilitates the plotting of data in an XY graph with two Y axes.
8949: Puts plot definition data into the users environment in order for
8950: graph.png to plot it. Returns an <img> tag for the plot.
8951:
8952: Inputs:
8953:
8954: =over 4
8955:
8956: =item $Title: string, the title of the plot
8957:
8958: =item $xlabel: string, text describing the X-axis of the plot
8959:
8960: =item $ylabel: string, text describing the Y-axis of the plot
8961:
8962: =item $colors: Array ref containing the hex color codes for the data to be
8963: plotted in. If undefined, default values will be used.
8964:
8965: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8966:
8967: =item $Ydata1: The first data set
8968:
8969: =item $Min1: The minimum value of the left Y-axis
8970:
8971: =item $Max1: The maximum value of the left Y-axis
8972:
8973: =item $Ydata2: The second data set
8974:
8975: =item $Min2: The minimum value of the right Y-axis
8976:
8977: =item $Max2: The maximum value of the left Y-axis
8978:
8979: =item %Values: hash indicating or overriding any default values which are
8980: passed to graph.png.
8981: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8982:
8983: =back
8984:
8985: Returns:
8986:
8987: An <img> tag which references graph.png and the appropriate identifying
8988: information for the plot.
1.136 matthew 8989:
8990: =cut
8991:
8992: ############################################################
8993: ############################################################
1.137 matthew 8994: sub DrawXYYGraph {
8995: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8996: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8997: #
8998: # Create the identifier for the graph
8999: my $identifier = &get_cgi_id();
9000: my $id = 'cgi.'.$identifier;
9001: #
9002: $Title = '' if (! defined($Title));
9003: $xlabel = '' if (! defined($xlabel));
9004: $ylabel = '' if (! defined($ylabel));
9005: my %ValuesHash =
9006: (
1.369 www 9007: $id.'.title' => &escape($Title),
9008: $id.'.xlabel' => &escape($xlabel),
9009: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9010: $id.'.labels' => join(',',@$Xlabels),
9011: $id.'.PlotType' => 'XY',
9012: $id.'.NumSets' => 2,
1.137 matthew 9013: $id.'.two_axes' => 1,
9014: $id.'.y1_max_value' => $Max1,
9015: $id.'.y1_min_value' => $Min1,
9016: $id.'.y2_max_value' => $Max2,
9017: $id.'.y2_min_value' => $Min2,
1.136 matthew 9018: );
9019: #
1.137 matthew 9020: if (defined($colors) && ref($colors) eq 'ARRAY') {
9021: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9022: }
9023: #
9024: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9025: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9026: return '';
9027: }
9028: my $NumSets=1;
1.137 matthew 9029: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9030: next if (! ref($array));
9031: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9032: }
9033: #
9034: # Deal with other parameters
9035: while (my ($key,$value) = each(%Values)) {
9036: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9037: }
9038: #
1.646 raeburn 9039: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9040: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9041: }
9042:
9043: ############################################################
9044: ############################################################
9045:
9046: =pod
9047:
1.157 matthew 9048: =back
9049:
1.139 matthew 9050: =head1 Statistics helper routines?
9051:
9052: Bad place for them but what the hell.
9053:
1.157 matthew 9054: =over 4
9055:
1.648 raeburn 9056: =item * &chartlink()
1.139 matthew 9057:
9058: Returns a link to the chart for a specific student.
9059:
9060: Inputs:
9061:
9062: =over 4
9063:
9064: =item $linktext: The text of the link
9065:
9066: =item $sname: The students username
9067:
9068: =item $sdomain: The students domain
9069:
9070: =back
9071:
1.157 matthew 9072: =back
9073:
1.139 matthew 9074: =cut
9075:
9076: ############################################################
9077: ############################################################
9078: sub chartlink {
9079: my ($linktext, $sname, $sdomain) = @_;
9080: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9081: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9082: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9083: '">'.$linktext.'</a>';
1.153 matthew 9084: }
9085:
9086: #######################################################
9087: #######################################################
9088:
9089: =pod
9090:
9091: =head1 Course Environment Routines
1.157 matthew 9092:
9093: =over 4
1.153 matthew 9094:
1.648 raeburn 9095: =item * &restore_course_settings()
1.153 matthew 9096:
1.648 raeburn 9097: =item * &store_course_settings()
1.153 matthew 9098:
9099: Restores/Store indicated form parameters from the course environment.
9100: Will not overwrite existing values of the form parameters.
9101:
9102: Inputs:
9103: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9104:
9105: a hash ref describing the data to be stored. For example:
9106:
9107: %Save_Parameters = ('Status' => 'scalar',
9108: 'chartoutputmode' => 'scalar',
9109: 'chartoutputdata' => 'scalar',
9110: 'Section' => 'array',
1.373 raeburn 9111: 'Group' => 'array',
1.153 matthew 9112: 'StudentData' => 'array',
9113: 'Maps' => 'array');
9114:
9115: Returns: both routines return nothing
9116:
1.631 raeburn 9117: =back
9118:
1.153 matthew 9119: =cut
9120:
9121: #######################################################
9122: #######################################################
9123: sub store_course_settings {
1.496 albertel 9124: return &store_settings($env{'request.course.id'},@_);
9125: }
9126:
9127: sub store_settings {
1.153 matthew 9128: # save to the environment
9129: # appenv the same items, just to be safe
1.300 albertel 9130: my $udom = $env{'user.domain'};
9131: my $uname = $env{'user.name'};
1.496 albertel 9132: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9133: my %SaveHash;
9134: my %AppHash;
9135: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9136: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9137: my $envname = 'environment.'.$basename;
1.258 albertel 9138: if (exists($env{'form.'.$setting})) {
1.153 matthew 9139: # Save this value away
9140: if ($type eq 'scalar' &&
1.258 albertel 9141: (! exists($env{$envname}) ||
9142: $env{$envname} ne $env{'form.'.$setting})) {
9143: $SaveHash{$basename} = $env{'form.'.$setting};
9144: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9145: } elsif ($type eq 'array') {
9146: my $stored_form;
1.258 albertel 9147: if (ref($env{'form.'.$setting})) {
1.153 matthew 9148: $stored_form = join(',',
9149: map {
1.369 www 9150: &escape($_);
1.258 albertel 9151: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9152: } else {
9153: $stored_form =
1.369 www 9154: &escape($env{'form.'.$setting});
1.153 matthew 9155: }
9156: # Determine if the array contents are the same.
1.258 albertel 9157: if ($stored_form ne $env{$envname}) {
1.153 matthew 9158: $SaveHash{$basename} = $stored_form;
9159: $AppHash{$envname} = $stored_form;
9160: }
9161: }
9162: }
9163: }
9164: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9165: $udom,$uname);
1.153 matthew 9166: if ($put_result !~ /^(ok|delayed)/) {
9167: &Apache::lonnet::logthis('unable to save form parameters, '.
9168: 'got error:'.$put_result);
9169: }
9170: # Make sure these settings stick around in this session, too
1.646 raeburn 9171: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9172: return;
9173: }
9174:
9175: sub restore_course_settings {
1.499 albertel 9176: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9177: }
9178:
9179: sub restore_settings {
9180: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9181: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9182: next if (exists($env{'form.'.$setting}));
1.496 albertel 9183: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9184: '.'.$setting;
1.258 albertel 9185: if (exists($env{$envname})) {
1.153 matthew 9186: if ($type eq 'scalar') {
1.258 albertel 9187: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9188: } elsif ($type eq 'array') {
1.258 albertel 9189: $env{'form.'.$setting} = [
1.153 matthew 9190: map {
1.369 www 9191: &unescape($_);
1.258 albertel 9192: } split(',',$env{$envname})
1.153 matthew 9193: ];
9194: }
9195: }
9196: }
1.127 matthew 9197: }
9198:
1.618 raeburn 9199: #######################################################
9200: #######################################################
9201:
9202: =pod
9203:
9204: =head1 Domain E-mail Routines
9205:
9206: =over 4
9207:
1.648 raeburn 9208: =item * &build_recipient_list()
1.618 raeburn 9209:
1.766 raeburn 9210: Build recipient lists for four types of e-mail:
9211: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9212: (d) Help requests, generated by
9213: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9214:
9215: Inputs:
1.619 raeburn 9216: defmail (scalar - email address of default recipient),
1.618 raeburn 9217: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9218: defdom (domain for which to retrieve configuration settings),
9219: origmail (scalar - email address of recipient from loncapa.conf,
9220: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9221:
1.655 raeburn 9222: Returns: comma separated list of addresses to which to send e-mail.
9223:
9224: =back
1.618 raeburn 9225:
9226: =cut
9227:
9228: ############################################################
9229: ############################################################
9230: sub build_recipient_list {
1.619 raeburn 9231: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9232: my @recipients;
9233: my $otheremails;
9234: my %domconfig =
9235: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9236: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9237: if (exists($domconfig{'contacts'}{$mailing})) {
9238: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9239: my @contacts = ('adminemail','supportemail');
9240: foreach my $item (@contacts) {
9241: if ($domconfig{'contacts'}{$mailing}{$item}) {
9242: my $addr = $domconfig{'contacts'}{$item};
9243: if (!grep(/^\Q$addr\E$/,@recipients)) {
9244: push(@recipients,$addr);
9245: }
1.619 raeburn 9246: }
1.766 raeburn 9247: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9248: }
9249: }
1.766 raeburn 9250: } elsif ($origmail ne '') {
9251: push(@recipients,$origmail);
1.618 raeburn 9252: }
1.619 raeburn 9253: } elsif ($origmail ne '') {
9254: push(@recipients,$origmail);
1.618 raeburn 9255: }
1.688 raeburn 9256: if (defined($defmail)) {
9257: if ($defmail ne '') {
9258: push(@recipients,$defmail);
9259: }
1.618 raeburn 9260: }
9261: if ($otheremails) {
1.619 raeburn 9262: my @others;
9263: if ($otheremails =~ /,/) {
9264: @others = split(/,/,$otheremails);
1.618 raeburn 9265: } else {
1.619 raeburn 9266: push(@others,$otheremails);
9267: }
9268: foreach my $addr (@others) {
9269: if (!grep(/^\Q$addr\E$/,@recipients)) {
9270: push(@recipients,$addr);
9271: }
1.618 raeburn 9272: }
9273: }
1.619 raeburn 9274: my $recipientlist = join(',',@recipients);
1.618 raeburn 9275: return $recipientlist;
9276: }
9277:
1.127 matthew 9278: ############################################################
9279: ############################################################
1.154 albertel 9280:
1.655 raeburn 9281: =pod
9282:
9283: =head1 Course Catalog Routines
9284:
9285: =over 4
9286:
9287: =item * &gather_categories()
9288:
9289: Converts category definitions - keys of categories hash stored in
9290: coursecategories in configuration.db on the primary library server in a
9291: domain - to an array. Also generates javascript and idx hash used to
9292: generate Domain Coordinator interface for editing Course Categories.
9293:
9294: Inputs:
1.663 raeburn 9295:
1.655 raeburn 9296: categories (reference to hash of category definitions).
1.663 raeburn 9297:
1.655 raeburn 9298: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9299: categories and subcategories).
1.663 raeburn 9300:
1.655 raeburn 9301: idx (reference to hash of counters used in Domain Coordinator interface for
9302: editing Course Categories).
1.663 raeburn 9303:
1.655 raeburn 9304: jsarray (reference to array of categories used to create Javascript arrays for
9305: Domain Coordinator interface for editing Course Categories).
9306:
9307: Returns: nothing
9308:
9309: Side effects: populates cats, idx and jsarray.
9310:
9311: =cut
9312:
9313: sub gather_categories {
9314: my ($categories,$cats,$idx,$jsarray) = @_;
9315: my %counters;
9316: my $num = 0;
9317: foreach my $item (keys(%{$categories})) {
9318: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9319: if ($container eq '' && $depth == 0) {
9320: $cats->[$depth][$categories->{$item}] = $cat;
9321: } else {
9322: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9323: }
9324: my ($escitem,$tail) = split(/:/,$item,2);
9325: if ($counters{$tail} eq '') {
9326: $counters{$tail} = $num;
9327: $num ++;
9328: }
9329: if (ref($idx) eq 'HASH') {
9330: $idx->{$item} = $counters{$tail};
9331: }
9332: if (ref($jsarray) eq 'ARRAY') {
9333: push(@{$jsarray->[$counters{$tail}]},$item);
9334: }
9335: }
9336: return;
9337: }
9338:
9339: =pod
9340:
9341: =item * &extract_categories()
9342:
9343: Used to generate breadcrumb trails for course categories.
9344:
9345: Inputs:
1.663 raeburn 9346:
1.655 raeburn 9347: categories (reference to hash of category definitions).
1.663 raeburn 9348:
1.655 raeburn 9349: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9350: categories and subcategories).
1.663 raeburn 9351:
1.655 raeburn 9352: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9353:
1.655 raeburn 9354: allitems (reference to hash - key is category key
9355: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9356:
1.655 raeburn 9357: idx (reference to hash of counters used in Domain Coordinator interface for
9358: editing Course Categories).
1.663 raeburn 9359:
1.655 raeburn 9360: jsarray (reference to array of categories used to create Javascript arrays for
9361: Domain Coordinator interface for editing Course Categories).
9362:
1.665 raeburn 9363: subcats (reference to hash of arrays containing all subcategories within each
9364: category, -recursive)
9365:
1.655 raeburn 9366: Returns: nothing
9367:
9368: Side effects: populates trails and allitems hash references.
9369:
9370: =cut
9371:
9372: sub extract_categories {
1.665 raeburn 9373: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9374: if (ref($categories) eq 'HASH') {
9375: &gather_categories($categories,$cats,$idx,$jsarray);
9376: if (ref($cats->[0]) eq 'ARRAY') {
9377: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9378: my $name = $cats->[0][$i];
9379: my $item = &escape($name).'::0';
9380: my $trailstr;
9381: if ($name eq 'instcode') {
9382: $trailstr = &mt('Official courses (with institutional codes)');
9383: } else {
9384: $trailstr = $name;
9385: }
9386: if ($allitems->{$item} eq '') {
9387: push(@{$trails},$trailstr);
9388: $allitems->{$item} = scalar(@{$trails})-1;
9389: }
9390: my @parents = ($name);
9391: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9392: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9393: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9394: if (ref($subcats) eq 'HASH') {
9395: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9396: }
9397: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9398: }
9399: } else {
9400: if (ref($subcats) eq 'HASH') {
9401: $subcats->{$item} = [];
1.655 raeburn 9402: }
9403: }
9404: }
9405: }
9406: }
9407: return;
9408: }
9409:
9410: =pod
9411:
9412: =item *&recurse_categories()
9413:
9414: Recursively used to generate breadcrumb trails for course categories.
9415:
9416: Inputs:
1.663 raeburn 9417:
1.655 raeburn 9418: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9419: categories and subcategories).
1.663 raeburn 9420:
1.655 raeburn 9421: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9422:
9423: category (current course category, for which breadcrumb trail is being generated).
9424:
9425: trails (reference to array of breadcrumb trails for each category).
9426:
1.655 raeburn 9427: allitems (reference to hash - key is category key
9428: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9429:
1.655 raeburn 9430: parents (array containing containers directories for current category,
9431: back to top level).
9432:
9433: Returns: nothing
9434:
9435: Side effects: populates trails and allitems hash references
9436:
9437: =cut
9438:
9439: sub recurse_categories {
1.665 raeburn 9440: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9441: my $shallower = $depth - 1;
9442: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9443: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9444: my $name = $cats->[$depth]{$category}[$k];
9445: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9446: my $trailstr = join(' -> ',(@{$parents},$category));
9447: if ($allitems->{$item} eq '') {
9448: push(@{$trails},$trailstr);
9449: $allitems->{$item} = scalar(@{$trails})-1;
9450: }
9451: my $deeper = $depth+1;
9452: push(@{$parents},$category);
1.665 raeburn 9453: if (ref($subcats) eq 'HASH') {
9454: my $subcat = &escape($name).':'.$category.':'.$depth;
9455: for (my $j=@{$parents}; $j>=0; $j--) {
9456: my $higher;
9457: if ($j > 0) {
9458: $higher = &escape($parents->[$j]).':'.
9459: &escape($parents->[$j-1]).':'.$j;
9460: } else {
9461: $higher = &escape($parents->[$j]).'::'.$j;
9462: }
9463: push(@{$subcats->{$higher}},$subcat);
9464: }
9465: }
9466: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9467: $subcats);
1.655 raeburn 9468: pop(@{$parents});
9469: }
9470: } else {
9471: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9472: my $trailstr = join(' -> ',(@{$parents},$category));
9473: if ($allitems->{$item} eq '') {
9474: push(@{$trails},$trailstr);
9475: $allitems->{$item} = scalar(@{$trails})-1;
9476: }
9477: }
9478: return;
9479: }
9480:
1.663 raeburn 9481: =pod
9482:
9483: =item *&assign_categories_table()
9484:
9485: Create a datatable for display of hierarchical categories in a domain,
9486: with checkboxes to allow a course to be categorized.
9487:
9488: Inputs:
9489:
9490: cathash - reference to hash of categories defined for the domain (from
9491: configuration.db)
9492:
9493: currcat - scalar with an & separated list of categories assigned to a course.
9494:
9495: Returns: $output (markup to be displayed)
9496:
9497: =cut
9498:
9499: sub assign_categories_table {
9500: my ($cathash,$currcat) = @_;
9501: my $output;
9502: if (ref($cathash) eq 'HASH') {
9503: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9504: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9505: $maxdepth = scalar(@cats);
9506: if (@cats > 0) {
9507: my $itemcount = 0;
9508: if (ref($cats[0]) eq 'ARRAY') {
9509: $output = &Apache::loncommon::start_data_table();
9510: my @currcategories;
9511: if ($currcat ne '') {
9512: @currcategories = split('&',$currcat);
9513: }
9514: for (my $i=0; $i<@{$cats[0]}; $i++) {
9515: my $parent = $cats[0][$i];
9516: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9517: next if ($parent eq 'instcode');
9518: my $item = &escape($parent).'::0';
9519: my $checked = '';
9520: if (@currcategories > 0) {
9521: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9522: $checked = ' checked="checked"';
1.663 raeburn 9523: }
9524: }
1.675 raeburn 9525: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9526: '<input type="checkbox" name="usecategory" value="'.
9527: $item.'"'.$checked.' />'.$parent.'</span>'.
9528: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9529: my $depth = 1;
9530: push(@path,$parent);
9531: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9532: pop(@path);
9533: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9534: $itemcount ++;
9535: }
9536: $output .= &Apache::loncommon::end_data_table();
9537: }
9538: }
9539: }
9540: return $output;
9541: }
9542:
9543: =pod
9544:
9545: =item *&assign_category_rows()
9546:
9547: Create a datatable row for display of nested categories in a domain,
9548: with checkboxes to allow a course to be categorized,called recursively.
9549:
9550: Inputs:
9551:
9552: itemcount - track row number for alternating colors
9553:
9554: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9555: categories and subcategories.
9556:
9557: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9558:
9559: parent - parent of current category item
9560:
9561: path - Array containing all categories back up through the hierarchy from the
9562: current category to the top level.
9563:
9564: currcategories - reference to array of current categories assigned to the course
9565:
9566: Returns: $output (markup to be displayed).
9567:
9568: =cut
9569:
9570: sub assign_category_rows {
9571: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9572: my ($text,$name,$item,$chgstr);
9573: if (ref($cats) eq 'ARRAY') {
9574: my $maxdepth = scalar(@{$cats});
9575: if (ref($cats->[$depth]) eq 'HASH') {
9576: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9577: my $numchildren = @{$cats->[$depth]{$parent}};
9578: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9579: $text .= '<td><table class="LC_datatable">';
9580: for (my $j=0; $j<$numchildren; $j++) {
9581: $name = $cats->[$depth]{$parent}[$j];
9582: $item = &escape($name).':'.&escape($parent).':'.$depth;
9583: my $deeper = $depth+1;
9584: my $checked = '';
9585: if (ref($currcategories) eq 'ARRAY') {
9586: if (@{$currcategories} > 0) {
9587: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9588: $checked = ' checked="checked"';
1.663 raeburn 9589: }
9590: }
9591: }
1.664 raeburn 9592: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9593: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9594: $item.'"'.$checked.' />'.$name.'</label></span>'.
9595: '<input type="hidden" name="catname" value="'.$name.'" />'.
9596: '</td><td>';
1.663 raeburn 9597: if (ref($path) eq 'ARRAY') {
9598: push(@{$path},$name);
9599: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9600: pop(@{$path});
9601: }
9602: $text .= '</td></tr>';
9603: }
9604: $text .= '</table></td>';
9605: }
9606: }
9607: }
9608: return $text;
9609: }
9610:
1.655 raeburn 9611: ############################################################
9612: ############################################################
9613:
9614:
1.443 albertel 9615: sub commit_customrole {
1.664 raeburn 9616: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9617: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9618: ($start?', '.&mt('starting').' '.localtime($start):'').
9619: ($end?', ending '.localtime($end):'').': <b>'.
9620: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9621: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9622: '</b><br />';
9623: return $output;
9624: }
9625:
9626: sub commit_standardrole {
1.541 raeburn 9627: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9628: my ($output,$logmsg,$linefeed);
9629: if ($context eq 'auto') {
9630: $linefeed = "\n";
9631: } else {
9632: $linefeed = "<br />\n";
9633: }
1.443 albertel 9634: if ($three eq 'st') {
1.541 raeburn 9635: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9636: $one,$two,$sec,$context);
9637: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9638: ($result eq 'unknown_course') || ($result eq 'refused')) {
9639: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9640: } else {
1.541 raeburn 9641: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9642: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9643: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9644: if ($context eq 'auto') {
9645: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9646: } else {
9647: $output .= '<b>'.$result.'</b>'.$linefeed.
9648: &mt('Add to classlist').': <b>ok</b>';
9649: }
9650: $output .= $linefeed;
1.443 albertel 9651: }
9652: } else {
9653: $output = &mt('Assigning').' '.$three.' in '.$url.
9654: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9655: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9656: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9657: if ($context eq 'auto') {
9658: $output .= $result.$linefeed;
9659: } else {
9660: $output .= '<b>'.$result.'</b>'.$linefeed;
9661: }
1.443 albertel 9662: }
9663: return $output;
9664: }
9665:
9666: sub commit_studentrole {
1.541 raeburn 9667: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9668: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9669: if ($context eq 'auto') {
9670: $linefeed = "\n";
9671: } else {
9672: $linefeed = '<br />'."\n";
9673: }
1.443 albertel 9674: if (defined($one) && defined($two)) {
9675: my $cid=$one.'_'.$two;
9676: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9677: my $secchange = 0;
9678: my $expire_role_result;
9679: my $modify_section_result;
1.628 raeburn 9680: if ($oldsec ne '-1') {
9681: if ($oldsec ne $sec) {
1.443 albertel 9682: $secchange = 1;
1.628 raeburn 9683: my $now = time;
1.443 albertel 9684: my $uurl='/'.$cid;
9685: $uurl=~s/\_/\//g;
9686: if ($oldsec) {
9687: $uurl.='/'.$oldsec;
9688: }
1.626 raeburn 9689: $oldsecurl = $uurl;
1.628 raeburn 9690: $expire_role_result =
1.652 raeburn 9691: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9692: if ($env{'request.course.sec'} ne '') {
9693: if ($expire_role_result eq 'refused') {
9694: my @roles = ('st');
9695: my @statuses = ('previous');
9696: my @roledoms = ($one);
9697: my $withsec = 1;
9698: my %roleshash =
9699: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9700: \@statuses,\@roles,\@roledoms,$withsec);
9701: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9702: my ($oldstart,$oldend) =
9703: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9704: if ($oldend > 0 && $oldend <= $now) {
9705: $expire_role_result = 'ok';
9706: }
9707: }
9708: }
9709: }
1.443 albertel 9710: $result = $expire_role_result;
9711: }
9712: }
9713: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9714: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9715: if ($modify_section_result =~ /^ok/) {
9716: if ($secchange == 1) {
1.628 raeburn 9717: if ($sec eq '') {
9718: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9719: } else {
9720: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9721: }
1.443 albertel 9722: } elsif ($oldsec eq '-1') {
1.628 raeburn 9723: if ($sec eq '') {
9724: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9725: } else {
9726: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9727: }
1.443 albertel 9728: } else {
1.628 raeburn 9729: if ($sec eq '') {
9730: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9731: } else {
9732: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9733: }
1.443 albertel 9734: }
9735: } else {
1.628 raeburn 9736: if ($secchange) {
9737: $$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;
9738: } else {
9739: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9740: }
1.443 albertel 9741: }
9742: $result = $modify_section_result;
9743: } elsif ($secchange == 1) {
1.628 raeburn 9744: if ($oldsec eq '') {
9745: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9746: } else {
9747: $$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;
9748: }
1.626 raeburn 9749: if ($expire_role_result eq 'refused') {
9750: my $newsecurl = '/'.$cid;
9751: $newsecurl =~ s/\_/\//g;
9752: if ($sec ne '') {
9753: $newsecurl.='/'.$sec;
9754: }
9755: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9756: if ($sec eq '') {
9757: $$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;
9758: } else {
9759: $$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;
9760: }
9761: }
9762: }
1.443 albertel 9763: }
9764: } else {
1.626 raeburn 9765: $$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 9766: $result = "error: incomplete course id\n";
9767: }
9768: return $result;
9769: }
9770:
9771: ############################################################
9772: ############################################################
9773:
1.566 albertel 9774: sub check_clone {
1.578 raeburn 9775: my ($args,$linefeed) = @_;
1.566 albertel 9776: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9777: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9778: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9779: my $clonemsg;
9780: my $can_clone = 0;
9781:
9782: if ($clonehome eq 'no_host') {
1.578 raeburn 9783: $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 9784: } else {
9785: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9786: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9787: $can_clone = 1;
9788: } else {
9789: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9790: $args->{'clonedomain'},$args->{'clonecourse'});
9791: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9792: if (grep(/^\*$/,@cloners)) {
9793: $can_clone = 1;
9794: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9795: $can_clone = 1;
9796: } else {
9797: my %roleshash =
9798: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9799: $args->{'ccdomain'},
9800: 'userroles',['active'],['cc'],
9801: [$args->{'clonedomain'}]);
9802: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9803: $can_clone = 1;
9804: } else {
9805: $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'});
9806: }
1.566 albertel 9807: }
1.578 raeburn 9808: }
1.566 albertel 9809: }
9810: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9811: }
9812:
1.444 albertel 9813: sub construct_course {
1.541 raeburn 9814: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9815: my $outcome;
1.541 raeburn 9816: my $linefeed = '<br />'."\n";
9817: if ($context eq 'auto') {
9818: $linefeed = "\n";
9819: }
1.566 albertel 9820:
9821: #
9822: # Are we cloning?
9823: #
9824: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9825: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9826: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9827: if ($context ne 'auto') {
1.578 raeburn 9828: if ($clonemsg ne '') {
9829: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9830: }
1.566 albertel 9831: }
9832: $outcome .= $clonemsg.$linefeed;
9833:
9834: if (!$can_clone) {
9835: return (0,$outcome);
9836: }
9837: }
9838:
1.444 albertel 9839: #
9840: # Open course
9841: #
9842: my $crstype = lc($args->{'crstype'});
9843: my %cenv=();
9844: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9845: $args->{'cdescr'},
9846: $args->{'curl'},
9847: $args->{'course_home'},
9848: $args->{'nonstandard'},
9849: $args->{'crscode'},
9850: $args->{'ccuname'}.':'.
9851: $args->{'ccdomain'},
9852: $args->{'crstype'});
9853:
9854: # Note: The testing routines depend on this being output; see
9855: # Utils::Course. This needs to at least be output as a comment
9856: # if anyone ever decides to not show this, and Utils::Course::new
9857: # will need to be suitably modified.
1.541 raeburn 9858: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9859: #
9860: # Check if created correctly
9861: #
1.479 albertel 9862: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9863: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9864: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9865:
1.444 albertel 9866: #
1.566 albertel 9867: # Do the cloning
9868: #
9869: if ($can_clone && $cloneid) {
9870: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9871: if ($context ne 'auto') {
9872: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9873: }
9874: $outcome .= $clonemsg.$linefeed;
9875: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9876: # Copy all files
1.637 www 9877: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9878: # Restore URL
1.566 albertel 9879: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9880: # Restore title
1.566 albertel 9881: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9882: # Mark as cloned
1.566 albertel 9883: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9884: # Need to clone grading mode
9885: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9886: $cenv{'grading'}=$newenv{'grading'};
9887: # Do not clone these environment entries
9888: &Apache::lonnet::del('environment',
9889: ['default_enrollment_start_date',
9890: 'default_enrollment_end_date',
9891: 'question.email',
9892: 'policy.email',
9893: 'comment.email',
9894: 'pch.users.denied',
1.725 raeburn 9895: 'plc.users.denied',
9896: 'hidefromcat',
9897: 'categories'],
1.638 www 9898: $$crsudom,$$crsunum);
1.444 albertel 9899: }
1.566 albertel 9900:
1.444 albertel 9901: #
9902: # Set environment (will override cloned, if existing)
9903: #
9904: my @sections = ();
9905: my @xlists = ();
9906: if ($args->{'crstype'}) {
9907: $cenv{'type'}=$args->{'crstype'};
9908: }
9909: if ($args->{'crsid'}) {
9910: $cenv{'courseid'}=$args->{'crsid'};
9911: }
9912: if ($args->{'crscode'}) {
9913: $cenv{'internal.coursecode'}=$args->{'crscode'};
9914: }
9915: if ($args->{'crsquota'} ne '') {
9916: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9917: } else {
9918: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9919: }
9920: if ($args->{'ccuname'}) {
9921: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9922: ':'.$args->{'ccdomain'};
9923: } else {
9924: $cenv{'internal.courseowner'} = $args->{'curruser'};
9925: }
9926: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9927: if ($args->{'crssections'}) {
9928: $cenv{'internal.sectionnums'} = '';
9929: if ($args->{'crssections'} =~ m/,/) {
9930: @sections = split/,/,$args->{'crssections'};
9931: } else {
9932: $sections[0] = $args->{'crssections'};
9933: }
9934: if (@sections > 0) {
9935: foreach my $item (@sections) {
9936: my ($sec,$gp) = split/:/,$item;
9937: my $class = $args->{'crscode'}.$sec;
9938: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9939: $cenv{'internal.sectionnums'} .= $item.',';
9940: unless ($addcheck eq 'ok') {
9941: push @badclasses, $class;
9942: }
9943: }
9944: $cenv{'internal.sectionnums'} =~ s/,$//;
9945: }
9946: }
9947: # do not hide course coordinator from staff listing,
9948: # even if privileged
9949: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9950: # add crosslistings
9951: if ($args->{'crsxlist'}) {
9952: $cenv{'internal.crosslistings'}='';
9953: if ($args->{'crsxlist'} =~ m/,/) {
9954: @xlists = split/,/,$args->{'crsxlist'};
9955: } else {
9956: $xlists[0] = $args->{'crsxlist'};
9957: }
9958: if (@xlists > 0) {
9959: foreach my $item (@xlists) {
9960: my ($xl,$gp) = split/:/,$item;
9961: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9962: $cenv{'internal.crosslistings'} .= $item.',';
9963: unless ($addcheck eq 'ok') {
9964: push @badclasses, $xl;
9965: }
9966: }
9967: $cenv{'internal.crosslistings'} =~ s/,$//;
9968: }
9969: }
9970: if ($args->{'autoadds'}) {
9971: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9972: }
9973: if ($args->{'autodrops'}) {
9974: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9975: }
9976: # check for notification of enrollment changes
9977: my @notified = ();
9978: if ($args->{'notify_owner'}) {
9979: if ($args->{'ccuname'} ne '') {
9980: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9981: }
9982: }
9983: if ($args->{'notify_dc'}) {
9984: if ($uname ne '') {
1.630 raeburn 9985: push(@notified,$uname.':'.$udom);
1.444 albertel 9986: }
9987: }
9988: if (@notified > 0) {
9989: my $notifylist;
9990: if (@notified > 1) {
9991: $notifylist = join(',',@notified);
9992: } else {
9993: $notifylist = $notified[0];
9994: }
9995: $cenv{'internal.notifylist'} = $notifylist;
9996: }
9997: if (@badclasses > 0) {
9998: my %lt=&Apache::lonlocal::texthash(
9999: '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',
10000: 'dnhr' => 'does not have rights to access enrollment in these classes',
10001: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10002: );
1.541 raeburn 10003: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10004: ' ('.$lt{'adby'}.')';
10005: if ($context eq 'auto') {
10006: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10007: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10008: foreach my $item (@badclasses) {
10009: if ($context eq 'auto') {
10010: $outcome .= " - $item\n";
10011: } else {
10012: $outcome .= "<li>$item</li>\n";
10013: }
10014: }
10015: if ($context eq 'auto') {
10016: $outcome .= $linefeed;
10017: } else {
1.566 albertel 10018: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10019: }
10020: }
1.444 albertel 10021: }
10022: if ($args->{'no_end_date'}) {
10023: $args->{'endaccess'} = 0;
10024: }
10025: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10026: $cenv{'internal.autoend'}=$args->{'enrollend'};
10027: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10028: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10029: if ($args->{'showphotos'}) {
10030: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10031: }
10032: $cenv{'internal.authtype'} = $args->{'authtype'};
10033: $cenv{'internal.autharg'} = $args->{'autharg'};
10034: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10035: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10036: 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');
10037: if ($context eq 'auto') {
10038: $outcome .= $krb_msg;
10039: } else {
1.566 albertel 10040: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10041: }
10042: $outcome .= $linefeed;
1.444 albertel 10043: }
10044: }
10045: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10046: if ($args->{'setpolicy'}) {
10047: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10048: }
10049: if ($args->{'setcontent'}) {
10050: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10051: }
10052: }
10053: if ($args->{'reshome'}) {
10054: $cenv{'reshome'}=$args->{'reshome'}.'/';
10055: $cenv{'reshome'}=~s/\/+$/\//;
10056: }
10057: #
10058: # course has keyed access
10059: #
10060: if ($args->{'setkeys'}) {
10061: $cenv{'keyaccess'}='yes';
10062: }
10063: # if specified, key authority is not course, but user
10064: # only active if keyaccess is yes
10065: if ($args->{'keyauth'}) {
1.487 albertel 10066: my ($user,$domain) = split(':',$args->{'keyauth'});
10067: $user = &LONCAPA::clean_username($user);
10068: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10069: if ($user ne '' && $domain ne '') {
1.487 albertel 10070: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10071: }
10072: }
10073:
10074: if ($args->{'disresdis'}) {
10075: $cenv{'pch.roles.denied'}='st';
10076: }
10077: if ($args->{'disablechat'}) {
10078: $cenv{'plc.roles.denied'}='st';
10079: }
10080:
10081: # Record we've not yet viewed the Course Initialization Helper for this
10082: # course
10083: $cenv{'course.helper.not.run'} = 1;
10084: #
10085: # Use new Randomseed
10086: #
10087: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10088: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10089: #
10090: # The encryption code and receipt prefix for this course
10091: #
10092: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10093: $cenv{'internal.encpref'}=100+int(9*rand(99));
10094: #
10095: # By default, use standard grading
10096: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10097:
1.541 raeburn 10098: $outcome .= $linefeed.&mt('Setting environment').': '.
10099: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10100: #
10101: # Open all assignments
10102: #
10103: if ($args->{'openall'}) {
10104: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10105: my %storecontent = ($storeunder => time,
10106: $storeunder.'.type' => 'date_start');
10107:
10108: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10109: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10110: }
10111: #
10112: # Set first page
10113: #
10114: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10115: || ($cloneid)) {
1.445 albertel 10116: use LONCAPA::map;
1.444 albertel 10117: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10118:
10119: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10120: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10121:
1.444 albertel 10122: $outcome .= ($fatal?$errtext:'read ok').' - ';
10123: my $title; my $url;
10124: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10125: $title=&mt('Syllabus');
1.444 albertel 10126: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10127: } else {
1.690 bisitz 10128: $title=&mt('Navigate Contents');
1.444 albertel 10129: $url='/adm/navmaps';
10130: }
1.445 albertel 10131:
10132: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10133: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10134:
10135: if ($errtext) { $fatal=2; }
1.541 raeburn 10136: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10137: }
1.566 albertel 10138:
10139: return (1,$outcome);
1.444 albertel 10140: }
10141:
10142: ############################################################
10143: ############################################################
10144:
1.378 raeburn 10145: sub course_type {
10146: my ($cid) = @_;
10147: if (!defined($cid)) {
10148: $cid = $env{'request.course.id'};
10149: }
1.404 albertel 10150: if (defined($env{'course.'.$cid.'.type'})) {
10151: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10152: } else {
10153: return 'Course';
1.377 raeburn 10154: }
10155: }
1.156 albertel 10156:
1.406 raeburn 10157: sub group_term {
10158: my $crstype = &course_type();
10159: my %names = (
10160: 'Course' => 'group',
1.865 raeburn 10161: 'Community' => 'group',
1.406 raeburn 10162: );
10163: return $names{$crstype};
10164: }
10165:
1.156 albertel 10166: sub icon {
10167: my ($file)=@_;
1.505 albertel 10168: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10169: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10170: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10171: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10172: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10173: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10174: $curfext.".gif") {
10175: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10176: $curfext.".gif";
10177: }
10178: }
1.249 albertel 10179: return &lonhttpdurl($iconname);
1.154 albertel 10180: }
1.84 albertel 10181:
1.575 albertel 10182: sub lonhttpdurl {
1.692 www 10183: #
10184: # Had been used for "small fry" static images on separate port 8080.
10185: # Modify here if lightweight http functionality desired again.
10186: # Currently eliminated due to increasing firewall issues.
10187: #
1.575 albertel 10188: my ($url)=@_;
1.692 www 10189: return $url;
1.215 albertel 10190: }
10191:
1.213 albertel 10192: sub connection_aborted {
10193: my ($r)=@_;
10194: $r->print(" ");$r->rflush();
10195: my $c = $r->connection;
10196: return $c->aborted();
10197: }
10198:
1.221 foxr 10199: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10200: # strings as 'strings'.
10201: sub escape_single {
1.221 foxr 10202: my ($input) = @_;
1.223 albertel 10203: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10204: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10205: return $input;
10206: }
1.223 albertel 10207:
1.222 foxr 10208: # Same as escape_single, but escape's "'s This
10209: # can be used for "strings"
10210: sub escape_double {
10211: my ($input) = @_;
10212: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10213: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10214: return $input;
10215: }
1.223 albertel 10216:
1.222 foxr 10217: # Escapes the last element of a full URL.
10218: sub escape_url {
10219: my ($url) = @_;
1.238 raeburn 10220: my @urlslices = split(/\//, $url,-1);
1.369 www 10221: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10222: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10223: }
1.462 albertel 10224:
1.820 raeburn 10225: sub compare_arrays {
10226: my ($arrayref1,$arrayref2) = @_;
10227: my (@difference,%count);
10228: @difference = ();
10229: %count = ();
10230: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10231: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10232: foreach my $element (keys(%count)) {
10233: if ($count{$element} == 1) {
10234: push(@difference,$element);
10235: }
10236: }
10237: }
10238: return @difference;
10239: }
10240:
1.817 bisitz 10241: # -------------------------------------------------------- Initialize user login
1.462 albertel 10242: sub init_user_environment {
1.463 albertel 10243: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10244: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10245:
10246: my $public=($username eq 'public' && $domain eq 'public');
10247:
10248: # See if old ID present, if so, remove
10249:
10250: my ($filename,$cookie,$userroles);
10251: my $now=time;
10252:
10253: if ($public) {
10254: my $max_public=100;
10255: my $oldest;
10256: my $oldest_time=0;
10257: for(my $next=1;$next<=$max_public;$next++) {
10258: if (-e $lonids."/publicuser_$next.id") {
10259: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10260: if ($mtime<$oldest_time || !$oldest_time) {
10261: $oldest_time=$mtime;
10262: $oldest=$next;
10263: }
10264: } else {
10265: $cookie="publicuser_$next";
10266: last;
10267: }
10268: }
10269: if (!$cookie) { $cookie="publicuser_$oldest"; }
10270: } else {
1.463 albertel 10271: # if this isn't a robot, kill any existing non-robot sessions
10272: if (!$args->{'robot'}) {
10273: opendir(DIR,$lonids);
10274: while ($filename=readdir(DIR)) {
10275: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10276: unlink($lonids.'/'.$filename);
10277: }
1.462 albertel 10278: }
1.463 albertel 10279: closedir(DIR);
1.462 albertel 10280: }
10281: # Give them a new cookie
1.463 albertel 10282: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10283: : $now.$$.int(rand(10000)));
1.463 albertel 10284: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10285:
10286: # Initialize roles
10287:
10288: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10289: }
10290: # ------------------------------------ Check browser type and MathML capability
10291:
10292: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10293: $clientunicode,$clientos) = &decode_user_agent($r);
10294:
10295: # ------------------------------------------------------------- Get environment
10296:
10297: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10298: my ($tmp) = keys(%userenv);
10299: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10300: # default remote control to off
10301: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10302: } else {
10303: undef(%userenv);
10304: }
10305: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10306: $form->{'interface'}=$userenv{'interface'};
10307: }
10308: $env{'environment.remote'}=$userenv{'remote'};
10309: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10310:
10311: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10312: foreach my $option ('interface','localpath','localres') {
10313: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10314: }
10315: # --------------------------------------------------------- Write first profile
10316:
10317: {
10318: my %initial_env =
10319: ("user.name" => $username,
10320: "user.domain" => $domain,
10321: "user.home" => $authhost,
10322: "browser.type" => $clientbrowser,
10323: "browser.version" => $clientversion,
10324: "browser.mathml" => $clientmathml,
10325: "browser.unicode" => $clientunicode,
10326: "browser.os" => $clientos,
10327: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10328: "request.course.fn" => '',
10329: "request.course.uri" => '',
10330: "request.course.sec" => '',
10331: "request.role" => 'cm',
10332: "request.role.adv" => $env{'user.adv'},
10333: "request.host" => $ENV{'REMOTE_ADDR'},);
10334:
10335: if ($form->{'localpath'}) {
10336: $initial_env{"browser.localpath"} = $form->{'localpath'};
10337: $initial_env{"browser.localres"} = $form->{'localres'};
10338: }
10339:
10340: if ($public) {
10341: $initial_env{"environment.remote"} = "off";
10342: }
10343: if ($form->{'interface'}) {
10344: $form->{'interface'}=~s/\W//gs;
10345: $initial_env{"browser.interface"} = $form->{'interface'};
10346: $env{'browser.interface'}=$form->{'interface'};
10347: }
10348:
1.724 raeburn 10349: foreach my $tool ('aboutme','blog','portfolio') {
10350: $userenv{'availabletools.'.$tool} =
10351: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10352: }
10353:
1.864 raeburn 10354: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10355: $userenv{'canrequest.'.$crstype} =
10356: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10357: 'reload','requestcourses');
10358: }
10359:
1.462 albertel 10360: $env{'user.environment'} = "$lonids/$cookie.id";
10361:
10362: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10363: &GDBM_WRCREAT(),0640)) {
10364: &_add_to_env(\%disk_env,\%initial_env);
10365: &_add_to_env(\%disk_env,\%userenv,'environment.');
10366: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10367: if (ref($args->{'extra_env'})) {
10368: &_add_to_env(\%disk_env,$args->{'extra_env'});
10369: }
1.462 albertel 10370: untie(%disk_env);
10371: } else {
1.705 tempelho 10372: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10373: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10374: return 'error: '.$!;
10375: }
10376: }
10377: $env{'request.role'}='cm';
10378: $env{'request.role.adv'}=$env{'user.adv'};
10379: $env{'browser.type'}=$clientbrowser;
10380:
10381: return $cookie;
10382:
10383: }
10384:
10385: sub _add_to_env {
10386: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10387: if (ref($env_data) eq 'HASH') {
10388: while (my ($key,$value) = each(%$env_data)) {
10389: $idf->{$prefix.$key} = $value;
10390: $env{$prefix.$key} = $value;
10391: }
1.462 albertel 10392: }
10393: }
10394:
1.685 tempelho 10395: # --- Get the symbolic name of a problem and the url
10396: sub get_symb {
10397: my ($request,$silent) = @_;
1.726 raeburn 10398: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10399: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10400: if ($symb eq '') {
10401: if (!$silent) {
10402: $request->print("Unable to handle ambiguous references:$url:.");
10403: return ();
10404: }
10405: }
10406: &Apache::lonenc::check_decrypt(\$symb);
10407: return ($symb);
10408: }
10409:
10410: # --------------------------------------------------------------Get annotation
10411:
10412: sub get_annotation {
10413: my ($symb,$enc) = @_;
10414:
10415: my $key = $symb;
10416: if (!$enc) {
10417: $key =
10418: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10419: }
10420: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10421: return $annotation{$key};
10422: }
10423:
10424: sub clean_symb {
1.731 raeburn 10425: my ($symb,$delete_enc) = @_;
1.685 tempelho 10426:
10427: &Apache::lonenc::check_decrypt(\$symb);
10428: my $enc = $env{'request.enc'};
1.731 raeburn 10429: if ($delete_enc) {
1.730 raeburn 10430: delete($env{'request.enc'});
10431: }
1.685 tempelho 10432:
10433: return ($symb,$enc);
10434: }
1.462 albertel 10435:
1.41 ng 10436: =pod
10437:
10438: =back
10439:
1.112 bowersj2 10440: =cut
1.41 ng 10441:
1.112 bowersj2 10442: 1;
10443: __END__;
1.41 ng 10444:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>