Annotation of loncom/interface/loncommon.pm, revision 1.867
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.866 kalberla 4: # $Id: loncommon.pm,v 1.865 2009/07/25 23:16:04 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.468 raeburn 485: my ($domainfilter,$sec_element,$formname)=@_;
1.865 raeburn 486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role');
1.468 raeburn 487: my $output = '
1.776 bisitz 488: <script type="text/javascript" language="JavaScript">
1.824 bisitz 489: // <![CDATA[
1.468 raeburn 490: var stdeditbrowser;'."\n";
491: $output .= <<"ENDSTDBRW";
1.377 raeburn 492: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 493: var url = '/adm/pickcourse?';
1.468 raeburn 494: var domainfilter = '';
495: var formid = getFormIdByName(formname);
496: if (formid > -1) {
497: var domid = getIndexByName(formid,udom);
498: if (domid > -1) {
499: if (document.forms[formid].elements[domid].type == 'select-one') {
500: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
501: }
502: if (document.forms[formid].elements[domid].type == 'hidden') {
503: domainfilter=document.forms[formid].elements[domid].value;
504: }
505: }
1.91 www 506: }
1.128 albertel 507: if (domainfilter != null) {
508: if (domainfilter != '') {
509: url += 'domainfilter='+domainfilter+'&';
510: }
511: }
1.91 www 512: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 513: '&cdomelement='+udom+
514: '&cnameelement='+desc;
1.468 raeburn 515: if (extra_element !=null && extra_element != '') {
1.594 raeburn 516: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 517: url += '&roleelement='+extra_element;
518: if (domainfilter == null || domainfilter == '') {
519: url += '&domainfilter='+extra_element;
520: }
1.234 raeburn 521: }
1.468 raeburn 522: else {
523: if (formname == 'portform') {
524: url += '&setroles='+extra_element;
1.800 raeburn 525: } else {
526: if (formname == 'rules') {
527: url += '&fixeddom='+extra_element;
528: }
1.468 raeburn 529: }
530: }
1.230 raeburn 531: }
1.293 raeburn 532: if (multflag !=null && multflag != '') {
533: url += '&multiple='+multflag;
534: }
1.865 raeburn 535: if (crstype == 'Course/Community') {
1.377 raeburn 536: if (formname == 'cu') {
537: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
538: if (crstype == "") {
539: alert("$crs_or_grp_alert");
540: return;
541: }
542: }
543: }
544: if (crstype !=null && crstype != '') {
545: url += '&type='+crstype;
546: }
1.102 www 547: var title = 'Course_Browser';
1.91 www 548: var options = 'scrollbars=1,resizable=1,menubar=0';
549: options += ',width=700,height=600';
550: stdeditbrowser = open(url,title,options,'1');
551: stdeditbrowser.focus();
552: }
1.468 raeburn 553:
554: function getFormIdByName(formname) {
555: for (var i=0;i<document.forms.length;i++) {
556: if (document.forms[i].name == formname) {
557: return i;
558: }
559: }
560: return -1;
561: }
562:
563: function getIndexByName(formid,item) {
564: for (var i=0;i<document.forms[formid].elements.length;i++) {
565: if (document.forms[formid].elements[i].name == item) {
566: return i;
567: }
568: }
569: return -1;
570: }
1.91 www 571: ENDSTDBRW
1.468 raeburn 572: if ($sec_element ne '') {
573: $output .= &setsec_javascript($sec_element,$formname);
574: }
575: $output .= '
1.824 bisitz 576: // ]]>
1.468 raeburn 577: </script>';
578: return $output;
579: }
580:
581: sub setsec_javascript {
582: my ($sec_element,$formname) = @_;
583: my $setsections = qq|
584: function setSect(sectionlist) {
1.629 raeburn 585: var sectionsArray = new Array();
586: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
587: sectionsArray = sectionlist.split(",");
588: }
1.468 raeburn 589: var numSections = sectionsArray.length;
590: document.$formname.$sec_element.length = 0;
591: if (numSections == 0) {
592: document.$formname.$sec_element.multiple=false;
593: document.$formname.$sec_element.size=1;
594: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
595: } else {
596: if (numSections == 1) {
597: document.$formname.$sec_element.multiple=false;
598: document.$formname.$sec_element.size=1;
599: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
600: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
601: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
602: } else {
603: for (var i=0; i<numSections; i++) {
604: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
605: }
606: document.$formname.$sec_element.multiple=true
607: if (numSections < 3) {
608: document.$formname.$sec_element.size=numSections;
609: } else {
610: document.$formname.$sec_element.size=3;
611: }
612: document.$formname.$sec_element.options[0].selected = false
613: }
614: }
1.91 www 615: }
1.468 raeburn 616: |;
617: return $setsections;
618: }
619:
1.91 www 620:
621: sub selectcourse_link {
1.377 raeburn 622: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787 bisitz 623: return '<span class="LC_nobreak">'
624: ."<a href='"
625: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
626: .'","'.$udomele.'","'.$desc.'","'.$extra_element
627: .'","'.$multflag.'","'.$selecttype.'");'
628: ."'>".&mt('Select Course').'</a>'
629: .'</span>';
1.74 www 630: }
1.42 matthew 631:
1.653 raeburn 632: sub selectauthor_link {
633: my ($form,$udom)=@_;
634: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
635: &mt('Select Author').'</a>';
636: }
637:
1.273 raeburn 638: sub check_uncheck_jscript {
639: my $jscript = <<"ENDSCRT";
640: function checkAll(field) {
641: if (field.length > 0) {
642: for (i = 0; i < field.length; i++) {
643: field[i].checked = true ;
644: }
645: } else {
646: field.checked = true
647: }
648: }
649:
650: function uncheckAll(field) {
651: if (field.length > 0) {
652: for (i = 0; i < field.length; i++) {
653: field[i].checked = false ;
1.543 albertel 654: }
655: } else {
1.273 raeburn 656: field.checked = false ;
657: }
658: }
659: ENDSCRT
660: return $jscript;
661: }
662:
1.656 www 663: sub select_timezone {
1.659 raeburn 664: my ($name,$selected,$onchange,$includeempty)=@_;
665: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
666: if ($includeempty) {
667: $output .= '<option value=""';
668: if (($selected eq '') || ($selected eq 'local')) {
669: $output .= ' selected="selected" ';
670: }
671: $output .= '> </option>';
672: }
1.657 raeburn 673: my @timezones = DateTime::TimeZone->all_names;
674: foreach my $tzone (@timezones) {
675: $output.= '<option value="'.$tzone.'"';
676: if ($tzone eq $selected) {
677: $output.=' selected="selected"';
678: }
679: $output.=">$tzone</option>\n";
1.656 www 680: }
681: $output.="</select>";
682: return $output;
683: }
1.273 raeburn 684:
1.687 raeburn 685: sub select_datelocale {
686: my ($name,$selected,$onchange,$includeempty)=@_;
687: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
688: if ($includeempty) {
689: $output .= '<option value=""';
690: if ($selected eq '') {
691: $output .= ' selected="selected" ';
692: }
693: $output .= '> </option>';
694: }
695: my (@possibles,%locale_names);
696: my @locales = DateTime::Locale::Catalog::Locales;
697: foreach my $locale (@locales) {
698: if (ref($locale) eq 'HASH') {
699: my $id = $locale->{'id'};
700: if ($id ne '') {
701: my $en_terr = $locale->{'en_territory'};
702: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 703: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 704: if (grep(/^en$/,@languages) || !@languages) {
705: if ($en_terr ne '') {
706: $locale_names{$id} = '('.$en_terr.')';
707: } elsif ($native_terr ne '') {
708: $locale_names{$id} = $native_terr;
709: }
710: } else {
711: if ($native_terr ne '') {
712: $locale_names{$id} = $native_terr.' ';
713: } elsif ($en_terr ne '') {
714: $locale_names{$id} = '('.$en_terr.')';
715: }
716: }
717: push (@possibles,$id);
718: }
719: }
720: }
721: foreach my $item (sort(@possibles)) {
722: $output.= '<option value="'.$item.'"';
723: if ($item eq $selected) {
724: $output.=' selected="selected"';
725: }
726: $output.=">$item";
727: if ($locale_names{$item} ne '') {
728: $output.=" $locale_names{$item}</option>\n";
729: }
730: $output.="</option>\n";
731: }
732: $output.="</select>";
733: return $output;
734: }
735:
1.792 raeburn 736: sub select_language {
737: my ($name,$selected,$includeempty) = @_;
738: my %langchoices;
739: if ($includeempty) {
740: %langchoices = ('' => 'No language preference');
741: }
742: foreach my $id (&languageids()) {
743: my $code = &supportedlanguagecode($id);
744: if ($code) {
745: $langchoices{$code} = &plainlanguagedescription($id);
746: }
747: }
748: return &select_form($selected,$name,%langchoices);
749: }
750:
1.42 matthew 751: =pod
1.36 matthew 752:
1.648 raeburn 753: =item * &linked_select_forms(...)
1.36 matthew 754:
755: linked_select_forms returns a string containing a <script></script> block
756: and html for two <select> menus. The select menus will be linked in that
757: changing the value of the first menu will result in new values being placed
758: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 759: order unless a defined order is provided.
1.36 matthew 760:
761: linked_select_forms takes the following ordered inputs:
762:
763: =over 4
764:
1.112 bowersj2 765: =item * $formname, the name of the <form> tag
1.36 matthew 766:
1.112 bowersj2 767: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 768:
1.112 bowersj2 769: =item * $firstdefault, the default value for the first menu
1.36 matthew 770:
1.112 bowersj2 771: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 772:
1.112 bowersj2 773: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 774:
1.112 bowersj2 775: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 776:
1.609 raeburn 777: =item * $menuorder, the order of values in the first menu
778:
1.41 ng 779: =back
780:
1.36 matthew 781: Below is an example of such a hash. Only the 'text', 'default', and
782: 'select2' keys must appear as stated. keys(%menu) are the possible
783: values for the first select menu. The text that coincides with the
1.41 ng 784: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 785: and text for the second menu are given in the hash pointed to by
786: $menu{$choice1}->{'select2'}.
787:
1.112 bowersj2 788: my %menu = ( A1 => { text =>"Choice A1" ,
789: default => "B3",
790: select2 => {
791: B1 => "Choice B1",
792: B2 => "Choice B2",
793: B3 => "Choice B3",
794: B4 => "Choice B4"
1.609 raeburn 795: },
796: order => ['B4','B3','B1','B2'],
1.112 bowersj2 797: },
798: A2 => { text =>"Choice A2" ,
799: default => "C2",
800: select2 => {
801: C1 => "Choice C1",
802: C2 => "Choice C2",
803: C3 => "Choice C3"
1.609 raeburn 804: },
805: order => ['C2','C1','C3'],
1.112 bowersj2 806: },
807: A3 => { text =>"Choice A3" ,
808: default => "D6",
809: select2 => {
810: D1 => "Choice D1",
811: D2 => "Choice D2",
812: D3 => "Choice D3",
813: D4 => "Choice D4",
814: D5 => "Choice D5",
815: D6 => "Choice D6",
816: D7 => "Choice D7"
1.609 raeburn 817: },
818: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 819: }
820: );
1.36 matthew 821:
822: =cut
823:
824: sub linked_select_forms {
825: my ($formname,
826: $middletext,
827: $firstdefault,
828: $firstselectname,
829: $secondselectname,
1.609 raeburn 830: $hashref,
831: $menuorder,
1.36 matthew 832: ) = @_;
833: my $second = "document.$formname.$secondselectname";
834: my $first = "document.$formname.$firstselectname";
835: # output the javascript to do the changing
836: my $result = '';
1.776 bisitz 837: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 838: $result.="// <![CDATA[\n";
1.36 matthew 839: $result.="var select2data = new Object();\n";
840: $" = '","';
841: my $debug = '';
842: foreach my $s1 (sort(keys(%$hashref))) {
843: $result.="select2data.d_$s1 = new Object();\n";
844: $result.="select2data.d_$s1.def = new String('".
845: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 846: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 847: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 848: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
849: @s2values = @{$hashref->{$s1}->{'order'}};
850: }
1.36 matthew 851: $result.="\"@s2values\");\n";
852: $result.="select2data.d_$s1.texts = new Array(";
853: my @s2texts;
854: foreach my $value (@s2values) {
855: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
856: }
857: $result.="\"@s2texts\");\n";
858: }
859: $"=' ';
860: $result.= <<"END";
861:
862: function select1_changed() {
863: // Determine new choice
864: var newvalue = "d_" + $first.value;
865: // update select2
866: var values = select2data[newvalue].values;
867: var texts = select2data[newvalue].texts;
868: var select2def = select2data[newvalue].def;
869: var i;
870: // out with the old
871: for (i = 0; i < $second.options.length; i++) {
872: $second.options[i] = null;
873: }
874: // in with the nuclear
875: for (i=0;i<values.length; i++) {
876: $second.options[i] = new Option(values[i]);
1.143 matthew 877: $second.options[i].value = values[i];
1.36 matthew 878: $second.options[i].text = texts[i];
879: if (values[i] == select2def) {
880: $second.options[i].selected = true;
881: }
882: }
883: }
1.824 bisitz 884: // ]]>
1.36 matthew 885: </script>
886: END
887: # output the initial values for the selection lists
888: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 889: my @order = sort(keys(%{$hashref}));
890: if (ref($menuorder) eq 'ARRAY') {
891: @order = @{$menuorder};
892: }
893: foreach my $value (@order) {
1.36 matthew 894: $result.=" <option value=\"$value\" ";
1.253 albertel 895: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 896: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 897: }
898: $result .= "</select>\n";
899: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
900: $result .= $middletext;
901: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
902: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 903:
904: my @secondorder = sort(keys(%select2));
905: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
906: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
907: }
908: foreach my $value (@secondorder) {
1.36 matthew 909: $result.=" <option value=\"$value\" ";
1.253 albertel 910: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 911: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 912: }
913: $result .= "</select>\n";
914: # return $debug;
915: return $result;
916: } # end of sub linked_select_forms {
917:
1.45 matthew 918: =pod
1.44 bowersj2 919:
1.648 raeburn 920: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 921:
1.112 bowersj2 922: Returns a string corresponding to an HTML link to the given help
923: $topic, where $topic corresponds to the name of a .tex file in
924: /home/httpd/html/adm/help/tex, with underscores replaced by
925: spaces.
926:
927: $text will optionally be linked to the same topic, allowing you to
928: link text in addition to the graphic. If you do not want to link
929: text, but wish to specify one of the later parameters, pass an
930: empty string.
931:
932: $stayOnPage is a value that will be interpreted as a boolean. If true,
933: the link will not open a new window. If false, the link will open
934: a new window using Javascript. (Default is false.)
935:
936: $width and $height are optional numerical parameters that will
937: override the width and height of the popped up window, which may
938: be useful for certain help topics with big pictures included.
1.44 bowersj2 939:
940: =cut
941:
942: sub help_open_topic {
1.48 bowersj2 943: my ($topic, $text, $stayOnPage, $width, $height) = @_;
944: $text = "" if (not defined $text);
1.44 bowersj2 945: $stayOnPage = 0 if (not defined $stayOnPage);
946: $width = 350 if (not defined $width);
947: $height = 400 if (not defined $height);
948: my $filename = $topic;
949: $filename =~ s/ /_/g;
950:
1.48 bowersj2 951: my $template = "";
952: my $link;
1.572 banghart 953:
1.159 www 954: $topic=~s/\W/\_/g;
1.44 bowersj2 955:
1.572 banghart 956: if (!$stayOnPage) {
1.72 bowersj2 957: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 958: } else {
1.48 bowersj2 959: $link = "/adm/help/${filename}.hlp";
960: }
961:
962: # Add the text
1.755 neumanie 963: if ($text ne "") {
1.763 bisitz 964: $template.='<span class="LC_help_open_topic">'
965: .'<a target="_top" href="'.$link.'">'
966: .$text.'</a>';
1.48 bowersj2 967: }
968:
1.763 bisitz 969: # (Always) Add the graphic
1.179 matthew 970: my $title = &mt('Online Help');
1.667 raeburn 971: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 972: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
973: .'<img src="'.$helpicon.'" border="0"'
974: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 975: .' title="'.$title.'"'
1.763 bisitz 976: .' /></a>';
977: if ($text ne "") {
978: $template.='</span>';
979: }
1.44 bowersj2 980: return $template;
981:
1.106 bowersj2 982: }
983:
984: # This is a quicky function for Latex cheatsheet editing, since it
985: # appears in at least four places
986: sub helpLatexCheatsheet {
1.732 raeburn 987: my ($topic,$text,$not_author) = @_;
988: my $out;
1.106 bowersj2 989: my $addOther = '';
1.732 raeburn 990: if ($topic) {
1.763 bisitz 991: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
992: undef, undef, 600).
993: '</span> ';
994: }
995: $out = '<span>' # Start cheatsheet
996: .$addOther
997: .'<span>'
998: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
999: undef,undef,600)
1000: .'</span> <span>'
1001: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1002: undef,undef,600)
1003: .'</span>';
1.732 raeburn 1004: unless ($not_author) {
1.763 bisitz 1005: $out .= ' <span>'
1006: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1007: undef,undef,600)
1008: .'</span>';
1.732 raeburn 1009: }
1.763 bisitz 1010: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1011: return $out;
1.172 www 1012: }
1013:
1.430 albertel 1014: sub general_help {
1015: my $helptopic='Student_Intro';
1016: if ($env{'request.role'}=~/^(ca|au)/) {
1017: $helptopic='Authoring_Intro';
1018: } elsif ($env{'request.role'}=~/^cc/) {
1019: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1020: } elsif ($env{'request.role'}=~/^dc/) {
1021: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1022: }
1023: return $helptopic;
1024: }
1025:
1026: sub update_help_link {
1027: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1028: my $origurl = $ENV{'REQUEST_URI'};
1029: $origurl=~s|^/~|/priv/|;
1030: my $timestamp = time;
1031: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1032: $$datum = &escape($$datum);
1033: }
1034:
1035: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1036: my $output .= <<"ENDOUTPUT";
1037: <script type="text/javascript">
1.824 bisitz 1038: // <![CDATA[
1.430 albertel 1039: banner_link = '$banner_link';
1.824 bisitz 1040: // ]]>
1.430 albertel 1041: </script>
1042: ENDOUTPUT
1043: return $output;
1044: }
1045:
1046: # now just updates the help link and generates a blue icon
1.193 raeburn 1047: sub help_open_menu {
1.430 albertel 1048: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1049: = @_;
1.430 albertel 1050: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1051: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1052: # if environment.remote is on (using remote control UI)
1.798 tempelho 1053: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1054: $stayOnPage=1;
1.430 albertel 1055: }
1056: my $output;
1057: if ($component_help) {
1058: if (!$text) {
1059: $output=&help_open_topic($component_help,undef,$stayOnPage,
1060: $width,$height);
1061: } else {
1062: my $help_text;
1063: $help_text=&unescape($topic);
1064: $output='<table><tr><td>'.
1065: &help_open_topic($component_help,$help_text,$stayOnPage,
1066: $width,$height).'</td></tr></table>';
1067: }
1068: }
1069: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1070: return $output.$banner_link;
1071: }
1072:
1073: sub top_nav_help {
1074: my ($text) = @_;
1.436 albertel 1075: $text = &mt($text);
1.572 banghart 1076: my $stay_on_page =
1.798 tempelho 1077: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1078: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1079: : "javascript:helpMenu('open')";
1.572 banghart 1080: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1081:
1.201 raeburn 1082: my $title = &mt('Get help');
1.436 albertel 1083:
1084: return <<"END";
1085: $banner_link
1086: <a href="$link" title="$title">$text</a>
1087: END
1088: }
1089:
1090: sub help_menu_js {
1091: my ($text) = @_;
1092:
1093: my $stayOnPage =
1.798 tempelho 1094: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1095:
1096: my $width = 620;
1097: my $height = 600;
1.430 albertel 1098: my $helptopic=&general_help();
1099: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1100: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1101: my $start_page =
1102: &Apache::loncommon::start_page('Help Menu', undef,
1103: {'frameset' => 1,
1104: 'js_ready' => 1,
1105: 'add_entries' => {
1106: 'border' => '0',
1.579 raeburn 1107: 'rows' => "110,*",},});
1.331 albertel 1108: my $end_page =
1109: &Apache::loncommon::end_page({'frameset' => 1,
1110: 'js_ready' => 1,});
1111:
1.436 albertel 1112: my $template .= <<"ENDTEMPLATE";
1113: <script type="text/javascript">
1.253 albertel 1114: // <!-- BEGIN LON-CAPA Internal
1115: // <![CDATA[
1.430 albertel 1116: var banner_link = '';
1.243 raeburn 1117: function helpMenu(target) {
1118: var caller = this;
1119: if (target == 'open') {
1120: var newWindow = null;
1121: try {
1.262 albertel 1122: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1123: }
1124: catch(error) {
1125: writeHelp(caller);
1126: return;
1127: }
1128: if (newWindow) {
1129: caller = newWindow;
1130: }
1.193 raeburn 1131: }
1.243 raeburn 1132: writeHelp(caller);
1133: return;
1134: }
1135: function writeHelp(caller) {
1.430 albertel 1136: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1137: caller.document.close()
1138: caller.focus()
1.193 raeburn 1139: }
1.253 albertel 1140: // ]]>
1.219 albertel 1141: // END LON-CAPA Internal -->
1.436 albertel 1142: </script>
1.193 raeburn 1143: ENDTEMPLATE
1144: return $template;
1145: }
1146:
1.172 www 1147: sub help_open_bug {
1148: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1149: unless ($env{'user.adv'}) { return ''; }
1.172 www 1150: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1151: $text = "" if (not defined $text);
1152: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1153: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1154: $stayOnPage=1;
1155: }
1.184 albertel 1156: $width = 600 if (not defined $width);
1157: $height = 600 if (not defined $height);
1.172 www 1158:
1159: $topic=~s/\W+/\+/g;
1160: my $link='';
1161: my $template='';
1.379 albertel 1162: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1163: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1164: if (!$stayOnPage)
1165: {
1166: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1167: }
1168: else
1169: {
1170: $link = $url;
1171: }
1172: # Add the text
1173: if ($text ne "")
1174: {
1175: $template .=
1176: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1177: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1178: }
1179:
1180: # Add the graphic
1.179 matthew 1181: my $title = &mt('Report a Bug');
1.215 albertel 1182: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1183: $template .= <<"ENDTEMPLATE";
1.436 albertel 1184: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1185: ENDTEMPLATE
1186: if ($text ne '') { $template.='</td></tr></table>' };
1187: return $template;
1188:
1189: }
1190:
1191: sub help_open_faq {
1192: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1193: unless ($env{'user.adv'}) { return ''; }
1.172 www 1194: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1195: $text = "" if (not defined $text);
1196: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1197: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1198: $stayOnPage=1;
1199: }
1200: $width = 350 if (not defined $width);
1201: $height = 400 if (not defined $height);
1202:
1203: $topic=~s/\W+/\+/g;
1204: my $link='';
1205: my $template='';
1206: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1207: if (!$stayOnPage)
1208: {
1209: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1210: }
1211: else
1212: {
1213: $link = $url;
1214: }
1215:
1216: # Add the text
1217: if ($text ne "")
1218: {
1219: $template .=
1.173 www 1220: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1221: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1222: }
1223:
1224: # Add the graphic
1.179 matthew 1225: my $title = &mt('View the FAQ');
1.215 albertel 1226: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1227: $template .= <<"ENDTEMPLATE";
1.436 albertel 1228: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1229: ENDTEMPLATE
1230: if ($text ne '') { $template.='</td></tr></table>' };
1231: return $template;
1232:
1.44 bowersj2 1233: }
1.37 matthew 1234:
1.180 matthew 1235: ###############################################################
1236: ###############################################################
1237:
1.45 matthew 1238: =pod
1239:
1.648 raeburn 1240: =item * &change_content_javascript():
1.256 matthew 1241:
1242: This and the next function allow you to create small sections of an
1243: otherwise static HTML page that you can update on the fly with
1244: Javascript, even in Netscape 4.
1245:
1246: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1247: must be written to the HTML page once. It will prove the Javascript
1248: function "change(name, content)". Calling the change function with the
1249: name of the section
1250: you want to update, matching the name passed to C<changable_area>, and
1251: the new content you want to put in there, will put the content into
1252: that area.
1253:
1254: B<Note>: Netscape 4 only reserves enough space for the changable area
1255: to contain room for the original contents. You need to "make space"
1256: for whatever changes you wish to make, and be B<sure> to check your
1257: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1258: it's adequate for updating a one-line status display, but little more.
1259: This script will set the space to 100% width, so you only need to
1260: worry about height in Netscape 4.
1261:
1262: Modern browsers are much less limiting, and if you can commit to the
1263: user not using Netscape 4, this feature may be used freely with
1264: pretty much any HTML.
1265:
1266: =cut
1267:
1268: sub change_content_javascript {
1269: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1270: if ($env{'browser.type'} eq 'netscape' &&
1271: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1272: return (<<NETSCAPE4);
1273: function change(name, content) {
1274: doc = document.layers[name+"___escape"].layers[0].document;
1275: doc.open();
1276: doc.write(content);
1277: doc.close();
1278: }
1279: NETSCAPE4
1280: } else {
1281: # Otherwise, we need to use semi-standards-compliant code
1282: # (technically, "innerHTML" isn't standard but the equivalent
1283: # is really scary, and every useful browser supports it
1284: return (<<DOMBASED);
1285: function change(name, content) {
1286: element = document.getElementById(name);
1287: element.innerHTML = content;
1288: }
1289: DOMBASED
1290: }
1291: }
1292:
1293: =pod
1294:
1.648 raeburn 1295: =item * &changable_area($name,$origContent):
1.256 matthew 1296:
1297: This provides a "changable area" that can be modified on the fly via
1298: the Javascript code provided in C<change_content_javascript>. $name is
1299: the name you will use to reference the area later; do not repeat the
1300: same name on a given HTML page more then once. $origContent is what
1301: the area will originally contain, which can be left blank.
1302:
1303: =cut
1304:
1305: sub changable_area {
1306: my ($name, $origContent) = @_;
1307:
1.258 albertel 1308: if ($env{'browser.type'} eq 'netscape' &&
1309: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1310: # If this is netscape 4, we need to use the Layer tag
1311: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1312: } else {
1313: return "<span id='$name'>$origContent</span>";
1314: }
1315: }
1316:
1317: =pod
1318:
1.648 raeburn 1319: =item * &viewport_geometry_js
1.590 raeburn 1320:
1321: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1322:
1323: =cut
1324:
1325:
1326: sub viewport_geometry_js {
1327: return <<"GEOMETRY";
1328: var Geometry = {};
1329: function init_geometry() {
1330: if (Geometry.init) { return };
1331: Geometry.init=1;
1332: if (window.innerHeight) {
1333: Geometry.getViewportHeight = function() { return window.innerHeight; };
1334: Geometry.getViewportWidth = function() { return window.innerWidth; };
1335: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1336: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1337: }
1338: else if (document.documentElement && document.documentElement.clientHeight) {
1339: Geometry.getViewportHeight =
1340: function() { return document.documentElement.clientHeight; };
1341: Geometry.getViewportWidth =
1342: function() { return document.documentElement.clientWidth; };
1343:
1344: Geometry.getHorizontalScroll =
1345: function() { return document.documentElement.scrollLeft; };
1346: Geometry.getVerticalScroll =
1347: function() { return document.documentElement.scrollTop; };
1348: }
1349: else if (document.body.clientHeight) {
1350: Geometry.getViewportHeight =
1351: function() { return document.body.clientHeight; };
1352: Geometry.getViewportWidth =
1353: function() { return document.body.clientWidth; };
1354: Geometry.getHorizontalScroll =
1355: function() { return document.body.scrollLeft; };
1356: Geometry.getVerticalScroll =
1357: function() { return document.body.scrollTop; };
1358: }
1359: }
1360:
1361: GEOMETRY
1362: }
1363:
1364: =pod
1365:
1.648 raeburn 1366: =item * &viewport_size_js()
1.590 raeburn 1367:
1368: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1369:
1370: =cut
1371:
1372: sub viewport_size_js {
1373: my $geometry = &viewport_geometry_js();
1374: return <<"DIMS";
1375:
1376: $geometry
1377:
1378: function getViewportDims(width,height) {
1379: init_geometry();
1380: width.value = Geometry.getViewportWidth();
1381: height.value = Geometry.getViewportHeight();
1382: return;
1383: }
1384:
1385: DIMS
1386: }
1387:
1388: =pod
1389:
1.648 raeburn 1390: =item * &resize_textarea_js()
1.565 albertel 1391:
1392: emits the needed javascript to resize a textarea to be as big as possible
1393:
1394: creates a function resize_textrea that takes two IDs first should be
1395: the id of the element to resize, second should be the id of a div that
1396: surrounds everything that comes after the textarea, this routine needs
1397: to be attached to the <body> for the onload and onresize events.
1398:
1.648 raeburn 1399: =back
1.565 albertel 1400:
1401: =cut
1402:
1403: sub resize_textarea_js {
1.590 raeburn 1404: my $geometry = &viewport_geometry_js();
1.565 albertel 1405: return <<"RESIZE";
1406: <script type="text/javascript">
1.824 bisitz 1407: // <![CDATA[
1.590 raeburn 1408: $geometry
1.565 albertel 1409:
1.588 albertel 1410: function getX(element) {
1411: var x = 0;
1412: while (element) {
1413: x += element.offsetLeft;
1414: element = element.offsetParent;
1415: }
1416: return x;
1417: }
1418: function getY(element) {
1419: var y = 0;
1420: while (element) {
1421: y += element.offsetTop;
1422: element = element.offsetParent;
1423: }
1424: return y;
1425: }
1426:
1427:
1.565 albertel 1428: function resize_textarea(textarea_id,bottom_id) {
1429: init_geometry();
1430: var textarea = document.getElementById(textarea_id);
1431: //alert(textarea);
1432:
1.588 albertel 1433: var textarea_top = getY(textarea);
1.565 albertel 1434: var textarea_height = textarea.offsetHeight;
1435: var bottom = document.getElementById(bottom_id);
1.588 albertel 1436: var bottom_top = getY(bottom);
1.565 albertel 1437: var bottom_height = bottom.offsetHeight;
1438: var window_height = Geometry.getViewportHeight();
1.588 albertel 1439: var fudge = 23;
1.565 albertel 1440: var new_height = window_height-fudge-textarea_top-bottom_height;
1441: if (new_height < 300) {
1442: new_height = 300;
1443: }
1444: textarea.style.height=new_height+'px';
1445: }
1.824 bisitz 1446: // ]]>
1.565 albertel 1447: </script>
1448: RESIZE
1449:
1450: }
1451:
1452: =pod
1453:
1.256 matthew 1454: =head1 Excel and CSV file utility routines
1455:
1456: =over 4
1457:
1458: =cut
1459:
1460: ###############################################################
1461: ###############################################################
1462:
1463: =pod
1464:
1.648 raeburn 1465: =item * &csv_translate($text)
1.37 matthew 1466:
1.185 www 1467: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1468: format.
1469:
1470: =cut
1471:
1.180 matthew 1472: ###############################################################
1473: ###############################################################
1.37 matthew 1474: sub csv_translate {
1475: my $text = shift;
1476: $text =~ s/\"/\"\"/g;
1.209 albertel 1477: $text =~ s/\n/ /g;
1.37 matthew 1478: return $text;
1479: }
1.180 matthew 1480:
1481: ###############################################################
1482: ###############################################################
1483:
1484: =pod
1485:
1.648 raeburn 1486: =item * &define_excel_formats()
1.180 matthew 1487:
1488: Define some commonly used Excel cell formats.
1489:
1490: Currently supported formats:
1491:
1492: =over 4
1493:
1494: =item header
1495:
1496: =item bold
1497:
1498: =item h1
1499:
1500: =item h2
1501:
1502: =item h3
1503:
1.256 matthew 1504: =item h4
1505:
1506: =item i
1507:
1.180 matthew 1508: =item date
1509:
1510: =back
1511:
1512: Inputs: $workbook
1513:
1514: Returns: $format, a hash reference.
1515:
1516: =cut
1517:
1518: ###############################################################
1519: ###############################################################
1520: sub define_excel_formats {
1521: my ($workbook) = @_;
1522: my $format;
1523: $format->{'header'} = $workbook->add_format(bold => 1,
1524: bottom => 1,
1525: align => 'center');
1526: $format->{'bold'} = $workbook->add_format(bold=>1);
1527: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1528: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1529: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1530: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1531: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1532: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1533: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1534: return $format;
1535: }
1536:
1537: ###############################################################
1538: ###############################################################
1.113 bowersj2 1539:
1540: =pod
1541:
1.648 raeburn 1542: =item * &create_workbook()
1.255 matthew 1543:
1544: Create an Excel worksheet. If it fails, output message on the
1545: request object and return undefs.
1546:
1547: Inputs: Apache request object
1548:
1549: Returns (undef) on failure,
1550: Excel worksheet object, scalar with filename, and formats
1551: from &Apache::loncommon::define_excel_formats on success
1552:
1553: =cut
1554:
1555: ###############################################################
1556: ###############################################################
1557: sub create_workbook {
1558: my ($r) = @_;
1559: #
1560: # Create the excel spreadsheet
1561: my $filename = '/prtspool/'.
1.258 albertel 1562: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1563: time.'_'.rand(1000000000).'.xls';
1564: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1565: if (! defined($workbook)) {
1566: $r->log_error("Error creating excel spreadsheet $filename: $!");
1567: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1568: "This error has been logged. ".
1569: "Please alert your LON-CAPA administrator").
1570: '</p>');
1571: return (undef);
1572: }
1573: #
1574: $workbook->set_tempdir('/home/httpd/perl/tmp');
1575: #
1576: my $format = &Apache::loncommon::define_excel_formats($workbook);
1577: return ($workbook,$filename,$format);
1578: }
1579:
1580: ###############################################################
1581: ###############################################################
1582:
1583: =pod
1584:
1.648 raeburn 1585: =item * &create_text_file()
1.113 bowersj2 1586:
1.542 raeburn 1587: Create a file to write to and eventually make available to the user.
1.256 matthew 1588: If file creation fails, outputs an error message on the request object and
1589: return undefs.
1.113 bowersj2 1590:
1.256 matthew 1591: Inputs: Apache request object, and file suffix
1.113 bowersj2 1592:
1.256 matthew 1593: Returns (undef) on failure,
1594: Filehandle and filename on success.
1.113 bowersj2 1595:
1596: =cut
1597:
1.256 matthew 1598: ###############################################################
1599: ###############################################################
1600: sub create_text_file {
1601: my ($r,$suffix) = @_;
1602: if (! defined($suffix)) { $suffix = 'txt'; };
1603: my $fh;
1604: my $filename = '/prtspool/'.
1.258 albertel 1605: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1606: time.'_'.rand(1000000000).'.'.$suffix;
1607: $fh = Apache::File->new('>/home/httpd'.$filename);
1608: if (! defined($fh)) {
1609: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1610: $r->print(&mt('Problems occurred in creating the output file. '
1611: .'This error has been logged. '
1612: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1613: }
1.256 matthew 1614: return ($fh,$filename)
1.113 bowersj2 1615: }
1616:
1617:
1.256 matthew 1618: =pod
1.113 bowersj2 1619:
1620: =back
1621:
1622: =cut
1.37 matthew 1623:
1624: ###############################################################
1.33 matthew 1625: ## Home server <option> list generating code ##
1626: ###############################################################
1.35 matthew 1627:
1.169 www 1628: # ------------------------------------------
1629:
1630: sub domain_select {
1631: my ($name,$value,$multiple)=@_;
1632: my %domains=map {
1.514 albertel 1633: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1634: } &Apache::lonnet::all_domains();
1.169 www 1635: if ($multiple) {
1636: $domains{''}=&mt('Any domain');
1.550 albertel 1637: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1638: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1639: } else {
1.550 albertel 1640: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1641: return &select_form($name,$value,%domains);
1642: }
1643: }
1644:
1.282 albertel 1645: #-------------------------------------------
1646:
1647: =pod
1648:
1.519 raeburn 1649: =head1 Routines for form select boxes
1650:
1651: =over 4
1652:
1.648 raeburn 1653: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1654:
1655: Returns a string containing a <select> element int multiple mode
1656:
1657:
1658: Args:
1659: $name - name of the <select> element
1.506 raeburn 1660: $value - scalar or array ref of values that should already be selected
1.282 albertel 1661: $size - number of rows long the select element is
1.283 albertel 1662: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1663: (shown text should already have been &mt())
1.506 raeburn 1664: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1665:
1.282 albertel 1666: =cut
1667:
1668: #-------------------------------------------
1.169 www 1669: sub multiple_select_form {
1.284 albertel 1670: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1671: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1672: my $output='';
1.191 matthew 1673: if (! defined($size)) {
1674: $size = 4;
1.283 albertel 1675: if (scalar(keys(%$hash))<4) {
1676: $size = scalar(keys(%$hash));
1.191 matthew 1677: }
1678: }
1.734 bisitz 1679: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1680: my @order;
1.506 raeburn 1681: if (ref($order) eq 'ARRAY') {
1682: @order = @{$order};
1683: } else {
1684: @order = sort(keys(%$hash));
1.501 banghart 1685: }
1686: if (exists($$hash{'select_form_order'})) {
1687: @order = @{$$hash{'select_form_order'}};
1688: }
1689:
1.284 albertel 1690: foreach my $key (@order) {
1.356 albertel 1691: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1692: $output.='selected="selected" ' if ($selected{$key});
1693: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1694: }
1695: $output.="</select>\n";
1696: return $output;
1697: }
1698:
1.88 www 1699: #-------------------------------------------
1700:
1701: =pod
1702:
1.648 raeburn 1703: =item * &select_form($defdom,$name,%hash)
1.88 www 1704:
1705: Returns a string containing a <select name='$name' size='1'> form to
1706: allow a user to select options from a hash option_name => displayed text.
1707: See lonrights.pm for an example invocation and use.
1708:
1709: =cut
1710:
1711: #-------------------------------------------
1712: sub select_form {
1713: my ($def,$name,%hash) = @_;
1714: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1715: my @keys;
1716: if (exists($hash{'select_form_order'})) {
1717: @keys=@{$hash{'select_form_order'}};
1718: } else {
1719: @keys=sort(keys(%hash));
1720: }
1.356 albertel 1721: foreach my $key (@keys) {
1722: $selectform.=
1723: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1724: ($key eq $def ? 'selected="selected" ' : '').
1725: ">".&mt($hash{$key})."</option>\n";
1.88 www 1726: }
1727: $selectform.="</select>";
1728: return $selectform;
1729: }
1730:
1.475 www 1731: # For display filters
1732:
1733: sub display_filter {
1734: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1735: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1736: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1737: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1738: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1739: '</label></span> <span class="LC_nobreak">'.
1.475 www 1740: &mt('Filter [_1]',
1.477 www 1741: &select_form($env{'form.displayfilter'},
1742: 'displayfilter',
1743: ('currentfolder' => 'Current folder/page',
1744: 'containing' => 'Containing phrase',
1745: 'none' => 'None'))).
1.714 bisitz 1746: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1747: }
1748:
1.167 www 1749: sub gradeleveldescription {
1750: my $gradelevel=shift;
1751: my %gradelevels=(0 => 'Not specified',
1752: 1 => 'Grade 1',
1753: 2 => 'Grade 2',
1754: 3 => 'Grade 3',
1755: 4 => 'Grade 4',
1756: 5 => 'Grade 5',
1757: 6 => 'Grade 6',
1758: 7 => 'Grade 7',
1759: 8 => 'Grade 8',
1760: 9 => 'Grade 9',
1761: 10 => 'Grade 10',
1762: 11 => 'Grade 11',
1763: 12 => 'Grade 12',
1764: 13 => 'Grade 13',
1765: 14 => '100 Level',
1766: 15 => '200 Level',
1767: 16 => '300 Level',
1768: 17 => '400 Level',
1769: 18 => 'Graduate Level');
1770: return &mt($gradelevels{$gradelevel});
1771: }
1772:
1.163 www 1773: sub select_level_form {
1774: my ($deflevel,$name)=@_;
1775: unless ($deflevel) { $deflevel=0; }
1.167 www 1776: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1777: for (my $i=0; $i<=18; $i++) {
1778: $selectform.="<option value=\"$i\" ".
1.253 albertel 1779: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1780: ">".&gradeleveldescription($i)."</option>\n";
1781: }
1782: $selectform.="</select>";
1783: return $selectform;
1.163 www 1784: }
1.167 www 1785:
1.35 matthew 1786: #-------------------------------------------
1787:
1.45 matthew 1788: =pod
1789:
1.743 raeburn 1790: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1791:
1792: Returns a string containing a <select name='$name' size='1'> form to
1793: allow a user to select the domain to preform an operation in.
1794: See loncreateuser.pm for an example invocation and use.
1795:
1.90 www 1796: If the $includeempty flag is set, it also includes an empty choice ("no domain
1797: selected");
1798:
1.743 raeburn 1799: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1800:
1801: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1802:
1.35 matthew 1803: =cut
1804:
1805: #-------------------------------------------
1.34 matthew 1806: sub select_dom_form {
1.743 raeburn 1807: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1808: my $onchange;
1809: if ($autosubmit) {
1810: $onchange = ' onchange="this.form.submit()"';
1811: }
1.550 albertel 1812: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1813: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1814: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1815: foreach my $dom (@domains) {
1816: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1817: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1818: if ($showdomdesc) {
1819: if ($dom ne '') {
1820: my $domdesc = &Apache::lonnet::domain($dom,'description');
1821: if ($domdesc ne '') {
1822: $selectdomain .= ' ('.$domdesc.')';
1823: }
1824: }
1825: }
1826: $selectdomain .= "</option>\n";
1.34 matthew 1827: }
1828: $selectdomain.="</select>";
1829: return $selectdomain;
1830: }
1831:
1.35 matthew 1832: #-------------------------------------------
1833:
1.45 matthew 1834: =pod
1835:
1.648 raeburn 1836: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1837:
1.586 raeburn 1838: input: 4 arguments (two required, two optional) -
1839: $domain - domain of new user
1840: $name - name of form element
1841: $default - Value of 'default' causes a default item to be first
1842: option, and selected by default.
1843: $hide - Value of 'hide' causes hiding of the name of the server,
1844: if 1 server found, or default, if 0 found.
1.594 raeburn 1845: output: returns 2 items:
1.586 raeburn 1846: (a) form element which contains either:
1847: (i) <select name="$name">
1848: <option value="$hostid1">$hostid $servers{$hostid}</option>
1849: <option value="$hostid2">$hostid $servers{$hostid}</option>
1850: </select>
1851: form item if there are multiple library servers in $domain, or
1852: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1853: if there is only one library server in $domain.
1854:
1855: (b) number of library servers found.
1856:
1857: See loncreateuser.pm for example of use.
1.35 matthew 1858:
1859: =cut
1860:
1861: #-------------------------------------------
1.586 raeburn 1862: sub home_server_form_item {
1863: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1864: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1865: my $result;
1866: my $numlib = keys(%servers);
1867: if ($numlib > 1) {
1868: $result .= '<select name="'.$name.'" />'."\n";
1869: if ($default) {
1.804 bisitz 1870: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1871: '</option>'."\n";
1872: }
1873: foreach my $hostid (sort(keys(%servers))) {
1874: $result.= '<option value="'.$hostid.'">'.
1875: $hostid.' '.$servers{$hostid}."</option>\n";
1876: }
1877: $result .= '</select>'."\n";
1878: } elsif ($numlib == 1) {
1879: my $hostid;
1880: foreach my $item (keys(%servers)) {
1881: $hostid = $item;
1882: }
1883: $result .= '<input type="hidden" name="'.$name.'" value="'.
1884: $hostid.'" />';
1885: if (!$hide) {
1886: $result .= $hostid.' '.$servers{$hostid};
1887: }
1888: $result .= "\n";
1889: } elsif ($default) {
1890: $result .= '<input type="hidden" name="'.$name.
1891: '" value="default" />';
1892: if (!$hide) {
1893: $result .= &mt('default');
1894: }
1895: $result .= "\n";
1.33 matthew 1896: }
1.586 raeburn 1897: return ($result,$numlib);
1.33 matthew 1898: }
1.112 bowersj2 1899:
1900: =pod
1901:
1.534 albertel 1902: =back
1903:
1.112 bowersj2 1904: =cut
1.87 matthew 1905:
1906: ###############################################################
1.112 bowersj2 1907: ## Decoding User Agent ##
1.87 matthew 1908: ###############################################################
1909:
1910: =pod
1911:
1.112 bowersj2 1912: =head1 Decoding the User Agent
1913:
1914: =over 4
1915:
1916: =item * &decode_user_agent()
1.87 matthew 1917:
1918: Inputs: $r
1919:
1920: Outputs:
1921:
1922: =over 4
1923:
1.112 bowersj2 1924: =item * $httpbrowser
1.87 matthew 1925:
1.112 bowersj2 1926: =item * $clientbrowser
1.87 matthew 1927:
1.112 bowersj2 1928: =item * $clientversion
1.87 matthew 1929:
1.112 bowersj2 1930: =item * $clientmathml
1.87 matthew 1931:
1.112 bowersj2 1932: =item * $clientunicode
1.87 matthew 1933:
1.112 bowersj2 1934: =item * $clientos
1.87 matthew 1935:
1936: =back
1937:
1.157 matthew 1938: =back
1939:
1.87 matthew 1940: =cut
1941:
1942: ###############################################################
1943: ###############################################################
1944: sub decode_user_agent {
1.247 albertel 1945: my ($r)=@_;
1.87 matthew 1946: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1947: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1948: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1949: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1950: my $clientbrowser='unknown';
1951: my $clientversion='0';
1952: my $clientmathml='';
1953: my $clientunicode='0';
1954: for (my $i=0;$i<=$#browsertype;$i++) {
1955: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1956: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1957: $clientbrowser=$bname;
1958: $httpbrowser=~/$vreg/i;
1959: $clientversion=$1;
1960: $clientmathml=($clientversion>=$minv);
1961: $clientunicode=($clientversion>=$univ);
1962: }
1963: }
1964: my $clientos='unknown';
1965: if (($httpbrowser=~/linux/i) ||
1966: ($httpbrowser=~/unix/i) ||
1967: ($httpbrowser=~/ux/i) ||
1968: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1969: if (($httpbrowser=~/vax/i) ||
1970: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1971: if ($httpbrowser=~/next/i) { $clientos='next'; }
1972: if (($httpbrowser=~/mac/i) ||
1973: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1974: if ($httpbrowser=~/win/i) { $clientos='win'; }
1975: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1976: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1977: $clientunicode,$clientos,);
1978: }
1979:
1.32 matthew 1980: ###############################################################
1981: ## Authentication changing form generation subroutines ##
1982: ###############################################################
1983: ##
1984: ## All of the authform_xxxxxxx subroutines take their inputs in a
1985: ## hash, and have reasonable default values.
1986: ##
1987: ## formname = the name given in the <form> tag.
1.35 matthew 1988: #-------------------------------------------
1989:
1.45 matthew 1990: =pod
1991:
1.112 bowersj2 1992: =head1 Authentication Routines
1993:
1994: =over 4
1995:
1.648 raeburn 1996: =item * &authform_xxxxxx()
1.35 matthew 1997:
1998: The authform_xxxxxx subroutines provide javascript and html forms which
1999: handle some of the conveniences required for authentication forms.
2000: This is not an optimal method, but it works.
2001:
2002: =over 4
2003:
1.112 bowersj2 2004: =item * authform_header
1.35 matthew 2005:
1.112 bowersj2 2006: =item * authform_authorwarning
1.35 matthew 2007:
1.112 bowersj2 2008: =item * authform_nochange
1.35 matthew 2009:
1.112 bowersj2 2010: =item * authform_kerberos
1.35 matthew 2011:
1.112 bowersj2 2012: =item * authform_internal
1.35 matthew 2013:
1.112 bowersj2 2014: =item * authform_filesystem
1.35 matthew 2015:
2016: =back
2017:
1.648 raeburn 2018: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2019:
1.35 matthew 2020: =cut
2021:
2022: #-------------------------------------------
1.32 matthew 2023: sub authform_header{
2024: my %in = (
2025: formname => 'cu',
1.80 albertel 2026: kerb_def_dom => '',
1.32 matthew 2027: @_,
2028: );
2029: $in{'formname'} = 'document.' . $in{'formname'};
2030: my $result='';
1.80 albertel 2031:
2032: #---------------------------------------------- Code for upper case translation
2033: my $Javascript_toUpperCase;
2034: unless ($in{kerb_def_dom}) {
2035: $Javascript_toUpperCase =<<"END";
2036: switch (choice) {
2037: case 'krb': currentform.elements[choicearg].value =
2038: currentform.elements[choicearg].value.toUpperCase();
2039: break;
2040: default:
2041: }
2042: END
2043: } else {
2044: $Javascript_toUpperCase = "";
2045: }
2046:
1.165 raeburn 2047: my $radioval = "'nochange'";
1.591 raeburn 2048: if (defined($in{'curr_authtype'})) {
2049: if ($in{'curr_authtype'} ne '') {
2050: $radioval = "'".$in{'curr_authtype'}."arg'";
2051: }
1.174 matthew 2052: }
1.165 raeburn 2053: my $argfield = 'null';
1.591 raeburn 2054: if (defined($in{'mode'})) {
1.165 raeburn 2055: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2056: if (defined($in{'curr_autharg'})) {
2057: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2058: $argfield = "'$in{'curr_autharg'}'";
2059: }
2060: }
2061: }
2062: }
2063:
1.32 matthew 2064: $result.=<<"END";
2065: var current = new Object();
1.165 raeburn 2066: current.radiovalue = $radioval;
2067: current.argfield = $argfield;
1.32 matthew 2068:
2069: function changed_radio(choice,currentform) {
2070: var choicearg = choice + 'arg';
2071: // If a radio button in changed, we need to change the argfield
2072: if (current.radiovalue != choice) {
2073: current.radiovalue = choice;
2074: if (current.argfield != null) {
2075: currentform.elements[current.argfield].value = '';
2076: }
2077: if (choice == 'nochange') {
2078: current.argfield = null;
2079: } else {
2080: current.argfield = choicearg;
2081: switch(choice) {
2082: case 'krb':
2083: currentform.elements[current.argfield].value =
2084: "$in{'kerb_def_dom'}";
2085: break;
2086: default:
2087: break;
2088: }
2089: }
2090: }
2091: return;
2092: }
1.22 www 2093:
1.32 matthew 2094: function changed_text(choice,currentform) {
2095: var choicearg = choice + 'arg';
2096: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2097: $Javascript_toUpperCase
1.32 matthew 2098: // clear old field
2099: if ((current.argfield != choicearg) && (current.argfield != null)) {
2100: currentform.elements[current.argfield].value = '';
2101: }
2102: current.argfield = choicearg;
2103: }
2104: set_auth_radio_buttons(choice,currentform);
2105: return;
1.20 www 2106: }
1.32 matthew 2107:
2108: function set_auth_radio_buttons(newvalue,currentform) {
2109: var i=0;
2110: while (i < currentform.login.length) {
2111: if (currentform.login[i].value == newvalue) { break; }
2112: i++;
2113: }
2114: if (i == currentform.login.length) {
2115: return;
2116: }
2117: current.radiovalue = newvalue;
2118: currentform.login[i].checked = true;
2119: return;
2120: }
2121: END
2122: return $result;
2123: }
2124:
2125: sub authform_authorwarning{
2126: my $result='';
1.144 matthew 2127: $result='<i>'.
2128: &mt('As a general rule, only authors or co-authors should be '.
2129: 'filesystem authenticated '.
2130: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2131: return $result;
2132: }
2133:
2134: sub authform_nochange{
2135: my %in = (
2136: formname => 'document.cu',
2137: kerb_def_dom => 'MSU.EDU',
2138: @_,
2139: );
1.586 raeburn 2140: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2141: my $result;
2142: if (keys(%can_assign) == 0) {
2143: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2144: } else {
2145: $result = '<label>'.&mt('[_1] Do not change login data',
2146: '<input type="radio" name="login" value="nochange" '.
2147: 'checked="checked" onclick="'.
1.281 albertel 2148: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2149: '</label>';
1.586 raeburn 2150: }
1.32 matthew 2151: return $result;
2152: }
2153:
1.591 raeburn 2154: sub authform_kerberos {
1.32 matthew 2155: my %in = (
2156: formname => 'document.cu',
2157: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2158: kerb_def_auth => 'krb4',
1.32 matthew 2159: @_,
2160: );
1.586 raeburn 2161: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2162: $autharg,$jscall);
2163: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2164: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2165: $check5 = ' checked="checked"';
1.80 albertel 2166: } else {
1.772 bisitz 2167: $check4 = ' checked="checked"';
1.80 albertel 2168: }
1.165 raeburn 2169: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2170: if (defined($in{'curr_authtype'})) {
2171: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2172: $krbcheck = ' checked="checked"';
1.623 raeburn 2173: if (defined($in{'mode'})) {
2174: if ($in{'mode'} eq 'modifyuser') {
2175: $krbcheck = '';
2176: }
2177: }
1.591 raeburn 2178: if (defined($in{'curr_kerb_ver'})) {
2179: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2180: $check5 = ' checked="checked"';
1.591 raeburn 2181: $check4 = '';
2182: } else {
1.772 bisitz 2183: $check4 = ' checked="checked"';
1.591 raeburn 2184: $check5 = '';
2185: }
1.586 raeburn 2186: }
1.591 raeburn 2187: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2188: $krbarg = $in{'curr_autharg'};
2189: }
1.586 raeburn 2190: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2191: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2192: $result =
2193: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2194: $in{'curr_autharg'},$krbver);
2195: } else {
2196: $result =
2197: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2198: }
2199: return $result;
2200: }
2201: }
2202: } else {
2203: if ($authnum == 1) {
1.784 bisitz 2204: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2205: }
2206: }
1.586 raeburn 2207: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2208: return;
1.587 raeburn 2209: } elsif ($authtype eq '') {
1.591 raeburn 2210: if (defined($in{'mode'})) {
1.587 raeburn 2211: if ($in{'mode'} eq 'modifycourse') {
2212: if ($authnum == 1) {
1.784 bisitz 2213: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2214: }
2215: }
2216: }
1.586 raeburn 2217: }
2218: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2219: if ($authtype eq '') {
2220: $authtype = '<input type="radio" name="login" value="krb" '.
2221: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2222: $krbcheck.' />';
2223: }
2224: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2225: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2226: $in{'curr_authtype'} eq 'krb5') ||
2227: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2228: $in{'curr_authtype'} eq 'krb4')) {
2229: $result .= &mt
1.144 matthew 2230: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2231: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2232: '<label>'.$authtype,
1.281 albertel 2233: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2234: 'value="'.$krbarg.'" '.
1.144 matthew 2235: 'onchange="'.$jscall.'" />',
1.281 albertel 2236: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2237: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2238: '</label>');
1.586 raeburn 2239: } elsif ($can_assign{'krb4'}) {
2240: $result .= &mt
2241: ('[_1] Kerberos authenticated with domain [_2] '.
2242: '[_3] Version 4 [_4]',
2243: '<label>'.$authtype,
2244: '</label><input type="text" size="10" name="krbarg" '.
2245: 'value="'.$krbarg.'" '.
2246: 'onchange="'.$jscall.'" />',
2247: '<label><input type="hidden" name="krbver" value="4" />',
2248: '</label>');
2249: } elsif ($can_assign{'krb5'}) {
2250: $result .= &mt
2251: ('[_1] Kerberos authenticated with domain [_2] '.
2252: '[_3] Version 5 [_4]',
2253: '<label>'.$authtype,
2254: '</label><input type="text" size="10" name="krbarg" '.
2255: 'value="'.$krbarg.'" '.
2256: 'onchange="'.$jscall.'" />',
2257: '<label><input type="hidden" name="krbver" value="5" />',
2258: '</label>');
2259: }
1.32 matthew 2260: return $result;
2261: }
2262:
2263: sub authform_internal{
1.586 raeburn 2264: my %in = (
1.32 matthew 2265: formname => 'document.cu',
2266: kerb_def_dom => 'MSU.EDU',
2267: @_,
2268: );
1.586 raeburn 2269: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2270: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2271: if (defined($in{'curr_authtype'})) {
2272: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2273: if ($can_assign{'int'}) {
1.772 bisitz 2274: $intcheck = 'checked="checked" ';
1.623 raeburn 2275: if (defined($in{'mode'})) {
2276: if ($in{'mode'} eq 'modifyuser') {
2277: $intcheck = '';
2278: }
2279: }
1.591 raeburn 2280: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2281: $intarg = $in{'curr_autharg'};
2282: }
2283: } else {
2284: $result = &mt('Currently internally authenticated.');
2285: return $result;
1.165 raeburn 2286: }
2287: }
1.586 raeburn 2288: } else {
2289: if ($authnum == 1) {
1.784 bisitz 2290: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2291: }
2292: }
2293: if (!$can_assign{'int'}) {
2294: return;
1.587 raeburn 2295: } elsif ($authtype eq '') {
1.591 raeburn 2296: if (defined($in{'mode'})) {
1.587 raeburn 2297: if ($in{'mode'} eq 'modifycourse') {
2298: if ($authnum == 1) {
1.784 bisitz 2299: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2300: }
2301: }
2302: }
1.165 raeburn 2303: }
1.586 raeburn 2304: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2305: if ($authtype eq '') {
2306: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2307: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2308: }
1.605 bisitz 2309: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2310: $intarg.'" onchange="'.$jscall.'" />';
2311: $result = &mt
1.144 matthew 2312: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2313: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2314: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2315: return $result;
2316: }
2317:
2318: sub authform_local{
2319: my %in = (
2320: formname => 'document.cu',
2321: kerb_def_dom => 'MSU.EDU',
2322: @_,
2323: );
1.586 raeburn 2324: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2325: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2326: if (defined($in{'curr_authtype'})) {
2327: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2328: if ($can_assign{'loc'}) {
1.772 bisitz 2329: $loccheck = 'checked="checked" ';
1.623 raeburn 2330: if (defined($in{'mode'})) {
2331: if ($in{'mode'} eq 'modifyuser') {
2332: $loccheck = '';
2333: }
2334: }
1.591 raeburn 2335: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2336: $locarg = $in{'curr_autharg'};
2337: }
2338: } else {
2339: $result = &mt('Currently using local (institutional) authentication.');
2340: return $result;
1.165 raeburn 2341: }
2342: }
1.586 raeburn 2343: } else {
2344: if ($authnum == 1) {
1.784 bisitz 2345: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2346: }
2347: }
2348: if (!$can_assign{'loc'}) {
2349: return;
1.587 raeburn 2350: } elsif ($authtype eq '') {
1.591 raeburn 2351: if (defined($in{'mode'})) {
1.587 raeburn 2352: if ($in{'mode'} eq 'modifycourse') {
2353: if ($authnum == 1) {
1.784 bisitz 2354: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2355: }
2356: }
2357: }
1.165 raeburn 2358: }
1.586 raeburn 2359: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2360: if ($authtype eq '') {
2361: $authtype = '<input type="radio" name="login" value="loc" '.
2362: $loccheck.' onchange="'.$jscall.'" onclick="'.
2363: $jscall.'" />';
2364: }
2365: $autharg = '<input type="text" size="10" name="locarg" value="'.
2366: $locarg.'" onchange="'.$jscall.'" />';
2367: $result = &mt('[_1] Local Authentication with argument [_2]',
2368: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2369: return $result;
2370: }
2371:
2372: sub authform_filesystem{
2373: my %in = (
2374: formname => 'document.cu',
2375: kerb_def_dom => 'MSU.EDU',
2376: @_,
2377: );
1.586 raeburn 2378: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2379: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2380: if (defined($in{'curr_authtype'})) {
2381: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2382: if ($can_assign{'fsys'}) {
1.772 bisitz 2383: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2384: if (defined($in{'mode'})) {
2385: if ($in{'mode'} eq 'modifyuser') {
2386: $fsyscheck = '';
2387: }
2388: }
1.586 raeburn 2389: } else {
2390: $result = &mt('Currently Filesystem Authenticated.');
2391: return $result;
2392: }
2393: }
2394: } else {
2395: if ($authnum == 1) {
1.784 bisitz 2396: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2397: }
2398: }
2399: if (!$can_assign{'fsys'}) {
2400: return;
1.587 raeburn 2401: } elsif ($authtype eq '') {
1.591 raeburn 2402: if (defined($in{'mode'})) {
1.587 raeburn 2403: if ($in{'mode'} eq 'modifycourse') {
2404: if ($authnum == 1) {
1.784 bisitz 2405: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2406: }
2407: }
2408: }
1.586 raeburn 2409: }
2410: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2411: if ($authtype eq '') {
2412: $authtype = '<input type="radio" name="login" value="fsys" '.
2413: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2414: $jscall.'" />';
2415: }
2416: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2417: ' onchange="'.$jscall.'" />';
2418: $result = &mt
1.144 matthew 2419: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2420: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2421: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2422: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2423: 'onchange="'.$jscall.'" />');
1.32 matthew 2424: return $result;
2425: }
2426:
1.586 raeburn 2427: sub get_assignable_auth {
2428: my ($dom) = @_;
2429: if ($dom eq '') {
2430: $dom = $env{'request.role.domain'};
2431: }
2432: my %can_assign = (
2433: krb4 => 1,
2434: krb5 => 1,
2435: int => 1,
2436: loc => 1,
2437: );
2438: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2439: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2440: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2441: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2442: my $context;
2443: if ($env{'request.role'} =~ /^au/) {
2444: $context = 'author';
2445: } elsif ($env{'request.role'} =~ /^dc/) {
2446: $context = 'domain';
2447: } elsif ($env{'request.course.id'}) {
2448: $context = 'course';
2449: }
2450: if ($context) {
2451: if (ref($authhash->{$context}) eq 'HASH') {
2452: %can_assign = %{$authhash->{$context}};
2453: }
2454: }
2455: }
2456: }
2457: my $authnum = 0;
2458: foreach my $key (keys(%can_assign)) {
2459: if ($can_assign{$key}) {
2460: $authnum ++;
2461: }
2462: }
2463: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2464: $authnum --;
2465: }
2466: return ($authnum,%can_assign);
2467: }
2468:
1.80 albertel 2469: ###############################################################
2470: ## Get Kerberos Defaults for Domain ##
2471: ###############################################################
2472: ##
2473: ## Returns default kerberos version and an associated argument
2474: ## as listed in file domain.tab. If not listed, provides
2475: ## appropriate default domain and kerberos version.
2476: ##
2477: #-------------------------------------------
2478:
2479: =pod
2480:
1.648 raeburn 2481: =item * &get_kerberos_defaults()
1.80 albertel 2482:
2483: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2484: version and domain. If not found, it defaults to version 4 and the
2485: domain of the server.
1.80 albertel 2486:
1.648 raeburn 2487: =over 4
2488:
1.80 albertel 2489: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2490:
1.648 raeburn 2491: =back
2492:
2493: =back
2494:
1.80 albertel 2495: =cut
2496:
2497: #-------------------------------------------
2498: sub get_kerberos_defaults {
2499: my $domain=shift;
1.641 raeburn 2500: my ($krbdef,$krbdefdom);
2501: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2502: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2503: $krbdef = $domdefaults{'auth_def'};
2504: $krbdefdom = $domdefaults{'auth_arg_def'};
2505: } else {
1.80 albertel 2506: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2507: my $krbdefdom=$1;
2508: $krbdefdom=~tr/a-z/A-Z/;
2509: $krbdef = "krb4";
2510: }
2511: return ($krbdef,$krbdefdom);
2512: }
1.112 bowersj2 2513:
1.32 matthew 2514:
1.46 matthew 2515: ###############################################################
2516: ## Thesaurus Functions ##
2517: ###############################################################
1.20 www 2518:
1.46 matthew 2519: =pod
1.20 www 2520:
1.112 bowersj2 2521: =head1 Thesaurus Functions
2522:
2523: =over 4
2524:
1.648 raeburn 2525: =item * &initialize_keywords()
1.46 matthew 2526:
2527: Initializes the package variable %Keywords if it is empty. Uses the
2528: package variable $thesaurus_db_file.
2529:
2530: =cut
2531:
2532: ###################################################
2533:
2534: sub initialize_keywords {
2535: return 1 if (scalar keys(%Keywords));
2536: # If we are here, %Keywords is empty, so fill it up
2537: # Make sure the file we need exists...
2538: if (! -e $thesaurus_db_file) {
2539: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2540: " failed because it does not exist");
2541: return 0;
2542: }
2543: # Set up the hash as a database
2544: my %thesaurus_db;
2545: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2546: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2547: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2548: $thesaurus_db_file);
2549: return 0;
2550: }
2551: # Get the average number of appearances of a word.
2552: my $avecount = $thesaurus_db{'average.count'};
2553: # Put keywords (those that appear > average) into %Keywords
2554: while (my ($word,$data)=each (%thesaurus_db)) {
2555: my ($count,undef) = split /:/,$data;
2556: $Keywords{$word}++ if ($count > $avecount);
2557: }
2558: untie %thesaurus_db;
2559: # Remove special values from %Keywords.
1.356 albertel 2560: foreach my $value ('total.count','average.count') {
2561: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2562: }
1.46 matthew 2563: return 1;
2564: }
2565:
2566: ###################################################
2567:
2568: =pod
2569:
1.648 raeburn 2570: =item * &keyword($word)
1.46 matthew 2571:
2572: Returns true if $word is a keyword. A keyword is a word that appears more
2573: than the average number of times in the thesaurus database. Calls
2574: &initialize_keywords
2575:
2576: =cut
2577:
2578: ###################################################
1.20 www 2579:
2580: sub keyword {
1.46 matthew 2581: return if (!&initialize_keywords());
2582: my $word=lc(shift());
2583: $word=~s/\W//g;
2584: return exists($Keywords{$word});
1.20 www 2585: }
1.46 matthew 2586:
2587: ###############################################################
2588:
2589: =pod
1.20 www 2590:
1.648 raeburn 2591: =item * &get_related_words()
1.46 matthew 2592:
1.160 matthew 2593: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2594: an array of words. If the keyword is not in the thesaurus, an empty array
2595: will be returned. The order of the words returned is determined by the
2596: database which holds them.
2597:
2598: Uses global $thesaurus_db_file.
2599:
2600: =cut
2601:
2602: ###############################################################
2603: sub get_related_words {
2604: my $keyword = shift;
2605: my %thesaurus_db;
2606: if (! -e $thesaurus_db_file) {
2607: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2608: "failed because the file does not exist");
2609: return ();
2610: }
2611: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2612: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2613: return ();
2614: }
2615: my @Words=();
1.429 www 2616: my $count=0;
1.46 matthew 2617: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2618: # The first element is the number of times
2619: # the word appears. We do not need it now.
1.429 www 2620: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2621: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2622: my $threshold=$mostfrequentcount/10;
2623: foreach my $possibleword (@RelatedWords) {
2624: my ($word,$wordcount)=split(/\,/,$possibleword);
2625: if ($wordcount>$threshold) {
2626: push(@Words,$word);
2627: $count++;
2628: if ($count>10) { last; }
2629: }
1.20 www 2630: }
2631: }
1.46 matthew 2632: untie %thesaurus_db;
2633: return @Words;
1.14 harris41 2634: }
1.46 matthew 2635:
1.112 bowersj2 2636: =pod
2637:
2638: =back
2639:
2640: =cut
1.61 www 2641:
2642: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2643: =pod
2644:
1.112 bowersj2 2645: =head1 User Name Functions
2646:
2647: =over 4
2648:
1.648 raeburn 2649: =item * &plainname($uname,$udom,$first)
1.81 albertel 2650:
1.112 bowersj2 2651: Takes a users logon name and returns it as a string in
1.226 albertel 2652: "first middle last generation" form
2653: if $first is set to 'lastname' then it returns it as
2654: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2655:
2656: =cut
1.61 www 2657:
1.295 www 2658:
1.81 albertel 2659: ###############################################################
1.61 www 2660: sub plainname {
1.226 albertel 2661: my ($uname,$udom,$first)=@_;
1.537 albertel 2662: return if (!defined($uname) || !defined($udom));
1.295 www 2663: my %names=&getnames($uname,$udom);
1.226 albertel 2664: my $name=&Apache::lonnet::format_name($names{'firstname'},
2665: $names{'middlename'},
2666: $names{'lastname'},
2667: $names{'generation'},$first);
2668: $name=~s/^\s+//;
1.62 www 2669: $name=~s/\s+$//;
2670: $name=~s/\s+/ /g;
1.353 albertel 2671: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2672: return $name;
1.61 www 2673: }
1.66 www 2674:
2675: # -------------------------------------------------------------------- Nickname
1.81 albertel 2676: =pod
2677:
1.648 raeburn 2678: =item * &nickname($uname,$udom)
1.81 albertel 2679:
2680: Gets a users name and returns it as a string as
2681:
2682: ""nickname""
1.66 www 2683:
1.81 albertel 2684: if the user has a nickname or
2685:
2686: "first middle last generation"
2687:
2688: if the user does not
2689:
2690: =cut
1.66 www 2691:
2692: sub nickname {
2693: my ($uname,$udom)=@_;
1.537 albertel 2694: return if (!defined($uname) || !defined($udom));
1.295 www 2695: my %names=&getnames($uname,$udom);
1.68 albertel 2696: my $name=$names{'nickname'};
1.66 www 2697: if ($name) {
2698: $name='"'.$name.'"';
2699: } else {
2700: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2701: $names{'lastname'}.' '.$names{'generation'};
2702: $name=~s/\s+$//;
2703: $name=~s/\s+/ /g;
2704: }
2705: return $name;
2706: }
2707:
1.295 www 2708: sub getnames {
2709: my ($uname,$udom)=@_;
1.537 albertel 2710: return if (!defined($uname) || !defined($udom));
1.433 albertel 2711: if ($udom eq 'public' && $uname eq 'public') {
2712: return ('lastname' => &mt('Public'));
2713: }
1.295 www 2714: my $id=$uname.':'.$udom;
2715: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2716: if ($cached) {
2717: return %{$names};
2718: } else {
2719: my %loadnames=&Apache::lonnet::get('environment',
2720: ['firstname','middlename','lastname','generation','nickname'],
2721: $udom,$uname);
2722: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2723: return %loadnames;
2724: }
2725: }
1.61 www 2726:
1.542 raeburn 2727: # -------------------------------------------------------------------- getemails
1.648 raeburn 2728:
1.542 raeburn 2729: =pod
2730:
1.648 raeburn 2731: =item * &getemails($uname,$udom)
1.542 raeburn 2732:
2733: Gets a user's email information and returns it as a hash with keys:
2734: notification, critnotification, permanentemail
2735:
2736: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2737: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2738:
1.648 raeburn 2739:
1.542 raeburn 2740: =cut
2741:
1.648 raeburn 2742:
1.466 albertel 2743: sub getemails {
2744: my ($uname,$udom)=@_;
2745: if ($udom eq 'public' && $uname eq 'public') {
2746: return;
2747: }
1.467 www 2748: if (!$udom) { $udom=$env{'user.domain'}; }
2749: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2750: my $id=$uname.':'.$udom;
2751: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2752: if ($cached) {
2753: return %{$names};
2754: } else {
2755: my %loadnames=&Apache::lonnet::get('environment',
2756: ['notification','critnotification',
2757: 'permanentemail'],
2758: $udom,$uname);
2759: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2760: return %loadnames;
2761: }
2762: }
2763:
1.551 albertel 2764: sub flush_email_cache {
2765: my ($uname,$udom)=@_;
2766: if (!$udom) { $udom =$env{'user.domain'}; }
2767: if (!$uname) { $uname=$env{'user.name'}; }
2768: return if ($udom eq 'public' && $uname eq 'public');
2769: my $id=$uname.':'.$udom;
2770: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2771: }
2772:
1.728 raeburn 2773: # -------------------------------------------------------------------- getlangs
2774:
2775: =pod
2776:
2777: =item * &getlangs($uname,$udom)
2778:
2779: Gets a user's language preference and returns it as a hash with key:
2780: language.
2781:
2782: =cut
2783:
2784:
2785: sub getlangs {
2786: my ($uname,$udom) = @_;
2787: if (!$udom) { $udom =$env{'user.domain'}; }
2788: if (!$uname) { $uname=$env{'user.name'}; }
2789: my $id=$uname.':'.$udom;
2790: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2791: if ($cached) {
2792: return %{$langs};
2793: } else {
2794: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2795: $udom,$uname);
2796: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2797: return %loadlangs;
2798: }
2799: }
2800:
2801: sub flush_langs_cache {
2802: my ($uname,$udom)=@_;
2803: if (!$udom) { $udom =$env{'user.domain'}; }
2804: if (!$uname) { $uname=$env{'user.name'}; }
2805: return if ($udom eq 'public' && $uname eq 'public');
2806: my $id=$uname.':'.$udom;
2807: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2808: }
2809:
1.61 www 2810: # ------------------------------------------------------------------ Screenname
1.81 albertel 2811:
2812: =pod
2813:
1.648 raeburn 2814: =item * &screenname($uname,$udom)
1.81 albertel 2815:
2816: Gets a users screenname and returns it as a string
2817:
2818: =cut
1.61 www 2819:
2820: sub screenname {
2821: my ($uname,$udom)=@_;
1.258 albertel 2822: if ($uname eq $env{'user.name'} &&
2823: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2824: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2825: return $names{'screenname'};
1.62 www 2826: }
2827:
1.212 albertel 2828:
1.802 bisitz 2829: # ------------------------------------------------------------- Confirm Wrapper
2830: =pod
2831:
2832: =item confirmwrapper
2833:
2834: Wrap messages about completion of operation in box
2835:
2836: =cut
2837:
2838: sub confirmwrapper {
2839: my ($message)=@_;
2840: if ($message) {
2841: return "\n".'<div class="LC_confirm_box">'."\n"
2842: .$message."\n"
2843: .'</div>'."\n";
2844: } else {
2845: return $message;
2846: }
2847: }
2848:
1.62 www 2849: # ------------------------------------------------------------- Message Wrapper
2850:
2851: sub messagewrapper {
1.369 www 2852: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2853: return
1.441 albertel 2854: '<a href="/adm/email?compose=individual&'.
2855: 'recname='.$username.'&recdom='.$domain.
2856: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2857: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2858: }
1.802 bisitz 2859:
1.74 www 2860: # --------------------------------------------------------------- Notes Wrapper
2861:
2862: sub noteswrapper {
2863: my ($link,$un,$do)=@_;
2864: return
2865: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2866: }
1.802 bisitz 2867:
1.62 www 2868: # ------------------------------------------------------------- Aboutme Wrapper
2869:
2870: sub aboutmewrapper {
1.166 www 2871: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2872: if (!defined($username) && !defined($domain)) {
2873: return;
2874: }
1.205 www 2875: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2876: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2877: }
2878:
2879: # ------------------------------------------------------------ Syllabus Wrapper
2880:
2881: sub syllabuswrapper {
1.707 bisitz 2882: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2883: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2884: }
1.14 harris41 2885:
1.802 bisitz 2886: # -----------------------------------------------------------------------------
2887:
1.208 matthew 2888: sub track_student_link {
1.268 albertel 2889: my ($linktext,$sname,$sdom,$target,$start) = @_;
2890: my $link ="/adm/trackstudent?";
1.208 matthew 2891: my $title = 'View recent activity';
2892: if (defined($sname) && $sname !~ /^\s*$/ &&
2893: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2894: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2895: $title .= ' of this student';
1.268 albertel 2896: }
1.208 matthew 2897: if (defined($target) && $target !~ /^\s*$/) {
2898: $target = qq{target="$target"};
2899: } else {
2900: $target = '';
2901: }
1.268 albertel 2902: if ($start) { $link.='&start='.$start; }
1.554 albertel 2903: $title = &mt($title);
2904: $linktext = &mt($linktext);
1.448 albertel 2905: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2906: &help_open_topic('View_recent_activity');
1.208 matthew 2907: }
2908:
1.781 raeburn 2909: sub slot_reservations_link {
2910: my ($linktext,$sname,$sdom,$target) = @_;
2911: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2912: my $title = 'View slot reservation history';
2913: if (defined($sname) && $sname !~ /^\s*$/ &&
2914: defined($sdom) && $sdom !~ /^\s*$/) {
2915: $link .= "&uname=$sname&udom=$sdom";
2916: $title .= ' of this student';
2917: }
2918: if (defined($target) && $target !~ /^\s*$/) {
2919: $target = qq{target="$target"};
2920: } else {
2921: $target = '';
2922: }
2923: $title = &mt($title);
2924: $linktext = &mt($linktext);
2925: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2926: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2927:
2928: }
2929:
1.508 www 2930: # ===================================================== Display a student photo
2931:
2932:
1.509 albertel 2933: sub student_image_tag {
1.508 www 2934: my ($domain,$user)=@_;
2935: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2936: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2937: return '<img src="'.$imgsrc.'" align="right" />';
2938: } else {
2939: return '';
2940: }
2941: }
2942:
1.112 bowersj2 2943: =pod
2944:
2945: =back
2946:
2947: =head1 Access .tab File Data
2948:
2949: =over 4
2950:
1.648 raeburn 2951: =item * &languageids()
1.112 bowersj2 2952:
2953: returns list of all language ids
2954:
2955: =cut
2956:
1.14 harris41 2957: sub languageids {
1.16 harris41 2958: return sort(keys(%language));
1.14 harris41 2959: }
2960:
1.112 bowersj2 2961: =pod
2962:
1.648 raeburn 2963: =item * &languagedescription()
1.112 bowersj2 2964:
2965: returns description of a specified language id
2966:
2967: =cut
2968:
1.14 harris41 2969: sub languagedescription {
1.125 www 2970: my $code=shift;
2971: return ($supported_language{$code}?'* ':'').
2972: $language{$code}.
1.126 www 2973: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2974: }
2975:
2976: sub plainlanguagedescription {
2977: my $code=shift;
2978: return $language{$code};
2979: }
2980:
2981: sub supportedlanguagecode {
2982: my $code=shift;
2983: return $supported_language{$code};
1.97 www 2984: }
2985:
1.112 bowersj2 2986: =pod
2987:
1.648 raeburn 2988: =item * ©rightids()
1.112 bowersj2 2989:
2990: returns list of all copyrights
2991:
2992: =cut
2993:
2994: sub copyrightids {
2995: return sort(keys(%cprtag));
2996: }
2997:
2998: =pod
2999:
1.648 raeburn 3000: =item * ©rightdescription()
1.112 bowersj2 3001:
3002: returns description of a specified copyright id
3003:
3004: =cut
3005:
3006: sub copyrightdescription {
1.166 www 3007: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3008: }
1.197 matthew 3009:
3010: =pod
3011:
1.648 raeburn 3012: =item * &source_copyrightids()
1.192 taceyjo1 3013:
3014: returns list of all source copyrights
3015:
3016: =cut
3017:
3018: sub source_copyrightids {
3019: return sort(keys(%scprtag));
3020: }
3021:
3022: =pod
3023:
1.648 raeburn 3024: =item * &source_copyrightdescription()
1.192 taceyjo1 3025:
3026: returns description of a specified source copyright id
3027:
3028: =cut
3029:
3030: sub source_copyrightdescription {
3031: return &mt($scprtag{shift(@_)});
3032: }
1.112 bowersj2 3033:
3034: =pod
3035:
1.648 raeburn 3036: =item * &filecategories()
1.112 bowersj2 3037:
3038: returns list of all file categories
3039:
3040: =cut
3041:
3042: sub filecategories {
3043: return sort(keys(%category_extensions));
3044: }
3045:
3046: =pod
3047:
1.648 raeburn 3048: =item * &filecategorytypes()
1.112 bowersj2 3049:
3050: returns list of file types belonging to a given file
3051: category
3052:
3053: =cut
3054:
3055: sub filecategorytypes {
1.356 albertel 3056: my ($cat) = @_;
3057: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3058: }
3059:
3060: =pod
3061:
1.648 raeburn 3062: =item * &fileembstyle()
1.112 bowersj2 3063:
3064: returns embedding style for a specified file type
3065:
3066: =cut
3067:
3068: sub fileembstyle {
3069: return $fe{lc(shift(@_))};
1.169 www 3070: }
3071:
1.351 www 3072: sub filemimetype {
3073: return $fm{lc(shift(@_))};
3074: }
3075:
1.169 www 3076:
3077: sub filecategoryselect {
3078: my ($name,$value)=@_;
1.189 matthew 3079: return &select_form($value,$name,
1.169 www 3080: '' => &mt('Any category'),
3081: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3082: }
3083:
3084: =pod
3085:
1.648 raeburn 3086: =item * &filedescription()
1.112 bowersj2 3087:
3088: returns description for a specified file type
3089:
3090: =cut
3091:
3092: sub filedescription {
1.188 matthew 3093: my $file_description = $fd{lc(shift())};
3094: $file_description =~ s:([\[\]]):~$1:g;
3095: return &mt($file_description);
1.112 bowersj2 3096: }
3097:
3098: =pod
3099:
1.648 raeburn 3100: =item * &filedescriptionex()
1.112 bowersj2 3101:
3102: returns description for a specified file type with
3103: extra formatting
3104:
3105: =cut
3106:
3107: sub filedescriptionex {
3108: my $ex=shift;
1.188 matthew 3109: my $file_description = $fd{lc($ex)};
3110: $file_description =~ s:([\[\]]):~$1:g;
3111: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3112: }
3113:
3114: # End of .tab access
3115: =pod
3116:
3117: =back
3118:
3119: =cut
3120:
3121: # ------------------------------------------------------------------ File Types
3122: sub fileextensions {
3123: return sort(keys(%fe));
3124: }
3125:
1.97 www 3126: # ----------------------------------------------------------- Display Languages
3127: # returns a hash with all desired display languages
3128: #
3129:
3130: sub display_languages {
3131: my %languages=();
1.695 raeburn 3132: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3133: $languages{$lang}=1;
1.97 www 3134: }
3135: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3136: if ($env{'form.displaylanguage'}) {
1.356 albertel 3137: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3138: $languages{$lang}=1;
1.97 www 3139: }
3140: }
3141: return %languages;
1.14 harris41 3142: }
3143:
1.582 albertel 3144: sub languages {
3145: my ($possible_langs) = @_;
1.695 raeburn 3146: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3147: if (!ref($possible_langs)) {
3148: if( wantarray ) {
3149: return @preferred_langs;
3150: } else {
3151: return $preferred_langs[0];
3152: }
3153: }
3154: my %possibilities = map { $_ => 1 } (@$possible_langs);
3155: my @preferred_possibilities;
3156: foreach my $preferred_lang (@preferred_langs) {
3157: if (exists($possibilities{$preferred_lang})) {
3158: push(@preferred_possibilities, $preferred_lang);
3159: }
3160: }
3161: if( wantarray ) {
3162: return @preferred_possibilities;
3163: }
3164: return $preferred_possibilities[0];
3165: }
3166:
1.742 raeburn 3167: sub user_lang {
3168: my ($touname,$toudom,$fromcid) = @_;
3169: my @userlangs;
3170: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3171: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3172: $env{'course.'.$fromcid.'.languages'}));
3173: } else {
3174: my %langhash = &getlangs($touname,$toudom);
3175: if ($langhash{'languages'} ne '') {
3176: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3177: } else {
3178: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3179: if ($domdefs{'lang_def'} ne '') {
3180: @userlangs = ($domdefs{'lang_def'});
3181: }
3182: }
3183: }
3184: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3185: my $user_lh = Apache::localize->get_handle(@languages);
3186: return $user_lh;
3187: }
3188:
3189:
1.112 bowersj2 3190: ###############################################################
3191: ## Student Answer Attempts ##
3192: ###############################################################
3193:
3194: =pod
3195:
3196: =head1 Alternate Problem Views
3197:
3198: =over 4
3199:
1.648 raeburn 3200: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3201: $getattempt, $regexp, $gradesub)
3202:
3203: Return string with previous attempt on problem. Arguments:
3204:
3205: =over 4
3206:
3207: =item * $symb: Problem, including path
3208:
3209: =item * $username: username of the desired student
3210:
3211: =item * $domain: domain of the desired student
1.14 harris41 3212:
1.112 bowersj2 3213: =item * $course: Course ID
1.14 harris41 3214:
1.112 bowersj2 3215: =item * $getattempt: Leave blank for all attempts, otherwise put
3216: something
1.14 harris41 3217:
1.112 bowersj2 3218: =item * $regexp: if string matches this regexp, the string will be
3219: sent to $gradesub
1.14 harris41 3220:
1.112 bowersj2 3221: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3222:
1.112 bowersj2 3223: =back
1.14 harris41 3224:
1.112 bowersj2 3225: The output string is a table containing all desired attempts, if any.
1.16 harris41 3226:
1.112 bowersj2 3227: =cut
1.1 albertel 3228:
3229: sub get_previous_attempt {
1.43 ng 3230: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3231: my $prevattempts='';
1.43 ng 3232: no strict 'refs';
1.1 albertel 3233: if ($symb) {
1.3 albertel 3234: my (%returnhash)=
3235: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3236: if ($returnhash{'version'}) {
3237: my %lasthash=();
3238: my $version;
3239: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3240: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3241: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3242: }
1.1 albertel 3243: }
1.596 albertel 3244: $prevattempts=&start_data_table().&start_data_table_header_row();
3245: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3246: foreach my $key (sort(keys(%lasthash))) {
3247: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3248: if ($#parts > 0) {
1.31 albertel 3249: my $data=$parts[-1];
3250: pop(@parts);
1.596 albertel 3251: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3252: } else {
1.41 ng 3253: if ($#parts == 0) {
3254: $prevattempts.='<th>'.$parts[0].'</th>';
3255: } else {
3256: $prevattempts.='<th>'.$ign.'</th>';
3257: }
1.31 albertel 3258: }
1.16 harris41 3259: }
1.596 albertel 3260: $prevattempts.=&end_data_table_header_row();
1.40 ng 3261: if ($getattempt eq '') {
3262: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3263: $prevattempts.=&start_data_table_row().
3264: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3265: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3266: my $value = &format_previous_attempt_value($key,
3267: $returnhash{$version.':'.$key});
3268: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3269: }
1.596 albertel 3270: $prevattempts.=&end_data_table_row();
1.40 ng 3271: }
1.1 albertel 3272: }
1.596 albertel 3273: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3274: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3275: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3276: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3277: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3278: }
1.596 albertel 3279: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3280: } else {
1.596 albertel 3281: $prevattempts=
3282: &start_data_table().&start_data_table_row().
3283: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3284: &end_data_table_row().&end_data_table();
1.1 albertel 3285: }
3286: } else {
1.596 albertel 3287: $prevattempts=
3288: &start_data_table().&start_data_table_row().
3289: '<td>'.&mt('No data.').'</td>'.
3290: &end_data_table_row().&end_data_table();
1.1 albertel 3291: }
1.10 albertel 3292: }
3293:
1.581 albertel 3294: sub format_previous_attempt_value {
3295: my ($key,$value) = @_;
3296: if ($key =~ /timestamp/) {
3297: $value = &Apache::lonlocal::locallocaltime($value);
3298: } elsif (ref($value) eq 'ARRAY') {
3299: $value = '('.join(', ', @{ $value }).')';
3300: } else {
3301: $value = &unescape($value);
3302: }
3303: return $value;
3304: }
3305:
3306:
1.107 albertel 3307: sub relative_to_absolute {
3308: my ($url,$output)=@_;
3309: my $parser=HTML::TokeParser->new(\$output);
3310: my $token;
3311: my $thisdir=$url;
3312: my @rlinks=();
3313: while ($token=$parser->get_token) {
3314: if ($token->[0] eq 'S') {
3315: if ($token->[1] eq 'a') {
3316: if ($token->[2]->{'href'}) {
3317: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3318: }
3319: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3320: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3321: } elsif ($token->[1] eq 'base') {
3322: $thisdir=$token->[2]->{'href'};
3323: }
3324: }
3325: }
3326: $thisdir=~s-/[^/]*$--;
1.356 albertel 3327: foreach my $link (@rlinks) {
1.726 raeburn 3328: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3329: ($link=~/^\//) ||
3330: ($link=~/^javascript:/i) ||
3331: ($link=~/^mailto:/i) ||
3332: ($link=~/^\#/)) {
3333: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3334: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3335: }
3336: }
3337: # -------------------------------------------------- Deal with Applet codebases
3338: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3339: return $output;
3340: }
3341:
1.112 bowersj2 3342: =pod
3343:
1.648 raeburn 3344: =item * &get_student_view()
1.112 bowersj2 3345:
3346: show a snapshot of what student was looking at
3347:
3348: =cut
3349:
1.10 albertel 3350: sub get_student_view {
1.186 albertel 3351: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3352: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3353: my (%form);
1.10 albertel 3354: my @elements=('symb','courseid','domain','username');
3355: foreach my $element (@elements) {
1.186 albertel 3356: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3357: }
1.186 albertel 3358: if (defined($moreenv)) {
3359: %form=(%form,%{$moreenv});
3360: }
1.236 albertel 3361: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3362: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3363: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3364: $userview=~s/\<body[^\>]*\>//gi;
3365: $userview=~s/\<\/body\>//gi;
3366: $userview=~s/\<html\>//gi;
3367: $userview=~s/\<\/html\>//gi;
3368: $userview=~s/\<head\>//gi;
3369: $userview=~s/\<\/head\>//gi;
3370: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3371: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3372: if (wantarray) {
3373: return ($userview,$response);
3374: } else {
3375: return $userview;
3376: }
3377: }
3378:
3379: sub get_student_view_with_retries {
3380: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3381:
3382: my $ok = 0; # True if we got a good response.
3383: my $content;
3384: my $response;
3385:
3386: # Try to get the student_view done. within the retries count:
3387:
3388: do {
3389: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3390: $ok = $response->is_success;
3391: if (!$ok) {
3392: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3393: }
3394: $retries--;
3395: } while (!$ok && ($retries > 0));
3396:
3397: if (!$ok) {
3398: $content = ''; # On error return an empty content.
3399: }
1.651 www 3400: if (wantarray) {
3401: return ($content, $response);
3402: } else {
3403: return $content;
3404: }
1.11 albertel 3405: }
3406:
1.112 bowersj2 3407: =pod
3408:
1.648 raeburn 3409: =item * &get_student_answers()
1.112 bowersj2 3410:
3411: show a snapshot of how student was answering problem
3412:
3413: =cut
3414:
1.11 albertel 3415: sub get_student_answers {
1.100 sakharuk 3416: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3417: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3418: my (%moreenv);
1.11 albertel 3419: my @elements=('symb','courseid','domain','username');
3420: foreach my $element (@elements) {
1.186 albertel 3421: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3422: }
1.186 albertel 3423: $moreenv{'grade_target'}='answer';
3424: %moreenv=(%form,%moreenv);
1.497 raeburn 3425: $feedurl = &Apache::lonnet::clutter($feedurl);
3426: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3427: return $userview;
1.1 albertel 3428: }
1.116 albertel 3429:
3430: =pod
3431:
3432: =item * &submlink()
3433:
1.242 albertel 3434: Inputs: $text $uname $udom $symb $target
1.116 albertel 3435:
3436: Returns: A link to grades.pm such as to see the SUBM view of a student
3437:
3438: =cut
3439:
3440: ###############################################
3441: sub submlink {
1.242 albertel 3442: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3443: if (!($uname && $udom)) {
3444: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3445: &Apache::lonnet::whichuser($symb);
1.116 albertel 3446: if (!$symb) { $symb=$cursymb; }
3447: }
1.254 matthew 3448: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3449: $symb=&escape($symb);
1.242 albertel 3450: if ($target) { $target="target=\"$target\""; }
3451: return '<a href="/adm/grades?&command=submission&'.
3452: 'symb='.$symb.'&student='.$uname.
3453: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3454: }
3455: ##############################################
3456:
3457: =pod
3458:
3459: =item * &pgrdlink()
3460:
3461: Inputs: $text $uname $udom $symb $target
3462:
3463: Returns: A link to grades.pm such as to see the PGRD view of a student
3464:
3465: =cut
3466:
3467: ###############################################
3468: sub pgrdlink {
3469: my $link=&submlink(@_);
3470: $link=~s/(&command=submission)/$1&showgrading=yes/;
3471: return $link;
3472: }
3473: ##############################################
3474:
3475: =pod
3476:
3477: =item * &pprmlink()
3478:
3479: Inputs: $text $uname $udom $symb $target
3480:
3481: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3482: student and a specific resource
1.242 albertel 3483:
3484: =cut
3485:
3486: ###############################################
3487: sub pprmlink {
3488: my ($text,$uname,$udom,$symb,$target)=@_;
3489: if (!($uname && $udom)) {
3490: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3491: &Apache::lonnet::whichuser($symb);
1.242 albertel 3492: if (!$symb) { $symb=$cursymb; }
3493: }
1.254 matthew 3494: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3495: $symb=&escape($symb);
1.242 albertel 3496: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3497: return '<a href="/adm/parmset?command=set&'.
3498: 'symb='.$symb.'&uname='.$uname.
3499: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3500: }
3501: ##############################################
1.37 matthew 3502:
1.112 bowersj2 3503: =pod
3504:
3505: =back
3506:
3507: =cut
3508:
1.37 matthew 3509: ###############################################
1.51 www 3510:
3511:
3512: sub timehash {
1.687 raeburn 3513: my ($thistime) = @_;
3514: my $timezone = &Apache::lonlocal::gettimezone();
3515: my $dt = DateTime->from_epoch(epoch => $thistime)
3516: ->set_time_zone($timezone);
3517: my $wday = $dt->day_of_week();
3518: if ($wday == 7) { $wday = 0; }
3519: return ( 'second' => $dt->second(),
3520: 'minute' => $dt->minute(),
3521: 'hour' => $dt->hour(),
3522: 'day' => $dt->day_of_month(),
3523: 'month' => $dt->month(),
3524: 'year' => $dt->year(),
3525: 'weekday' => $wday,
3526: 'dayyear' => $dt->day_of_year(),
3527: 'dlsav' => $dt->is_dst() );
1.51 www 3528: }
3529:
1.370 www 3530: sub utc_string {
3531: my ($date)=@_;
1.371 www 3532: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3533: }
3534:
1.51 www 3535: sub maketime {
3536: my %th=@_;
1.687 raeburn 3537: my ($epoch_time,$timezone,$dt);
3538: $timezone = &Apache::lonlocal::gettimezone();
3539: eval {
3540: $dt = DateTime->new( year => $th{'year'},
3541: month => $th{'month'},
3542: day => $th{'day'},
3543: hour => $th{'hour'},
3544: minute => $th{'minute'},
3545: second => $th{'second'},
3546: time_zone => $timezone,
3547: );
3548: };
3549: if (!$@) {
3550: $epoch_time = $dt->epoch;
3551: if ($epoch_time) {
3552: return $epoch_time;
3553: }
3554: }
1.51 www 3555: return POSIX::mktime(
3556: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3557: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3558: }
3559:
3560: #########################################
1.51 www 3561:
3562: sub findallcourses {
1.482 raeburn 3563: my ($roles,$uname,$udom) = @_;
1.355 albertel 3564: my %roles;
3565: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3566: my %courses;
1.51 www 3567: my $now=time;
1.482 raeburn 3568: if (!defined($uname)) {
3569: $uname = $env{'user.name'};
3570: }
3571: if (!defined($udom)) {
3572: $udom = $env{'user.domain'};
3573: }
3574: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3575: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3576: if (!%roles) {
3577: %roles = (
3578: cc => 1,
3579: in => 1,
3580: ep => 1,
3581: ta => 1,
3582: cr => 1,
3583: st => 1,
3584: );
3585: }
3586: foreach my $entry (keys(%roleshash)) {
3587: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3588: if ($trole =~ /^cr/) {
3589: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3590: } else {
3591: next if (!exists($roles{$trole}));
3592: }
3593: if ($tend) {
3594: next if ($tend < $now);
3595: }
3596: if ($tstart) {
3597: next if ($tstart > $now);
3598: }
3599: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3600: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3601: if ($secpart eq '') {
3602: ($cnum,$role) = split(/_/,$cnumpart);
3603: $sec = 'none';
3604: $realsec = '';
3605: } else {
3606: $cnum = $cnumpart;
3607: ($sec,$role) = split(/_/,$secpart);
3608: $realsec = $sec;
1.490 raeburn 3609: }
1.482 raeburn 3610: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3611: }
3612: } else {
3613: foreach my $key (keys(%env)) {
1.483 albertel 3614: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3615: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3616: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3617: next if ($role eq 'ca' || $role eq 'aa');
3618: next if (%roles && !exists($roles{$role}));
3619: my ($starttime,$endtime)=split(/\./,$env{$key});
3620: my $active=1;
3621: if ($starttime) {
3622: if ($now<$starttime) { $active=0; }
3623: }
3624: if ($endtime) {
3625: if ($now>$endtime) { $active=0; }
3626: }
3627: if ($active) {
3628: if ($sec eq '') {
3629: $sec = 'none';
3630: }
3631: $courses{$cdom.'_'.$cnum}{$sec} =
3632: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3633: }
3634: }
1.51 www 3635: }
3636: }
1.474 raeburn 3637: return %courses;
1.51 www 3638: }
1.37 matthew 3639:
1.54 www 3640: ###############################################
1.474 raeburn 3641:
3642: sub blockcheck {
1.482 raeburn 3643: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3644:
3645: if (!defined($udom)) {
3646: $udom = $env{'user.domain'};
3647: }
3648: if (!defined($uname)) {
3649: $uname = $env{'user.name'};
3650: }
3651:
3652: # If uname and udom are for a course, check for blocks in the course.
3653:
3654: if (&Apache::lonnet::is_course($udom,$uname)) {
3655: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3656: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3657: return ($startblock,$endblock);
3658: }
1.474 raeburn 3659:
1.502 raeburn 3660: my $startblock = 0;
3661: my $endblock = 0;
1.482 raeburn 3662: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3663:
1.490 raeburn 3664: # If uname is for a user, and activity is course-specific, i.e.,
3665: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3666:
1.490 raeburn 3667: if (($activity eq 'boards' || $activity eq 'chat' ||
3668: $activity eq 'groups') && ($env{'request.course.id'})) {
3669: foreach my $key (keys(%live_courses)) {
3670: if ($key ne $env{'request.course.id'}) {
3671: delete($live_courses{$key});
3672: }
3673: }
3674: }
3675:
3676: my $otheruser = 0;
3677: my %own_courses;
3678: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3679: # Resource belongs to user other than current user.
3680: $otheruser = 1;
3681: # Gather courses for current user
3682: %own_courses =
3683: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3684: }
3685:
3686: # Gather active course roles - course coordinator, instructor,
3687: # exam proctor, ta, student, or custom role.
1.474 raeburn 3688:
3689: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3690: my ($cdom,$cnum);
3691: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3692: $cdom = $env{'course.'.$course.'.domain'};
3693: $cnum = $env{'course.'.$course.'.num'};
3694: } else {
1.490 raeburn 3695: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3696: }
3697: my $no_ownblock = 0;
3698: my $no_userblock = 0;
1.533 raeburn 3699: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3700: # Check if current user has 'evb' priv for this
3701: if (defined($own_courses{$course})) {
3702: foreach my $sec (keys(%{$own_courses{$course}})) {
3703: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3704: if ($sec ne 'none') {
3705: $checkrole .= '/'.$sec;
3706: }
3707: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3708: $no_ownblock = 1;
3709: last;
3710: }
3711: }
3712: }
3713: # if they have 'evb' priv and are currently not playing student
3714: next if (($no_ownblock) &&
3715: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3716: }
1.474 raeburn 3717: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3718: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3719: if ($sec ne 'none') {
1.482 raeburn 3720: $checkrole .= '/'.$sec;
1.474 raeburn 3721: }
1.490 raeburn 3722: if ($otheruser) {
3723: # Resource belongs to user other than current user.
3724: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3725: my ($trole,$tdom,$tnum,$tsec);
3726: my $entry = $live_courses{$course}{$sec};
3727: if ($entry =~ /^cr/) {
3728: ($trole,$tdom,$tnum,$tsec) =
3729: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3730: } else {
3731: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3732: }
3733: my ($spec,$area,$trest,%allroles,%userroles);
3734: $area = '/'.$tdom.'/'.$tnum;
3735: $trest = $tnum;
3736: if ($tsec ne '') {
3737: $area .= '/'.$tsec;
3738: $trest .= '/'.$tsec;
3739: }
3740: $spec = $trole.'.'.$area;
3741: if ($trole =~ /^cr/) {
3742: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3743: $tdom,$spec,$trest,$area);
3744: } else {
3745: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3746: $tdom,$spec,$trest,$area);
3747: }
3748: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3749: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3750: if ($1) {
3751: $no_userblock = 1;
3752: last;
3753: }
3754: }
1.490 raeburn 3755: } else {
3756: # Resource belongs to current user
3757: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3758: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3759: $no_ownblock = 1;
3760: last;
3761: }
1.474 raeburn 3762: }
3763: }
3764: # if they have the evb priv and are currently not playing student
1.482 raeburn 3765: next if (($no_ownblock) &&
1.491 albertel 3766: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3767: next if ($no_userblock);
1.474 raeburn 3768:
1.866 kalberla 3769: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3770: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3771:
3772: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3773: if (($start != 0) &&
3774: (($startblock == 0) || ($startblock > $start))) {
3775: $startblock = $start;
3776: }
3777: if (($end != 0) &&
3778: (($endblock == 0) || ($endblock < $end))) {
3779: $endblock = $end;
3780: }
1.490 raeburn 3781: }
3782: return ($startblock,$endblock);
3783: }
3784:
3785: sub get_blocks {
3786: my ($setters,$activity,$cdom,$cnum) = @_;
3787: my $startblock = 0;
3788: my $endblock = 0;
3789: my $course = $cdom.'_'.$cnum;
3790: $setters->{$course} = {};
3791: $setters->{$course}{'staff'} = [];
3792: $setters->{$course}{'times'} = [];
3793: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3794: foreach my $record (keys(%records)) {
3795: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3796: if ($start <= time && $end >= time) {
3797: my ($staff_name,$staff_dom,$title,$blocks) =
3798: &parse_block_record($records{$record});
3799: if ($blocks->{$activity} eq 'on') {
3800: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3801: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3802: if ( ($startblock == 0) || ($startblock > $start) ) {
3803: $startblock = $start;
1.490 raeburn 3804: }
1.491 albertel 3805: if ( ($endblock == 0) || ($endblock < $end) ) {
3806: $endblock = $end;
1.474 raeburn 3807: }
3808: }
3809: }
3810: }
3811: return ($startblock,$endblock);
3812: }
3813:
3814: sub parse_block_record {
3815: my ($record) = @_;
3816: my ($setuname,$setudom,$title,$blocks);
3817: if (ref($record) eq 'HASH') {
3818: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3819: $title = &unescape($record->{'event'});
3820: $blocks = $record->{'blocks'};
3821: } else {
3822: my @data = split(/:/,$record,3);
3823: if (scalar(@data) eq 2) {
3824: $title = $data[1];
3825: ($setuname,$setudom) = split(/@/,$data[0]);
3826: } else {
3827: ($setuname,$setudom,$title) = @data;
3828: }
3829: $blocks = { 'com' => 'on' };
3830: }
3831: return ($setuname,$setudom,$title,$blocks);
3832: }
3833:
3834: sub build_block_table {
3835: my ($startblock,$endblock,$setters) = @_;
3836: my %lt = &Apache::lonlocal::texthash(
3837: 'cacb' => 'Currently active communication blocks',
3838: 'cour' => 'Course',
3839: 'dura' => 'Duration',
3840: 'blse' => 'Block set by'
3841: );
3842: my $output;
1.476 raeburn 3843: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3844: $output .= &start_data_table();
3845: $output .= '
3846: <tr>
3847: <th>'.$lt{'cour'}.'</th>
3848: <th>'.$lt{'dura'}.'</th>
3849: <th>'.$lt{'blse'}.'</th>
3850: </tr>
3851: ';
3852: foreach my $course (keys(%{$setters})) {
3853: my %courseinfo=&Apache::lonnet::coursedescription($course);
3854: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3855: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3856: my $fullname = &plainname($uname,$udom);
3857: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3858: && $env{'user.name'} ne 'public'
3859: && $env{'user.domain'} ne 'public') {
3860: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3861: }
1.474 raeburn 3862: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3863: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3864: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3865: $output .= &Apache::loncommon::start_data_table_row().
3866: '<td>'.$courseinfo{'description'}.'</td>'.
3867: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3868: '<td>'.$fullname.'</td>'.
1.474 raeburn 3869: &Apache::loncommon::end_data_table_row();
3870: }
3871: }
3872: $output .= &end_data_table();
3873: }
1.854 kalberla 3874: sub blocking_status {
1.867 ! kalberla 3875: my $blocked;
1.854 kalberla 3876: my ($activity,$uname,$udom) = @_;
1.867 ! kalberla 3877: my %setters;
! 3878: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
! 3879: if ($startblock && $endblock) {
! 3880: $blocked = 1;
! 3881: }
1.854 kalberla 3882: if(!wantarray) {
3883: return $blocked;
3884: }
3885: my $output;
3886: my $querystring;
3887: $querystring = "?activity=$activity";
3888:
3889: $output .= <<"END_MYBLOCK";
3890: <script type="text/javascript">
3891: // <![CDATA[
3892: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3893: var options = "width=" + w + ",height=" + h + ",";
3894: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3895: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3896: var newWin = window.open(url, wdwName, options);
3897: newWin.focus();
3898: }
3899:
3900: // ]]>
3901: </script>
3902: END_MYBLOCK
3903: my $popupUrl = "/adm/blockingstatus/$querystring";
1.867 ! kalberla 3904: $output .= <<"END_BLOCK";
! 3905: <div class='LC_comblock'>
! 3906: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'>
! 3907: <img class='LC_noBorder LC_middle' src='/res/adm/pages/comblock.png' alt='Communication Blocking'/></a>
! 3908: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'>Communication Blocking</a>
! 3909: </div>
! 3910:
! 3911: END_BLOCK
1.474 raeburn 3912:
1.854 kalberla 3913: return ($blocked, $output);
3914: }
1.490 raeburn 3915:
1.60 matthew 3916: ###############################################
3917:
1.682 raeburn 3918: sub check_ip_acc {
3919: my ($acc)=@_;
3920: &Apache::lonxml::debug("acc is $acc");
3921: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3922: return 1;
3923: }
3924: my $allowed=0;
3925: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3926:
3927: my $name;
3928: foreach my $pattern (split(',',$acc)) {
3929: $pattern =~ s/^\s*//;
3930: $pattern =~ s/\s*$//;
3931: if ($pattern =~ /\*$/) {
3932: #35.8.*
3933: $pattern=~s/\*//;
3934: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3935: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3936: #35.8.3.[34-56]
3937: my $low=$2;
3938: my $high=$3;
3939: $pattern=$1;
3940: if ($ip =~ /^\Q$pattern\E/) {
3941: my $last=(split(/\./,$ip))[3];
3942: if ($last <=$high && $last >=$low) { $allowed=1; }
3943: }
3944: } elsif ($pattern =~ /^\*/) {
3945: #*.msu.edu
3946: $pattern=~s/\*//;
3947: if (!defined($name)) {
3948: use Socket;
3949: my $netaddr=inet_aton($ip);
3950: ($name)=gethostbyaddr($netaddr,AF_INET);
3951: }
3952: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3953: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3954: #127.0.0.1
3955: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3956: } else {
3957: #some.name.com
3958: if (!defined($name)) {
3959: use Socket;
3960: my $netaddr=inet_aton($ip);
3961: ($name)=gethostbyaddr($netaddr,AF_INET);
3962: }
3963: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3964: }
3965: if ($allowed) { last; }
3966: }
3967: return $allowed;
3968: }
3969:
3970: ###############################################
3971:
1.60 matthew 3972: =pod
3973:
1.112 bowersj2 3974: =head1 Domain Template Functions
3975:
3976: =over 4
3977:
3978: =item * &determinedomain()
1.60 matthew 3979:
3980: Inputs: $domain (usually will be undef)
3981:
1.63 www 3982: Returns: Determines which domain should be used for designs
1.60 matthew 3983:
3984: =cut
1.54 www 3985:
1.60 matthew 3986: ###############################################
1.63 www 3987: sub determinedomain {
3988: my $domain=shift;
1.531 albertel 3989: if (! $domain) {
1.60 matthew 3990: # Determine domain if we have not been given one
3991: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3992: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3993: if ($env{'request.role.domain'}) {
3994: $domain=$env{'request.role.domain'};
1.60 matthew 3995: }
3996: }
1.63 www 3997: return $domain;
3998: }
3999: ###############################################
1.517 raeburn 4000:
1.518 albertel 4001: sub devalidate_domconfig_cache {
4002: my ($udom)=@_;
4003: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4004: }
4005:
4006: # ---------------------- Get domain configuration for a domain
4007: sub get_domainconf {
4008: my ($udom) = @_;
4009: my $cachetime=1800;
4010: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4011: if (defined($cached)) { return %{$result}; }
4012:
4013: my %domconfig = &Apache::lonnet::get_dom('configuration',
4014: ['login','rolecolors'],$udom);
1.632 raeburn 4015: my (%designhash,%legacy);
1.518 albertel 4016: if (keys(%domconfig) > 0) {
4017: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4018: if (keys(%{$domconfig{'login'}})) {
4019: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4020: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4021: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4022: $designhash{$udom.'.login.'.$key.'_'.$img} =
4023: $domconfig{'login'}{$key}{$img};
4024: }
4025: } else {
4026: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4027: }
1.632 raeburn 4028: }
4029: } else {
4030: $legacy{'login'} = 1;
1.518 albertel 4031: }
1.632 raeburn 4032: } else {
4033: $legacy{'login'} = 1;
1.518 albertel 4034: }
4035: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4036: if (keys(%{$domconfig{'rolecolors'}})) {
4037: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4038: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4039: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4040: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4041: }
1.518 albertel 4042: }
4043: }
1.632 raeburn 4044: } else {
4045: $legacy{'rolecolors'} = 1;
1.518 albertel 4046: }
1.632 raeburn 4047: } else {
4048: $legacy{'rolecolors'} = 1;
1.518 albertel 4049: }
1.632 raeburn 4050: if (keys(%legacy) > 0) {
4051: my %legacyhash = &get_legacy_domconf($udom);
4052: foreach my $item (keys(%legacyhash)) {
4053: if ($item =~ /^\Q$udom\E\.login/) {
4054: if ($legacy{'login'}) {
4055: $designhash{$item} = $legacyhash{$item};
4056: }
4057: } else {
4058: if ($legacy{'rolecolors'}) {
4059: $designhash{$item} = $legacyhash{$item};
4060: }
1.518 albertel 4061: }
4062: }
4063: }
1.632 raeburn 4064: } else {
4065: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4066: }
4067: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4068: $cachetime);
4069: return %designhash;
4070: }
4071:
1.632 raeburn 4072: sub get_legacy_domconf {
4073: my ($udom) = @_;
4074: my %legacyhash;
4075: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4076: my $designfile = $designdir.'/'.$udom.'.tab';
4077: if (-e $designfile) {
4078: if ( open (my $fh,"<$designfile") ) {
4079: while (my $line = <$fh>) {
4080: next if ($line =~ /^\#/);
4081: chomp($line);
4082: my ($key,$val)=(split(/\=/,$line));
4083: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4084: }
4085: close($fh);
4086: }
4087: }
4088: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4089: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4090: }
4091: return %legacyhash;
4092: }
4093:
1.63 www 4094: =pod
4095:
1.112 bowersj2 4096: =item * &domainlogo()
1.63 www 4097:
4098: Inputs: $domain (usually will be undef)
4099:
4100: Returns: A link to a domain logo, if the domain logo exists.
4101: If the domain logo does not exist, a description of the domain.
4102:
4103: =cut
1.112 bowersj2 4104:
1.63 www 4105: ###############################################
4106: sub domainlogo {
1.517 raeburn 4107: my $domain = &determinedomain(shift);
1.518 albertel 4108: my %designhash = &get_domainconf($domain);
1.517 raeburn 4109: # See if there is a logo
4110: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4111: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4112: if ($imgsrc =~ m{^/(adm|res)/}) {
4113: if ($imgsrc =~ m{^/res/}) {
4114: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4115: &Apache::lonnet::repcopy($local_name);
4116: }
4117: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4118: }
4119: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4120: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4121: return &Apache::lonnet::domain($domain,'description');
1.59 www 4122: } else {
1.60 matthew 4123: return '';
1.59 www 4124: }
4125: }
1.63 www 4126: ##############################################
4127:
4128: =pod
4129:
1.112 bowersj2 4130: =item * &designparm()
1.63 www 4131:
4132: Inputs: $which parameter; $domain (usually will be undef)
4133:
4134: Returns: value of designparamter $which
4135:
4136: =cut
1.112 bowersj2 4137:
1.397 albertel 4138:
1.400 albertel 4139: ##############################################
1.397 albertel 4140: sub designparm {
4141: my ($which,$domain)=@_;
4142: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4143: return $env{'environment.color.'.$which};
1.96 www 4144: }
1.63 www 4145: $domain=&determinedomain($domain);
1.518 albertel 4146: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4147: my $output;
1.517 raeburn 4148: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4149: $output = $domdesign{$domain.'.'.$which};
1.63 www 4150: } else {
1.520 raeburn 4151: $output = $defaultdesign{$which};
4152: }
4153: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4154: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4155: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4156: if ($output =~ m{^/res/}) {
4157: my $local_name = &Apache::lonnet::filelocation('',$output);
4158: &Apache::lonnet::repcopy($local_name);
4159: }
1.520 raeburn 4160: $output = &lonhttpdurl($output);
4161: }
1.63 www 4162: }
1.520 raeburn 4163: return $output;
1.63 www 4164: }
1.59 www 4165:
1.822 bisitz 4166: ##############################################
4167: =pod
4168:
1.832 bisitz 4169: =item * &authorspace()
4170:
4171: Inputs: ./.
4172:
4173: Returns: Path to the Construction Space of the current user's
4174: accessed author space
4175: The author space will be that of the current user
4176: when accessing the own author space
4177: and that of the co-author/assistent co-author
4178: when accessing the co-author's/assistent co-author's
4179: space
4180:
4181: =cut
4182:
4183: sub authorspace {
4184: my $caname = '';
4185: if ($env{'request.role'} =~ /^ca|^aa/) {
4186: (undef,$caname) =
4187: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4188: } else {
4189: $caname = $env{'user.name'};
4190: }
4191: return '/priv/'.$caname.'/';
4192: }
4193:
4194: ##############################################
4195: =pod
4196:
1.822 bisitz 4197: =item * &head_subbox()
4198:
4199: Inputs: $content (contains HTML code with page functions, etc.)
4200:
4201: Returns: HTML div with $content
4202: To be included in page header
4203:
4204: =cut
4205:
4206: sub head_subbox {
4207: my ($content)=@_;
4208: my $output =
1.844 bisitz 4209: '<div id="LC_head_subbox">'
1.822 bisitz 4210: .$content
4211: .'</div>'
4212: }
4213:
4214: ##############################################
4215: =pod
4216:
4217: =item * &CSTR_pageheader()
4218:
4219: Inputs: ./.
4220:
4221: Returns: HTML div with CSTR path and recent box
4222: To be included on Construction Space pages
4223:
4224: =cut
4225:
4226: sub CSTR_pageheader {
4227: # this is for resources; directories have customtitle, and crumbs
4228: # and select recent are created in lonpubdir.pm
4229: my ($uname,$thisdisfn)=
4230: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4231: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4232: $formaction=~s/\/+/\//g;
4233:
4234: my $parentpath = '';
4235: my $lastitem = '';
4236: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4237: $parentpath = $1;
4238: $lastitem = $2;
4239: } else {
4240: $lastitem = $thisdisfn;
4241: }
4242: return
4243: '<div>'
4244: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4245: .'<b>'.&mt('Construction Space:').'</b> '
4246: .'<form name="dirs" method="post" action="'.$formaction
4247: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4248: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4249: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4250: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4251: .'</form>'
4252: .&Apache::lonmenu::constspaceform()
4253: .'</div>';
4254: }
4255:
1.60 matthew 4256: ###############################################
4257: ###############################################
4258:
4259: =pod
4260:
1.112 bowersj2 4261: =back
4262:
1.549 albertel 4263: =head1 HTML Helpers
1.112 bowersj2 4264:
4265: =over 4
4266:
4267: =item * &bodytag()
1.60 matthew 4268:
4269: Returns a uniform header for LON-CAPA web pages.
4270:
4271: Inputs:
4272:
1.112 bowersj2 4273: =over 4
4274:
4275: =item * $title, A title to be displayed on the page.
4276:
4277: =item * $function, the current role (can be undef).
4278:
4279: =item * $addentries, extra parameters for the <body> tag.
4280:
4281: =item * $bodyonly, if defined, only return the <body> tag.
4282:
4283: =item * $domain, if defined, force a given domain.
4284:
4285: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4286: text interface only)
1.60 matthew 4287:
1.814 bisitz 4288: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4289: navigational links
1.317 albertel 4290:
1.338 albertel 4291: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4292:
1.361 albertel 4293: =item * $no_inline_link, if true and in remote mode, don't show the
4294: 'Switch To Inline Menu' link
4295:
1.460 albertel 4296: =item * $args, optional argument valid values are
4297: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4298: inherit_jsmath -> when creating popup window in a page,
4299: should it have jsmath forced on by the
4300: current page
1.460 albertel 4301:
1.112 bowersj2 4302: =back
4303:
1.60 matthew 4304: Returns: A uniform header for LON-CAPA web pages.
4305: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4306: If $bodyonly is undef or zero, an html string containing a <body> tag and
4307: other decorations will be returned.
4308:
4309: =cut
4310:
1.54 www 4311: sub bodytag {
1.831 bisitz 4312: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4313: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4314:
1.460 albertel 4315: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4316:
1.183 matthew 4317: $function = &get_users_function() if (!$function);
1.339 albertel 4318: my $img = &designparm($function.'.img',$domain);
4319: my $font = &designparm($function.'.font',$domain);
4320: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4321:
1.803 bisitz 4322: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4323: 'bgcolor' => $pgbg,
1.339 albertel 4324: 'text' => $font,
4325: 'alink' => &designparm($function.'.alink',$domain),
4326: 'vlink' => &designparm($function.'.vlink',$domain),
4327: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4328: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4329:
1.63 www 4330: # role and realm
1.378 raeburn 4331: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4332: if ($role eq 'ca') {
1.479 albertel 4333: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4334: $realm = &plainname($rname,$rdom);
1.378 raeburn 4335: }
1.55 www 4336: # realm
1.258 albertel 4337: if ($env{'request.course.id'}) {
1.378 raeburn 4338: if ($env{'request.role'} !~ /^cr/) {
4339: $role = &Apache::lonnet::plaintext($role,&course_type());
4340: }
1.359 albertel 4341: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4342: } else {
4343: $role = &Apache::lonnet::plaintext($role);
1.54 www 4344: }
1.433 albertel 4345:
1.359 albertel 4346: if (!$realm) { $realm=' '; }
1.55 www 4347: # Set messages
1.60 matthew 4348: my $messages=&domainlogo($domain);
1.330 albertel 4349:
1.438 albertel 4350: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4351:
1.101 www 4352: # construct main body tag
1.359 albertel 4353: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4354: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4355:
1.530 albertel 4356: if ($bodyonly) {
1.60 matthew 4357: return $bodytag;
1.798 tempelho 4358: }
1.359 albertel 4359:
1.410 albertel 4360: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4361: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4362: undef($role);
1.434 albertel 4363: } else {
4364: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4365: }
1.359 albertel 4366:
1.762 bisitz 4367: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4368: #
4369: # Extra info if you are the DC
4370: my $dc_info = '';
4371: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4372: $env{'course.'.$env{'request.course.id'}.
4373: '.domain'}.'/'})) {
4374: my $cid = $env{'request.course.id'};
4375: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4376: $dc_info =~ s/\s+$//;
1.359 albertel 4377: $dc_info = '('.$dc_info.')';
4378: }
4379:
1.853 droeschl 4380: $role = "($role)" if $role;
4381: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4382:
1.837 bisitz 4383: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4384: # No Remote
1.258 albertel 4385: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4386: $forcereg=1;
4387: }
4388:
1.836 bisitz 4389: # if ($env{'request.state'} eq 'construct') {
4390: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4391: # }
1.359 albertel 4392:
1.816 bisitz 4393: my $titletable = '<table id="LC_title_bar">'
1.836 bisitz 4394: ."<tr><td> $titleinfo $dc_info</td>"
1.816 bisitz 4395: .'</tr></table>';
4396:
1.814 bisitz 4397: if ($no_nav_bar) {
1.359 albertel 4398: $bodytag .= $titletable;
4399: } else {
1.852 droeschl 4400: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4401: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4402:
1.359 albertel 4403: if ($env{'request.state'} eq 'construct') {
1.863 droeschl 4404: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
1.272 raeburn 4405: } else {
1.863 droeschl 4406: $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
1.272 raeburn 4407: }
1.235 raeburn 4408: }
4409: return $bodytag;
1.94 www 4410: }
1.95 www 4411:
1.93 www 4412: #
1.95 www 4413: # Top frame rendering, Remote is up
1.93 www 4414: #
1.359 albertel 4415:
1.517 raeburn 4416: my $imgsrc = $img;
4417: if ($img =~ /^\/adm/) {
1.575 albertel 4418: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4419: }
4420: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4421:
1.305 www 4422: # Explicit link to get inline menu
1.361 albertel 4423: my $menu= ($no_inline_link?''
1.853 droeschl 4424: :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4425: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4426: <em>$realm</em> $dc_info </div>
4427: <ol class="LC_smallMenu LC_right">
4428: <li>$menu</li>
4429: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4430: #
1.94 www 4431: return(<<ENDBODY);
1.60 matthew 4432: $bodytag
1.359 albertel 4433: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4434: <tr><td>$upperleft</td>
4435: <td>$messages </td>
1.54 www 4436: </tr>
1.359 albertel 4437: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4438: </tr>
1.356 albertel 4439: </table>
1.54 www 4440: ENDBODY
1.182 matthew 4441: }
4442:
1.330 albertel 4443: sub make_attr_string {
4444: my ($register,$attr_ref) = @_;
4445:
4446: if ($attr_ref && !ref($attr_ref)) {
4447: die("addentries Must be a hash ref ".
4448: join(':',caller(1))." ".
4449: join(':',caller(0))." ");
4450: }
4451:
4452: if ($register) {
1.339 albertel 4453: my ($on_load,$on_unload);
4454: foreach my $key (keys(%{$attr_ref})) {
4455: if (lc($key) eq 'onload') {
4456: $on_load.=$attr_ref->{$key}.';';
4457: delete($attr_ref->{$key});
4458:
4459: } elsif (lc($key) eq 'onunload') {
4460: $on_unload.=$attr_ref->{$key}.';';
4461: delete($attr_ref->{$key});
4462: }
4463: }
4464: $attr_ref->{'onload'} =
4465: &Apache::lonmenu::loadevents(). $on_load;
4466: $attr_ref->{'onunload'}=
4467: &Apache::lonmenu::unloadevents().$on_unload;
4468: }
4469:
4470: # Accessibility font enhance
4471: if ($env{'browser.fontenhance'} eq 'on') {
4472: my $style;
4473: foreach my $key (keys(%{$attr_ref})) {
4474: if (lc($key) eq 'style') {
4475: $style.=$attr_ref->{$key}.';';
4476: delete($attr_ref->{$key});
4477: }
4478: }
4479: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4480: }
1.339 albertel 4481:
1.330 albertel 4482: my $attr_string;
4483: foreach my $attr (keys(%$attr_ref)) {
4484: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4485: }
4486: return $attr_string;
4487: }
4488:
4489:
1.182 matthew 4490: ###############################################
1.251 albertel 4491: ###############################################
4492:
4493: =pod
4494:
4495: =item * &endbodytag()
4496:
4497: Returns a uniform footer for LON-CAPA web pages.
4498:
1.635 raeburn 4499: Inputs: 1 - optional reference to an args hash
4500: If in the hash, key for noredirectlink has a value which evaluates to true,
4501: a 'Continue' link is not displayed if the page contains an
4502: internal redirect in the <head></head> section,
4503: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4504:
4505: =cut
4506:
4507: sub endbodytag {
1.635 raeburn 4508: my ($args) = @_;
1.251 albertel 4509: my $endbodytag='</body>';
1.269 albertel 4510: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4511: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4512: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4513: $endbodytag=
4514: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4515: &mt('Continue').'</a>'.
4516: $endbodytag;
4517: }
1.315 albertel 4518: }
1.251 albertel 4519: return $endbodytag;
4520: }
4521:
1.352 albertel 4522: =pod
4523:
4524: =item * &standard_css()
4525:
4526: Returns a style sheet
4527:
4528: Inputs: (all optional)
4529: domain -> force to color decorate a page for a specific
4530: domain
4531: function -> force usage of a specific rolish color scheme
4532: bgcolor -> override the default page bgcolor
4533:
4534: =cut
4535:
1.343 albertel 4536: sub standard_css {
1.345 albertel 4537: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4538: $function = &get_users_function() if (!$function);
4539: my $img = &designparm($function.'.img', $domain);
4540: my $tabbg = &designparm($function.'.tabbg', $domain);
4541: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4542: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4543: #second colour for later usage
1.345 albertel 4544: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4545: my $pgbg_or_bgcolor =
4546: $bgcolor ||
1.352 albertel 4547: &designparm($function.'.pgbg', $domain);
1.382 albertel 4548: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4549: my $alink = &designparm($function.'.alink', $domain);
4550: my $vlink = &designparm($function.'.vlink', $domain);
4551: my $link = &designparm($function.'.link', $domain);
4552:
1.704 muellerd 4553: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4554: my $bgcol = &designparm('login.bgcol',$domain);
4555: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4556:
1.602 albertel 4557: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4558: my $mono = 'monospace';
1.850 bisitz 4559: my $data_table_head = $sidebg;
4560: my $data_table_light = '#FAFAFA';
4561: my $data_table_dark = '#F0F0F0';
1.470 banghart 4562: my $data_table_darker = '#CCCCCC';
1.349 albertel 4563: my $data_table_highlight = '#FFFF00';
1.352 albertel 4564: my $mail_new = '#FFBB77';
4565: my $mail_new_hover = '#DD9955';
4566: my $mail_read = '#BBBB77';
4567: my $mail_read_hover = '#999944';
4568: my $mail_replied = '#AAAA88';
4569: my $mail_replied_hover = '#888855';
4570: my $mail_other = '#99BBBB';
4571: my $mail_other_hover = '#669999';
1.391 albertel 4572: my $table_header = '#DDDDDD';
1.489 raeburn 4573: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4574: my $lg_border_color = '#C8C8C8';
1.392 albertel 4575:
1.608 albertel 4576: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4577: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4578: : '0 3px 0 4px';
1.448 albertel 4579:
1.523 albertel 4580:
1.343 albertel 4581: return <<END;
1.795 www 4582: body {
4583: font-family: $sans;
4584: line-height:130%;
4585: font-size:0.83em;
4586: color:$font;
4587: }
4588:
4589: a:link, a:visited {
4590: font-size:100%;
4591: }
4592:
4593: a:focus {
4594: color: red;
4595: background: yellow
4596: }
1.698 harmsja 4597:
1.846 bisitz 4598: hr {
4599: clear: both;
4600: color: $tabbg;
4601: background-color: $tabbg;
4602: height: 3px;
4603: border: none;
4604: }
4605:
1.795 www 4606: form, .inline {
4607: display: inline;
4608: }
1.721 harmsja 4609:
1.795 www 4610: .LC_right {
4611: text-align:right;
4612: }
4613:
4614: .LC_middle {
4615: vertical-align:middle;
4616: }
1.721 harmsja 4617:
4618: /* just for tests */
1.754 droeschl 4619: .LC_400Box {width:400px; }
1.721 harmsja 4620: /* end */
4621:
1.778 bisitz 4622: .LC_filename {
4623: font-family: $mono;
4624: white-space:pre;
4625: }
4626:
4627: .LC_fileicon {
4628: border: none;
4629: height: 1.3em;
4630: vertical-align: text-bottom;
4631: margin-right: 0.3em;
4632: text-decoration:none;
4633: }
4634:
1.350 albertel 4635: .LC_error {
4636: color: red;
4637: font-size: larger;
4638: }
1.795 www 4639:
1.457 albertel 4640: .LC_warning,
4641: .LC_diff_removed {
1.733 bisitz 4642: color: red;
1.394 albertel 4643: }
1.532 albertel 4644:
4645: .LC_info,
1.457 albertel 4646: .LC_success,
4647: .LC_diff_added {
1.350 albertel 4648: color: green;
4649: }
1.795 www 4650:
1.802 bisitz 4651: div.LC_confirm_box {
4652: background-color: #FAFAFA;
4653: border: 1px solid $lg_border_color;
4654: margin-right: 0;
4655: padding: 5px;
4656: }
4657:
4658: div.LC_confirm_box .LC_error img,
4659: div.LC_confirm_box .LC_success img {
4660: vertical-align: middle;
4661: }
4662:
1.440 albertel 4663: .LC_icon {
1.771 droeschl 4664: border: none;
1.790 droeschl 4665: vertical-align: middle;
1.771 droeschl 4666: }
4667:
1.543 albertel 4668: .LC_docs_spacer {
4669: width: 25px;
4670: height: 1px;
1.771 droeschl 4671: border: none;
1.543 albertel 4672: }
1.346 albertel 4673:
1.532 albertel 4674: .LC_internal_info {
1.735 bisitz 4675: color: #999999;
1.532 albertel 4676: }
4677:
1.794 www 4678: .LC_discussion {
4679: background: $tabbg;
4680: border: 1px solid black;
4681: margin: 2px;
4682: }
4683:
4684: .LC_disc_action_links_bar {
4685: background: $tabbg;
1.803 bisitz 4686: border: none;
1.795 www 4687: margin: 4px;
1.794 www 4688: }
4689:
4690: .LC_disc_action_left {
4691: text-align: left;
4692: }
4693:
4694: .LC_disc_action_right {
4695: text-align: right;
4696: }
4697:
4698: .LC_disc_new_item {
4699: background: white;
4700: border: 2px solid red;
4701: margin: 2px;
4702: }
4703:
4704: .LC_disc_old_item {
4705: background: white;
4706: border: 1px solid black;
4707: margin: 2px;
4708: }
4709:
1.458 albertel 4710: table.LC_pastsubmission {
4711: border: 1px solid black;
4712: margin: 2px;
4713: }
4714:
1.795 www 4715: table#LC_top_nav,
4716: table#LC_menubuttons,
4717: table#LC_nav_location {
1.345 albertel 4718: width: 100%;
4719: background: $pgbg;
1.392 albertel 4720: border: 2px;
1.402 albertel 4721: border-collapse: separate;
1.803 bisitz 4722: padding: 0;
1.345 albertel 4723: }
1.392 albertel 4724:
1.801 tempelho 4725: table#LC_title_bar a {
4726: color: $fontmenu;
4727: }
1.836 bisitz 4728:
1.807 droeschl 4729: table#LC_title_bar {
1.819 tempelho 4730: clear: both;
1.836 bisitz 4731: display: none;
1.807 droeschl 4732: }
4733:
1.795 www 4734: table#LC_title_bar,
4735: table.LC_breadcrumbs,
1.393 albertel 4736: table#LC_title_bar.LC_with_remote {
1.359 albertel 4737: width: 100%;
1.392 albertel 4738: border-color: $pgbg;
4739: border-style: solid;
4740: border-width: $border;
1.379 albertel 4741: background: $pgbg;
1.801 tempelho 4742: color: $fontmenu;
1.392 albertel 4743: border-collapse: collapse;
1.803 bisitz 4744: padding: 0;
1.819 tempelho 4745: margin: 0;
1.359 albertel 4746: }
1.795 www 4747:
1.359 albertel 4748: table#LC_title_bar td {
4749: background: $tabbg;
4750: }
1.795 www 4751:
1.706 harmsja 4752: table#LC_menubuttons img{
1.803 bisitz 4753: border: none;
1.346 albertel 4754: }
1.795 www 4755:
1.345 albertel 4756: table#LC_top_nav td {
4757: background: $tabbg;
1.803 bisitz 4758: border: none;
1.407 albertel 4759: font-size: small;
1.706 harmsja 4760: vertical-align:top;
4761: padding:2px 5px 2px 5px;
1.345 albertel 4762: }
1.795 www 4763:
4764: table#LC_top_nav td a,
4765: div#LC_top_nav a {
1.345 albertel 4766: color: $font;
4767: }
1.795 www 4768:
1.364 albertel 4769: table#LC_top_nav td.LC_top_nav_logo {
4770: background: $tabbg;
1.432 albertel 4771: text-align: left;
1.408 albertel 4772: white-space: nowrap;
1.432 albertel 4773: width: 31px;
1.408 albertel 4774: }
1.795 www 4775:
1.408 albertel 4776: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4777: border: none;
1.408 albertel 4778: vertical-align: bottom;
1.364 albertel 4779: }
1.795 www 4780:
1.777 tempelho 4781: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4782: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4783: width: 2.0em;
4784: }
1.795 www 4785:
1.442 albertel 4786: table#LC_top_nav td.LC_top_nav_login {
4787: width: 4.0em;
4788: text-align: center;
4789: }
1.795 www 4790:
1.842 droeschl 4791: .LC_breadcrumbs_component {
4792: float: right;
4793: margin: 0 1em;
1.357 albertel 4794: }
1.842 droeschl 4795: .LC_breadcrumbs_component img {
4796: vertical-align: middle;
1.777 tempelho 4797: }
1.795 www 4798:
1.383 albertel 4799: td.LC_table_cell_checkbox {
4800: text-align: center;
4801: }
1.795 www 4802:
1.779 bisitz 4803: table#LC_mainmenu td.LC_mainmenu_column {
4804: vertical-align: top;
1.777 tempelho 4805: }
1.522 albertel 4806:
1.795 www 4807: .LC_fontsize_small {
1.705 tempelho 4808: font-size: 70%;
4809: }
4810:
1.844 bisitz 4811: #LC_breadcrumbs {
1.819 tempelho 4812: clear:both;
4813: background: $sidebg;
1.822 bisitz 4814: border-bottom: 1px solid $lg_border_color;
1.819 tempelho 4815: line-height: 32px;
1.822 bisitz 4816: margin: 0;
1.819 tempelho 4817: padding: 0;
4818: }
1.862 bisitz 4819:
1.839 droeschl 4820: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4821: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4822: display:none;
4823: }
1.819 tempelho 4824:
1.844 bisitz 4825: #LC_head_subbox {
1.822 bisitz 4826: clear:both;
4827: background: #F8F8F8; /* $sidebg; */
4828: border-bottom: 1px solid $lg_border_color;
4829: margin: 0 0 10px 0;
4830: padding: 5px;
4831: }
4832:
1.795 www 4833: .LC_fontsize_medium {
1.705 tempelho 4834: font-size: 85%;
4835: }
4836:
1.795 www 4837: .LC_fontsize_large {
1.705 tempelho 4838: font-size: 120%;
4839: }
4840:
1.346 albertel 4841: .LC_menubuttons_inline_text {
4842: color: $font;
1.698 harmsja 4843: font-size: 90%;
1.701 harmsja 4844: padding-left:3px;
1.346 albertel 4845: }
4846:
1.526 www 4847: .LC_menubuttons_link {
4848: text-decoration: none;
4849: }
1.795 www 4850:
1.522 albertel 4851: .LC_menubuttons_category {
1.521 www 4852: color: $font;
1.526 www 4853: background: $pgbg;
1.521 www 4854: font-size: larger;
4855: font-weight: bold;
4856: }
4857:
1.346 albertel 4858: td.LC_menubuttons_text {
1.779 bisitz 4859: color: $font;
1.346 albertel 4860: }
1.706 harmsja 4861:
1.346 albertel 4862: .LC_current_location {
4863: background: $tabbg;
4864: }
1.795 www 4865:
1.346 albertel 4866: .LC_new_mail {
1.634 www 4867: background: $tabbg;
1.346 albertel 4868: font-weight: bold;
4869: }
1.347 albertel 4870:
1.666 raeburn 4871: .LC_roleslog_note {
1.701 harmsja 4872: font-size: small;
1.666 raeburn 4873: }
4874:
1.795 www 4875: table.LC_data_table,
4876: table.LC_mail_list {
1.347 albertel 4877: border: 1px solid #000000;
1.402 albertel 4878: border-collapse: separate;
1.426 albertel 4879: border-spacing: 1px;
1.610 albertel 4880: background: $pgbg;
1.347 albertel 4881: }
1.795 www 4882:
1.422 albertel 4883: .LC_data_table_dense {
4884: font-size: small;
4885: }
1.795 www 4886:
1.507 raeburn 4887: table.LC_nested_outer {
4888: border: 1px solid #000000;
1.589 raeburn 4889: border-collapse: collapse;
1.803 bisitz 4890: border-spacing: 0;
1.507 raeburn 4891: width: 100%;
4892: }
1.795 www 4893:
1.507 raeburn 4894: table.LC_nested {
1.803 bisitz 4895: border: none;
1.589 raeburn 4896: border-collapse: collapse;
1.803 bisitz 4897: border-spacing: 0;
1.507 raeburn 4898: width: 100%;
4899: }
1.795 www 4900:
4901: table.LC_data_table tr th,
4902: table.LC_calendar tr th,
4903: table.LC_mail_list tr th,
1.523 albertel 4904: table.LC_prior_tries tr th {
1.349 albertel 4905: font-weight: bold;
4906: background-color: $data_table_head;
1.801 tempelho 4907: color:$fontmenu;
1.701 harmsja 4908: font-size:90%;
1.347 albertel 4909: }
1.795 www 4910:
1.711 raeburn 4911: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4912: background-color: #CCCCCC;
1.711 raeburn 4913: font-weight: bold;
4914: text-align: left;
4915: }
1.795 www 4916:
1.779 bisitz 4917: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4918: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4919: background-color: $data_table_light;
1.425 albertel 4920: padding: 2px;
1.347 albertel 4921: }
1.795 www 4922:
1.610 albertel 4923: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4924: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4925: background-color: $data_table_dark;
1.709 bisitz 4926: padding: 2px;
1.347 albertel 4927: }
1.795 www 4928:
1.425 albertel 4929: table.LC_data_table tr.LC_data_table_highlight td {
4930: background-color: $data_table_darker;
4931: }
1.795 www 4932:
1.639 raeburn 4933: table.LC_data_table tr td.LC_leftcol_header {
4934: background-color: $data_table_head;
4935: font-weight: bold;
4936: }
1.795 www 4937:
1.451 albertel 4938: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4939: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4940: background-color: #FFFFFF;
1.421 albertel 4941: font-weight: bold;
4942: font-style: italic;
4943: text-align: center;
4944: padding: 8px;
1.347 albertel 4945: }
1.795 www 4946:
1.507 raeburn 4947: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4948: padding: 4ex
4949: }
1.795 www 4950:
1.507 raeburn 4951: table.LC_nested_outer tr th {
4952: font-weight: bold;
1.801 tempelho 4953: color:$fontmenu;
1.507 raeburn 4954: background-color: $data_table_head;
1.701 harmsja 4955: font-size: small;
1.507 raeburn 4956: border-bottom: 1px solid #000000;
4957: }
1.795 www 4958:
1.507 raeburn 4959: table.LC_nested_outer tr td.LC_subheader {
4960: background-color: $data_table_head;
4961: font-weight: bold;
4962: font-size: small;
4963: border-bottom: 1px solid #000000;
4964: text-align: right;
1.451 albertel 4965: }
1.795 www 4966:
1.507 raeburn 4967: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4968: background-color: #CCCCCC;
1.451 albertel 4969: font-weight: bold;
4970: font-size: small;
1.507 raeburn 4971: text-align: center;
4972: }
1.795 www 4973:
1.589 raeburn 4974: table.LC_nested tr.LC_info_row td.LC_left_item,
4975: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4976: text-align: left;
1.451 albertel 4977: }
1.795 www 4978:
1.507 raeburn 4979: table.LC_nested td {
1.735 bisitz 4980: background-color: #FFFFFF;
1.451 albertel 4981: font-size: small;
1.507 raeburn 4982: }
1.795 www 4983:
1.507 raeburn 4984: table.LC_nested_outer tr th.LC_right_item,
4985: table.LC_nested tr.LC_info_row td.LC_right_item,
4986: table.LC_nested tr.LC_odd_row td.LC_right_item,
4987: table.LC_nested tr td.LC_right_item {
1.451 albertel 4988: text-align: right;
4989: }
4990:
1.507 raeburn 4991: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4992: background-color: #EEEEEE;
1.451 albertel 4993: }
4994:
1.473 raeburn 4995: table.LC_createuser {
4996: }
4997:
4998: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4999: font-size: small;
1.473 raeburn 5000: }
5001:
5002: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5003: background-color: #CCCCCC;
1.473 raeburn 5004: font-weight: bold;
5005: text-align: center;
5006: }
5007:
1.349 albertel 5008: table.LC_calendar {
5009: border: 1px solid #000000;
5010: border-collapse: collapse;
5011: }
1.795 www 5012:
1.349 albertel 5013: table.LC_calendar_pickdate {
5014: font-size: xx-small;
5015: }
1.795 www 5016:
1.349 albertel 5017: table.LC_calendar tr td {
5018: border: 1px solid #000000;
5019: vertical-align: top;
5020: }
1.795 www 5021:
1.349 albertel 5022: table.LC_calendar tr td.LC_calendar_day_empty {
5023: background-color: $data_table_dark;
5024: }
1.795 www 5025:
1.779 bisitz 5026: table.LC_calendar tr td.LC_calendar_day_current {
5027: background-color: $data_table_highlight;
1.777 tempelho 5028: }
1.795 www 5029:
1.349 albertel 5030: table.LC_mail_list tr.LC_mail_new {
5031: background-color: $mail_new;
5032: }
1.795 www 5033:
1.349 albertel 5034: table.LC_mail_list tr.LC_mail_new:hover {
5035: background-color: $mail_new_hover;
5036: }
1.795 www 5037:
5038: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5039: }
1.795 www 5040:
5041: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5042: }
1.795 www 5043:
1.349 albertel 5044: table.LC_mail_list tr.LC_mail_read {
5045: background-color: $mail_read;
5046: }
1.795 www 5047:
1.349 albertel 5048: table.LC_mail_list tr.LC_mail_read:hover {
5049: background-color: $mail_read_hover;
5050: }
1.795 www 5051:
1.349 albertel 5052: table.LC_mail_list tr.LC_mail_replied {
5053: background-color: $mail_replied;
5054: }
1.795 www 5055:
1.349 albertel 5056: table.LC_mail_list tr.LC_mail_replied:hover {
5057: background-color: $mail_replied_hover;
5058: }
1.795 www 5059:
1.349 albertel 5060: table.LC_mail_list tr.LC_mail_other {
5061: background-color: $mail_other;
5062: }
1.795 www 5063:
1.349 albertel 5064: table.LC_mail_list tr.LC_mail_other:hover {
5065: background-color: $mail_other_hover;
5066: }
1.494 raeburn 5067:
1.777 tempelho 5068: table.LC_data_table tr > td.LC_browser_file,
5069: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5070: background: #CCFF88;
5071: }
1.795 www 5072:
1.777 tempelho 5073: table.LC_data_table tr > td.LC_browser_file_locked,
5074: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5075: background: #FFAA99;
1.387 albertel 5076: }
1.795 www 5077:
1.777 tempelho 5078: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5079: background: #AAAAAA;
5080: }
1.795 www 5081:
1.777 tempelho 5082: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5083: table.LC_data_table tr > td.LC_browser_file_metamodified {
5084: background: #FFFF77;
1.777 tempelho 5085: }
1.795 www 5086:
1.696 bisitz 5087: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5088: background: #CCCCFF;
1.387 albertel 5089: }
1.696 bisitz 5090:
1.707 bisitz 5091: table.LC_data_table tr > td.LC_roles_is {
5092: /* background: #77FF77; */
5093: }
1.795 www 5094:
1.707 bisitz 5095: table.LC_data_table tr > td.LC_roles_future {
5096: background: #FFFF77;
5097: }
1.795 www 5098:
1.707 bisitz 5099: table.LC_data_table tr > td.LC_roles_will {
5100: background: #FFAA77;
5101: }
1.795 www 5102:
1.707 bisitz 5103: table.LC_data_table tr > td.LC_roles_expired {
5104: background: #FF7777;
5105: }
1.795 www 5106:
1.707 bisitz 5107: table.LC_data_table tr > td.LC_roles_will_not {
5108: background: #AAFF77;
5109: }
1.795 www 5110:
1.707 bisitz 5111: table.LC_data_table tr > td.LC_roles_selected {
5112: background: #11CC55;
5113: }
5114:
1.388 albertel 5115: span.LC_current_location {
1.701 harmsja 5116: font-size:larger;
1.388 albertel 5117: background: $pgbg;
5118: }
1.387 albertel 5119:
1.395 albertel 5120: span.LC_parm_menu_item {
5121: font-size: larger;
5122: }
1.795 www 5123:
1.395 albertel 5124: span.LC_parm_scope_all {
5125: color: red;
5126: }
1.795 www 5127:
1.395 albertel 5128: span.LC_parm_scope_folder {
5129: color: green;
5130: }
1.795 www 5131:
1.395 albertel 5132: span.LC_parm_scope_resource {
5133: color: orange;
5134: }
1.795 www 5135:
1.395 albertel 5136: span.LC_parm_part {
5137: color: blue;
5138: }
1.795 www 5139:
1.395 albertel 5140: span.LC_parm_folder, span.LC_parm_symb {
5141: font-size: x-small;
5142: font-family: $mono;
5143: color: #AAAAAA;
5144: }
5145:
1.795 www 5146: td.LC_parm_overview_level_menu,
5147: td.LC_parm_overview_map_menu,
5148: td.LC_parm_overview_parm_selectors,
5149: td.LC_parm_overview_restrictions {
1.396 albertel 5150: border: 1px solid black;
5151: border-collapse: collapse;
5152: }
1.795 www 5153:
1.396 albertel 5154: table.LC_parm_overview_restrictions td {
5155: border-width: 1px 4px 1px 4px;
5156: border-style: solid;
5157: border-color: $pgbg;
5158: text-align: center;
5159: }
1.795 www 5160:
1.396 albertel 5161: table.LC_parm_overview_restrictions th {
5162: background: $tabbg;
5163: border-width: 1px 4px 1px 4px;
5164: border-style: solid;
5165: border-color: $pgbg;
5166: }
1.795 www 5167:
1.398 albertel 5168: table#LC_helpmenu {
1.803 bisitz 5169: border: none;
1.398 albertel 5170: height: 55px;
1.803 bisitz 5171: border-spacing: 0;
1.398 albertel 5172: }
5173:
5174: table#LC_helpmenu fieldset legend {
5175: font-size: larger;
5176: }
1.795 www 5177:
1.397 albertel 5178: table#LC_helpmenu_links {
5179: width: 100%;
5180: border: 1px solid black;
5181: background: $pgbg;
1.803 bisitz 5182: padding: 0;
1.397 albertel 5183: border-spacing: 1px;
5184: }
1.795 www 5185:
1.397 albertel 5186: table#LC_helpmenu_links tr td {
5187: padding: 1px;
5188: background: $tabbg;
1.399 albertel 5189: text-align: center;
5190: font-weight: bold;
1.397 albertel 5191: }
1.396 albertel 5192:
1.795 www 5193: table#LC_helpmenu_links a:link,
5194: table#LC_helpmenu_links a:visited,
1.397 albertel 5195: table#LC_helpmenu_links a:active {
5196: text-decoration: none;
5197: color: $font;
5198: }
1.795 www 5199:
1.397 albertel 5200: table#LC_helpmenu_links a:hover {
5201: text-decoration: underline;
5202: color: $vlink;
5203: }
1.396 albertel 5204:
1.417 albertel 5205: .LC_chrt_popup_exists {
5206: border: 1px solid #339933;
5207: margin: -1px;
5208: }
1.795 www 5209:
1.417 albertel 5210: .LC_chrt_popup_up {
5211: border: 1px solid yellow;
5212: margin: -1px;
5213: }
1.795 www 5214:
1.417 albertel 5215: .LC_chrt_popup {
5216: border: 1px solid #8888FF;
5217: background: #CCCCFF;
5218: }
1.795 www 5219:
1.421 albertel 5220: table.LC_pick_box {
5221: border-collapse: separate;
5222: background: white;
5223: border: 1px solid black;
5224: border-spacing: 1px;
5225: }
1.795 www 5226:
1.421 albertel 5227: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5228: background: $sidebg;
1.421 albertel 5229: font-weight: bold;
5230: text-align: right;
1.740 bisitz 5231: vertical-align: top;
1.421 albertel 5232: width: 184px;
5233: padding: 8px;
5234: }
1.795 www 5235:
1.579 raeburn 5236: table.LC_pick_box td.LC_pick_box_value {
5237: text-align: left;
5238: padding: 8px;
5239: }
1.795 www 5240:
1.579 raeburn 5241: table.LC_pick_box td.LC_pick_box_select {
5242: text-align: left;
5243: padding: 8px;
5244: }
1.795 www 5245:
1.424 albertel 5246: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5247: padding: 0;
1.421 albertel 5248: height: 1px;
5249: background: black;
5250: }
1.795 www 5251:
1.421 albertel 5252: table.LC_pick_box td.LC_pick_box_submit {
5253: text-align: right;
5254: }
1.795 www 5255:
1.579 raeburn 5256: table.LC_pick_box td.LC_evenrow_value {
5257: text-align: left;
5258: padding: 8px;
5259: background-color: $data_table_light;
5260: }
1.795 www 5261:
1.579 raeburn 5262: table.LC_pick_box td.LC_oddrow_value {
5263: text-align: left;
5264: padding: 8px;
5265: background-color: $data_table_light;
5266: }
1.795 www 5267:
1.579 raeburn 5268: table.LC_helpform_receipt {
5269: width: 620px;
5270: border-collapse: separate;
5271: background: white;
5272: border: 1px solid black;
5273: border-spacing: 1px;
5274: }
1.795 www 5275:
1.579 raeburn 5276: table.LC_helpform_receipt td.LC_pick_box_title {
5277: background: $tabbg;
5278: font-weight: bold;
5279: text-align: right;
5280: width: 184px;
5281: padding: 8px;
5282: }
1.795 www 5283:
1.579 raeburn 5284: table.LC_helpform_receipt td.LC_evenrow_value {
5285: text-align: left;
5286: padding: 8px;
5287: background-color: $data_table_light;
5288: }
1.795 www 5289:
1.579 raeburn 5290: table.LC_helpform_receipt td.LC_oddrow_value {
5291: text-align: left;
5292: padding: 8px;
5293: background-color: $data_table_light;
5294: }
1.795 www 5295:
1.579 raeburn 5296: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5297: padding: 0;
1.579 raeburn 5298: height: 1px;
5299: background: black;
5300: }
1.795 www 5301:
1.579 raeburn 5302: span.LC_helpform_receipt_cat {
5303: font-weight: bold;
5304: }
1.795 www 5305:
1.424 albertel 5306: table.LC_group_priv_box {
5307: background: white;
5308: border: 1px solid black;
5309: border-spacing: 1px;
5310: }
1.795 www 5311:
1.424 albertel 5312: table.LC_group_priv_box td.LC_pick_box_title {
5313: background: $tabbg;
5314: font-weight: bold;
5315: text-align: right;
5316: width: 184px;
5317: }
1.795 www 5318:
1.424 albertel 5319: table.LC_group_priv_box td.LC_groups_fixed {
5320: background: $data_table_light;
5321: text-align: center;
5322: }
1.795 www 5323:
1.424 albertel 5324: table.LC_group_priv_box td.LC_groups_optional {
5325: background: $data_table_dark;
5326: text-align: center;
5327: }
1.795 www 5328:
1.424 albertel 5329: table.LC_group_priv_box td.LC_groups_functionality {
5330: background: $data_table_darker;
5331: text-align: center;
5332: font-weight: bold;
5333: }
1.795 www 5334:
1.424 albertel 5335: table.LC_group_priv td {
5336: text-align: left;
1.803 bisitz 5337: padding: 0;
1.424 albertel 5338: }
5339:
1.421 albertel 5340: table.LC_notify_front_page {
5341: background: white;
5342: border: 1px solid black;
5343: padding: 8px;
5344: }
1.795 www 5345:
1.421 albertel 5346: table.LC_notify_front_page td {
5347: padding: 8px;
5348: }
1.795 www 5349:
1.424 albertel 5350: .LC_navbuttons {
5351: margin: 2ex 0ex 2ex 0ex;
5352: }
1.795 www 5353:
1.423 albertel 5354: .LC_topic_bar {
5355: font-weight: bold;
5356: width: 100%;
5357: background: $tabbg;
5358: vertical-align: middle;
5359: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5360: padding: 3px;
1.423 albertel 5361: }
1.795 www 5362:
1.423 albertel 5363: .LC_topic_bar span {
5364: vertical-align: middle;
5365: }
1.795 www 5366:
1.423 albertel 5367: .LC_topic_bar img {
5368: vertical-align: bottom;
5369: }
1.795 www 5370:
1.423 albertel 5371: table.LC_course_group_status {
5372: margin: 20px;
5373: }
1.795 www 5374:
1.423 albertel 5375: table.LC_status_selector td {
5376: vertical-align: top;
5377: text-align: center;
1.424 albertel 5378: padding: 4px;
5379: }
1.795 www 5380:
1.599 albertel 5381: div.LC_feedback_link {
1.616 albertel 5382: clear: both;
1.829 kalberla 5383: background: $sidebg;
1.779 bisitz 5384: width: 100%;
1.829 kalberla 5385: padding-bottom: 10px;
5386: border: 1px $tabbg solid;
1.833 kalberla 5387: height: 22px;
5388: line-height: 22px;
5389: padding-top: 5px;
5390: }
5391:
5392: div.LC_feedback_link img {
5393: height: 22px;
1.867 ! kalberla 5394: vertical-align:middle;
1.829 kalberla 5395: }
5396:
5397: div.LC_feedback_link a{
5398: text-decoration: none;
1.489 raeburn 5399: }
1.795 www 5400:
1.867 ! kalberla 5401: div.LC_comblock {
! 5402: display:inline;
! 5403: color:$font;
! 5404: font-size:90%;
! 5405: }
! 5406:
! 5407: div.LC_feedback_link div.LC_comblock {
! 5408: padding-left:5px;
! 5409: }
! 5410:
! 5411: div.LC_feedback_link div.LC_comblock a {
! 5412: color:$font;
! 5413: }
! 5414:
1.489 raeburn 5415: span.LC_feedback_link {
1.858 bisitz 5416: /* background: $feedback_link_bg; */
1.599 albertel 5417: font-size: larger;
5418: }
1.795 www 5419:
1.599 albertel 5420: span.LC_message_link {
1.858 bisitz 5421: /* background: $feedback_link_bg; */
1.599 albertel 5422: font-size: larger;
5423: position: absolute;
5424: right: 1em;
1.489 raeburn 5425: }
1.421 albertel 5426:
1.515 albertel 5427: table.LC_prior_tries {
1.524 albertel 5428: border: 1px solid #000000;
5429: border-collapse: separate;
5430: border-spacing: 1px;
1.515 albertel 5431: }
1.523 albertel 5432:
1.515 albertel 5433: table.LC_prior_tries td {
1.524 albertel 5434: padding: 2px;
1.515 albertel 5435: }
1.523 albertel 5436:
5437: .LC_answer_correct {
1.795 www 5438: background: lightgreen;
5439: color: darkgreen;
5440: padding: 6px;
1.523 albertel 5441: }
1.795 www 5442:
1.523 albertel 5443: .LC_answer_charged_try {
1.797 www 5444: background: #FFAAAA;
1.795 www 5445: color: darkred;
5446: padding: 6px;
1.523 albertel 5447: }
1.795 www 5448:
1.779 bisitz 5449: .LC_answer_not_charged_try,
1.523 albertel 5450: .LC_answer_no_grade,
5451: .LC_answer_late {
1.795 www 5452: background: lightyellow;
1.523 albertel 5453: color: black;
1.795 www 5454: padding: 6px;
1.523 albertel 5455: }
1.795 www 5456:
1.523 albertel 5457: .LC_answer_previous {
1.795 www 5458: background: lightblue;
5459: color: darkblue;
5460: padding: 6px;
1.523 albertel 5461: }
1.795 www 5462:
1.779 bisitz 5463: .LC_answer_no_message {
1.777 tempelho 5464: background: #FFFFFF;
5465: color: black;
1.795 www 5466: padding: 6px;
1.779 bisitz 5467: }
1.795 www 5468:
1.779 bisitz 5469: .LC_answer_unknown {
5470: background: orange;
5471: color: black;
1.795 www 5472: padding: 6px;
1.777 tempelho 5473: }
1.795 www 5474:
1.529 albertel 5475: span.LC_prior_numerical,
5476: span.LC_prior_string,
5477: span.LC_prior_custom,
5478: span.LC_prior_reaction,
5479: span.LC_prior_math {
1.523 albertel 5480: font-family: monospace;
5481: white-space: pre;
5482: }
5483:
1.525 albertel 5484: span.LC_prior_string {
5485: font-family: monospace;
5486: white-space: pre;
5487: }
5488:
1.523 albertel 5489: table.LC_prior_option {
5490: width: 100%;
5491: border-collapse: collapse;
5492: }
1.795 www 5493:
5494: table.LC_prior_rank,
5495: table.LC_prior_match {
1.528 albertel 5496: border-collapse: collapse;
5497: }
1.795 www 5498:
1.528 albertel 5499: table.LC_prior_option tr td,
5500: table.LC_prior_rank tr td,
5501: table.LC_prior_match tr td {
1.524 albertel 5502: border: 1px solid #000000;
1.515 albertel 5503: }
5504:
1.855 bisitz 5505: .LC_nobreak {
1.544 albertel 5506: white-space: nowrap;
1.519 raeburn 5507: }
5508:
1.576 raeburn 5509: span.LC_cusr_emph {
5510: font-style: italic;
5511: }
5512:
1.633 raeburn 5513: span.LC_cusr_subheading {
5514: font-weight: normal;
5515: font-size: 85%;
5516: }
5517:
1.545 albertel 5518: table.LC_docs_documents {
5519: background: #BBBBBB;
1.803 bisitz 5520: border-width: 0;
1.545 albertel 5521: border-collapse: collapse;
5522: }
1.795 www 5523:
1.777 tempelho 5524: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5525: border: 2px solid black;
5526: padding: 4px;
1.777 tempelho 5527: }
1.795 www 5528:
1.861 bisitz 5529: div.LC_docs_entry_move {
1.859 bisitz 5530: border: 1px solid #BBBBBB;
1.545 albertel 5531: background: #DDDDDD;
1.861 bisitz 5532: width: 22px;
1.859 bisitz 5533: padding: 1px;
5534: margin: 0;
1.545 albertel 5535: }
5536:
1.861 bisitz 5537: table.LC_data_table tr > td.LC_docs_entry_commands,
5538: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5539: background: #DDDDDD;
5540: font-size: x-small;
5541: }
1.795 www 5542:
1.861 bisitz 5543: .LC_docs_entry_parameter {
5544: white-space: nowrap;
5545: }
5546:
1.544 albertel 5547: .LC_docs_copy {
1.545 albertel 5548: color: #000099;
1.544 albertel 5549: }
1.795 www 5550:
1.544 albertel 5551: .LC_docs_cut {
1.545 albertel 5552: color: #550044;
1.544 albertel 5553: }
1.795 www 5554:
1.544 albertel 5555: .LC_docs_rename {
1.545 albertel 5556: color: #009900;
1.544 albertel 5557: }
1.795 www 5558:
1.544 albertel 5559: .LC_docs_remove {
1.545 albertel 5560: color: #990000;
5561: }
5562:
1.547 albertel 5563: .LC_docs_reinit_warn,
5564: .LC_docs_ext_edit {
5565: font-size: x-small;
5566: }
5567:
1.545 albertel 5568: table.LC_docs_adddocs td,
5569: table.LC_docs_adddocs th {
5570: border: 1px solid #BBBBBB;
5571: padding: 4px;
5572: background: #DDDDDD;
1.543 albertel 5573: }
5574:
1.584 albertel 5575: table.LC_sty_begin {
5576: background: #BBFFBB;
5577: }
1.795 www 5578:
1.584 albertel 5579: table.LC_sty_end {
5580: background: #FFBBBB;
5581: }
5582:
1.589 raeburn 5583: table.LC_double_column {
1.803 bisitz 5584: border-width: 0;
1.589 raeburn 5585: border-collapse: collapse;
5586: width: 100%;
5587: padding: 2px;
5588: }
5589:
5590: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5591: top: 2px;
1.589 raeburn 5592: left: 2px;
5593: width: 47%;
5594: vertical-align: top;
5595: }
5596:
5597: table.LC_double_column tr td.LC_right_col {
5598: top: 2px;
1.779 bisitz 5599: right: 2px;
1.589 raeburn 5600: width: 47%;
5601: vertical-align: top;
5602: }
5603:
1.594 raeburn 5604: span.LC_role_level {
5605: font-weight: bold;
5606: }
5607:
1.591 raeburn 5608: div.LC_left_float {
5609: float: left;
5610: padding-right: 5%;
1.597 albertel 5611: padding-bottom: 4px;
1.591 raeburn 5612: }
5613:
5614: div.LC_clear_float_header {
1.597 albertel 5615: padding-bottom: 2px;
1.591 raeburn 5616: }
5617:
5618: div.LC_clear_float_footer {
1.597 albertel 5619: padding-top: 10px;
1.591 raeburn 5620: clear: both;
5621: }
5622:
1.597 albertel 5623: div.LC_grade_show_user {
5624: margin-top: 20px;
5625: border: 1px solid black;
5626: }
1.795 www 5627:
1.597 albertel 5628: div.LC_grade_user_name {
5629: background: #DDDDEE;
5630: border-bottom: 1px solid black;
1.705 tempelho 5631: font-weight: bold;
5632: font-size: large;
1.597 albertel 5633: }
1.795 www 5634:
1.597 albertel 5635: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5636: background: #DDEEDD;
5637: }
5638:
5639: div.LC_grade_show_problem,
5640: div.LC_grade_submissions,
5641: div.LC_grade_message_center,
5642: div.LC_grade_info_links,
5643: div.LC_grade_assign {
5644: margin: 5px;
5645: width: 99%;
5646: background: #FFFFFF;
5647: }
1.795 www 5648:
1.597 albertel 5649: div.LC_grade_show_problem_header,
5650: div.LC_grade_submissions_header,
5651: div.LC_grade_message_center_header,
5652: div.LC_grade_assign_header {
1.705 tempelho 5653: font-weight: bold;
5654: font-size: large;
1.597 albertel 5655: }
1.795 www 5656:
1.597 albertel 5657: div.LC_grade_show_problem_problem,
5658: div.LC_grade_submissions_body,
5659: div.LC_grade_message_center_body,
5660: div.LC_grade_assign_body {
5661: border: 1px solid black;
5662: width: 99%;
5663: background: #FFFFFF;
5664: }
1.795 www 5665:
1.598 albertel 5666: span.LC_grade_check_note {
1.705 tempelho 5667: font-weight: normal;
5668: font-size: medium;
1.598 albertel 5669: display: inline;
5670: position: absolute;
5671: right: 1em;
5672: }
1.597 albertel 5673:
1.613 albertel 5674: table.LC_scantron_action {
5675: width: 100%;
5676: }
1.795 www 5677:
1.613 albertel 5678: table.LC_scantron_action tr th {
1.698 harmsja 5679: font-weight:bold;
5680: font-style:normal;
1.613 albertel 5681: }
1.795 www 5682:
1.779 bisitz 5683: .LC_edit_problem_header,
1.614 albertel 5684: div.LC_edit_problem_footer {
1.705 tempelho 5685: font-weight: normal;
5686: font-size: medium;
1.602 albertel 5687: margin: 2px;
1.600 albertel 5688: }
1.795 www 5689:
1.600 albertel 5690: div.LC_edit_problem_header,
1.602 albertel 5691: div.LC_edit_problem_header div,
1.614 albertel 5692: div.LC_edit_problem_footer,
5693: div.LC_edit_problem_footer div,
1.602 albertel 5694: div.LC_edit_problem_editxml_header,
5695: div.LC_edit_problem_editxml_header div {
1.600 albertel 5696: margin-top: 5px;
5697: }
1.795 www 5698:
1.600 albertel 5699: div.LC_edit_problem_header_title {
1.705 tempelho 5700: font-weight: bold;
5701: font-size: larger;
1.602 albertel 5702: background: $tabbg;
5703: padding: 3px;
5704: }
1.795 www 5705:
1.602 albertel 5706: table.LC_edit_problem_header_title {
1.705 tempelho 5707: font-size: larger;
5708: font-weight: bold;
1.602 albertel 5709: width: 100%;
5710: border-color: $pgbg;
5711: border-style: solid;
5712: border-width: $border;
1.600 albertel 5713: background: $tabbg;
1.602 albertel 5714: border-collapse: collapse;
1.803 bisitz 5715: padding: 0;
1.602 albertel 5716: }
5717:
5718: div.LC_edit_problem_discards {
5719: float: left;
5720: padding-bottom: 5px;
5721: }
1.795 www 5722:
1.602 albertel 5723: div.LC_edit_problem_saves {
5724: float: right;
5725: padding-bottom: 5px;
1.600 albertel 5726: }
1.795 www 5727:
1.679 riegler 5728: img.stift{
1.803 bisitz 5729: border-width: 0;
5730: vertical-align: middle;
1.677 riegler 5731: }
1.680 riegler 5732:
1.681 riegler 5733: table#LC_mainmenu{
5734: margin-top:10px;
5735: width:80%;
5736: }
5737:
1.680 riegler 5738: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5739: vertical-align: top;
5740: width: 45%;
5741: }
1.795 www 5742:
1.779 bisitz 5743: .LC_mainmenu_fieldset_category {
5744: color: $font;
5745: background: $pgbg;
5746: font-size: small;
5747: font-weight: bold;
1.777 tempelho 5748: }
1.795 www 5749:
1.716 raeburn 5750: div.LC_createcourse {
5751: margin: 10px 10px 10px 10px;
5752: }
5753:
1.693 droeschl 5754: /* ---- Remove when done ----
5755: # The following styles is part of the redesign of LON-CAPA and are
5756: # subject to change during this project.
5757: # Don't rely on their current functionality as they might be
5758: # changed or removed.
5759: # --------------------------*/
5760:
1.698 harmsja 5761: a:hover,
1.721 harmsja 5762: ol.LC_smallMenu a:hover,
5763: ol#LC_MenuBreadcrumbs a:hover,
5764: ol#LC_PathBreadcrumbs a:hover,
5765: ul#LC_TabMainMenuContent a:hover,
5766: .LC_FormSectionClearButton input:hover
1.795 www 5767: ul.LC_TabContent li:hover a {
1.698 harmsja 5768: color:#BF2317;
5769: text-decoration:none;
1.693 droeschl 5770: }
5771:
1.779 bisitz 5772: h1 {
1.813 bisitz 5773: padding: 0;
1.693 droeschl 5774: line-height:130%;
5775: }
1.698 harmsja 5776:
1.795 www 5777: h2,h3,h4,h5,h6 {
1.803 bisitz 5778: margin: 5px 0 5px 0;
5779: padding: 0;
1.721 harmsja 5780: line-height:130%;
1.693 droeschl 5781: }
1.795 www 5782:
5783: .LC_hcell {
1.698 harmsja 5784: padding:3px 15px 3px 15px;
1.803 bisitz 5785: margin: 0;
1.703 harmsja 5786: background-color:$tabbg;
1.801 tempelho 5787: color:$fontmenu;
1.779 bisitz 5788: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5789: }
1.795 www 5790:
1.840 bisitz 5791: .LC_Box > .LC_hcell {
1.847 tempelho 5792: margin: 0 -10px 10px -10px;
1.835 bisitz 5793: }
5794:
1.721 harmsja 5795: .LC_noBorder {
1.803 bisitz 5796: border: 0;
1.698 harmsja 5797: }
1.693 droeschl 5798:
1.761 tempelho 5799: .LC_Right {
5800: float: right;
1.803 bisitz 5801: margin: 0;
5802: padding: 0;
1.761 tempelho 5803: }
5804:
1.721 harmsja 5805: .LC_FormSectionClearButton input {
1.779 bisitz 5806: background-color:transparent;
1.803 bisitz 5807: border: none;
1.698 harmsja 5808: cursor:pointer;
5809: text-decoration:underline;
1.693 droeschl 5810: }
1.763 bisitz 5811:
5812: .LC_help_open_topic {
5813: color: #FFFFFF;
5814: background-color: #EEEEFF;
5815: margin: 1px;
5816: padding: 4px;
5817: border: 1px solid #000033;
5818: white-space: nowrap;
1.783 amueller 5819: /* vertical-align: middle; */
1.759 neumanie 5820: }
1.693 droeschl 5821:
1.698 harmsja 5822: dl,ul,div,fieldset {
1.803 bisitz 5823: margin: 10px 10px 10px 0;
1.806 bisitz 5824: /* overflow: hidden; */
1.693 droeschl 5825: }
1.795 www 5826:
1.838 bisitz 5827: fieldset > legend {
5828: font-weight: bold;
5829: padding: 0 5px 0 5px;
5830: }
5831:
1.813 bisitz 5832: #LC_nav_bar {
1.807 droeschl 5833: float: left;
1.852 droeschl 5834: margin: 0.2em 0 0 0;
1.807 droeschl 5835: }
5836:
1.813 bisitz 5837: #LC_nav_bar em{
1.807 droeschl 5838: font-weight: bold;
5839: font-style: normal;
5840: }
5841:
5842: ol.LC_smallMenu {
5843: float: right;
1.852 droeschl 5844: margin: 0.2em 0 0 0;
1.807 droeschl 5845: }
5846:
1.852 droeschl 5847: ol#LC_PathBreadcrumbs {
1.803 bisitz 5848: margin: 0;
1.693 droeschl 5849: }
5850:
1.721 harmsja 5851: ol.LC_smallMenu li {
1.693 droeschl 5852: display: inline;
1.803 bisitz 5853: padding: 5px 5px 0 10px;
1.693 droeschl 5854: vertical-align: top;
5855: }
5856:
1.721 harmsja 5857: ol.LC_smallMenu li img {
1.693 droeschl 5858: vertical-align: bottom;
5859: }
5860:
1.721 harmsja 5861: ol.LC_smallMenu a {
1.693 droeschl 5862: font-size: 90%;
5863: color: RGB(80, 80, 80);
5864: text-decoration: none;
5865: }
1.795 www 5866:
1.808 droeschl 5867: ul#LC_TabMainMenuContent {
1.807 droeschl 5868: clear: both;
1.808 droeschl 5869: color: $fontmenu;
5870: background: $tabbg;
5871: list-style: none;
5872: padding: 0;
5873: margin: 0;
5874: width: 100%;
5875: }
5876:
5877: ul#LC_TabMainMenuContent li {
5878: font-weight: bold;
5879: line-height: 1.8em;
5880: padding: 0 0.8em;
5881: border-right: 1px solid black;
5882: display: inline;
5883: vertical-align: middle;
1.807 droeschl 5884: }
5885:
1.847 tempelho 5886: ul.LC_TabContent {
1.721 harmsja 5887: display:block;
1.847 tempelho 5888: background: $sidebg;
1.858 bisitz 5889: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5890: list-style:none;
1.847 tempelho 5891: margin: -10px -10px 0 -10px;
1.803 bisitz 5892: padding: 0;
1.693 droeschl 5893: }
5894:
1.847 tempelho 5895: ul.LC_TabContentBigger {
5896: display:block;
5897: list-style:none;
5898: padding: 0;
5899: }
5900:
5901:
1.795 www 5902: ul.LC_TabContent li,
5903: ul.LC_TabContentBigger li {
1.693 droeschl 5904: display: inline;
1.741 harmsja 5905: border-right: solid 1px $lg_border_color;
5906: float:left;
5907: line-height:140%;
5908: white-space:nowrap;
5909: }
1.795 www 5910:
1.808 droeschl 5911: ul#LC_TabMainMenuContent li a {
5912: color: $fontmenu;
1.693 droeschl 5913: text-decoration: none;
5914: }
1.795 www 5915:
1.721 harmsja 5916: ul.LC_TabContent {
1.847 tempelho 5917: min-height:1.5em;
1.721 harmsja 5918: }
1.795 www 5919:
5920: ul.LC_TabContent li {
1.741 harmsja 5921: vertical-align:middle;
1.803 bisitz 5922: padding: 0 10px 0 10px;
1.745 ehlerst 5923: background-color:$tabbg;
5924: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5925: }
1.795 www 5926:
1.847 tempelho 5927: ul.LC_TabContent .right {
5928: float:right;
5929: }
5930:
1.795 www 5931: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5932: color:rgb(47,47,47);
5933: text-decoration:none;
5934: font-size:95%;
5935: font-weight:bold;
1.761 tempelho 5936: padding-right: 16px;
1.721 harmsja 5937: }
1.795 www 5938:
5939: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5940: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5941: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5942: padding-right: 16px;
1.744 ehlerst 5943: }
1.795 www 5944:
5945: ul.LC_TabContentBigger li {
1.741 harmsja 5946: vertical-align:bottom;
5947: border-top:solid 1px $lg_border_color;
5948: border-left:solid 1px $lg_border_color;
5949: padding:5px 10px 5px 10px;
5950: margin-left:2px;
1.841 tempelho 5951: background: #d9d9d9;
5952: }
5953:
5954: #maincoursedoc {
5955: clear:both;
1.741 harmsja 5956: }
1.795 www 5957:
5958: ul.LC_TabContentBigger li:hover,
5959: ul.LC_TabContentBigger li.active {
1.847 tempelho 5960: background: #ffffff;
1.857 tempelho 5961: color:$font;
1.744 ehlerst 5962: }
1.795 www 5963:
5964: ul.LC_TabContentBigger li,
5965: ul.LC_TabContentBigger li a {
1.741 harmsja 5966: font-size:110%;
5967: font-weight:bold;
1.857 tempelho 5968: color: #737373;
1.741 harmsja 5969: }
1.693 droeschl 5970:
1.862 bisitz 5971: ul.LC_CourseBreadcrumbs {
5972: background: $sidebg;
5973: line-height: 32px;
5974: padding-left: 10px;
5975: margin: 0 0 10px 0;
5976: list-style-position: inside;
5977:
5978: }
5979:
1.795 www 5980: ol#LC_MenuBreadcrumbs,
1.862 bisitz 5981: ol#LC_PathBreadcrumbs {
1.693 droeschl 5982: padding-left: 10px;
1.819 tempelho 5983: margin: 0;
1.693 droeschl 5984: list-style-position: inside;
5985: }
5986:
1.795 www 5987: ol#LC_MenuBreadcrumbs li,
5988: ol#LC_PathBreadcrumbs li,
1.862 bisitz 5989: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 5990: display: inline;
5991: white-space: nowrap;
1.693 droeschl 5992: }
5993:
1.823 bisitz 5994: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 5995: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 5996: text-decoration: none;
5997: font-size:90%;
5998: }
1.795 www 5999:
6000: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6001: text-decoration:none;
6002: font-size:100%;
6003: font-weight:bold;
1.693 droeschl 6004: }
1.795 www 6005:
1.840 bisitz 6006: .LC_Box {
1.835 bisitz 6007: border: solid 1px $lg_border_color;
6008: padding: 0 10px 10px 10px;
1.746 neumanie 6009: }
1.795 www 6010:
6011: .LC_AboutMe_Image {
1.747 neumanie 6012: float:left;
6013: margin-right:10px;
6014: }
1.795 www 6015:
6016: .LC_Clear_AboutMe_Image {
1.747 neumanie 6017: clear:left;
6018: }
1.795 www 6019:
1.721 harmsja 6020: dl.LC_ListStyleClean dt {
1.693 droeschl 6021: padding-right: 5px;
6022: display: table-header-group;
6023: }
6024:
1.721 harmsja 6025: dl.LC_ListStyleClean dd {
1.693 droeschl 6026: display: table-row;
6027: }
6028:
1.721 harmsja 6029: .LC_ListStyleClean,
6030: .LC_ListStyleSimple,
6031: .LC_ListStyleNormal,
1.777 tempelho 6032: .LC_ListStyle_Border,
1.795 www 6033: .LC_ListStyleSpecial {
1.693 droeschl 6034: /*display:block; */
6035: list-style-position: inside;
6036: list-style-type: none;
6037: overflow: hidden;
1.803 bisitz 6038: padding: 0;
1.693 droeschl 6039: }
6040:
1.721 harmsja 6041: .LC_ListStyleSimple li,
6042: .LC_ListStyleSimple dd,
6043: .LC_ListStyleNormal li,
6044: .LC_ListStyleNormal dd,
6045: .LC_ListStyleSpecial li,
1.795 www 6046: .LC_ListStyleSpecial dd {
1.803 bisitz 6047: margin: 0;
1.693 droeschl 6048: padding: 5px 5px 5px 10px;
6049: clear: both;
6050: }
6051:
1.721 harmsja 6052: .LC_ListStyleClean li,
6053: .LC_ListStyleClean dd {
1.803 bisitz 6054: padding-top: 0;
6055: padding-bottom: 0;
1.693 droeschl 6056: }
6057:
1.721 harmsja 6058: .LC_ListStyleSimple dd,
1.795 www 6059: .LC_ListStyleSimple li {
1.698 harmsja 6060: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6061: }
6062:
1.721 harmsja 6063: .LC_ListStyleSpecial li,
6064: .LC_ListStyleSpecial dd {
1.693 droeschl 6065: list-style-type: none;
6066: background-color: RGB(220, 220, 220);
6067: margin-bottom: 4px;
6068: }
6069:
1.721 harmsja 6070: table.LC_SimpleTable {
1.698 harmsja 6071: margin:5px;
6072: border:solid 1px $lg_border_color;
1.795 www 6073: }
1.693 droeschl 6074:
1.721 harmsja 6075: table.LC_SimpleTable tr {
1.803 bisitz 6076: padding: 0;
1.698 harmsja 6077: border:solid 1px $lg_border_color;
1.693 droeschl 6078: }
1.795 www 6079:
6080: table.LC_SimpleTable thead {
1.698 harmsja 6081: background:rgb(220,220,220);
1.693 droeschl 6082: }
6083:
1.721 harmsja 6084: div.LC_columnSection {
1.693 droeschl 6085: display: block;
6086: clear: both;
6087: overflow: hidden;
1.803 bisitz 6088: margin: 0;
1.693 droeschl 6089: }
6090:
1.721 harmsja 6091: div.LC_columnSection>* {
1.693 droeschl 6092: float: left;
1.803 bisitz 6093: margin: 10px 20px 10px 0;
1.747 neumanie 6094: overflow:hidden;
1.693 droeschl 6095: }
1.721 harmsja 6096:
1.694 tempelho 6097: .LC_loginpage_container {
6098: text-align:left;
6099: margin : 0 auto;
1.785 tempelho 6100: width:90%;
1.694 tempelho 6101: padding: 10px;
6102: height: auto;
1.712 muellerd 6103: background-color:#FFFFFF;
1.694 tempelho 6104: border:1px solid #CCCCCC;
6105: }
6106:
6107:
6108: .LC_loginpage_loginContainer {
6109: float:left;
1.712 muellerd 6110: width: 182px;
1.785 tempelho 6111: padding: 2px;
1.712 muellerd 6112: border:1px solid #CCCCCC;
6113: background-color:$loginbg;
1.694 tempelho 6114: }
6115:
1.795 www 6116: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6117: margin-top: 0;
1.712 muellerd 6118: display:block;
6119: background:$bgcol;
6120: color:$textcol;
6121: padding-left:5px;
6122: }
1.785 tempelho 6123:
1.694 tempelho 6124: .LC_loginpage_loginInfo {
6125: float:left;
1.785 tempelho 6126: width:182px;
1.694 tempelho 6127: border:1px solid #CCCCCC;
1.785 tempelho 6128: padding:2px;
1.712 muellerd 6129: }
6130:
1.694 tempelho 6131: .LC_loginpage_space {
1.754 droeschl 6132: clear: both;
6133: margin-bottom: 20px;
1.694 tempelho 6134: border-bottom: 1px solid #CCCCCC;
6135: }
6136:
1.785 tempelho 6137: .LC_loginpage_floatLeft {
6138: float: left;
6139: width: 200px;
6140: margin: 0;
6141: }
6142:
1.795 www 6143: table em {
1.754 droeschl 6144: font-weight: bold;
6145: font-style: normal;
1.748 schulted 6146: }
1.795 www 6147:
1.779 bisitz 6148: table.LC_tableBrowseRes,
1.795 www 6149: table.LC_tableOfContent {
1.769 schulted 6150: border:none;
1.858 bisitz 6151: border-spacing: 1px;
1.754 droeschl 6152: padding: 3px;
6153: background-color: #FFFFFF;
6154: font-size: 90%;
1.753 droeschl 6155: }
1.789 droeschl 6156:
6157: table.LC_tableOfContent{
6158: border-collapse: collapse;
6159: }
6160:
1.771 droeschl 6161: table.LC_tableBrowseRes a,
1.768 schulted 6162: table.LC_tableOfContent a {
1.771 droeschl 6163: background-color: transparent;
1.753 droeschl 6164: text-decoration: none;
6165: }
6166:
1.771 droeschl 6167: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6168: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6169: background-color: #EEEEEE;
1.753 droeschl 6170: }
6171:
1.795 www 6172: table.LC_tableOfContent img {
1.753 droeschl 6173: border: none;
6174: height: 1.3em;
6175: vertical-align: text-bottom;
6176: margin-right: 0.3em;
6177: }
1.757 schulted 6178:
1.795 www 6179: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6180: background-image:url(/res/adm/pages/open-first-problem.gif);
6181: }
6182:
1.795 www 6183: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6184: background-image:url(/res/adm/pages/start-navigation.gif);
6185: }
6186:
1.795 www 6187: a#LC_content_toolbar_closenav {
1.774 ehlerst 6188: background-image:url(/res/adm/pages/close-navigation.gif);
6189: }
6190:
1.795 www 6191: a#LC_content_toolbar_everything {
1.774 ehlerst 6192: background-image:url(/res/adm/pages/show-all.gif);
6193: }
6194:
1.795 www 6195: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6196: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6197: }
6198:
1.795 www 6199: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6200: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6201: }
6202:
1.795 www 6203: a#LC_content_toolbar_changefolder {
1.757 schulted 6204: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6205: }
6206:
1.795 www 6207: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6208: background-image:url(/res/adm/pages/open-all-folders.gif);
6209: }
6210:
1.795 www 6211: ul#LC_toolbar li a:hover {
1.757 schulted 6212: background-position: bottom center;
6213: }
6214:
1.795 www 6215: ul#LC_toolbar {
1.803 bisitz 6216: padding: 0;
1.757 schulted 6217: margin: 2px;
6218: list-style:none;
6219: position:relative;
6220: background-color:white;
6221: }
6222:
1.795 www 6223: ul#LC_toolbar li {
1.757 schulted 6224: border:1px solid white;
1.803 bisitz 6225: padding: 0;
1.757 schulted 6226: margin: 0;
1.795 www 6227: float: left;
1.767 droeschl 6228: display:inline;
1.757 schulted 6229: vertical-align:middle;
1.795 www 6230: }
1.757 schulted 6231:
1.783 amueller 6232:
1.795 www 6233: a.LC_toolbarItem {
1.767 droeschl 6234: display:block;
1.803 bisitz 6235: padding: 0;
6236: margin: 0;
1.757 schulted 6237: height: 32px;
6238: width: 32px;
1.779 bisitz 6239: color:white;
1.803 bisitz 6240: border: none;
1.757 schulted 6241: background-repeat:no-repeat;
6242: background-color:transparent;
6243: }
6244:
1.843 bisitz 6245: ul.LC_funclist li {
1.782 bisitz 6246: float: left;
6247: white-space: nowrap;
6248: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6249: margin: 0 15px 15px 10px;
1.782 bisitz 6250: }
6251:
1.757 schulted 6252:
1.343 albertel 6253: END
6254: }
6255:
1.306 albertel 6256: =pod
6257:
6258: =item * &headtag()
6259:
6260: Returns a uniform footer for LON-CAPA web pages.
6261:
1.307 albertel 6262: Inputs: $title - optional title for the head
6263: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6264: $args - optional arguments
1.319 albertel 6265: force_register - if is true call registerurl so the remote is
6266: informed
1.415 albertel 6267: redirect -> array ref of
6268: 1- seconds before redirect occurs
6269: 2- url to redirect to
6270: 3- whether the side effect should occur
1.315 albertel 6271: (side effect of setting
6272: $env{'internal.head.redirect'} to the url
6273: redirected too)
1.352 albertel 6274: domain -> force to color decorate a page for a specific
6275: domain
6276: function -> force usage of a specific rolish color scheme
6277: bgcolor -> override the default page bgcolor
1.460 albertel 6278: no_auto_mt_title
6279: -> prevent &mt()ing the title arg
1.464 albertel 6280:
1.306 albertel 6281: =cut
6282:
6283: sub headtag {
1.313 albertel 6284: my ($title,$head_extra,$args) = @_;
1.306 albertel 6285:
1.363 albertel 6286: my $function = $args->{'function'} || &get_users_function();
6287: my $domain = $args->{'domain'} || &determinedomain();
6288: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6289: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6290: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6291: #time(),
1.418 albertel 6292: $env{'environment.color.timestamp'},
1.363 albertel 6293: $function,$domain,$bgcolor);
6294:
1.369 www 6295: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6296:
1.308 albertel 6297: my $result =
6298: '<head>'.
1.461 albertel 6299: &font_settings();
1.319 albertel 6300:
1.461 albertel 6301: if (!$args->{'frameset'}) {
6302: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6303: }
1.319 albertel 6304: if ($args->{'force_register'}) {
6305: $result .= &Apache::lonmenu::registerurl(1);
6306: }
1.436 albertel 6307: if (!$args->{'no_nav_bar'}
6308: && !$args->{'only_body'}
6309: && !$args->{'frameset'}) {
6310: $result .= &help_menu_js();
6311: }
1.319 albertel 6312:
1.314 albertel 6313: if (ref($args->{'redirect'})) {
1.414 albertel 6314: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6315: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6316: if (!$inhibit_continue) {
6317: $env{'internal.head.redirect'} = $url;
6318: }
1.313 albertel 6319: $result.=<<ADDMETA
6320: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6321: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6322: ADDMETA
6323: }
1.306 albertel 6324: if (!defined($title)) {
6325: $title = 'The LearningOnline Network with CAPA';
6326: }
1.460 albertel 6327: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6328: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6329: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6330: .$head_extra;
1.306 albertel 6331: return $result;
6332: }
6333:
6334: =pod
6335:
1.340 albertel 6336: =item * &font_settings()
6337:
6338: Returns neccessary <meta> to set the proper encoding
6339:
6340: Inputs: none
6341:
6342: =cut
6343:
6344: sub font_settings {
6345: my $headerstring='';
1.647 www 6346: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6347: $headerstring.=
6348: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6349: }
6350: return $headerstring;
6351: }
6352:
1.341 albertel 6353: =pod
6354:
6355: =item * &xml_begin()
6356:
6357: Returns the needed doctype and <html>
6358:
6359: Inputs: none
6360:
6361: =cut
6362:
6363: sub xml_begin {
6364: my $output='';
6365:
1.592 albertel 6366: if ($env{'internal.start_page'}==1) {
6367: &Apache::lonhtmlcommon::init_htmlareafields();
6368: }
1.342 albertel 6369:
1.341 albertel 6370: if ($env{'browser.mathml'}) {
6371: $output='<?xml version="1.0"?>'
6372: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6373: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6374:
6375: # .'<!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">] >'
6376: .'<!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">'
6377: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6378: .'xmlns="http://www.w3.org/1999/xhtml">';
6379: } else {
1.849 bisitz 6380: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6381: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6382: }
6383: return $output;
6384: }
1.340 albertel 6385:
6386: =pod
6387:
1.306 albertel 6388: =item * &endheadtag()
6389:
6390: Returns a uniform </head> for LON-CAPA web pages.
6391:
6392: Inputs: none
6393:
6394: =cut
6395:
6396: sub endheadtag {
6397: return '</head>';
6398: }
6399:
6400: =pod
6401:
6402: =item * &head()
6403:
6404: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6405:
1.648 raeburn 6406: Inputs:
6407:
6408: =over 4
6409:
6410: $title - optional title for the page
6411:
6412: $head_extra - optional extra HTML to put inside the <head>
6413:
6414: =back
1.405 albertel 6415:
1.306 albertel 6416: =cut
6417:
6418: sub head {
1.325 albertel 6419: my ($title,$head_extra,$args) = @_;
6420: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6421: }
6422:
6423: =pod
6424:
6425: =item * &start_page()
6426:
6427: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6428:
1.648 raeburn 6429: Inputs:
6430:
6431: =over 4
6432:
6433: $title - optional title for the page
6434:
6435: $head_extra - optional extra HTML to incude inside the <head>
6436:
6437: $args - additional optional args supported are:
6438:
6439: =over 8
6440:
6441: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6442: arg on
1.814 bisitz 6443: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6444: add_entries -> additional attributes to add to the <body>
6445: domain -> force to color decorate a page for a
1.317 albertel 6446: specific domain
1.648 raeburn 6447: function -> force usage of a specific rolish color
1.317 albertel 6448: scheme
1.648 raeburn 6449: redirect -> see &headtag()
6450: bgcolor -> override the default page bg color
6451: js_ready -> return a string ready for being used in
1.317 albertel 6452: a javascript writeln
1.648 raeburn 6453: html_encode -> return a string ready for being used in
1.320 albertel 6454: a html attribute
1.648 raeburn 6455: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6456: $forcereg arg
1.648 raeburn 6457: frameset -> if true will start with a <frameset>
1.330 albertel 6458: rather than <body>
1.648 raeburn 6459: skip_phases -> hash ref of
1.338 albertel 6460: head -> skip the <html><head> generation
6461: body -> skip all <body> generation
1.648 raeburn 6462: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6463: 'Switch To Inline Menu' link
1.648 raeburn 6464: no_auto_mt_title -> prevent &mt()ing the title arg
6465: inherit_jsmath -> when creating popup window in a page,
6466: should it have jsmath forced on by the
6467: current page
1.867 ! kalberla 6468: bread_crumbs -> Array containing breadcrumbs
! 6469: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6470:
1.648 raeburn 6471: =back
1.460 albertel 6472:
1.648 raeburn 6473: =back
1.562 albertel 6474:
1.306 albertel 6475: =cut
6476:
6477: sub start_page {
1.309 albertel 6478: my ($title,$head_extra,$args) = @_;
1.318 albertel 6479: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6480: my %head_args;
1.352 albertel 6481: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6482: 'bgcolor','frameset','no_nav_bar','only_body',
6483: 'no_auto_mt_title') {
1.319 albertel 6484: if (defined($args->{$arg})) {
1.324 raeburn 6485: $head_args{$arg} = $args->{$arg};
1.319 albertel 6486: }
1.313 albertel 6487: }
1.319 albertel 6488:
1.315 albertel 6489: $env{'internal.start_page'}++;
1.338 albertel 6490: my $result;
6491: if (! exists($args->{'skip_phases'}{'head'}) ) {
6492: $result.=
1.341 albertel 6493: &xml_begin().
1.338 albertel 6494: &headtag($title,$head_extra,\%head_args).&endheadtag();
6495: }
6496:
6497: if (! exists($args->{'skip_phases'}{'body'}) ) {
6498: if ($args->{'frameset'}) {
6499: my $attr_string = &make_attr_string($args->{'force_register'},
6500: $args->{'add_entries'});
6501: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6502: } else {
6503: $result .=
6504: &bodytag($title,
6505: $args->{'function'}, $args->{'add_entries'},
6506: $args->{'only_body'}, $args->{'domain'},
6507: $args->{'force_register'}, $args->{'no_nav_bar'},
6508: $args->{'bgcolor'}, $args->{'no_inline_link'},
6509: $args);
6510: }
1.330 albertel 6511: }
1.338 albertel 6512:
1.315 albertel 6513: if ($args->{'js_ready'}) {
1.713 kaisler 6514: $result = &js_ready($result);
1.315 albertel 6515: }
1.320 albertel 6516: if ($args->{'html_encode'}) {
1.713 kaisler 6517: $result = &html_encode($result);
6518: }
6519:
1.813 bisitz 6520: # Preparation for new and consistent functionlist at top of screen
6521: # if ($args->{'functionlist'}) {
6522: # $result .= &build_functionlist();
6523: #}
6524:
6525: # Don't add anything more if only_body wanted
6526: return $result if $args->{'only_body'};
6527:
6528: #Breadcrumbs
1.758 kaisler 6529: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6530: &Apache::lonhtmlcommon::clear_breadcrumbs();
6531: #if any br links exists, add them to the breadcrumbs
6532: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6533: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6534: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6535: }
6536: }
6537:
6538: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6539: if(exists($args->{'bread_crumbs_component'})){
6540: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6541: }else{
6542: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6543: }
1.320 albertel 6544: }
1.315 albertel 6545: return $result;
1.306 albertel 6546: }
6547:
1.330 albertel 6548:
1.306 albertel 6549: =pod
6550:
6551: =item * &head()
6552:
6553: Returns a complete </body></html> section for LON-CAPA web pages.
6554:
1.315 albertel 6555: Inputs: $args - additional optional args supported are:
6556: js_ready -> return a string ready for being used in
6557: a javascript writeln
1.320 albertel 6558: html_encode -> return a string ready for being used in
6559: a html attribute
1.330 albertel 6560: frameset -> if true will start with a <frameset>
6561: rather than <body>
1.493 albertel 6562: dicsussion -> if true will get discussion from
6563: lonxml::xmlend
6564: (you can pass the target and parser arguments
6565: through optional 'target' and 'parser' args
6566: to this routine)
1.306 albertel 6567:
6568: =cut
6569:
6570: sub end_page {
1.315 albertel 6571: my ($args) = @_;
6572: $env{'internal.end_page'}++;
1.330 albertel 6573: my $result;
1.335 albertel 6574: if ($args->{'discussion'}) {
6575: my ($target,$parser);
6576: if (ref($args->{'discussion'})) {
6577: ($target,$parser) =($args->{'discussion'}{'target'},
6578: $args->{'discussion'}{'parser'});
6579: }
6580: $result .= &Apache::lonxml::xmlend($target,$parser);
6581: }
6582:
1.330 albertel 6583: if ($args->{'frameset'}) {
6584: $result .= '</frameset>';
6585: } else {
1.635 raeburn 6586: $result .= &endbodytag($args);
1.330 albertel 6587: }
6588: $result .= "\n</html>";
6589:
1.315 albertel 6590: if ($args->{'js_ready'}) {
1.317 albertel 6591: $result = &js_ready($result);
1.315 albertel 6592: }
1.335 albertel 6593:
1.320 albertel 6594: if ($args->{'html_encode'}) {
6595: $result = &html_encode($result);
6596: }
1.335 albertel 6597:
1.315 albertel 6598: return $result;
6599: }
6600:
1.320 albertel 6601: sub html_encode {
6602: my ($result) = @_;
6603:
1.322 albertel 6604: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6605:
6606: return $result;
6607: }
1.317 albertel 6608: sub js_ready {
6609: my ($result) = @_;
6610:
1.323 albertel 6611: $result =~ s/[\n\r]/ /xmsg;
6612: $result =~ s/\\/\\\\/xmsg;
6613: $result =~ s/'/\\'/xmsg;
1.372 albertel 6614: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6615:
6616: return $result;
6617: }
6618:
1.315 albertel 6619: sub validate_page {
6620: if ( exists($env{'internal.start_page'})
1.316 albertel 6621: && $env{'internal.start_page'} > 1) {
6622: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6623: $env{'internal.start_page'}.' '.
1.316 albertel 6624: $ENV{'request.filename'});
1.315 albertel 6625: }
6626: if ( exists($env{'internal.end_page'})
1.316 albertel 6627: && $env{'internal.end_page'} > 1) {
6628: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6629: $env{'internal.end_page'}.' '.
1.316 albertel 6630: $env{'request.filename'});
1.315 albertel 6631: }
6632: if ( exists($env{'internal.start_page'})
6633: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6634: &Apache::lonnet::logthis('start_page called without end_page '.
6635: $env{'request.filename'});
1.315 albertel 6636: }
6637: if ( ! exists($env{'internal.start_page'})
6638: && exists($env{'internal.end_page'})) {
1.316 albertel 6639: &Apache::lonnet::logthis('end_page called without start_page'.
6640: $env{'request.filename'});
1.315 albertel 6641: }
1.306 albertel 6642: }
1.315 albertel 6643:
1.318 albertel 6644: sub simple_error_page {
6645: my ($r,$title,$msg) = @_;
6646: my $page =
6647: &Apache::loncommon::start_page($title).
6648: &mt($msg).
6649: &Apache::loncommon::end_page();
6650: if (ref($r)) {
6651: $r->print($page);
1.327 albertel 6652: return;
1.318 albertel 6653: }
6654: return $page;
6655: }
1.347 albertel 6656:
6657: {
1.610 albertel 6658: my @row_count;
1.347 albertel 6659: sub start_data_table {
1.422 albertel 6660: my ($add_class) = @_;
6661: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6662: unshift(@row_count,0);
1.422 albertel 6663: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6664: }
6665:
6666: sub end_data_table {
1.610 albertel 6667: shift(@row_count);
1.389 albertel 6668: return '</table>'."\n";;
1.347 albertel 6669: }
6670:
6671: sub start_data_table_row {
1.422 albertel 6672: my ($add_class) = @_;
1.610 albertel 6673: $row_count[0]++;
6674: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6675: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6676: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6677: }
1.471 banghart 6678:
6679: sub continue_data_table_row {
6680: my ($add_class) = @_;
1.610 albertel 6681: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6682: $css_class = (join(' ',$css_class,$add_class));
6683: return '<tr class="'.$css_class.'">'."\n";;
6684: }
1.347 albertel 6685:
6686: sub end_data_table_row {
1.389 albertel 6687: return '</tr>'."\n";;
1.347 albertel 6688: }
1.367 www 6689:
1.421 albertel 6690: sub start_data_table_empty_row {
1.707 bisitz 6691: # $row_count[0]++;
1.421 albertel 6692: return '<tr class="LC_empty_row" >'."\n";;
6693: }
6694:
6695: sub end_data_table_empty_row {
6696: return '</tr>'."\n";;
6697: }
6698:
1.367 www 6699: sub start_data_table_header_row {
1.389 albertel 6700: return '<tr class="LC_header_row">'."\n";;
1.367 www 6701: }
6702:
6703: sub end_data_table_header_row {
1.389 albertel 6704: return '</tr>'."\n";;
1.367 www 6705: }
1.347 albertel 6706: }
6707:
1.548 albertel 6708: =pod
6709:
6710: =item * &inhibit_menu_check($arg)
6711:
6712: Checks for a inhibitmenu state and generates output to preserve it
6713:
6714: Inputs: $arg - can be any of
6715: - undef - in which case the return value is a string
6716: to add into arguments list of a uri
6717: - 'input' - in which case the return value is a HTML
6718: <form> <input> field of type hidden to
6719: preserve the value
6720: - a url - in which case the return value is the url with
6721: the neccesary cgi args added to preserve the
6722: inhibitmenu state
6723: - a ref to a url - no return value, but the string is
6724: updated to include the neccessary cgi
6725: args to preserve the inhibitmenu state
6726:
6727: =cut
6728:
6729: sub inhibit_menu_check {
6730: my ($arg) = @_;
6731: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6732: if ($arg eq 'input') {
6733: if ($env{'form.inhibitmenu'}) {
6734: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6735: } else {
6736: return
6737: }
6738: }
6739: if ($env{'form.inhibitmenu'}) {
6740: if (ref($arg)) {
6741: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6742: } elsif ($arg eq '') {
6743: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6744: } else {
6745: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6746: }
6747: }
6748: if (!ref($arg)) {
6749: return $arg;
6750: }
6751: }
6752:
1.251 albertel 6753: ###############################################
1.182 matthew 6754:
6755: =pod
6756:
1.549 albertel 6757: =back
6758:
6759: =head1 User Information Routines
6760:
6761: =over 4
6762:
1.405 albertel 6763: =item * &get_users_function()
1.182 matthew 6764:
6765: Used by &bodytag to determine the current users primary role.
6766: Returns either 'student','coordinator','admin', or 'author'.
6767:
6768: =cut
6769:
6770: ###############################################
6771: sub get_users_function {
1.815 tempelho 6772: my $function = 'norole';
1.818 tempelho 6773: if ($env{'request.role'}=~/^(st)/) {
6774: $function='student';
6775: }
1.258 albertel 6776: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6777: $function='coordinator';
6778: }
1.258 albertel 6779: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6780: $function='admin';
6781: }
1.826 bisitz 6782: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6783: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6784: $function='author';
6785: }
6786: return $function;
1.54 www 6787: }
1.99 www 6788:
6789: ###############################################
6790:
1.233 raeburn 6791: =pod
6792:
1.821 raeburn 6793: =item * &show_course()
6794:
6795: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6796: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6797:
6798: Inputs:
6799: None
6800:
6801: Outputs:
6802: Scalar: 1 if 'Course' to be used, 0 otherwise.
6803:
6804: =cut
6805:
6806: ###############################################
6807: sub show_course {
6808: my $course = !$env{'user.adv'};
6809: if (!$env{'user.adv'}) {
6810: foreach my $env (keys(%env)) {
6811: next if ($env !~ m/^user\.priv\./);
6812: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6813: $course = 0;
6814: last;
6815: }
6816: }
6817: }
6818: return $course;
6819: }
6820:
6821: ###############################################
6822:
6823: =pod
6824:
1.542 raeburn 6825: =item * &check_user_status()
1.274 raeburn 6826:
6827: Determines current status of supplied role for a
6828: specific user. Roles can be active, previous or future.
6829:
6830: Inputs:
6831: user's domain, user's username, course's domain,
1.375 raeburn 6832: course's number, optional section ID.
1.274 raeburn 6833:
6834: Outputs:
6835: role status: active, previous or future.
6836:
6837: =cut
6838:
6839: sub check_user_status {
1.412 raeburn 6840: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6841: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6842: my @uroles = keys %userinfo;
6843: my $srchstr;
6844: my $active_chk = 'none';
1.412 raeburn 6845: my $now = time;
1.274 raeburn 6846: if (@uroles > 0) {
1.412 raeburn 6847: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6848: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6849: } else {
1.412 raeburn 6850: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6851: }
6852: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6853: my $role_end = 0;
6854: my $role_start = 0;
6855: $active_chk = 'active';
1.412 raeburn 6856: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6857: $role_end = $1;
6858: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6859: $role_start = $1;
1.274 raeburn 6860: }
6861: }
6862: if ($role_start > 0) {
1.412 raeburn 6863: if ($now < $role_start) {
1.274 raeburn 6864: $active_chk = 'future';
6865: }
6866: }
6867: if ($role_end > 0) {
1.412 raeburn 6868: if ($now > $role_end) {
1.274 raeburn 6869: $active_chk = 'previous';
6870: }
6871: }
6872: }
6873: }
6874: return $active_chk;
6875: }
6876:
6877: ###############################################
6878:
6879: =pod
6880:
1.405 albertel 6881: =item * &get_sections()
1.233 raeburn 6882:
6883: Determines all the sections for a course including
6884: sections with students and sections containing other roles.
1.419 raeburn 6885: Incoming parameters:
6886:
6887: 1. domain
6888: 2. course number
6889: 3. reference to array containing roles for which sections should
6890: be gathered (optional).
6891: 4. reference to array containing status types for which sections
6892: should be gathered (optional).
6893:
6894: If the third argument is undefined, sections are gathered for any role.
6895: If the fourth argument is undefined, sections are gathered for any status.
6896: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6897:
1.374 raeburn 6898: Returns section hash (keys are section IDs, values are
6899: number of users in each section), subject to the
1.419 raeburn 6900: optional roles filter, optional status filter
1.233 raeburn 6901:
6902: =cut
6903:
6904: ###############################################
6905: sub get_sections {
1.419 raeburn 6906: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6907: if (!defined($cdom) || !defined($cnum)) {
6908: my $cid = $env{'request.course.id'};
6909:
6910: return if (!defined($cid));
6911:
6912: $cdom = $env{'course.'.$cid.'.domain'};
6913: $cnum = $env{'course.'.$cid.'.num'};
6914: }
6915:
6916: my %sectioncount;
1.419 raeburn 6917: my $now = time;
1.240 albertel 6918:
1.366 albertel 6919: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6920: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6921: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6922: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6923: my $start_index = &Apache::loncoursedata::CL_START();
6924: my $end_index = &Apache::loncoursedata::CL_END();
6925: my $status;
1.366 albertel 6926: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6927: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6928: $data->[$status_index],
6929: $data->[$start_index],
6930: $data->[$end_index]);
6931: if ($stu_status eq 'Active') {
6932: $status = 'active';
6933: } elsif ($end < $now) {
6934: $status = 'previous';
6935: } elsif ($start > $now) {
6936: $status = 'future';
6937: }
6938: if ($section ne '-1' && $section !~ /^\s*$/) {
6939: if ((!defined($possible_status)) || (($status ne '') &&
6940: (grep/^\Q$status\E$/,@{$possible_status}))) {
6941: $sectioncount{$section}++;
6942: }
1.240 albertel 6943: }
6944: }
6945: }
6946: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6947: foreach my $user (sort(keys(%courseroles))) {
6948: if ($user !~ /^(\w{2})/) { next; }
6949: my ($role) = ($user =~ /^(\w{2})/);
6950: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6951: my ($section,$status);
1.240 albertel 6952: if ($role eq 'cr' &&
6953: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6954: $section=$1;
6955: }
6956: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6957: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6958: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6959: if ($end == -1 && $start == -1) {
6960: next; #deleted role
6961: }
6962: if (!defined($possible_status)) {
6963: $sectioncount{$section}++;
6964: } else {
6965: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6966: $status = 'active';
6967: } elsif ($end < $now) {
6968: $status = 'future';
6969: } elsif ($start > $now) {
6970: $status = 'previous';
6971: }
6972: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6973: $sectioncount{$section}++;
6974: }
6975: }
1.233 raeburn 6976: }
1.366 albertel 6977: return %sectioncount;
1.233 raeburn 6978: }
6979:
1.274 raeburn 6980: ###############################################
1.294 raeburn 6981:
6982: =pod
1.405 albertel 6983:
6984: =item * &get_course_users()
6985:
1.275 raeburn 6986: Retrieves usernames:domains for users in the specified course
6987: with specific role(s), and access status.
6988:
6989: Incoming parameters:
1.277 albertel 6990: 1. course domain
6991: 2. course number
6992: 3. access status: users must have - either active,
1.275 raeburn 6993: previous, future, or all.
1.277 albertel 6994: 4. reference to array of permissible roles
1.288 raeburn 6995: 5. reference to array of section restrictions (optional)
6996: 6. reference to results object (hash of hashes).
6997: 7. reference to optional userdata hash
1.609 raeburn 6998: 8. reference to optional statushash
1.630 raeburn 6999: 9. flag if privileged users (except those set to unhide in
7000: course settings) should be excluded
1.609 raeburn 7001: Keys of top level results hash are roles.
1.275 raeburn 7002: Keys of inner hashes are username:domain, with
7003: values set to access type.
1.288 raeburn 7004: Optional userdata hash returns an array with arguments in the
7005: same order as loncoursedata::get_classlist() for student data.
7006:
1.609 raeburn 7007: Optional statushash returns
7008:
1.288 raeburn 7009: Entries for end, start, section and status are blank because
7010: of the possibility of multiple values for non-student roles.
7011:
1.275 raeburn 7012: =cut
1.405 albertel 7013:
1.275 raeburn 7014: ###############################################
1.405 albertel 7015:
1.275 raeburn 7016: sub get_course_users {
1.630 raeburn 7017: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7018: my %idx = ();
1.419 raeburn 7019: my %seclists;
1.288 raeburn 7020:
7021: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7022: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7023: $idx{end} = &Apache::loncoursedata::CL_END();
7024: $idx{start} = &Apache::loncoursedata::CL_START();
7025: $idx{id} = &Apache::loncoursedata::CL_ID();
7026: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7027: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7028: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7029:
1.290 albertel 7030: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7031: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7032: my $now = time;
1.277 albertel 7033: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7034: my $match = 0;
1.412 raeburn 7035: my $secmatch = 0;
1.419 raeburn 7036: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7037: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7038: if ($section eq '') {
7039: $section = 'none';
7040: }
1.291 albertel 7041: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7042: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7043: $secmatch = 1;
7044: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7045: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7046: $secmatch = 1;
7047: }
7048: } else {
1.419 raeburn 7049: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7050: $secmatch = 1;
7051: }
1.290 albertel 7052: }
1.412 raeburn 7053: if (!$secmatch) {
7054: next;
7055: }
1.419 raeburn 7056: }
1.275 raeburn 7057: if (defined($$types{'active'})) {
1.288 raeburn 7058: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7059: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7060: $match = 1;
1.275 raeburn 7061: }
7062: }
7063: if (defined($$types{'previous'})) {
1.609 raeburn 7064: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7065: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7066: $match = 1;
1.275 raeburn 7067: }
7068: }
7069: if (defined($$types{'future'})) {
1.609 raeburn 7070: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7071: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7072: $match = 1;
1.275 raeburn 7073: }
7074: }
1.609 raeburn 7075: if ($match) {
7076: push(@{$seclists{$student}},$section);
7077: if (ref($userdata) eq 'HASH') {
7078: $$userdata{$student} = $$classlist{$student};
7079: }
7080: if (ref($statushash) eq 'HASH') {
7081: $statushash->{$student}{'st'}{$section} = $status;
7082: }
1.288 raeburn 7083: }
1.275 raeburn 7084: }
7085: }
1.412 raeburn 7086: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7087: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7088: my $now = time;
1.609 raeburn 7089: my %displaystatus = ( previous => 'Expired',
7090: active => 'Active',
7091: future => 'Future',
7092: );
1.630 raeburn 7093: my %nothide;
7094: if ($hidepriv) {
7095: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7096: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7097: if ($user !~ /:/) {
7098: $nothide{join(':',split(/[\@]/,$user))}=1;
7099: } else {
7100: $nothide{$user} = 1;
7101: }
7102: }
7103: }
1.439 raeburn 7104: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7105: my $match = 0;
1.412 raeburn 7106: my $secmatch = 0;
1.439 raeburn 7107: my $status;
1.412 raeburn 7108: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7109: $user =~ s/:$//;
1.439 raeburn 7110: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7111: if ($end == -1 || $start == -1) {
7112: next;
7113: }
7114: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7115: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7116: my ($uname,$udom) = split(/:/,$user);
7117: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7118: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7119: $secmatch = 1;
7120: } elsif ($usec eq '') {
1.420 albertel 7121: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7122: $secmatch = 1;
7123: }
7124: } else {
7125: if (grep(/^\Q$usec\E$/,@{$sections})) {
7126: $secmatch = 1;
7127: }
7128: }
7129: if (!$secmatch) {
7130: next;
7131: }
1.288 raeburn 7132: }
1.419 raeburn 7133: if ($usec eq '') {
7134: $usec = 'none';
7135: }
1.275 raeburn 7136: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7137: if ($hidepriv) {
7138: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7139: (!$nothide{$uname.':'.$udom})) {
7140: next;
7141: }
7142: }
1.503 raeburn 7143: if ($end > 0 && $end < $now) {
1.439 raeburn 7144: $status = 'previous';
7145: } elsif ($start > $now) {
7146: $status = 'future';
7147: } else {
7148: $status = 'active';
7149: }
1.277 albertel 7150: foreach my $type (keys(%{$types})) {
1.275 raeburn 7151: if ($status eq $type) {
1.420 albertel 7152: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7153: push(@{$$users{$role}{$user}},$type);
7154: }
1.288 raeburn 7155: $match = 1;
7156: }
7157: }
1.419 raeburn 7158: if (($match) && (ref($userdata) eq 'HASH')) {
7159: if (!exists($$userdata{$uname.':'.$udom})) {
7160: &get_user_info($udom,$uname,\%idx,$userdata);
7161: }
1.420 albertel 7162: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7163: push(@{$seclists{$uname.':'.$udom}},$usec);
7164: }
1.609 raeburn 7165: if (ref($statushash) eq 'HASH') {
7166: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7167: }
1.275 raeburn 7168: }
7169: }
7170: }
7171: }
1.290 albertel 7172: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7173: if ((defined($cdom)) && (defined($cnum))) {
7174: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7175: if ( defined($csettings{'internal.courseowner'}) ) {
7176: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7177: next if ($owner eq '');
7178: my ($ownername,$ownerdom);
7179: if ($owner =~ /^([^:]+):([^:]+)$/) {
7180: $ownername = $1;
7181: $ownerdom = $2;
7182: } else {
7183: $ownername = $owner;
7184: $ownerdom = $cdom;
7185: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7186: }
7187: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7188: if (defined($userdata) &&
1.609 raeburn 7189: !exists($$userdata{$owner})) {
7190: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7191: if (!grep(/^none$/,@{$seclists{$owner}})) {
7192: push(@{$seclists{$owner}},'none');
7193: }
7194: if (ref($statushash) eq 'HASH') {
7195: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7196: }
1.290 albertel 7197: }
1.279 raeburn 7198: }
7199: }
7200: }
1.419 raeburn 7201: foreach my $user (keys(%seclists)) {
7202: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7203: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7204: }
1.275 raeburn 7205: }
7206: return;
7207: }
7208:
1.288 raeburn 7209: sub get_user_info {
7210: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7211: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7212: &plainname($uname,$udom,'lastname');
1.291 albertel 7213: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7214: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7215: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7216: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7217: return;
7218: }
1.275 raeburn 7219:
1.472 raeburn 7220: ###############################################
7221:
7222: =pod
7223:
7224: =item * &get_user_quota()
7225:
7226: Retrieves quota assigned for storage of portfolio files for a user
7227:
7228: Incoming parameters:
7229: 1. user's username
7230: 2. user's domain
7231:
7232: Returns:
1.536 raeburn 7233: 1. Disk quota (in Mb) assigned to student.
7234: 2. (Optional) Type of setting: custom or default
7235: (individually assigned or default for user's
7236: institutional status).
7237: 3. (Optional) - User's institutional status (e.g., faculty, staff
7238: or student - types as defined in localenroll::inst_usertypes
7239: for user's domain, which determines default quota for user.
7240: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7241:
7242: If a value has been stored in the user's environment,
1.536 raeburn 7243: it will return that, otherwise it returns the maximal default
7244: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7245:
7246: =cut
7247:
7248: ###############################################
7249:
7250:
7251: sub get_user_quota {
7252: my ($uname,$udom) = @_;
1.536 raeburn 7253: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7254: if (!defined($udom)) {
7255: $udom = $env{'user.domain'};
7256: }
7257: if (!defined($uname)) {
7258: $uname = $env{'user.name'};
7259: }
7260: if (($udom eq '' || $uname eq '') ||
7261: ($udom eq 'public') && ($uname eq 'public')) {
7262: $quota = 0;
1.536 raeburn 7263: $quotatype = 'default';
7264: $defquota = 0;
1.472 raeburn 7265: } else {
1.536 raeburn 7266: my $inststatus;
1.472 raeburn 7267: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7268: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7269: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7270: } else {
1.536 raeburn 7271: my %userenv =
7272: &Apache::lonnet::get('environment',['portfolioquota',
7273: 'inststatus'],$udom,$uname);
1.472 raeburn 7274: my ($tmp) = keys(%userenv);
7275: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7276: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7277: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7278: } else {
7279: undef(%userenv);
7280: }
7281: }
1.536 raeburn 7282: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7283: if ($quota eq '') {
1.536 raeburn 7284: $quota = $defquota;
7285: $quotatype = 'default';
7286: } else {
7287: $quotatype = 'custom';
1.472 raeburn 7288: }
7289: }
1.536 raeburn 7290: if (wantarray) {
7291: return ($quota,$quotatype,$settingstatus,$defquota);
7292: } else {
7293: return $quota;
7294: }
1.472 raeburn 7295: }
7296:
7297: ###############################################
7298:
7299: =pod
7300:
7301: =item * &default_quota()
7302:
1.536 raeburn 7303: Retrieves default quota assigned for storage of user portfolio files,
7304: given an (optional) user's institutional status.
1.472 raeburn 7305:
7306: Incoming parameters:
7307: 1. domain
1.536 raeburn 7308: 2. (Optional) institutional status(es). This is a : separated list of
7309: status types (e.g., faculty, staff, student etc.)
7310: which apply to the user for whom the default is being retrieved.
7311: If the institutional status string in undefined, the domain
7312: default quota will be returned.
1.472 raeburn 7313:
7314: Returns:
7315: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7316: 2. (Optional) institutional type which determined the value of the
7317: default quota.
1.472 raeburn 7318:
7319: If a value has been stored in the domain's configuration db,
7320: it will return that, otherwise it returns 20 (for backwards
7321: compatibility with domains which have not set up a configuration
7322: db file; the original statically defined portfolio quota was 20 Mb).
7323:
1.536 raeburn 7324: If the user's status includes multiple types (e.g., staff and student),
7325: the largest default quota which applies to the user determines the
7326: default quota returned.
7327:
1.780 raeburn 7328: =back
7329:
1.472 raeburn 7330: =cut
7331:
7332: ###############################################
7333:
7334:
7335: sub default_quota {
1.536 raeburn 7336: my ($udom,$inststatus) = @_;
7337: my ($defquota,$settingstatus);
7338: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7339: ['quotas'],$udom);
7340: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7341: if ($inststatus ne '') {
1.765 raeburn 7342: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7343: foreach my $item (@statuses) {
1.711 raeburn 7344: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7345: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7346: if ($defquota eq '') {
7347: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7348: $settingstatus = $item;
7349: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7350: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7351: $settingstatus = $item;
7352: }
7353: }
7354: } else {
7355: if ($quotahash{'quotas'}{$item} ne '') {
7356: if ($defquota eq '') {
7357: $defquota = $quotahash{'quotas'}{$item};
7358: $settingstatus = $item;
7359: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7360: $defquota = $quotahash{'quotas'}{$item};
7361: $settingstatus = $item;
7362: }
1.536 raeburn 7363: }
7364: }
7365: }
7366: }
7367: if ($defquota eq '') {
1.711 raeburn 7368: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7369: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7370: } else {
7371: $defquota = $quotahash{'quotas'}{'default'};
7372: }
1.536 raeburn 7373: $settingstatus = 'default';
7374: }
7375: } else {
7376: $settingstatus = 'default';
7377: $defquota = 20;
7378: }
7379: if (wantarray) {
7380: return ($defquota,$settingstatus);
1.472 raeburn 7381: } else {
1.536 raeburn 7382: return $defquota;
1.472 raeburn 7383: }
7384: }
7385:
1.384 raeburn 7386: sub get_secgrprole_info {
7387: my ($cdom,$cnum,$needroles,$type) = @_;
7388: my %sections_count = &get_sections($cdom,$cnum);
7389: my @sections = (sort {$a <=> $b} keys(%sections_count));
7390: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7391: my @groups = sort(keys(%curr_groups));
7392: my $allroles = [];
7393: my $rolehash;
7394: my $accesshash = {
7395: active => 'Currently has access',
7396: future => 'Will have future access',
7397: previous => 'Previously had access',
7398: };
7399: if ($needroles) {
7400: $rolehash = {'all' => 'all'};
1.385 albertel 7401: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7402: if (&Apache::lonnet::error(%user_roles)) {
7403: undef(%user_roles);
7404: }
7405: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7406: my ($role)=split(/\:/,$item,2);
7407: if ($role eq 'cr') { next; }
7408: if ($role =~ /^cr/) {
7409: $$rolehash{$role} = (split('/',$role))[3];
7410: } else {
7411: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7412: }
7413: }
7414: foreach my $key (sort(keys(%{$rolehash}))) {
7415: push(@{$allroles},$key);
7416: }
7417: push (@{$allroles},'st');
7418: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7419: }
7420: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7421: }
7422:
1.555 raeburn 7423: sub user_picker {
1.627 raeburn 7424: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7425: my $currdom = $dom;
7426: my %curr_selected = (
7427: srchin => 'dom',
1.580 raeburn 7428: srchby => 'lastname',
1.555 raeburn 7429: );
7430: my $srchterm;
1.625 raeburn 7431: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7432: if ($srch->{'srchby'} ne '') {
7433: $curr_selected{'srchby'} = $srch->{'srchby'};
7434: }
7435: if ($srch->{'srchin'} ne '') {
7436: $curr_selected{'srchin'} = $srch->{'srchin'};
7437: }
7438: if ($srch->{'srchtype'} ne '') {
7439: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7440: }
7441: if ($srch->{'srchdomain'} ne '') {
7442: $currdom = $srch->{'srchdomain'};
7443: }
7444: $srchterm = $srch->{'srchterm'};
7445: }
7446: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7447: 'usr' => 'Search criteria',
1.563 raeburn 7448: 'doma' => 'Domain/institution to search',
1.558 albertel 7449: 'uname' => 'username',
7450: 'lastname' => 'last name',
1.555 raeburn 7451: 'lastfirst' => 'last name, first name',
1.558 albertel 7452: 'crs' => 'in this course',
1.576 raeburn 7453: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7454: 'alc' => 'all LON-CAPA',
1.573 raeburn 7455: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7456: 'exact' => 'is',
7457: 'contains' => 'contains',
1.569 raeburn 7458: 'begins' => 'begins with',
1.571 raeburn 7459: 'youm' => "You must include some text to search for.",
7460: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7461: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7462: 'yomc' => "You must choose a domain when using an institutional directory search.",
7463: 'ymcd' => "You must choose a domain when using a domain search.",
7464: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7465: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7466: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7467: );
1.563 raeburn 7468: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7469: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7470:
7471: my @srchins = ('crs','dom','alc','instd');
7472:
7473: foreach my $option (@srchins) {
7474: # FIXME 'alc' option unavailable until
7475: # loncreateuser::print_user_query_page()
7476: # has been completed.
7477: next if ($option eq 'alc');
7478: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7479: if ($curr_selected{'srchin'} eq $option) {
7480: $srchinsel .= '
7481: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7482: } else {
7483: $srchinsel .= '
7484: <option value="'.$option.'">'.$lt{$option}.'</option>';
7485: }
1.555 raeburn 7486: }
1.563 raeburn 7487: $srchinsel .= "\n </select>\n";
1.555 raeburn 7488:
7489: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7490: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7491: if ($curr_selected{'srchby'} eq $option) {
7492: $srchbysel .= '
7493: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7494: } else {
7495: $srchbysel .= '
7496: <option value="'.$option.'">'.$lt{$option}.'</option>';
7497: }
7498: }
7499: $srchbysel .= "\n </select>\n";
7500:
7501: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7502: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7503: if ($curr_selected{'srchtype'} eq $option) {
7504: $srchtypesel .= '
7505: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7506: } else {
7507: $srchtypesel .= '
7508: <option value="'.$option.'">'.$lt{$option}.'</option>';
7509: }
7510: }
7511: $srchtypesel .= "\n </select>\n";
7512:
1.558 albertel 7513: my ($newuserscript,$new_user_create);
1.556 raeburn 7514:
7515: if ($forcenewuser) {
1.576 raeburn 7516: if (ref($srch) eq 'HASH') {
7517: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7518: if ($cancreate) {
7519: $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>';
7520: } else {
1.799 bisitz 7521: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7522: my %usertypetext = (
7523: official => 'institutional',
7524: unofficial => 'non-institutional',
7525: );
1.799 bisitz 7526: $new_user_create = '<p class="LC_warning">'
7527: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7528: .' '
7529: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7530: ,'<a href="'.$helplink.'">','</a>')
7531: .'</p><br />';
1.627 raeburn 7532: }
1.576 raeburn 7533: }
7534: }
7535:
1.556 raeburn 7536: $newuserscript = <<"ENDSCRIPT";
7537:
1.570 raeburn 7538: function setSearch(createnew,callingForm) {
1.556 raeburn 7539: if (createnew == 1) {
1.570 raeburn 7540: for (var i=0; i<callingForm.srchby.length; i++) {
7541: if (callingForm.srchby.options[i].value == 'uname') {
7542: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7543: }
7544: }
1.570 raeburn 7545: for (var i=0; i<callingForm.srchin.length; i++) {
7546: if ( callingForm.srchin.options[i].value == 'dom') {
7547: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7548: }
7549: }
1.570 raeburn 7550: for (var i=0; i<callingForm.srchtype.length; i++) {
7551: if (callingForm.srchtype.options[i].value == 'exact') {
7552: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7553: }
7554: }
1.570 raeburn 7555: for (var i=0; i<callingForm.srchdomain.length; i++) {
7556: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7557: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7558: }
7559: }
7560: }
7561: }
7562: ENDSCRIPT
1.558 albertel 7563:
1.556 raeburn 7564: }
7565:
1.555 raeburn 7566: my $output = <<"END_BLOCK";
1.556 raeburn 7567: <script type="text/javascript">
1.824 bisitz 7568: // <![CDATA[
1.570 raeburn 7569: function validateEntry(callingForm) {
1.558 albertel 7570:
1.556 raeburn 7571: var checkok = 1;
1.558 albertel 7572: var srchin;
1.570 raeburn 7573: for (var i=0; i<callingForm.srchin.length; i++) {
7574: if ( callingForm.srchin[i].checked ) {
7575: srchin = callingForm.srchin[i].value;
1.558 albertel 7576: }
7577: }
7578:
1.570 raeburn 7579: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7580: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7581: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7582: var srchterm = callingForm.srchterm.value;
7583: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7584: var msg = "";
7585:
7586: if (srchterm == "") {
7587: checkok = 0;
1.571 raeburn 7588: msg += "$lt{'youm'}\\n";
1.556 raeburn 7589: }
7590:
1.569 raeburn 7591: if (srchtype== 'begins') {
7592: if (srchterm.length < 2) {
7593: checkok = 0;
1.571 raeburn 7594: msg += "$lt{'thte'}\\n";
1.569 raeburn 7595: }
7596: }
7597:
1.556 raeburn 7598: if (srchtype== 'contains') {
7599: if (srchterm.length < 3) {
7600: checkok = 0;
1.571 raeburn 7601: msg += "$lt{'thet'}\\n";
1.556 raeburn 7602: }
7603: }
7604: if (srchin == 'instd') {
7605: if (srchdomain == '') {
7606: checkok = 0;
1.571 raeburn 7607: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7608: }
7609: }
7610: if (srchin == 'dom') {
7611: if (srchdomain == '') {
7612: checkok = 0;
1.571 raeburn 7613: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7614: }
7615: }
7616: if (srchby == 'lastfirst') {
7617: if (srchterm.indexOf(",") == -1) {
7618: checkok = 0;
1.571 raeburn 7619: msg += "$lt{'whus'}\\n";
1.556 raeburn 7620: }
7621: if (srchterm.indexOf(",") == srchterm.length -1) {
7622: checkok = 0;
1.571 raeburn 7623: msg += "$lt{'whse'}\\n";
1.556 raeburn 7624: }
7625: }
7626: if (checkok == 0) {
1.571 raeburn 7627: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7628: return;
7629: }
7630: if (checkok == 1) {
1.570 raeburn 7631: callingForm.submit();
1.556 raeburn 7632: }
7633: }
7634:
7635: $newuserscript
7636:
1.824 bisitz 7637: // ]]>
1.556 raeburn 7638: </script>
1.558 albertel 7639:
7640: $new_user_create
7641:
1.555 raeburn 7642: <table>
1.558 albertel 7643: <tr>
1.573 raeburn 7644: <td>$lt{'doma'}:</td>
7645: <td>$domform</td>
7646: </td>
7647: </tr>
7648: <tr>
7649: <td>$lt{'usr'}:</td>
1.563 raeburn 7650: <td>$srchbysel
7651: $srchtypesel
7652: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7653: $srchinsel
1.563 raeburn 7654: </td>
7655: </tr>
1.555 raeburn 7656: </table>
7657: <br />
7658: END_BLOCK
1.558 albertel 7659:
1.555 raeburn 7660: return $output;
7661: }
7662:
1.612 raeburn 7663: sub user_rule_check {
1.615 raeburn 7664: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7665: my $response;
7666: if (ref($usershash) eq 'HASH') {
7667: foreach my $user (keys(%{$usershash})) {
7668: my ($uname,$udom) = split(/:/,$user);
7669: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7670: my ($id,$newuser);
1.612 raeburn 7671: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7672: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7673: $id = $usershash->{$user}->{'id'};
7674: }
7675: my $inst_response;
7676: if (ref($checks) eq 'HASH') {
7677: if (defined($checks->{'username'})) {
1.615 raeburn 7678: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7679: &Apache::lonnet::get_instuser($udom,$uname);
7680: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7681: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7682: &Apache::lonnet::get_instuser($udom,undef,$id);
7683: }
1.615 raeburn 7684: } else {
7685: ($inst_response,%{$inst_results->{$user}}) =
7686: &Apache::lonnet::get_instuser($udom,$uname);
7687: return;
1.612 raeburn 7688: }
1.615 raeburn 7689: if (!$got_rules->{$udom}) {
1.612 raeburn 7690: my %domconfig = &Apache::lonnet::get_dom('configuration',
7691: ['usercreation'],$udom);
7692: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7693: foreach my $item ('username','id') {
1.612 raeburn 7694: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7695: $$curr_rules{$udom}{$item} =
7696: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7697: }
7698: }
7699: }
1.615 raeburn 7700: $got_rules->{$udom} = 1;
1.585 raeburn 7701: }
1.612 raeburn 7702: foreach my $item (keys(%{$checks})) {
7703: if (ref($$curr_rules{$udom}) eq 'HASH') {
7704: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7705: if (@{$$curr_rules{$udom}{$item}} > 0) {
7706: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7707: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7708: if ($rule_check{$rule}) {
7709: $$rulematch{$user}{$item} = $rule;
7710: if ($inst_response eq 'ok') {
1.615 raeburn 7711: if (ref($inst_results) eq 'HASH') {
7712: if (ref($inst_results->{$user}) eq 'HASH') {
7713: if (keys(%{$inst_results->{$user}}) == 0) {
7714: $$alerts{$item}{$udom}{$uname} = 1;
7715: }
1.612 raeburn 7716: }
7717: }
1.615 raeburn 7718: }
7719: last;
1.585 raeburn 7720: }
7721: }
7722: }
7723: }
7724: }
7725: }
7726: }
7727: }
1.612 raeburn 7728: return;
7729: }
7730:
7731: sub user_rule_formats {
7732: my ($domain,$domdesc,$curr_rules,$check) = @_;
7733: my %text = (
7734: 'username' => 'Usernames',
7735: 'id' => 'IDs',
7736: );
7737: my $output;
7738: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7739: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7740: if (@{$ruleorder} > 0) {
7741: $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>';
7742: foreach my $rule (@{$ruleorder}) {
7743: if (ref($curr_rules) eq 'ARRAY') {
7744: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7745: if (ref($rules->{$rule}) eq 'HASH') {
7746: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7747: $rules->{$rule}{'desc'}.'</li>';
7748: }
7749: }
7750: }
7751: }
7752: $output .= '</ul>';
7753: }
7754: }
7755: return $output;
7756: }
7757:
7758: sub instrule_disallow_msg {
1.615 raeburn 7759: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7760: my $response;
7761: my %text = (
7762: item => 'username',
7763: items => 'usernames',
7764: match => 'matches',
7765: do => 'does',
7766: action => 'a username',
7767: one => 'one',
7768: );
7769: if ($count > 1) {
7770: $text{'item'} = 'usernames';
7771: $text{'match'} ='match';
7772: $text{'do'} = 'do';
7773: $text{'action'} = 'usernames',
7774: $text{'one'} = 'ones';
7775: }
7776: if ($checkitem eq 'id') {
7777: $text{'items'} = 'IDs';
7778: $text{'item'} = 'ID';
7779: $text{'action'} = 'an ID';
1.615 raeburn 7780: if ($count > 1) {
7781: $text{'item'} = 'IDs';
7782: $text{'action'} = 'IDs';
7783: }
1.612 raeburn 7784: }
1.674 bisitz 7785: $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 7786: if ($mode eq 'upload') {
7787: if ($checkitem eq 'username') {
7788: $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'}.");
7789: } elsif ($checkitem eq 'id') {
1.674 bisitz 7790: $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 7791: }
1.669 raeburn 7792: } elsif ($mode eq 'selfcreate') {
7793: if ($checkitem eq 'id') {
7794: $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.");
7795: }
1.615 raeburn 7796: } else {
7797: if ($checkitem eq 'username') {
7798: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7799: } elsif ($checkitem eq 'id') {
7800: $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.");
7801: }
1.612 raeburn 7802: }
7803: return $response;
1.585 raeburn 7804: }
7805:
1.624 raeburn 7806: sub personal_data_fieldtitles {
7807: my %fieldtitles = &Apache::lonlocal::texthash (
7808: id => 'Student/Employee ID',
7809: permanentemail => 'E-mail address',
7810: lastname => 'Last Name',
7811: firstname => 'First Name',
7812: middlename => 'Middle Name',
7813: generation => 'Generation',
7814: gen => 'Generation',
1.765 raeburn 7815: inststatus => 'Affiliation',
1.624 raeburn 7816: );
7817: return %fieldtitles;
7818: }
7819:
1.642 raeburn 7820: sub sorted_inst_types {
7821: my ($dom) = @_;
7822: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7823: my $othertitle = &mt('All users');
7824: if ($env{'request.course.id'}) {
1.668 raeburn 7825: $othertitle = &mt('Any users');
1.642 raeburn 7826: }
7827: my @types;
7828: if (ref($order) eq 'ARRAY') {
7829: @types = @{$order};
7830: }
7831: if (@types == 0) {
7832: if (ref($usertypes) eq 'HASH') {
7833: @types = sort(keys(%{$usertypes}));
7834: }
7835: }
7836: if (keys(%{$usertypes}) > 0) {
7837: $othertitle = &mt('Other users');
7838: }
7839: return ($othertitle,$usertypes,\@types);
7840: }
7841:
1.645 raeburn 7842: sub get_institutional_codes {
7843: my ($settings,$allcourses,$LC_code) = @_;
7844: # Get complete list of course sections to update
7845: my @currsections = ();
7846: my @currxlists = ();
7847: my $coursecode = $$settings{'internal.coursecode'};
7848:
7849: if ($$settings{'internal.sectionnums'} ne '') {
7850: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7851: }
7852:
7853: if ($$settings{'internal.crosslistings'} ne '') {
7854: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7855: }
7856:
7857: if (@currxlists > 0) {
7858: foreach (@currxlists) {
7859: if (m/^([^:]+):(\w*)$/) {
7860: unless (grep/^$1$/,@{$allcourses}) {
7861: push @{$allcourses},$1;
7862: $$LC_code{$1} = $2;
7863: }
7864: }
7865: }
7866: }
7867:
7868: if (@currsections > 0) {
7869: foreach (@currsections) {
7870: if (m/^(\w+):(\w*)$/) {
7871: my $sec = $coursecode.$1;
7872: my $lc_sec = $2;
7873: unless (grep/^$sec$/,@{$allcourses}) {
7874: push @{$allcourses},$sec;
7875: $$LC_code{$sec} = $lc_sec;
7876: }
7877: }
7878: }
7879: }
7880: return;
7881: }
7882:
1.112 bowersj2 7883: =pod
7884:
1.780 raeburn 7885: =head1 Slot Helpers
7886:
7887: =over 4
7888:
7889: =item * sorted_slots()
7890:
7891: Sorts an array of slot names in order of slot start time (earliest first).
7892:
7893: Inputs:
7894:
7895: =over 4
7896:
7897: slotsarr - Reference to array of unsorted slot names.
7898:
7899: slots - Reference to hash of hash, where outer hash keys are slot names.
7900:
1.549 albertel 7901: =back
7902:
1.780 raeburn 7903: Returns:
7904:
7905: =over 4
7906:
7907: sorted - An array of slot names sorted by the start time of the slot.
7908:
7909: =back
7910:
7911: =back
7912:
7913: =cut
7914:
7915:
7916: sub sorted_slots {
7917: my ($slotsarr,$slots) = @_;
7918: my @sorted;
7919: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7920: @sorted =
7921: sort {
7922: if (ref($slots->{$a}) && ref($slots->{$b})) {
7923: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7924: }
7925: if (ref($slots->{$a})) { return -1;}
7926: if (ref($slots->{$b})) { return 1;}
7927: return 0;
7928: } @{$slotsarr};
7929: }
7930: return @sorted;
7931: }
7932:
7933:
7934: =pod
7935:
1.549 albertel 7936: =head1 HTTP Helpers
7937:
7938: =over 4
7939:
1.648 raeburn 7940: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7941:
1.258 albertel 7942: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7943: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7944: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7945:
7946: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7947: $possible_names is an ref to an array of form element names. As an example:
7948: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7949: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7950:
7951: =cut
1.1 albertel 7952:
1.6 albertel 7953: sub get_unprocessed_cgi {
1.25 albertel 7954: my ($query,$possible_names)= @_;
1.26 matthew 7955: # $Apache::lonxml::debug=1;
1.356 albertel 7956: foreach my $pair (split(/&/,$query)) {
7957: my ($name, $value) = split(/=/,$pair);
1.369 www 7958: $name = &unescape($name);
1.25 albertel 7959: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7960: $value =~ tr/+/ /;
7961: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7962: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7963: }
1.16 harris41 7964: }
1.6 albertel 7965: }
7966:
1.112 bowersj2 7967: =pod
7968:
1.648 raeburn 7969: =item * &cacheheader()
1.112 bowersj2 7970:
7971: returns cache-controlling header code
7972:
7973: =cut
7974:
1.7 albertel 7975: sub cacheheader {
1.258 albertel 7976: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7977: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7978: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7979: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7980: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7981: return $output;
1.7 albertel 7982: }
7983:
1.112 bowersj2 7984: =pod
7985:
1.648 raeburn 7986: =item * &no_cache($r)
1.112 bowersj2 7987:
7988: specifies header code to not have cache
7989:
7990: =cut
7991:
1.9 albertel 7992: sub no_cache {
1.216 albertel 7993: my ($r) = @_;
7994: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7995: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7996: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7997: $r->no_cache(1);
7998: $r->header_out("Expires" => $date);
7999: $r->header_out("Pragma" => "no-cache");
1.123 www 8000: }
8001:
8002: sub content_type {
1.181 albertel 8003: my ($r,$type,$charset) = @_;
1.299 foxr 8004: if ($r) {
8005: # Note that printout.pl calls this with undef for $r.
8006: &no_cache($r);
8007: }
1.258 albertel 8008: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8009: unless ($charset) {
8010: $charset=&Apache::lonlocal::current_encoding;
8011: }
8012: if ($charset) { $type.='; charset='.$charset; }
8013: if ($r) {
8014: $r->content_type($type);
8015: } else {
8016: print("Content-type: $type\n\n");
8017: }
1.9 albertel 8018: }
1.25 albertel 8019:
1.112 bowersj2 8020: =pod
8021:
1.648 raeburn 8022: =item * &add_to_env($name,$value)
1.112 bowersj2 8023:
1.258 albertel 8024: adds $name to the %env hash with value
1.112 bowersj2 8025: $value, if $name already exists, the entry is converted to an array
8026: reference and $value is added to the array.
8027:
8028: =cut
8029:
1.25 albertel 8030: sub add_to_env {
8031: my ($name,$value)=@_;
1.258 albertel 8032: if (defined($env{$name})) {
8033: if (ref($env{$name})) {
1.25 albertel 8034: #already have multiple values
1.258 albertel 8035: push(@{ $env{$name} },$value);
1.25 albertel 8036: } else {
8037: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8038: my $first=$env{$name};
8039: undef($env{$name});
8040: push(@{ $env{$name} },$first,$value);
1.25 albertel 8041: }
8042: } else {
1.258 albertel 8043: $env{$name}=$value;
1.25 albertel 8044: }
1.31 albertel 8045: }
1.149 albertel 8046:
8047: =pod
8048:
1.648 raeburn 8049: =item * &get_env_multiple($name)
1.149 albertel 8050:
1.258 albertel 8051: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8052: values may be defined and end up as an array ref.
8053:
8054: returns an array of values
8055:
8056: =cut
8057:
8058: sub get_env_multiple {
8059: my ($name) = @_;
8060: my @values;
1.258 albertel 8061: if (defined($env{$name})) {
1.149 albertel 8062: # exists is it an array
1.258 albertel 8063: if (ref($env{$name})) {
8064: @values=@{ $env{$name} };
1.149 albertel 8065: } else {
1.258 albertel 8066: $values[0]=$env{$name};
1.149 albertel 8067: }
8068: }
8069: return(@values);
8070: }
8071:
1.660 raeburn 8072: sub ask_for_embedded_content {
8073: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8074: my $upload_output = '
8075: <form name="upload_embedded" action="'.$actionurl.'"
8076: method="post" enctype="multipart/form-data">';
8077: $upload_output .= $state;
1.661 raeburn 8078: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8079:
8080: my $num = 0;
8081: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8082: $upload_output .= &start_data_table_row().
8083: '<td>'.$embed_file.'</td><td>';
8084: if ($args->{'ignore_remote_references'}
8085: && $embed_file =~ m{^\w+://}) {
8086: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8087: } elsif ($args->{'error_on_invalid_names'}
8088: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8089:
8090: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8091:
8092: } else {
8093: $upload_output .='
1.661 raeburn 8094: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8095: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8096: my $attrib = join(':',@{$$allfiles{$embed_file}});
8097: $upload_output .=
8098: "\n\t\t".
8099: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8100: $attrib.'" />';
8101: if (exists($$codebase{$embed_file})) {
8102: $upload_output .=
8103: "\n\t\t".
8104: '<input name="codebase_'.$num.'" type="hidden" value="'.
8105: &escape($$codebase{$embed_file}).'" />';
8106: }
8107: }
8108: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8109: $num++;
8110: }
8111: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8112: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8113: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8114: '.&mt('(only files for which a location has been provided will be uploaded)').'
8115: </form>';
8116: return $upload_output;
8117: }
8118:
1.661 raeburn 8119: sub upload_embedded {
8120: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8121: $current_disk_usage) = @_;
8122: my $output;
8123: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8124: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8125: my $orig_uploaded_filename =
8126: $env{'form.embedded_item_'.$i.'.filename'};
8127:
8128: $env{'form.embedded_orig_'.$i} =
8129: &unescape($env{'form.embedded_orig_'.$i});
8130: my ($path,$fname) =
8131: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8132: # no path, whole string is fname
8133: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8134:
8135: $path = $env{'form.currentpath'}.$path;
8136: $fname = &Apache::lonnet::clean_filename($fname);
8137: # See if there is anything left
8138: next if ($fname eq '');
8139:
8140: # Check if file already exists as a file or directory.
8141: my ($state,$msg);
8142: if ($context eq 'portfolio') {
8143: my $port_path = $dirpath;
8144: if ($group ne '') {
8145: $port_path = "groups/$group/$port_path";
8146: }
8147: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8148: $dir_root,$port_path,$disk_quota,
8149: $current_disk_usage,$uname,$udom);
8150: if ($state eq 'will_exceed_quota'
8151: || $state eq 'file_locked'
8152: || $state eq 'file_exists' ) {
8153: $output .= $msg;
8154: next;
8155: }
8156: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8157: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8158: if ($state eq 'exists') {
8159: $output .= $msg;
8160: next;
8161: }
8162: }
8163: # Check if extension is valid
8164: if (($fname =~ /\.(\w+)$/) &&
8165: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8166: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8167: next;
8168: } elsif (($fname =~ /\.(\w+)$/) &&
8169: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8170: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8171: next;
8172: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8173: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8174: next;
8175: }
8176:
8177: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8178: if ($context eq 'portfolio') {
8179: my $result=
8180: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8181: $dirpath.$path);
8182: if ($result !~ m|^/uploaded/|) {
8183: $output .= '<span class="LC_error">'
8184: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8185: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8186: .'</span><br />';
8187: next;
8188: } else {
8189: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8190: $path.$fname.'</span>').'</p>';
8191: }
8192: } else {
8193: # Save the file
8194: my $target = $env{'form.embedded_item_'.$i};
8195: my $fullpath = $dir_root.$dirpath.'/'.$path;
8196: my $dest = $fullpath.$fname;
8197: my $url = $url_root.$dirpath.'/'.$path.$fname;
8198: my @parts=split(/\//,$fullpath);
8199: my $count;
8200: my $filepath = $dir_root;
8201: for ($count=4;$count<=$#parts;$count++) {
8202: $filepath .= "/$parts[$count]";
8203: if ((-e $filepath)!=1) {
8204: mkdir($filepath,0770);
8205: }
8206: }
8207: my $fh;
8208: if (!open($fh,'>'.$dest)) {
8209: &Apache::lonnet::logthis('Failed to create '.$dest);
8210: $output .= '<span class="LC_error">'.
8211: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8212: '</span><br />';
8213: } else {
8214: if (!print $fh $env{'form.embedded_item_'.$i}) {
8215: &Apache::lonnet::logthis('Failed to write to '.$dest);
8216: $output .= '<span class="LC_error">'.
8217: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8218: '</span><br />';
8219: } else {
8220: if ($context eq 'testbank') {
8221: $output .= &mt('Embedded file uploaded successfully:').
8222: ' <a href="'.$url.'">'.
8223: $orig_uploaded_filename.'</a><br />';
8224: } else {
1.705 tempelho 8225: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8226: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8227: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8228: }
8229: }
8230: close($fh);
8231: }
8232: }
8233: }
8234: return $output;
8235: }
8236:
8237: sub check_for_existing {
8238: my ($path,$fname,$element) = @_;
8239: my ($state,$msg);
8240: if (-d $path.'/'.$fname) {
8241: $state = 'exists';
8242: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8243: } elsif (-e $path.'/'.$fname) {
8244: $state = 'exists';
8245: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8246: }
8247: if ($state eq 'exists') {
8248: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8249: }
8250: return ($state,$msg);
8251: }
8252:
8253: sub check_for_upload {
8254: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8255: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8256: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8257: my $getpropath = 1;
8258: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8259: $getpropath);
8260: my $found_file = 0;
8261: my $locked_file = 0;
8262: foreach my $line (@dir_list) {
8263: my ($file_name)=split(/\&/,$line,2);
8264: if ($file_name eq $fname){
8265: $file_name = $path.$file_name;
8266: if ($group ne '') {
8267: $file_name = $group.$file_name;
8268: }
8269: $found_file = 1;
8270: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8271: $locked_file = 1;
8272: }
8273: }
8274: }
8275: if (($current_disk_usage + $filesize) > $disk_quota){
8276: my $msg = '<span class="LC_error">'.
8277: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8278: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8279: return ('will_exceed_quota',$msg);
8280: } elsif ($found_file) {
8281: if ($locked_file) {
8282: my $msg = '<span class="LC_error">';
8283: $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>');
8284: $msg .= '</span><br />';
8285: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8286: return ('file_locked',$msg);
8287: } else {
8288: my $msg = '<span class="LC_error">';
8289: $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'});
8290: $msg .= '</span>';
8291: $msg .= '<br />';
8292: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8293: return ('file_exists',$msg);
8294: }
8295: }
8296: }
8297:
1.31 albertel 8298:
1.41 ng 8299: =pod
1.45 matthew 8300:
1.464 albertel 8301: =back
1.41 ng 8302:
1.112 bowersj2 8303: =head1 CSV Upload/Handling functions
1.38 albertel 8304:
1.41 ng 8305: =over 4
8306:
1.648 raeburn 8307: =item * &upfile_store($r)
1.41 ng 8308:
8309: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8310: needs $env{'form.upfile'}
1.41 ng 8311: returns $datatoken to be put into hidden field
8312:
8313: =cut
1.31 albertel 8314:
8315: sub upfile_store {
8316: my $r=shift;
1.258 albertel 8317: $env{'form.upfile'}=~s/\r/\n/gs;
8318: $env{'form.upfile'}=~s/\f/\n/gs;
8319: $env{'form.upfile'}=~s/\n+/\n/gs;
8320: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8321:
1.258 albertel 8322: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8323: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8324: {
1.158 raeburn 8325: my $datafile = $r->dir_config('lonDaemons').
8326: '/tmp/'.$datatoken.'.tmp';
8327: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8328: print $fh $env{'form.upfile'};
1.158 raeburn 8329: close($fh);
8330: }
1.31 albertel 8331: }
8332: return $datatoken;
8333: }
8334:
1.56 matthew 8335: =pod
8336:
1.648 raeburn 8337: =item * &load_tmp_file($r)
1.41 ng 8338:
8339: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8340: needs $env{'form.datatoken'},
8341: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8342:
8343: =cut
1.31 albertel 8344:
8345: sub load_tmp_file {
8346: my $r=shift;
8347: my @studentdata=();
8348: {
1.158 raeburn 8349: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8350: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8351: if ( open(my $fh,"<$studentfile") ) {
8352: @studentdata=<$fh>;
8353: close($fh);
8354: }
1.31 albertel 8355: }
1.258 albertel 8356: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8357: }
8358:
1.56 matthew 8359: =pod
8360:
1.648 raeburn 8361: =item * &upfile_record_sep()
1.41 ng 8362:
8363: Separate uploaded file into records
8364: returns array of records,
1.258 albertel 8365: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8366:
8367: =cut
1.31 albertel 8368:
8369: sub upfile_record_sep {
1.258 albertel 8370: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8371: } else {
1.248 albertel 8372: my @records;
1.258 albertel 8373: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8374: if ($line=~/^\s*$/) { next; }
8375: push(@records,$line);
8376: }
8377: return @records;
1.31 albertel 8378: }
8379: }
8380:
1.56 matthew 8381: =pod
8382:
1.648 raeburn 8383: =item * &record_sep($record)
1.41 ng 8384:
1.258 albertel 8385: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8386:
8387: =cut
8388:
1.263 www 8389: sub takeleft {
8390: my $index=shift;
8391: return substr('0000'.$index,-4,4);
8392: }
8393:
1.31 albertel 8394: sub record_sep {
8395: my $record=shift;
8396: my %components=();
1.258 albertel 8397: if ($env{'form.upfiletype'} eq 'xml') {
8398: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8399: my $i=0;
1.356 albertel 8400: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8401: $field=~s/^(\"|\')//;
8402: $field=~s/(\"|\')$//;
1.263 www 8403: $components{&takeleft($i)}=$field;
1.31 albertel 8404: $i++;
8405: }
1.258 albertel 8406: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8407: my $i=0;
1.356 albertel 8408: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8409: $field=~s/^(\"|\')//;
8410: $field=~s/(\"|\')$//;
1.263 www 8411: $components{&takeleft($i)}=$field;
1.31 albertel 8412: $i++;
8413: }
8414: } else {
1.561 www 8415: my $separator=',';
1.480 banghart 8416: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8417: $separator=';';
1.480 banghart 8418: }
1.31 albertel 8419: my $i=0;
1.561 www 8420: # the character we are looking for to indicate the end of a quote or a record
8421: my $looking_for=$separator;
8422: # do not add the characters to the fields
8423: my $ignore=0;
8424: # we just encountered a separator (or the beginning of the record)
8425: my $just_found_separator=1;
8426: # store the field we are working on here
8427: my $field='';
8428: # work our way through all characters in record
8429: foreach my $character ($record=~/(.)/g) {
8430: if ($character eq $looking_for) {
8431: if ($character ne $separator) {
8432: # Found the end of a quote, again looking for separator
8433: $looking_for=$separator;
8434: $ignore=1;
8435: } else {
8436: # Found a separator, store away what we got
8437: $components{&takeleft($i)}=$field;
8438: $i++;
8439: $just_found_separator=1;
8440: $ignore=0;
8441: $field='';
8442: }
8443: next;
8444: }
8445: # single or double quotation marks after a separator indicate beginning of a quote
8446: # we are now looking for the end of the quote and need to ignore separators
8447: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8448: $looking_for=$character;
8449: next;
8450: }
8451: # ignore would be true after we reached the end of a quote
8452: if ($ignore) { next; }
8453: if (($just_found_separator) && ($character=~/\s/)) { next; }
8454: $field.=$character;
8455: $just_found_separator=0;
1.31 albertel 8456: }
1.561 www 8457: # catch the very last entry, since we never encountered the separator
8458: $components{&takeleft($i)}=$field;
1.31 albertel 8459: }
8460: return %components;
8461: }
8462:
1.144 matthew 8463: ######################################################
8464: ######################################################
8465:
1.56 matthew 8466: =pod
8467:
1.648 raeburn 8468: =item * &upfile_select_html()
1.41 ng 8469:
1.144 matthew 8470: Return HTML code to select a file from the users machine and specify
8471: the file type.
1.41 ng 8472:
8473: =cut
8474:
1.144 matthew 8475: ######################################################
8476: ######################################################
1.31 albertel 8477: sub upfile_select_html {
1.144 matthew 8478: my %Types = (
8479: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8480: semisv => &mt('Semicolon separated values'),
1.144 matthew 8481: space => &mt('Space separated'),
8482: tab => &mt('Tabulator separated'),
8483: # xml => &mt('HTML/XML'),
8484: );
8485: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8486: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8487: foreach my $type (sort(keys(%Types))) {
8488: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8489: }
8490: $Str .= "</select>\n";
8491: return $Str;
1.31 albertel 8492: }
8493:
1.301 albertel 8494: sub get_samples {
8495: my ($records,$toget) = @_;
8496: my @samples=({});
8497: my $got=0;
8498: foreach my $rec (@$records) {
8499: my %temp = &record_sep($rec);
8500: if (! grep(/\S/, values(%temp))) { next; }
8501: if (%temp) {
8502: $samples[$got]=\%temp;
8503: $got++;
8504: if ($got == $toget) { last; }
8505: }
8506: }
8507: return \@samples;
8508: }
8509:
1.144 matthew 8510: ######################################################
8511: ######################################################
8512:
1.56 matthew 8513: =pod
8514:
1.648 raeburn 8515: =item * &csv_print_samples($r,$records)
1.41 ng 8516:
8517: Prints a table of sample values from each column uploaded $r is an
8518: Apache Request ref, $records is an arrayref from
8519: &Apache::loncommon::upfile_record_sep
8520:
8521: =cut
8522:
1.144 matthew 8523: ######################################################
8524: ######################################################
1.31 albertel 8525: sub csv_print_samples {
8526: my ($r,$records) = @_;
1.662 bisitz 8527: my $samples = &get_samples($records,5);
1.301 albertel 8528:
1.594 raeburn 8529: $r->print(&mt('Samples').'<br />'.&start_data_table().
8530: &start_data_table_header_row());
1.356 albertel 8531: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8532: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8533: $r->print(&end_data_table_header_row());
1.301 albertel 8534: foreach my $hash (@$samples) {
1.594 raeburn 8535: $r->print(&start_data_table_row());
1.356 albertel 8536: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8537: $r->print('<td>');
1.356 albertel 8538: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8539: $r->print('</td>');
8540: }
1.594 raeburn 8541: $r->print(&end_data_table_row());
1.31 albertel 8542: }
1.594 raeburn 8543: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8544: }
8545:
1.144 matthew 8546: ######################################################
8547: ######################################################
8548:
1.56 matthew 8549: =pod
8550:
1.648 raeburn 8551: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8552:
8553: Prints a table to create associations between values and table columns.
1.144 matthew 8554:
1.41 ng 8555: $r is an Apache Request ref,
8556: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8557: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8558:
8559: =cut
8560:
1.144 matthew 8561: ######################################################
8562: ######################################################
1.31 albertel 8563: sub csv_print_select_table {
8564: my ($r,$records,$d) = @_;
1.301 albertel 8565: my $i=0;
8566: my $samples = &get_samples($records,1);
1.144 matthew 8567: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8568: &start_data_table().&start_data_table_header_row().
1.144 matthew 8569: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8570: '<th>'.&mt('Column').'</th>'.
8571: &end_data_table_header_row()."\n");
1.356 albertel 8572: foreach my $array_ref (@$d) {
8573: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8574: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8575:
8576: $r->print('<td><select name=f'.$i.
1.32 matthew 8577: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8578: $r->print('<option value="none"></option>');
1.356 albertel 8579: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8580: $r->print('<option value="'.$sample.'"'.
8581: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8582: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8583: }
1.594 raeburn 8584: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8585: $i++;
8586: }
1.594 raeburn 8587: $r->print(&end_data_table());
1.31 albertel 8588: $i--;
8589: return $i;
8590: }
1.56 matthew 8591:
1.144 matthew 8592: ######################################################
8593: ######################################################
8594:
1.56 matthew 8595: =pod
1.31 albertel 8596:
1.648 raeburn 8597: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8598:
8599: Prints a table of sample values from the upload and can make associate samples to internal names.
8600:
8601: $r is an Apache Request ref,
8602: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8603: $d is an array of 2 element arrays (internal name, displayed name)
8604:
8605: =cut
8606:
1.144 matthew 8607: ######################################################
8608: ######################################################
1.31 albertel 8609: sub csv_samples_select_table {
8610: my ($r,$records,$d) = @_;
8611: my $i=0;
1.144 matthew 8612: #
1.662 bisitz 8613: my $max_samples = 5;
8614: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8615: $r->print(&start_data_table().
8616: &start_data_table_header_row().'<th>'.
8617: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8618: &end_data_table_header_row());
1.301 albertel 8619:
8620: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8621: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8622: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8623: foreach my $option (@$d) {
8624: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8625: $r->print('<option value="'.$value.'"'.
1.253 albertel 8626: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8627: $display.'</option>');
1.31 albertel 8628: }
8629: $r->print('</select></td><td>');
1.662 bisitz 8630: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8631: if (defined($samples->[$line]{$key})) {
8632: $r->print($samples->[$line]{$key}."<br />\n");
8633: }
8634: }
1.594 raeburn 8635: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8636: $i++;
8637: }
1.594 raeburn 8638: $r->print(&end_data_table());
1.31 albertel 8639: $i--;
8640: return($i);
1.115 matthew 8641: }
8642:
1.144 matthew 8643: ######################################################
8644: ######################################################
8645:
1.115 matthew 8646: =pod
8647:
1.648 raeburn 8648: =item * &clean_excel_name($name)
1.115 matthew 8649:
8650: Returns a replacement for $name which does not contain any illegal characters.
8651:
8652: =cut
8653:
1.144 matthew 8654: ######################################################
8655: ######################################################
1.115 matthew 8656: sub clean_excel_name {
8657: my ($name) = @_;
8658: $name =~ s/[:\*\?\/\\]//g;
8659: if (length($name) > 31) {
8660: $name = substr($name,0,31);
8661: }
8662: return $name;
1.25 albertel 8663: }
1.84 albertel 8664:
1.85 albertel 8665: =pod
8666:
1.648 raeburn 8667: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8668:
8669: Returns either 1 or undef
8670:
8671: 1 if the part is to be hidden, undef if it is to be shown
8672:
8673: Arguments are:
8674:
8675: $id the id of the part to be checked
8676: $symb, optional the symb of the resource to check
8677: $udom, optional the domain of the user to check for
8678: $uname, optional the username of the user to check for
8679:
8680: =cut
1.84 albertel 8681:
8682: sub check_if_partid_hidden {
8683: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8684: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8685: $symb,$udom,$uname);
1.141 albertel 8686: my $truth=1;
8687: #if the string starts with !, then the list is the list to show not hide
8688: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8689: my @hiddenlist=split(/,/,$hiddenparts);
8690: foreach my $checkid (@hiddenlist) {
1.141 albertel 8691: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8692: }
1.141 albertel 8693: return !$truth;
1.84 albertel 8694: }
1.127 matthew 8695:
1.138 matthew 8696:
8697: ############################################################
8698: ############################################################
8699:
8700: =pod
8701:
1.157 matthew 8702: =back
8703:
1.138 matthew 8704: =head1 cgi-bin script and graphing routines
8705:
1.157 matthew 8706: =over 4
8707:
1.648 raeburn 8708: =item * &get_cgi_id()
1.138 matthew 8709:
8710: Inputs: none
8711:
8712: Returns an id which can be used to pass environment variables
8713: to various cgi-bin scripts. These environment variables will
8714: be removed from the users environment after a given time by
8715: the routine &Apache::lonnet::transfer_profile_to_env.
8716:
8717: =cut
8718:
8719: ############################################################
8720: ############################################################
1.152 albertel 8721: my $uniq=0;
1.136 matthew 8722: sub get_cgi_id {
1.154 albertel 8723: $uniq=($uniq+1)%100000;
1.280 albertel 8724: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8725: }
8726:
1.127 matthew 8727: ############################################################
8728: ############################################################
8729:
8730: =pod
8731:
1.648 raeburn 8732: =item * &DrawBarGraph()
1.127 matthew 8733:
1.138 matthew 8734: Facilitates the plotting of data in a (stacked) bar graph.
8735: Puts plot definition data into the users environment in order for
8736: graph.png to plot it. Returns an <img> tag for the plot.
8737: The bars on the plot are labeled '1','2',...,'n'.
8738:
8739: Inputs:
8740:
8741: =over 4
8742:
8743: =item $Title: string, the title of the plot
8744:
8745: =item $xlabel: string, text describing the X-axis of the plot
8746:
8747: =item $ylabel: string, text describing the Y-axis of the plot
8748:
8749: =item $Max: scalar, the maximum Y value to use in the plot
8750: If $Max is < any data point, the graph will not be rendered.
8751:
1.140 matthew 8752: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8753: they are plotted. If undefined, default values will be used.
8754:
1.178 matthew 8755: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8756:
1.138 matthew 8757: =item @Values: An array of array references. Each array reference holds data
8758: to be plotted in a stacked bar chart.
8759:
1.239 matthew 8760: =item If the final element of @Values is a hash reference the key/value
8761: pairs will be added to the graph definition.
8762:
1.138 matthew 8763: =back
8764:
8765: Returns:
8766:
8767: An <img> tag which references graph.png and the appropriate identifying
8768: information for the plot.
8769:
1.127 matthew 8770: =cut
8771:
8772: ############################################################
8773: ############################################################
1.134 matthew 8774: sub DrawBarGraph {
1.178 matthew 8775: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8776: #
8777: if (! defined($colors)) {
8778: $colors = ['#33ff00',
8779: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8780: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8781: ];
8782: }
1.228 matthew 8783: my $extra_settings = {};
8784: if (ref($Values[-1]) eq 'HASH') {
8785: $extra_settings = pop(@Values);
8786: }
1.127 matthew 8787: #
1.136 matthew 8788: my $identifier = &get_cgi_id();
8789: my $id = 'cgi.'.$identifier;
1.129 matthew 8790: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8791: return '';
8792: }
1.225 matthew 8793: #
8794: my @Labels;
8795: if (defined($labels)) {
8796: @Labels = @$labels;
8797: } else {
8798: for (my $i=0;$i<@{$Values[0]};$i++) {
8799: push (@Labels,$i+1);
8800: }
8801: }
8802: #
1.129 matthew 8803: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8804: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8805: my %ValuesHash;
8806: my $NumSets=1;
8807: foreach my $array (@Values) {
8808: next if (! ref($array));
1.136 matthew 8809: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8810: join(',',@$array);
1.129 matthew 8811: }
1.127 matthew 8812: #
1.136 matthew 8813: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8814: if ($NumBars < 3) {
8815: $width = 120+$NumBars*32;
1.220 matthew 8816: $xskip = 1;
1.225 matthew 8817: $bar_width = 30;
8818: } elsif ($NumBars < 5) {
8819: $width = 120+$NumBars*20;
8820: $xskip = 1;
8821: $bar_width = 20;
1.220 matthew 8822: } elsif ($NumBars < 10) {
1.136 matthew 8823: $width = 120+$NumBars*15;
8824: $xskip = 1;
8825: $bar_width = 15;
8826: } elsif ($NumBars <= 25) {
8827: $width = 120+$NumBars*11;
8828: $xskip = 5;
8829: $bar_width = 8;
8830: } elsif ($NumBars <= 50) {
8831: $width = 120+$NumBars*8;
8832: $xskip = 5;
8833: $bar_width = 4;
8834: } else {
8835: $width = 120+$NumBars*8;
8836: $xskip = 5;
8837: $bar_width = 4;
8838: }
8839: #
1.137 matthew 8840: $Max = 1 if ($Max < 1);
8841: if ( int($Max) < $Max ) {
8842: $Max++;
8843: $Max = int($Max);
8844: }
1.127 matthew 8845: $Title = '' if (! defined($Title));
8846: $xlabel = '' if (! defined($xlabel));
8847: $ylabel = '' if (! defined($ylabel));
1.369 www 8848: $ValuesHash{$id.'.title'} = &escape($Title);
8849: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8850: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8851: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8852: $ValuesHash{$id.'.NumBars'} = $NumBars;
8853: $ValuesHash{$id.'.NumSets'} = $NumSets;
8854: $ValuesHash{$id.'.PlotType'} = 'bar';
8855: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8856: $ValuesHash{$id.'.height'} = $height;
8857: $ValuesHash{$id.'.width'} = $width;
8858: $ValuesHash{$id.'.xskip'} = $xskip;
8859: $ValuesHash{$id.'.bar_width'} = $bar_width;
8860: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8861: #
1.228 matthew 8862: # Deal with other parameters
8863: while (my ($key,$value) = each(%$extra_settings)) {
8864: $ValuesHash{$id.'.'.$key} = $value;
8865: }
8866: #
1.646 raeburn 8867: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8868: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8869: }
8870:
8871: ############################################################
8872: ############################################################
8873:
8874: =pod
8875:
1.648 raeburn 8876: =item * &DrawXYGraph()
1.137 matthew 8877:
1.138 matthew 8878: Facilitates the plotting of data in an XY graph.
8879: Puts plot definition data into the users environment in order for
8880: graph.png to plot it. Returns an <img> tag for the plot.
8881:
8882: Inputs:
8883:
8884: =over 4
8885:
8886: =item $Title: string, the title of the plot
8887:
8888: =item $xlabel: string, text describing the X-axis of the plot
8889:
8890: =item $ylabel: string, text describing the Y-axis of the plot
8891:
8892: =item $Max: scalar, the maximum Y value to use in the plot
8893: If $Max is < any data point, the graph will not be rendered.
8894:
8895: =item $colors: Array ref containing the hex color codes for the data to be
8896: plotted in. If undefined, default values will be used.
8897:
8898: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8899:
8900: =item $Ydata: Array ref containing Array refs.
1.185 www 8901: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8902:
8903: =item %Values: hash indicating or overriding any default values which are
8904: passed to graph.png.
8905: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8906:
8907: =back
8908:
8909: Returns:
8910:
8911: An <img> tag which references graph.png and the appropriate identifying
8912: information for the plot.
8913:
1.137 matthew 8914: =cut
8915:
8916: ############################################################
8917: ############################################################
8918: sub DrawXYGraph {
8919: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8920: #
8921: # Create the identifier for the graph
8922: my $identifier = &get_cgi_id();
8923: my $id = 'cgi.'.$identifier;
8924: #
8925: $Title = '' if (! defined($Title));
8926: $xlabel = '' if (! defined($xlabel));
8927: $ylabel = '' if (! defined($ylabel));
8928: my %ValuesHash =
8929: (
1.369 www 8930: $id.'.title' => &escape($Title),
8931: $id.'.xlabel' => &escape($xlabel),
8932: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8933: $id.'.y_max_value'=> $Max,
8934: $id.'.labels' => join(',',@$Xlabels),
8935: $id.'.PlotType' => 'XY',
8936: );
8937: #
8938: if (defined($colors) && ref($colors) eq 'ARRAY') {
8939: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8940: }
8941: #
8942: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8943: return '';
8944: }
8945: my $NumSets=1;
1.138 matthew 8946: foreach my $array (@{$Ydata}){
1.137 matthew 8947: next if (! ref($array));
8948: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8949: }
1.138 matthew 8950: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8951: #
8952: # Deal with other parameters
8953: while (my ($key,$value) = each(%Values)) {
8954: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8955: }
8956: #
1.646 raeburn 8957: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8958: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8959: }
8960:
8961: ############################################################
8962: ############################################################
8963:
8964: =pod
8965:
1.648 raeburn 8966: =item * &DrawXYYGraph()
1.138 matthew 8967:
8968: Facilitates the plotting of data in an XY graph with two Y axes.
8969: Puts plot definition data into the users environment in order for
8970: graph.png to plot it. Returns an <img> tag for the plot.
8971:
8972: Inputs:
8973:
8974: =over 4
8975:
8976: =item $Title: string, the title of the plot
8977:
8978: =item $xlabel: string, text describing the X-axis of the plot
8979:
8980: =item $ylabel: string, text describing the Y-axis of the plot
8981:
8982: =item $colors: Array ref containing the hex color codes for the data to be
8983: plotted in. If undefined, default values will be used.
8984:
8985: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8986:
8987: =item $Ydata1: The first data set
8988:
8989: =item $Min1: The minimum value of the left Y-axis
8990:
8991: =item $Max1: The maximum value of the left Y-axis
8992:
8993: =item $Ydata2: The second data set
8994:
8995: =item $Min2: The minimum value of the right Y-axis
8996:
8997: =item $Max2: The maximum value of the left Y-axis
8998:
8999: =item %Values: hash indicating or overriding any default values which are
9000: passed to graph.png.
9001: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9002:
9003: =back
9004:
9005: Returns:
9006:
9007: An <img> tag which references graph.png and the appropriate identifying
9008: information for the plot.
1.136 matthew 9009:
9010: =cut
9011:
9012: ############################################################
9013: ############################################################
1.137 matthew 9014: sub DrawXYYGraph {
9015: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9016: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9017: #
9018: # Create the identifier for the graph
9019: my $identifier = &get_cgi_id();
9020: my $id = 'cgi.'.$identifier;
9021: #
9022: $Title = '' if (! defined($Title));
9023: $xlabel = '' if (! defined($xlabel));
9024: $ylabel = '' if (! defined($ylabel));
9025: my %ValuesHash =
9026: (
1.369 www 9027: $id.'.title' => &escape($Title),
9028: $id.'.xlabel' => &escape($xlabel),
9029: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9030: $id.'.labels' => join(',',@$Xlabels),
9031: $id.'.PlotType' => 'XY',
9032: $id.'.NumSets' => 2,
1.137 matthew 9033: $id.'.two_axes' => 1,
9034: $id.'.y1_max_value' => $Max1,
9035: $id.'.y1_min_value' => $Min1,
9036: $id.'.y2_max_value' => $Max2,
9037: $id.'.y2_min_value' => $Min2,
1.136 matthew 9038: );
9039: #
1.137 matthew 9040: if (defined($colors) && ref($colors) eq 'ARRAY') {
9041: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9042: }
9043: #
9044: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9045: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9046: return '';
9047: }
9048: my $NumSets=1;
1.137 matthew 9049: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9050: next if (! ref($array));
9051: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9052: }
9053: #
9054: # Deal with other parameters
9055: while (my ($key,$value) = each(%Values)) {
9056: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9057: }
9058: #
1.646 raeburn 9059: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9060: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9061: }
9062:
9063: ############################################################
9064: ############################################################
9065:
9066: =pod
9067:
1.157 matthew 9068: =back
9069:
1.139 matthew 9070: =head1 Statistics helper routines?
9071:
9072: Bad place for them but what the hell.
9073:
1.157 matthew 9074: =over 4
9075:
1.648 raeburn 9076: =item * &chartlink()
1.139 matthew 9077:
9078: Returns a link to the chart for a specific student.
9079:
9080: Inputs:
9081:
9082: =over 4
9083:
9084: =item $linktext: The text of the link
9085:
9086: =item $sname: The students username
9087:
9088: =item $sdomain: The students domain
9089:
9090: =back
9091:
1.157 matthew 9092: =back
9093:
1.139 matthew 9094: =cut
9095:
9096: ############################################################
9097: ############################################################
9098: sub chartlink {
9099: my ($linktext, $sname, $sdomain) = @_;
9100: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9101: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9102: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9103: '">'.$linktext.'</a>';
1.153 matthew 9104: }
9105:
9106: #######################################################
9107: #######################################################
9108:
9109: =pod
9110:
9111: =head1 Course Environment Routines
1.157 matthew 9112:
9113: =over 4
1.153 matthew 9114:
1.648 raeburn 9115: =item * &restore_course_settings()
1.153 matthew 9116:
1.648 raeburn 9117: =item * &store_course_settings()
1.153 matthew 9118:
9119: Restores/Store indicated form parameters from the course environment.
9120: Will not overwrite existing values of the form parameters.
9121:
9122: Inputs:
9123: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9124:
9125: a hash ref describing the data to be stored. For example:
9126:
9127: %Save_Parameters = ('Status' => 'scalar',
9128: 'chartoutputmode' => 'scalar',
9129: 'chartoutputdata' => 'scalar',
9130: 'Section' => 'array',
1.373 raeburn 9131: 'Group' => 'array',
1.153 matthew 9132: 'StudentData' => 'array',
9133: 'Maps' => 'array');
9134:
9135: Returns: both routines return nothing
9136:
1.631 raeburn 9137: =back
9138:
1.153 matthew 9139: =cut
9140:
9141: #######################################################
9142: #######################################################
9143: sub store_course_settings {
1.496 albertel 9144: return &store_settings($env{'request.course.id'},@_);
9145: }
9146:
9147: sub store_settings {
1.153 matthew 9148: # save to the environment
9149: # appenv the same items, just to be safe
1.300 albertel 9150: my $udom = $env{'user.domain'};
9151: my $uname = $env{'user.name'};
1.496 albertel 9152: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9153: my %SaveHash;
9154: my %AppHash;
9155: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9156: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9157: my $envname = 'environment.'.$basename;
1.258 albertel 9158: if (exists($env{'form.'.$setting})) {
1.153 matthew 9159: # Save this value away
9160: if ($type eq 'scalar' &&
1.258 albertel 9161: (! exists($env{$envname}) ||
9162: $env{$envname} ne $env{'form.'.$setting})) {
9163: $SaveHash{$basename} = $env{'form.'.$setting};
9164: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9165: } elsif ($type eq 'array') {
9166: my $stored_form;
1.258 albertel 9167: if (ref($env{'form.'.$setting})) {
1.153 matthew 9168: $stored_form = join(',',
9169: map {
1.369 www 9170: &escape($_);
1.258 albertel 9171: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9172: } else {
9173: $stored_form =
1.369 www 9174: &escape($env{'form.'.$setting});
1.153 matthew 9175: }
9176: # Determine if the array contents are the same.
1.258 albertel 9177: if ($stored_form ne $env{$envname}) {
1.153 matthew 9178: $SaveHash{$basename} = $stored_form;
9179: $AppHash{$envname} = $stored_form;
9180: }
9181: }
9182: }
9183: }
9184: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9185: $udom,$uname);
1.153 matthew 9186: if ($put_result !~ /^(ok|delayed)/) {
9187: &Apache::lonnet::logthis('unable to save form parameters, '.
9188: 'got error:'.$put_result);
9189: }
9190: # Make sure these settings stick around in this session, too
1.646 raeburn 9191: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9192: return;
9193: }
9194:
9195: sub restore_course_settings {
1.499 albertel 9196: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9197: }
9198:
9199: sub restore_settings {
9200: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9201: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9202: next if (exists($env{'form.'.$setting}));
1.496 albertel 9203: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9204: '.'.$setting;
1.258 albertel 9205: if (exists($env{$envname})) {
1.153 matthew 9206: if ($type eq 'scalar') {
1.258 albertel 9207: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9208: } elsif ($type eq 'array') {
1.258 albertel 9209: $env{'form.'.$setting} = [
1.153 matthew 9210: map {
1.369 www 9211: &unescape($_);
1.258 albertel 9212: } split(',',$env{$envname})
1.153 matthew 9213: ];
9214: }
9215: }
9216: }
1.127 matthew 9217: }
9218:
1.618 raeburn 9219: #######################################################
9220: #######################################################
9221:
9222: =pod
9223:
9224: =head1 Domain E-mail Routines
9225:
9226: =over 4
9227:
1.648 raeburn 9228: =item * &build_recipient_list()
1.618 raeburn 9229:
1.766 raeburn 9230: Build recipient lists for four types of e-mail:
9231: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9232: (d) Help requests, generated by
9233: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9234:
9235: Inputs:
1.619 raeburn 9236: defmail (scalar - email address of default recipient),
1.618 raeburn 9237: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9238: defdom (domain for which to retrieve configuration settings),
9239: origmail (scalar - email address of recipient from loncapa.conf,
9240: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9241:
1.655 raeburn 9242: Returns: comma separated list of addresses to which to send e-mail.
9243:
9244: =back
1.618 raeburn 9245:
9246: =cut
9247:
9248: ############################################################
9249: ############################################################
9250: sub build_recipient_list {
1.619 raeburn 9251: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9252: my @recipients;
9253: my $otheremails;
9254: my %domconfig =
9255: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9256: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9257: if (exists($domconfig{'contacts'}{$mailing})) {
9258: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9259: my @contacts = ('adminemail','supportemail');
9260: foreach my $item (@contacts) {
9261: if ($domconfig{'contacts'}{$mailing}{$item}) {
9262: my $addr = $domconfig{'contacts'}{$item};
9263: if (!grep(/^\Q$addr\E$/,@recipients)) {
9264: push(@recipients,$addr);
9265: }
1.619 raeburn 9266: }
1.766 raeburn 9267: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9268: }
9269: }
1.766 raeburn 9270: } elsif ($origmail ne '') {
9271: push(@recipients,$origmail);
1.618 raeburn 9272: }
1.619 raeburn 9273: } elsif ($origmail ne '') {
9274: push(@recipients,$origmail);
1.618 raeburn 9275: }
1.688 raeburn 9276: if (defined($defmail)) {
9277: if ($defmail ne '') {
9278: push(@recipients,$defmail);
9279: }
1.618 raeburn 9280: }
9281: if ($otheremails) {
1.619 raeburn 9282: my @others;
9283: if ($otheremails =~ /,/) {
9284: @others = split(/,/,$otheremails);
1.618 raeburn 9285: } else {
1.619 raeburn 9286: push(@others,$otheremails);
9287: }
9288: foreach my $addr (@others) {
9289: if (!grep(/^\Q$addr\E$/,@recipients)) {
9290: push(@recipients,$addr);
9291: }
1.618 raeburn 9292: }
9293: }
1.619 raeburn 9294: my $recipientlist = join(',',@recipients);
1.618 raeburn 9295: return $recipientlist;
9296: }
9297:
1.127 matthew 9298: ############################################################
9299: ############################################################
1.154 albertel 9300:
1.655 raeburn 9301: =pod
9302:
9303: =head1 Course Catalog Routines
9304:
9305: =over 4
9306:
9307: =item * &gather_categories()
9308:
9309: Converts category definitions - keys of categories hash stored in
9310: coursecategories in configuration.db on the primary library server in a
9311: domain - to an array. Also generates javascript and idx hash used to
9312: generate Domain Coordinator interface for editing Course Categories.
9313:
9314: Inputs:
1.663 raeburn 9315:
1.655 raeburn 9316: categories (reference to hash of category definitions).
1.663 raeburn 9317:
1.655 raeburn 9318: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9319: categories and subcategories).
1.663 raeburn 9320:
1.655 raeburn 9321: idx (reference to hash of counters used in Domain Coordinator interface for
9322: editing Course Categories).
1.663 raeburn 9323:
1.655 raeburn 9324: jsarray (reference to array of categories used to create Javascript arrays for
9325: Domain Coordinator interface for editing Course Categories).
9326:
9327: Returns: nothing
9328:
9329: Side effects: populates cats, idx and jsarray.
9330:
9331: =cut
9332:
9333: sub gather_categories {
9334: my ($categories,$cats,$idx,$jsarray) = @_;
9335: my %counters;
9336: my $num = 0;
9337: foreach my $item (keys(%{$categories})) {
9338: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9339: if ($container eq '' && $depth == 0) {
9340: $cats->[$depth][$categories->{$item}] = $cat;
9341: } else {
9342: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9343: }
9344: my ($escitem,$tail) = split(/:/,$item,2);
9345: if ($counters{$tail} eq '') {
9346: $counters{$tail} = $num;
9347: $num ++;
9348: }
9349: if (ref($idx) eq 'HASH') {
9350: $idx->{$item} = $counters{$tail};
9351: }
9352: if (ref($jsarray) eq 'ARRAY') {
9353: push(@{$jsarray->[$counters{$tail}]},$item);
9354: }
9355: }
9356: return;
9357: }
9358:
9359: =pod
9360:
9361: =item * &extract_categories()
9362:
9363: Used to generate breadcrumb trails for course categories.
9364:
9365: Inputs:
1.663 raeburn 9366:
1.655 raeburn 9367: categories (reference to hash of category definitions).
1.663 raeburn 9368:
1.655 raeburn 9369: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9370: categories and subcategories).
1.663 raeburn 9371:
1.655 raeburn 9372: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9373:
1.655 raeburn 9374: allitems (reference to hash - key is category key
9375: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9376:
1.655 raeburn 9377: idx (reference to hash of counters used in Domain Coordinator interface for
9378: editing Course Categories).
1.663 raeburn 9379:
1.655 raeburn 9380: jsarray (reference to array of categories used to create Javascript arrays for
9381: Domain Coordinator interface for editing Course Categories).
9382:
1.665 raeburn 9383: subcats (reference to hash of arrays containing all subcategories within each
9384: category, -recursive)
9385:
1.655 raeburn 9386: Returns: nothing
9387:
9388: Side effects: populates trails and allitems hash references.
9389:
9390: =cut
9391:
9392: sub extract_categories {
1.665 raeburn 9393: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9394: if (ref($categories) eq 'HASH') {
9395: &gather_categories($categories,$cats,$idx,$jsarray);
9396: if (ref($cats->[0]) eq 'ARRAY') {
9397: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9398: my $name = $cats->[0][$i];
9399: my $item = &escape($name).'::0';
9400: my $trailstr;
9401: if ($name eq 'instcode') {
9402: $trailstr = &mt('Official courses (with institutional codes)');
9403: } else {
9404: $trailstr = $name;
9405: }
9406: if ($allitems->{$item} eq '') {
9407: push(@{$trails},$trailstr);
9408: $allitems->{$item} = scalar(@{$trails})-1;
9409: }
9410: my @parents = ($name);
9411: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9412: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9413: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9414: if (ref($subcats) eq 'HASH') {
9415: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9416: }
9417: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9418: }
9419: } else {
9420: if (ref($subcats) eq 'HASH') {
9421: $subcats->{$item} = [];
1.655 raeburn 9422: }
9423: }
9424: }
9425: }
9426: }
9427: return;
9428: }
9429:
9430: =pod
9431:
9432: =item *&recurse_categories()
9433:
9434: Recursively used to generate breadcrumb trails for course categories.
9435:
9436: Inputs:
1.663 raeburn 9437:
1.655 raeburn 9438: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9439: categories and subcategories).
1.663 raeburn 9440:
1.655 raeburn 9441: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9442:
9443: category (current course category, for which breadcrumb trail is being generated).
9444:
9445: trails (reference to array of breadcrumb trails for each category).
9446:
1.655 raeburn 9447: allitems (reference to hash - key is category key
9448: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9449:
1.655 raeburn 9450: parents (array containing containers directories for current category,
9451: back to top level).
9452:
9453: Returns: nothing
9454:
9455: Side effects: populates trails and allitems hash references
9456:
9457: =cut
9458:
9459: sub recurse_categories {
1.665 raeburn 9460: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9461: my $shallower = $depth - 1;
9462: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9463: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9464: my $name = $cats->[$depth]{$category}[$k];
9465: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9466: my $trailstr = join(' -> ',(@{$parents},$category));
9467: if ($allitems->{$item} eq '') {
9468: push(@{$trails},$trailstr);
9469: $allitems->{$item} = scalar(@{$trails})-1;
9470: }
9471: my $deeper = $depth+1;
9472: push(@{$parents},$category);
1.665 raeburn 9473: if (ref($subcats) eq 'HASH') {
9474: my $subcat = &escape($name).':'.$category.':'.$depth;
9475: for (my $j=@{$parents}; $j>=0; $j--) {
9476: my $higher;
9477: if ($j > 0) {
9478: $higher = &escape($parents->[$j]).':'.
9479: &escape($parents->[$j-1]).':'.$j;
9480: } else {
9481: $higher = &escape($parents->[$j]).'::'.$j;
9482: }
9483: push(@{$subcats->{$higher}},$subcat);
9484: }
9485: }
9486: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9487: $subcats);
1.655 raeburn 9488: pop(@{$parents});
9489: }
9490: } else {
9491: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9492: my $trailstr = join(' -> ',(@{$parents},$category));
9493: if ($allitems->{$item} eq '') {
9494: push(@{$trails},$trailstr);
9495: $allitems->{$item} = scalar(@{$trails})-1;
9496: }
9497: }
9498: return;
9499: }
9500:
1.663 raeburn 9501: =pod
9502:
9503: =item *&assign_categories_table()
9504:
9505: Create a datatable for display of hierarchical categories in a domain,
9506: with checkboxes to allow a course to be categorized.
9507:
9508: Inputs:
9509:
9510: cathash - reference to hash of categories defined for the domain (from
9511: configuration.db)
9512:
9513: currcat - scalar with an & separated list of categories assigned to a course.
9514:
9515: Returns: $output (markup to be displayed)
9516:
9517: =cut
9518:
9519: sub assign_categories_table {
9520: my ($cathash,$currcat) = @_;
9521: my $output;
9522: if (ref($cathash) eq 'HASH') {
9523: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9524: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9525: $maxdepth = scalar(@cats);
9526: if (@cats > 0) {
9527: my $itemcount = 0;
9528: if (ref($cats[0]) eq 'ARRAY') {
9529: $output = &Apache::loncommon::start_data_table();
9530: my @currcategories;
9531: if ($currcat ne '') {
9532: @currcategories = split('&',$currcat);
9533: }
9534: for (my $i=0; $i<@{$cats[0]}; $i++) {
9535: my $parent = $cats[0][$i];
9536: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9537: next if ($parent eq 'instcode');
9538: my $item = &escape($parent).'::0';
9539: my $checked = '';
9540: if (@currcategories > 0) {
9541: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9542: $checked = ' checked="checked"';
1.663 raeburn 9543: }
9544: }
1.675 raeburn 9545: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9546: '<input type="checkbox" name="usecategory" value="'.
9547: $item.'"'.$checked.' />'.$parent.'</span>'.
9548: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9549: my $depth = 1;
9550: push(@path,$parent);
9551: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9552: pop(@path);
9553: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9554: $itemcount ++;
9555: }
9556: $output .= &Apache::loncommon::end_data_table();
9557: }
9558: }
9559: }
9560: return $output;
9561: }
9562:
9563: =pod
9564:
9565: =item *&assign_category_rows()
9566:
9567: Create a datatable row for display of nested categories in a domain,
9568: with checkboxes to allow a course to be categorized,called recursively.
9569:
9570: Inputs:
9571:
9572: itemcount - track row number for alternating colors
9573:
9574: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9575: categories and subcategories.
9576:
9577: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9578:
9579: parent - parent of current category item
9580:
9581: path - Array containing all categories back up through the hierarchy from the
9582: current category to the top level.
9583:
9584: currcategories - reference to array of current categories assigned to the course
9585:
9586: Returns: $output (markup to be displayed).
9587:
9588: =cut
9589:
9590: sub assign_category_rows {
9591: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9592: my ($text,$name,$item,$chgstr);
9593: if (ref($cats) eq 'ARRAY') {
9594: my $maxdepth = scalar(@{$cats});
9595: if (ref($cats->[$depth]) eq 'HASH') {
9596: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9597: my $numchildren = @{$cats->[$depth]{$parent}};
9598: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9599: $text .= '<td><table class="LC_datatable">';
9600: for (my $j=0; $j<$numchildren; $j++) {
9601: $name = $cats->[$depth]{$parent}[$j];
9602: $item = &escape($name).':'.&escape($parent).':'.$depth;
9603: my $deeper = $depth+1;
9604: my $checked = '';
9605: if (ref($currcategories) eq 'ARRAY') {
9606: if (@{$currcategories} > 0) {
9607: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9608: $checked = ' checked="checked"';
1.663 raeburn 9609: }
9610: }
9611: }
1.664 raeburn 9612: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9613: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9614: $item.'"'.$checked.' />'.$name.'</label></span>'.
9615: '<input type="hidden" name="catname" value="'.$name.'" />'.
9616: '</td><td>';
1.663 raeburn 9617: if (ref($path) eq 'ARRAY') {
9618: push(@{$path},$name);
9619: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9620: pop(@{$path});
9621: }
9622: $text .= '</td></tr>';
9623: }
9624: $text .= '</table></td>';
9625: }
9626: }
9627: }
9628: return $text;
9629: }
9630:
1.655 raeburn 9631: ############################################################
9632: ############################################################
9633:
9634:
1.443 albertel 9635: sub commit_customrole {
1.664 raeburn 9636: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9637: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9638: ($start?', '.&mt('starting').' '.localtime($start):'').
9639: ($end?', ending '.localtime($end):'').': <b>'.
9640: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9641: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9642: '</b><br />';
9643: return $output;
9644: }
9645:
9646: sub commit_standardrole {
1.541 raeburn 9647: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9648: my ($output,$logmsg,$linefeed);
9649: if ($context eq 'auto') {
9650: $linefeed = "\n";
9651: } else {
9652: $linefeed = "<br />\n";
9653: }
1.443 albertel 9654: if ($three eq 'st') {
1.541 raeburn 9655: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9656: $one,$two,$sec,$context);
9657: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9658: ($result eq 'unknown_course') || ($result eq 'refused')) {
9659: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9660: } else {
1.541 raeburn 9661: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9662: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9663: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9664: if ($context eq 'auto') {
9665: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9666: } else {
9667: $output .= '<b>'.$result.'</b>'.$linefeed.
9668: &mt('Add to classlist').': <b>ok</b>';
9669: }
9670: $output .= $linefeed;
1.443 albertel 9671: }
9672: } else {
9673: $output = &mt('Assigning').' '.$three.' in '.$url.
9674: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9675: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9676: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9677: if ($context eq 'auto') {
9678: $output .= $result.$linefeed;
9679: } else {
9680: $output .= '<b>'.$result.'</b>'.$linefeed;
9681: }
1.443 albertel 9682: }
9683: return $output;
9684: }
9685:
9686: sub commit_studentrole {
1.541 raeburn 9687: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9688: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9689: if ($context eq 'auto') {
9690: $linefeed = "\n";
9691: } else {
9692: $linefeed = '<br />'."\n";
9693: }
1.443 albertel 9694: if (defined($one) && defined($two)) {
9695: my $cid=$one.'_'.$two;
9696: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9697: my $secchange = 0;
9698: my $expire_role_result;
9699: my $modify_section_result;
1.628 raeburn 9700: if ($oldsec ne '-1') {
9701: if ($oldsec ne $sec) {
1.443 albertel 9702: $secchange = 1;
1.628 raeburn 9703: my $now = time;
1.443 albertel 9704: my $uurl='/'.$cid;
9705: $uurl=~s/\_/\//g;
9706: if ($oldsec) {
9707: $uurl.='/'.$oldsec;
9708: }
1.626 raeburn 9709: $oldsecurl = $uurl;
1.628 raeburn 9710: $expire_role_result =
1.652 raeburn 9711: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9712: if ($env{'request.course.sec'} ne '') {
9713: if ($expire_role_result eq 'refused') {
9714: my @roles = ('st');
9715: my @statuses = ('previous');
9716: my @roledoms = ($one);
9717: my $withsec = 1;
9718: my %roleshash =
9719: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9720: \@statuses,\@roles,\@roledoms,$withsec);
9721: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9722: my ($oldstart,$oldend) =
9723: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9724: if ($oldend > 0 && $oldend <= $now) {
9725: $expire_role_result = 'ok';
9726: }
9727: }
9728: }
9729: }
1.443 albertel 9730: $result = $expire_role_result;
9731: }
9732: }
9733: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9734: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9735: if ($modify_section_result =~ /^ok/) {
9736: if ($secchange == 1) {
1.628 raeburn 9737: if ($sec eq '') {
9738: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9739: } else {
9740: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9741: }
1.443 albertel 9742: } elsif ($oldsec eq '-1') {
1.628 raeburn 9743: if ($sec eq '') {
9744: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9745: } else {
9746: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9747: }
1.443 albertel 9748: } else {
1.628 raeburn 9749: if ($sec eq '') {
9750: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9751: } else {
9752: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9753: }
1.443 albertel 9754: }
9755: } else {
1.628 raeburn 9756: if ($secchange) {
9757: $$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;
9758: } else {
9759: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9760: }
1.443 albertel 9761: }
9762: $result = $modify_section_result;
9763: } elsif ($secchange == 1) {
1.628 raeburn 9764: if ($oldsec eq '') {
9765: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9766: } else {
9767: $$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;
9768: }
1.626 raeburn 9769: if ($expire_role_result eq 'refused') {
9770: my $newsecurl = '/'.$cid;
9771: $newsecurl =~ s/\_/\//g;
9772: if ($sec ne '') {
9773: $newsecurl.='/'.$sec;
9774: }
9775: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9776: if ($sec eq '') {
9777: $$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;
9778: } else {
9779: $$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;
9780: }
9781: }
9782: }
1.443 albertel 9783: }
9784: } else {
1.626 raeburn 9785: $$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 9786: $result = "error: incomplete course id\n";
9787: }
9788: return $result;
9789: }
9790:
9791: ############################################################
9792: ############################################################
9793:
1.566 albertel 9794: sub check_clone {
1.578 raeburn 9795: my ($args,$linefeed) = @_;
1.566 albertel 9796: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9797: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9798: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9799: my $clonemsg;
9800: my $can_clone = 0;
9801:
9802: if ($clonehome eq 'no_host') {
1.578 raeburn 9803: $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 9804: } else {
9805: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9806: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9807: $can_clone = 1;
9808: } else {
9809: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9810: $args->{'clonedomain'},$args->{'clonecourse'});
9811: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9812: if (grep(/^\*$/,@cloners)) {
9813: $can_clone = 1;
9814: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9815: $can_clone = 1;
9816: } else {
9817: my %roleshash =
9818: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9819: $args->{'ccdomain'},
9820: 'userroles',['active'],['cc'],
9821: [$args->{'clonedomain'}]);
9822: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9823: $can_clone = 1;
9824: } else {
9825: $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'});
9826: }
1.566 albertel 9827: }
1.578 raeburn 9828: }
1.566 albertel 9829: }
9830: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9831: }
9832:
1.444 albertel 9833: sub construct_course {
1.541 raeburn 9834: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9835: my $outcome;
1.541 raeburn 9836: my $linefeed = '<br />'."\n";
9837: if ($context eq 'auto') {
9838: $linefeed = "\n";
9839: }
1.566 albertel 9840:
9841: #
9842: # Are we cloning?
9843: #
9844: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9845: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9846: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9847: if ($context ne 'auto') {
1.578 raeburn 9848: if ($clonemsg ne '') {
9849: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9850: }
1.566 albertel 9851: }
9852: $outcome .= $clonemsg.$linefeed;
9853:
9854: if (!$can_clone) {
9855: return (0,$outcome);
9856: }
9857: }
9858:
1.444 albertel 9859: #
9860: # Open course
9861: #
9862: my $crstype = lc($args->{'crstype'});
9863: my %cenv=();
9864: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9865: $args->{'cdescr'},
9866: $args->{'curl'},
9867: $args->{'course_home'},
9868: $args->{'nonstandard'},
9869: $args->{'crscode'},
9870: $args->{'ccuname'}.':'.
9871: $args->{'ccdomain'},
9872: $args->{'crstype'});
9873:
9874: # Note: The testing routines depend on this being output; see
9875: # Utils::Course. This needs to at least be output as a comment
9876: # if anyone ever decides to not show this, and Utils::Course::new
9877: # will need to be suitably modified.
1.541 raeburn 9878: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9879: #
9880: # Check if created correctly
9881: #
1.479 albertel 9882: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9883: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9884: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9885:
1.444 albertel 9886: #
1.566 albertel 9887: # Do the cloning
9888: #
9889: if ($can_clone && $cloneid) {
9890: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9891: if ($context ne 'auto') {
9892: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9893: }
9894: $outcome .= $clonemsg.$linefeed;
9895: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9896: # Copy all files
1.637 www 9897: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9898: # Restore URL
1.566 albertel 9899: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9900: # Restore title
1.566 albertel 9901: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9902: # Mark as cloned
1.566 albertel 9903: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9904: # Need to clone grading mode
9905: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9906: $cenv{'grading'}=$newenv{'grading'};
9907: # Do not clone these environment entries
9908: &Apache::lonnet::del('environment',
9909: ['default_enrollment_start_date',
9910: 'default_enrollment_end_date',
9911: 'question.email',
9912: 'policy.email',
9913: 'comment.email',
9914: 'pch.users.denied',
1.725 raeburn 9915: 'plc.users.denied',
9916: 'hidefromcat',
9917: 'categories'],
1.638 www 9918: $$crsudom,$$crsunum);
1.444 albertel 9919: }
1.566 albertel 9920:
1.444 albertel 9921: #
9922: # Set environment (will override cloned, if existing)
9923: #
9924: my @sections = ();
9925: my @xlists = ();
9926: if ($args->{'crstype'}) {
9927: $cenv{'type'}=$args->{'crstype'};
9928: }
9929: if ($args->{'crsid'}) {
9930: $cenv{'courseid'}=$args->{'crsid'};
9931: }
9932: if ($args->{'crscode'}) {
9933: $cenv{'internal.coursecode'}=$args->{'crscode'};
9934: }
9935: if ($args->{'crsquota'} ne '') {
9936: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9937: } else {
9938: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9939: }
9940: if ($args->{'ccuname'}) {
9941: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9942: ':'.$args->{'ccdomain'};
9943: } else {
9944: $cenv{'internal.courseowner'} = $args->{'curruser'};
9945: }
9946: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9947: if ($args->{'crssections'}) {
9948: $cenv{'internal.sectionnums'} = '';
9949: if ($args->{'crssections'} =~ m/,/) {
9950: @sections = split/,/,$args->{'crssections'};
9951: } else {
9952: $sections[0] = $args->{'crssections'};
9953: }
9954: if (@sections > 0) {
9955: foreach my $item (@sections) {
9956: my ($sec,$gp) = split/:/,$item;
9957: my $class = $args->{'crscode'}.$sec;
9958: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9959: $cenv{'internal.sectionnums'} .= $item.',';
9960: unless ($addcheck eq 'ok') {
9961: push @badclasses, $class;
9962: }
9963: }
9964: $cenv{'internal.sectionnums'} =~ s/,$//;
9965: }
9966: }
9967: # do not hide course coordinator from staff listing,
9968: # even if privileged
9969: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9970: # add crosslistings
9971: if ($args->{'crsxlist'}) {
9972: $cenv{'internal.crosslistings'}='';
9973: if ($args->{'crsxlist'} =~ m/,/) {
9974: @xlists = split/,/,$args->{'crsxlist'};
9975: } else {
9976: $xlists[0] = $args->{'crsxlist'};
9977: }
9978: if (@xlists > 0) {
9979: foreach my $item (@xlists) {
9980: my ($xl,$gp) = split/:/,$item;
9981: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9982: $cenv{'internal.crosslistings'} .= $item.',';
9983: unless ($addcheck eq 'ok') {
9984: push @badclasses, $xl;
9985: }
9986: }
9987: $cenv{'internal.crosslistings'} =~ s/,$//;
9988: }
9989: }
9990: if ($args->{'autoadds'}) {
9991: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9992: }
9993: if ($args->{'autodrops'}) {
9994: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9995: }
9996: # check for notification of enrollment changes
9997: my @notified = ();
9998: if ($args->{'notify_owner'}) {
9999: if ($args->{'ccuname'} ne '') {
10000: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10001: }
10002: }
10003: if ($args->{'notify_dc'}) {
10004: if ($uname ne '') {
1.630 raeburn 10005: push(@notified,$uname.':'.$udom);
1.444 albertel 10006: }
10007: }
10008: if (@notified > 0) {
10009: my $notifylist;
10010: if (@notified > 1) {
10011: $notifylist = join(',',@notified);
10012: } else {
10013: $notifylist = $notified[0];
10014: }
10015: $cenv{'internal.notifylist'} = $notifylist;
10016: }
10017: if (@badclasses > 0) {
10018: my %lt=&Apache::lonlocal::texthash(
10019: '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',
10020: 'dnhr' => 'does not have rights to access enrollment in these classes',
10021: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10022: );
1.541 raeburn 10023: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10024: ' ('.$lt{'adby'}.')';
10025: if ($context eq 'auto') {
10026: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10027: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10028: foreach my $item (@badclasses) {
10029: if ($context eq 'auto') {
10030: $outcome .= " - $item\n";
10031: } else {
10032: $outcome .= "<li>$item</li>\n";
10033: }
10034: }
10035: if ($context eq 'auto') {
10036: $outcome .= $linefeed;
10037: } else {
1.566 albertel 10038: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10039: }
10040: }
1.444 albertel 10041: }
10042: if ($args->{'no_end_date'}) {
10043: $args->{'endaccess'} = 0;
10044: }
10045: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10046: $cenv{'internal.autoend'}=$args->{'enrollend'};
10047: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10048: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10049: if ($args->{'showphotos'}) {
10050: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10051: }
10052: $cenv{'internal.authtype'} = $args->{'authtype'};
10053: $cenv{'internal.autharg'} = $args->{'autharg'};
10054: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10055: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10056: 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');
10057: if ($context eq 'auto') {
10058: $outcome .= $krb_msg;
10059: } else {
1.566 albertel 10060: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10061: }
10062: $outcome .= $linefeed;
1.444 albertel 10063: }
10064: }
10065: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10066: if ($args->{'setpolicy'}) {
10067: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10068: }
10069: if ($args->{'setcontent'}) {
10070: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10071: }
10072: }
10073: if ($args->{'reshome'}) {
10074: $cenv{'reshome'}=$args->{'reshome'}.'/';
10075: $cenv{'reshome'}=~s/\/+$/\//;
10076: }
10077: #
10078: # course has keyed access
10079: #
10080: if ($args->{'setkeys'}) {
10081: $cenv{'keyaccess'}='yes';
10082: }
10083: # if specified, key authority is not course, but user
10084: # only active if keyaccess is yes
10085: if ($args->{'keyauth'}) {
1.487 albertel 10086: my ($user,$domain) = split(':',$args->{'keyauth'});
10087: $user = &LONCAPA::clean_username($user);
10088: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10089: if ($user ne '' && $domain ne '') {
1.487 albertel 10090: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10091: }
10092: }
10093:
10094: if ($args->{'disresdis'}) {
10095: $cenv{'pch.roles.denied'}='st';
10096: }
10097: if ($args->{'disablechat'}) {
10098: $cenv{'plc.roles.denied'}='st';
10099: }
10100:
10101: # Record we've not yet viewed the Course Initialization Helper for this
10102: # course
10103: $cenv{'course.helper.not.run'} = 1;
10104: #
10105: # Use new Randomseed
10106: #
10107: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10108: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10109: #
10110: # The encryption code and receipt prefix for this course
10111: #
10112: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10113: $cenv{'internal.encpref'}=100+int(9*rand(99));
10114: #
10115: # By default, use standard grading
10116: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10117:
1.541 raeburn 10118: $outcome .= $linefeed.&mt('Setting environment').': '.
10119: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10120: #
10121: # Open all assignments
10122: #
10123: if ($args->{'openall'}) {
10124: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10125: my %storecontent = ($storeunder => time,
10126: $storeunder.'.type' => 'date_start');
10127:
10128: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10129: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10130: }
10131: #
10132: # Set first page
10133: #
10134: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10135: || ($cloneid)) {
1.445 albertel 10136: use LONCAPA::map;
1.444 albertel 10137: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10138:
10139: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10140: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10141:
1.444 albertel 10142: $outcome .= ($fatal?$errtext:'read ok').' - ';
10143: my $title; my $url;
10144: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10145: $title=&mt('Syllabus');
1.444 albertel 10146: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10147: } else {
1.690 bisitz 10148: $title=&mt('Navigate Contents');
1.444 albertel 10149: $url='/adm/navmaps';
10150: }
1.445 albertel 10151:
10152: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10153: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10154:
10155: if ($errtext) { $fatal=2; }
1.541 raeburn 10156: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10157: }
1.566 albertel 10158:
10159: return (1,$outcome);
1.444 albertel 10160: }
10161:
10162: ############################################################
10163: ############################################################
10164:
1.378 raeburn 10165: sub course_type {
10166: my ($cid) = @_;
10167: if (!defined($cid)) {
10168: $cid = $env{'request.course.id'};
10169: }
1.404 albertel 10170: if (defined($env{'course.'.$cid.'.type'})) {
10171: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10172: } else {
10173: return 'Course';
1.377 raeburn 10174: }
10175: }
1.156 albertel 10176:
1.406 raeburn 10177: sub group_term {
10178: my $crstype = &course_type();
10179: my %names = (
10180: 'Course' => 'group',
1.865 raeburn 10181: 'Community' => 'group',
1.406 raeburn 10182: );
10183: return $names{$crstype};
10184: }
10185:
1.156 albertel 10186: sub icon {
10187: my ($file)=@_;
1.505 albertel 10188: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10189: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10190: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10191: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10192: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10193: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10194: $curfext.".gif") {
10195: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10196: $curfext.".gif";
10197: }
10198: }
1.249 albertel 10199: return &lonhttpdurl($iconname);
1.154 albertel 10200: }
1.84 albertel 10201:
1.575 albertel 10202: sub lonhttpdurl {
1.692 www 10203: #
10204: # Had been used for "small fry" static images on separate port 8080.
10205: # Modify here if lightweight http functionality desired again.
10206: # Currently eliminated due to increasing firewall issues.
10207: #
1.575 albertel 10208: my ($url)=@_;
1.692 www 10209: return $url;
1.215 albertel 10210: }
10211:
1.213 albertel 10212: sub connection_aborted {
10213: my ($r)=@_;
10214: $r->print(" ");$r->rflush();
10215: my $c = $r->connection;
10216: return $c->aborted();
10217: }
10218:
1.221 foxr 10219: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10220: # strings as 'strings'.
10221: sub escape_single {
1.221 foxr 10222: my ($input) = @_;
1.223 albertel 10223: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10224: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10225: return $input;
10226: }
1.223 albertel 10227:
1.222 foxr 10228: # Same as escape_single, but escape's "'s This
10229: # can be used for "strings"
10230: sub escape_double {
10231: my ($input) = @_;
10232: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10233: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10234: return $input;
10235: }
1.223 albertel 10236:
1.222 foxr 10237: # Escapes the last element of a full URL.
10238: sub escape_url {
10239: my ($url) = @_;
1.238 raeburn 10240: my @urlslices = split(/\//, $url,-1);
1.369 www 10241: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10242: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10243: }
1.462 albertel 10244:
1.820 raeburn 10245: sub compare_arrays {
10246: my ($arrayref1,$arrayref2) = @_;
10247: my (@difference,%count);
10248: @difference = ();
10249: %count = ();
10250: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10251: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10252: foreach my $element (keys(%count)) {
10253: if ($count{$element} == 1) {
10254: push(@difference,$element);
10255: }
10256: }
10257: }
10258: return @difference;
10259: }
10260:
1.817 bisitz 10261: # -------------------------------------------------------- Initialize user login
1.462 albertel 10262: sub init_user_environment {
1.463 albertel 10263: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10264: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10265:
10266: my $public=($username eq 'public' && $domain eq 'public');
10267:
10268: # See if old ID present, if so, remove
10269:
10270: my ($filename,$cookie,$userroles);
10271: my $now=time;
10272:
10273: if ($public) {
10274: my $max_public=100;
10275: my $oldest;
10276: my $oldest_time=0;
10277: for(my $next=1;$next<=$max_public;$next++) {
10278: if (-e $lonids."/publicuser_$next.id") {
10279: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10280: if ($mtime<$oldest_time || !$oldest_time) {
10281: $oldest_time=$mtime;
10282: $oldest=$next;
10283: }
10284: } else {
10285: $cookie="publicuser_$next";
10286: last;
10287: }
10288: }
10289: if (!$cookie) { $cookie="publicuser_$oldest"; }
10290: } else {
1.463 albertel 10291: # if this isn't a robot, kill any existing non-robot sessions
10292: if (!$args->{'robot'}) {
10293: opendir(DIR,$lonids);
10294: while ($filename=readdir(DIR)) {
10295: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10296: unlink($lonids.'/'.$filename);
10297: }
1.462 albertel 10298: }
1.463 albertel 10299: closedir(DIR);
1.462 albertel 10300: }
10301: # Give them a new cookie
1.463 albertel 10302: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10303: : $now.$$.int(rand(10000)));
1.463 albertel 10304: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10305:
10306: # Initialize roles
10307:
10308: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10309: }
10310: # ------------------------------------ Check browser type and MathML capability
10311:
10312: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10313: $clientunicode,$clientos) = &decode_user_agent($r);
10314:
10315: # ------------------------------------------------------------- Get environment
10316:
10317: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10318: my ($tmp) = keys(%userenv);
10319: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10320: # default remote control to off
10321: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10322: } else {
10323: undef(%userenv);
10324: }
10325: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10326: $form->{'interface'}=$userenv{'interface'};
10327: }
10328: $env{'environment.remote'}=$userenv{'remote'};
10329: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10330:
10331: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10332: foreach my $option ('interface','localpath','localres') {
10333: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10334: }
10335: # --------------------------------------------------------- Write first profile
10336:
10337: {
10338: my %initial_env =
10339: ("user.name" => $username,
10340: "user.domain" => $domain,
10341: "user.home" => $authhost,
10342: "browser.type" => $clientbrowser,
10343: "browser.version" => $clientversion,
10344: "browser.mathml" => $clientmathml,
10345: "browser.unicode" => $clientunicode,
10346: "browser.os" => $clientos,
10347: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10348: "request.course.fn" => '',
10349: "request.course.uri" => '',
10350: "request.course.sec" => '',
10351: "request.role" => 'cm',
10352: "request.role.adv" => $env{'user.adv'},
10353: "request.host" => $ENV{'REMOTE_ADDR'},);
10354:
10355: if ($form->{'localpath'}) {
10356: $initial_env{"browser.localpath"} = $form->{'localpath'};
10357: $initial_env{"browser.localres"} = $form->{'localres'};
10358: }
10359:
10360: if ($public) {
10361: $initial_env{"environment.remote"} = "off";
10362: }
10363: if ($form->{'interface'}) {
10364: $form->{'interface'}=~s/\W//gs;
10365: $initial_env{"browser.interface"} = $form->{'interface'};
10366: $env{'browser.interface'}=$form->{'interface'};
10367: }
10368:
1.724 raeburn 10369: foreach my $tool ('aboutme','blog','portfolio') {
10370: $userenv{'availabletools.'.$tool} =
10371: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10372: }
10373:
1.864 raeburn 10374: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10375: $userenv{'canrequest.'.$crstype} =
10376: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10377: 'reload','requestcourses');
10378: }
10379:
1.462 albertel 10380: $env{'user.environment'} = "$lonids/$cookie.id";
10381:
10382: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10383: &GDBM_WRCREAT(),0640)) {
10384: &_add_to_env(\%disk_env,\%initial_env);
10385: &_add_to_env(\%disk_env,\%userenv,'environment.');
10386: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10387: if (ref($args->{'extra_env'})) {
10388: &_add_to_env(\%disk_env,$args->{'extra_env'});
10389: }
1.462 albertel 10390: untie(%disk_env);
10391: } else {
1.705 tempelho 10392: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10393: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10394: return 'error: '.$!;
10395: }
10396: }
10397: $env{'request.role'}='cm';
10398: $env{'request.role.adv'}=$env{'user.adv'};
10399: $env{'browser.type'}=$clientbrowser;
10400:
10401: return $cookie;
10402:
10403: }
10404:
10405: sub _add_to_env {
10406: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10407: if (ref($env_data) eq 'HASH') {
10408: while (my ($key,$value) = each(%$env_data)) {
10409: $idf->{$prefix.$key} = $value;
10410: $env{$prefix.$key} = $value;
10411: }
1.462 albertel 10412: }
10413: }
10414:
1.685 tempelho 10415: # --- Get the symbolic name of a problem and the url
10416: sub get_symb {
10417: my ($request,$silent) = @_;
1.726 raeburn 10418: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10419: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10420: if ($symb eq '') {
10421: if (!$silent) {
10422: $request->print("Unable to handle ambiguous references:$url:.");
10423: return ();
10424: }
10425: }
10426: &Apache::lonenc::check_decrypt(\$symb);
10427: return ($symb);
10428: }
10429:
10430: # --------------------------------------------------------------Get annotation
10431:
10432: sub get_annotation {
10433: my ($symb,$enc) = @_;
10434:
10435: my $key = $symb;
10436: if (!$enc) {
10437: $key =
10438: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10439: }
10440: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10441: return $annotation{$key};
10442: }
10443:
10444: sub clean_symb {
1.731 raeburn 10445: my ($symb,$delete_enc) = @_;
1.685 tempelho 10446:
10447: &Apache::lonenc::check_decrypt(\$symb);
10448: my $enc = $env{'request.enc'};
1.731 raeburn 10449: if ($delete_enc) {
1.730 raeburn 10450: delete($env{'request.enc'});
10451: }
1.685 tempelho 10452:
10453: return ($symb,$enc);
10454: }
1.462 albertel 10455:
1.41 ng 10456: =pod
10457:
10458: =back
10459:
1.112 bowersj2 10460: =cut
1.41 ng 10461:
1.112 bowersj2 10462: 1;
10463: __END__;
1.41 ng 10464:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>