Annotation of loncom/interface/loncommon.pm, revision 1.869
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.866 kalberla 4: # $Id: loncommon.pm,v 1.865 2009/07/25 23:16:04 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.468 raeburn 485: my ($domainfilter,$sec_element,$formname)=@_;
1.865 raeburn 486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role');
1.468 raeburn 487: my $output = '
1.776 bisitz 488: <script type="text/javascript" language="JavaScript">
1.824 bisitz 489: // <![CDATA[
1.468 raeburn 490: var stdeditbrowser;'."\n";
491: $output .= <<"ENDSTDBRW";
1.377 raeburn 492: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 493: var url = '/adm/pickcourse?';
1.468 raeburn 494: var domainfilter = '';
495: var formid = getFormIdByName(formname);
496: if (formid > -1) {
497: var domid = getIndexByName(formid,udom);
498: if (domid > -1) {
499: if (document.forms[formid].elements[domid].type == 'select-one') {
500: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
501: }
502: if (document.forms[formid].elements[domid].type == 'hidden') {
503: domainfilter=document.forms[formid].elements[domid].value;
504: }
505: }
1.91 www 506: }
1.128 albertel 507: if (domainfilter != null) {
508: if (domainfilter != '') {
509: url += 'domainfilter='+domainfilter+'&';
510: }
511: }
1.91 www 512: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 513: '&cdomelement='+udom+
514: '&cnameelement='+desc;
1.468 raeburn 515: if (extra_element !=null && extra_element != '') {
1.594 raeburn 516: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 517: url += '&roleelement='+extra_element;
518: if (domainfilter == null || domainfilter == '') {
519: url += '&domainfilter='+extra_element;
520: }
1.234 raeburn 521: }
1.468 raeburn 522: else {
523: if (formname == 'portform') {
524: url += '&setroles='+extra_element;
1.800 raeburn 525: } else {
526: if (formname == 'rules') {
527: url += '&fixeddom='+extra_element;
528: }
1.468 raeburn 529: }
530: }
1.230 raeburn 531: }
1.293 raeburn 532: if (multflag !=null && multflag != '') {
533: url += '&multiple='+multflag;
534: }
1.865 raeburn 535: if (crstype == 'Course/Community') {
1.377 raeburn 536: if (formname == 'cu') {
537: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
538: if (crstype == "") {
539: alert("$crs_or_grp_alert");
540: return;
541: }
542: }
543: }
544: if (crstype !=null && crstype != '') {
545: url += '&type='+crstype;
546: }
1.102 www 547: var title = 'Course_Browser';
1.91 www 548: var options = 'scrollbars=1,resizable=1,menubar=0';
549: options += ',width=700,height=600';
550: stdeditbrowser = open(url,title,options,'1');
551: stdeditbrowser.focus();
552: }
1.468 raeburn 553:
554: function getFormIdByName(formname) {
555: for (var i=0;i<document.forms.length;i++) {
556: if (document.forms[i].name == formname) {
557: return i;
558: }
559: }
560: return -1;
561: }
562:
563: function getIndexByName(formid,item) {
564: for (var i=0;i<document.forms[formid].elements.length;i++) {
565: if (document.forms[formid].elements[i].name == item) {
566: return i;
567: }
568: }
569: return -1;
570: }
1.91 www 571: ENDSTDBRW
1.468 raeburn 572: if ($sec_element ne '') {
573: $output .= &setsec_javascript($sec_element,$formname);
574: }
575: $output .= '
1.824 bisitz 576: // ]]>
1.468 raeburn 577: </script>';
578: return $output;
579: }
580:
581: sub setsec_javascript {
582: my ($sec_element,$formname) = @_;
583: my $setsections = qq|
584: function setSect(sectionlist) {
1.629 raeburn 585: var sectionsArray = new Array();
586: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
587: sectionsArray = sectionlist.split(",");
588: }
1.468 raeburn 589: var numSections = sectionsArray.length;
590: document.$formname.$sec_element.length = 0;
591: if (numSections == 0) {
592: document.$formname.$sec_element.multiple=false;
593: document.$formname.$sec_element.size=1;
594: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
595: } else {
596: if (numSections == 1) {
597: document.$formname.$sec_element.multiple=false;
598: document.$formname.$sec_element.size=1;
599: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
600: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
601: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
602: } else {
603: for (var i=0; i<numSections; i++) {
604: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
605: }
606: document.$formname.$sec_element.multiple=true
607: if (numSections < 3) {
608: document.$formname.$sec_element.size=numSections;
609: } else {
610: document.$formname.$sec_element.size=3;
611: }
612: document.$formname.$sec_element.options[0].selected = false
613: }
614: }
1.91 www 615: }
1.468 raeburn 616: |;
617: return $setsections;
618: }
619:
1.91 www 620:
621: sub selectcourse_link {
1.377 raeburn 622: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787 bisitz 623: return '<span class="LC_nobreak">'
624: ."<a href='"
625: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
626: .'","'.$udomele.'","'.$desc.'","'.$extra_element
627: .'","'.$multflag.'","'.$selecttype.'");'
628: ."'>".&mt('Select Course').'</a>'
629: .'</span>';
1.74 www 630: }
1.42 matthew 631:
1.653 raeburn 632: sub selectauthor_link {
633: my ($form,$udom)=@_;
634: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
635: &mt('Select Author').'</a>';
636: }
637:
1.273 raeburn 638: sub check_uncheck_jscript {
639: my $jscript = <<"ENDSCRT";
640: function checkAll(field) {
641: if (field.length > 0) {
642: for (i = 0; i < field.length; i++) {
643: field[i].checked = true ;
644: }
645: } else {
646: field.checked = true
647: }
648: }
649:
650: function uncheckAll(field) {
651: if (field.length > 0) {
652: for (i = 0; i < field.length; i++) {
653: field[i].checked = false ;
1.543 albertel 654: }
655: } else {
1.273 raeburn 656: field.checked = false ;
657: }
658: }
659: ENDSCRT
660: return $jscript;
661: }
662:
1.656 www 663: sub select_timezone {
1.659 raeburn 664: my ($name,$selected,$onchange,$includeempty)=@_;
665: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
666: if ($includeempty) {
667: $output .= '<option value=""';
668: if (($selected eq '') || ($selected eq 'local')) {
669: $output .= ' selected="selected" ';
670: }
671: $output .= '> </option>';
672: }
1.657 raeburn 673: my @timezones = DateTime::TimeZone->all_names;
674: foreach my $tzone (@timezones) {
675: $output.= '<option value="'.$tzone.'"';
676: if ($tzone eq $selected) {
677: $output.=' selected="selected"';
678: }
679: $output.=">$tzone</option>\n";
1.656 www 680: }
681: $output.="</select>";
682: return $output;
683: }
1.273 raeburn 684:
1.687 raeburn 685: sub select_datelocale {
686: my ($name,$selected,$onchange,$includeempty)=@_;
687: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
688: if ($includeempty) {
689: $output .= '<option value=""';
690: if ($selected eq '') {
691: $output .= ' selected="selected" ';
692: }
693: $output .= '> </option>';
694: }
695: my (@possibles,%locale_names);
696: my @locales = DateTime::Locale::Catalog::Locales;
697: foreach my $locale (@locales) {
698: if (ref($locale) eq 'HASH') {
699: my $id = $locale->{'id'};
700: if ($id ne '') {
701: my $en_terr = $locale->{'en_territory'};
702: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 703: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 704: if (grep(/^en$/,@languages) || !@languages) {
705: if ($en_terr ne '') {
706: $locale_names{$id} = '('.$en_terr.')';
707: } elsif ($native_terr ne '') {
708: $locale_names{$id} = $native_terr;
709: }
710: } else {
711: if ($native_terr ne '') {
712: $locale_names{$id} = $native_terr.' ';
713: } elsif ($en_terr ne '') {
714: $locale_names{$id} = '('.$en_terr.')';
715: }
716: }
717: push (@possibles,$id);
718: }
719: }
720: }
721: foreach my $item (sort(@possibles)) {
722: $output.= '<option value="'.$item.'"';
723: if ($item eq $selected) {
724: $output.=' selected="selected"';
725: }
726: $output.=">$item";
727: if ($locale_names{$item} ne '') {
728: $output.=" $locale_names{$item}</option>\n";
729: }
730: $output.="</option>\n";
731: }
732: $output.="</select>";
733: return $output;
734: }
735:
1.792 raeburn 736: sub select_language {
737: my ($name,$selected,$includeempty) = @_;
738: my %langchoices;
739: if ($includeempty) {
740: %langchoices = ('' => 'No language preference');
741: }
742: foreach my $id (&languageids()) {
743: my $code = &supportedlanguagecode($id);
744: if ($code) {
745: $langchoices{$code} = &plainlanguagedescription($id);
746: }
747: }
748: return &select_form($selected,$name,%langchoices);
749: }
750:
1.42 matthew 751: =pod
1.36 matthew 752:
1.648 raeburn 753: =item * &linked_select_forms(...)
1.36 matthew 754:
755: linked_select_forms returns a string containing a <script></script> block
756: and html for two <select> menus. The select menus will be linked in that
757: changing the value of the first menu will result in new values being placed
758: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 759: order unless a defined order is provided.
1.36 matthew 760:
761: linked_select_forms takes the following ordered inputs:
762:
763: =over 4
764:
1.112 bowersj2 765: =item * $formname, the name of the <form> tag
1.36 matthew 766:
1.112 bowersj2 767: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 768:
1.112 bowersj2 769: =item * $firstdefault, the default value for the first menu
1.36 matthew 770:
1.112 bowersj2 771: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 772:
1.112 bowersj2 773: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 774:
1.112 bowersj2 775: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 776:
1.609 raeburn 777: =item * $menuorder, the order of values in the first menu
778:
1.41 ng 779: =back
780:
1.36 matthew 781: Below is an example of such a hash. Only the 'text', 'default', and
782: 'select2' keys must appear as stated. keys(%menu) are the possible
783: values for the first select menu. The text that coincides with the
1.41 ng 784: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 785: and text for the second menu are given in the hash pointed to by
786: $menu{$choice1}->{'select2'}.
787:
1.112 bowersj2 788: my %menu = ( A1 => { text =>"Choice A1" ,
789: default => "B3",
790: select2 => {
791: B1 => "Choice B1",
792: B2 => "Choice B2",
793: B3 => "Choice B3",
794: B4 => "Choice B4"
1.609 raeburn 795: },
796: order => ['B4','B3','B1','B2'],
1.112 bowersj2 797: },
798: A2 => { text =>"Choice A2" ,
799: default => "C2",
800: select2 => {
801: C1 => "Choice C1",
802: C2 => "Choice C2",
803: C3 => "Choice C3"
1.609 raeburn 804: },
805: order => ['C2','C1','C3'],
1.112 bowersj2 806: },
807: A3 => { text =>"Choice A3" ,
808: default => "D6",
809: select2 => {
810: D1 => "Choice D1",
811: D2 => "Choice D2",
812: D3 => "Choice D3",
813: D4 => "Choice D4",
814: D5 => "Choice D5",
815: D6 => "Choice D6",
816: D7 => "Choice D7"
1.609 raeburn 817: },
818: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 819: }
820: );
1.36 matthew 821:
822: =cut
823:
824: sub linked_select_forms {
825: my ($formname,
826: $middletext,
827: $firstdefault,
828: $firstselectname,
829: $secondselectname,
1.609 raeburn 830: $hashref,
831: $menuorder,
1.36 matthew 832: ) = @_;
833: my $second = "document.$formname.$secondselectname";
834: my $first = "document.$formname.$firstselectname";
835: # output the javascript to do the changing
836: my $result = '';
1.776 bisitz 837: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 838: $result.="// <![CDATA[\n";
1.36 matthew 839: $result.="var select2data = new Object();\n";
840: $" = '","';
841: my $debug = '';
842: foreach my $s1 (sort(keys(%$hashref))) {
843: $result.="select2data.d_$s1 = new Object();\n";
844: $result.="select2data.d_$s1.def = new String('".
845: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 846: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 847: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 848: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
849: @s2values = @{$hashref->{$s1}->{'order'}};
850: }
1.36 matthew 851: $result.="\"@s2values\");\n";
852: $result.="select2data.d_$s1.texts = new Array(";
853: my @s2texts;
854: foreach my $value (@s2values) {
855: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
856: }
857: $result.="\"@s2texts\");\n";
858: }
859: $"=' ';
860: $result.= <<"END";
861:
862: function select1_changed() {
863: // Determine new choice
864: var newvalue = "d_" + $first.value;
865: // update select2
866: var values = select2data[newvalue].values;
867: var texts = select2data[newvalue].texts;
868: var select2def = select2data[newvalue].def;
869: var i;
870: // out with the old
871: for (i = 0; i < $second.options.length; i++) {
872: $second.options[i] = null;
873: }
874: // in with the nuclear
875: for (i=0;i<values.length; i++) {
876: $second.options[i] = new Option(values[i]);
1.143 matthew 877: $second.options[i].value = values[i];
1.36 matthew 878: $second.options[i].text = texts[i];
879: if (values[i] == select2def) {
880: $second.options[i].selected = true;
881: }
882: }
883: }
1.824 bisitz 884: // ]]>
1.36 matthew 885: </script>
886: END
887: # output the initial values for the selection lists
888: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 889: my @order = sort(keys(%{$hashref}));
890: if (ref($menuorder) eq 'ARRAY') {
891: @order = @{$menuorder};
892: }
893: foreach my $value (@order) {
1.36 matthew 894: $result.=" <option value=\"$value\" ";
1.253 albertel 895: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 896: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 897: }
898: $result .= "</select>\n";
899: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
900: $result .= $middletext;
901: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
902: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 903:
904: my @secondorder = sort(keys(%select2));
905: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
906: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
907: }
908: foreach my $value (@secondorder) {
1.36 matthew 909: $result.=" <option value=\"$value\" ";
1.253 albertel 910: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 911: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 912: }
913: $result .= "</select>\n";
914: # return $debug;
915: return $result;
916: } # end of sub linked_select_forms {
917:
1.45 matthew 918: =pod
1.44 bowersj2 919:
1.648 raeburn 920: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 921:
1.112 bowersj2 922: Returns a string corresponding to an HTML link to the given help
923: $topic, where $topic corresponds to the name of a .tex file in
924: /home/httpd/html/adm/help/tex, with underscores replaced by
925: spaces.
926:
927: $text will optionally be linked to the same topic, allowing you to
928: link text in addition to the graphic. If you do not want to link
929: text, but wish to specify one of the later parameters, pass an
930: empty string.
931:
932: $stayOnPage is a value that will be interpreted as a boolean. If true,
933: the link will not open a new window. If false, the link will open
934: a new window using Javascript. (Default is false.)
935:
936: $width and $height are optional numerical parameters that will
937: override the width and height of the popped up window, which may
938: be useful for certain help topics with big pictures included.
1.44 bowersj2 939:
940: =cut
941:
942: sub help_open_topic {
1.48 bowersj2 943: my ($topic, $text, $stayOnPage, $width, $height) = @_;
944: $text = "" if (not defined $text);
1.44 bowersj2 945: $stayOnPage = 0 if (not defined $stayOnPage);
946: $width = 350 if (not defined $width);
947: $height = 400 if (not defined $height);
948: my $filename = $topic;
949: $filename =~ s/ /_/g;
950:
1.48 bowersj2 951: my $template = "";
952: my $link;
1.572 banghart 953:
1.159 www 954: $topic=~s/\W/\_/g;
1.44 bowersj2 955:
1.572 banghart 956: if (!$stayOnPage) {
1.72 bowersj2 957: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 958: } else {
1.48 bowersj2 959: $link = "/adm/help/${filename}.hlp";
960: }
961:
962: # Add the text
1.755 neumanie 963: if ($text ne "") {
1.763 bisitz 964: $template.='<span class="LC_help_open_topic">'
965: .'<a target="_top" href="'.$link.'">'
966: .$text.'</a>';
1.48 bowersj2 967: }
968:
1.763 bisitz 969: # (Always) Add the graphic
1.179 matthew 970: my $title = &mt('Online Help');
1.667 raeburn 971: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 972: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
973: .'<img src="'.$helpicon.'" border="0"'
974: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 975: .' title="'.$title.'"'
1.763 bisitz 976: .' /></a>';
977: if ($text ne "") {
978: $template.='</span>';
979: }
1.44 bowersj2 980: return $template;
981:
1.106 bowersj2 982: }
983:
984: # This is a quicky function for Latex cheatsheet editing, since it
985: # appears in at least four places
986: sub helpLatexCheatsheet {
1.732 raeburn 987: my ($topic,$text,$not_author) = @_;
988: my $out;
1.106 bowersj2 989: my $addOther = '';
1.732 raeburn 990: if ($topic) {
1.763 bisitz 991: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
992: undef, undef, 600).
993: '</span> ';
994: }
995: $out = '<span>' # Start cheatsheet
996: .$addOther
997: .'<span>'
998: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
999: undef,undef,600)
1000: .'</span> <span>'
1001: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1002: undef,undef,600)
1003: .'</span>';
1.732 raeburn 1004: unless ($not_author) {
1.763 bisitz 1005: $out .= ' <span>'
1006: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1007: undef,undef,600)
1008: .'</span>';
1.732 raeburn 1009: }
1.763 bisitz 1010: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1011: return $out;
1.172 www 1012: }
1013:
1.430 albertel 1014: sub general_help {
1015: my $helptopic='Student_Intro';
1016: if ($env{'request.role'}=~/^(ca|au)/) {
1017: $helptopic='Authoring_Intro';
1018: } elsif ($env{'request.role'}=~/^cc/) {
1019: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1020: } elsif ($env{'request.role'}=~/^dc/) {
1021: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1022: }
1023: return $helptopic;
1024: }
1025:
1026: sub update_help_link {
1027: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1028: my $origurl = $ENV{'REQUEST_URI'};
1029: $origurl=~s|^/~|/priv/|;
1030: my $timestamp = time;
1031: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1032: $$datum = &escape($$datum);
1033: }
1034:
1035: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1036: my $output .= <<"ENDOUTPUT";
1037: <script type="text/javascript">
1.824 bisitz 1038: // <![CDATA[
1.430 albertel 1039: banner_link = '$banner_link';
1.824 bisitz 1040: // ]]>
1.430 albertel 1041: </script>
1042: ENDOUTPUT
1043: return $output;
1044: }
1045:
1046: # now just updates the help link and generates a blue icon
1.193 raeburn 1047: sub help_open_menu {
1.430 albertel 1048: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1049: = @_;
1.430 albertel 1050: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1051: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1052: # if environment.remote is on (using remote control UI)
1.798 tempelho 1053: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1054: $stayOnPage=1;
1.430 albertel 1055: }
1056: my $output;
1057: if ($component_help) {
1058: if (!$text) {
1059: $output=&help_open_topic($component_help,undef,$stayOnPage,
1060: $width,$height);
1061: } else {
1062: my $help_text;
1063: $help_text=&unescape($topic);
1064: $output='<table><tr><td>'.
1065: &help_open_topic($component_help,$help_text,$stayOnPage,
1066: $width,$height).'</td></tr></table>';
1067: }
1068: }
1069: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1070: return $output.$banner_link;
1071: }
1072:
1073: sub top_nav_help {
1074: my ($text) = @_;
1.436 albertel 1075: $text = &mt($text);
1.572 banghart 1076: my $stay_on_page =
1.798 tempelho 1077: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1078: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1079: : "javascript:helpMenu('open')";
1.572 banghart 1080: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1081:
1.201 raeburn 1082: my $title = &mt('Get help');
1.436 albertel 1083:
1084: return <<"END";
1085: $banner_link
1086: <a href="$link" title="$title">$text</a>
1087: END
1088: }
1089:
1090: sub help_menu_js {
1091: my ($text) = @_;
1092:
1093: my $stayOnPage =
1.798 tempelho 1094: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1095:
1096: my $width = 620;
1097: my $height = 600;
1.430 albertel 1098: my $helptopic=&general_help();
1099: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1100: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1101: my $start_page =
1102: &Apache::loncommon::start_page('Help Menu', undef,
1103: {'frameset' => 1,
1104: 'js_ready' => 1,
1105: 'add_entries' => {
1106: 'border' => '0',
1.579 raeburn 1107: 'rows' => "110,*",},});
1.331 albertel 1108: my $end_page =
1109: &Apache::loncommon::end_page({'frameset' => 1,
1110: 'js_ready' => 1,});
1111:
1.436 albertel 1112: my $template .= <<"ENDTEMPLATE";
1113: <script type="text/javascript">
1.253 albertel 1114: // <!-- BEGIN LON-CAPA Internal
1115: // <![CDATA[
1.430 albertel 1116: var banner_link = '';
1.243 raeburn 1117: function helpMenu(target) {
1118: var caller = this;
1119: if (target == 'open') {
1120: var newWindow = null;
1121: try {
1.262 albertel 1122: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1123: }
1124: catch(error) {
1125: writeHelp(caller);
1126: return;
1127: }
1128: if (newWindow) {
1129: caller = newWindow;
1130: }
1.193 raeburn 1131: }
1.243 raeburn 1132: writeHelp(caller);
1133: return;
1134: }
1135: function writeHelp(caller) {
1.430 albertel 1136: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1137: caller.document.close()
1138: caller.focus()
1.193 raeburn 1139: }
1.253 albertel 1140: // ]]>
1.219 albertel 1141: // END LON-CAPA Internal -->
1.436 albertel 1142: </script>
1.193 raeburn 1143: ENDTEMPLATE
1144: return $template;
1145: }
1146:
1.172 www 1147: sub help_open_bug {
1148: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1149: unless ($env{'user.adv'}) { return ''; }
1.172 www 1150: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1151: $text = "" if (not defined $text);
1152: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1153: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1154: $stayOnPage=1;
1155: }
1.184 albertel 1156: $width = 600 if (not defined $width);
1157: $height = 600 if (not defined $height);
1.172 www 1158:
1159: $topic=~s/\W+/\+/g;
1160: my $link='';
1161: my $template='';
1.379 albertel 1162: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1163: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1164: if (!$stayOnPage)
1165: {
1166: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1167: }
1168: else
1169: {
1170: $link = $url;
1171: }
1172: # Add the text
1173: if ($text ne "")
1174: {
1175: $template .=
1176: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1177: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1178: }
1179:
1180: # Add the graphic
1.179 matthew 1181: my $title = &mt('Report a Bug');
1.215 albertel 1182: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1183: $template .= <<"ENDTEMPLATE";
1.436 albertel 1184: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1185: ENDTEMPLATE
1186: if ($text ne '') { $template.='</td></tr></table>' };
1187: return $template;
1188:
1189: }
1190:
1191: sub help_open_faq {
1192: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1193: unless ($env{'user.adv'}) { return ''; }
1.172 www 1194: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1195: $text = "" if (not defined $text);
1196: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1197: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1198: $stayOnPage=1;
1199: }
1200: $width = 350 if (not defined $width);
1201: $height = 400 if (not defined $height);
1202:
1203: $topic=~s/\W+/\+/g;
1204: my $link='';
1205: my $template='';
1206: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1207: if (!$stayOnPage)
1208: {
1209: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1210: }
1211: else
1212: {
1213: $link = $url;
1214: }
1215:
1216: # Add the text
1217: if ($text ne "")
1218: {
1219: $template .=
1.173 www 1220: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1221: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1222: }
1223:
1224: # Add the graphic
1.179 matthew 1225: my $title = &mt('View the FAQ');
1.215 albertel 1226: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1227: $template .= <<"ENDTEMPLATE";
1.436 albertel 1228: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1229: ENDTEMPLATE
1230: if ($text ne '') { $template.='</td></tr></table>' };
1231: return $template;
1232:
1.44 bowersj2 1233: }
1.37 matthew 1234:
1.180 matthew 1235: ###############################################################
1236: ###############################################################
1237:
1.45 matthew 1238: =pod
1239:
1.648 raeburn 1240: =item * &change_content_javascript():
1.256 matthew 1241:
1242: This and the next function allow you to create small sections of an
1243: otherwise static HTML page that you can update on the fly with
1244: Javascript, even in Netscape 4.
1245:
1246: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1247: must be written to the HTML page once. It will prove the Javascript
1248: function "change(name, content)". Calling the change function with the
1249: name of the section
1250: you want to update, matching the name passed to C<changable_area>, and
1251: the new content you want to put in there, will put the content into
1252: that area.
1253:
1254: B<Note>: Netscape 4 only reserves enough space for the changable area
1255: to contain room for the original contents. You need to "make space"
1256: for whatever changes you wish to make, and be B<sure> to check your
1257: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1258: it's adequate for updating a one-line status display, but little more.
1259: This script will set the space to 100% width, so you only need to
1260: worry about height in Netscape 4.
1261:
1262: Modern browsers are much less limiting, and if you can commit to the
1263: user not using Netscape 4, this feature may be used freely with
1264: pretty much any HTML.
1265:
1266: =cut
1267:
1268: sub change_content_javascript {
1269: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1270: if ($env{'browser.type'} eq 'netscape' &&
1271: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1272: return (<<NETSCAPE4);
1273: function change(name, content) {
1274: doc = document.layers[name+"___escape"].layers[0].document;
1275: doc.open();
1276: doc.write(content);
1277: doc.close();
1278: }
1279: NETSCAPE4
1280: } else {
1281: # Otherwise, we need to use semi-standards-compliant code
1282: # (technically, "innerHTML" isn't standard but the equivalent
1283: # is really scary, and every useful browser supports it
1284: return (<<DOMBASED);
1285: function change(name, content) {
1286: element = document.getElementById(name);
1287: element.innerHTML = content;
1288: }
1289: DOMBASED
1290: }
1291: }
1292:
1293: =pod
1294:
1.648 raeburn 1295: =item * &changable_area($name,$origContent):
1.256 matthew 1296:
1297: This provides a "changable area" that can be modified on the fly via
1298: the Javascript code provided in C<change_content_javascript>. $name is
1299: the name you will use to reference the area later; do not repeat the
1300: same name on a given HTML page more then once. $origContent is what
1301: the area will originally contain, which can be left blank.
1302:
1303: =cut
1304:
1305: sub changable_area {
1306: my ($name, $origContent) = @_;
1307:
1.258 albertel 1308: if ($env{'browser.type'} eq 'netscape' &&
1309: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1310: # If this is netscape 4, we need to use the Layer tag
1311: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1312: } else {
1313: return "<span id='$name'>$origContent</span>";
1314: }
1315: }
1316:
1317: =pod
1318:
1.648 raeburn 1319: =item * &viewport_geometry_js
1.590 raeburn 1320:
1321: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1322:
1323: =cut
1324:
1325:
1326: sub viewport_geometry_js {
1327: return <<"GEOMETRY";
1328: var Geometry = {};
1329: function init_geometry() {
1330: if (Geometry.init) { return };
1331: Geometry.init=1;
1332: if (window.innerHeight) {
1333: Geometry.getViewportHeight = function() { return window.innerHeight; };
1334: Geometry.getViewportWidth = function() { return window.innerWidth; };
1335: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1336: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1337: }
1338: else if (document.documentElement && document.documentElement.clientHeight) {
1339: Geometry.getViewportHeight =
1340: function() { return document.documentElement.clientHeight; };
1341: Geometry.getViewportWidth =
1342: function() { return document.documentElement.clientWidth; };
1343:
1344: Geometry.getHorizontalScroll =
1345: function() { return document.documentElement.scrollLeft; };
1346: Geometry.getVerticalScroll =
1347: function() { return document.documentElement.scrollTop; };
1348: }
1349: else if (document.body.clientHeight) {
1350: Geometry.getViewportHeight =
1351: function() { return document.body.clientHeight; };
1352: Geometry.getViewportWidth =
1353: function() { return document.body.clientWidth; };
1354: Geometry.getHorizontalScroll =
1355: function() { return document.body.scrollLeft; };
1356: Geometry.getVerticalScroll =
1357: function() { return document.body.scrollTop; };
1358: }
1359: }
1360:
1361: GEOMETRY
1362: }
1363:
1364: =pod
1365:
1.648 raeburn 1366: =item * &viewport_size_js()
1.590 raeburn 1367:
1368: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1369:
1370: =cut
1371:
1372: sub viewport_size_js {
1373: my $geometry = &viewport_geometry_js();
1374: return <<"DIMS";
1375:
1376: $geometry
1377:
1378: function getViewportDims(width,height) {
1379: init_geometry();
1380: width.value = Geometry.getViewportWidth();
1381: height.value = Geometry.getViewportHeight();
1382: return;
1383: }
1384:
1385: DIMS
1386: }
1387:
1388: =pod
1389:
1.648 raeburn 1390: =item * &resize_textarea_js()
1.565 albertel 1391:
1392: emits the needed javascript to resize a textarea to be as big as possible
1393:
1394: creates a function resize_textrea that takes two IDs first should be
1395: the id of the element to resize, second should be the id of a div that
1396: surrounds everything that comes after the textarea, this routine needs
1397: to be attached to the <body> for the onload and onresize events.
1398:
1.648 raeburn 1399: =back
1.565 albertel 1400:
1401: =cut
1402:
1403: sub resize_textarea_js {
1.590 raeburn 1404: my $geometry = &viewport_geometry_js();
1.565 albertel 1405: return <<"RESIZE";
1406: <script type="text/javascript">
1.824 bisitz 1407: // <![CDATA[
1.590 raeburn 1408: $geometry
1.565 albertel 1409:
1.588 albertel 1410: function getX(element) {
1411: var x = 0;
1412: while (element) {
1413: x += element.offsetLeft;
1414: element = element.offsetParent;
1415: }
1416: return x;
1417: }
1418: function getY(element) {
1419: var y = 0;
1420: while (element) {
1421: y += element.offsetTop;
1422: element = element.offsetParent;
1423: }
1424: return y;
1425: }
1426:
1427:
1.565 albertel 1428: function resize_textarea(textarea_id,bottom_id) {
1429: init_geometry();
1430: var textarea = document.getElementById(textarea_id);
1431: //alert(textarea);
1432:
1.588 albertel 1433: var textarea_top = getY(textarea);
1.565 albertel 1434: var textarea_height = textarea.offsetHeight;
1435: var bottom = document.getElementById(bottom_id);
1.588 albertel 1436: var bottom_top = getY(bottom);
1.565 albertel 1437: var bottom_height = bottom.offsetHeight;
1438: var window_height = Geometry.getViewportHeight();
1.588 albertel 1439: var fudge = 23;
1.565 albertel 1440: var new_height = window_height-fudge-textarea_top-bottom_height;
1441: if (new_height < 300) {
1442: new_height = 300;
1443: }
1444: textarea.style.height=new_height+'px';
1445: }
1.824 bisitz 1446: // ]]>
1.565 albertel 1447: </script>
1448: RESIZE
1449:
1450: }
1451:
1452: =pod
1453:
1.256 matthew 1454: =head1 Excel and CSV file utility routines
1455:
1456: =over 4
1457:
1458: =cut
1459:
1460: ###############################################################
1461: ###############################################################
1462:
1463: =pod
1464:
1.648 raeburn 1465: =item * &csv_translate($text)
1.37 matthew 1466:
1.185 www 1467: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1468: format.
1469:
1470: =cut
1471:
1.180 matthew 1472: ###############################################################
1473: ###############################################################
1.37 matthew 1474: sub csv_translate {
1475: my $text = shift;
1476: $text =~ s/\"/\"\"/g;
1.209 albertel 1477: $text =~ s/\n/ /g;
1.37 matthew 1478: return $text;
1479: }
1.180 matthew 1480:
1481: ###############################################################
1482: ###############################################################
1483:
1484: =pod
1485:
1.648 raeburn 1486: =item * &define_excel_formats()
1.180 matthew 1487:
1488: Define some commonly used Excel cell formats.
1489:
1490: Currently supported formats:
1491:
1492: =over 4
1493:
1494: =item header
1495:
1496: =item bold
1497:
1498: =item h1
1499:
1500: =item h2
1501:
1502: =item h3
1503:
1.256 matthew 1504: =item h4
1505:
1506: =item i
1507:
1.180 matthew 1508: =item date
1509:
1510: =back
1511:
1512: Inputs: $workbook
1513:
1514: Returns: $format, a hash reference.
1515:
1516: =cut
1517:
1518: ###############################################################
1519: ###############################################################
1520: sub define_excel_formats {
1521: my ($workbook) = @_;
1522: my $format;
1523: $format->{'header'} = $workbook->add_format(bold => 1,
1524: bottom => 1,
1525: align => 'center');
1526: $format->{'bold'} = $workbook->add_format(bold=>1);
1527: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1528: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1529: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1530: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1531: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1532: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1533: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1534: return $format;
1535: }
1536:
1537: ###############################################################
1538: ###############################################################
1.113 bowersj2 1539:
1540: =pod
1541:
1.648 raeburn 1542: =item * &create_workbook()
1.255 matthew 1543:
1544: Create an Excel worksheet. If it fails, output message on the
1545: request object and return undefs.
1546:
1547: Inputs: Apache request object
1548:
1549: Returns (undef) on failure,
1550: Excel worksheet object, scalar with filename, and formats
1551: from &Apache::loncommon::define_excel_formats on success
1552:
1553: =cut
1554:
1555: ###############################################################
1556: ###############################################################
1557: sub create_workbook {
1558: my ($r) = @_;
1559: #
1560: # Create the excel spreadsheet
1561: my $filename = '/prtspool/'.
1.258 albertel 1562: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1563: time.'_'.rand(1000000000).'.xls';
1564: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1565: if (! defined($workbook)) {
1566: $r->log_error("Error creating excel spreadsheet $filename: $!");
1567: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1568: "This error has been logged. ".
1569: "Please alert your LON-CAPA administrator").
1570: '</p>');
1571: return (undef);
1572: }
1573: #
1574: $workbook->set_tempdir('/home/httpd/perl/tmp');
1575: #
1576: my $format = &Apache::loncommon::define_excel_formats($workbook);
1577: return ($workbook,$filename,$format);
1578: }
1579:
1580: ###############################################################
1581: ###############################################################
1582:
1583: =pod
1584:
1.648 raeburn 1585: =item * &create_text_file()
1.113 bowersj2 1586:
1.542 raeburn 1587: Create a file to write to and eventually make available to the user.
1.256 matthew 1588: If file creation fails, outputs an error message on the request object and
1589: return undefs.
1.113 bowersj2 1590:
1.256 matthew 1591: Inputs: Apache request object, and file suffix
1.113 bowersj2 1592:
1.256 matthew 1593: Returns (undef) on failure,
1594: Filehandle and filename on success.
1.113 bowersj2 1595:
1596: =cut
1597:
1.256 matthew 1598: ###############################################################
1599: ###############################################################
1600: sub create_text_file {
1601: my ($r,$suffix) = @_;
1602: if (! defined($suffix)) { $suffix = 'txt'; };
1603: my $fh;
1604: my $filename = '/prtspool/'.
1.258 albertel 1605: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1606: time.'_'.rand(1000000000).'.'.$suffix;
1607: $fh = Apache::File->new('>/home/httpd'.$filename);
1608: if (! defined($fh)) {
1609: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1610: $r->print(&mt('Problems occurred in creating the output file. '
1611: .'This error has been logged. '
1612: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1613: }
1.256 matthew 1614: return ($fh,$filename)
1.113 bowersj2 1615: }
1616:
1617:
1.256 matthew 1618: =pod
1.113 bowersj2 1619:
1620: =back
1621:
1622: =cut
1.37 matthew 1623:
1624: ###############################################################
1.33 matthew 1625: ## Home server <option> list generating code ##
1626: ###############################################################
1.35 matthew 1627:
1.169 www 1628: # ------------------------------------------
1629:
1630: sub domain_select {
1631: my ($name,$value,$multiple)=@_;
1632: my %domains=map {
1.514 albertel 1633: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1634: } &Apache::lonnet::all_domains();
1.169 www 1635: if ($multiple) {
1636: $domains{''}=&mt('Any domain');
1.550 albertel 1637: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1638: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1639: } else {
1.550 albertel 1640: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1641: return &select_form($name,$value,%domains);
1642: }
1643: }
1644:
1.282 albertel 1645: #-------------------------------------------
1646:
1647: =pod
1648:
1.519 raeburn 1649: =head1 Routines for form select boxes
1650:
1651: =over 4
1652:
1.648 raeburn 1653: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1654:
1655: Returns a string containing a <select> element int multiple mode
1656:
1657:
1658: Args:
1659: $name - name of the <select> element
1.506 raeburn 1660: $value - scalar or array ref of values that should already be selected
1.282 albertel 1661: $size - number of rows long the select element is
1.283 albertel 1662: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1663: (shown text should already have been &mt())
1.506 raeburn 1664: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1665:
1.282 albertel 1666: =cut
1667:
1668: #-------------------------------------------
1.169 www 1669: sub multiple_select_form {
1.284 albertel 1670: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1671: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1672: my $output='';
1.191 matthew 1673: if (! defined($size)) {
1674: $size = 4;
1.283 albertel 1675: if (scalar(keys(%$hash))<4) {
1676: $size = scalar(keys(%$hash));
1.191 matthew 1677: }
1678: }
1.734 bisitz 1679: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1680: my @order;
1.506 raeburn 1681: if (ref($order) eq 'ARRAY') {
1682: @order = @{$order};
1683: } else {
1684: @order = sort(keys(%$hash));
1.501 banghart 1685: }
1686: if (exists($$hash{'select_form_order'})) {
1687: @order = @{$$hash{'select_form_order'}};
1688: }
1689:
1.284 albertel 1690: foreach my $key (@order) {
1.356 albertel 1691: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1692: $output.='selected="selected" ' if ($selected{$key});
1693: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1694: }
1695: $output.="</select>\n";
1696: return $output;
1697: }
1698:
1.88 www 1699: #-------------------------------------------
1700:
1701: =pod
1702:
1.648 raeburn 1703: =item * &select_form($defdom,$name,%hash)
1.88 www 1704:
1705: Returns a string containing a <select name='$name' size='1'> form to
1706: allow a user to select options from a hash option_name => displayed text.
1707: See lonrights.pm for an example invocation and use.
1708:
1709: =cut
1710:
1711: #-------------------------------------------
1712: sub select_form {
1713: my ($def,$name,%hash) = @_;
1714: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1715: my @keys;
1716: if (exists($hash{'select_form_order'})) {
1717: @keys=@{$hash{'select_form_order'}};
1718: } else {
1719: @keys=sort(keys(%hash));
1720: }
1.356 albertel 1721: foreach my $key (@keys) {
1722: $selectform.=
1723: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1724: ($key eq $def ? 'selected="selected" ' : '').
1725: ">".&mt($hash{$key})."</option>\n";
1.88 www 1726: }
1727: $selectform.="</select>";
1728: return $selectform;
1729: }
1730:
1.475 www 1731: # For display filters
1732:
1733: sub display_filter {
1734: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1735: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1736: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1737: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1738: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1739: '</label></span> <span class="LC_nobreak">'.
1.475 www 1740: &mt('Filter [_1]',
1.477 www 1741: &select_form($env{'form.displayfilter'},
1742: 'displayfilter',
1743: ('currentfolder' => 'Current folder/page',
1744: 'containing' => 'Containing phrase',
1745: 'none' => 'None'))).
1.714 bisitz 1746: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1747: }
1748:
1.167 www 1749: sub gradeleveldescription {
1750: my $gradelevel=shift;
1751: my %gradelevels=(0 => 'Not specified',
1752: 1 => 'Grade 1',
1753: 2 => 'Grade 2',
1754: 3 => 'Grade 3',
1755: 4 => 'Grade 4',
1756: 5 => 'Grade 5',
1757: 6 => 'Grade 6',
1758: 7 => 'Grade 7',
1759: 8 => 'Grade 8',
1760: 9 => 'Grade 9',
1761: 10 => 'Grade 10',
1762: 11 => 'Grade 11',
1763: 12 => 'Grade 12',
1764: 13 => 'Grade 13',
1765: 14 => '100 Level',
1766: 15 => '200 Level',
1767: 16 => '300 Level',
1768: 17 => '400 Level',
1769: 18 => 'Graduate Level');
1770: return &mt($gradelevels{$gradelevel});
1771: }
1772:
1.163 www 1773: sub select_level_form {
1774: my ($deflevel,$name)=@_;
1775: unless ($deflevel) { $deflevel=0; }
1.167 www 1776: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1777: for (my $i=0; $i<=18; $i++) {
1778: $selectform.="<option value=\"$i\" ".
1.253 albertel 1779: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1780: ">".&gradeleveldescription($i)."</option>\n";
1781: }
1782: $selectform.="</select>";
1783: return $selectform;
1.163 www 1784: }
1.167 www 1785:
1.35 matthew 1786: #-------------------------------------------
1787:
1.45 matthew 1788: =pod
1789:
1.743 raeburn 1790: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1791:
1792: Returns a string containing a <select name='$name' size='1'> form to
1793: allow a user to select the domain to preform an operation in.
1794: See loncreateuser.pm for an example invocation and use.
1795:
1.90 www 1796: If the $includeempty flag is set, it also includes an empty choice ("no domain
1797: selected");
1798:
1.743 raeburn 1799: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1800:
1801: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1802:
1.35 matthew 1803: =cut
1804:
1805: #-------------------------------------------
1.34 matthew 1806: sub select_dom_form {
1.743 raeburn 1807: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1808: my $onchange;
1809: if ($autosubmit) {
1810: $onchange = ' onchange="this.form.submit()"';
1811: }
1.550 albertel 1812: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1813: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1814: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1815: foreach my $dom (@domains) {
1816: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1817: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1818: if ($showdomdesc) {
1819: if ($dom ne '') {
1820: my $domdesc = &Apache::lonnet::domain($dom,'description');
1821: if ($domdesc ne '') {
1822: $selectdomain .= ' ('.$domdesc.')';
1823: }
1824: }
1825: }
1826: $selectdomain .= "</option>\n";
1.34 matthew 1827: }
1828: $selectdomain.="</select>";
1829: return $selectdomain;
1830: }
1831:
1.35 matthew 1832: #-------------------------------------------
1833:
1.45 matthew 1834: =pod
1835:
1.648 raeburn 1836: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1837:
1.586 raeburn 1838: input: 4 arguments (two required, two optional) -
1839: $domain - domain of new user
1840: $name - name of form element
1841: $default - Value of 'default' causes a default item to be first
1842: option, and selected by default.
1843: $hide - Value of 'hide' causes hiding of the name of the server,
1844: if 1 server found, or default, if 0 found.
1.594 raeburn 1845: output: returns 2 items:
1.586 raeburn 1846: (a) form element which contains either:
1847: (i) <select name="$name">
1848: <option value="$hostid1">$hostid $servers{$hostid}</option>
1849: <option value="$hostid2">$hostid $servers{$hostid}</option>
1850: </select>
1851: form item if there are multiple library servers in $domain, or
1852: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1853: if there is only one library server in $domain.
1854:
1855: (b) number of library servers found.
1856:
1857: See loncreateuser.pm for example of use.
1.35 matthew 1858:
1859: =cut
1860:
1861: #-------------------------------------------
1.586 raeburn 1862: sub home_server_form_item {
1863: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1864: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1865: my $result;
1866: my $numlib = keys(%servers);
1867: if ($numlib > 1) {
1868: $result .= '<select name="'.$name.'" />'."\n";
1869: if ($default) {
1.804 bisitz 1870: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1871: '</option>'."\n";
1872: }
1873: foreach my $hostid (sort(keys(%servers))) {
1874: $result.= '<option value="'.$hostid.'">'.
1875: $hostid.' '.$servers{$hostid}."</option>\n";
1876: }
1877: $result .= '</select>'."\n";
1878: } elsif ($numlib == 1) {
1879: my $hostid;
1880: foreach my $item (keys(%servers)) {
1881: $hostid = $item;
1882: }
1883: $result .= '<input type="hidden" name="'.$name.'" value="'.
1884: $hostid.'" />';
1885: if (!$hide) {
1886: $result .= $hostid.' '.$servers{$hostid};
1887: }
1888: $result .= "\n";
1889: } elsif ($default) {
1890: $result .= '<input type="hidden" name="'.$name.
1891: '" value="default" />';
1892: if (!$hide) {
1893: $result .= &mt('default');
1894: }
1895: $result .= "\n";
1.33 matthew 1896: }
1.586 raeburn 1897: return ($result,$numlib);
1.33 matthew 1898: }
1.112 bowersj2 1899:
1900: =pod
1901:
1.534 albertel 1902: =back
1903:
1.112 bowersj2 1904: =cut
1.87 matthew 1905:
1906: ###############################################################
1.112 bowersj2 1907: ## Decoding User Agent ##
1.87 matthew 1908: ###############################################################
1909:
1910: =pod
1911:
1.112 bowersj2 1912: =head1 Decoding the User Agent
1913:
1914: =over 4
1915:
1916: =item * &decode_user_agent()
1.87 matthew 1917:
1918: Inputs: $r
1919:
1920: Outputs:
1921:
1922: =over 4
1923:
1.112 bowersj2 1924: =item * $httpbrowser
1.87 matthew 1925:
1.112 bowersj2 1926: =item * $clientbrowser
1.87 matthew 1927:
1.112 bowersj2 1928: =item * $clientversion
1.87 matthew 1929:
1.112 bowersj2 1930: =item * $clientmathml
1.87 matthew 1931:
1.112 bowersj2 1932: =item * $clientunicode
1.87 matthew 1933:
1.112 bowersj2 1934: =item * $clientos
1.87 matthew 1935:
1936: =back
1937:
1.157 matthew 1938: =back
1939:
1.87 matthew 1940: =cut
1941:
1942: ###############################################################
1943: ###############################################################
1944: sub decode_user_agent {
1.247 albertel 1945: my ($r)=@_;
1.87 matthew 1946: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1947: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1948: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1949: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1950: my $clientbrowser='unknown';
1951: my $clientversion='0';
1952: my $clientmathml='';
1953: my $clientunicode='0';
1954: for (my $i=0;$i<=$#browsertype;$i++) {
1955: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1956: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1957: $clientbrowser=$bname;
1958: $httpbrowser=~/$vreg/i;
1959: $clientversion=$1;
1960: $clientmathml=($clientversion>=$minv);
1961: $clientunicode=($clientversion>=$univ);
1962: }
1963: }
1964: my $clientos='unknown';
1965: if (($httpbrowser=~/linux/i) ||
1966: ($httpbrowser=~/unix/i) ||
1967: ($httpbrowser=~/ux/i) ||
1968: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1969: if (($httpbrowser=~/vax/i) ||
1970: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1971: if ($httpbrowser=~/next/i) { $clientos='next'; }
1972: if (($httpbrowser=~/mac/i) ||
1973: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1974: if ($httpbrowser=~/win/i) { $clientos='win'; }
1975: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1976: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1977: $clientunicode,$clientos,);
1978: }
1979:
1.32 matthew 1980: ###############################################################
1981: ## Authentication changing form generation subroutines ##
1982: ###############################################################
1983: ##
1984: ## All of the authform_xxxxxxx subroutines take their inputs in a
1985: ## hash, and have reasonable default values.
1986: ##
1987: ## formname = the name given in the <form> tag.
1.35 matthew 1988: #-------------------------------------------
1989:
1.45 matthew 1990: =pod
1991:
1.112 bowersj2 1992: =head1 Authentication Routines
1993:
1994: =over 4
1995:
1.648 raeburn 1996: =item * &authform_xxxxxx()
1.35 matthew 1997:
1998: The authform_xxxxxx subroutines provide javascript and html forms which
1999: handle some of the conveniences required for authentication forms.
2000: This is not an optimal method, but it works.
2001:
2002: =over 4
2003:
1.112 bowersj2 2004: =item * authform_header
1.35 matthew 2005:
1.112 bowersj2 2006: =item * authform_authorwarning
1.35 matthew 2007:
1.112 bowersj2 2008: =item * authform_nochange
1.35 matthew 2009:
1.112 bowersj2 2010: =item * authform_kerberos
1.35 matthew 2011:
1.112 bowersj2 2012: =item * authform_internal
1.35 matthew 2013:
1.112 bowersj2 2014: =item * authform_filesystem
1.35 matthew 2015:
2016: =back
2017:
1.648 raeburn 2018: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2019:
1.35 matthew 2020: =cut
2021:
2022: #-------------------------------------------
1.32 matthew 2023: sub authform_header{
2024: my %in = (
2025: formname => 'cu',
1.80 albertel 2026: kerb_def_dom => '',
1.32 matthew 2027: @_,
2028: );
2029: $in{'formname'} = 'document.' . $in{'formname'};
2030: my $result='';
1.80 albertel 2031:
2032: #---------------------------------------------- Code for upper case translation
2033: my $Javascript_toUpperCase;
2034: unless ($in{kerb_def_dom}) {
2035: $Javascript_toUpperCase =<<"END";
2036: switch (choice) {
2037: case 'krb': currentform.elements[choicearg].value =
2038: currentform.elements[choicearg].value.toUpperCase();
2039: break;
2040: default:
2041: }
2042: END
2043: } else {
2044: $Javascript_toUpperCase = "";
2045: }
2046:
1.165 raeburn 2047: my $radioval = "'nochange'";
1.591 raeburn 2048: if (defined($in{'curr_authtype'})) {
2049: if ($in{'curr_authtype'} ne '') {
2050: $radioval = "'".$in{'curr_authtype'}."arg'";
2051: }
1.174 matthew 2052: }
1.165 raeburn 2053: my $argfield = 'null';
1.591 raeburn 2054: if (defined($in{'mode'})) {
1.165 raeburn 2055: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2056: if (defined($in{'curr_autharg'})) {
2057: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2058: $argfield = "'$in{'curr_autharg'}'";
2059: }
2060: }
2061: }
2062: }
2063:
1.32 matthew 2064: $result.=<<"END";
2065: var current = new Object();
1.165 raeburn 2066: current.radiovalue = $radioval;
2067: current.argfield = $argfield;
1.32 matthew 2068:
2069: function changed_radio(choice,currentform) {
2070: var choicearg = choice + 'arg';
2071: // If a radio button in changed, we need to change the argfield
2072: if (current.radiovalue != choice) {
2073: current.radiovalue = choice;
2074: if (current.argfield != null) {
2075: currentform.elements[current.argfield].value = '';
2076: }
2077: if (choice == 'nochange') {
2078: current.argfield = null;
2079: } else {
2080: current.argfield = choicearg;
2081: switch(choice) {
2082: case 'krb':
2083: currentform.elements[current.argfield].value =
2084: "$in{'kerb_def_dom'}";
2085: break;
2086: default:
2087: break;
2088: }
2089: }
2090: }
2091: return;
2092: }
1.22 www 2093:
1.32 matthew 2094: function changed_text(choice,currentform) {
2095: var choicearg = choice + 'arg';
2096: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2097: $Javascript_toUpperCase
1.32 matthew 2098: // clear old field
2099: if ((current.argfield != choicearg) && (current.argfield != null)) {
2100: currentform.elements[current.argfield].value = '';
2101: }
2102: current.argfield = choicearg;
2103: }
2104: set_auth_radio_buttons(choice,currentform);
2105: return;
1.20 www 2106: }
1.32 matthew 2107:
2108: function set_auth_radio_buttons(newvalue,currentform) {
2109: var i=0;
2110: while (i < currentform.login.length) {
2111: if (currentform.login[i].value == newvalue) { break; }
2112: i++;
2113: }
2114: if (i == currentform.login.length) {
2115: return;
2116: }
2117: current.radiovalue = newvalue;
2118: currentform.login[i].checked = true;
2119: return;
2120: }
2121: END
2122: return $result;
2123: }
2124:
2125: sub authform_authorwarning{
2126: my $result='';
1.144 matthew 2127: $result='<i>'.
2128: &mt('As a general rule, only authors or co-authors should be '.
2129: 'filesystem authenticated '.
2130: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2131: return $result;
2132: }
2133:
2134: sub authform_nochange{
2135: my %in = (
2136: formname => 'document.cu',
2137: kerb_def_dom => 'MSU.EDU',
2138: @_,
2139: );
1.586 raeburn 2140: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2141: my $result;
2142: if (keys(%can_assign) == 0) {
2143: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2144: } else {
2145: $result = '<label>'.&mt('[_1] Do not change login data',
2146: '<input type="radio" name="login" value="nochange" '.
2147: 'checked="checked" onclick="'.
1.281 albertel 2148: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2149: '</label>';
1.586 raeburn 2150: }
1.32 matthew 2151: return $result;
2152: }
2153:
1.591 raeburn 2154: sub authform_kerberos {
1.32 matthew 2155: my %in = (
2156: formname => 'document.cu',
2157: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2158: kerb_def_auth => 'krb4',
1.32 matthew 2159: @_,
2160: );
1.586 raeburn 2161: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2162: $autharg,$jscall);
2163: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2164: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2165: $check5 = ' checked="checked"';
1.80 albertel 2166: } else {
1.772 bisitz 2167: $check4 = ' checked="checked"';
1.80 albertel 2168: }
1.165 raeburn 2169: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2170: if (defined($in{'curr_authtype'})) {
2171: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2172: $krbcheck = ' checked="checked"';
1.623 raeburn 2173: if (defined($in{'mode'})) {
2174: if ($in{'mode'} eq 'modifyuser') {
2175: $krbcheck = '';
2176: }
2177: }
1.591 raeburn 2178: if (defined($in{'curr_kerb_ver'})) {
2179: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2180: $check5 = ' checked="checked"';
1.591 raeburn 2181: $check4 = '';
2182: } else {
1.772 bisitz 2183: $check4 = ' checked="checked"';
1.591 raeburn 2184: $check5 = '';
2185: }
1.586 raeburn 2186: }
1.591 raeburn 2187: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2188: $krbarg = $in{'curr_autharg'};
2189: }
1.586 raeburn 2190: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2191: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2192: $result =
2193: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2194: $in{'curr_autharg'},$krbver);
2195: } else {
2196: $result =
2197: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2198: }
2199: return $result;
2200: }
2201: }
2202: } else {
2203: if ($authnum == 1) {
1.784 bisitz 2204: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2205: }
2206: }
1.586 raeburn 2207: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2208: return;
1.587 raeburn 2209: } elsif ($authtype eq '') {
1.591 raeburn 2210: if (defined($in{'mode'})) {
1.587 raeburn 2211: if ($in{'mode'} eq 'modifycourse') {
2212: if ($authnum == 1) {
1.784 bisitz 2213: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2214: }
2215: }
2216: }
1.586 raeburn 2217: }
2218: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2219: if ($authtype eq '') {
2220: $authtype = '<input type="radio" name="login" value="krb" '.
2221: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2222: $krbcheck.' />';
2223: }
2224: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2225: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2226: $in{'curr_authtype'} eq 'krb5') ||
2227: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2228: $in{'curr_authtype'} eq 'krb4')) {
2229: $result .= &mt
1.144 matthew 2230: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2231: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2232: '<label>'.$authtype,
1.281 albertel 2233: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2234: 'value="'.$krbarg.'" '.
1.144 matthew 2235: 'onchange="'.$jscall.'" />',
1.281 albertel 2236: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2237: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2238: '</label>');
1.586 raeburn 2239: } elsif ($can_assign{'krb4'}) {
2240: $result .= &mt
2241: ('[_1] Kerberos authenticated with domain [_2] '.
2242: '[_3] Version 4 [_4]',
2243: '<label>'.$authtype,
2244: '</label><input type="text" size="10" name="krbarg" '.
2245: 'value="'.$krbarg.'" '.
2246: 'onchange="'.$jscall.'" />',
2247: '<label><input type="hidden" name="krbver" value="4" />',
2248: '</label>');
2249: } elsif ($can_assign{'krb5'}) {
2250: $result .= &mt
2251: ('[_1] Kerberos authenticated with domain [_2] '.
2252: '[_3] Version 5 [_4]',
2253: '<label>'.$authtype,
2254: '</label><input type="text" size="10" name="krbarg" '.
2255: 'value="'.$krbarg.'" '.
2256: 'onchange="'.$jscall.'" />',
2257: '<label><input type="hidden" name="krbver" value="5" />',
2258: '</label>');
2259: }
1.32 matthew 2260: return $result;
2261: }
2262:
2263: sub authform_internal{
1.586 raeburn 2264: my %in = (
1.32 matthew 2265: formname => 'document.cu',
2266: kerb_def_dom => 'MSU.EDU',
2267: @_,
2268: );
1.586 raeburn 2269: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2270: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2271: if (defined($in{'curr_authtype'})) {
2272: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2273: if ($can_assign{'int'}) {
1.772 bisitz 2274: $intcheck = 'checked="checked" ';
1.623 raeburn 2275: if (defined($in{'mode'})) {
2276: if ($in{'mode'} eq 'modifyuser') {
2277: $intcheck = '';
2278: }
2279: }
1.591 raeburn 2280: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2281: $intarg = $in{'curr_autharg'};
2282: }
2283: } else {
2284: $result = &mt('Currently internally authenticated.');
2285: return $result;
1.165 raeburn 2286: }
2287: }
1.586 raeburn 2288: } else {
2289: if ($authnum == 1) {
1.784 bisitz 2290: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2291: }
2292: }
2293: if (!$can_assign{'int'}) {
2294: return;
1.587 raeburn 2295: } elsif ($authtype eq '') {
1.591 raeburn 2296: if (defined($in{'mode'})) {
1.587 raeburn 2297: if ($in{'mode'} eq 'modifycourse') {
2298: if ($authnum == 1) {
1.784 bisitz 2299: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2300: }
2301: }
2302: }
1.165 raeburn 2303: }
1.586 raeburn 2304: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2305: if ($authtype eq '') {
2306: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2307: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2308: }
1.605 bisitz 2309: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2310: $intarg.'" onchange="'.$jscall.'" />';
2311: $result = &mt
1.144 matthew 2312: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2313: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2314: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2315: return $result;
2316: }
2317:
2318: sub authform_local{
2319: my %in = (
2320: formname => 'document.cu',
2321: kerb_def_dom => 'MSU.EDU',
2322: @_,
2323: );
1.586 raeburn 2324: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2325: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2326: if (defined($in{'curr_authtype'})) {
2327: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2328: if ($can_assign{'loc'}) {
1.772 bisitz 2329: $loccheck = 'checked="checked" ';
1.623 raeburn 2330: if (defined($in{'mode'})) {
2331: if ($in{'mode'} eq 'modifyuser') {
2332: $loccheck = '';
2333: }
2334: }
1.591 raeburn 2335: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2336: $locarg = $in{'curr_autharg'};
2337: }
2338: } else {
2339: $result = &mt('Currently using local (institutional) authentication.');
2340: return $result;
1.165 raeburn 2341: }
2342: }
1.586 raeburn 2343: } else {
2344: if ($authnum == 1) {
1.784 bisitz 2345: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2346: }
2347: }
2348: if (!$can_assign{'loc'}) {
2349: return;
1.587 raeburn 2350: } elsif ($authtype eq '') {
1.591 raeburn 2351: if (defined($in{'mode'})) {
1.587 raeburn 2352: if ($in{'mode'} eq 'modifycourse') {
2353: if ($authnum == 1) {
1.784 bisitz 2354: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2355: }
2356: }
2357: }
1.165 raeburn 2358: }
1.586 raeburn 2359: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2360: if ($authtype eq '') {
2361: $authtype = '<input type="radio" name="login" value="loc" '.
2362: $loccheck.' onchange="'.$jscall.'" onclick="'.
2363: $jscall.'" />';
2364: }
2365: $autharg = '<input type="text" size="10" name="locarg" value="'.
2366: $locarg.'" onchange="'.$jscall.'" />';
2367: $result = &mt('[_1] Local Authentication with argument [_2]',
2368: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2369: return $result;
2370: }
2371:
2372: sub authform_filesystem{
2373: my %in = (
2374: formname => 'document.cu',
2375: kerb_def_dom => 'MSU.EDU',
2376: @_,
2377: );
1.586 raeburn 2378: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2379: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2380: if (defined($in{'curr_authtype'})) {
2381: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2382: if ($can_assign{'fsys'}) {
1.772 bisitz 2383: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2384: if (defined($in{'mode'})) {
2385: if ($in{'mode'} eq 'modifyuser') {
2386: $fsyscheck = '';
2387: }
2388: }
1.586 raeburn 2389: } else {
2390: $result = &mt('Currently Filesystem Authenticated.');
2391: return $result;
2392: }
2393: }
2394: } else {
2395: if ($authnum == 1) {
1.784 bisitz 2396: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2397: }
2398: }
2399: if (!$can_assign{'fsys'}) {
2400: return;
1.587 raeburn 2401: } elsif ($authtype eq '') {
1.591 raeburn 2402: if (defined($in{'mode'})) {
1.587 raeburn 2403: if ($in{'mode'} eq 'modifycourse') {
2404: if ($authnum == 1) {
1.784 bisitz 2405: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2406: }
2407: }
2408: }
1.586 raeburn 2409: }
2410: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2411: if ($authtype eq '') {
2412: $authtype = '<input type="radio" name="login" value="fsys" '.
2413: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2414: $jscall.'" />';
2415: }
2416: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2417: ' onchange="'.$jscall.'" />';
2418: $result = &mt
1.144 matthew 2419: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2420: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2421: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2422: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2423: 'onchange="'.$jscall.'" />');
1.32 matthew 2424: return $result;
2425: }
2426:
1.586 raeburn 2427: sub get_assignable_auth {
2428: my ($dom) = @_;
2429: if ($dom eq '') {
2430: $dom = $env{'request.role.domain'};
2431: }
2432: my %can_assign = (
2433: krb4 => 1,
2434: krb5 => 1,
2435: int => 1,
2436: loc => 1,
2437: );
2438: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2439: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2440: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2441: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2442: my $context;
2443: if ($env{'request.role'} =~ /^au/) {
2444: $context = 'author';
2445: } elsif ($env{'request.role'} =~ /^dc/) {
2446: $context = 'domain';
2447: } elsif ($env{'request.course.id'}) {
2448: $context = 'course';
2449: }
2450: if ($context) {
2451: if (ref($authhash->{$context}) eq 'HASH') {
2452: %can_assign = %{$authhash->{$context}};
2453: }
2454: }
2455: }
2456: }
2457: my $authnum = 0;
2458: foreach my $key (keys(%can_assign)) {
2459: if ($can_assign{$key}) {
2460: $authnum ++;
2461: }
2462: }
2463: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2464: $authnum --;
2465: }
2466: return ($authnum,%can_assign);
2467: }
2468:
1.80 albertel 2469: ###############################################################
2470: ## Get Kerberos Defaults for Domain ##
2471: ###############################################################
2472: ##
2473: ## Returns default kerberos version and an associated argument
2474: ## as listed in file domain.tab. If not listed, provides
2475: ## appropriate default domain and kerberos version.
2476: ##
2477: #-------------------------------------------
2478:
2479: =pod
2480:
1.648 raeburn 2481: =item * &get_kerberos_defaults()
1.80 albertel 2482:
2483: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2484: version and domain. If not found, it defaults to version 4 and the
2485: domain of the server.
1.80 albertel 2486:
1.648 raeburn 2487: =over 4
2488:
1.80 albertel 2489: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2490:
1.648 raeburn 2491: =back
2492:
2493: =back
2494:
1.80 albertel 2495: =cut
2496:
2497: #-------------------------------------------
2498: sub get_kerberos_defaults {
2499: my $domain=shift;
1.641 raeburn 2500: my ($krbdef,$krbdefdom);
2501: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2502: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2503: $krbdef = $domdefaults{'auth_def'};
2504: $krbdefdom = $domdefaults{'auth_arg_def'};
2505: } else {
1.80 albertel 2506: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2507: my $krbdefdom=$1;
2508: $krbdefdom=~tr/a-z/A-Z/;
2509: $krbdef = "krb4";
2510: }
2511: return ($krbdef,$krbdefdom);
2512: }
1.112 bowersj2 2513:
1.32 matthew 2514:
1.46 matthew 2515: ###############################################################
2516: ## Thesaurus Functions ##
2517: ###############################################################
1.20 www 2518:
1.46 matthew 2519: =pod
1.20 www 2520:
1.112 bowersj2 2521: =head1 Thesaurus Functions
2522:
2523: =over 4
2524:
1.648 raeburn 2525: =item * &initialize_keywords()
1.46 matthew 2526:
2527: Initializes the package variable %Keywords if it is empty. Uses the
2528: package variable $thesaurus_db_file.
2529:
2530: =cut
2531:
2532: ###################################################
2533:
2534: sub initialize_keywords {
2535: return 1 if (scalar keys(%Keywords));
2536: # If we are here, %Keywords is empty, so fill it up
2537: # Make sure the file we need exists...
2538: if (! -e $thesaurus_db_file) {
2539: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2540: " failed because it does not exist");
2541: return 0;
2542: }
2543: # Set up the hash as a database
2544: my %thesaurus_db;
2545: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2546: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2547: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2548: $thesaurus_db_file);
2549: return 0;
2550: }
2551: # Get the average number of appearances of a word.
2552: my $avecount = $thesaurus_db{'average.count'};
2553: # Put keywords (those that appear > average) into %Keywords
2554: while (my ($word,$data)=each (%thesaurus_db)) {
2555: my ($count,undef) = split /:/,$data;
2556: $Keywords{$word}++ if ($count > $avecount);
2557: }
2558: untie %thesaurus_db;
2559: # Remove special values from %Keywords.
1.356 albertel 2560: foreach my $value ('total.count','average.count') {
2561: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2562: }
1.46 matthew 2563: return 1;
2564: }
2565:
2566: ###################################################
2567:
2568: =pod
2569:
1.648 raeburn 2570: =item * &keyword($word)
1.46 matthew 2571:
2572: Returns true if $word is a keyword. A keyword is a word that appears more
2573: than the average number of times in the thesaurus database. Calls
2574: &initialize_keywords
2575:
2576: =cut
2577:
2578: ###################################################
1.20 www 2579:
2580: sub keyword {
1.46 matthew 2581: return if (!&initialize_keywords());
2582: my $word=lc(shift());
2583: $word=~s/\W//g;
2584: return exists($Keywords{$word});
1.20 www 2585: }
1.46 matthew 2586:
2587: ###############################################################
2588:
2589: =pod
1.20 www 2590:
1.648 raeburn 2591: =item * &get_related_words()
1.46 matthew 2592:
1.160 matthew 2593: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2594: an array of words. If the keyword is not in the thesaurus, an empty array
2595: will be returned. The order of the words returned is determined by the
2596: database which holds them.
2597:
2598: Uses global $thesaurus_db_file.
2599:
2600: =cut
2601:
2602: ###############################################################
2603: sub get_related_words {
2604: my $keyword = shift;
2605: my %thesaurus_db;
2606: if (! -e $thesaurus_db_file) {
2607: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2608: "failed because the file does not exist");
2609: return ();
2610: }
2611: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2612: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2613: return ();
2614: }
2615: my @Words=();
1.429 www 2616: my $count=0;
1.46 matthew 2617: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2618: # The first element is the number of times
2619: # the word appears. We do not need it now.
1.429 www 2620: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2621: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2622: my $threshold=$mostfrequentcount/10;
2623: foreach my $possibleword (@RelatedWords) {
2624: my ($word,$wordcount)=split(/\,/,$possibleword);
2625: if ($wordcount>$threshold) {
2626: push(@Words,$word);
2627: $count++;
2628: if ($count>10) { last; }
2629: }
1.20 www 2630: }
2631: }
1.46 matthew 2632: untie %thesaurus_db;
2633: return @Words;
1.14 harris41 2634: }
1.46 matthew 2635:
1.112 bowersj2 2636: =pod
2637:
2638: =back
2639:
2640: =cut
1.61 www 2641:
2642: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2643: =pod
2644:
1.112 bowersj2 2645: =head1 User Name Functions
2646:
2647: =over 4
2648:
1.648 raeburn 2649: =item * &plainname($uname,$udom,$first)
1.81 albertel 2650:
1.112 bowersj2 2651: Takes a users logon name and returns it as a string in
1.226 albertel 2652: "first middle last generation" form
2653: if $first is set to 'lastname' then it returns it as
2654: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2655:
2656: =cut
1.61 www 2657:
1.295 www 2658:
1.81 albertel 2659: ###############################################################
1.61 www 2660: sub plainname {
1.226 albertel 2661: my ($uname,$udom,$first)=@_;
1.537 albertel 2662: return if (!defined($uname) || !defined($udom));
1.295 www 2663: my %names=&getnames($uname,$udom);
1.226 albertel 2664: my $name=&Apache::lonnet::format_name($names{'firstname'},
2665: $names{'middlename'},
2666: $names{'lastname'},
2667: $names{'generation'},$first);
2668: $name=~s/^\s+//;
1.62 www 2669: $name=~s/\s+$//;
2670: $name=~s/\s+/ /g;
1.353 albertel 2671: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2672: return $name;
1.61 www 2673: }
1.66 www 2674:
2675: # -------------------------------------------------------------------- Nickname
1.81 albertel 2676: =pod
2677:
1.648 raeburn 2678: =item * &nickname($uname,$udom)
1.81 albertel 2679:
2680: Gets a users name and returns it as a string as
2681:
2682: ""nickname""
1.66 www 2683:
1.81 albertel 2684: if the user has a nickname or
2685:
2686: "first middle last generation"
2687:
2688: if the user does not
2689:
2690: =cut
1.66 www 2691:
2692: sub nickname {
2693: my ($uname,$udom)=@_;
1.537 albertel 2694: return if (!defined($uname) || !defined($udom));
1.295 www 2695: my %names=&getnames($uname,$udom);
1.68 albertel 2696: my $name=$names{'nickname'};
1.66 www 2697: if ($name) {
2698: $name='"'.$name.'"';
2699: } else {
2700: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2701: $names{'lastname'}.' '.$names{'generation'};
2702: $name=~s/\s+$//;
2703: $name=~s/\s+/ /g;
2704: }
2705: return $name;
2706: }
2707:
1.295 www 2708: sub getnames {
2709: my ($uname,$udom)=@_;
1.537 albertel 2710: return if (!defined($uname) || !defined($udom));
1.433 albertel 2711: if ($udom eq 'public' && $uname eq 'public') {
2712: return ('lastname' => &mt('Public'));
2713: }
1.295 www 2714: my $id=$uname.':'.$udom;
2715: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2716: if ($cached) {
2717: return %{$names};
2718: } else {
2719: my %loadnames=&Apache::lonnet::get('environment',
2720: ['firstname','middlename','lastname','generation','nickname'],
2721: $udom,$uname);
2722: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2723: return %loadnames;
2724: }
2725: }
1.61 www 2726:
1.542 raeburn 2727: # -------------------------------------------------------------------- getemails
1.648 raeburn 2728:
1.542 raeburn 2729: =pod
2730:
1.648 raeburn 2731: =item * &getemails($uname,$udom)
1.542 raeburn 2732:
2733: Gets a user's email information and returns it as a hash with keys:
2734: notification, critnotification, permanentemail
2735:
2736: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2737: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2738:
1.648 raeburn 2739:
1.542 raeburn 2740: =cut
2741:
1.648 raeburn 2742:
1.466 albertel 2743: sub getemails {
2744: my ($uname,$udom)=@_;
2745: if ($udom eq 'public' && $uname eq 'public') {
2746: return;
2747: }
1.467 www 2748: if (!$udom) { $udom=$env{'user.domain'}; }
2749: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2750: my $id=$uname.':'.$udom;
2751: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2752: if ($cached) {
2753: return %{$names};
2754: } else {
2755: my %loadnames=&Apache::lonnet::get('environment',
2756: ['notification','critnotification',
2757: 'permanentemail'],
2758: $udom,$uname);
2759: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2760: return %loadnames;
2761: }
2762: }
2763:
1.551 albertel 2764: sub flush_email_cache {
2765: my ($uname,$udom)=@_;
2766: if (!$udom) { $udom =$env{'user.domain'}; }
2767: if (!$uname) { $uname=$env{'user.name'}; }
2768: return if ($udom eq 'public' && $uname eq 'public');
2769: my $id=$uname.':'.$udom;
2770: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2771: }
2772:
1.728 raeburn 2773: # -------------------------------------------------------------------- getlangs
2774:
2775: =pod
2776:
2777: =item * &getlangs($uname,$udom)
2778:
2779: Gets a user's language preference and returns it as a hash with key:
2780: language.
2781:
2782: =cut
2783:
2784:
2785: sub getlangs {
2786: my ($uname,$udom) = @_;
2787: if (!$udom) { $udom =$env{'user.domain'}; }
2788: if (!$uname) { $uname=$env{'user.name'}; }
2789: my $id=$uname.':'.$udom;
2790: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2791: if ($cached) {
2792: return %{$langs};
2793: } else {
2794: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2795: $udom,$uname);
2796: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2797: return %loadlangs;
2798: }
2799: }
2800:
2801: sub flush_langs_cache {
2802: my ($uname,$udom)=@_;
2803: if (!$udom) { $udom =$env{'user.domain'}; }
2804: if (!$uname) { $uname=$env{'user.name'}; }
2805: return if ($udom eq 'public' && $uname eq 'public');
2806: my $id=$uname.':'.$udom;
2807: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2808: }
2809:
1.61 www 2810: # ------------------------------------------------------------------ Screenname
1.81 albertel 2811:
2812: =pod
2813:
1.648 raeburn 2814: =item * &screenname($uname,$udom)
1.81 albertel 2815:
2816: Gets a users screenname and returns it as a string
2817:
2818: =cut
1.61 www 2819:
2820: sub screenname {
2821: my ($uname,$udom)=@_;
1.258 albertel 2822: if ($uname eq $env{'user.name'} &&
2823: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2824: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2825: return $names{'screenname'};
1.62 www 2826: }
2827:
1.212 albertel 2828:
1.802 bisitz 2829: # ------------------------------------------------------------- Confirm Wrapper
2830: =pod
2831:
2832: =item confirmwrapper
2833:
2834: Wrap messages about completion of operation in box
2835:
2836: =cut
2837:
2838: sub confirmwrapper {
2839: my ($message)=@_;
2840: if ($message) {
2841: return "\n".'<div class="LC_confirm_box">'."\n"
2842: .$message."\n"
2843: .'</div>'."\n";
2844: } else {
2845: return $message;
2846: }
2847: }
2848:
1.62 www 2849: # ------------------------------------------------------------- Message Wrapper
2850:
2851: sub messagewrapper {
1.369 www 2852: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2853: return
1.441 albertel 2854: '<a href="/adm/email?compose=individual&'.
2855: 'recname='.$username.'&recdom='.$domain.
2856: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2857: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2858: }
1.802 bisitz 2859:
1.74 www 2860: # --------------------------------------------------------------- Notes Wrapper
2861:
2862: sub noteswrapper {
2863: my ($link,$un,$do)=@_;
2864: return
2865: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2866: }
1.802 bisitz 2867:
1.62 www 2868: # ------------------------------------------------------------- Aboutme Wrapper
2869:
2870: sub aboutmewrapper {
1.166 www 2871: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2872: if (!defined($username) && !defined($domain)) {
2873: return;
2874: }
1.205 www 2875: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2876: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2877: }
2878:
2879: # ------------------------------------------------------------ Syllabus Wrapper
2880:
2881: sub syllabuswrapper {
1.707 bisitz 2882: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2883: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2884: }
1.14 harris41 2885:
1.802 bisitz 2886: # -----------------------------------------------------------------------------
2887:
1.208 matthew 2888: sub track_student_link {
1.268 albertel 2889: my ($linktext,$sname,$sdom,$target,$start) = @_;
2890: my $link ="/adm/trackstudent?";
1.208 matthew 2891: my $title = 'View recent activity';
2892: if (defined($sname) && $sname !~ /^\s*$/ &&
2893: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2894: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2895: $title .= ' of this student';
1.268 albertel 2896: }
1.208 matthew 2897: if (defined($target) && $target !~ /^\s*$/) {
2898: $target = qq{target="$target"};
2899: } else {
2900: $target = '';
2901: }
1.268 albertel 2902: if ($start) { $link.='&start='.$start; }
1.554 albertel 2903: $title = &mt($title);
2904: $linktext = &mt($linktext);
1.448 albertel 2905: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2906: &help_open_topic('View_recent_activity');
1.208 matthew 2907: }
2908:
1.781 raeburn 2909: sub slot_reservations_link {
2910: my ($linktext,$sname,$sdom,$target) = @_;
2911: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2912: my $title = 'View slot reservation history';
2913: if (defined($sname) && $sname !~ /^\s*$/ &&
2914: defined($sdom) && $sdom !~ /^\s*$/) {
2915: $link .= "&uname=$sname&udom=$sdom";
2916: $title .= ' of this student';
2917: }
2918: if (defined($target) && $target !~ /^\s*$/) {
2919: $target = qq{target="$target"};
2920: } else {
2921: $target = '';
2922: }
2923: $title = &mt($title);
2924: $linktext = &mt($linktext);
2925: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2926: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2927:
2928: }
2929:
1.508 www 2930: # ===================================================== Display a student photo
2931:
2932:
1.509 albertel 2933: sub student_image_tag {
1.508 www 2934: my ($domain,$user)=@_;
2935: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2936: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2937: return '<img src="'.$imgsrc.'" align="right" />';
2938: } else {
2939: return '';
2940: }
2941: }
2942:
1.112 bowersj2 2943: =pod
2944:
2945: =back
2946:
2947: =head1 Access .tab File Data
2948:
2949: =over 4
2950:
1.648 raeburn 2951: =item * &languageids()
1.112 bowersj2 2952:
2953: returns list of all language ids
2954:
2955: =cut
2956:
1.14 harris41 2957: sub languageids {
1.16 harris41 2958: return sort(keys(%language));
1.14 harris41 2959: }
2960:
1.112 bowersj2 2961: =pod
2962:
1.648 raeburn 2963: =item * &languagedescription()
1.112 bowersj2 2964:
2965: returns description of a specified language id
2966:
2967: =cut
2968:
1.14 harris41 2969: sub languagedescription {
1.125 www 2970: my $code=shift;
2971: return ($supported_language{$code}?'* ':'').
2972: $language{$code}.
1.126 www 2973: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2974: }
2975:
2976: sub plainlanguagedescription {
2977: my $code=shift;
2978: return $language{$code};
2979: }
2980:
2981: sub supportedlanguagecode {
2982: my $code=shift;
2983: return $supported_language{$code};
1.97 www 2984: }
2985:
1.112 bowersj2 2986: =pod
2987:
1.648 raeburn 2988: =item * ©rightids()
1.112 bowersj2 2989:
2990: returns list of all copyrights
2991:
2992: =cut
2993:
2994: sub copyrightids {
2995: return sort(keys(%cprtag));
2996: }
2997:
2998: =pod
2999:
1.648 raeburn 3000: =item * ©rightdescription()
1.112 bowersj2 3001:
3002: returns description of a specified copyright id
3003:
3004: =cut
3005:
3006: sub copyrightdescription {
1.166 www 3007: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3008: }
1.197 matthew 3009:
3010: =pod
3011:
1.648 raeburn 3012: =item * &source_copyrightids()
1.192 taceyjo1 3013:
3014: returns list of all source copyrights
3015:
3016: =cut
3017:
3018: sub source_copyrightids {
3019: return sort(keys(%scprtag));
3020: }
3021:
3022: =pod
3023:
1.648 raeburn 3024: =item * &source_copyrightdescription()
1.192 taceyjo1 3025:
3026: returns description of a specified source copyright id
3027:
3028: =cut
3029:
3030: sub source_copyrightdescription {
3031: return &mt($scprtag{shift(@_)});
3032: }
1.112 bowersj2 3033:
3034: =pod
3035:
1.648 raeburn 3036: =item * &filecategories()
1.112 bowersj2 3037:
3038: returns list of all file categories
3039:
3040: =cut
3041:
3042: sub filecategories {
3043: return sort(keys(%category_extensions));
3044: }
3045:
3046: =pod
3047:
1.648 raeburn 3048: =item * &filecategorytypes()
1.112 bowersj2 3049:
3050: returns list of file types belonging to a given file
3051: category
3052:
3053: =cut
3054:
3055: sub filecategorytypes {
1.356 albertel 3056: my ($cat) = @_;
3057: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3058: }
3059:
3060: =pod
3061:
1.648 raeburn 3062: =item * &fileembstyle()
1.112 bowersj2 3063:
3064: returns embedding style for a specified file type
3065:
3066: =cut
3067:
3068: sub fileembstyle {
3069: return $fe{lc(shift(@_))};
1.169 www 3070: }
3071:
1.351 www 3072: sub filemimetype {
3073: return $fm{lc(shift(@_))};
3074: }
3075:
1.169 www 3076:
3077: sub filecategoryselect {
3078: my ($name,$value)=@_;
1.189 matthew 3079: return &select_form($value,$name,
1.169 www 3080: '' => &mt('Any category'),
3081: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3082: }
3083:
3084: =pod
3085:
1.648 raeburn 3086: =item * &filedescription()
1.112 bowersj2 3087:
3088: returns description for a specified file type
3089:
3090: =cut
3091:
3092: sub filedescription {
1.188 matthew 3093: my $file_description = $fd{lc(shift())};
3094: $file_description =~ s:([\[\]]):~$1:g;
3095: return &mt($file_description);
1.112 bowersj2 3096: }
3097:
3098: =pod
3099:
1.648 raeburn 3100: =item * &filedescriptionex()
1.112 bowersj2 3101:
3102: returns description for a specified file type with
3103: extra formatting
3104:
3105: =cut
3106:
3107: sub filedescriptionex {
3108: my $ex=shift;
1.188 matthew 3109: my $file_description = $fd{lc($ex)};
3110: $file_description =~ s:([\[\]]):~$1:g;
3111: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3112: }
3113:
3114: # End of .tab access
3115: =pod
3116:
3117: =back
3118:
3119: =cut
3120:
3121: # ------------------------------------------------------------------ File Types
3122: sub fileextensions {
3123: return sort(keys(%fe));
3124: }
3125:
1.97 www 3126: # ----------------------------------------------------------- Display Languages
3127: # returns a hash with all desired display languages
3128: #
3129:
3130: sub display_languages {
3131: my %languages=();
1.695 raeburn 3132: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3133: $languages{$lang}=1;
1.97 www 3134: }
3135: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3136: if ($env{'form.displaylanguage'}) {
1.356 albertel 3137: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3138: $languages{$lang}=1;
1.97 www 3139: }
3140: }
3141: return %languages;
1.14 harris41 3142: }
3143:
1.582 albertel 3144: sub languages {
3145: my ($possible_langs) = @_;
1.695 raeburn 3146: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3147: if (!ref($possible_langs)) {
3148: if( wantarray ) {
3149: return @preferred_langs;
3150: } else {
3151: return $preferred_langs[0];
3152: }
3153: }
3154: my %possibilities = map { $_ => 1 } (@$possible_langs);
3155: my @preferred_possibilities;
3156: foreach my $preferred_lang (@preferred_langs) {
3157: if (exists($possibilities{$preferred_lang})) {
3158: push(@preferred_possibilities, $preferred_lang);
3159: }
3160: }
3161: if( wantarray ) {
3162: return @preferred_possibilities;
3163: }
3164: return $preferred_possibilities[0];
3165: }
3166:
1.742 raeburn 3167: sub user_lang {
3168: my ($touname,$toudom,$fromcid) = @_;
3169: my @userlangs;
3170: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3171: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3172: $env{'course.'.$fromcid.'.languages'}));
3173: } else {
3174: my %langhash = &getlangs($touname,$toudom);
3175: if ($langhash{'languages'} ne '') {
3176: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3177: } else {
3178: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3179: if ($domdefs{'lang_def'} ne '') {
3180: @userlangs = ($domdefs{'lang_def'});
3181: }
3182: }
3183: }
3184: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3185: my $user_lh = Apache::localize->get_handle(@languages);
3186: return $user_lh;
3187: }
3188:
3189:
1.112 bowersj2 3190: ###############################################################
3191: ## Student Answer Attempts ##
3192: ###############################################################
3193:
3194: =pod
3195:
3196: =head1 Alternate Problem Views
3197:
3198: =over 4
3199:
1.648 raeburn 3200: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3201: $getattempt, $regexp, $gradesub)
3202:
3203: Return string with previous attempt on problem. Arguments:
3204:
3205: =over 4
3206:
3207: =item * $symb: Problem, including path
3208:
3209: =item * $username: username of the desired student
3210:
3211: =item * $domain: domain of the desired student
1.14 harris41 3212:
1.112 bowersj2 3213: =item * $course: Course ID
1.14 harris41 3214:
1.112 bowersj2 3215: =item * $getattempt: Leave blank for all attempts, otherwise put
3216: something
1.14 harris41 3217:
1.112 bowersj2 3218: =item * $regexp: if string matches this regexp, the string will be
3219: sent to $gradesub
1.14 harris41 3220:
1.112 bowersj2 3221: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3222:
1.112 bowersj2 3223: =back
1.14 harris41 3224:
1.112 bowersj2 3225: The output string is a table containing all desired attempts, if any.
1.16 harris41 3226:
1.112 bowersj2 3227: =cut
1.1 albertel 3228:
3229: sub get_previous_attempt {
1.43 ng 3230: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3231: my $prevattempts='';
1.43 ng 3232: no strict 'refs';
1.1 albertel 3233: if ($symb) {
1.3 albertel 3234: my (%returnhash)=
3235: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3236: if ($returnhash{'version'}) {
3237: my %lasthash=();
3238: my $version;
3239: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3240: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3241: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3242: }
1.1 albertel 3243: }
1.596 albertel 3244: $prevattempts=&start_data_table().&start_data_table_header_row();
3245: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3246: foreach my $key (sort(keys(%lasthash))) {
3247: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3248: if ($#parts > 0) {
1.31 albertel 3249: my $data=$parts[-1];
3250: pop(@parts);
1.596 albertel 3251: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3252: } else {
1.41 ng 3253: if ($#parts == 0) {
3254: $prevattempts.='<th>'.$parts[0].'</th>';
3255: } else {
3256: $prevattempts.='<th>'.$ign.'</th>';
3257: }
1.31 albertel 3258: }
1.16 harris41 3259: }
1.596 albertel 3260: $prevattempts.=&end_data_table_header_row();
1.40 ng 3261: if ($getattempt eq '') {
3262: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3263: $prevattempts.=&start_data_table_row().
3264: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3265: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3266: my $value = &format_previous_attempt_value($key,
3267: $returnhash{$version.':'.$key});
3268: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3269: }
1.596 albertel 3270: $prevattempts.=&end_data_table_row();
1.40 ng 3271: }
1.1 albertel 3272: }
1.596 albertel 3273: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3274: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3275: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3276: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3277: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3278: }
1.596 albertel 3279: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3280: } else {
1.596 albertel 3281: $prevattempts=
3282: &start_data_table().&start_data_table_row().
3283: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3284: &end_data_table_row().&end_data_table();
1.1 albertel 3285: }
3286: } else {
1.596 albertel 3287: $prevattempts=
3288: &start_data_table().&start_data_table_row().
3289: '<td>'.&mt('No data.').'</td>'.
3290: &end_data_table_row().&end_data_table();
1.1 albertel 3291: }
1.10 albertel 3292: }
3293:
1.581 albertel 3294: sub format_previous_attempt_value {
3295: my ($key,$value) = @_;
3296: if ($key =~ /timestamp/) {
3297: $value = &Apache::lonlocal::locallocaltime($value);
3298: } elsif (ref($value) eq 'ARRAY') {
3299: $value = '('.join(', ', @{ $value }).')';
3300: } else {
3301: $value = &unescape($value);
3302: }
3303: return $value;
3304: }
3305:
3306:
1.107 albertel 3307: sub relative_to_absolute {
3308: my ($url,$output)=@_;
3309: my $parser=HTML::TokeParser->new(\$output);
3310: my $token;
3311: my $thisdir=$url;
3312: my @rlinks=();
3313: while ($token=$parser->get_token) {
3314: if ($token->[0] eq 'S') {
3315: if ($token->[1] eq 'a') {
3316: if ($token->[2]->{'href'}) {
3317: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3318: }
3319: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3320: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3321: } elsif ($token->[1] eq 'base') {
3322: $thisdir=$token->[2]->{'href'};
3323: }
3324: }
3325: }
3326: $thisdir=~s-/[^/]*$--;
1.356 albertel 3327: foreach my $link (@rlinks) {
1.726 raeburn 3328: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3329: ($link=~/^\//) ||
3330: ($link=~/^javascript:/i) ||
3331: ($link=~/^mailto:/i) ||
3332: ($link=~/^\#/)) {
3333: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3334: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3335: }
3336: }
3337: # -------------------------------------------------- Deal with Applet codebases
3338: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3339: return $output;
3340: }
3341:
1.112 bowersj2 3342: =pod
3343:
1.648 raeburn 3344: =item * &get_student_view()
1.112 bowersj2 3345:
3346: show a snapshot of what student was looking at
3347:
3348: =cut
3349:
1.10 albertel 3350: sub get_student_view {
1.186 albertel 3351: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3352: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3353: my (%form);
1.10 albertel 3354: my @elements=('symb','courseid','domain','username');
3355: foreach my $element (@elements) {
1.186 albertel 3356: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3357: }
1.186 albertel 3358: if (defined($moreenv)) {
3359: %form=(%form,%{$moreenv});
3360: }
1.236 albertel 3361: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3362: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3363: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3364: $userview=~s/\<body[^\>]*\>//gi;
3365: $userview=~s/\<\/body\>//gi;
3366: $userview=~s/\<html\>//gi;
3367: $userview=~s/\<\/html\>//gi;
3368: $userview=~s/\<head\>//gi;
3369: $userview=~s/\<\/head\>//gi;
3370: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3371: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3372: if (wantarray) {
3373: return ($userview,$response);
3374: } else {
3375: return $userview;
3376: }
3377: }
3378:
3379: sub get_student_view_with_retries {
3380: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3381:
3382: my $ok = 0; # True if we got a good response.
3383: my $content;
3384: my $response;
3385:
3386: # Try to get the student_view done. within the retries count:
3387:
3388: do {
3389: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3390: $ok = $response->is_success;
3391: if (!$ok) {
3392: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3393: }
3394: $retries--;
3395: } while (!$ok && ($retries > 0));
3396:
3397: if (!$ok) {
3398: $content = ''; # On error return an empty content.
3399: }
1.651 www 3400: if (wantarray) {
3401: return ($content, $response);
3402: } else {
3403: return $content;
3404: }
1.11 albertel 3405: }
3406:
1.112 bowersj2 3407: =pod
3408:
1.648 raeburn 3409: =item * &get_student_answers()
1.112 bowersj2 3410:
3411: show a snapshot of how student was answering problem
3412:
3413: =cut
3414:
1.11 albertel 3415: sub get_student_answers {
1.100 sakharuk 3416: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3417: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3418: my (%moreenv);
1.11 albertel 3419: my @elements=('symb','courseid','domain','username');
3420: foreach my $element (@elements) {
1.186 albertel 3421: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3422: }
1.186 albertel 3423: $moreenv{'grade_target'}='answer';
3424: %moreenv=(%form,%moreenv);
1.497 raeburn 3425: $feedurl = &Apache::lonnet::clutter($feedurl);
3426: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3427: return $userview;
1.1 albertel 3428: }
1.116 albertel 3429:
3430: =pod
3431:
3432: =item * &submlink()
3433:
1.242 albertel 3434: Inputs: $text $uname $udom $symb $target
1.116 albertel 3435:
3436: Returns: A link to grades.pm such as to see the SUBM view of a student
3437:
3438: =cut
3439:
3440: ###############################################
3441: sub submlink {
1.242 albertel 3442: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3443: if (!($uname && $udom)) {
3444: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3445: &Apache::lonnet::whichuser($symb);
1.116 albertel 3446: if (!$symb) { $symb=$cursymb; }
3447: }
1.254 matthew 3448: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3449: $symb=&escape($symb);
1.242 albertel 3450: if ($target) { $target="target=\"$target\""; }
3451: return '<a href="/adm/grades?&command=submission&'.
3452: 'symb='.$symb.'&student='.$uname.
3453: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3454: }
3455: ##############################################
3456:
3457: =pod
3458:
3459: =item * &pgrdlink()
3460:
3461: Inputs: $text $uname $udom $symb $target
3462:
3463: Returns: A link to grades.pm such as to see the PGRD view of a student
3464:
3465: =cut
3466:
3467: ###############################################
3468: sub pgrdlink {
3469: my $link=&submlink(@_);
3470: $link=~s/(&command=submission)/$1&showgrading=yes/;
3471: return $link;
3472: }
3473: ##############################################
3474:
3475: =pod
3476:
3477: =item * &pprmlink()
3478:
3479: Inputs: $text $uname $udom $symb $target
3480:
3481: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3482: student and a specific resource
1.242 albertel 3483:
3484: =cut
3485:
3486: ###############################################
3487: sub pprmlink {
3488: my ($text,$uname,$udom,$symb,$target)=@_;
3489: if (!($uname && $udom)) {
3490: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3491: &Apache::lonnet::whichuser($symb);
1.242 albertel 3492: if (!$symb) { $symb=$cursymb; }
3493: }
1.254 matthew 3494: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3495: $symb=&escape($symb);
1.242 albertel 3496: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3497: return '<a href="/adm/parmset?command=set&'.
3498: 'symb='.$symb.'&uname='.$uname.
3499: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3500: }
3501: ##############################################
1.37 matthew 3502:
1.112 bowersj2 3503: =pod
3504:
3505: =back
3506:
3507: =cut
3508:
1.37 matthew 3509: ###############################################
1.51 www 3510:
3511:
3512: sub timehash {
1.687 raeburn 3513: my ($thistime) = @_;
3514: my $timezone = &Apache::lonlocal::gettimezone();
3515: my $dt = DateTime->from_epoch(epoch => $thistime)
3516: ->set_time_zone($timezone);
3517: my $wday = $dt->day_of_week();
3518: if ($wday == 7) { $wday = 0; }
3519: return ( 'second' => $dt->second(),
3520: 'minute' => $dt->minute(),
3521: 'hour' => $dt->hour(),
3522: 'day' => $dt->day_of_month(),
3523: 'month' => $dt->month(),
3524: 'year' => $dt->year(),
3525: 'weekday' => $wday,
3526: 'dayyear' => $dt->day_of_year(),
3527: 'dlsav' => $dt->is_dst() );
1.51 www 3528: }
3529:
1.370 www 3530: sub utc_string {
3531: my ($date)=@_;
1.371 www 3532: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3533: }
3534:
1.51 www 3535: sub maketime {
3536: my %th=@_;
1.687 raeburn 3537: my ($epoch_time,$timezone,$dt);
3538: $timezone = &Apache::lonlocal::gettimezone();
3539: eval {
3540: $dt = DateTime->new( year => $th{'year'},
3541: month => $th{'month'},
3542: day => $th{'day'},
3543: hour => $th{'hour'},
3544: minute => $th{'minute'},
3545: second => $th{'second'},
3546: time_zone => $timezone,
3547: );
3548: };
3549: if (!$@) {
3550: $epoch_time = $dt->epoch;
3551: if ($epoch_time) {
3552: return $epoch_time;
3553: }
3554: }
1.51 www 3555: return POSIX::mktime(
3556: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3557: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3558: }
3559:
3560: #########################################
1.51 www 3561:
3562: sub findallcourses {
1.482 raeburn 3563: my ($roles,$uname,$udom) = @_;
1.355 albertel 3564: my %roles;
3565: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3566: my %courses;
1.51 www 3567: my $now=time;
1.482 raeburn 3568: if (!defined($uname)) {
3569: $uname = $env{'user.name'};
3570: }
3571: if (!defined($udom)) {
3572: $udom = $env{'user.domain'};
3573: }
3574: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3575: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3576: if (!%roles) {
3577: %roles = (
3578: cc => 1,
3579: in => 1,
3580: ep => 1,
3581: ta => 1,
3582: cr => 1,
3583: st => 1,
3584: );
3585: }
3586: foreach my $entry (keys(%roleshash)) {
3587: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3588: if ($trole =~ /^cr/) {
3589: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3590: } else {
3591: next if (!exists($roles{$trole}));
3592: }
3593: if ($tend) {
3594: next if ($tend < $now);
3595: }
3596: if ($tstart) {
3597: next if ($tstart > $now);
3598: }
3599: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3600: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3601: if ($secpart eq '') {
3602: ($cnum,$role) = split(/_/,$cnumpart);
3603: $sec = 'none';
3604: $realsec = '';
3605: } else {
3606: $cnum = $cnumpart;
3607: ($sec,$role) = split(/_/,$secpart);
3608: $realsec = $sec;
1.490 raeburn 3609: }
1.482 raeburn 3610: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3611: }
3612: } else {
3613: foreach my $key (keys(%env)) {
1.483 albertel 3614: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3615: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3616: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3617: next if ($role eq 'ca' || $role eq 'aa');
3618: next if (%roles && !exists($roles{$role}));
3619: my ($starttime,$endtime)=split(/\./,$env{$key});
3620: my $active=1;
3621: if ($starttime) {
3622: if ($now<$starttime) { $active=0; }
3623: }
3624: if ($endtime) {
3625: if ($now>$endtime) { $active=0; }
3626: }
3627: if ($active) {
3628: if ($sec eq '') {
3629: $sec = 'none';
3630: }
3631: $courses{$cdom.'_'.$cnum}{$sec} =
3632: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3633: }
3634: }
1.51 www 3635: }
3636: }
1.474 raeburn 3637: return %courses;
1.51 www 3638: }
1.37 matthew 3639:
1.54 www 3640: ###############################################
1.474 raeburn 3641:
3642: sub blockcheck {
1.482 raeburn 3643: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3644:
3645: if (!defined($udom)) {
3646: $udom = $env{'user.domain'};
3647: }
3648: if (!defined($uname)) {
3649: $uname = $env{'user.name'};
3650: }
3651:
3652: # If uname and udom are for a course, check for blocks in the course.
3653:
3654: if (&Apache::lonnet::is_course($udom,$uname)) {
3655: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3656: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3657: return ($startblock,$endblock);
3658: }
1.474 raeburn 3659:
1.502 raeburn 3660: my $startblock = 0;
3661: my $endblock = 0;
1.482 raeburn 3662: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3663:
1.490 raeburn 3664: # If uname is for a user, and activity is course-specific, i.e.,
3665: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3666:
1.490 raeburn 3667: if (($activity eq 'boards' || $activity eq 'chat' ||
3668: $activity eq 'groups') && ($env{'request.course.id'})) {
3669: foreach my $key (keys(%live_courses)) {
3670: if ($key ne $env{'request.course.id'}) {
3671: delete($live_courses{$key});
3672: }
3673: }
3674: }
3675:
3676: my $otheruser = 0;
3677: my %own_courses;
3678: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3679: # Resource belongs to user other than current user.
3680: $otheruser = 1;
3681: # Gather courses for current user
3682: %own_courses =
3683: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3684: }
3685:
3686: # Gather active course roles - course coordinator, instructor,
3687: # exam proctor, ta, student, or custom role.
1.474 raeburn 3688:
3689: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3690: my ($cdom,$cnum);
3691: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3692: $cdom = $env{'course.'.$course.'.domain'};
3693: $cnum = $env{'course.'.$course.'.num'};
3694: } else {
1.490 raeburn 3695: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3696: }
3697: my $no_ownblock = 0;
3698: my $no_userblock = 0;
1.533 raeburn 3699: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3700: # Check if current user has 'evb' priv for this
3701: if (defined($own_courses{$course})) {
3702: foreach my $sec (keys(%{$own_courses{$course}})) {
3703: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3704: if ($sec ne 'none') {
3705: $checkrole .= '/'.$sec;
3706: }
3707: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3708: $no_ownblock = 1;
3709: last;
3710: }
3711: }
3712: }
3713: # if they have 'evb' priv and are currently not playing student
3714: next if (($no_ownblock) &&
3715: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3716: }
1.474 raeburn 3717: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3718: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3719: if ($sec ne 'none') {
1.482 raeburn 3720: $checkrole .= '/'.$sec;
1.474 raeburn 3721: }
1.490 raeburn 3722: if ($otheruser) {
3723: # Resource belongs to user other than current user.
3724: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3725: my ($trole,$tdom,$tnum,$tsec);
3726: my $entry = $live_courses{$course}{$sec};
3727: if ($entry =~ /^cr/) {
3728: ($trole,$tdom,$tnum,$tsec) =
3729: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3730: } else {
3731: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3732: }
3733: my ($spec,$area,$trest,%allroles,%userroles);
3734: $area = '/'.$tdom.'/'.$tnum;
3735: $trest = $tnum;
3736: if ($tsec ne '') {
3737: $area .= '/'.$tsec;
3738: $trest .= '/'.$tsec;
3739: }
3740: $spec = $trole.'.'.$area;
3741: if ($trole =~ /^cr/) {
3742: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3743: $tdom,$spec,$trest,$area);
3744: } else {
3745: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3746: $tdom,$spec,$trest,$area);
3747: }
3748: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3749: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3750: if ($1) {
3751: $no_userblock = 1;
3752: last;
3753: }
3754: }
1.490 raeburn 3755: } else {
3756: # Resource belongs to current user
3757: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3758: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3759: $no_ownblock = 1;
3760: last;
3761: }
1.474 raeburn 3762: }
3763: }
3764: # if they have the evb priv and are currently not playing student
1.482 raeburn 3765: next if (($no_ownblock) &&
1.491 albertel 3766: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3767: next if ($no_userblock);
1.474 raeburn 3768:
1.866 kalberla 3769: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3770: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3771:
3772: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3773: if (($start != 0) &&
3774: (($startblock == 0) || ($startblock > $start))) {
3775: $startblock = $start;
3776: }
3777: if (($end != 0) &&
3778: (($endblock == 0) || ($endblock < $end))) {
3779: $endblock = $end;
3780: }
1.490 raeburn 3781: }
3782: return ($startblock,$endblock);
3783: }
3784:
3785: sub get_blocks {
3786: my ($setters,$activity,$cdom,$cnum) = @_;
3787: my $startblock = 0;
3788: my $endblock = 0;
3789: my $course = $cdom.'_'.$cnum;
3790: $setters->{$course} = {};
3791: $setters->{$course}{'staff'} = [];
3792: $setters->{$course}{'times'} = [];
3793: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3794: foreach my $record (keys(%records)) {
3795: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3796: if ($start <= time && $end >= time) {
3797: my ($staff_name,$staff_dom,$title,$blocks) =
3798: &parse_block_record($records{$record});
3799: if ($blocks->{$activity} eq 'on') {
3800: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3801: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3802: if ( ($startblock == 0) || ($startblock > $start) ) {
3803: $startblock = $start;
1.490 raeburn 3804: }
1.491 albertel 3805: if ( ($endblock == 0) || ($endblock < $end) ) {
3806: $endblock = $end;
1.474 raeburn 3807: }
3808: }
3809: }
3810: }
3811: return ($startblock,$endblock);
3812: }
3813:
3814: sub parse_block_record {
3815: my ($record) = @_;
3816: my ($setuname,$setudom,$title,$blocks);
3817: if (ref($record) eq 'HASH') {
3818: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3819: $title = &unescape($record->{'event'});
3820: $blocks = $record->{'blocks'};
3821: } else {
3822: my @data = split(/:/,$record,3);
3823: if (scalar(@data) eq 2) {
3824: $title = $data[1];
3825: ($setuname,$setudom) = split(/@/,$data[0]);
3826: } else {
3827: ($setuname,$setudom,$title) = @data;
3828: }
3829: $blocks = { 'com' => 'on' };
3830: }
3831: return ($setuname,$setudom,$title,$blocks);
3832: }
3833:
1.854 kalberla 3834: sub blocking_status {
1.867 kalberla 3835: my $blocked;
1.854 kalberla 3836: my ($activity,$uname,$udom) = @_;
1.867 kalberla 3837: my %setters;
3838: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3839: if ($startblock && $endblock) {
3840: $blocked = 1;
3841: }
1.854 kalberla 3842: if(!wantarray) {
3843: return $blocked;
3844: }
3845: my $output;
3846: my $querystring;
3847: $querystring = "?activity=$activity";
3848:
3849: $output .= <<"END_MYBLOCK";
3850: <script type="text/javascript">
3851: // <![CDATA[
3852: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3853: var options = "width=" + w + ",height=" + h + ",";
3854: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3855: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3856: var newWin = window.open(url, wdwName, options);
3857: newWin.focus();
3858: }
3859:
3860: // ]]>
3861: </script>
3862: END_MYBLOCK
3863: my $popupUrl = "/adm/blockingstatus/$querystring";
1.867 kalberla 3864: $output .= <<"END_BLOCK";
3865: <div class='LC_comblock'>
1.869 ! kalberla 3866: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
! 3867: title='Communication Blocked'>
! 3868: <img class='LC_noBorder LC_middle' title='Communication Blocked' src='/res/adm/pages/comblock.png' alt='Communication Blocked'/></a>
! 3869: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
! 3870: title='Communication Blocked'>Communication Blocked</a>
1.867 kalberla 3871: </div>
3872:
3873: END_BLOCK
1.474 raeburn 3874:
1.854 kalberla 3875: return ($blocked, $output);
3876: }
1.490 raeburn 3877:
1.60 matthew 3878: ###############################################
3879:
1.682 raeburn 3880: sub check_ip_acc {
3881: my ($acc)=@_;
3882: &Apache::lonxml::debug("acc is $acc");
3883: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3884: return 1;
3885: }
3886: my $allowed=0;
3887: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3888:
3889: my $name;
3890: foreach my $pattern (split(',',$acc)) {
3891: $pattern =~ s/^\s*//;
3892: $pattern =~ s/\s*$//;
3893: if ($pattern =~ /\*$/) {
3894: #35.8.*
3895: $pattern=~s/\*//;
3896: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3897: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3898: #35.8.3.[34-56]
3899: my $low=$2;
3900: my $high=$3;
3901: $pattern=$1;
3902: if ($ip =~ /^\Q$pattern\E/) {
3903: my $last=(split(/\./,$ip))[3];
3904: if ($last <=$high && $last >=$low) { $allowed=1; }
3905: }
3906: } elsif ($pattern =~ /^\*/) {
3907: #*.msu.edu
3908: $pattern=~s/\*//;
3909: if (!defined($name)) {
3910: use Socket;
3911: my $netaddr=inet_aton($ip);
3912: ($name)=gethostbyaddr($netaddr,AF_INET);
3913: }
3914: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3915: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3916: #127.0.0.1
3917: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3918: } else {
3919: #some.name.com
3920: if (!defined($name)) {
3921: use Socket;
3922: my $netaddr=inet_aton($ip);
3923: ($name)=gethostbyaddr($netaddr,AF_INET);
3924: }
3925: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3926: }
3927: if ($allowed) { last; }
3928: }
3929: return $allowed;
3930: }
3931:
3932: ###############################################
3933:
1.60 matthew 3934: =pod
3935:
1.112 bowersj2 3936: =head1 Domain Template Functions
3937:
3938: =over 4
3939:
3940: =item * &determinedomain()
1.60 matthew 3941:
3942: Inputs: $domain (usually will be undef)
3943:
1.63 www 3944: Returns: Determines which domain should be used for designs
1.60 matthew 3945:
3946: =cut
1.54 www 3947:
1.60 matthew 3948: ###############################################
1.63 www 3949: sub determinedomain {
3950: my $domain=shift;
1.531 albertel 3951: if (! $domain) {
1.60 matthew 3952: # Determine domain if we have not been given one
3953: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3954: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3955: if ($env{'request.role.domain'}) {
3956: $domain=$env{'request.role.domain'};
1.60 matthew 3957: }
3958: }
1.63 www 3959: return $domain;
3960: }
3961: ###############################################
1.517 raeburn 3962:
1.518 albertel 3963: sub devalidate_domconfig_cache {
3964: my ($udom)=@_;
3965: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3966: }
3967:
3968: # ---------------------- Get domain configuration for a domain
3969: sub get_domainconf {
3970: my ($udom) = @_;
3971: my $cachetime=1800;
3972: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3973: if (defined($cached)) { return %{$result}; }
3974:
3975: my %domconfig = &Apache::lonnet::get_dom('configuration',
3976: ['login','rolecolors'],$udom);
1.632 raeburn 3977: my (%designhash,%legacy);
1.518 albertel 3978: if (keys(%domconfig) > 0) {
3979: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3980: if (keys(%{$domconfig{'login'}})) {
3981: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3982: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3983: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3984: $designhash{$udom.'.login.'.$key.'_'.$img} =
3985: $domconfig{'login'}{$key}{$img};
3986: }
3987: } else {
3988: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3989: }
1.632 raeburn 3990: }
3991: } else {
3992: $legacy{'login'} = 1;
1.518 albertel 3993: }
1.632 raeburn 3994: } else {
3995: $legacy{'login'} = 1;
1.518 albertel 3996: }
3997: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3998: if (keys(%{$domconfig{'rolecolors'}})) {
3999: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4000: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4001: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4002: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4003: }
1.518 albertel 4004: }
4005: }
1.632 raeburn 4006: } else {
4007: $legacy{'rolecolors'} = 1;
1.518 albertel 4008: }
1.632 raeburn 4009: } else {
4010: $legacy{'rolecolors'} = 1;
1.518 albertel 4011: }
1.632 raeburn 4012: if (keys(%legacy) > 0) {
4013: my %legacyhash = &get_legacy_domconf($udom);
4014: foreach my $item (keys(%legacyhash)) {
4015: if ($item =~ /^\Q$udom\E\.login/) {
4016: if ($legacy{'login'}) {
4017: $designhash{$item} = $legacyhash{$item};
4018: }
4019: } else {
4020: if ($legacy{'rolecolors'}) {
4021: $designhash{$item} = $legacyhash{$item};
4022: }
1.518 albertel 4023: }
4024: }
4025: }
1.632 raeburn 4026: } else {
4027: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4028: }
4029: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4030: $cachetime);
4031: return %designhash;
4032: }
4033:
1.632 raeburn 4034: sub get_legacy_domconf {
4035: my ($udom) = @_;
4036: my %legacyhash;
4037: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4038: my $designfile = $designdir.'/'.$udom.'.tab';
4039: if (-e $designfile) {
4040: if ( open (my $fh,"<$designfile") ) {
4041: while (my $line = <$fh>) {
4042: next if ($line =~ /^\#/);
4043: chomp($line);
4044: my ($key,$val)=(split(/\=/,$line));
4045: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4046: }
4047: close($fh);
4048: }
4049: }
4050: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4051: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4052: }
4053: return %legacyhash;
4054: }
4055:
1.63 www 4056: =pod
4057:
1.112 bowersj2 4058: =item * &domainlogo()
1.63 www 4059:
4060: Inputs: $domain (usually will be undef)
4061:
4062: Returns: A link to a domain logo, if the domain logo exists.
4063: If the domain logo does not exist, a description of the domain.
4064:
4065: =cut
1.112 bowersj2 4066:
1.63 www 4067: ###############################################
4068: sub domainlogo {
1.517 raeburn 4069: my $domain = &determinedomain(shift);
1.518 albertel 4070: my %designhash = &get_domainconf($domain);
1.517 raeburn 4071: # See if there is a logo
4072: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4073: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4074: if ($imgsrc =~ m{^/(adm|res)/}) {
4075: if ($imgsrc =~ m{^/res/}) {
4076: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4077: &Apache::lonnet::repcopy($local_name);
4078: }
4079: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4080: }
4081: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4082: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4083: return &Apache::lonnet::domain($domain,'description');
1.59 www 4084: } else {
1.60 matthew 4085: return '';
1.59 www 4086: }
4087: }
1.63 www 4088: ##############################################
4089:
4090: =pod
4091:
1.112 bowersj2 4092: =item * &designparm()
1.63 www 4093:
4094: Inputs: $which parameter; $domain (usually will be undef)
4095:
4096: Returns: value of designparamter $which
4097:
4098: =cut
1.112 bowersj2 4099:
1.397 albertel 4100:
1.400 albertel 4101: ##############################################
1.397 albertel 4102: sub designparm {
4103: my ($which,$domain)=@_;
4104: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4105: return $env{'environment.color.'.$which};
1.96 www 4106: }
1.63 www 4107: $domain=&determinedomain($domain);
1.518 albertel 4108: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4109: my $output;
1.517 raeburn 4110: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4111: $output = $domdesign{$domain.'.'.$which};
1.63 www 4112: } else {
1.520 raeburn 4113: $output = $defaultdesign{$which};
4114: }
4115: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4116: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4117: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4118: if ($output =~ m{^/res/}) {
4119: my $local_name = &Apache::lonnet::filelocation('',$output);
4120: &Apache::lonnet::repcopy($local_name);
4121: }
1.520 raeburn 4122: $output = &lonhttpdurl($output);
4123: }
1.63 www 4124: }
1.520 raeburn 4125: return $output;
1.63 www 4126: }
1.59 www 4127:
1.822 bisitz 4128: ##############################################
4129: =pod
4130:
1.832 bisitz 4131: =item * &authorspace()
4132:
4133: Inputs: ./.
4134:
4135: Returns: Path to the Construction Space of the current user's
4136: accessed author space
4137: The author space will be that of the current user
4138: when accessing the own author space
4139: and that of the co-author/assistent co-author
4140: when accessing the co-author's/assistent co-author's
4141: space
4142:
4143: =cut
4144:
4145: sub authorspace {
4146: my $caname = '';
4147: if ($env{'request.role'} =~ /^ca|^aa/) {
4148: (undef,$caname) =
4149: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4150: } else {
4151: $caname = $env{'user.name'};
4152: }
4153: return '/priv/'.$caname.'/';
4154: }
4155:
4156: ##############################################
4157: =pod
4158:
1.822 bisitz 4159: =item * &head_subbox()
4160:
4161: Inputs: $content (contains HTML code with page functions, etc.)
4162:
4163: Returns: HTML div with $content
4164: To be included in page header
4165:
4166: =cut
4167:
4168: sub head_subbox {
4169: my ($content)=@_;
4170: my $output =
1.844 bisitz 4171: '<div id="LC_head_subbox">'
1.822 bisitz 4172: .$content
4173: .'</div>'
4174: }
4175:
4176: ##############################################
4177: =pod
4178:
4179: =item * &CSTR_pageheader()
4180:
4181: Inputs: ./.
4182:
4183: Returns: HTML div with CSTR path and recent box
4184: To be included on Construction Space pages
4185:
4186: =cut
4187:
4188: sub CSTR_pageheader {
4189: # this is for resources; directories have customtitle, and crumbs
4190: # and select recent are created in lonpubdir.pm
4191: my ($uname,$thisdisfn)=
4192: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4193: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4194: $formaction=~s/\/+/\//g;
4195:
4196: my $parentpath = '';
4197: my $lastitem = '';
4198: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4199: $parentpath = $1;
4200: $lastitem = $2;
4201: } else {
4202: $lastitem = $thisdisfn;
4203: }
4204: return
4205: '<div>'
4206: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4207: .'<b>'.&mt('Construction Space:').'</b> '
4208: .'<form name="dirs" method="post" action="'.$formaction
4209: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4210: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4211: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4212: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4213: .'</form>'
4214: .&Apache::lonmenu::constspaceform()
4215: .'</div>';
4216: }
4217:
1.60 matthew 4218: ###############################################
4219: ###############################################
4220:
4221: =pod
4222:
1.112 bowersj2 4223: =back
4224:
1.549 albertel 4225: =head1 HTML Helpers
1.112 bowersj2 4226:
4227: =over 4
4228:
4229: =item * &bodytag()
1.60 matthew 4230:
4231: Returns a uniform header for LON-CAPA web pages.
4232:
4233: Inputs:
4234:
1.112 bowersj2 4235: =over 4
4236:
4237: =item * $title, A title to be displayed on the page.
4238:
4239: =item * $function, the current role (can be undef).
4240:
4241: =item * $addentries, extra parameters for the <body> tag.
4242:
4243: =item * $bodyonly, if defined, only return the <body> tag.
4244:
4245: =item * $domain, if defined, force a given domain.
4246:
4247: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4248: text interface only)
1.60 matthew 4249:
1.814 bisitz 4250: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4251: navigational links
1.317 albertel 4252:
1.338 albertel 4253: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4254:
1.361 albertel 4255: =item * $no_inline_link, if true and in remote mode, don't show the
4256: 'Switch To Inline Menu' link
4257:
1.460 albertel 4258: =item * $args, optional argument valid values are
4259: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4260: inherit_jsmath -> when creating popup window in a page,
4261: should it have jsmath forced on by the
4262: current page
1.460 albertel 4263:
1.112 bowersj2 4264: =back
4265:
1.60 matthew 4266: Returns: A uniform header for LON-CAPA web pages.
4267: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4268: If $bodyonly is undef or zero, an html string containing a <body> tag and
4269: other decorations will be returned.
4270:
4271: =cut
4272:
1.54 www 4273: sub bodytag {
1.831 bisitz 4274: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4275: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4276:
1.460 albertel 4277: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4278:
1.183 matthew 4279: $function = &get_users_function() if (!$function);
1.339 albertel 4280: my $img = &designparm($function.'.img',$domain);
4281: my $font = &designparm($function.'.font',$domain);
4282: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4283:
1.803 bisitz 4284: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4285: 'bgcolor' => $pgbg,
1.339 albertel 4286: 'text' => $font,
4287: 'alink' => &designparm($function.'.alink',$domain),
4288: 'vlink' => &designparm($function.'.vlink',$domain),
4289: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4290: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4291:
1.63 www 4292: # role and realm
1.378 raeburn 4293: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4294: if ($role eq 'ca') {
1.479 albertel 4295: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4296: $realm = &plainname($rname,$rdom);
1.378 raeburn 4297: }
1.55 www 4298: # realm
1.258 albertel 4299: if ($env{'request.course.id'}) {
1.378 raeburn 4300: if ($env{'request.role'} !~ /^cr/) {
4301: $role = &Apache::lonnet::plaintext($role,&course_type());
4302: }
1.359 albertel 4303: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4304: } else {
4305: $role = &Apache::lonnet::plaintext($role);
1.54 www 4306: }
1.433 albertel 4307:
1.359 albertel 4308: if (!$realm) { $realm=' '; }
1.55 www 4309: # Set messages
1.60 matthew 4310: my $messages=&domainlogo($domain);
1.330 albertel 4311:
1.438 albertel 4312: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4313:
1.101 www 4314: # construct main body tag
1.359 albertel 4315: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4316: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4317:
1.530 albertel 4318: if ($bodyonly) {
1.60 matthew 4319: return $bodytag;
1.798 tempelho 4320: }
1.359 albertel 4321:
1.410 albertel 4322: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4323: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4324: undef($role);
1.434 albertel 4325: } else {
4326: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4327: }
1.359 albertel 4328:
1.762 bisitz 4329: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4330: #
4331: # Extra info if you are the DC
4332: my $dc_info = '';
4333: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4334: $env{'course.'.$env{'request.course.id'}.
4335: '.domain'}.'/'})) {
4336: my $cid = $env{'request.course.id'};
4337: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4338: $dc_info =~ s/\s+$//;
1.359 albertel 4339: $dc_info = '('.$dc_info.')';
4340: }
4341:
1.853 droeschl 4342: $role = "($role)" if $role;
4343: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4344:
1.837 bisitz 4345: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4346: # No Remote
1.258 albertel 4347: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4348: $forcereg=1;
4349: }
4350:
1.836 bisitz 4351: # if ($env{'request.state'} eq 'construct') {
4352: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4353: # }
1.359 albertel 4354:
1.816 bisitz 4355: my $titletable = '<table id="LC_title_bar">'
1.836 bisitz 4356: ."<tr><td> $titleinfo $dc_info</td>"
1.816 bisitz 4357: .'</tr></table>';
4358:
1.814 bisitz 4359: if ($no_nav_bar) {
1.359 albertel 4360: $bodytag .= $titletable;
4361: } else {
1.852 droeschl 4362: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4363: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4364:
1.359 albertel 4365: if ($env{'request.state'} eq 'construct') {
1.863 droeschl 4366: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
1.272 raeburn 4367: } else {
1.863 droeschl 4368: $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
1.272 raeburn 4369: }
1.235 raeburn 4370: }
4371: return $bodytag;
1.94 www 4372: }
1.95 www 4373:
1.93 www 4374: #
1.95 www 4375: # Top frame rendering, Remote is up
1.93 www 4376: #
1.359 albertel 4377:
1.517 raeburn 4378: my $imgsrc = $img;
4379: if ($img =~ /^\/adm/) {
1.575 albertel 4380: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4381: }
4382: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4383:
1.305 www 4384: # Explicit link to get inline menu
1.361 albertel 4385: my $menu= ($no_inline_link?''
1.853 droeschl 4386: :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4387: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4388: <em>$realm</em> $dc_info </div>
4389: <ol class="LC_smallMenu LC_right">
4390: <li>$menu</li>
4391: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4392: #
1.94 www 4393: return(<<ENDBODY);
1.60 matthew 4394: $bodytag
1.359 albertel 4395: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4396: <tr><td>$upperleft</td>
4397: <td>$messages </td>
1.54 www 4398: </tr>
1.359 albertel 4399: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4400: </tr>
1.356 albertel 4401: </table>
1.54 www 4402: ENDBODY
1.182 matthew 4403: }
4404:
1.330 albertel 4405: sub make_attr_string {
4406: my ($register,$attr_ref) = @_;
4407:
4408: if ($attr_ref && !ref($attr_ref)) {
4409: die("addentries Must be a hash ref ".
4410: join(':',caller(1))." ".
4411: join(':',caller(0))." ");
4412: }
4413:
4414: if ($register) {
1.339 albertel 4415: my ($on_load,$on_unload);
4416: foreach my $key (keys(%{$attr_ref})) {
4417: if (lc($key) eq 'onload') {
4418: $on_load.=$attr_ref->{$key}.';';
4419: delete($attr_ref->{$key});
4420:
4421: } elsif (lc($key) eq 'onunload') {
4422: $on_unload.=$attr_ref->{$key}.';';
4423: delete($attr_ref->{$key});
4424: }
4425: }
4426: $attr_ref->{'onload'} =
4427: &Apache::lonmenu::loadevents(). $on_load;
4428: $attr_ref->{'onunload'}=
4429: &Apache::lonmenu::unloadevents().$on_unload;
4430: }
4431:
4432: # Accessibility font enhance
4433: if ($env{'browser.fontenhance'} eq 'on') {
4434: my $style;
4435: foreach my $key (keys(%{$attr_ref})) {
4436: if (lc($key) eq 'style') {
4437: $style.=$attr_ref->{$key}.';';
4438: delete($attr_ref->{$key});
4439: }
4440: }
4441: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4442: }
1.339 albertel 4443:
1.330 albertel 4444: my $attr_string;
4445: foreach my $attr (keys(%$attr_ref)) {
4446: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4447: }
4448: return $attr_string;
4449: }
4450:
4451:
1.182 matthew 4452: ###############################################
1.251 albertel 4453: ###############################################
4454:
4455: =pod
4456:
4457: =item * &endbodytag()
4458:
4459: Returns a uniform footer for LON-CAPA web pages.
4460:
1.635 raeburn 4461: Inputs: 1 - optional reference to an args hash
4462: If in the hash, key for noredirectlink has a value which evaluates to true,
4463: a 'Continue' link is not displayed if the page contains an
4464: internal redirect in the <head></head> section,
4465: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4466:
4467: =cut
4468:
4469: sub endbodytag {
1.635 raeburn 4470: my ($args) = @_;
1.251 albertel 4471: my $endbodytag='</body>';
1.269 albertel 4472: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4473: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4474: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4475: $endbodytag=
4476: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4477: &mt('Continue').'</a>'.
4478: $endbodytag;
4479: }
1.315 albertel 4480: }
1.251 albertel 4481: return $endbodytag;
4482: }
4483:
1.352 albertel 4484: =pod
4485:
4486: =item * &standard_css()
4487:
4488: Returns a style sheet
4489:
4490: Inputs: (all optional)
4491: domain -> force to color decorate a page for a specific
4492: domain
4493: function -> force usage of a specific rolish color scheme
4494: bgcolor -> override the default page bgcolor
4495:
4496: =cut
4497:
1.343 albertel 4498: sub standard_css {
1.345 albertel 4499: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4500: $function = &get_users_function() if (!$function);
4501: my $img = &designparm($function.'.img', $domain);
4502: my $tabbg = &designparm($function.'.tabbg', $domain);
4503: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4504: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4505: #second colour for later usage
1.345 albertel 4506: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4507: my $pgbg_or_bgcolor =
4508: $bgcolor ||
1.352 albertel 4509: &designparm($function.'.pgbg', $domain);
1.382 albertel 4510: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4511: my $alink = &designparm($function.'.alink', $domain);
4512: my $vlink = &designparm($function.'.vlink', $domain);
4513: my $link = &designparm($function.'.link', $domain);
4514:
1.704 muellerd 4515: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4516: my $bgcol = &designparm('login.bgcol',$domain);
4517: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4518:
1.602 albertel 4519: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4520: my $mono = 'monospace';
1.850 bisitz 4521: my $data_table_head = $sidebg;
4522: my $data_table_light = '#FAFAFA';
4523: my $data_table_dark = '#F0F0F0';
1.470 banghart 4524: my $data_table_darker = '#CCCCCC';
1.349 albertel 4525: my $data_table_highlight = '#FFFF00';
1.352 albertel 4526: my $mail_new = '#FFBB77';
4527: my $mail_new_hover = '#DD9955';
4528: my $mail_read = '#BBBB77';
4529: my $mail_read_hover = '#999944';
4530: my $mail_replied = '#AAAA88';
4531: my $mail_replied_hover = '#888855';
4532: my $mail_other = '#99BBBB';
4533: my $mail_other_hover = '#669999';
1.391 albertel 4534: my $table_header = '#DDDDDD';
1.489 raeburn 4535: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4536: my $lg_border_color = '#C8C8C8';
1.392 albertel 4537:
1.608 albertel 4538: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4539: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4540: : '0 3px 0 4px';
1.448 albertel 4541:
1.523 albertel 4542:
1.343 albertel 4543: return <<END;
1.795 www 4544: body {
4545: font-family: $sans;
4546: line-height:130%;
4547: font-size:0.83em;
4548: color:$font;
4549: }
4550:
4551: a:link, a:visited {
4552: font-size:100%;
4553: }
4554:
4555: a:focus {
4556: color: red;
4557: background: yellow
4558: }
1.698 harmsja 4559:
1.846 bisitz 4560: hr {
4561: clear: both;
4562: color: $tabbg;
4563: background-color: $tabbg;
4564: height: 3px;
4565: border: none;
4566: }
4567:
1.795 www 4568: form, .inline {
4569: display: inline;
4570: }
1.721 harmsja 4571:
1.795 www 4572: .LC_right {
4573: text-align:right;
4574: }
4575:
4576: .LC_middle {
4577: vertical-align:middle;
4578: }
1.721 harmsja 4579:
4580: /* just for tests */
1.754 droeschl 4581: .LC_400Box {width:400px; }
1.721 harmsja 4582: /* end */
4583:
1.778 bisitz 4584: .LC_filename {
4585: font-family: $mono;
4586: white-space:pre;
4587: }
4588:
4589: .LC_fileicon {
4590: border: none;
4591: height: 1.3em;
4592: vertical-align: text-bottom;
4593: margin-right: 0.3em;
4594: text-decoration:none;
4595: }
4596:
1.350 albertel 4597: .LC_error {
4598: color: red;
4599: font-size: larger;
4600: }
1.795 www 4601:
1.457 albertel 4602: .LC_warning,
4603: .LC_diff_removed {
1.733 bisitz 4604: color: red;
1.394 albertel 4605: }
1.532 albertel 4606:
4607: .LC_info,
1.457 albertel 4608: .LC_success,
4609: .LC_diff_added {
1.350 albertel 4610: color: green;
4611: }
1.795 www 4612:
1.802 bisitz 4613: div.LC_confirm_box {
4614: background-color: #FAFAFA;
4615: border: 1px solid $lg_border_color;
4616: margin-right: 0;
4617: padding: 5px;
4618: }
4619:
4620: div.LC_confirm_box .LC_error img,
4621: div.LC_confirm_box .LC_success img {
4622: vertical-align: middle;
4623: }
4624:
1.440 albertel 4625: .LC_icon {
1.771 droeschl 4626: border: none;
1.790 droeschl 4627: vertical-align: middle;
1.771 droeschl 4628: }
4629:
1.543 albertel 4630: .LC_docs_spacer {
4631: width: 25px;
4632: height: 1px;
1.771 droeschl 4633: border: none;
1.543 albertel 4634: }
1.346 albertel 4635:
1.532 albertel 4636: .LC_internal_info {
1.735 bisitz 4637: color: #999999;
1.532 albertel 4638: }
4639:
1.794 www 4640: .LC_discussion {
4641: background: $tabbg;
4642: border: 1px solid black;
4643: margin: 2px;
4644: }
4645:
4646: .LC_disc_action_links_bar {
4647: background: $tabbg;
1.803 bisitz 4648: border: none;
1.795 www 4649: margin: 4px;
1.794 www 4650: }
4651:
4652: .LC_disc_action_left {
4653: text-align: left;
4654: }
4655:
4656: .LC_disc_action_right {
4657: text-align: right;
4658: }
4659:
4660: .LC_disc_new_item {
4661: background: white;
4662: border: 2px solid red;
4663: margin: 2px;
4664: }
4665:
4666: .LC_disc_old_item {
4667: background: white;
4668: border: 1px solid black;
4669: margin: 2px;
4670: }
4671:
1.458 albertel 4672: table.LC_pastsubmission {
4673: border: 1px solid black;
4674: margin: 2px;
4675: }
4676:
1.795 www 4677: table#LC_top_nav,
4678: table#LC_menubuttons,
4679: table#LC_nav_location {
1.345 albertel 4680: width: 100%;
4681: background: $pgbg;
1.392 albertel 4682: border: 2px;
1.402 albertel 4683: border-collapse: separate;
1.803 bisitz 4684: padding: 0;
1.345 albertel 4685: }
1.392 albertel 4686:
1.801 tempelho 4687: table#LC_title_bar a {
4688: color: $fontmenu;
4689: }
1.836 bisitz 4690:
1.807 droeschl 4691: table#LC_title_bar {
1.819 tempelho 4692: clear: both;
1.836 bisitz 4693: display: none;
1.807 droeschl 4694: }
4695:
1.795 www 4696: table#LC_title_bar,
4697: table.LC_breadcrumbs,
1.393 albertel 4698: table#LC_title_bar.LC_with_remote {
1.359 albertel 4699: width: 100%;
1.392 albertel 4700: border-color: $pgbg;
4701: border-style: solid;
4702: border-width: $border;
1.379 albertel 4703: background: $pgbg;
1.801 tempelho 4704: color: $fontmenu;
1.392 albertel 4705: border-collapse: collapse;
1.803 bisitz 4706: padding: 0;
1.819 tempelho 4707: margin: 0;
1.359 albertel 4708: }
1.795 www 4709:
1.359 albertel 4710: table#LC_title_bar td {
4711: background: $tabbg;
4712: }
1.795 www 4713:
1.706 harmsja 4714: table#LC_menubuttons img{
1.803 bisitz 4715: border: none;
1.346 albertel 4716: }
1.795 www 4717:
1.345 albertel 4718: table#LC_top_nav td {
4719: background: $tabbg;
1.803 bisitz 4720: border: none;
1.407 albertel 4721: font-size: small;
1.706 harmsja 4722: vertical-align:top;
4723: padding:2px 5px 2px 5px;
1.345 albertel 4724: }
1.795 www 4725:
4726: table#LC_top_nav td a,
4727: div#LC_top_nav a {
1.345 albertel 4728: color: $font;
4729: }
1.795 www 4730:
1.364 albertel 4731: table#LC_top_nav td.LC_top_nav_logo {
4732: background: $tabbg;
1.432 albertel 4733: text-align: left;
1.408 albertel 4734: white-space: nowrap;
1.432 albertel 4735: width: 31px;
1.408 albertel 4736: }
1.795 www 4737:
1.408 albertel 4738: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4739: border: none;
1.408 albertel 4740: vertical-align: bottom;
1.364 albertel 4741: }
1.795 www 4742:
1.777 tempelho 4743: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4744: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4745: width: 2.0em;
4746: }
1.795 www 4747:
1.442 albertel 4748: table#LC_top_nav td.LC_top_nav_login {
4749: width: 4.0em;
4750: text-align: center;
4751: }
1.795 www 4752:
1.842 droeschl 4753: .LC_breadcrumbs_component {
4754: float: right;
4755: margin: 0 1em;
1.357 albertel 4756: }
1.842 droeschl 4757: .LC_breadcrumbs_component img {
4758: vertical-align: middle;
1.777 tempelho 4759: }
1.795 www 4760:
1.383 albertel 4761: td.LC_table_cell_checkbox {
4762: text-align: center;
4763: }
1.795 www 4764:
1.779 bisitz 4765: table#LC_mainmenu td.LC_mainmenu_column {
4766: vertical-align: top;
1.777 tempelho 4767: }
1.522 albertel 4768:
1.795 www 4769: .LC_fontsize_small {
1.705 tempelho 4770: font-size: 70%;
4771: }
4772:
1.844 bisitz 4773: #LC_breadcrumbs {
1.819 tempelho 4774: clear:both;
4775: background: $sidebg;
1.822 bisitz 4776: border-bottom: 1px solid $lg_border_color;
1.819 tempelho 4777: line-height: 32px;
1.822 bisitz 4778: margin: 0;
1.819 tempelho 4779: padding: 0;
4780: }
1.862 bisitz 4781:
1.839 droeschl 4782: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4783: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4784: display:none;
4785: }
1.819 tempelho 4786:
1.844 bisitz 4787: #LC_head_subbox {
1.822 bisitz 4788: clear:both;
4789: background: #F8F8F8; /* $sidebg; */
4790: border-bottom: 1px solid $lg_border_color;
4791: margin: 0 0 10px 0;
4792: padding: 5px;
4793: }
4794:
1.795 www 4795: .LC_fontsize_medium {
1.705 tempelho 4796: font-size: 85%;
4797: }
4798:
1.795 www 4799: .LC_fontsize_large {
1.705 tempelho 4800: font-size: 120%;
4801: }
4802:
1.346 albertel 4803: .LC_menubuttons_inline_text {
4804: color: $font;
1.698 harmsja 4805: font-size: 90%;
1.701 harmsja 4806: padding-left:3px;
1.346 albertel 4807: }
4808:
1.526 www 4809: .LC_menubuttons_link {
4810: text-decoration: none;
4811: }
1.795 www 4812:
1.522 albertel 4813: .LC_menubuttons_category {
1.521 www 4814: color: $font;
1.526 www 4815: background: $pgbg;
1.521 www 4816: font-size: larger;
4817: font-weight: bold;
4818: }
4819:
1.346 albertel 4820: td.LC_menubuttons_text {
1.779 bisitz 4821: color: $font;
1.346 albertel 4822: }
1.706 harmsja 4823:
1.346 albertel 4824: .LC_current_location {
4825: background: $tabbg;
4826: }
1.795 www 4827:
1.346 albertel 4828: .LC_new_mail {
1.634 www 4829: background: $tabbg;
1.346 albertel 4830: font-weight: bold;
4831: }
1.347 albertel 4832:
1.666 raeburn 4833: .LC_roleslog_note {
1.701 harmsja 4834: font-size: small;
1.666 raeburn 4835: }
4836:
1.795 www 4837: table.LC_data_table,
4838: table.LC_mail_list {
1.347 albertel 4839: border: 1px solid #000000;
1.402 albertel 4840: border-collapse: separate;
1.426 albertel 4841: border-spacing: 1px;
1.610 albertel 4842: background: $pgbg;
1.347 albertel 4843: }
1.795 www 4844:
1.422 albertel 4845: .LC_data_table_dense {
4846: font-size: small;
4847: }
1.795 www 4848:
1.507 raeburn 4849: table.LC_nested_outer {
4850: border: 1px solid #000000;
1.589 raeburn 4851: border-collapse: collapse;
1.803 bisitz 4852: border-spacing: 0;
1.507 raeburn 4853: width: 100%;
4854: }
1.795 www 4855:
1.507 raeburn 4856: table.LC_nested {
1.803 bisitz 4857: border: none;
1.589 raeburn 4858: border-collapse: collapse;
1.803 bisitz 4859: border-spacing: 0;
1.507 raeburn 4860: width: 100%;
4861: }
1.795 www 4862:
4863: table.LC_data_table tr th,
4864: table.LC_calendar tr th,
4865: table.LC_mail_list tr th,
1.523 albertel 4866: table.LC_prior_tries tr th {
1.349 albertel 4867: font-weight: bold;
4868: background-color: $data_table_head;
1.801 tempelho 4869: color:$fontmenu;
1.701 harmsja 4870: font-size:90%;
1.347 albertel 4871: }
1.795 www 4872:
1.711 raeburn 4873: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4874: background-color: #CCCCCC;
1.711 raeburn 4875: font-weight: bold;
4876: text-align: left;
4877: }
1.795 www 4878:
1.779 bisitz 4879: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4880: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4881: background-color: $data_table_light;
1.425 albertel 4882: padding: 2px;
1.347 albertel 4883: }
1.795 www 4884:
1.610 albertel 4885: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4886: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4887: background-color: $data_table_dark;
1.709 bisitz 4888: padding: 2px;
1.347 albertel 4889: }
1.795 www 4890:
1.425 albertel 4891: table.LC_data_table tr.LC_data_table_highlight td {
4892: background-color: $data_table_darker;
4893: }
1.795 www 4894:
1.639 raeburn 4895: table.LC_data_table tr td.LC_leftcol_header {
4896: background-color: $data_table_head;
4897: font-weight: bold;
4898: }
1.795 www 4899:
1.451 albertel 4900: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4901: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4902: background-color: #FFFFFF;
1.421 albertel 4903: font-weight: bold;
4904: font-style: italic;
4905: text-align: center;
4906: padding: 8px;
1.347 albertel 4907: }
1.795 www 4908:
1.507 raeburn 4909: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4910: padding: 4ex
4911: }
1.795 www 4912:
1.507 raeburn 4913: table.LC_nested_outer tr th {
4914: font-weight: bold;
1.801 tempelho 4915: color:$fontmenu;
1.507 raeburn 4916: background-color: $data_table_head;
1.701 harmsja 4917: font-size: small;
1.507 raeburn 4918: border-bottom: 1px solid #000000;
4919: }
1.795 www 4920:
1.507 raeburn 4921: table.LC_nested_outer tr td.LC_subheader {
4922: background-color: $data_table_head;
4923: font-weight: bold;
4924: font-size: small;
4925: border-bottom: 1px solid #000000;
4926: text-align: right;
1.451 albertel 4927: }
1.795 www 4928:
1.507 raeburn 4929: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4930: background-color: #CCCCCC;
1.451 albertel 4931: font-weight: bold;
4932: font-size: small;
1.507 raeburn 4933: text-align: center;
4934: }
1.795 www 4935:
1.589 raeburn 4936: table.LC_nested tr.LC_info_row td.LC_left_item,
4937: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4938: text-align: left;
1.451 albertel 4939: }
1.795 www 4940:
1.507 raeburn 4941: table.LC_nested td {
1.735 bisitz 4942: background-color: #FFFFFF;
1.451 albertel 4943: font-size: small;
1.507 raeburn 4944: }
1.795 www 4945:
1.507 raeburn 4946: table.LC_nested_outer tr th.LC_right_item,
4947: table.LC_nested tr.LC_info_row td.LC_right_item,
4948: table.LC_nested tr.LC_odd_row td.LC_right_item,
4949: table.LC_nested tr td.LC_right_item {
1.451 albertel 4950: text-align: right;
4951: }
4952:
1.507 raeburn 4953: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4954: background-color: #EEEEEE;
1.451 albertel 4955: }
4956:
1.473 raeburn 4957: table.LC_createuser {
4958: }
4959:
4960: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4961: font-size: small;
1.473 raeburn 4962: }
4963:
4964: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4965: background-color: #CCCCCC;
1.473 raeburn 4966: font-weight: bold;
4967: text-align: center;
4968: }
4969:
1.349 albertel 4970: table.LC_calendar {
4971: border: 1px solid #000000;
4972: border-collapse: collapse;
4973: }
1.795 www 4974:
1.349 albertel 4975: table.LC_calendar_pickdate {
4976: font-size: xx-small;
4977: }
1.795 www 4978:
1.349 albertel 4979: table.LC_calendar tr td {
4980: border: 1px solid #000000;
4981: vertical-align: top;
4982: }
1.795 www 4983:
1.349 albertel 4984: table.LC_calendar tr td.LC_calendar_day_empty {
4985: background-color: $data_table_dark;
4986: }
1.795 www 4987:
1.779 bisitz 4988: table.LC_calendar tr td.LC_calendar_day_current {
4989: background-color: $data_table_highlight;
1.777 tempelho 4990: }
1.795 www 4991:
1.349 albertel 4992: table.LC_mail_list tr.LC_mail_new {
4993: background-color: $mail_new;
4994: }
1.795 www 4995:
1.349 albertel 4996: table.LC_mail_list tr.LC_mail_new:hover {
4997: background-color: $mail_new_hover;
4998: }
1.795 www 4999:
5000: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5001: }
1.795 www 5002:
5003: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5004: }
1.795 www 5005:
1.349 albertel 5006: table.LC_mail_list tr.LC_mail_read {
5007: background-color: $mail_read;
5008: }
1.795 www 5009:
1.349 albertel 5010: table.LC_mail_list tr.LC_mail_read:hover {
5011: background-color: $mail_read_hover;
5012: }
1.795 www 5013:
1.349 albertel 5014: table.LC_mail_list tr.LC_mail_replied {
5015: background-color: $mail_replied;
5016: }
1.795 www 5017:
1.349 albertel 5018: table.LC_mail_list tr.LC_mail_replied:hover {
5019: background-color: $mail_replied_hover;
5020: }
1.795 www 5021:
1.349 albertel 5022: table.LC_mail_list tr.LC_mail_other {
5023: background-color: $mail_other;
5024: }
1.795 www 5025:
1.349 albertel 5026: table.LC_mail_list tr.LC_mail_other:hover {
5027: background-color: $mail_other_hover;
5028: }
1.494 raeburn 5029:
1.777 tempelho 5030: table.LC_data_table tr > td.LC_browser_file,
5031: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5032: background: #CCFF88;
5033: }
1.795 www 5034:
1.777 tempelho 5035: table.LC_data_table tr > td.LC_browser_file_locked,
5036: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5037: background: #FFAA99;
1.387 albertel 5038: }
1.795 www 5039:
1.777 tempelho 5040: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5041: background: #AAAAAA;
5042: }
1.795 www 5043:
1.777 tempelho 5044: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5045: table.LC_data_table tr > td.LC_browser_file_metamodified {
5046: background: #FFFF77;
1.777 tempelho 5047: }
1.795 www 5048:
1.696 bisitz 5049: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5050: background: #CCCCFF;
1.387 albertel 5051: }
1.696 bisitz 5052:
1.707 bisitz 5053: table.LC_data_table tr > td.LC_roles_is {
5054: /* background: #77FF77; */
5055: }
1.795 www 5056:
1.707 bisitz 5057: table.LC_data_table tr > td.LC_roles_future {
5058: background: #FFFF77;
5059: }
1.795 www 5060:
1.707 bisitz 5061: table.LC_data_table tr > td.LC_roles_will {
5062: background: #FFAA77;
5063: }
1.795 www 5064:
1.707 bisitz 5065: table.LC_data_table tr > td.LC_roles_expired {
5066: background: #FF7777;
5067: }
1.795 www 5068:
1.707 bisitz 5069: table.LC_data_table tr > td.LC_roles_will_not {
5070: background: #AAFF77;
5071: }
1.795 www 5072:
1.707 bisitz 5073: table.LC_data_table tr > td.LC_roles_selected {
5074: background: #11CC55;
5075: }
5076:
1.388 albertel 5077: span.LC_current_location {
1.701 harmsja 5078: font-size:larger;
1.388 albertel 5079: background: $pgbg;
5080: }
1.387 albertel 5081:
1.395 albertel 5082: span.LC_parm_menu_item {
5083: font-size: larger;
5084: }
1.795 www 5085:
1.395 albertel 5086: span.LC_parm_scope_all {
5087: color: red;
5088: }
1.795 www 5089:
1.395 albertel 5090: span.LC_parm_scope_folder {
5091: color: green;
5092: }
1.795 www 5093:
1.395 albertel 5094: span.LC_parm_scope_resource {
5095: color: orange;
5096: }
1.795 www 5097:
1.395 albertel 5098: span.LC_parm_part {
5099: color: blue;
5100: }
1.795 www 5101:
1.395 albertel 5102: span.LC_parm_folder, span.LC_parm_symb {
5103: font-size: x-small;
5104: font-family: $mono;
5105: color: #AAAAAA;
5106: }
5107:
1.795 www 5108: td.LC_parm_overview_level_menu,
5109: td.LC_parm_overview_map_menu,
5110: td.LC_parm_overview_parm_selectors,
5111: td.LC_parm_overview_restrictions {
1.396 albertel 5112: border: 1px solid black;
5113: border-collapse: collapse;
5114: }
1.795 www 5115:
1.396 albertel 5116: table.LC_parm_overview_restrictions td {
5117: border-width: 1px 4px 1px 4px;
5118: border-style: solid;
5119: border-color: $pgbg;
5120: text-align: center;
5121: }
1.795 www 5122:
1.396 albertel 5123: table.LC_parm_overview_restrictions th {
5124: background: $tabbg;
5125: border-width: 1px 4px 1px 4px;
5126: border-style: solid;
5127: border-color: $pgbg;
5128: }
1.795 www 5129:
1.398 albertel 5130: table#LC_helpmenu {
1.803 bisitz 5131: border: none;
1.398 albertel 5132: height: 55px;
1.803 bisitz 5133: border-spacing: 0;
1.398 albertel 5134: }
5135:
5136: table#LC_helpmenu fieldset legend {
5137: font-size: larger;
5138: }
1.795 www 5139:
1.397 albertel 5140: table#LC_helpmenu_links {
5141: width: 100%;
5142: border: 1px solid black;
5143: background: $pgbg;
1.803 bisitz 5144: padding: 0;
1.397 albertel 5145: border-spacing: 1px;
5146: }
1.795 www 5147:
1.397 albertel 5148: table#LC_helpmenu_links tr td {
5149: padding: 1px;
5150: background: $tabbg;
1.399 albertel 5151: text-align: center;
5152: font-weight: bold;
1.397 albertel 5153: }
1.396 albertel 5154:
1.795 www 5155: table#LC_helpmenu_links a:link,
5156: table#LC_helpmenu_links a:visited,
1.397 albertel 5157: table#LC_helpmenu_links a:active {
5158: text-decoration: none;
5159: color: $font;
5160: }
1.795 www 5161:
1.397 albertel 5162: table#LC_helpmenu_links a:hover {
5163: text-decoration: underline;
5164: color: $vlink;
5165: }
1.396 albertel 5166:
1.417 albertel 5167: .LC_chrt_popup_exists {
5168: border: 1px solid #339933;
5169: margin: -1px;
5170: }
1.795 www 5171:
1.417 albertel 5172: .LC_chrt_popup_up {
5173: border: 1px solid yellow;
5174: margin: -1px;
5175: }
1.795 www 5176:
1.417 albertel 5177: .LC_chrt_popup {
5178: border: 1px solid #8888FF;
5179: background: #CCCCFF;
5180: }
1.795 www 5181:
1.421 albertel 5182: table.LC_pick_box {
5183: border-collapse: separate;
5184: background: white;
5185: border: 1px solid black;
5186: border-spacing: 1px;
5187: }
1.795 www 5188:
1.421 albertel 5189: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5190: background: $sidebg;
1.421 albertel 5191: font-weight: bold;
5192: text-align: right;
1.740 bisitz 5193: vertical-align: top;
1.421 albertel 5194: width: 184px;
5195: padding: 8px;
5196: }
1.795 www 5197:
1.579 raeburn 5198: table.LC_pick_box td.LC_pick_box_value {
5199: text-align: left;
5200: padding: 8px;
5201: }
1.795 www 5202:
1.579 raeburn 5203: table.LC_pick_box td.LC_pick_box_select {
5204: text-align: left;
5205: padding: 8px;
5206: }
1.795 www 5207:
1.424 albertel 5208: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5209: padding: 0;
1.421 albertel 5210: height: 1px;
5211: background: black;
5212: }
1.795 www 5213:
1.421 albertel 5214: table.LC_pick_box td.LC_pick_box_submit {
5215: text-align: right;
5216: }
1.795 www 5217:
1.579 raeburn 5218: table.LC_pick_box td.LC_evenrow_value {
5219: text-align: left;
5220: padding: 8px;
5221: background-color: $data_table_light;
5222: }
1.795 www 5223:
1.579 raeburn 5224: table.LC_pick_box td.LC_oddrow_value {
5225: text-align: left;
5226: padding: 8px;
5227: background-color: $data_table_light;
5228: }
1.795 www 5229:
1.579 raeburn 5230: table.LC_helpform_receipt {
5231: width: 620px;
5232: border-collapse: separate;
5233: background: white;
5234: border: 1px solid black;
5235: border-spacing: 1px;
5236: }
1.795 www 5237:
1.579 raeburn 5238: table.LC_helpform_receipt td.LC_pick_box_title {
5239: background: $tabbg;
5240: font-weight: bold;
5241: text-align: right;
5242: width: 184px;
5243: padding: 8px;
5244: }
1.795 www 5245:
1.579 raeburn 5246: table.LC_helpform_receipt td.LC_evenrow_value {
5247: text-align: left;
5248: padding: 8px;
5249: background-color: $data_table_light;
5250: }
1.795 www 5251:
1.579 raeburn 5252: table.LC_helpform_receipt td.LC_oddrow_value {
5253: text-align: left;
5254: padding: 8px;
5255: background-color: $data_table_light;
5256: }
1.795 www 5257:
1.579 raeburn 5258: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5259: padding: 0;
1.579 raeburn 5260: height: 1px;
5261: background: black;
5262: }
1.795 www 5263:
1.579 raeburn 5264: span.LC_helpform_receipt_cat {
5265: font-weight: bold;
5266: }
1.795 www 5267:
1.424 albertel 5268: table.LC_group_priv_box {
5269: background: white;
5270: border: 1px solid black;
5271: border-spacing: 1px;
5272: }
1.795 www 5273:
1.424 albertel 5274: table.LC_group_priv_box td.LC_pick_box_title {
5275: background: $tabbg;
5276: font-weight: bold;
5277: text-align: right;
5278: width: 184px;
5279: }
1.795 www 5280:
1.424 albertel 5281: table.LC_group_priv_box td.LC_groups_fixed {
5282: background: $data_table_light;
5283: text-align: center;
5284: }
1.795 www 5285:
1.424 albertel 5286: table.LC_group_priv_box td.LC_groups_optional {
5287: background: $data_table_dark;
5288: text-align: center;
5289: }
1.795 www 5290:
1.424 albertel 5291: table.LC_group_priv_box td.LC_groups_functionality {
5292: background: $data_table_darker;
5293: text-align: center;
5294: font-weight: bold;
5295: }
1.795 www 5296:
1.424 albertel 5297: table.LC_group_priv td {
5298: text-align: left;
1.803 bisitz 5299: padding: 0;
1.424 albertel 5300: }
5301:
1.421 albertel 5302: table.LC_notify_front_page {
5303: background: white;
5304: border: 1px solid black;
5305: padding: 8px;
5306: }
1.795 www 5307:
1.421 albertel 5308: table.LC_notify_front_page td {
5309: padding: 8px;
5310: }
1.795 www 5311:
1.424 albertel 5312: .LC_navbuttons {
5313: margin: 2ex 0ex 2ex 0ex;
5314: }
1.795 www 5315:
1.423 albertel 5316: .LC_topic_bar {
5317: font-weight: bold;
5318: width: 100%;
5319: background: $tabbg;
5320: vertical-align: middle;
5321: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5322: padding: 3px;
1.423 albertel 5323: }
1.795 www 5324:
1.423 albertel 5325: .LC_topic_bar span {
5326: vertical-align: middle;
5327: }
1.795 www 5328:
1.423 albertel 5329: .LC_topic_bar img {
5330: vertical-align: bottom;
5331: }
1.795 www 5332:
1.423 albertel 5333: table.LC_course_group_status {
5334: margin: 20px;
5335: }
1.795 www 5336:
1.423 albertel 5337: table.LC_status_selector td {
5338: vertical-align: top;
5339: text-align: center;
1.424 albertel 5340: padding: 4px;
5341: }
1.795 www 5342:
1.599 albertel 5343: div.LC_feedback_link {
1.616 albertel 5344: clear: both;
1.829 kalberla 5345: background: $sidebg;
1.779 bisitz 5346: width: 100%;
1.829 kalberla 5347: padding-bottom: 10px;
5348: border: 1px $tabbg solid;
1.833 kalberla 5349: height: 22px;
5350: line-height: 22px;
5351: padding-top: 5px;
5352: }
5353:
5354: div.LC_feedback_link img {
5355: height: 22px;
1.867 kalberla 5356: vertical-align:middle;
1.829 kalberla 5357: }
5358:
5359: div.LC_feedback_link a{
5360: text-decoration: none;
1.489 raeburn 5361: }
1.795 www 5362:
1.867 kalberla 5363: div.LC_comblock {
5364: display:inline;
5365: color:$font;
5366: font-size:90%;
5367: }
5368:
5369: div.LC_feedback_link div.LC_comblock {
5370: padding-left:5px;
5371: }
5372:
5373: div.LC_feedback_link div.LC_comblock a {
5374: color:$font;
5375: }
5376:
1.489 raeburn 5377: span.LC_feedback_link {
1.858 bisitz 5378: /* background: $feedback_link_bg; */
1.599 albertel 5379: font-size: larger;
5380: }
1.795 www 5381:
1.599 albertel 5382: span.LC_message_link {
1.858 bisitz 5383: /* background: $feedback_link_bg; */
1.599 albertel 5384: font-size: larger;
5385: position: absolute;
5386: right: 1em;
1.489 raeburn 5387: }
1.421 albertel 5388:
1.515 albertel 5389: table.LC_prior_tries {
1.524 albertel 5390: border: 1px solid #000000;
5391: border-collapse: separate;
5392: border-spacing: 1px;
1.515 albertel 5393: }
1.523 albertel 5394:
1.515 albertel 5395: table.LC_prior_tries td {
1.524 albertel 5396: padding: 2px;
1.515 albertel 5397: }
1.523 albertel 5398:
5399: .LC_answer_correct {
1.795 www 5400: background: lightgreen;
5401: color: darkgreen;
5402: padding: 6px;
1.523 albertel 5403: }
1.795 www 5404:
1.523 albertel 5405: .LC_answer_charged_try {
1.797 www 5406: background: #FFAAAA;
1.795 www 5407: color: darkred;
5408: padding: 6px;
1.523 albertel 5409: }
1.795 www 5410:
1.779 bisitz 5411: .LC_answer_not_charged_try,
1.523 albertel 5412: .LC_answer_no_grade,
5413: .LC_answer_late {
1.795 www 5414: background: lightyellow;
1.523 albertel 5415: color: black;
1.795 www 5416: padding: 6px;
1.523 albertel 5417: }
1.795 www 5418:
1.523 albertel 5419: .LC_answer_previous {
1.795 www 5420: background: lightblue;
5421: color: darkblue;
5422: padding: 6px;
1.523 albertel 5423: }
1.795 www 5424:
1.779 bisitz 5425: .LC_answer_no_message {
1.777 tempelho 5426: background: #FFFFFF;
5427: color: black;
1.795 www 5428: padding: 6px;
1.779 bisitz 5429: }
1.795 www 5430:
1.779 bisitz 5431: .LC_answer_unknown {
5432: background: orange;
5433: color: black;
1.795 www 5434: padding: 6px;
1.777 tempelho 5435: }
1.795 www 5436:
1.529 albertel 5437: span.LC_prior_numerical,
5438: span.LC_prior_string,
5439: span.LC_prior_custom,
5440: span.LC_prior_reaction,
5441: span.LC_prior_math {
1.523 albertel 5442: font-family: monospace;
5443: white-space: pre;
5444: }
5445:
1.525 albertel 5446: span.LC_prior_string {
5447: font-family: monospace;
5448: white-space: pre;
5449: }
5450:
1.523 albertel 5451: table.LC_prior_option {
5452: width: 100%;
5453: border-collapse: collapse;
5454: }
1.795 www 5455:
5456: table.LC_prior_rank,
5457: table.LC_prior_match {
1.528 albertel 5458: border-collapse: collapse;
5459: }
1.795 www 5460:
1.528 albertel 5461: table.LC_prior_option tr td,
5462: table.LC_prior_rank tr td,
5463: table.LC_prior_match tr td {
1.524 albertel 5464: border: 1px solid #000000;
1.515 albertel 5465: }
5466:
1.855 bisitz 5467: .LC_nobreak {
1.544 albertel 5468: white-space: nowrap;
1.519 raeburn 5469: }
5470:
1.576 raeburn 5471: span.LC_cusr_emph {
5472: font-style: italic;
5473: }
5474:
1.633 raeburn 5475: span.LC_cusr_subheading {
5476: font-weight: normal;
5477: font-size: 85%;
5478: }
5479:
1.545 albertel 5480: table.LC_docs_documents {
5481: background: #BBBBBB;
1.803 bisitz 5482: border-width: 0;
1.545 albertel 5483: border-collapse: collapse;
5484: }
1.795 www 5485:
1.777 tempelho 5486: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5487: border: 2px solid black;
5488: padding: 4px;
1.777 tempelho 5489: }
1.795 www 5490:
1.861 bisitz 5491: div.LC_docs_entry_move {
1.859 bisitz 5492: border: 1px solid #BBBBBB;
1.545 albertel 5493: background: #DDDDDD;
1.861 bisitz 5494: width: 22px;
1.859 bisitz 5495: padding: 1px;
5496: margin: 0;
1.545 albertel 5497: }
5498:
1.861 bisitz 5499: table.LC_data_table tr > td.LC_docs_entry_commands,
5500: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5501: background: #DDDDDD;
5502: font-size: x-small;
5503: }
1.795 www 5504:
1.861 bisitz 5505: .LC_docs_entry_parameter {
5506: white-space: nowrap;
5507: }
5508:
1.544 albertel 5509: .LC_docs_copy {
1.545 albertel 5510: color: #000099;
1.544 albertel 5511: }
1.795 www 5512:
1.544 albertel 5513: .LC_docs_cut {
1.545 albertel 5514: color: #550044;
1.544 albertel 5515: }
1.795 www 5516:
1.544 albertel 5517: .LC_docs_rename {
1.545 albertel 5518: color: #009900;
1.544 albertel 5519: }
1.795 www 5520:
1.544 albertel 5521: .LC_docs_remove {
1.545 albertel 5522: color: #990000;
5523: }
5524:
1.547 albertel 5525: .LC_docs_reinit_warn,
5526: .LC_docs_ext_edit {
5527: font-size: x-small;
5528: }
5529:
1.545 albertel 5530: table.LC_docs_adddocs td,
5531: table.LC_docs_adddocs th {
5532: border: 1px solid #BBBBBB;
5533: padding: 4px;
5534: background: #DDDDDD;
1.543 albertel 5535: }
5536:
1.584 albertel 5537: table.LC_sty_begin {
5538: background: #BBFFBB;
5539: }
1.795 www 5540:
1.584 albertel 5541: table.LC_sty_end {
5542: background: #FFBBBB;
5543: }
5544:
1.589 raeburn 5545: table.LC_double_column {
1.803 bisitz 5546: border-width: 0;
1.589 raeburn 5547: border-collapse: collapse;
5548: width: 100%;
5549: padding: 2px;
5550: }
5551:
5552: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5553: top: 2px;
1.589 raeburn 5554: left: 2px;
5555: width: 47%;
5556: vertical-align: top;
5557: }
5558:
5559: table.LC_double_column tr td.LC_right_col {
5560: top: 2px;
1.779 bisitz 5561: right: 2px;
1.589 raeburn 5562: width: 47%;
5563: vertical-align: top;
5564: }
5565:
1.594 raeburn 5566: span.LC_role_level {
5567: font-weight: bold;
5568: }
5569:
1.591 raeburn 5570: div.LC_left_float {
5571: float: left;
5572: padding-right: 5%;
1.597 albertel 5573: padding-bottom: 4px;
1.591 raeburn 5574: }
5575:
5576: div.LC_clear_float_header {
1.597 albertel 5577: padding-bottom: 2px;
1.591 raeburn 5578: }
5579:
5580: div.LC_clear_float_footer {
1.597 albertel 5581: padding-top: 10px;
1.591 raeburn 5582: clear: both;
5583: }
5584:
1.597 albertel 5585: div.LC_grade_show_user {
5586: margin-top: 20px;
5587: border: 1px solid black;
5588: }
1.795 www 5589:
1.597 albertel 5590: div.LC_grade_user_name {
5591: background: #DDDDEE;
5592: border-bottom: 1px solid black;
1.705 tempelho 5593: font-weight: bold;
5594: font-size: large;
1.597 albertel 5595: }
1.795 www 5596:
1.597 albertel 5597: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5598: background: #DDEEDD;
5599: }
5600:
5601: div.LC_grade_show_problem,
5602: div.LC_grade_submissions,
5603: div.LC_grade_message_center,
5604: div.LC_grade_info_links,
5605: div.LC_grade_assign {
5606: margin: 5px;
5607: width: 99%;
5608: background: #FFFFFF;
5609: }
1.795 www 5610:
1.597 albertel 5611: div.LC_grade_show_problem_header,
5612: div.LC_grade_submissions_header,
5613: div.LC_grade_message_center_header,
5614: div.LC_grade_assign_header {
1.705 tempelho 5615: font-weight: bold;
5616: font-size: large;
1.597 albertel 5617: }
1.795 www 5618:
1.597 albertel 5619: div.LC_grade_show_problem_problem,
5620: div.LC_grade_submissions_body,
5621: div.LC_grade_message_center_body,
5622: div.LC_grade_assign_body {
5623: border: 1px solid black;
5624: width: 99%;
5625: background: #FFFFFF;
5626: }
1.795 www 5627:
1.598 albertel 5628: span.LC_grade_check_note {
1.705 tempelho 5629: font-weight: normal;
5630: font-size: medium;
1.598 albertel 5631: display: inline;
5632: position: absolute;
5633: right: 1em;
5634: }
1.597 albertel 5635:
1.613 albertel 5636: table.LC_scantron_action {
5637: width: 100%;
5638: }
1.795 www 5639:
1.613 albertel 5640: table.LC_scantron_action tr th {
1.698 harmsja 5641: font-weight:bold;
5642: font-style:normal;
1.613 albertel 5643: }
1.795 www 5644:
1.779 bisitz 5645: .LC_edit_problem_header,
1.614 albertel 5646: div.LC_edit_problem_footer {
1.705 tempelho 5647: font-weight: normal;
5648: font-size: medium;
1.602 albertel 5649: margin: 2px;
1.600 albertel 5650: }
1.795 www 5651:
1.600 albertel 5652: div.LC_edit_problem_header,
1.602 albertel 5653: div.LC_edit_problem_header div,
1.614 albertel 5654: div.LC_edit_problem_footer,
5655: div.LC_edit_problem_footer div,
1.602 albertel 5656: div.LC_edit_problem_editxml_header,
5657: div.LC_edit_problem_editxml_header div {
1.600 albertel 5658: margin-top: 5px;
5659: }
1.795 www 5660:
1.600 albertel 5661: div.LC_edit_problem_header_title {
1.705 tempelho 5662: font-weight: bold;
5663: font-size: larger;
1.602 albertel 5664: background: $tabbg;
5665: padding: 3px;
5666: }
1.795 www 5667:
1.602 albertel 5668: table.LC_edit_problem_header_title {
1.705 tempelho 5669: font-size: larger;
5670: font-weight: bold;
1.602 albertel 5671: width: 100%;
5672: border-color: $pgbg;
5673: border-style: solid;
5674: border-width: $border;
1.600 albertel 5675: background: $tabbg;
1.602 albertel 5676: border-collapse: collapse;
1.803 bisitz 5677: padding: 0;
1.602 albertel 5678: }
5679:
5680: div.LC_edit_problem_discards {
5681: float: left;
5682: padding-bottom: 5px;
5683: }
1.795 www 5684:
1.602 albertel 5685: div.LC_edit_problem_saves {
5686: float: right;
5687: padding-bottom: 5px;
1.600 albertel 5688: }
1.795 www 5689:
1.679 riegler 5690: img.stift{
1.803 bisitz 5691: border-width: 0;
5692: vertical-align: middle;
1.677 riegler 5693: }
1.680 riegler 5694:
1.681 riegler 5695: table#LC_mainmenu{
5696: margin-top:10px;
5697: width:80%;
5698: }
5699:
1.680 riegler 5700: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5701: vertical-align: top;
5702: width: 45%;
5703: }
1.795 www 5704:
1.779 bisitz 5705: .LC_mainmenu_fieldset_category {
5706: color: $font;
5707: background: $pgbg;
5708: font-size: small;
5709: font-weight: bold;
1.777 tempelho 5710: }
1.795 www 5711:
1.716 raeburn 5712: div.LC_createcourse {
5713: margin: 10px 10px 10px 10px;
5714: }
5715:
1.693 droeschl 5716: /* ---- Remove when done ----
5717: # The following styles is part of the redesign of LON-CAPA and are
5718: # subject to change during this project.
5719: # Don't rely on their current functionality as they might be
5720: # changed or removed.
5721: # --------------------------*/
5722:
1.698 harmsja 5723: a:hover,
1.721 harmsja 5724: ol.LC_smallMenu a:hover,
5725: ol#LC_MenuBreadcrumbs a:hover,
5726: ol#LC_PathBreadcrumbs a:hover,
5727: ul#LC_TabMainMenuContent a:hover,
5728: .LC_FormSectionClearButton input:hover
1.795 www 5729: ul.LC_TabContent li:hover a {
1.698 harmsja 5730: color:#BF2317;
5731: text-decoration:none;
1.693 droeschl 5732: }
5733:
1.779 bisitz 5734: h1 {
1.813 bisitz 5735: padding: 0;
1.693 droeschl 5736: line-height:130%;
5737: }
1.698 harmsja 5738:
1.795 www 5739: h2,h3,h4,h5,h6 {
1.803 bisitz 5740: margin: 5px 0 5px 0;
5741: padding: 0;
1.721 harmsja 5742: line-height:130%;
1.693 droeschl 5743: }
1.795 www 5744:
5745: .LC_hcell {
1.698 harmsja 5746: padding:3px 15px 3px 15px;
1.803 bisitz 5747: margin: 0;
1.703 harmsja 5748: background-color:$tabbg;
1.801 tempelho 5749: color:$fontmenu;
1.779 bisitz 5750: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5751: }
1.795 www 5752:
1.840 bisitz 5753: .LC_Box > .LC_hcell {
1.847 tempelho 5754: margin: 0 -10px 10px -10px;
1.835 bisitz 5755: }
5756:
1.721 harmsja 5757: .LC_noBorder {
1.803 bisitz 5758: border: 0;
1.698 harmsja 5759: }
1.693 droeschl 5760:
1.761 tempelho 5761: .LC_Right {
5762: float: right;
1.803 bisitz 5763: margin: 0;
5764: padding: 0;
1.761 tempelho 5765: }
5766:
1.721 harmsja 5767: .LC_FormSectionClearButton input {
1.779 bisitz 5768: background-color:transparent;
1.803 bisitz 5769: border: none;
1.698 harmsja 5770: cursor:pointer;
5771: text-decoration:underline;
1.693 droeschl 5772: }
1.763 bisitz 5773:
5774: .LC_help_open_topic {
5775: color: #FFFFFF;
5776: background-color: #EEEEFF;
5777: margin: 1px;
5778: padding: 4px;
5779: border: 1px solid #000033;
5780: white-space: nowrap;
1.783 amueller 5781: /* vertical-align: middle; */
1.759 neumanie 5782: }
1.693 droeschl 5783:
1.698 harmsja 5784: dl,ul,div,fieldset {
1.803 bisitz 5785: margin: 10px 10px 10px 0;
1.806 bisitz 5786: /* overflow: hidden; */
1.693 droeschl 5787: }
1.795 www 5788:
1.838 bisitz 5789: fieldset > legend {
5790: font-weight: bold;
5791: padding: 0 5px 0 5px;
5792: }
5793:
1.813 bisitz 5794: #LC_nav_bar {
1.807 droeschl 5795: float: left;
1.852 droeschl 5796: margin: 0.2em 0 0 0;
1.807 droeschl 5797: }
5798:
1.813 bisitz 5799: #LC_nav_bar em{
1.807 droeschl 5800: font-weight: bold;
5801: font-style: normal;
5802: }
5803:
5804: ol.LC_smallMenu {
5805: float: right;
1.852 droeschl 5806: margin: 0.2em 0 0 0;
1.807 droeschl 5807: }
5808:
1.852 droeschl 5809: ol#LC_PathBreadcrumbs {
1.803 bisitz 5810: margin: 0;
1.693 droeschl 5811: }
5812:
1.721 harmsja 5813: ol.LC_smallMenu li {
1.693 droeschl 5814: display: inline;
1.803 bisitz 5815: padding: 5px 5px 0 10px;
1.693 droeschl 5816: vertical-align: top;
5817: }
5818:
1.721 harmsja 5819: ol.LC_smallMenu li img {
1.693 droeschl 5820: vertical-align: bottom;
5821: }
5822:
1.721 harmsja 5823: ol.LC_smallMenu a {
1.693 droeschl 5824: font-size: 90%;
5825: color: RGB(80, 80, 80);
5826: text-decoration: none;
5827: }
1.795 www 5828:
1.808 droeschl 5829: ul#LC_TabMainMenuContent {
1.807 droeschl 5830: clear: both;
1.808 droeschl 5831: color: $fontmenu;
5832: background: $tabbg;
5833: list-style: none;
5834: padding: 0;
5835: margin: 0;
5836: width: 100%;
5837: }
5838:
5839: ul#LC_TabMainMenuContent li {
5840: font-weight: bold;
5841: line-height: 1.8em;
5842: padding: 0 0.8em;
5843: border-right: 1px solid black;
5844: display: inline;
5845: vertical-align: middle;
1.807 droeschl 5846: }
5847:
1.847 tempelho 5848: ul.LC_TabContent {
1.721 harmsja 5849: display:block;
1.847 tempelho 5850: background: $sidebg;
1.858 bisitz 5851: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5852: list-style:none;
1.847 tempelho 5853: margin: -10px -10px 0 -10px;
1.803 bisitz 5854: padding: 0;
1.693 droeschl 5855: }
5856:
1.847 tempelho 5857: ul.LC_TabContentBigger {
5858: display:block;
5859: list-style:none;
5860: padding: 0;
5861: }
5862:
5863:
1.795 www 5864: ul.LC_TabContent li,
5865: ul.LC_TabContentBigger li {
1.693 droeschl 5866: display: inline;
1.741 harmsja 5867: border-right: solid 1px $lg_border_color;
5868: float:left;
5869: line-height:140%;
5870: white-space:nowrap;
5871: }
1.795 www 5872:
1.808 droeschl 5873: ul#LC_TabMainMenuContent li a {
5874: color: $fontmenu;
1.693 droeschl 5875: text-decoration: none;
5876: }
1.795 www 5877:
1.721 harmsja 5878: ul.LC_TabContent {
1.847 tempelho 5879: min-height:1.5em;
1.721 harmsja 5880: }
1.795 www 5881:
5882: ul.LC_TabContent li {
1.741 harmsja 5883: vertical-align:middle;
1.803 bisitz 5884: padding: 0 10px 0 10px;
1.745 ehlerst 5885: background-color:$tabbg;
5886: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5887: }
1.795 www 5888:
1.847 tempelho 5889: ul.LC_TabContent .right {
5890: float:right;
5891: }
5892:
1.795 www 5893: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5894: color:rgb(47,47,47);
5895: text-decoration:none;
5896: font-size:95%;
5897: font-weight:bold;
1.761 tempelho 5898: padding-right: 16px;
1.721 harmsja 5899: }
1.795 www 5900:
5901: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5902: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5903: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5904: padding-right: 16px;
1.744 ehlerst 5905: }
1.795 www 5906:
5907: ul.LC_TabContentBigger li {
1.741 harmsja 5908: vertical-align:bottom;
5909: border-top:solid 1px $lg_border_color;
5910: border-left:solid 1px $lg_border_color;
5911: padding:5px 10px 5px 10px;
5912: margin-left:2px;
1.841 tempelho 5913: background: #d9d9d9;
5914: }
5915:
5916: #maincoursedoc {
5917: clear:both;
1.741 harmsja 5918: }
1.795 www 5919:
5920: ul.LC_TabContentBigger li:hover,
5921: ul.LC_TabContentBigger li.active {
1.847 tempelho 5922: background: #ffffff;
1.857 tempelho 5923: color:$font;
1.744 ehlerst 5924: }
1.795 www 5925:
5926: ul.LC_TabContentBigger li,
5927: ul.LC_TabContentBigger li a {
1.741 harmsja 5928: font-size:110%;
5929: font-weight:bold;
1.857 tempelho 5930: color: #737373;
1.741 harmsja 5931: }
1.693 droeschl 5932:
1.862 bisitz 5933: ul.LC_CourseBreadcrumbs {
5934: background: $sidebg;
5935: line-height: 32px;
5936: padding-left: 10px;
5937: margin: 0 0 10px 0;
5938: list-style-position: inside;
5939:
5940: }
5941:
1.795 www 5942: ol#LC_MenuBreadcrumbs,
1.862 bisitz 5943: ol#LC_PathBreadcrumbs {
1.693 droeschl 5944: padding-left: 10px;
1.819 tempelho 5945: margin: 0;
1.693 droeschl 5946: list-style-position: inside;
5947: }
5948:
1.795 www 5949: ol#LC_MenuBreadcrumbs li,
5950: ol#LC_PathBreadcrumbs li,
1.862 bisitz 5951: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 5952: display: inline;
5953: white-space: nowrap;
1.693 droeschl 5954: }
5955:
1.823 bisitz 5956: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 5957: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 5958: text-decoration: none;
5959: font-size:90%;
5960: }
1.795 www 5961:
5962: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 5963: text-decoration:none;
5964: font-size:100%;
5965: font-weight:bold;
1.693 droeschl 5966: }
1.795 www 5967:
1.840 bisitz 5968: .LC_Box {
1.835 bisitz 5969: border: solid 1px $lg_border_color;
5970: padding: 0 10px 10px 10px;
1.746 neumanie 5971: }
1.795 www 5972:
5973: .LC_AboutMe_Image {
1.747 neumanie 5974: float:left;
5975: margin-right:10px;
5976: }
1.795 www 5977:
5978: .LC_Clear_AboutMe_Image {
1.747 neumanie 5979: clear:left;
5980: }
1.795 www 5981:
1.721 harmsja 5982: dl.LC_ListStyleClean dt {
1.693 droeschl 5983: padding-right: 5px;
5984: display: table-header-group;
5985: }
5986:
1.721 harmsja 5987: dl.LC_ListStyleClean dd {
1.693 droeschl 5988: display: table-row;
5989: }
5990:
1.721 harmsja 5991: .LC_ListStyleClean,
5992: .LC_ListStyleSimple,
5993: .LC_ListStyleNormal,
1.777 tempelho 5994: .LC_ListStyle_Border,
1.795 www 5995: .LC_ListStyleSpecial {
1.693 droeschl 5996: /*display:block; */
5997: list-style-position: inside;
5998: list-style-type: none;
5999: overflow: hidden;
1.803 bisitz 6000: padding: 0;
1.693 droeschl 6001: }
6002:
1.721 harmsja 6003: .LC_ListStyleSimple li,
6004: .LC_ListStyleSimple dd,
6005: .LC_ListStyleNormal li,
6006: .LC_ListStyleNormal dd,
6007: .LC_ListStyleSpecial li,
1.795 www 6008: .LC_ListStyleSpecial dd {
1.803 bisitz 6009: margin: 0;
1.693 droeschl 6010: padding: 5px 5px 5px 10px;
6011: clear: both;
6012: }
6013:
1.721 harmsja 6014: .LC_ListStyleClean li,
6015: .LC_ListStyleClean dd {
1.803 bisitz 6016: padding-top: 0;
6017: padding-bottom: 0;
1.693 droeschl 6018: }
6019:
1.721 harmsja 6020: .LC_ListStyleSimple dd,
1.795 www 6021: .LC_ListStyleSimple li {
1.698 harmsja 6022: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6023: }
6024:
1.721 harmsja 6025: .LC_ListStyleSpecial li,
6026: .LC_ListStyleSpecial dd {
1.693 droeschl 6027: list-style-type: none;
6028: background-color: RGB(220, 220, 220);
6029: margin-bottom: 4px;
6030: }
6031:
1.721 harmsja 6032: table.LC_SimpleTable {
1.698 harmsja 6033: margin:5px;
6034: border:solid 1px $lg_border_color;
1.795 www 6035: }
1.693 droeschl 6036:
1.721 harmsja 6037: table.LC_SimpleTable tr {
1.803 bisitz 6038: padding: 0;
1.698 harmsja 6039: border:solid 1px $lg_border_color;
1.693 droeschl 6040: }
1.795 www 6041:
6042: table.LC_SimpleTable thead {
1.698 harmsja 6043: background:rgb(220,220,220);
1.693 droeschl 6044: }
6045:
1.721 harmsja 6046: div.LC_columnSection {
1.693 droeschl 6047: display: block;
6048: clear: both;
6049: overflow: hidden;
1.803 bisitz 6050: margin: 0;
1.693 droeschl 6051: }
6052:
1.721 harmsja 6053: div.LC_columnSection>* {
1.693 droeschl 6054: float: left;
1.803 bisitz 6055: margin: 10px 20px 10px 0;
1.747 neumanie 6056: overflow:hidden;
1.693 droeschl 6057: }
1.721 harmsja 6058:
1.694 tempelho 6059: .LC_loginpage_container {
6060: text-align:left;
6061: margin : 0 auto;
1.785 tempelho 6062: width:90%;
1.694 tempelho 6063: padding: 10px;
6064: height: auto;
1.712 muellerd 6065: background-color:#FFFFFF;
1.694 tempelho 6066: border:1px solid #CCCCCC;
6067: }
6068:
6069:
6070: .LC_loginpage_loginContainer {
6071: float:left;
1.712 muellerd 6072: width: 182px;
1.785 tempelho 6073: padding: 2px;
1.712 muellerd 6074: border:1px solid #CCCCCC;
6075: background-color:$loginbg;
1.694 tempelho 6076: }
6077:
1.795 www 6078: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6079: margin-top: 0;
1.712 muellerd 6080: display:block;
6081: background:$bgcol;
6082: color:$textcol;
6083: padding-left:5px;
6084: }
1.785 tempelho 6085:
1.694 tempelho 6086: .LC_loginpage_loginInfo {
6087: float:left;
1.785 tempelho 6088: width:182px;
1.694 tempelho 6089: border:1px solid #CCCCCC;
1.785 tempelho 6090: padding:2px;
1.712 muellerd 6091: }
6092:
1.694 tempelho 6093: .LC_loginpage_space {
1.754 droeschl 6094: clear: both;
6095: margin-bottom: 20px;
1.694 tempelho 6096: border-bottom: 1px solid #CCCCCC;
6097: }
6098:
1.785 tempelho 6099: .LC_loginpage_floatLeft {
6100: float: left;
6101: width: 200px;
6102: margin: 0;
6103: }
6104:
1.795 www 6105: table em {
1.754 droeschl 6106: font-weight: bold;
6107: font-style: normal;
1.748 schulted 6108: }
1.795 www 6109:
1.779 bisitz 6110: table.LC_tableBrowseRes,
1.795 www 6111: table.LC_tableOfContent {
1.769 schulted 6112: border:none;
1.858 bisitz 6113: border-spacing: 1px;
1.754 droeschl 6114: padding: 3px;
6115: background-color: #FFFFFF;
6116: font-size: 90%;
1.753 droeschl 6117: }
1.789 droeschl 6118:
6119: table.LC_tableOfContent{
6120: border-collapse: collapse;
6121: }
6122:
1.771 droeschl 6123: table.LC_tableBrowseRes a,
1.768 schulted 6124: table.LC_tableOfContent a {
1.771 droeschl 6125: background-color: transparent;
1.753 droeschl 6126: text-decoration: none;
6127: }
6128:
1.771 droeschl 6129: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6130: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6131: background-color: #EEEEEE;
1.753 droeschl 6132: }
6133:
1.795 www 6134: table.LC_tableOfContent img {
1.753 droeschl 6135: border: none;
6136: height: 1.3em;
6137: vertical-align: text-bottom;
6138: margin-right: 0.3em;
6139: }
1.757 schulted 6140:
1.795 www 6141: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6142: background-image:url(/res/adm/pages/open-first-problem.gif);
6143: }
6144:
1.795 www 6145: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6146: background-image:url(/res/adm/pages/start-navigation.gif);
6147: }
6148:
1.795 www 6149: a#LC_content_toolbar_closenav {
1.774 ehlerst 6150: background-image:url(/res/adm/pages/close-navigation.gif);
6151: }
6152:
1.795 www 6153: a#LC_content_toolbar_everything {
1.774 ehlerst 6154: background-image:url(/res/adm/pages/show-all.gif);
6155: }
6156:
1.795 www 6157: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6158: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6159: }
6160:
1.795 www 6161: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6162: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6163: }
6164:
1.795 www 6165: a#LC_content_toolbar_changefolder {
1.757 schulted 6166: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6167: }
6168:
1.795 www 6169: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6170: background-image:url(/res/adm/pages/open-all-folders.gif);
6171: }
6172:
1.795 www 6173: ul#LC_toolbar li a:hover {
1.757 schulted 6174: background-position: bottom center;
6175: }
6176:
1.795 www 6177: ul#LC_toolbar {
1.803 bisitz 6178: padding: 0;
1.757 schulted 6179: margin: 2px;
6180: list-style:none;
6181: position:relative;
6182: background-color:white;
6183: }
6184:
1.795 www 6185: ul#LC_toolbar li {
1.757 schulted 6186: border:1px solid white;
1.803 bisitz 6187: padding: 0;
1.757 schulted 6188: margin: 0;
1.795 www 6189: float: left;
1.767 droeschl 6190: display:inline;
1.757 schulted 6191: vertical-align:middle;
1.795 www 6192: }
1.757 schulted 6193:
1.783 amueller 6194:
1.795 www 6195: a.LC_toolbarItem {
1.767 droeschl 6196: display:block;
1.803 bisitz 6197: padding: 0;
6198: margin: 0;
1.757 schulted 6199: height: 32px;
6200: width: 32px;
1.779 bisitz 6201: color:white;
1.803 bisitz 6202: border: none;
1.757 schulted 6203: background-repeat:no-repeat;
6204: background-color:transparent;
6205: }
6206:
1.843 bisitz 6207: ul.LC_funclist li {
1.782 bisitz 6208: float: left;
6209: white-space: nowrap;
6210: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6211: margin: 0 15px 15px 10px;
1.782 bisitz 6212: }
6213:
1.757 schulted 6214:
1.343 albertel 6215: END
6216: }
6217:
1.306 albertel 6218: =pod
6219:
6220: =item * &headtag()
6221:
6222: Returns a uniform footer for LON-CAPA web pages.
6223:
1.307 albertel 6224: Inputs: $title - optional title for the head
6225: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6226: $args - optional arguments
1.319 albertel 6227: force_register - if is true call registerurl so the remote is
6228: informed
1.415 albertel 6229: redirect -> array ref of
6230: 1- seconds before redirect occurs
6231: 2- url to redirect to
6232: 3- whether the side effect should occur
1.315 albertel 6233: (side effect of setting
6234: $env{'internal.head.redirect'} to the url
6235: redirected too)
1.352 albertel 6236: domain -> force to color decorate a page for a specific
6237: domain
6238: function -> force usage of a specific rolish color scheme
6239: bgcolor -> override the default page bgcolor
1.460 albertel 6240: no_auto_mt_title
6241: -> prevent &mt()ing the title arg
1.464 albertel 6242:
1.306 albertel 6243: =cut
6244:
6245: sub headtag {
1.313 albertel 6246: my ($title,$head_extra,$args) = @_;
1.306 albertel 6247:
1.363 albertel 6248: my $function = $args->{'function'} || &get_users_function();
6249: my $domain = $args->{'domain'} || &determinedomain();
6250: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6251: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6252: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6253: #time(),
1.418 albertel 6254: $env{'environment.color.timestamp'},
1.363 albertel 6255: $function,$domain,$bgcolor);
6256:
1.369 www 6257: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6258:
1.308 albertel 6259: my $result =
6260: '<head>'.
1.461 albertel 6261: &font_settings();
1.319 albertel 6262:
1.461 albertel 6263: if (!$args->{'frameset'}) {
6264: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6265: }
1.319 albertel 6266: if ($args->{'force_register'}) {
6267: $result .= &Apache::lonmenu::registerurl(1);
6268: }
1.436 albertel 6269: if (!$args->{'no_nav_bar'}
6270: && !$args->{'only_body'}
6271: && !$args->{'frameset'}) {
6272: $result .= &help_menu_js();
6273: }
1.319 albertel 6274:
1.314 albertel 6275: if (ref($args->{'redirect'})) {
1.414 albertel 6276: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6277: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6278: if (!$inhibit_continue) {
6279: $env{'internal.head.redirect'} = $url;
6280: }
1.313 albertel 6281: $result.=<<ADDMETA
6282: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6283: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6284: ADDMETA
6285: }
1.306 albertel 6286: if (!defined($title)) {
6287: $title = 'The LearningOnline Network with CAPA';
6288: }
1.460 albertel 6289: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6290: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6291: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6292: .$head_extra;
1.306 albertel 6293: return $result;
6294: }
6295:
6296: =pod
6297:
1.340 albertel 6298: =item * &font_settings()
6299:
6300: Returns neccessary <meta> to set the proper encoding
6301:
6302: Inputs: none
6303:
6304: =cut
6305:
6306: sub font_settings {
6307: my $headerstring='';
1.647 www 6308: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6309: $headerstring.=
6310: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6311: }
6312: return $headerstring;
6313: }
6314:
1.341 albertel 6315: =pod
6316:
6317: =item * &xml_begin()
6318:
6319: Returns the needed doctype and <html>
6320:
6321: Inputs: none
6322:
6323: =cut
6324:
6325: sub xml_begin {
6326: my $output='';
6327:
1.592 albertel 6328: if ($env{'internal.start_page'}==1) {
6329: &Apache::lonhtmlcommon::init_htmlareafields();
6330: }
1.342 albertel 6331:
1.341 albertel 6332: if ($env{'browser.mathml'}) {
6333: $output='<?xml version="1.0"?>'
6334: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6335: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6336:
6337: # .'<!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">] >'
6338: .'<!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">'
6339: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6340: .'xmlns="http://www.w3.org/1999/xhtml">';
6341: } else {
1.849 bisitz 6342: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6343: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6344: }
6345: return $output;
6346: }
1.340 albertel 6347:
6348: =pod
6349:
1.306 albertel 6350: =item * &endheadtag()
6351:
6352: Returns a uniform </head> for LON-CAPA web pages.
6353:
6354: Inputs: none
6355:
6356: =cut
6357:
6358: sub endheadtag {
6359: return '</head>';
6360: }
6361:
6362: =pod
6363:
6364: =item * &head()
6365:
6366: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6367:
1.648 raeburn 6368: Inputs:
6369:
6370: =over 4
6371:
6372: $title - optional title for the page
6373:
6374: $head_extra - optional extra HTML to put inside the <head>
6375:
6376: =back
1.405 albertel 6377:
1.306 albertel 6378: =cut
6379:
6380: sub head {
1.325 albertel 6381: my ($title,$head_extra,$args) = @_;
6382: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6383: }
6384:
6385: =pod
6386:
6387: =item * &start_page()
6388:
6389: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6390:
1.648 raeburn 6391: Inputs:
6392:
6393: =over 4
6394:
6395: $title - optional title for the page
6396:
6397: $head_extra - optional extra HTML to incude inside the <head>
6398:
6399: $args - additional optional args supported are:
6400:
6401: =over 8
6402:
6403: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6404: arg on
1.814 bisitz 6405: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6406: add_entries -> additional attributes to add to the <body>
6407: domain -> force to color decorate a page for a
1.317 albertel 6408: specific domain
1.648 raeburn 6409: function -> force usage of a specific rolish color
1.317 albertel 6410: scheme
1.648 raeburn 6411: redirect -> see &headtag()
6412: bgcolor -> override the default page bg color
6413: js_ready -> return a string ready for being used in
1.317 albertel 6414: a javascript writeln
1.648 raeburn 6415: html_encode -> return a string ready for being used in
1.320 albertel 6416: a html attribute
1.648 raeburn 6417: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6418: $forcereg arg
1.648 raeburn 6419: frameset -> if true will start with a <frameset>
1.330 albertel 6420: rather than <body>
1.648 raeburn 6421: skip_phases -> hash ref of
1.338 albertel 6422: head -> skip the <html><head> generation
6423: body -> skip all <body> generation
1.648 raeburn 6424: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6425: 'Switch To Inline Menu' link
1.648 raeburn 6426: no_auto_mt_title -> prevent &mt()ing the title arg
6427: inherit_jsmath -> when creating popup window in a page,
6428: should it have jsmath forced on by the
6429: current page
1.867 kalberla 6430: bread_crumbs -> Array containing breadcrumbs
6431: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6432:
1.648 raeburn 6433: =back
1.460 albertel 6434:
1.648 raeburn 6435: =back
1.562 albertel 6436:
1.306 albertel 6437: =cut
6438:
6439: sub start_page {
1.309 albertel 6440: my ($title,$head_extra,$args) = @_;
1.318 albertel 6441: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6442: my %head_args;
1.352 albertel 6443: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6444: 'bgcolor','frameset','no_nav_bar','only_body',
6445: 'no_auto_mt_title') {
1.319 albertel 6446: if (defined($args->{$arg})) {
1.324 raeburn 6447: $head_args{$arg} = $args->{$arg};
1.319 albertel 6448: }
1.313 albertel 6449: }
1.319 albertel 6450:
1.315 albertel 6451: $env{'internal.start_page'}++;
1.338 albertel 6452: my $result;
6453: if (! exists($args->{'skip_phases'}{'head'}) ) {
6454: $result.=
1.341 albertel 6455: &xml_begin().
1.338 albertel 6456: &headtag($title,$head_extra,\%head_args).&endheadtag();
6457: }
6458:
6459: if (! exists($args->{'skip_phases'}{'body'}) ) {
6460: if ($args->{'frameset'}) {
6461: my $attr_string = &make_attr_string($args->{'force_register'},
6462: $args->{'add_entries'});
6463: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6464: } else {
6465: $result .=
6466: &bodytag($title,
6467: $args->{'function'}, $args->{'add_entries'},
6468: $args->{'only_body'}, $args->{'domain'},
6469: $args->{'force_register'}, $args->{'no_nav_bar'},
6470: $args->{'bgcolor'}, $args->{'no_inline_link'},
6471: $args);
6472: }
1.330 albertel 6473: }
1.338 albertel 6474:
1.315 albertel 6475: if ($args->{'js_ready'}) {
1.713 kaisler 6476: $result = &js_ready($result);
1.315 albertel 6477: }
1.320 albertel 6478: if ($args->{'html_encode'}) {
1.713 kaisler 6479: $result = &html_encode($result);
6480: }
6481:
1.813 bisitz 6482: # Preparation for new and consistent functionlist at top of screen
6483: # if ($args->{'functionlist'}) {
6484: # $result .= &build_functionlist();
6485: #}
6486:
6487: # Don't add anything more if only_body wanted
6488: return $result if $args->{'only_body'};
6489:
6490: #Breadcrumbs
1.758 kaisler 6491: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6492: &Apache::lonhtmlcommon::clear_breadcrumbs();
6493: #if any br links exists, add them to the breadcrumbs
6494: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6495: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6496: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6497: }
6498: }
6499:
6500: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6501: if(exists($args->{'bread_crumbs_component'})){
6502: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6503: }else{
6504: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6505: }
1.320 albertel 6506: }
1.315 albertel 6507: return $result;
1.306 albertel 6508: }
6509:
1.330 albertel 6510:
1.306 albertel 6511: =pod
6512:
6513: =item * &head()
6514:
6515: Returns a complete </body></html> section for LON-CAPA web pages.
6516:
1.315 albertel 6517: Inputs: $args - additional optional args supported are:
6518: js_ready -> return a string ready for being used in
6519: a javascript writeln
1.320 albertel 6520: html_encode -> return a string ready for being used in
6521: a html attribute
1.330 albertel 6522: frameset -> if true will start with a <frameset>
6523: rather than <body>
1.493 albertel 6524: dicsussion -> if true will get discussion from
6525: lonxml::xmlend
6526: (you can pass the target and parser arguments
6527: through optional 'target' and 'parser' args
6528: to this routine)
1.306 albertel 6529:
6530: =cut
6531:
6532: sub end_page {
1.315 albertel 6533: my ($args) = @_;
6534: $env{'internal.end_page'}++;
1.330 albertel 6535: my $result;
1.335 albertel 6536: if ($args->{'discussion'}) {
6537: my ($target,$parser);
6538: if (ref($args->{'discussion'})) {
6539: ($target,$parser) =($args->{'discussion'}{'target'},
6540: $args->{'discussion'}{'parser'});
6541: }
6542: $result .= &Apache::lonxml::xmlend($target,$parser);
6543: }
6544:
1.330 albertel 6545: if ($args->{'frameset'}) {
6546: $result .= '</frameset>';
6547: } else {
1.635 raeburn 6548: $result .= &endbodytag($args);
1.330 albertel 6549: }
6550: $result .= "\n</html>";
6551:
1.315 albertel 6552: if ($args->{'js_ready'}) {
1.317 albertel 6553: $result = &js_ready($result);
1.315 albertel 6554: }
1.335 albertel 6555:
1.320 albertel 6556: if ($args->{'html_encode'}) {
6557: $result = &html_encode($result);
6558: }
1.335 albertel 6559:
1.315 albertel 6560: return $result;
6561: }
6562:
1.320 albertel 6563: sub html_encode {
6564: my ($result) = @_;
6565:
1.322 albertel 6566: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6567:
6568: return $result;
6569: }
1.317 albertel 6570: sub js_ready {
6571: my ($result) = @_;
6572:
1.323 albertel 6573: $result =~ s/[\n\r]/ /xmsg;
6574: $result =~ s/\\/\\\\/xmsg;
6575: $result =~ s/'/\\'/xmsg;
1.372 albertel 6576: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6577:
6578: return $result;
6579: }
6580:
1.315 albertel 6581: sub validate_page {
6582: if ( exists($env{'internal.start_page'})
1.316 albertel 6583: && $env{'internal.start_page'} > 1) {
6584: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6585: $env{'internal.start_page'}.' '.
1.316 albertel 6586: $ENV{'request.filename'});
1.315 albertel 6587: }
6588: if ( exists($env{'internal.end_page'})
1.316 albertel 6589: && $env{'internal.end_page'} > 1) {
6590: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6591: $env{'internal.end_page'}.' '.
1.316 albertel 6592: $env{'request.filename'});
1.315 albertel 6593: }
6594: if ( exists($env{'internal.start_page'})
6595: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6596: &Apache::lonnet::logthis('start_page called without end_page '.
6597: $env{'request.filename'});
1.315 albertel 6598: }
6599: if ( ! exists($env{'internal.start_page'})
6600: && exists($env{'internal.end_page'})) {
1.316 albertel 6601: &Apache::lonnet::logthis('end_page called without start_page'.
6602: $env{'request.filename'});
1.315 albertel 6603: }
1.306 albertel 6604: }
1.315 albertel 6605:
1.318 albertel 6606: sub simple_error_page {
6607: my ($r,$title,$msg) = @_;
6608: my $page =
6609: &Apache::loncommon::start_page($title).
6610: &mt($msg).
6611: &Apache::loncommon::end_page();
6612: if (ref($r)) {
6613: $r->print($page);
1.327 albertel 6614: return;
1.318 albertel 6615: }
6616: return $page;
6617: }
1.347 albertel 6618:
6619: {
1.610 albertel 6620: my @row_count;
1.347 albertel 6621: sub start_data_table {
1.422 albertel 6622: my ($add_class) = @_;
6623: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6624: unshift(@row_count,0);
1.422 albertel 6625: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6626: }
6627:
6628: sub end_data_table {
1.610 albertel 6629: shift(@row_count);
1.389 albertel 6630: return '</table>'."\n";;
1.347 albertel 6631: }
6632:
6633: sub start_data_table_row {
1.422 albertel 6634: my ($add_class) = @_;
1.610 albertel 6635: $row_count[0]++;
6636: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6637: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6638: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6639: }
1.471 banghart 6640:
6641: sub continue_data_table_row {
6642: my ($add_class) = @_;
1.610 albertel 6643: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6644: $css_class = (join(' ',$css_class,$add_class));
6645: return '<tr class="'.$css_class.'">'."\n";;
6646: }
1.347 albertel 6647:
6648: sub end_data_table_row {
1.389 albertel 6649: return '</tr>'."\n";;
1.347 albertel 6650: }
1.367 www 6651:
1.421 albertel 6652: sub start_data_table_empty_row {
1.707 bisitz 6653: # $row_count[0]++;
1.421 albertel 6654: return '<tr class="LC_empty_row" >'."\n";;
6655: }
6656:
6657: sub end_data_table_empty_row {
6658: return '</tr>'."\n";;
6659: }
6660:
1.367 www 6661: sub start_data_table_header_row {
1.389 albertel 6662: return '<tr class="LC_header_row">'."\n";;
1.367 www 6663: }
6664:
6665: sub end_data_table_header_row {
1.389 albertel 6666: return '</tr>'."\n";;
1.367 www 6667: }
1.347 albertel 6668: }
6669:
1.548 albertel 6670: =pod
6671:
6672: =item * &inhibit_menu_check($arg)
6673:
6674: Checks for a inhibitmenu state and generates output to preserve it
6675:
6676: Inputs: $arg - can be any of
6677: - undef - in which case the return value is a string
6678: to add into arguments list of a uri
6679: - 'input' - in which case the return value is a HTML
6680: <form> <input> field of type hidden to
6681: preserve the value
6682: - a url - in which case the return value is the url with
6683: the neccesary cgi args added to preserve the
6684: inhibitmenu state
6685: - a ref to a url - no return value, but the string is
6686: updated to include the neccessary cgi
6687: args to preserve the inhibitmenu state
6688:
6689: =cut
6690:
6691: sub inhibit_menu_check {
6692: my ($arg) = @_;
6693: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6694: if ($arg eq 'input') {
6695: if ($env{'form.inhibitmenu'}) {
6696: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6697: } else {
6698: return
6699: }
6700: }
6701: if ($env{'form.inhibitmenu'}) {
6702: if (ref($arg)) {
6703: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6704: } elsif ($arg eq '') {
6705: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6706: } else {
6707: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6708: }
6709: }
6710: if (!ref($arg)) {
6711: return $arg;
6712: }
6713: }
6714:
1.251 albertel 6715: ###############################################
1.182 matthew 6716:
6717: =pod
6718:
1.549 albertel 6719: =back
6720:
6721: =head1 User Information Routines
6722:
6723: =over 4
6724:
1.405 albertel 6725: =item * &get_users_function()
1.182 matthew 6726:
6727: Used by &bodytag to determine the current users primary role.
6728: Returns either 'student','coordinator','admin', or 'author'.
6729:
6730: =cut
6731:
6732: ###############################################
6733: sub get_users_function {
1.815 tempelho 6734: my $function = 'norole';
1.818 tempelho 6735: if ($env{'request.role'}=~/^(st)/) {
6736: $function='student';
6737: }
1.258 albertel 6738: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6739: $function='coordinator';
6740: }
1.258 albertel 6741: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6742: $function='admin';
6743: }
1.826 bisitz 6744: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6745: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6746: $function='author';
6747: }
6748: return $function;
1.54 www 6749: }
1.99 www 6750:
6751: ###############################################
6752:
1.233 raeburn 6753: =pod
6754:
1.821 raeburn 6755: =item * &show_course()
6756:
6757: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6758: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6759:
6760: Inputs:
6761: None
6762:
6763: Outputs:
6764: Scalar: 1 if 'Course' to be used, 0 otherwise.
6765:
6766: =cut
6767:
6768: ###############################################
6769: sub show_course {
6770: my $course = !$env{'user.adv'};
6771: if (!$env{'user.adv'}) {
6772: foreach my $env (keys(%env)) {
6773: next if ($env !~ m/^user\.priv\./);
6774: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6775: $course = 0;
6776: last;
6777: }
6778: }
6779: }
6780: return $course;
6781: }
6782:
6783: ###############################################
6784:
6785: =pod
6786:
1.542 raeburn 6787: =item * &check_user_status()
1.274 raeburn 6788:
6789: Determines current status of supplied role for a
6790: specific user. Roles can be active, previous or future.
6791:
6792: Inputs:
6793: user's domain, user's username, course's domain,
1.375 raeburn 6794: course's number, optional section ID.
1.274 raeburn 6795:
6796: Outputs:
6797: role status: active, previous or future.
6798:
6799: =cut
6800:
6801: sub check_user_status {
1.412 raeburn 6802: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6803: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6804: my @uroles = keys %userinfo;
6805: my $srchstr;
6806: my $active_chk = 'none';
1.412 raeburn 6807: my $now = time;
1.274 raeburn 6808: if (@uroles > 0) {
1.412 raeburn 6809: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6810: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6811: } else {
1.412 raeburn 6812: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6813: }
6814: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6815: my $role_end = 0;
6816: my $role_start = 0;
6817: $active_chk = 'active';
1.412 raeburn 6818: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6819: $role_end = $1;
6820: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6821: $role_start = $1;
1.274 raeburn 6822: }
6823: }
6824: if ($role_start > 0) {
1.412 raeburn 6825: if ($now < $role_start) {
1.274 raeburn 6826: $active_chk = 'future';
6827: }
6828: }
6829: if ($role_end > 0) {
1.412 raeburn 6830: if ($now > $role_end) {
1.274 raeburn 6831: $active_chk = 'previous';
6832: }
6833: }
6834: }
6835: }
6836: return $active_chk;
6837: }
6838:
6839: ###############################################
6840:
6841: =pod
6842:
1.405 albertel 6843: =item * &get_sections()
1.233 raeburn 6844:
6845: Determines all the sections for a course including
6846: sections with students and sections containing other roles.
1.419 raeburn 6847: Incoming parameters:
6848:
6849: 1. domain
6850: 2. course number
6851: 3. reference to array containing roles for which sections should
6852: be gathered (optional).
6853: 4. reference to array containing status types for which sections
6854: should be gathered (optional).
6855:
6856: If the third argument is undefined, sections are gathered for any role.
6857: If the fourth argument is undefined, sections are gathered for any status.
6858: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6859:
1.374 raeburn 6860: Returns section hash (keys are section IDs, values are
6861: number of users in each section), subject to the
1.419 raeburn 6862: optional roles filter, optional status filter
1.233 raeburn 6863:
6864: =cut
6865:
6866: ###############################################
6867: sub get_sections {
1.419 raeburn 6868: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6869: if (!defined($cdom) || !defined($cnum)) {
6870: my $cid = $env{'request.course.id'};
6871:
6872: return if (!defined($cid));
6873:
6874: $cdom = $env{'course.'.$cid.'.domain'};
6875: $cnum = $env{'course.'.$cid.'.num'};
6876: }
6877:
6878: my %sectioncount;
1.419 raeburn 6879: my $now = time;
1.240 albertel 6880:
1.366 albertel 6881: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6882: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6883: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6884: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6885: my $start_index = &Apache::loncoursedata::CL_START();
6886: my $end_index = &Apache::loncoursedata::CL_END();
6887: my $status;
1.366 albertel 6888: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6889: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6890: $data->[$status_index],
6891: $data->[$start_index],
6892: $data->[$end_index]);
6893: if ($stu_status eq 'Active') {
6894: $status = 'active';
6895: } elsif ($end < $now) {
6896: $status = 'previous';
6897: } elsif ($start > $now) {
6898: $status = 'future';
6899: }
6900: if ($section ne '-1' && $section !~ /^\s*$/) {
6901: if ((!defined($possible_status)) || (($status ne '') &&
6902: (grep/^\Q$status\E$/,@{$possible_status}))) {
6903: $sectioncount{$section}++;
6904: }
1.240 albertel 6905: }
6906: }
6907: }
6908: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6909: foreach my $user (sort(keys(%courseroles))) {
6910: if ($user !~ /^(\w{2})/) { next; }
6911: my ($role) = ($user =~ /^(\w{2})/);
6912: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6913: my ($section,$status);
1.240 albertel 6914: if ($role eq 'cr' &&
6915: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6916: $section=$1;
6917: }
6918: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6919: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6920: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6921: if ($end == -1 && $start == -1) {
6922: next; #deleted role
6923: }
6924: if (!defined($possible_status)) {
6925: $sectioncount{$section}++;
6926: } else {
6927: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6928: $status = 'active';
6929: } elsif ($end < $now) {
6930: $status = 'future';
6931: } elsif ($start > $now) {
6932: $status = 'previous';
6933: }
6934: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6935: $sectioncount{$section}++;
6936: }
6937: }
1.233 raeburn 6938: }
1.366 albertel 6939: return %sectioncount;
1.233 raeburn 6940: }
6941:
1.274 raeburn 6942: ###############################################
1.294 raeburn 6943:
6944: =pod
1.405 albertel 6945:
6946: =item * &get_course_users()
6947:
1.275 raeburn 6948: Retrieves usernames:domains for users in the specified course
6949: with specific role(s), and access status.
6950:
6951: Incoming parameters:
1.277 albertel 6952: 1. course domain
6953: 2. course number
6954: 3. access status: users must have - either active,
1.275 raeburn 6955: previous, future, or all.
1.277 albertel 6956: 4. reference to array of permissible roles
1.288 raeburn 6957: 5. reference to array of section restrictions (optional)
6958: 6. reference to results object (hash of hashes).
6959: 7. reference to optional userdata hash
1.609 raeburn 6960: 8. reference to optional statushash
1.630 raeburn 6961: 9. flag if privileged users (except those set to unhide in
6962: course settings) should be excluded
1.609 raeburn 6963: Keys of top level results hash are roles.
1.275 raeburn 6964: Keys of inner hashes are username:domain, with
6965: values set to access type.
1.288 raeburn 6966: Optional userdata hash returns an array with arguments in the
6967: same order as loncoursedata::get_classlist() for student data.
6968:
1.609 raeburn 6969: Optional statushash returns
6970:
1.288 raeburn 6971: Entries for end, start, section and status are blank because
6972: of the possibility of multiple values for non-student roles.
6973:
1.275 raeburn 6974: =cut
1.405 albertel 6975:
1.275 raeburn 6976: ###############################################
1.405 albertel 6977:
1.275 raeburn 6978: sub get_course_users {
1.630 raeburn 6979: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6980: my %idx = ();
1.419 raeburn 6981: my %seclists;
1.288 raeburn 6982:
6983: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6984: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6985: $idx{end} = &Apache::loncoursedata::CL_END();
6986: $idx{start} = &Apache::loncoursedata::CL_START();
6987: $idx{id} = &Apache::loncoursedata::CL_ID();
6988: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6989: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6990: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6991:
1.290 albertel 6992: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6993: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6994: my $now = time;
1.277 albertel 6995: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6996: my $match = 0;
1.412 raeburn 6997: my $secmatch = 0;
1.419 raeburn 6998: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6999: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7000: if ($section eq '') {
7001: $section = 'none';
7002: }
1.291 albertel 7003: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7004: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7005: $secmatch = 1;
7006: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7007: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7008: $secmatch = 1;
7009: }
7010: } else {
1.419 raeburn 7011: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7012: $secmatch = 1;
7013: }
1.290 albertel 7014: }
1.412 raeburn 7015: if (!$secmatch) {
7016: next;
7017: }
1.419 raeburn 7018: }
1.275 raeburn 7019: if (defined($$types{'active'})) {
1.288 raeburn 7020: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7021: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7022: $match = 1;
1.275 raeburn 7023: }
7024: }
7025: if (defined($$types{'previous'})) {
1.609 raeburn 7026: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7027: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7028: $match = 1;
1.275 raeburn 7029: }
7030: }
7031: if (defined($$types{'future'})) {
1.609 raeburn 7032: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7033: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7034: $match = 1;
1.275 raeburn 7035: }
7036: }
1.609 raeburn 7037: if ($match) {
7038: push(@{$seclists{$student}},$section);
7039: if (ref($userdata) eq 'HASH') {
7040: $$userdata{$student} = $$classlist{$student};
7041: }
7042: if (ref($statushash) eq 'HASH') {
7043: $statushash->{$student}{'st'}{$section} = $status;
7044: }
1.288 raeburn 7045: }
1.275 raeburn 7046: }
7047: }
1.412 raeburn 7048: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7049: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7050: my $now = time;
1.609 raeburn 7051: my %displaystatus = ( previous => 'Expired',
7052: active => 'Active',
7053: future => 'Future',
7054: );
1.630 raeburn 7055: my %nothide;
7056: if ($hidepriv) {
7057: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7058: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7059: if ($user !~ /:/) {
7060: $nothide{join(':',split(/[\@]/,$user))}=1;
7061: } else {
7062: $nothide{$user} = 1;
7063: }
7064: }
7065: }
1.439 raeburn 7066: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7067: my $match = 0;
1.412 raeburn 7068: my $secmatch = 0;
1.439 raeburn 7069: my $status;
1.412 raeburn 7070: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7071: $user =~ s/:$//;
1.439 raeburn 7072: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7073: if ($end == -1 || $start == -1) {
7074: next;
7075: }
7076: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7077: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7078: my ($uname,$udom) = split(/:/,$user);
7079: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7080: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7081: $secmatch = 1;
7082: } elsif ($usec eq '') {
1.420 albertel 7083: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7084: $secmatch = 1;
7085: }
7086: } else {
7087: if (grep(/^\Q$usec\E$/,@{$sections})) {
7088: $secmatch = 1;
7089: }
7090: }
7091: if (!$secmatch) {
7092: next;
7093: }
1.288 raeburn 7094: }
1.419 raeburn 7095: if ($usec eq '') {
7096: $usec = 'none';
7097: }
1.275 raeburn 7098: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7099: if ($hidepriv) {
7100: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7101: (!$nothide{$uname.':'.$udom})) {
7102: next;
7103: }
7104: }
1.503 raeburn 7105: if ($end > 0 && $end < $now) {
1.439 raeburn 7106: $status = 'previous';
7107: } elsif ($start > $now) {
7108: $status = 'future';
7109: } else {
7110: $status = 'active';
7111: }
1.277 albertel 7112: foreach my $type (keys(%{$types})) {
1.275 raeburn 7113: if ($status eq $type) {
1.420 albertel 7114: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7115: push(@{$$users{$role}{$user}},$type);
7116: }
1.288 raeburn 7117: $match = 1;
7118: }
7119: }
1.419 raeburn 7120: if (($match) && (ref($userdata) eq 'HASH')) {
7121: if (!exists($$userdata{$uname.':'.$udom})) {
7122: &get_user_info($udom,$uname,\%idx,$userdata);
7123: }
1.420 albertel 7124: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7125: push(@{$seclists{$uname.':'.$udom}},$usec);
7126: }
1.609 raeburn 7127: if (ref($statushash) eq 'HASH') {
7128: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7129: }
1.275 raeburn 7130: }
7131: }
7132: }
7133: }
1.290 albertel 7134: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7135: if ((defined($cdom)) && (defined($cnum))) {
7136: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7137: if ( defined($csettings{'internal.courseowner'}) ) {
7138: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7139: next if ($owner eq '');
7140: my ($ownername,$ownerdom);
7141: if ($owner =~ /^([^:]+):([^:]+)$/) {
7142: $ownername = $1;
7143: $ownerdom = $2;
7144: } else {
7145: $ownername = $owner;
7146: $ownerdom = $cdom;
7147: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7148: }
7149: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7150: if (defined($userdata) &&
1.609 raeburn 7151: !exists($$userdata{$owner})) {
7152: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7153: if (!grep(/^none$/,@{$seclists{$owner}})) {
7154: push(@{$seclists{$owner}},'none');
7155: }
7156: if (ref($statushash) eq 'HASH') {
7157: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7158: }
1.290 albertel 7159: }
1.279 raeburn 7160: }
7161: }
7162: }
1.419 raeburn 7163: foreach my $user (keys(%seclists)) {
7164: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7165: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7166: }
1.275 raeburn 7167: }
7168: return;
7169: }
7170:
1.288 raeburn 7171: sub get_user_info {
7172: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7173: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7174: &plainname($uname,$udom,'lastname');
1.291 albertel 7175: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7176: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7177: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7178: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7179: return;
7180: }
1.275 raeburn 7181:
1.472 raeburn 7182: ###############################################
7183:
7184: =pod
7185:
7186: =item * &get_user_quota()
7187:
7188: Retrieves quota assigned for storage of portfolio files for a user
7189:
7190: Incoming parameters:
7191: 1. user's username
7192: 2. user's domain
7193:
7194: Returns:
1.536 raeburn 7195: 1. Disk quota (in Mb) assigned to student.
7196: 2. (Optional) Type of setting: custom or default
7197: (individually assigned or default for user's
7198: institutional status).
7199: 3. (Optional) - User's institutional status (e.g., faculty, staff
7200: or student - types as defined in localenroll::inst_usertypes
7201: for user's domain, which determines default quota for user.
7202: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7203:
7204: If a value has been stored in the user's environment,
1.536 raeburn 7205: it will return that, otherwise it returns the maximal default
7206: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7207:
7208: =cut
7209:
7210: ###############################################
7211:
7212:
7213: sub get_user_quota {
7214: my ($uname,$udom) = @_;
1.536 raeburn 7215: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7216: if (!defined($udom)) {
7217: $udom = $env{'user.domain'};
7218: }
7219: if (!defined($uname)) {
7220: $uname = $env{'user.name'};
7221: }
7222: if (($udom eq '' || $uname eq '') ||
7223: ($udom eq 'public') && ($uname eq 'public')) {
7224: $quota = 0;
1.536 raeburn 7225: $quotatype = 'default';
7226: $defquota = 0;
1.472 raeburn 7227: } else {
1.536 raeburn 7228: my $inststatus;
1.472 raeburn 7229: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7230: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7231: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7232: } else {
1.536 raeburn 7233: my %userenv =
7234: &Apache::lonnet::get('environment',['portfolioquota',
7235: 'inststatus'],$udom,$uname);
1.472 raeburn 7236: my ($tmp) = keys(%userenv);
7237: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7238: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7239: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7240: } else {
7241: undef(%userenv);
7242: }
7243: }
1.536 raeburn 7244: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7245: if ($quota eq '') {
1.536 raeburn 7246: $quota = $defquota;
7247: $quotatype = 'default';
7248: } else {
7249: $quotatype = 'custom';
1.472 raeburn 7250: }
7251: }
1.536 raeburn 7252: if (wantarray) {
7253: return ($quota,$quotatype,$settingstatus,$defquota);
7254: } else {
7255: return $quota;
7256: }
1.472 raeburn 7257: }
7258:
7259: ###############################################
7260:
7261: =pod
7262:
7263: =item * &default_quota()
7264:
1.536 raeburn 7265: Retrieves default quota assigned for storage of user portfolio files,
7266: given an (optional) user's institutional status.
1.472 raeburn 7267:
7268: Incoming parameters:
7269: 1. domain
1.536 raeburn 7270: 2. (Optional) institutional status(es). This is a : separated list of
7271: status types (e.g., faculty, staff, student etc.)
7272: which apply to the user for whom the default is being retrieved.
7273: If the institutional status string in undefined, the domain
7274: default quota will be returned.
1.472 raeburn 7275:
7276: Returns:
7277: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7278: 2. (Optional) institutional type which determined the value of the
7279: default quota.
1.472 raeburn 7280:
7281: If a value has been stored in the domain's configuration db,
7282: it will return that, otherwise it returns 20 (for backwards
7283: compatibility with domains which have not set up a configuration
7284: db file; the original statically defined portfolio quota was 20 Mb).
7285:
1.536 raeburn 7286: If the user's status includes multiple types (e.g., staff and student),
7287: the largest default quota which applies to the user determines the
7288: default quota returned.
7289:
1.780 raeburn 7290: =back
7291:
1.472 raeburn 7292: =cut
7293:
7294: ###############################################
7295:
7296:
7297: sub default_quota {
1.536 raeburn 7298: my ($udom,$inststatus) = @_;
7299: my ($defquota,$settingstatus);
7300: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7301: ['quotas'],$udom);
7302: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7303: if ($inststatus ne '') {
1.765 raeburn 7304: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7305: foreach my $item (@statuses) {
1.711 raeburn 7306: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7307: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7308: if ($defquota eq '') {
7309: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7310: $settingstatus = $item;
7311: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7312: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7313: $settingstatus = $item;
7314: }
7315: }
7316: } else {
7317: if ($quotahash{'quotas'}{$item} ne '') {
7318: if ($defquota eq '') {
7319: $defquota = $quotahash{'quotas'}{$item};
7320: $settingstatus = $item;
7321: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7322: $defquota = $quotahash{'quotas'}{$item};
7323: $settingstatus = $item;
7324: }
1.536 raeburn 7325: }
7326: }
7327: }
7328: }
7329: if ($defquota eq '') {
1.711 raeburn 7330: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7331: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7332: } else {
7333: $defquota = $quotahash{'quotas'}{'default'};
7334: }
1.536 raeburn 7335: $settingstatus = 'default';
7336: }
7337: } else {
7338: $settingstatus = 'default';
7339: $defquota = 20;
7340: }
7341: if (wantarray) {
7342: return ($defquota,$settingstatus);
1.472 raeburn 7343: } else {
1.536 raeburn 7344: return $defquota;
1.472 raeburn 7345: }
7346: }
7347:
1.384 raeburn 7348: sub get_secgrprole_info {
7349: my ($cdom,$cnum,$needroles,$type) = @_;
7350: my %sections_count = &get_sections($cdom,$cnum);
7351: my @sections = (sort {$a <=> $b} keys(%sections_count));
7352: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7353: my @groups = sort(keys(%curr_groups));
7354: my $allroles = [];
7355: my $rolehash;
7356: my $accesshash = {
7357: active => 'Currently has access',
7358: future => 'Will have future access',
7359: previous => 'Previously had access',
7360: };
7361: if ($needroles) {
7362: $rolehash = {'all' => 'all'};
1.385 albertel 7363: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7364: if (&Apache::lonnet::error(%user_roles)) {
7365: undef(%user_roles);
7366: }
7367: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7368: my ($role)=split(/\:/,$item,2);
7369: if ($role eq 'cr') { next; }
7370: if ($role =~ /^cr/) {
7371: $$rolehash{$role} = (split('/',$role))[3];
7372: } else {
7373: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7374: }
7375: }
7376: foreach my $key (sort(keys(%{$rolehash}))) {
7377: push(@{$allroles},$key);
7378: }
7379: push (@{$allroles},'st');
7380: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7381: }
7382: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7383: }
7384:
1.555 raeburn 7385: sub user_picker {
1.627 raeburn 7386: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7387: my $currdom = $dom;
7388: my %curr_selected = (
7389: srchin => 'dom',
1.580 raeburn 7390: srchby => 'lastname',
1.555 raeburn 7391: );
7392: my $srchterm;
1.625 raeburn 7393: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7394: if ($srch->{'srchby'} ne '') {
7395: $curr_selected{'srchby'} = $srch->{'srchby'};
7396: }
7397: if ($srch->{'srchin'} ne '') {
7398: $curr_selected{'srchin'} = $srch->{'srchin'};
7399: }
7400: if ($srch->{'srchtype'} ne '') {
7401: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7402: }
7403: if ($srch->{'srchdomain'} ne '') {
7404: $currdom = $srch->{'srchdomain'};
7405: }
7406: $srchterm = $srch->{'srchterm'};
7407: }
7408: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7409: 'usr' => 'Search criteria',
1.563 raeburn 7410: 'doma' => 'Domain/institution to search',
1.558 albertel 7411: 'uname' => 'username',
7412: 'lastname' => 'last name',
1.555 raeburn 7413: 'lastfirst' => 'last name, first name',
1.558 albertel 7414: 'crs' => 'in this course',
1.576 raeburn 7415: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7416: 'alc' => 'all LON-CAPA',
1.573 raeburn 7417: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7418: 'exact' => 'is',
7419: 'contains' => 'contains',
1.569 raeburn 7420: 'begins' => 'begins with',
1.571 raeburn 7421: 'youm' => "You must include some text to search for.",
7422: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7423: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7424: 'yomc' => "You must choose a domain when using an institutional directory search.",
7425: 'ymcd' => "You must choose a domain when using a domain search.",
7426: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7427: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7428: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7429: );
1.563 raeburn 7430: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7431: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7432:
7433: my @srchins = ('crs','dom','alc','instd');
7434:
7435: foreach my $option (@srchins) {
7436: # FIXME 'alc' option unavailable until
7437: # loncreateuser::print_user_query_page()
7438: # has been completed.
7439: next if ($option eq 'alc');
7440: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7441: if ($curr_selected{'srchin'} eq $option) {
7442: $srchinsel .= '
7443: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7444: } else {
7445: $srchinsel .= '
7446: <option value="'.$option.'">'.$lt{$option}.'</option>';
7447: }
1.555 raeburn 7448: }
1.563 raeburn 7449: $srchinsel .= "\n </select>\n";
1.555 raeburn 7450:
7451: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7452: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7453: if ($curr_selected{'srchby'} eq $option) {
7454: $srchbysel .= '
7455: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7456: } else {
7457: $srchbysel .= '
7458: <option value="'.$option.'">'.$lt{$option}.'</option>';
7459: }
7460: }
7461: $srchbysel .= "\n </select>\n";
7462:
7463: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7464: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7465: if ($curr_selected{'srchtype'} eq $option) {
7466: $srchtypesel .= '
7467: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7468: } else {
7469: $srchtypesel .= '
7470: <option value="'.$option.'">'.$lt{$option}.'</option>';
7471: }
7472: }
7473: $srchtypesel .= "\n </select>\n";
7474:
1.558 albertel 7475: my ($newuserscript,$new_user_create);
1.556 raeburn 7476:
7477: if ($forcenewuser) {
1.576 raeburn 7478: if (ref($srch) eq 'HASH') {
7479: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7480: if ($cancreate) {
7481: $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>';
7482: } else {
1.799 bisitz 7483: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7484: my %usertypetext = (
7485: official => 'institutional',
7486: unofficial => 'non-institutional',
7487: );
1.799 bisitz 7488: $new_user_create = '<p class="LC_warning">'
7489: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7490: .' '
7491: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7492: ,'<a href="'.$helplink.'">','</a>')
7493: .'</p><br />';
1.627 raeburn 7494: }
1.576 raeburn 7495: }
7496: }
7497:
1.556 raeburn 7498: $newuserscript = <<"ENDSCRIPT";
7499:
1.570 raeburn 7500: function setSearch(createnew,callingForm) {
1.556 raeburn 7501: if (createnew == 1) {
1.570 raeburn 7502: for (var i=0; i<callingForm.srchby.length; i++) {
7503: if (callingForm.srchby.options[i].value == 'uname') {
7504: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7505: }
7506: }
1.570 raeburn 7507: for (var i=0; i<callingForm.srchin.length; i++) {
7508: if ( callingForm.srchin.options[i].value == 'dom') {
7509: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7510: }
7511: }
1.570 raeburn 7512: for (var i=0; i<callingForm.srchtype.length; i++) {
7513: if (callingForm.srchtype.options[i].value == 'exact') {
7514: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7515: }
7516: }
1.570 raeburn 7517: for (var i=0; i<callingForm.srchdomain.length; i++) {
7518: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7519: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7520: }
7521: }
7522: }
7523: }
7524: ENDSCRIPT
1.558 albertel 7525:
1.556 raeburn 7526: }
7527:
1.555 raeburn 7528: my $output = <<"END_BLOCK";
1.556 raeburn 7529: <script type="text/javascript">
1.824 bisitz 7530: // <![CDATA[
1.570 raeburn 7531: function validateEntry(callingForm) {
1.558 albertel 7532:
1.556 raeburn 7533: var checkok = 1;
1.558 albertel 7534: var srchin;
1.570 raeburn 7535: for (var i=0; i<callingForm.srchin.length; i++) {
7536: if ( callingForm.srchin[i].checked ) {
7537: srchin = callingForm.srchin[i].value;
1.558 albertel 7538: }
7539: }
7540:
1.570 raeburn 7541: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7542: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7543: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7544: var srchterm = callingForm.srchterm.value;
7545: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7546: var msg = "";
7547:
7548: if (srchterm == "") {
7549: checkok = 0;
1.571 raeburn 7550: msg += "$lt{'youm'}\\n";
1.556 raeburn 7551: }
7552:
1.569 raeburn 7553: if (srchtype== 'begins') {
7554: if (srchterm.length < 2) {
7555: checkok = 0;
1.571 raeburn 7556: msg += "$lt{'thte'}\\n";
1.569 raeburn 7557: }
7558: }
7559:
1.556 raeburn 7560: if (srchtype== 'contains') {
7561: if (srchterm.length < 3) {
7562: checkok = 0;
1.571 raeburn 7563: msg += "$lt{'thet'}\\n";
1.556 raeburn 7564: }
7565: }
7566: if (srchin == 'instd') {
7567: if (srchdomain == '') {
7568: checkok = 0;
1.571 raeburn 7569: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7570: }
7571: }
7572: if (srchin == 'dom') {
7573: if (srchdomain == '') {
7574: checkok = 0;
1.571 raeburn 7575: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7576: }
7577: }
7578: if (srchby == 'lastfirst') {
7579: if (srchterm.indexOf(",") == -1) {
7580: checkok = 0;
1.571 raeburn 7581: msg += "$lt{'whus'}\\n";
1.556 raeburn 7582: }
7583: if (srchterm.indexOf(",") == srchterm.length -1) {
7584: checkok = 0;
1.571 raeburn 7585: msg += "$lt{'whse'}\\n";
1.556 raeburn 7586: }
7587: }
7588: if (checkok == 0) {
1.571 raeburn 7589: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7590: return;
7591: }
7592: if (checkok == 1) {
1.570 raeburn 7593: callingForm.submit();
1.556 raeburn 7594: }
7595: }
7596:
7597: $newuserscript
7598:
1.824 bisitz 7599: // ]]>
1.556 raeburn 7600: </script>
1.558 albertel 7601:
7602: $new_user_create
7603:
1.555 raeburn 7604: <table>
1.558 albertel 7605: <tr>
1.573 raeburn 7606: <td>$lt{'doma'}:</td>
7607: <td>$domform</td>
7608: </td>
7609: </tr>
7610: <tr>
7611: <td>$lt{'usr'}:</td>
1.563 raeburn 7612: <td>$srchbysel
7613: $srchtypesel
7614: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7615: $srchinsel
1.563 raeburn 7616: </td>
7617: </tr>
1.555 raeburn 7618: </table>
7619: <br />
7620: END_BLOCK
1.558 albertel 7621:
1.555 raeburn 7622: return $output;
7623: }
7624:
1.612 raeburn 7625: sub user_rule_check {
1.615 raeburn 7626: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7627: my $response;
7628: if (ref($usershash) eq 'HASH') {
7629: foreach my $user (keys(%{$usershash})) {
7630: my ($uname,$udom) = split(/:/,$user);
7631: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7632: my ($id,$newuser);
1.612 raeburn 7633: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7634: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7635: $id = $usershash->{$user}->{'id'};
7636: }
7637: my $inst_response;
7638: if (ref($checks) eq 'HASH') {
7639: if (defined($checks->{'username'})) {
1.615 raeburn 7640: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7641: &Apache::lonnet::get_instuser($udom,$uname);
7642: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7643: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7644: &Apache::lonnet::get_instuser($udom,undef,$id);
7645: }
1.615 raeburn 7646: } else {
7647: ($inst_response,%{$inst_results->{$user}}) =
7648: &Apache::lonnet::get_instuser($udom,$uname);
7649: return;
1.612 raeburn 7650: }
1.615 raeburn 7651: if (!$got_rules->{$udom}) {
1.612 raeburn 7652: my %domconfig = &Apache::lonnet::get_dom('configuration',
7653: ['usercreation'],$udom);
7654: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7655: foreach my $item ('username','id') {
1.612 raeburn 7656: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7657: $$curr_rules{$udom}{$item} =
7658: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7659: }
7660: }
7661: }
1.615 raeburn 7662: $got_rules->{$udom} = 1;
1.585 raeburn 7663: }
1.612 raeburn 7664: foreach my $item (keys(%{$checks})) {
7665: if (ref($$curr_rules{$udom}) eq 'HASH') {
7666: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7667: if (@{$$curr_rules{$udom}{$item}} > 0) {
7668: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7669: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7670: if ($rule_check{$rule}) {
7671: $$rulematch{$user}{$item} = $rule;
7672: if ($inst_response eq 'ok') {
1.615 raeburn 7673: if (ref($inst_results) eq 'HASH') {
7674: if (ref($inst_results->{$user}) eq 'HASH') {
7675: if (keys(%{$inst_results->{$user}}) == 0) {
7676: $$alerts{$item}{$udom}{$uname} = 1;
7677: }
1.612 raeburn 7678: }
7679: }
1.615 raeburn 7680: }
7681: last;
1.585 raeburn 7682: }
7683: }
7684: }
7685: }
7686: }
7687: }
7688: }
7689: }
1.612 raeburn 7690: return;
7691: }
7692:
7693: sub user_rule_formats {
7694: my ($domain,$domdesc,$curr_rules,$check) = @_;
7695: my %text = (
7696: 'username' => 'Usernames',
7697: 'id' => 'IDs',
7698: );
7699: my $output;
7700: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7701: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7702: if (@{$ruleorder} > 0) {
7703: $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>';
7704: foreach my $rule (@{$ruleorder}) {
7705: if (ref($curr_rules) eq 'ARRAY') {
7706: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7707: if (ref($rules->{$rule}) eq 'HASH') {
7708: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7709: $rules->{$rule}{'desc'}.'</li>';
7710: }
7711: }
7712: }
7713: }
7714: $output .= '</ul>';
7715: }
7716: }
7717: return $output;
7718: }
7719:
7720: sub instrule_disallow_msg {
1.615 raeburn 7721: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7722: my $response;
7723: my %text = (
7724: item => 'username',
7725: items => 'usernames',
7726: match => 'matches',
7727: do => 'does',
7728: action => 'a username',
7729: one => 'one',
7730: );
7731: if ($count > 1) {
7732: $text{'item'} = 'usernames';
7733: $text{'match'} ='match';
7734: $text{'do'} = 'do';
7735: $text{'action'} = 'usernames',
7736: $text{'one'} = 'ones';
7737: }
7738: if ($checkitem eq 'id') {
7739: $text{'items'} = 'IDs';
7740: $text{'item'} = 'ID';
7741: $text{'action'} = 'an ID';
1.615 raeburn 7742: if ($count > 1) {
7743: $text{'item'} = 'IDs';
7744: $text{'action'} = 'IDs';
7745: }
1.612 raeburn 7746: }
1.674 bisitz 7747: $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 7748: if ($mode eq 'upload') {
7749: if ($checkitem eq 'username') {
7750: $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'}.");
7751: } elsif ($checkitem eq 'id') {
1.674 bisitz 7752: $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 7753: }
1.669 raeburn 7754: } elsif ($mode eq 'selfcreate') {
7755: if ($checkitem eq 'id') {
7756: $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.");
7757: }
1.615 raeburn 7758: } else {
7759: if ($checkitem eq 'username') {
7760: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7761: } elsif ($checkitem eq 'id') {
7762: $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.");
7763: }
1.612 raeburn 7764: }
7765: return $response;
1.585 raeburn 7766: }
7767:
1.624 raeburn 7768: sub personal_data_fieldtitles {
7769: my %fieldtitles = &Apache::lonlocal::texthash (
7770: id => 'Student/Employee ID',
7771: permanentemail => 'E-mail address',
7772: lastname => 'Last Name',
7773: firstname => 'First Name',
7774: middlename => 'Middle Name',
7775: generation => 'Generation',
7776: gen => 'Generation',
1.765 raeburn 7777: inststatus => 'Affiliation',
1.624 raeburn 7778: );
7779: return %fieldtitles;
7780: }
7781:
1.642 raeburn 7782: sub sorted_inst_types {
7783: my ($dom) = @_;
7784: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7785: my $othertitle = &mt('All users');
7786: if ($env{'request.course.id'}) {
1.668 raeburn 7787: $othertitle = &mt('Any users');
1.642 raeburn 7788: }
7789: my @types;
7790: if (ref($order) eq 'ARRAY') {
7791: @types = @{$order};
7792: }
7793: if (@types == 0) {
7794: if (ref($usertypes) eq 'HASH') {
7795: @types = sort(keys(%{$usertypes}));
7796: }
7797: }
7798: if (keys(%{$usertypes}) > 0) {
7799: $othertitle = &mt('Other users');
7800: }
7801: return ($othertitle,$usertypes,\@types);
7802: }
7803:
1.645 raeburn 7804: sub get_institutional_codes {
7805: my ($settings,$allcourses,$LC_code) = @_;
7806: # Get complete list of course sections to update
7807: my @currsections = ();
7808: my @currxlists = ();
7809: my $coursecode = $$settings{'internal.coursecode'};
7810:
7811: if ($$settings{'internal.sectionnums'} ne '') {
7812: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7813: }
7814:
7815: if ($$settings{'internal.crosslistings'} ne '') {
7816: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7817: }
7818:
7819: if (@currxlists > 0) {
7820: foreach (@currxlists) {
7821: if (m/^([^:]+):(\w*)$/) {
7822: unless (grep/^$1$/,@{$allcourses}) {
7823: push @{$allcourses},$1;
7824: $$LC_code{$1} = $2;
7825: }
7826: }
7827: }
7828: }
7829:
7830: if (@currsections > 0) {
7831: foreach (@currsections) {
7832: if (m/^(\w+):(\w*)$/) {
7833: my $sec = $coursecode.$1;
7834: my $lc_sec = $2;
7835: unless (grep/^$sec$/,@{$allcourses}) {
7836: push @{$allcourses},$sec;
7837: $$LC_code{$sec} = $lc_sec;
7838: }
7839: }
7840: }
7841: }
7842: return;
7843: }
7844:
1.112 bowersj2 7845: =pod
7846:
1.780 raeburn 7847: =head1 Slot Helpers
7848:
7849: =over 4
7850:
7851: =item * sorted_slots()
7852:
7853: Sorts an array of slot names in order of slot start time (earliest first).
7854:
7855: Inputs:
7856:
7857: =over 4
7858:
7859: slotsarr - Reference to array of unsorted slot names.
7860:
7861: slots - Reference to hash of hash, where outer hash keys are slot names.
7862:
1.549 albertel 7863: =back
7864:
1.780 raeburn 7865: Returns:
7866:
7867: =over 4
7868:
7869: sorted - An array of slot names sorted by the start time of the slot.
7870:
7871: =back
7872:
7873: =back
7874:
7875: =cut
7876:
7877:
7878: sub sorted_slots {
7879: my ($slotsarr,$slots) = @_;
7880: my @sorted;
7881: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7882: @sorted =
7883: sort {
7884: if (ref($slots->{$a}) && ref($slots->{$b})) {
7885: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7886: }
7887: if (ref($slots->{$a})) { return -1;}
7888: if (ref($slots->{$b})) { return 1;}
7889: return 0;
7890: } @{$slotsarr};
7891: }
7892: return @sorted;
7893: }
7894:
7895:
7896: =pod
7897:
1.549 albertel 7898: =head1 HTTP Helpers
7899:
7900: =over 4
7901:
1.648 raeburn 7902: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7903:
1.258 albertel 7904: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7905: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7906: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7907:
7908: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7909: $possible_names is an ref to an array of form element names. As an example:
7910: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7911: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7912:
7913: =cut
1.1 albertel 7914:
1.6 albertel 7915: sub get_unprocessed_cgi {
1.25 albertel 7916: my ($query,$possible_names)= @_;
1.26 matthew 7917: # $Apache::lonxml::debug=1;
1.356 albertel 7918: foreach my $pair (split(/&/,$query)) {
7919: my ($name, $value) = split(/=/,$pair);
1.369 www 7920: $name = &unescape($name);
1.25 albertel 7921: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7922: $value =~ tr/+/ /;
7923: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7924: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7925: }
1.16 harris41 7926: }
1.6 albertel 7927: }
7928:
1.112 bowersj2 7929: =pod
7930:
1.648 raeburn 7931: =item * &cacheheader()
1.112 bowersj2 7932:
7933: returns cache-controlling header code
7934:
7935: =cut
7936:
1.7 albertel 7937: sub cacheheader {
1.258 albertel 7938: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7939: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7940: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7941: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7942: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7943: return $output;
1.7 albertel 7944: }
7945:
1.112 bowersj2 7946: =pod
7947:
1.648 raeburn 7948: =item * &no_cache($r)
1.112 bowersj2 7949:
7950: specifies header code to not have cache
7951:
7952: =cut
7953:
1.9 albertel 7954: sub no_cache {
1.216 albertel 7955: my ($r) = @_;
7956: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7957: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7958: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7959: $r->no_cache(1);
7960: $r->header_out("Expires" => $date);
7961: $r->header_out("Pragma" => "no-cache");
1.123 www 7962: }
7963:
7964: sub content_type {
1.181 albertel 7965: my ($r,$type,$charset) = @_;
1.299 foxr 7966: if ($r) {
7967: # Note that printout.pl calls this with undef for $r.
7968: &no_cache($r);
7969: }
1.258 albertel 7970: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7971: unless ($charset) {
7972: $charset=&Apache::lonlocal::current_encoding;
7973: }
7974: if ($charset) { $type.='; charset='.$charset; }
7975: if ($r) {
7976: $r->content_type($type);
7977: } else {
7978: print("Content-type: $type\n\n");
7979: }
1.9 albertel 7980: }
1.25 albertel 7981:
1.112 bowersj2 7982: =pod
7983:
1.648 raeburn 7984: =item * &add_to_env($name,$value)
1.112 bowersj2 7985:
1.258 albertel 7986: adds $name to the %env hash with value
1.112 bowersj2 7987: $value, if $name already exists, the entry is converted to an array
7988: reference and $value is added to the array.
7989:
7990: =cut
7991:
1.25 albertel 7992: sub add_to_env {
7993: my ($name,$value)=@_;
1.258 albertel 7994: if (defined($env{$name})) {
7995: if (ref($env{$name})) {
1.25 albertel 7996: #already have multiple values
1.258 albertel 7997: push(@{ $env{$name} },$value);
1.25 albertel 7998: } else {
7999: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8000: my $first=$env{$name};
8001: undef($env{$name});
8002: push(@{ $env{$name} },$first,$value);
1.25 albertel 8003: }
8004: } else {
1.258 albertel 8005: $env{$name}=$value;
1.25 albertel 8006: }
1.31 albertel 8007: }
1.149 albertel 8008:
8009: =pod
8010:
1.648 raeburn 8011: =item * &get_env_multiple($name)
1.149 albertel 8012:
1.258 albertel 8013: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8014: values may be defined and end up as an array ref.
8015:
8016: returns an array of values
8017:
8018: =cut
8019:
8020: sub get_env_multiple {
8021: my ($name) = @_;
8022: my @values;
1.258 albertel 8023: if (defined($env{$name})) {
1.149 albertel 8024: # exists is it an array
1.258 albertel 8025: if (ref($env{$name})) {
8026: @values=@{ $env{$name} };
1.149 albertel 8027: } else {
1.258 albertel 8028: $values[0]=$env{$name};
1.149 albertel 8029: }
8030: }
8031: return(@values);
8032: }
8033:
1.660 raeburn 8034: sub ask_for_embedded_content {
8035: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8036: my $upload_output = '
8037: <form name="upload_embedded" action="'.$actionurl.'"
8038: method="post" enctype="multipart/form-data">';
8039: $upload_output .= $state;
1.661 raeburn 8040: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8041:
8042: my $num = 0;
8043: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8044: $upload_output .= &start_data_table_row().
8045: '<td>'.$embed_file.'</td><td>';
8046: if ($args->{'ignore_remote_references'}
8047: && $embed_file =~ m{^\w+://}) {
8048: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8049: } elsif ($args->{'error_on_invalid_names'}
8050: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8051:
8052: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8053:
8054: } else {
8055: $upload_output .='
1.661 raeburn 8056: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8057: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8058: my $attrib = join(':',@{$$allfiles{$embed_file}});
8059: $upload_output .=
8060: "\n\t\t".
8061: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8062: $attrib.'" />';
8063: if (exists($$codebase{$embed_file})) {
8064: $upload_output .=
8065: "\n\t\t".
8066: '<input name="codebase_'.$num.'" type="hidden" value="'.
8067: &escape($$codebase{$embed_file}).'" />';
8068: }
8069: }
8070: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8071: $num++;
8072: }
8073: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8074: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8075: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8076: '.&mt('(only files for which a location has been provided will be uploaded)').'
8077: </form>';
8078: return $upload_output;
8079: }
8080:
1.661 raeburn 8081: sub upload_embedded {
8082: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8083: $current_disk_usage) = @_;
8084: my $output;
8085: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8086: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8087: my $orig_uploaded_filename =
8088: $env{'form.embedded_item_'.$i.'.filename'};
8089:
8090: $env{'form.embedded_orig_'.$i} =
8091: &unescape($env{'form.embedded_orig_'.$i});
8092: my ($path,$fname) =
8093: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8094: # no path, whole string is fname
8095: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8096:
8097: $path = $env{'form.currentpath'}.$path;
8098: $fname = &Apache::lonnet::clean_filename($fname);
8099: # See if there is anything left
8100: next if ($fname eq '');
8101:
8102: # Check if file already exists as a file or directory.
8103: my ($state,$msg);
8104: if ($context eq 'portfolio') {
8105: my $port_path = $dirpath;
8106: if ($group ne '') {
8107: $port_path = "groups/$group/$port_path";
8108: }
8109: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8110: $dir_root,$port_path,$disk_quota,
8111: $current_disk_usage,$uname,$udom);
8112: if ($state eq 'will_exceed_quota'
8113: || $state eq 'file_locked'
8114: || $state eq 'file_exists' ) {
8115: $output .= $msg;
8116: next;
8117: }
8118: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8119: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8120: if ($state eq 'exists') {
8121: $output .= $msg;
8122: next;
8123: }
8124: }
8125: # Check if extension is valid
8126: if (($fname =~ /\.(\w+)$/) &&
8127: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8128: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8129: next;
8130: } elsif (($fname =~ /\.(\w+)$/) &&
8131: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8132: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8133: next;
8134: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8135: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8136: next;
8137: }
8138:
8139: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8140: if ($context eq 'portfolio') {
8141: my $result=
8142: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8143: $dirpath.$path);
8144: if ($result !~ m|^/uploaded/|) {
8145: $output .= '<span class="LC_error">'
8146: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8147: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8148: .'</span><br />';
8149: next;
8150: } else {
8151: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8152: $path.$fname.'</span>').'</p>';
8153: }
8154: } else {
8155: # Save the file
8156: my $target = $env{'form.embedded_item_'.$i};
8157: my $fullpath = $dir_root.$dirpath.'/'.$path;
8158: my $dest = $fullpath.$fname;
8159: my $url = $url_root.$dirpath.'/'.$path.$fname;
8160: my @parts=split(/\//,$fullpath);
8161: my $count;
8162: my $filepath = $dir_root;
8163: for ($count=4;$count<=$#parts;$count++) {
8164: $filepath .= "/$parts[$count]";
8165: if ((-e $filepath)!=1) {
8166: mkdir($filepath,0770);
8167: }
8168: }
8169: my $fh;
8170: if (!open($fh,'>'.$dest)) {
8171: &Apache::lonnet::logthis('Failed to create '.$dest);
8172: $output .= '<span class="LC_error">'.
8173: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8174: '</span><br />';
8175: } else {
8176: if (!print $fh $env{'form.embedded_item_'.$i}) {
8177: &Apache::lonnet::logthis('Failed to write to '.$dest);
8178: $output .= '<span class="LC_error">'.
8179: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8180: '</span><br />';
8181: } else {
8182: if ($context eq 'testbank') {
8183: $output .= &mt('Embedded file uploaded successfully:').
8184: ' <a href="'.$url.'">'.
8185: $orig_uploaded_filename.'</a><br />';
8186: } else {
1.705 tempelho 8187: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8188: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8189: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8190: }
8191: }
8192: close($fh);
8193: }
8194: }
8195: }
8196: return $output;
8197: }
8198:
8199: sub check_for_existing {
8200: my ($path,$fname,$element) = @_;
8201: my ($state,$msg);
8202: if (-d $path.'/'.$fname) {
8203: $state = 'exists';
8204: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8205: } elsif (-e $path.'/'.$fname) {
8206: $state = 'exists';
8207: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8208: }
8209: if ($state eq 'exists') {
8210: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8211: }
8212: return ($state,$msg);
8213: }
8214:
8215: sub check_for_upload {
8216: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8217: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8218: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8219: my $getpropath = 1;
8220: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8221: $getpropath);
8222: my $found_file = 0;
8223: my $locked_file = 0;
8224: foreach my $line (@dir_list) {
8225: my ($file_name)=split(/\&/,$line,2);
8226: if ($file_name eq $fname){
8227: $file_name = $path.$file_name;
8228: if ($group ne '') {
8229: $file_name = $group.$file_name;
8230: }
8231: $found_file = 1;
8232: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8233: $locked_file = 1;
8234: }
8235: }
8236: }
8237: if (($current_disk_usage + $filesize) > $disk_quota){
8238: my $msg = '<span class="LC_error">'.
8239: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8240: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8241: return ('will_exceed_quota',$msg);
8242: } elsif ($found_file) {
8243: if ($locked_file) {
8244: my $msg = '<span class="LC_error">';
8245: $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>');
8246: $msg .= '</span><br />';
8247: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8248: return ('file_locked',$msg);
8249: } else {
8250: my $msg = '<span class="LC_error">';
8251: $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'});
8252: $msg .= '</span>';
8253: $msg .= '<br />';
8254: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8255: return ('file_exists',$msg);
8256: }
8257: }
8258: }
8259:
1.31 albertel 8260:
1.41 ng 8261: =pod
1.45 matthew 8262:
1.464 albertel 8263: =back
1.41 ng 8264:
1.112 bowersj2 8265: =head1 CSV Upload/Handling functions
1.38 albertel 8266:
1.41 ng 8267: =over 4
8268:
1.648 raeburn 8269: =item * &upfile_store($r)
1.41 ng 8270:
8271: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8272: needs $env{'form.upfile'}
1.41 ng 8273: returns $datatoken to be put into hidden field
8274:
8275: =cut
1.31 albertel 8276:
8277: sub upfile_store {
8278: my $r=shift;
1.258 albertel 8279: $env{'form.upfile'}=~s/\r/\n/gs;
8280: $env{'form.upfile'}=~s/\f/\n/gs;
8281: $env{'form.upfile'}=~s/\n+/\n/gs;
8282: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8283:
1.258 albertel 8284: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8285: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8286: {
1.158 raeburn 8287: my $datafile = $r->dir_config('lonDaemons').
8288: '/tmp/'.$datatoken.'.tmp';
8289: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8290: print $fh $env{'form.upfile'};
1.158 raeburn 8291: close($fh);
8292: }
1.31 albertel 8293: }
8294: return $datatoken;
8295: }
8296:
1.56 matthew 8297: =pod
8298:
1.648 raeburn 8299: =item * &load_tmp_file($r)
1.41 ng 8300:
8301: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8302: needs $env{'form.datatoken'},
8303: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8304:
8305: =cut
1.31 albertel 8306:
8307: sub load_tmp_file {
8308: my $r=shift;
8309: my @studentdata=();
8310: {
1.158 raeburn 8311: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8312: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8313: if ( open(my $fh,"<$studentfile") ) {
8314: @studentdata=<$fh>;
8315: close($fh);
8316: }
1.31 albertel 8317: }
1.258 albertel 8318: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8319: }
8320:
1.56 matthew 8321: =pod
8322:
1.648 raeburn 8323: =item * &upfile_record_sep()
1.41 ng 8324:
8325: Separate uploaded file into records
8326: returns array of records,
1.258 albertel 8327: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8328:
8329: =cut
1.31 albertel 8330:
8331: sub upfile_record_sep {
1.258 albertel 8332: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8333: } else {
1.248 albertel 8334: my @records;
1.258 albertel 8335: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8336: if ($line=~/^\s*$/) { next; }
8337: push(@records,$line);
8338: }
8339: return @records;
1.31 albertel 8340: }
8341: }
8342:
1.56 matthew 8343: =pod
8344:
1.648 raeburn 8345: =item * &record_sep($record)
1.41 ng 8346:
1.258 albertel 8347: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8348:
8349: =cut
8350:
1.263 www 8351: sub takeleft {
8352: my $index=shift;
8353: return substr('0000'.$index,-4,4);
8354: }
8355:
1.31 albertel 8356: sub record_sep {
8357: my $record=shift;
8358: my %components=();
1.258 albertel 8359: if ($env{'form.upfiletype'} eq 'xml') {
8360: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8361: my $i=0;
1.356 albertel 8362: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8363: $field=~s/^(\"|\')//;
8364: $field=~s/(\"|\')$//;
1.263 www 8365: $components{&takeleft($i)}=$field;
1.31 albertel 8366: $i++;
8367: }
1.258 albertel 8368: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8369: my $i=0;
1.356 albertel 8370: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8371: $field=~s/^(\"|\')//;
8372: $field=~s/(\"|\')$//;
1.263 www 8373: $components{&takeleft($i)}=$field;
1.31 albertel 8374: $i++;
8375: }
8376: } else {
1.561 www 8377: my $separator=',';
1.480 banghart 8378: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8379: $separator=';';
1.480 banghart 8380: }
1.31 albertel 8381: my $i=0;
1.561 www 8382: # the character we are looking for to indicate the end of a quote or a record
8383: my $looking_for=$separator;
8384: # do not add the characters to the fields
8385: my $ignore=0;
8386: # we just encountered a separator (or the beginning of the record)
8387: my $just_found_separator=1;
8388: # store the field we are working on here
8389: my $field='';
8390: # work our way through all characters in record
8391: foreach my $character ($record=~/(.)/g) {
8392: if ($character eq $looking_for) {
8393: if ($character ne $separator) {
8394: # Found the end of a quote, again looking for separator
8395: $looking_for=$separator;
8396: $ignore=1;
8397: } else {
8398: # Found a separator, store away what we got
8399: $components{&takeleft($i)}=$field;
8400: $i++;
8401: $just_found_separator=1;
8402: $ignore=0;
8403: $field='';
8404: }
8405: next;
8406: }
8407: # single or double quotation marks after a separator indicate beginning of a quote
8408: # we are now looking for the end of the quote and need to ignore separators
8409: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8410: $looking_for=$character;
8411: next;
8412: }
8413: # ignore would be true after we reached the end of a quote
8414: if ($ignore) { next; }
8415: if (($just_found_separator) && ($character=~/\s/)) { next; }
8416: $field.=$character;
8417: $just_found_separator=0;
1.31 albertel 8418: }
1.561 www 8419: # catch the very last entry, since we never encountered the separator
8420: $components{&takeleft($i)}=$field;
1.31 albertel 8421: }
8422: return %components;
8423: }
8424:
1.144 matthew 8425: ######################################################
8426: ######################################################
8427:
1.56 matthew 8428: =pod
8429:
1.648 raeburn 8430: =item * &upfile_select_html()
1.41 ng 8431:
1.144 matthew 8432: Return HTML code to select a file from the users machine and specify
8433: the file type.
1.41 ng 8434:
8435: =cut
8436:
1.144 matthew 8437: ######################################################
8438: ######################################################
1.31 albertel 8439: sub upfile_select_html {
1.144 matthew 8440: my %Types = (
8441: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8442: semisv => &mt('Semicolon separated values'),
1.144 matthew 8443: space => &mt('Space separated'),
8444: tab => &mt('Tabulator separated'),
8445: # xml => &mt('HTML/XML'),
8446: );
8447: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8448: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8449: foreach my $type (sort(keys(%Types))) {
8450: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8451: }
8452: $Str .= "</select>\n";
8453: return $Str;
1.31 albertel 8454: }
8455:
1.301 albertel 8456: sub get_samples {
8457: my ($records,$toget) = @_;
8458: my @samples=({});
8459: my $got=0;
8460: foreach my $rec (@$records) {
8461: my %temp = &record_sep($rec);
8462: if (! grep(/\S/, values(%temp))) { next; }
8463: if (%temp) {
8464: $samples[$got]=\%temp;
8465: $got++;
8466: if ($got == $toget) { last; }
8467: }
8468: }
8469: return \@samples;
8470: }
8471:
1.144 matthew 8472: ######################################################
8473: ######################################################
8474:
1.56 matthew 8475: =pod
8476:
1.648 raeburn 8477: =item * &csv_print_samples($r,$records)
1.41 ng 8478:
8479: Prints a table of sample values from each column uploaded $r is an
8480: Apache Request ref, $records is an arrayref from
8481: &Apache::loncommon::upfile_record_sep
8482:
8483: =cut
8484:
1.144 matthew 8485: ######################################################
8486: ######################################################
1.31 albertel 8487: sub csv_print_samples {
8488: my ($r,$records) = @_;
1.662 bisitz 8489: my $samples = &get_samples($records,5);
1.301 albertel 8490:
1.594 raeburn 8491: $r->print(&mt('Samples').'<br />'.&start_data_table().
8492: &start_data_table_header_row());
1.356 albertel 8493: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8494: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8495: $r->print(&end_data_table_header_row());
1.301 albertel 8496: foreach my $hash (@$samples) {
1.594 raeburn 8497: $r->print(&start_data_table_row());
1.356 albertel 8498: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8499: $r->print('<td>');
1.356 albertel 8500: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8501: $r->print('</td>');
8502: }
1.594 raeburn 8503: $r->print(&end_data_table_row());
1.31 albertel 8504: }
1.594 raeburn 8505: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8506: }
8507:
1.144 matthew 8508: ######################################################
8509: ######################################################
8510:
1.56 matthew 8511: =pod
8512:
1.648 raeburn 8513: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8514:
8515: Prints a table to create associations between values and table columns.
1.144 matthew 8516:
1.41 ng 8517: $r is an Apache Request ref,
8518: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8519: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8520:
8521: =cut
8522:
1.144 matthew 8523: ######################################################
8524: ######################################################
1.31 albertel 8525: sub csv_print_select_table {
8526: my ($r,$records,$d) = @_;
1.301 albertel 8527: my $i=0;
8528: my $samples = &get_samples($records,1);
1.144 matthew 8529: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8530: &start_data_table().&start_data_table_header_row().
1.144 matthew 8531: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8532: '<th>'.&mt('Column').'</th>'.
8533: &end_data_table_header_row()."\n");
1.356 albertel 8534: foreach my $array_ref (@$d) {
8535: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8536: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8537:
8538: $r->print('<td><select name=f'.$i.
1.32 matthew 8539: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8540: $r->print('<option value="none"></option>');
1.356 albertel 8541: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8542: $r->print('<option value="'.$sample.'"'.
8543: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8544: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8545: }
1.594 raeburn 8546: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8547: $i++;
8548: }
1.594 raeburn 8549: $r->print(&end_data_table());
1.31 albertel 8550: $i--;
8551: return $i;
8552: }
1.56 matthew 8553:
1.144 matthew 8554: ######################################################
8555: ######################################################
8556:
1.56 matthew 8557: =pod
1.31 albertel 8558:
1.648 raeburn 8559: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8560:
8561: Prints a table of sample values from the upload and can make associate samples to internal names.
8562:
8563: $r is an Apache Request ref,
8564: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8565: $d is an array of 2 element arrays (internal name, displayed name)
8566:
8567: =cut
8568:
1.144 matthew 8569: ######################################################
8570: ######################################################
1.31 albertel 8571: sub csv_samples_select_table {
8572: my ($r,$records,$d) = @_;
8573: my $i=0;
1.144 matthew 8574: #
1.662 bisitz 8575: my $max_samples = 5;
8576: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8577: $r->print(&start_data_table().
8578: &start_data_table_header_row().'<th>'.
8579: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8580: &end_data_table_header_row());
1.301 albertel 8581:
8582: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8583: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8584: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8585: foreach my $option (@$d) {
8586: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8587: $r->print('<option value="'.$value.'"'.
1.253 albertel 8588: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8589: $display.'</option>');
1.31 albertel 8590: }
8591: $r->print('</select></td><td>');
1.662 bisitz 8592: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8593: if (defined($samples->[$line]{$key})) {
8594: $r->print($samples->[$line]{$key}."<br />\n");
8595: }
8596: }
1.594 raeburn 8597: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8598: $i++;
8599: }
1.594 raeburn 8600: $r->print(&end_data_table());
1.31 albertel 8601: $i--;
8602: return($i);
1.115 matthew 8603: }
8604:
1.144 matthew 8605: ######################################################
8606: ######################################################
8607:
1.115 matthew 8608: =pod
8609:
1.648 raeburn 8610: =item * &clean_excel_name($name)
1.115 matthew 8611:
8612: Returns a replacement for $name which does not contain any illegal characters.
8613:
8614: =cut
8615:
1.144 matthew 8616: ######################################################
8617: ######################################################
1.115 matthew 8618: sub clean_excel_name {
8619: my ($name) = @_;
8620: $name =~ s/[:\*\?\/\\]//g;
8621: if (length($name) > 31) {
8622: $name = substr($name,0,31);
8623: }
8624: return $name;
1.25 albertel 8625: }
1.84 albertel 8626:
1.85 albertel 8627: =pod
8628:
1.648 raeburn 8629: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8630:
8631: Returns either 1 or undef
8632:
8633: 1 if the part is to be hidden, undef if it is to be shown
8634:
8635: Arguments are:
8636:
8637: $id the id of the part to be checked
8638: $symb, optional the symb of the resource to check
8639: $udom, optional the domain of the user to check for
8640: $uname, optional the username of the user to check for
8641:
8642: =cut
1.84 albertel 8643:
8644: sub check_if_partid_hidden {
8645: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8646: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8647: $symb,$udom,$uname);
1.141 albertel 8648: my $truth=1;
8649: #if the string starts with !, then the list is the list to show not hide
8650: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8651: my @hiddenlist=split(/,/,$hiddenparts);
8652: foreach my $checkid (@hiddenlist) {
1.141 albertel 8653: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8654: }
1.141 albertel 8655: return !$truth;
1.84 albertel 8656: }
1.127 matthew 8657:
1.138 matthew 8658:
8659: ############################################################
8660: ############################################################
8661:
8662: =pod
8663:
1.157 matthew 8664: =back
8665:
1.138 matthew 8666: =head1 cgi-bin script and graphing routines
8667:
1.157 matthew 8668: =over 4
8669:
1.648 raeburn 8670: =item * &get_cgi_id()
1.138 matthew 8671:
8672: Inputs: none
8673:
8674: Returns an id which can be used to pass environment variables
8675: to various cgi-bin scripts. These environment variables will
8676: be removed from the users environment after a given time by
8677: the routine &Apache::lonnet::transfer_profile_to_env.
8678:
8679: =cut
8680:
8681: ############################################################
8682: ############################################################
1.152 albertel 8683: my $uniq=0;
1.136 matthew 8684: sub get_cgi_id {
1.154 albertel 8685: $uniq=($uniq+1)%100000;
1.280 albertel 8686: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8687: }
8688:
1.127 matthew 8689: ############################################################
8690: ############################################################
8691:
8692: =pod
8693:
1.648 raeburn 8694: =item * &DrawBarGraph()
1.127 matthew 8695:
1.138 matthew 8696: Facilitates the plotting of data in a (stacked) bar graph.
8697: Puts plot definition data into the users environment in order for
8698: graph.png to plot it. Returns an <img> tag for the plot.
8699: The bars on the plot are labeled '1','2',...,'n'.
8700:
8701: Inputs:
8702:
8703: =over 4
8704:
8705: =item $Title: string, the title of the plot
8706:
8707: =item $xlabel: string, text describing the X-axis of the plot
8708:
8709: =item $ylabel: string, text describing the Y-axis of the plot
8710:
8711: =item $Max: scalar, the maximum Y value to use in the plot
8712: If $Max is < any data point, the graph will not be rendered.
8713:
1.140 matthew 8714: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8715: they are plotted. If undefined, default values will be used.
8716:
1.178 matthew 8717: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8718:
1.138 matthew 8719: =item @Values: An array of array references. Each array reference holds data
8720: to be plotted in a stacked bar chart.
8721:
1.239 matthew 8722: =item If the final element of @Values is a hash reference the key/value
8723: pairs will be added to the graph definition.
8724:
1.138 matthew 8725: =back
8726:
8727: Returns:
8728:
8729: An <img> tag which references graph.png and the appropriate identifying
8730: information for the plot.
8731:
1.127 matthew 8732: =cut
8733:
8734: ############################################################
8735: ############################################################
1.134 matthew 8736: sub DrawBarGraph {
1.178 matthew 8737: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8738: #
8739: if (! defined($colors)) {
8740: $colors = ['#33ff00',
8741: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8742: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8743: ];
8744: }
1.228 matthew 8745: my $extra_settings = {};
8746: if (ref($Values[-1]) eq 'HASH') {
8747: $extra_settings = pop(@Values);
8748: }
1.127 matthew 8749: #
1.136 matthew 8750: my $identifier = &get_cgi_id();
8751: my $id = 'cgi.'.$identifier;
1.129 matthew 8752: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8753: return '';
8754: }
1.225 matthew 8755: #
8756: my @Labels;
8757: if (defined($labels)) {
8758: @Labels = @$labels;
8759: } else {
8760: for (my $i=0;$i<@{$Values[0]};$i++) {
8761: push (@Labels,$i+1);
8762: }
8763: }
8764: #
1.129 matthew 8765: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8766: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8767: my %ValuesHash;
8768: my $NumSets=1;
8769: foreach my $array (@Values) {
8770: next if (! ref($array));
1.136 matthew 8771: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8772: join(',',@$array);
1.129 matthew 8773: }
1.127 matthew 8774: #
1.136 matthew 8775: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8776: if ($NumBars < 3) {
8777: $width = 120+$NumBars*32;
1.220 matthew 8778: $xskip = 1;
1.225 matthew 8779: $bar_width = 30;
8780: } elsif ($NumBars < 5) {
8781: $width = 120+$NumBars*20;
8782: $xskip = 1;
8783: $bar_width = 20;
1.220 matthew 8784: } elsif ($NumBars < 10) {
1.136 matthew 8785: $width = 120+$NumBars*15;
8786: $xskip = 1;
8787: $bar_width = 15;
8788: } elsif ($NumBars <= 25) {
8789: $width = 120+$NumBars*11;
8790: $xskip = 5;
8791: $bar_width = 8;
8792: } elsif ($NumBars <= 50) {
8793: $width = 120+$NumBars*8;
8794: $xskip = 5;
8795: $bar_width = 4;
8796: } else {
8797: $width = 120+$NumBars*8;
8798: $xskip = 5;
8799: $bar_width = 4;
8800: }
8801: #
1.137 matthew 8802: $Max = 1 if ($Max < 1);
8803: if ( int($Max) < $Max ) {
8804: $Max++;
8805: $Max = int($Max);
8806: }
1.127 matthew 8807: $Title = '' if (! defined($Title));
8808: $xlabel = '' if (! defined($xlabel));
8809: $ylabel = '' if (! defined($ylabel));
1.369 www 8810: $ValuesHash{$id.'.title'} = &escape($Title);
8811: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8812: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8813: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8814: $ValuesHash{$id.'.NumBars'} = $NumBars;
8815: $ValuesHash{$id.'.NumSets'} = $NumSets;
8816: $ValuesHash{$id.'.PlotType'} = 'bar';
8817: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8818: $ValuesHash{$id.'.height'} = $height;
8819: $ValuesHash{$id.'.width'} = $width;
8820: $ValuesHash{$id.'.xskip'} = $xskip;
8821: $ValuesHash{$id.'.bar_width'} = $bar_width;
8822: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8823: #
1.228 matthew 8824: # Deal with other parameters
8825: while (my ($key,$value) = each(%$extra_settings)) {
8826: $ValuesHash{$id.'.'.$key} = $value;
8827: }
8828: #
1.646 raeburn 8829: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8830: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8831: }
8832:
8833: ############################################################
8834: ############################################################
8835:
8836: =pod
8837:
1.648 raeburn 8838: =item * &DrawXYGraph()
1.137 matthew 8839:
1.138 matthew 8840: Facilitates the plotting of data in an XY graph.
8841: Puts plot definition data into the users environment in order for
8842: graph.png to plot it. Returns an <img> tag for the plot.
8843:
8844: Inputs:
8845:
8846: =over 4
8847:
8848: =item $Title: string, the title of the plot
8849:
8850: =item $xlabel: string, text describing the X-axis of the plot
8851:
8852: =item $ylabel: string, text describing the Y-axis of the plot
8853:
8854: =item $Max: scalar, the maximum Y value to use in the plot
8855: If $Max is < any data point, the graph will not be rendered.
8856:
8857: =item $colors: Array ref containing the hex color codes for the data to be
8858: plotted in. If undefined, default values will be used.
8859:
8860: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8861:
8862: =item $Ydata: Array ref containing Array refs.
1.185 www 8863: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8864:
8865: =item %Values: hash indicating or overriding any default values which are
8866: passed to graph.png.
8867: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8868:
8869: =back
8870:
8871: Returns:
8872:
8873: An <img> tag which references graph.png and the appropriate identifying
8874: information for the plot.
8875:
1.137 matthew 8876: =cut
8877:
8878: ############################################################
8879: ############################################################
8880: sub DrawXYGraph {
8881: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8882: #
8883: # Create the identifier for the graph
8884: my $identifier = &get_cgi_id();
8885: my $id = 'cgi.'.$identifier;
8886: #
8887: $Title = '' if (! defined($Title));
8888: $xlabel = '' if (! defined($xlabel));
8889: $ylabel = '' if (! defined($ylabel));
8890: my %ValuesHash =
8891: (
1.369 www 8892: $id.'.title' => &escape($Title),
8893: $id.'.xlabel' => &escape($xlabel),
8894: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8895: $id.'.y_max_value'=> $Max,
8896: $id.'.labels' => join(',',@$Xlabels),
8897: $id.'.PlotType' => 'XY',
8898: );
8899: #
8900: if (defined($colors) && ref($colors) eq 'ARRAY') {
8901: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8902: }
8903: #
8904: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8905: return '';
8906: }
8907: my $NumSets=1;
1.138 matthew 8908: foreach my $array (@{$Ydata}){
1.137 matthew 8909: next if (! ref($array));
8910: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8911: }
1.138 matthew 8912: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8913: #
8914: # Deal with other parameters
8915: while (my ($key,$value) = each(%Values)) {
8916: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8917: }
8918: #
1.646 raeburn 8919: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8920: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8921: }
8922:
8923: ############################################################
8924: ############################################################
8925:
8926: =pod
8927:
1.648 raeburn 8928: =item * &DrawXYYGraph()
1.138 matthew 8929:
8930: Facilitates the plotting of data in an XY graph with two Y axes.
8931: Puts plot definition data into the users environment in order for
8932: graph.png to plot it. Returns an <img> tag for the plot.
8933:
8934: Inputs:
8935:
8936: =over 4
8937:
8938: =item $Title: string, the title of the plot
8939:
8940: =item $xlabel: string, text describing the X-axis of the plot
8941:
8942: =item $ylabel: string, text describing the Y-axis of the plot
8943:
8944: =item $colors: Array ref containing the hex color codes for the data to be
8945: plotted in. If undefined, default values will be used.
8946:
8947: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8948:
8949: =item $Ydata1: The first data set
8950:
8951: =item $Min1: The minimum value of the left Y-axis
8952:
8953: =item $Max1: The maximum value of the left Y-axis
8954:
8955: =item $Ydata2: The second data set
8956:
8957: =item $Min2: The minimum value of the right Y-axis
8958:
8959: =item $Max2: The maximum value of the left Y-axis
8960:
8961: =item %Values: hash indicating or overriding any default values which are
8962: passed to graph.png.
8963: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8964:
8965: =back
8966:
8967: Returns:
8968:
8969: An <img> tag which references graph.png and the appropriate identifying
8970: information for the plot.
1.136 matthew 8971:
8972: =cut
8973:
8974: ############################################################
8975: ############################################################
1.137 matthew 8976: sub DrawXYYGraph {
8977: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8978: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8979: #
8980: # Create the identifier for the graph
8981: my $identifier = &get_cgi_id();
8982: my $id = 'cgi.'.$identifier;
8983: #
8984: $Title = '' if (! defined($Title));
8985: $xlabel = '' if (! defined($xlabel));
8986: $ylabel = '' if (! defined($ylabel));
8987: my %ValuesHash =
8988: (
1.369 www 8989: $id.'.title' => &escape($Title),
8990: $id.'.xlabel' => &escape($xlabel),
8991: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8992: $id.'.labels' => join(',',@$Xlabels),
8993: $id.'.PlotType' => 'XY',
8994: $id.'.NumSets' => 2,
1.137 matthew 8995: $id.'.two_axes' => 1,
8996: $id.'.y1_max_value' => $Max1,
8997: $id.'.y1_min_value' => $Min1,
8998: $id.'.y2_max_value' => $Max2,
8999: $id.'.y2_min_value' => $Min2,
1.136 matthew 9000: );
9001: #
1.137 matthew 9002: if (defined($colors) && ref($colors) eq 'ARRAY') {
9003: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9004: }
9005: #
9006: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9007: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9008: return '';
9009: }
9010: my $NumSets=1;
1.137 matthew 9011: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9012: next if (! ref($array));
9013: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9014: }
9015: #
9016: # Deal with other parameters
9017: while (my ($key,$value) = each(%Values)) {
9018: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9019: }
9020: #
1.646 raeburn 9021: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9022: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9023: }
9024:
9025: ############################################################
9026: ############################################################
9027:
9028: =pod
9029:
1.157 matthew 9030: =back
9031:
1.139 matthew 9032: =head1 Statistics helper routines?
9033:
9034: Bad place for them but what the hell.
9035:
1.157 matthew 9036: =over 4
9037:
1.648 raeburn 9038: =item * &chartlink()
1.139 matthew 9039:
9040: Returns a link to the chart for a specific student.
9041:
9042: Inputs:
9043:
9044: =over 4
9045:
9046: =item $linktext: The text of the link
9047:
9048: =item $sname: The students username
9049:
9050: =item $sdomain: The students domain
9051:
9052: =back
9053:
1.157 matthew 9054: =back
9055:
1.139 matthew 9056: =cut
9057:
9058: ############################################################
9059: ############################################################
9060: sub chartlink {
9061: my ($linktext, $sname, $sdomain) = @_;
9062: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9063: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9064: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9065: '">'.$linktext.'</a>';
1.153 matthew 9066: }
9067:
9068: #######################################################
9069: #######################################################
9070:
9071: =pod
9072:
9073: =head1 Course Environment Routines
1.157 matthew 9074:
9075: =over 4
1.153 matthew 9076:
1.648 raeburn 9077: =item * &restore_course_settings()
1.153 matthew 9078:
1.648 raeburn 9079: =item * &store_course_settings()
1.153 matthew 9080:
9081: Restores/Store indicated form parameters from the course environment.
9082: Will not overwrite existing values of the form parameters.
9083:
9084: Inputs:
9085: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9086:
9087: a hash ref describing the data to be stored. For example:
9088:
9089: %Save_Parameters = ('Status' => 'scalar',
9090: 'chartoutputmode' => 'scalar',
9091: 'chartoutputdata' => 'scalar',
9092: 'Section' => 'array',
1.373 raeburn 9093: 'Group' => 'array',
1.153 matthew 9094: 'StudentData' => 'array',
9095: 'Maps' => 'array');
9096:
9097: Returns: both routines return nothing
9098:
1.631 raeburn 9099: =back
9100:
1.153 matthew 9101: =cut
9102:
9103: #######################################################
9104: #######################################################
9105: sub store_course_settings {
1.496 albertel 9106: return &store_settings($env{'request.course.id'},@_);
9107: }
9108:
9109: sub store_settings {
1.153 matthew 9110: # save to the environment
9111: # appenv the same items, just to be safe
1.300 albertel 9112: my $udom = $env{'user.domain'};
9113: my $uname = $env{'user.name'};
1.496 albertel 9114: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9115: my %SaveHash;
9116: my %AppHash;
9117: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9118: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9119: my $envname = 'environment.'.$basename;
1.258 albertel 9120: if (exists($env{'form.'.$setting})) {
1.153 matthew 9121: # Save this value away
9122: if ($type eq 'scalar' &&
1.258 albertel 9123: (! exists($env{$envname}) ||
9124: $env{$envname} ne $env{'form.'.$setting})) {
9125: $SaveHash{$basename} = $env{'form.'.$setting};
9126: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9127: } elsif ($type eq 'array') {
9128: my $stored_form;
1.258 albertel 9129: if (ref($env{'form.'.$setting})) {
1.153 matthew 9130: $stored_form = join(',',
9131: map {
1.369 www 9132: &escape($_);
1.258 albertel 9133: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9134: } else {
9135: $stored_form =
1.369 www 9136: &escape($env{'form.'.$setting});
1.153 matthew 9137: }
9138: # Determine if the array contents are the same.
1.258 albertel 9139: if ($stored_form ne $env{$envname}) {
1.153 matthew 9140: $SaveHash{$basename} = $stored_form;
9141: $AppHash{$envname} = $stored_form;
9142: }
9143: }
9144: }
9145: }
9146: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9147: $udom,$uname);
1.153 matthew 9148: if ($put_result !~ /^(ok|delayed)/) {
9149: &Apache::lonnet::logthis('unable to save form parameters, '.
9150: 'got error:'.$put_result);
9151: }
9152: # Make sure these settings stick around in this session, too
1.646 raeburn 9153: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9154: return;
9155: }
9156:
9157: sub restore_course_settings {
1.499 albertel 9158: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9159: }
9160:
9161: sub restore_settings {
9162: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9163: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9164: next if (exists($env{'form.'.$setting}));
1.496 albertel 9165: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9166: '.'.$setting;
1.258 albertel 9167: if (exists($env{$envname})) {
1.153 matthew 9168: if ($type eq 'scalar') {
1.258 albertel 9169: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9170: } elsif ($type eq 'array') {
1.258 albertel 9171: $env{'form.'.$setting} = [
1.153 matthew 9172: map {
1.369 www 9173: &unescape($_);
1.258 albertel 9174: } split(',',$env{$envname})
1.153 matthew 9175: ];
9176: }
9177: }
9178: }
1.127 matthew 9179: }
9180:
1.618 raeburn 9181: #######################################################
9182: #######################################################
9183:
9184: =pod
9185:
9186: =head1 Domain E-mail Routines
9187:
9188: =over 4
9189:
1.648 raeburn 9190: =item * &build_recipient_list()
1.618 raeburn 9191:
1.766 raeburn 9192: Build recipient lists for four types of e-mail:
9193: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9194: (d) Help requests, generated by
9195: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9196:
9197: Inputs:
1.619 raeburn 9198: defmail (scalar - email address of default recipient),
1.618 raeburn 9199: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9200: defdom (domain for which to retrieve configuration settings),
9201: origmail (scalar - email address of recipient from loncapa.conf,
9202: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9203:
1.655 raeburn 9204: Returns: comma separated list of addresses to which to send e-mail.
9205:
9206: =back
1.618 raeburn 9207:
9208: =cut
9209:
9210: ############################################################
9211: ############################################################
9212: sub build_recipient_list {
1.619 raeburn 9213: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9214: my @recipients;
9215: my $otheremails;
9216: my %domconfig =
9217: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9218: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9219: if (exists($domconfig{'contacts'}{$mailing})) {
9220: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9221: my @contacts = ('adminemail','supportemail');
9222: foreach my $item (@contacts) {
9223: if ($domconfig{'contacts'}{$mailing}{$item}) {
9224: my $addr = $domconfig{'contacts'}{$item};
9225: if (!grep(/^\Q$addr\E$/,@recipients)) {
9226: push(@recipients,$addr);
9227: }
1.619 raeburn 9228: }
1.766 raeburn 9229: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9230: }
9231: }
1.766 raeburn 9232: } elsif ($origmail ne '') {
9233: push(@recipients,$origmail);
1.618 raeburn 9234: }
1.619 raeburn 9235: } elsif ($origmail ne '') {
9236: push(@recipients,$origmail);
1.618 raeburn 9237: }
1.688 raeburn 9238: if (defined($defmail)) {
9239: if ($defmail ne '') {
9240: push(@recipients,$defmail);
9241: }
1.618 raeburn 9242: }
9243: if ($otheremails) {
1.619 raeburn 9244: my @others;
9245: if ($otheremails =~ /,/) {
9246: @others = split(/,/,$otheremails);
1.618 raeburn 9247: } else {
1.619 raeburn 9248: push(@others,$otheremails);
9249: }
9250: foreach my $addr (@others) {
9251: if (!grep(/^\Q$addr\E$/,@recipients)) {
9252: push(@recipients,$addr);
9253: }
1.618 raeburn 9254: }
9255: }
1.619 raeburn 9256: my $recipientlist = join(',',@recipients);
1.618 raeburn 9257: return $recipientlist;
9258: }
9259:
1.127 matthew 9260: ############################################################
9261: ############################################################
1.154 albertel 9262:
1.655 raeburn 9263: =pod
9264:
9265: =head1 Course Catalog Routines
9266:
9267: =over 4
9268:
9269: =item * &gather_categories()
9270:
9271: Converts category definitions - keys of categories hash stored in
9272: coursecategories in configuration.db on the primary library server in a
9273: domain - to an array. Also generates javascript and idx hash used to
9274: generate Domain Coordinator interface for editing Course Categories.
9275:
9276: Inputs:
1.663 raeburn 9277:
1.655 raeburn 9278: categories (reference to hash of category definitions).
1.663 raeburn 9279:
1.655 raeburn 9280: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9281: categories and subcategories).
1.663 raeburn 9282:
1.655 raeburn 9283: idx (reference to hash of counters used in Domain Coordinator interface for
9284: editing Course Categories).
1.663 raeburn 9285:
1.655 raeburn 9286: jsarray (reference to array of categories used to create Javascript arrays for
9287: Domain Coordinator interface for editing Course Categories).
9288:
9289: Returns: nothing
9290:
9291: Side effects: populates cats, idx and jsarray.
9292:
9293: =cut
9294:
9295: sub gather_categories {
9296: my ($categories,$cats,$idx,$jsarray) = @_;
9297: my %counters;
9298: my $num = 0;
9299: foreach my $item (keys(%{$categories})) {
9300: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9301: if ($container eq '' && $depth == 0) {
9302: $cats->[$depth][$categories->{$item}] = $cat;
9303: } else {
9304: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9305: }
9306: my ($escitem,$tail) = split(/:/,$item,2);
9307: if ($counters{$tail} eq '') {
9308: $counters{$tail} = $num;
9309: $num ++;
9310: }
9311: if (ref($idx) eq 'HASH') {
9312: $idx->{$item} = $counters{$tail};
9313: }
9314: if (ref($jsarray) eq 'ARRAY') {
9315: push(@{$jsarray->[$counters{$tail}]},$item);
9316: }
9317: }
9318: return;
9319: }
9320:
9321: =pod
9322:
9323: =item * &extract_categories()
9324:
9325: Used to generate breadcrumb trails for course categories.
9326:
9327: Inputs:
1.663 raeburn 9328:
1.655 raeburn 9329: categories (reference to hash of category definitions).
1.663 raeburn 9330:
1.655 raeburn 9331: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9332: categories and subcategories).
1.663 raeburn 9333:
1.655 raeburn 9334: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9335:
1.655 raeburn 9336: allitems (reference to hash - key is category key
9337: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9338:
1.655 raeburn 9339: idx (reference to hash of counters used in Domain Coordinator interface for
9340: editing Course Categories).
1.663 raeburn 9341:
1.655 raeburn 9342: jsarray (reference to array of categories used to create Javascript arrays for
9343: Domain Coordinator interface for editing Course Categories).
9344:
1.665 raeburn 9345: subcats (reference to hash of arrays containing all subcategories within each
9346: category, -recursive)
9347:
1.655 raeburn 9348: Returns: nothing
9349:
9350: Side effects: populates trails and allitems hash references.
9351:
9352: =cut
9353:
9354: sub extract_categories {
1.665 raeburn 9355: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9356: if (ref($categories) eq 'HASH') {
9357: &gather_categories($categories,$cats,$idx,$jsarray);
9358: if (ref($cats->[0]) eq 'ARRAY') {
9359: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9360: my $name = $cats->[0][$i];
9361: my $item = &escape($name).'::0';
9362: my $trailstr;
9363: if ($name eq 'instcode') {
9364: $trailstr = &mt('Official courses (with institutional codes)');
9365: } else {
9366: $trailstr = $name;
9367: }
9368: if ($allitems->{$item} eq '') {
9369: push(@{$trails},$trailstr);
9370: $allitems->{$item} = scalar(@{$trails})-1;
9371: }
9372: my @parents = ($name);
9373: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9374: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9375: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9376: if (ref($subcats) eq 'HASH') {
9377: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9378: }
9379: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9380: }
9381: } else {
9382: if (ref($subcats) eq 'HASH') {
9383: $subcats->{$item} = [];
1.655 raeburn 9384: }
9385: }
9386: }
9387: }
9388: }
9389: return;
9390: }
9391:
9392: =pod
9393:
9394: =item *&recurse_categories()
9395:
9396: Recursively used to generate breadcrumb trails for course categories.
9397:
9398: Inputs:
1.663 raeburn 9399:
1.655 raeburn 9400: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9401: categories and subcategories).
1.663 raeburn 9402:
1.655 raeburn 9403: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9404:
9405: category (current course category, for which breadcrumb trail is being generated).
9406:
9407: trails (reference to array of breadcrumb trails for each category).
9408:
1.655 raeburn 9409: allitems (reference to hash - key is category key
9410: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9411:
1.655 raeburn 9412: parents (array containing containers directories for current category,
9413: back to top level).
9414:
9415: Returns: nothing
9416:
9417: Side effects: populates trails and allitems hash references
9418:
9419: =cut
9420:
9421: sub recurse_categories {
1.665 raeburn 9422: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9423: my $shallower = $depth - 1;
9424: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9425: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9426: my $name = $cats->[$depth]{$category}[$k];
9427: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9428: my $trailstr = join(' -> ',(@{$parents},$category));
9429: if ($allitems->{$item} eq '') {
9430: push(@{$trails},$trailstr);
9431: $allitems->{$item} = scalar(@{$trails})-1;
9432: }
9433: my $deeper = $depth+1;
9434: push(@{$parents},$category);
1.665 raeburn 9435: if (ref($subcats) eq 'HASH') {
9436: my $subcat = &escape($name).':'.$category.':'.$depth;
9437: for (my $j=@{$parents}; $j>=0; $j--) {
9438: my $higher;
9439: if ($j > 0) {
9440: $higher = &escape($parents->[$j]).':'.
9441: &escape($parents->[$j-1]).':'.$j;
9442: } else {
9443: $higher = &escape($parents->[$j]).'::'.$j;
9444: }
9445: push(@{$subcats->{$higher}},$subcat);
9446: }
9447: }
9448: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9449: $subcats);
1.655 raeburn 9450: pop(@{$parents});
9451: }
9452: } else {
9453: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9454: my $trailstr = join(' -> ',(@{$parents},$category));
9455: if ($allitems->{$item} eq '') {
9456: push(@{$trails},$trailstr);
9457: $allitems->{$item} = scalar(@{$trails})-1;
9458: }
9459: }
9460: return;
9461: }
9462:
1.663 raeburn 9463: =pod
9464:
9465: =item *&assign_categories_table()
9466:
9467: Create a datatable for display of hierarchical categories in a domain,
9468: with checkboxes to allow a course to be categorized.
9469:
9470: Inputs:
9471:
9472: cathash - reference to hash of categories defined for the domain (from
9473: configuration.db)
9474:
9475: currcat - scalar with an & separated list of categories assigned to a course.
9476:
9477: Returns: $output (markup to be displayed)
9478:
9479: =cut
9480:
9481: sub assign_categories_table {
9482: my ($cathash,$currcat) = @_;
9483: my $output;
9484: if (ref($cathash) eq 'HASH') {
9485: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9486: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9487: $maxdepth = scalar(@cats);
9488: if (@cats > 0) {
9489: my $itemcount = 0;
9490: if (ref($cats[0]) eq 'ARRAY') {
9491: $output = &Apache::loncommon::start_data_table();
9492: my @currcategories;
9493: if ($currcat ne '') {
9494: @currcategories = split('&',$currcat);
9495: }
9496: for (my $i=0; $i<@{$cats[0]}; $i++) {
9497: my $parent = $cats[0][$i];
9498: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9499: next if ($parent eq 'instcode');
9500: my $item = &escape($parent).'::0';
9501: my $checked = '';
9502: if (@currcategories > 0) {
9503: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9504: $checked = ' checked="checked"';
1.663 raeburn 9505: }
9506: }
1.675 raeburn 9507: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9508: '<input type="checkbox" name="usecategory" value="'.
9509: $item.'"'.$checked.' />'.$parent.'</span>'.
9510: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9511: my $depth = 1;
9512: push(@path,$parent);
9513: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9514: pop(@path);
9515: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9516: $itemcount ++;
9517: }
9518: $output .= &Apache::loncommon::end_data_table();
9519: }
9520: }
9521: }
9522: return $output;
9523: }
9524:
9525: =pod
9526:
9527: =item *&assign_category_rows()
9528:
9529: Create a datatable row for display of nested categories in a domain,
9530: with checkboxes to allow a course to be categorized,called recursively.
9531:
9532: Inputs:
9533:
9534: itemcount - track row number for alternating colors
9535:
9536: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9537: categories and subcategories.
9538:
9539: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9540:
9541: parent - parent of current category item
9542:
9543: path - Array containing all categories back up through the hierarchy from the
9544: current category to the top level.
9545:
9546: currcategories - reference to array of current categories assigned to the course
9547:
9548: Returns: $output (markup to be displayed).
9549:
9550: =cut
9551:
9552: sub assign_category_rows {
9553: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9554: my ($text,$name,$item,$chgstr);
9555: if (ref($cats) eq 'ARRAY') {
9556: my $maxdepth = scalar(@{$cats});
9557: if (ref($cats->[$depth]) eq 'HASH') {
9558: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9559: my $numchildren = @{$cats->[$depth]{$parent}};
9560: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9561: $text .= '<td><table class="LC_datatable">';
9562: for (my $j=0; $j<$numchildren; $j++) {
9563: $name = $cats->[$depth]{$parent}[$j];
9564: $item = &escape($name).':'.&escape($parent).':'.$depth;
9565: my $deeper = $depth+1;
9566: my $checked = '';
9567: if (ref($currcategories) eq 'ARRAY') {
9568: if (@{$currcategories} > 0) {
9569: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9570: $checked = ' checked="checked"';
1.663 raeburn 9571: }
9572: }
9573: }
1.664 raeburn 9574: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9575: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9576: $item.'"'.$checked.' />'.$name.'</label></span>'.
9577: '<input type="hidden" name="catname" value="'.$name.'" />'.
9578: '</td><td>';
1.663 raeburn 9579: if (ref($path) eq 'ARRAY') {
9580: push(@{$path},$name);
9581: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9582: pop(@{$path});
9583: }
9584: $text .= '</td></tr>';
9585: }
9586: $text .= '</table></td>';
9587: }
9588: }
9589: }
9590: return $text;
9591: }
9592:
1.655 raeburn 9593: ############################################################
9594: ############################################################
9595:
9596:
1.443 albertel 9597: sub commit_customrole {
1.664 raeburn 9598: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9599: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9600: ($start?', '.&mt('starting').' '.localtime($start):'').
9601: ($end?', ending '.localtime($end):'').': <b>'.
9602: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9603: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9604: '</b><br />';
9605: return $output;
9606: }
9607:
9608: sub commit_standardrole {
1.541 raeburn 9609: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9610: my ($output,$logmsg,$linefeed);
9611: if ($context eq 'auto') {
9612: $linefeed = "\n";
9613: } else {
9614: $linefeed = "<br />\n";
9615: }
1.443 albertel 9616: if ($three eq 'st') {
1.541 raeburn 9617: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9618: $one,$two,$sec,$context);
9619: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9620: ($result eq 'unknown_course') || ($result eq 'refused')) {
9621: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9622: } else {
1.541 raeburn 9623: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9624: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9625: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9626: if ($context eq 'auto') {
9627: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9628: } else {
9629: $output .= '<b>'.$result.'</b>'.$linefeed.
9630: &mt('Add to classlist').': <b>ok</b>';
9631: }
9632: $output .= $linefeed;
1.443 albertel 9633: }
9634: } else {
9635: $output = &mt('Assigning').' '.$three.' in '.$url.
9636: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9637: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9638: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9639: if ($context eq 'auto') {
9640: $output .= $result.$linefeed;
9641: } else {
9642: $output .= '<b>'.$result.'</b>'.$linefeed;
9643: }
1.443 albertel 9644: }
9645: return $output;
9646: }
9647:
9648: sub commit_studentrole {
1.541 raeburn 9649: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9650: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9651: if ($context eq 'auto') {
9652: $linefeed = "\n";
9653: } else {
9654: $linefeed = '<br />'."\n";
9655: }
1.443 albertel 9656: if (defined($one) && defined($two)) {
9657: my $cid=$one.'_'.$two;
9658: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9659: my $secchange = 0;
9660: my $expire_role_result;
9661: my $modify_section_result;
1.628 raeburn 9662: if ($oldsec ne '-1') {
9663: if ($oldsec ne $sec) {
1.443 albertel 9664: $secchange = 1;
1.628 raeburn 9665: my $now = time;
1.443 albertel 9666: my $uurl='/'.$cid;
9667: $uurl=~s/\_/\//g;
9668: if ($oldsec) {
9669: $uurl.='/'.$oldsec;
9670: }
1.626 raeburn 9671: $oldsecurl = $uurl;
1.628 raeburn 9672: $expire_role_result =
1.652 raeburn 9673: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9674: if ($env{'request.course.sec'} ne '') {
9675: if ($expire_role_result eq 'refused') {
9676: my @roles = ('st');
9677: my @statuses = ('previous');
9678: my @roledoms = ($one);
9679: my $withsec = 1;
9680: my %roleshash =
9681: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9682: \@statuses,\@roles,\@roledoms,$withsec);
9683: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9684: my ($oldstart,$oldend) =
9685: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9686: if ($oldend > 0 && $oldend <= $now) {
9687: $expire_role_result = 'ok';
9688: }
9689: }
9690: }
9691: }
1.443 albertel 9692: $result = $expire_role_result;
9693: }
9694: }
9695: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9696: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9697: if ($modify_section_result =~ /^ok/) {
9698: if ($secchange == 1) {
1.628 raeburn 9699: if ($sec eq '') {
9700: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9701: } else {
9702: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9703: }
1.443 albertel 9704: } elsif ($oldsec eq '-1') {
1.628 raeburn 9705: if ($sec eq '') {
9706: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9707: } else {
9708: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9709: }
1.443 albertel 9710: } else {
1.628 raeburn 9711: if ($sec eq '') {
9712: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9713: } else {
9714: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9715: }
1.443 albertel 9716: }
9717: } else {
1.628 raeburn 9718: if ($secchange) {
9719: $$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;
9720: } else {
9721: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9722: }
1.443 albertel 9723: }
9724: $result = $modify_section_result;
9725: } elsif ($secchange == 1) {
1.628 raeburn 9726: if ($oldsec eq '') {
9727: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9728: } else {
9729: $$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;
9730: }
1.626 raeburn 9731: if ($expire_role_result eq 'refused') {
9732: my $newsecurl = '/'.$cid;
9733: $newsecurl =~ s/\_/\//g;
9734: if ($sec ne '') {
9735: $newsecurl.='/'.$sec;
9736: }
9737: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9738: if ($sec eq '') {
9739: $$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;
9740: } else {
9741: $$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;
9742: }
9743: }
9744: }
1.443 albertel 9745: }
9746: } else {
1.626 raeburn 9747: $$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 9748: $result = "error: incomplete course id\n";
9749: }
9750: return $result;
9751: }
9752:
9753: ############################################################
9754: ############################################################
9755:
1.566 albertel 9756: sub check_clone {
1.578 raeburn 9757: my ($args,$linefeed) = @_;
1.566 albertel 9758: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9759: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9760: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9761: my $clonemsg;
9762: my $can_clone = 0;
9763:
9764: if ($clonehome eq 'no_host') {
1.578 raeburn 9765: $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 9766: } else {
9767: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9768: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9769: $can_clone = 1;
9770: } else {
9771: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9772: $args->{'clonedomain'},$args->{'clonecourse'});
9773: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9774: if (grep(/^\*$/,@cloners)) {
9775: $can_clone = 1;
9776: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9777: $can_clone = 1;
9778: } else {
9779: my %roleshash =
9780: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9781: $args->{'ccdomain'},
9782: 'userroles',['active'],['cc'],
9783: [$args->{'clonedomain'}]);
9784: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9785: $can_clone = 1;
9786: } else {
9787: $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'});
9788: }
1.566 albertel 9789: }
1.578 raeburn 9790: }
1.566 albertel 9791: }
9792: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9793: }
9794:
1.444 albertel 9795: sub construct_course {
1.541 raeburn 9796: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9797: my $outcome;
1.541 raeburn 9798: my $linefeed = '<br />'."\n";
9799: if ($context eq 'auto') {
9800: $linefeed = "\n";
9801: }
1.566 albertel 9802:
9803: #
9804: # Are we cloning?
9805: #
9806: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9807: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9808: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9809: if ($context ne 'auto') {
1.578 raeburn 9810: if ($clonemsg ne '') {
9811: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9812: }
1.566 albertel 9813: }
9814: $outcome .= $clonemsg.$linefeed;
9815:
9816: if (!$can_clone) {
9817: return (0,$outcome);
9818: }
9819: }
9820:
1.444 albertel 9821: #
9822: # Open course
9823: #
9824: my $crstype = lc($args->{'crstype'});
9825: my %cenv=();
9826: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9827: $args->{'cdescr'},
9828: $args->{'curl'},
9829: $args->{'course_home'},
9830: $args->{'nonstandard'},
9831: $args->{'crscode'},
9832: $args->{'ccuname'}.':'.
9833: $args->{'ccdomain'},
9834: $args->{'crstype'});
9835:
9836: # Note: The testing routines depend on this being output; see
9837: # Utils::Course. This needs to at least be output as a comment
9838: # if anyone ever decides to not show this, and Utils::Course::new
9839: # will need to be suitably modified.
1.541 raeburn 9840: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9841: #
9842: # Check if created correctly
9843: #
1.479 albertel 9844: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9845: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9846: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9847:
1.444 albertel 9848: #
1.566 albertel 9849: # Do the cloning
9850: #
9851: if ($can_clone && $cloneid) {
9852: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9853: if ($context ne 'auto') {
9854: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9855: }
9856: $outcome .= $clonemsg.$linefeed;
9857: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9858: # Copy all files
1.637 www 9859: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9860: # Restore URL
1.566 albertel 9861: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9862: # Restore title
1.566 albertel 9863: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9864: # Mark as cloned
1.566 albertel 9865: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9866: # Need to clone grading mode
9867: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9868: $cenv{'grading'}=$newenv{'grading'};
9869: # Do not clone these environment entries
9870: &Apache::lonnet::del('environment',
9871: ['default_enrollment_start_date',
9872: 'default_enrollment_end_date',
9873: 'question.email',
9874: 'policy.email',
9875: 'comment.email',
9876: 'pch.users.denied',
1.725 raeburn 9877: 'plc.users.denied',
9878: 'hidefromcat',
9879: 'categories'],
1.638 www 9880: $$crsudom,$$crsunum);
1.444 albertel 9881: }
1.566 albertel 9882:
1.444 albertel 9883: #
9884: # Set environment (will override cloned, if existing)
9885: #
9886: my @sections = ();
9887: my @xlists = ();
9888: if ($args->{'crstype'}) {
9889: $cenv{'type'}=$args->{'crstype'};
9890: }
9891: if ($args->{'crsid'}) {
9892: $cenv{'courseid'}=$args->{'crsid'};
9893: }
9894: if ($args->{'crscode'}) {
9895: $cenv{'internal.coursecode'}=$args->{'crscode'};
9896: }
9897: if ($args->{'crsquota'} ne '') {
9898: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9899: } else {
9900: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9901: }
9902: if ($args->{'ccuname'}) {
9903: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9904: ':'.$args->{'ccdomain'};
9905: } else {
9906: $cenv{'internal.courseowner'} = $args->{'curruser'};
9907: }
9908: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9909: if ($args->{'crssections'}) {
9910: $cenv{'internal.sectionnums'} = '';
9911: if ($args->{'crssections'} =~ m/,/) {
9912: @sections = split/,/,$args->{'crssections'};
9913: } else {
9914: $sections[0] = $args->{'crssections'};
9915: }
9916: if (@sections > 0) {
9917: foreach my $item (@sections) {
9918: my ($sec,$gp) = split/:/,$item;
9919: my $class = $args->{'crscode'}.$sec;
9920: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9921: $cenv{'internal.sectionnums'} .= $item.',';
9922: unless ($addcheck eq 'ok') {
9923: push @badclasses, $class;
9924: }
9925: }
9926: $cenv{'internal.sectionnums'} =~ s/,$//;
9927: }
9928: }
9929: # do not hide course coordinator from staff listing,
9930: # even if privileged
9931: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9932: # add crosslistings
9933: if ($args->{'crsxlist'}) {
9934: $cenv{'internal.crosslistings'}='';
9935: if ($args->{'crsxlist'} =~ m/,/) {
9936: @xlists = split/,/,$args->{'crsxlist'};
9937: } else {
9938: $xlists[0] = $args->{'crsxlist'};
9939: }
9940: if (@xlists > 0) {
9941: foreach my $item (@xlists) {
9942: my ($xl,$gp) = split/:/,$item;
9943: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9944: $cenv{'internal.crosslistings'} .= $item.',';
9945: unless ($addcheck eq 'ok') {
9946: push @badclasses, $xl;
9947: }
9948: }
9949: $cenv{'internal.crosslistings'} =~ s/,$//;
9950: }
9951: }
9952: if ($args->{'autoadds'}) {
9953: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9954: }
9955: if ($args->{'autodrops'}) {
9956: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9957: }
9958: # check for notification of enrollment changes
9959: my @notified = ();
9960: if ($args->{'notify_owner'}) {
9961: if ($args->{'ccuname'} ne '') {
9962: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9963: }
9964: }
9965: if ($args->{'notify_dc'}) {
9966: if ($uname ne '') {
1.630 raeburn 9967: push(@notified,$uname.':'.$udom);
1.444 albertel 9968: }
9969: }
9970: if (@notified > 0) {
9971: my $notifylist;
9972: if (@notified > 1) {
9973: $notifylist = join(',',@notified);
9974: } else {
9975: $notifylist = $notified[0];
9976: }
9977: $cenv{'internal.notifylist'} = $notifylist;
9978: }
9979: if (@badclasses > 0) {
9980: my %lt=&Apache::lonlocal::texthash(
9981: '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',
9982: 'dnhr' => 'does not have rights to access enrollment in these classes',
9983: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9984: );
1.541 raeburn 9985: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9986: ' ('.$lt{'adby'}.')';
9987: if ($context eq 'auto') {
9988: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9989: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9990: foreach my $item (@badclasses) {
9991: if ($context eq 'auto') {
9992: $outcome .= " - $item\n";
9993: } else {
9994: $outcome .= "<li>$item</li>\n";
9995: }
9996: }
9997: if ($context eq 'auto') {
9998: $outcome .= $linefeed;
9999: } else {
1.566 albertel 10000: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10001: }
10002: }
1.444 albertel 10003: }
10004: if ($args->{'no_end_date'}) {
10005: $args->{'endaccess'} = 0;
10006: }
10007: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10008: $cenv{'internal.autoend'}=$args->{'enrollend'};
10009: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10010: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10011: if ($args->{'showphotos'}) {
10012: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10013: }
10014: $cenv{'internal.authtype'} = $args->{'authtype'};
10015: $cenv{'internal.autharg'} = $args->{'autharg'};
10016: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10017: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10018: 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');
10019: if ($context eq 'auto') {
10020: $outcome .= $krb_msg;
10021: } else {
1.566 albertel 10022: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10023: }
10024: $outcome .= $linefeed;
1.444 albertel 10025: }
10026: }
10027: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10028: if ($args->{'setpolicy'}) {
10029: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10030: }
10031: if ($args->{'setcontent'}) {
10032: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10033: }
10034: }
10035: if ($args->{'reshome'}) {
10036: $cenv{'reshome'}=$args->{'reshome'}.'/';
10037: $cenv{'reshome'}=~s/\/+$/\//;
10038: }
10039: #
10040: # course has keyed access
10041: #
10042: if ($args->{'setkeys'}) {
10043: $cenv{'keyaccess'}='yes';
10044: }
10045: # if specified, key authority is not course, but user
10046: # only active if keyaccess is yes
10047: if ($args->{'keyauth'}) {
1.487 albertel 10048: my ($user,$domain) = split(':',$args->{'keyauth'});
10049: $user = &LONCAPA::clean_username($user);
10050: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10051: if ($user ne '' && $domain ne '') {
1.487 albertel 10052: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10053: }
10054: }
10055:
10056: if ($args->{'disresdis'}) {
10057: $cenv{'pch.roles.denied'}='st';
10058: }
10059: if ($args->{'disablechat'}) {
10060: $cenv{'plc.roles.denied'}='st';
10061: }
10062:
10063: # Record we've not yet viewed the Course Initialization Helper for this
10064: # course
10065: $cenv{'course.helper.not.run'} = 1;
10066: #
10067: # Use new Randomseed
10068: #
10069: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10070: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10071: #
10072: # The encryption code and receipt prefix for this course
10073: #
10074: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10075: $cenv{'internal.encpref'}=100+int(9*rand(99));
10076: #
10077: # By default, use standard grading
10078: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10079:
1.541 raeburn 10080: $outcome .= $linefeed.&mt('Setting environment').': '.
10081: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10082: #
10083: # Open all assignments
10084: #
10085: if ($args->{'openall'}) {
10086: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10087: my %storecontent = ($storeunder => time,
10088: $storeunder.'.type' => 'date_start');
10089:
10090: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10091: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10092: }
10093: #
10094: # Set first page
10095: #
10096: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10097: || ($cloneid)) {
1.445 albertel 10098: use LONCAPA::map;
1.444 albertel 10099: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10100:
10101: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10102: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10103:
1.444 albertel 10104: $outcome .= ($fatal?$errtext:'read ok').' - ';
10105: my $title; my $url;
10106: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10107: $title=&mt('Syllabus');
1.444 albertel 10108: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10109: } else {
1.690 bisitz 10110: $title=&mt('Navigate Contents');
1.444 albertel 10111: $url='/adm/navmaps';
10112: }
1.445 albertel 10113:
10114: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10115: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10116:
10117: if ($errtext) { $fatal=2; }
1.541 raeburn 10118: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10119: }
1.566 albertel 10120:
10121: return (1,$outcome);
1.444 albertel 10122: }
10123:
10124: ############################################################
10125: ############################################################
10126:
1.378 raeburn 10127: sub course_type {
10128: my ($cid) = @_;
10129: if (!defined($cid)) {
10130: $cid = $env{'request.course.id'};
10131: }
1.404 albertel 10132: if (defined($env{'course.'.$cid.'.type'})) {
10133: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10134: } else {
10135: return 'Course';
1.377 raeburn 10136: }
10137: }
1.156 albertel 10138:
1.406 raeburn 10139: sub group_term {
10140: my $crstype = &course_type();
10141: my %names = (
10142: 'Course' => 'group',
1.865 raeburn 10143: 'Community' => 'group',
1.406 raeburn 10144: );
10145: return $names{$crstype};
10146: }
10147:
1.156 albertel 10148: sub icon {
10149: my ($file)=@_;
1.505 albertel 10150: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10151: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10152: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10153: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10154: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10155: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10156: $curfext.".gif") {
10157: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10158: $curfext.".gif";
10159: }
10160: }
1.249 albertel 10161: return &lonhttpdurl($iconname);
1.154 albertel 10162: }
1.84 albertel 10163:
1.575 albertel 10164: sub lonhttpdurl {
1.692 www 10165: #
10166: # Had been used for "small fry" static images on separate port 8080.
10167: # Modify here if lightweight http functionality desired again.
10168: # Currently eliminated due to increasing firewall issues.
10169: #
1.575 albertel 10170: my ($url)=@_;
1.692 www 10171: return $url;
1.215 albertel 10172: }
10173:
1.213 albertel 10174: sub connection_aborted {
10175: my ($r)=@_;
10176: $r->print(" ");$r->rflush();
10177: my $c = $r->connection;
10178: return $c->aborted();
10179: }
10180:
1.221 foxr 10181: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10182: # strings as 'strings'.
10183: sub escape_single {
1.221 foxr 10184: my ($input) = @_;
1.223 albertel 10185: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10186: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10187: return $input;
10188: }
1.223 albertel 10189:
1.222 foxr 10190: # Same as escape_single, but escape's "'s This
10191: # can be used for "strings"
10192: sub escape_double {
10193: my ($input) = @_;
10194: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10195: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10196: return $input;
10197: }
1.223 albertel 10198:
1.222 foxr 10199: # Escapes the last element of a full URL.
10200: sub escape_url {
10201: my ($url) = @_;
1.238 raeburn 10202: my @urlslices = split(/\//, $url,-1);
1.369 www 10203: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10204: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10205: }
1.462 albertel 10206:
1.820 raeburn 10207: sub compare_arrays {
10208: my ($arrayref1,$arrayref2) = @_;
10209: my (@difference,%count);
10210: @difference = ();
10211: %count = ();
10212: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10213: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10214: foreach my $element (keys(%count)) {
10215: if ($count{$element} == 1) {
10216: push(@difference,$element);
10217: }
10218: }
10219: }
10220: return @difference;
10221: }
10222:
1.817 bisitz 10223: # -------------------------------------------------------- Initialize user login
1.462 albertel 10224: sub init_user_environment {
1.463 albertel 10225: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10226: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10227:
10228: my $public=($username eq 'public' && $domain eq 'public');
10229:
10230: # See if old ID present, if so, remove
10231:
10232: my ($filename,$cookie,$userroles);
10233: my $now=time;
10234:
10235: if ($public) {
10236: my $max_public=100;
10237: my $oldest;
10238: my $oldest_time=0;
10239: for(my $next=1;$next<=$max_public;$next++) {
10240: if (-e $lonids."/publicuser_$next.id") {
10241: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10242: if ($mtime<$oldest_time || !$oldest_time) {
10243: $oldest_time=$mtime;
10244: $oldest=$next;
10245: }
10246: } else {
10247: $cookie="publicuser_$next";
10248: last;
10249: }
10250: }
10251: if (!$cookie) { $cookie="publicuser_$oldest"; }
10252: } else {
1.463 albertel 10253: # if this isn't a robot, kill any existing non-robot sessions
10254: if (!$args->{'robot'}) {
10255: opendir(DIR,$lonids);
10256: while ($filename=readdir(DIR)) {
10257: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10258: unlink($lonids.'/'.$filename);
10259: }
1.462 albertel 10260: }
1.463 albertel 10261: closedir(DIR);
1.462 albertel 10262: }
10263: # Give them a new cookie
1.463 albertel 10264: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10265: : $now.$$.int(rand(10000)));
1.463 albertel 10266: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10267:
10268: # Initialize roles
10269:
10270: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10271: }
10272: # ------------------------------------ Check browser type and MathML capability
10273:
10274: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10275: $clientunicode,$clientos) = &decode_user_agent($r);
10276:
10277: # ------------------------------------------------------------- Get environment
10278:
10279: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10280: my ($tmp) = keys(%userenv);
10281: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10282: # default remote control to off
10283: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10284: } else {
10285: undef(%userenv);
10286: }
10287: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10288: $form->{'interface'}=$userenv{'interface'};
10289: }
10290: $env{'environment.remote'}=$userenv{'remote'};
10291: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10292:
10293: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10294: foreach my $option ('interface','localpath','localres') {
10295: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10296: }
10297: # --------------------------------------------------------- Write first profile
10298:
10299: {
10300: my %initial_env =
10301: ("user.name" => $username,
10302: "user.domain" => $domain,
10303: "user.home" => $authhost,
10304: "browser.type" => $clientbrowser,
10305: "browser.version" => $clientversion,
10306: "browser.mathml" => $clientmathml,
10307: "browser.unicode" => $clientunicode,
10308: "browser.os" => $clientos,
10309: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10310: "request.course.fn" => '',
10311: "request.course.uri" => '',
10312: "request.course.sec" => '',
10313: "request.role" => 'cm',
10314: "request.role.adv" => $env{'user.adv'},
10315: "request.host" => $ENV{'REMOTE_ADDR'},);
10316:
10317: if ($form->{'localpath'}) {
10318: $initial_env{"browser.localpath"} = $form->{'localpath'};
10319: $initial_env{"browser.localres"} = $form->{'localres'};
10320: }
10321:
10322: if ($public) {
10323: $initial_env{"environment.remote"} = "off";
10324: }
10325: if ($form->{'interface'}) {
10326: $form->{'interface'}=~s/\W//gs;
10327: $initial_env{"browser.interface"} = $form->{'interface'};
10328: $env{'browser.interface'}=$form->{'interface'};
10329: }
10330:
1.724 raeburn 10331: foreach my $tool ('aboutme','blog','portfolio') {
10332: $userenv{'availabletools.'.$tool} =
10333: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10334: }
10335:
1.864 raeburn 10336: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10337: $userenv{'canrequest.'.$crstype} =
10338: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10339: 'reload','requestcourses');
10340: }
10341:
1.462 albertel 10342: $env{'user.environment'} = "$lonids/$cookie.id";
10343:
10344: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10345: &GDBM_WRCREAT(),0640)) {
10346: &_add_to_env(\%disk_env,\%initial_env);
10347: &_add_to_env(\%disk_env,\%userenv,'environment.');
10348: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10349: if (ref($args->{'extra_env'})) {
10350: &_add_to_env(\%disk_env,$args->{'extra_env'});
10351: }
1.462 albertel 10352: untie(%disk_env);
10353: } else {
1.705 tempelho 10354: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10355: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10356: return 'error: '.$!;
10357: }
10358: }
10359: $env{'request.role'}='cm';
10360: $env{'request.role.adv'}=$env{'user.adv'};
10361: $env{'browser.type'}=$clientbrowser;
10362:
10363: return $cookie;
10364:
10365: }
10366:
10367: sub _add_to_env {
10368: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10369: if (ref($env_data) eq 'HASH') {
10370: while (my ($key,$value) = each(%$env_data)) {
10371: $idf->{$prefix.$key} = $value;
10372: $env{$prefix.$key} = $value;
10373: }
1.462 albertel 10374: }
10375: }
10376:
1.685 tempelho 10377: # --- Get the symbolic name of a problem and the url
10378: sub get_symb {
10379: my ($request,$silent) = @_;
1.726 raeburn 10380: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10381: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10382: if ($symb eq '') {
10383: if (!$silent) {
10384: $request->print("Unable to handle ambiguous references:$url:.");
10385: return ();
10386: }
10387: }
10388: &Apache::lonenc::check_decrypt(\$symb);
10389: return ($symb);
10390: }
10391:
10392: # --------------------------------------------------------------Get annotation
10393:
10394: sub get_annotation {
10395: my ($symb,$enc) = @_;
10396:
10397: my $key = $symb;
10398: if (!$enc) {
10399: $key =
10400: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10401: }
10402: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10403: return $annotation{$key};
10404: }
10405:
10406: sub clean_symb {
1.731 raeburn 10407: my ($symb,$delete_enc) = @_;
1.685 tempelho 10408:
10409: &Apache::lonenc::check_decrypt(\$symb);
10410: my $enc = $env{'request.enc'};
1.731 raeburn 10411: if ($delete_enc) {
1.730 raeburn 10412: delete($env{'request.enc'});
10413: }
1.685 tempelho 10414:
10415: return ($symb,$enc);
10416: }
1.462 albertel 10417:
1.41 ng 10418: =pod
10419:
10420: =back
10421:
1.112 bowersj2 10422: =cut
1.41 ng 10423:
1.112 bowersj2 10424: 1;
10425: __END__;
1.41 ng 10426:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>