Annotation of loncom/interface/loncommon.pm, revision 1.878
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.878 ! bisitz 4: # $Id: loncommon.pm,v 1.877 2009/08/05 11:01:38 bisitz Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.468 raeburn 485: my ($domainfilter,$sec_element,$formname)=@_;
1.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.876 raeburn 487: my $id_functions = &javascript_index_functions();
488: my $output = '
1.776 bisitz 489: <script type="text/javascript" language="JavaScript">
1.824 bisitz 490: // <![CDATA[
1.468 raeburn 491: var stdeditbrowser;'."\n";
1.876 raeburn 492:
493: $output .= <<"ENDSTDBRW";
1.377 raeburn 494: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 495: var url = '/adm/pickcourse?';
1.876 raeburn 496: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 497: if (domainfilter != null) {
498: if (domainfilter != '') {
499: url += 'domainfilter='+domainfilter+'&';
500: }
501: }
1.91 www 502: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 503: '&cdomelement='+udom+
504: '&cnameelement='+desc;
1.468 raeburn 505: if (extra_element !=null && extra_element != '') {
1.594 raeburn 506: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 507: url += '&roleelement='+extra_element;
508: if (domainfilter == null || domainfilter == '') {
509: url += '&domainfilter='+extra_element;
510: }
1.234 raeburn 511: }
1.468 raeburn 512: else {
513: if (formname == 'portform') {
514: url += '&setroles='+extra_element;
1.800 raeburn 515: } else {
516: if (formname == 'rules') {
517: url += '&fixeddom='+extra_element;
518: }
1.468 raeburn 519: }
520: }
1.230 raeburn 521: }
1.872 raeburn 522: if (formname == 'ccrs') {
523: var ownername = document.forms[formid].ccuname.value;
524: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
525: url += '&cloner='+ownername+':'+ownerdom;
526: }
1.293 raeburn 527: if (multflag !=null && multflag != '') {
528: url += '&multiple='+multflag;
529: }
1.865 raeburn 530: if (crstype == 'Course/Community') {
1.377 raeburn 531: if (formname == 'cu') {
532: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
533: if (crstype == "") {
534: alert("$crs_or_grp_alert");
535: return;
536: }
537: }
538: }
539: if (crstype !=null && crstype != '') {
540: url += '&type='+crstype;
541: }
1.102 www 542: var title = 'Course_Browser';
1.91 www 543: var options = 'scrollbars=1,resizable=1,menubar=0';
544: options += ',width=700,height=600';
545: stdeditbrowser = open(url,title,options,'1');
546: stdeditbrowser.focus();
547: }
1.876 raeburn 548: $id_functions
549: ENDSTDBRW
550: if ($sec_element ne '') {
551: $output .= &setsec_javascript($sec_element,$formname);
552: }
553: $output .= '
554: // ]]>
555: </script>';
556: return $output;
557: }
558:
559: sub javascript_index_functions {
560: return <<"ENDJS";
561:
562: function getFormIdByName(formname) {
563: for (var i=0;i<document.forms.length;i++) {
564: if (document.forms[i].name == formname) {
565: return i;
566: }
567: }
568: return -1;
569: }
570:
571: function getIndexByName(formid,item) {
572: for (var i=0;i<document.forms[formid].elements.length;i++) {
573: if (document.forms[formid].elements[i].name == item) {
574: return i;
575: }
576: }
577: return -1;
578: }
1.468 raeburn 579:
1.876 raeburn 580: function getDomainFromSelectbox(formname,udom) {
581: var userdom;
582: var formid = getFormIdByName(formname);
583: if (formid > -1) {
584: var domid = getIndexByName(formid,udom);
585: if (domid > -1) {
586: if (document.forms[formid].elements[domid].type == 'select-one') {
587: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
588: }
589: if (document.forms[formid].elements[domid].type == 'hidden') {
590: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 591: }
592: }
593: }
1.876 raeburn 594: return userdom;
595: }
596:
597: ENDJS
1.468 raeburn 598:
1.876 raeburn 599: }
600:
601: sub userbrowser_javascript {
602: my $id_functions = &javascript_index_functions();
603: return <<"ENDUSERBRW";
604:
605: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom) {
606: var url = '/adm/pickuser?';
607: var userdom = getDomainFromSelectbox(formname,udom);
608: if (userdom != null) {
609: if (userdom != '') {
610: url += 'srchdom='+userdom+'&';
611: }
612: }
613: url += 'form=' + formname + '&unameelement='+uname+
614: '&udomelement='+udom+
615: '&ulastelement='+ulast+
616: '&ufirstelement='+ufirst+
617: '&uemailelement='+uemail+
618: '&hideudomelement='+hideudom;
619: var title = 'User_Browser';
620: var options = 'scrollbars=1,resizable=1,menubar=0';
621: options += ',width=700,height=600';
622: var stdeditbrowser = open(url,title,options,'1');
623: stdeditbrowser.focus();
624: }
625:
626: function fix_domain (formname,udom,origdom) {
627: var formid = getFormIdByName(formname);
628: if (formid > -1) {
629: var domid = getIndexByName(formid,udom);
630: var hidedomid = getIndexByName(formid,origdom);
631: if (hidedomid > -1) {
632: var fixeddom = document.forms[formid].elements[hidedomid].value;
633: if (domid > -1) {
634: var slct = document.forms[formid].elements[domid];
635: if (slct.type == 'select-one') {
636: var i;
637: for (i=0;i<slct.length;i++) {
638: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
639: }
640: }
641: if (slct.type == 'hidden') {
642: slct.value = fixeddom;
643: }
1.468 raeburn 644: }
645: }
646: }
1.876 raeburn 647: return;
648: }
649:
650: $id_functions
651: ENDUSERBRW
1.468 raeburn 652: }
653:
654: sub setsec_javascript {
655: my ($sec_element,$formname) = @_;
656: my $setsections = qq|
657: function setSect(sectionlist) {
1.629 raeburn 658: var sectionsArray = new Array();
659: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
660: sectionsArray = sectionlist.split(",");
661: }
1.468 raeburn 662: var numSections = sectionsArray.length;
663: document.$formname.$sec_element.length = 0;
664: if (numSections == 0) {
665: document.$formname.$sec_element.multiple=false;
666: document.$formname.$sec_element.size=1;
667: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
668: } else {
669: if (numSections == 1) {
670: document.$formname.$sec_element.multiple=false;
671: document.$formname.$sec_element.size=1;
672: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
673: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
674: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
675: } else {
676: for (var i=0; i<numSections; i++) {
677: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
678: }
679: document.$formname.$sec_element.multiple=true
680: if (numSections < 3) {
681: document.$formname.$sec_element.size=numSections;
682: } else {
683: document.$formname.$sec_element.size=3;
684: }
685: document.$formname.$sec_element.options[0].selected = false
686: }
687: }
1.91 www 688: }
1.468 raeburn 689: |;
690: return $setsections;
691: }
692:
1.91 www 693:
694: sub selectcourse_link {
1.377 raeburn 695: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.871 raeburn 696: my $linktext = &mt('Select Course');
697: if ($selecttype eq 'Community') {
698: $linktext = &mt('Select Community');
699: }
1.787 bisitz 700: return '<span class="LC_nobreak">'
701: ."<a href='"
702: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
703: .'","'.$udomele.'","'.$desc.'","'.$extra_element
704: .'","'.$multflag.'","'.$selecttype.'");'
1.871 raeburn 705: ."'>".$linktext.'</a>'
1.787 bisitz 706: .'</span>';
1.74 www 707: }
1.42 matthew 708:
1.653 raeburn 709: sub selectauthor_link {
710: my ($form,$udom)=@_;
711: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
712: &mt('Select Author').'</a>';
713: }
714:
1.876 raeburn 715: sub selectuser_link {
716: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,$linktext) = @_;
717: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
718: "'$lastelem','$firstelem','$emailelem','$hdomelem'".');">'.$linktext.'</a>';
719: }
720:
1.273 raeburn 721: sub check_uncheck_jscript {
722: my $jscript = <<"ENDSCRT";
723: function checkAll(field) {
724: if (field.length > 0) {
725: for (i = 0; i < field.length; i++) {
726: field[i].checked = true ;
727: }
728: } else {
729: field.checked = true
730: }
731: }
732:
733: function uncheckAll(field) {
734: if (field.length > 0) {
735: for (i = 0; i < field.length; i++) {
736: field[i].checked = false ;
1.543 albertel 737: }
738: } else {
1.273 raeburn 739: field.checked = false ;
740: }
741: }
742: ENDSCRT
743: return $jscript;
744: }
745:
1.656 www 746: sub select_timezone {
1.659 raeburn 747: my ($name,$selected,$onchange,$includeempty)=@_;
748: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
749: if ($includeempty) {
750: $output .= '<option value=""';
751: if (($selected eq '') || ($selected eq 'local')) {
752: $output .= ' selected="selected" ';
753: }
754: $output .= '> </option>';
755: }
1.657 raeburn 756: my @timezones = DateTime::TimeZone->all_names;
757: foreach my $tzone (@timezones) {
758: $output.= '<option value="'.$tzone.'"';
759: if ($tzone eq $selected) {
760: $output.=' selected="selected"';
761: }
762: $output.=">$tzone</option>\n";
1.656 www 763: }
764: $output.="</select>";
765: return $output;
766: }
1.273 raeburn 767:
1.687 raeburn 768: sub select_datelocale {
769: my ($name,$selected,$onchange,$includeempty)=@_;
770: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
771: if ($includeempty) {
772: $output .= '<option value=""';
773: if ($selected eq '') {
774: $output .= ' selected="selected" ';
775: }
776: $output .= '> </option>';
777: }
778: my (@possibles,%locale_names);
779: my @locales = DateTime::Locale::Catalog::Locales;
780: foreach my $locale (@locales) {
781: if (ref($locale) eq 'HASH') {
782: my $id = $locale->{'id'};
783: if ($id ne '') {
784: my $en_terr = $locale->{'en_territory'};
785: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 786: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 787: if (grep(/^en$/,@languages) || !@languages) {
788: if ($en_terr ne '') {
789: $locale_names{$id} = '('.$en_terr.')';
790: } elsif ($native_terr ne '') {
791: $locale_names{$id} = $native_terr;
792: }
793: } else {
794: if ($native_terr ne '') {
795: $locale_names{$id} = $native_terr.' ';
796: } elsif ($en_terr ne '') {
797: $locale_names{$id} = '('.$en_terr.')';
798: }
799: }
800: push (@possibles,$id);
801: }
802: }
803: }
804: foreach my $item (sort(@possibles)) {
805: $output.= '<option value="'.$item.'"';
806: if ($item eq $selected) {
807: $output.=' selected="selected"';
808: }
809: $output.=">$item";
810: if ($locale_names{$item} ne '') {
811: $output.=" $locale_names{$item}</option>\n";
812: }
813: $output.="</option>\n";
814: }
815: $output.="</select>";
816: return $output;
817: }
818:
1.792 raeburn 819: sub select_language {
820: my ($name,$selected,$includeempty) = @_;
821: my %langchoices;
822: if ($includeempty) {
823: %langchoices = ('' => 'No language preference');
824: }
825: foreach my $id (&languageids()) {
826: my $code = &supportedlanguagecode($id);
827: if ($code) {
828: $langchoices{$code} = &plainlanguagedescription($id);
829: }
830: }
831: return &select_form($selected,$name,%langchoices);
832: }
833:
1.42 matthew 834: =pod
1.36 matthew 835:
1.648 raeburn 836: =item * &linked_select_forms(...)
1.36 matthew 837:
838: linked_select_forms returns a string containing a <script></script> block
839: and html for two <select> menus. The select menus will be linked in that
840: changing the value of the first menu will result in new values being placed
841: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 842: order unless a defined order is provided.
1.36 matthew 843:
844: linked_select_forms takes the following ordered inputs:
845:
846: =over 4
847:
1.112 bowersj2 848: =item * $formname, the name of the <form> tag
1.36 matthew 849:
1.112 bowersj2 850: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 851:
1.112 bowersj2 852: =item * $firstdefault, the default value for the first menu
1.36 matthew 853:
1.112 bowersj2 854: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 855:
1.112 bowersj2 856: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 857:
1.112 bowersj2 858: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 859:
1.609 raeburn 860: =item * $menuorder, the order of values in the first menu
861:
1.41 ng 862: =back
863:
1.36 matthew 864: Below is an example of such a hash. Only the 'text', 'default', and
865: 'select2' keys must appear as stated. keys(%menu) are the possible
866: values for the first select menu. The text that coincides with the
1.41 ng 867: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 868: and text for the second menu are given in the hash pointed to by
869: $menu{$choice1}->{'select2'}.
870:
1.112 bowersj2 871: my %menu = ( A1 => { text =>"Choice A1" ,
872: default => "B3",
873: select2 => {
874: B1 => "Choice B1",
875: B2 => "Choice B2",
876: B3 => "Choice B3",
877: B4 => "Choice B4"
1.609 raeburn 878: },
879: order => ['B4','B3','B1','B2'],
1.112 bowersj2 880: },
881: A2 => { text =>"Choice A2" ,
882: default => "C2",
883: select2 => {
884: C1 => "Choice C1",
885: C2 => "Choice C2",
886: C3 => "Choice C3"
1.609 raeburn 887: },
888: order => ['C2','C1','C3'],
1.112 bowersj2 889: },
890: A3 => { text =>"Choice A3" ,
891: default => "D6",
892: select2 => {
893: D1 => "Choice D1",
894: D2 => "Choice D2",
895: D3 => "Choice D3",
896: D4 => "Choice D4",
897: D5 => "Choice D5",
898: D6 => "Choice D6",
899: D7 => "Choice D7"
1.609 raeburn 900: },
901: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 902: }
903: );
1.36 matthew 904:
905: =cut
906:
907: sub linked_select_forms {
908: my ($formname,
909: $middletext,
910: $firstdefault,
911: $firstselectname,
912: $secondselectname,
1.609 raeburn 913: $hashref,
914: $menuorder,
1.36 matthew 915: ) = @_;
916: my $second = "document.$formname.$secondselectname";
917: my $first = "document.$formname.$firstselectname";
918: # output the javascript to do the changing
919: my $result = '';
1.776 bisitz 920: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 921: $result.="// <![CDATA[\n";
1.36 matthew 922: $result.="var select2data = new Object();\n";
923: $" = '","';
924: my $debug = '';
925: foreach my $s1 (sort(keys(%$hashref))) {
926: $result.="select2data.d_$s1 = new Object();\n";
927: $result.="select2data.d_$s1.def = new String('".
928: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 929: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 930: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 931: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
932: @s2values = @{$hashref->{$s1}->{'order'}};
933: }
1.36 matthew 934: $result.="\"@s2values\");\n";
935: $result.="select2data.d_$s1.texts = new Array(";
936: my @s2texts;
937: foreach my $value (@s2values) {
938: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
939: }
940: $result.="\"@s2texts\");\n";
941: }
942: $"=' ';
943: $result.= <<"END";
944:
945: function select1_changed() {
946: // Determine new choice
947: var newvalue = "d_" + $first.value;
948: // update select2
949: var values = select2data[newvalue].values;
950: var texts = select2data[newvalue].texts;
951: var select2def = select2data[newvalue].def;
952: var i;
953: // out with the old
954: for (i = 0; i < $second.options.length; i++) {
955: $second.options[i] = null;
956: }
957: // in with the nuclear
958: for (i=0;i<values.length; i++) {
959: $second.options[i] = new Option(values[i]);
1.143 matthew 960: $second.options[i].value = values[i];
1.36 matthew 961: $second.options[i].text = texts[i];
962: if (values[i] == select2def) {
963: $second.options[i].selected = true;
964: }
965: }
966: }
1.824 bisitz 967: // ]]>
1.36 matthew 968: </script>
969: END
970: # output the initial values for the selection lists
971: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 972: my @order = sort(keys(%{$hashref}));
973: if (ref($menuorder) eq 'ARRAY') {
974: @order = @{$menuorder};
975: }
976: foreach my $value (@order) {
1.36 matthew 977: $result.=" <option value=\"$value\" ";
1.253 albertel 978: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 979: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 980: }
981: $result .= "</select>\n";
982: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
983: $result .= $middletext;
984: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
985: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 986:
987: my @secondorder = sort(keys(%select2));
988: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
989: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
990: }
991: foreach my $value (@secondorder) {
1.36 matthew 992: $result.=" <option value=\"$value\" ";
1.253 albertel 993: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 994: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 995: }
996: $result .= "</select>\n";
997: # return $debug;
998: return $result;
999: } # end of sub linked_select_forms {
1000:
1.45 matthew 1001: =pod
1.44 bowersj2 1002:
1.648 raeburn 1003: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 1004:
1.112 bowersj2 1005: Returns a string corresponding to an HTML link to the given help
1006: $topic, where $topic corresponds to the name of a .tex file in
1007: /home/httpd/html/adm/help/tex, with underscores replaced by
1008: spaces.
1009:
1010: $text will optionally be linked to the same topic, allowing you to
1011: link text in addition to the graphic. If you do not want to link
1012: text, but wish to specify one of the later parameters, pass an
1013: empty string.
1014:
1015: $stayOnPage is a value that will be interpreted as a boolean. If true,
1016: the link will not open a new window. If false, the link will open
1017: a new window using Javascript. (Default is false.)
1018:
1019: $width and $height are optional numerical parameters that will
1020: override the width and height of the popped up window, which may
1021: be useful for certain help topics with big pictures included.
1.44 bowersj2 1022:
1023: =cut
1024:
1025: sub help_open_topic {
1.48 bowersj2 1026: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1027: $text = "" if (not defined $text);
1.44 bowersj2 1028: $stayOnPage = 0 if (not defined $stayOnPage);
1029: $width = 350 if (not defined $width);
1030: $height = 400 if (not defined $height);
1031: my $filename = $topic;
1032: $filename =~ s/ /_/g;
1033:
1.48 bowersj2 1034: my $template = "";
1035: my $link;
1.572 banghart 1036:
1.159 www 1037: $topic=~s/\W/\_/g;
1.44 bowersj2 1038:
1.572 banghart 1039: if (!$stayOnPage) {
1.72 bowersj2 1040: $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 1041: } else {
1.48 bowersj2 1042: $link = "/adm/help/${filename}.hlp";
1043: }
1044:
1045: # Add the text
1.755 neumanie 1046: if ($text ne "") {
1.763 bisitz 1047: $template.='<span class="LC_help_open_topic">'
1048: .'<a target="_top" href="'.$link.'">'
1049: .$text.'</a>';
1.48 bowersj2 1050: }
1051:
1.763 bisitz 1052: # (Always) Add the graphic
1.179 matthew 1053: my $title = &mt('Online Help');
1.667 raeburn 1054: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 1055: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1056: .'<img src="'.$helpicon.'" border="0"'
1057: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 1058: .' title="'.$title.'"'
1.763 bisitz 1059: .' /></a>';
1060: if ($text ne "") {
1061: $template.='</span>';
1062: }
1.44 bowersj2 1063: return $template;
1064:
1.106 bowersj2 1065: }
1066:
1067: # This is a quicky function for Latex cheatsheet editing, since it
1068: # appears in at least four places
1069: sub helpLatexCheatsheet {
1.732 raeburn 1070: my ($topic,$text,$not_author) = @_;
1071: my $out;
1.106 bowersj2 1072: my $addOther = '';
1.732 raeburn 1073: if ($topic) {
1.763 bisitz 1074: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1075: undef, undef, 600).
1076: '</span> ';
1077: }
1078: $out = '<span>' # Start cheatsheet
1079: .$addOther
1080: .'<span>'
1081: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1082: undef,undef,600)
1083: .'</span> <span>'
1084: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1085: undef,undef,600)
1086: .'</span>';
1.732 raeburn 1087: unless ($not_author) {
1.763 bisitz 1088: $out .= ' <span>'
1089: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1090: undef,undef,600)
1091: .'</span>';
1.732 raeburn 1092: }
1.763 bisitz 1093: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1094: return $out;
1.172 www 1095: }
1096:
1.430 albertel 1097: sub general_help {
1098: my $helptopic='Student_Intro';
1099: if ($env{'request.role'}=~/^(ca|au)/) {
1100: $helptopic='Authoring_Intro';
1101: } elsif ($env{'request.role'}=~/^cc/) {
1102: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1103: } elsif ($env{'request.role'}=~/^dc/) {
1104: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1105: }
1106: return $helptopic;
1107: }
1108:
1109: sub update_help_link {
1110: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1111: my $origurl = $ENV{'REQUEST_URI'};
1112: $origurl=~s|^/~|/priv/|;
1113: my $timestamp = time;
1114: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1115: $$datum = &escape($$datum);
1116: }
1117:
1118: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1119: my $output .= <<"ENDOUTPUT";
1120: <script type="text/javascript">
1.824 bisitz 1121: // <![CDATA[
1.430 albertel 1122: banner_link = '$banner_link';
1.824 bisitz 1123: // ]]>
1.430 albertel 1124: </script>
1125: ENDOUTPUT
1126: return $output;
1127: }
1128:
1129: # now just updates the help link and generates a blue icon
1.193 raeburn 1130: sub help_open_menu {
1.430 albertel 1131: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1132: = @_;
1.430 albertel 1133: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1134: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1135: # if environment.remote is on (using remote control UI)
1.798 tempelho 1136: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1137: $stayOnPage=1;
1.430 albertel 1138: }
1139: my $output;
1140: if ($component_help) {
1141: if (!$text) {
1142: $output=&help_open_topic($component_help,undef,$stayOnPage,
1143: $width,$height);
1144: } else {
1145: my $help_text;
1146: $help_text=&unescape($topic);
1147: $output='<table><tr><td>'.
1148: &help_open_topic($component_help,$help_text,$stayOnPage,
1149: $width,$height).'</td></tr></table>';
1150: }
1151: }
1152: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1153: return $output.$banner_link;
1154: }
1155:
1156: sub top_nav_help {
1157: my ($text) = @_;
1.436 albertel 1158: $text = &mt($text);
1.572 banghart 1159: my $stay_on_page =
1.798 tempelho 1160: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1161: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1162: : "javascript:helpMenu('open')";
1.572 banghart 1163: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1164:
1.201 raeburn 1165: my $title = &mt('Get help');
1.436 albertel 1166:
1167: return <<"END";
1168: $banner_link
1169: <a href="$link" title="$title">$text</a>
1170: END
1171: }
1172:
1173: sub help_menu_js {
1174: my ($text) = @_;
1175:
1176: my $stayOnPage =
1.798 tempelho 1177: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1178:
1179: my $width = 620;
1180: my $height = 600;
1.430 albertel 1181: my $helptopic=&general_help();
1182: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1183: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1184: my $start_page =
1185: &Apache::loncommon::start_page('Help Menu', undef,
1186: {'frameset' => 1,
1187: 'js_ready' => 1,
1188: 'add_entries' => {
1189: 'border' => '0',
1.579 raeburn 1190: 'rows' => "110,*",},});
1.331 albertel 1191: my $end_page =
1192: &Apache::loncommon::end_page({'frameset' => 1,
1193: 'js_ready' => 1,});
1194:
1.436 albertel 1195: my $template .= <<"ENDTEMPLATE";
1196: <script type="text/javascript">
1.877 bisitz 1197: // <![CDATA[
1.253 albertel 1198: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1199: var banner_link = '';
1.243 raeburn 1200: function helpMenu(target) {
1201: var caller = this;
1202: if (target == 'open') {
1203: var newWindow = null;
1204: try {
1.262 albertel 1205: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1206: }
1207: catch(error) {
1208: writeHelp(caller);
1209: return;
1210: }
1211: if (newWindow) {
1212: caller = newWindow;
1213: }
1.193 raeburn 1214: }
1.243 raeburn 1215: writeHelp(caller);
1216: return;
1217: }
1218: function writeHelp(caller) {
1.430 albertel 1219: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1220: caller.document.close()
1221: caller.focus()
1.193 raeburn 1222: }
1.877 bisitz 1223: // END LON-CAPA Internal -->
1.253 albertel 1224: // ]]>
1.436 albertel 1225: </script>
1.193 raeburn 1226: ENDTEMPLATE
1227: return $template;
1228: }
1229:
1.172 www 1230: sub help_open_bug {
1231: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1232: unless ($env{'user.adv'}) { return ''; }
1.172 www 1233: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1234: $text = "" if (not defined $text);
1235: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1236: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1237: $stayOnPage=1;
1238: }
1.184 albertel 1239: $width = 600 if (not defined $width);
1240: $height = 600 if (not defined $height);
1.172 www 1241:
1242: $topic=~s/\W+/\+/g;
1243: my $link='';
1244: my $template='';
1.379 albertel 1245: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1246: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1247: if (!$stayOnPage)
1248: {
1249: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1250: }
1251: else
1252: {
1253: $link = $url;
1254: }
1255: # Add the text
1256: if ($text ne "")
1257: {
1258: $template .=
1259: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1260: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1261: }
1262:
1263: # Add the graphic
1.179 matthew 1264: my $title = &mt('Report a Bug');
1.215 albertel 1265: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1266: $template .= <<"ENDTEMPLATE";
1.436 albertel 1267: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1268: ENDTEMPLATE
1269: if ($text ne '') { $template.='</td></tr></table>' };
1270: return $template;
1271:
1272: }
1273:
1274: sub help_open_faq {
1275: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1276: unless ($env{'user.adv'}) { return ''; }
1.172 www 1277: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1278: $text = "" if (not defined $text);
1279: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1280: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1281: $stayOnPage=1;
1282: }
1283: $width = 350 if (not defined $width);
1284: $height = 400 if (not defined $height);
1285:
1286: $topic=~s/\W+/\+/g;
1287: my $link='';
1288: my $template='';
1289: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1290: if (!$stayOnPage)
1291: {
1292: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1293: }
1294: else
1295: {
1296: $link = $url;
1297: }
1298:
1299: # Add the text
1300: if ($text ne "")
1301: {
1302: $template .=
1.173 www 1303: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1304: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1305: }
1306:
1307: # Add the graphic
1.179 matthew 1308: my $title = &mt('View the FAQ');
1.215 albertel 1309: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1310: $template .= <<"ENDTEMPLATE";
1.436 albertel 1311: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1312: ENDTEMPLATE
1313: if ($text ne '') { $template.='</td></tr></table>' };
1314: return $template;
1315:
1.44 bowersj2 1316: }
1.37 matthew 1317:
1.180 matthew 1318: ###############################################################
1319: ###############################################################
1320:
1.45 matthew 1321: =pod
1322:
1.648 raeburn 1323: =item * &change_content_javascript():
1.256 matthew 1324:
1325: This and the next function allow you to create small sections of an
1326: otherwise static HTML page that you can update on the fly with
1327: Javascript, even in Netscape 4.
1328:
1329: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1330: must be written to the HTML page once. It will prove the Javascript
1331: function "change(name, content)". Calling the change function with the
1332: name of the section
1333: you want to update, matching the name passed to C<changable_area>, and
1334: the new content you want to put in there, will put the content into
1335: that area.
1336:
1337: B<Note>: Netscape 4 only reserves enough space for the changable area
1338: to contain room for the original contents. You need to "make space"
1339: for whatever changes you wish to make, and be B<sure> to check your
1340: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1341: it's adequate for updating a one-line status display, but little more.
1342: This script will set the space to 100% width, so you only need to
1343: worry about height in Netscape 4.
1344:
1345: Modern browsers are much less limiting, and if you can commit to the
1346: user not using Netscape 4, this feature may be used freely with
1347: pretty much any HTML.
1348:
1349: =cut
1350:
1351: sub change_content_javascript {
1352: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1353: if ($env{'browser.type'} eq 'netscape' &&
1354: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1355: return (<<NETSCAPE4);
1356: function change(name, content) {
1357: doc = document.layers[name+"___escape"].layers[0].document;
1358: doc.open();
1359: doc.write(content);
1360: doc.close();
1361: }
1362: NETSCAPE4
1363: } else {
1364: # Otherwise, we need to use semi-standards-compliant code
1365: # (technically, "innerHTML" isn't standard but the equivalent
1366: # is really scary, and every useful browser supports it
1367: return (<<DOMBASED);
1368: function change(name, content) {
1369: element = document.getElementById(name);
1370: element.innerHTML = content;
1371: }
1372: DOMBASED
1373: }
1374: }
1375:
1376: =pod
1377:
1.648 raeburn 1378: =item * &changable_area($name,$origContent):
1.256 matthew 1379:
1380: This provides a "changable area" that can be modified on the fly via
1381: the Javascript code provided in C<change_content_javascript>. $name is
1382: the name you will use to reference the area later; do not repeat the
1383: same name on a given HTML page more then once. $origContent is what
1384: the area will originally contain, which can be left blank.
1385:
1386: =cut
1387:
1388: sub changable_area {
1389: my ($name, $origContent) = @_;
1390:
1.258 albertel 1391: if ($env{'browser.type'} eq 'netscape' &&
1392: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1393: # If this is netscape 4, we need to use the Layer tag
1394: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1395: } else {
1396: return "<span id='$name'>$origContent</span>";
1397: }
1398: }
1399:
1400: =pod
1401:
1.648 raeburn 1402: =item * &viewport_geometry_js
1.590 raeburn 1403:
1404: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1405:
1406: =cut
1407:
1408:
1409: sub viewport_geometry_js {
1410: return <<"GEOMETRY";
1411: var Geometry = {};
1412: function init_geometry() {
1413: if (Geometry.init) { return };
1414: Geometry.init=1;
1415: if (window.innerHeight) {
1416: Geometry.getViewportHeight = function() { return window.innerHeight; };
1417: Geometry.getViewportWidth = function() { return window.innerWidth; };
1418: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1419: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1420: }
1421: else if (document.documentElement && document.documentElement.clientHeight) {
1422: Geometry.getViewportHeight =
1423: function() { return document.documentElement.clientHeight; };
1424: Geometry.getViewportWidth =
1425: function() { return document.documentElement.clientWidth; };
1426:
1427: Geometry.getHorizontalScroll =
1428: function() { return document.documentElement.scrollLeft; };
1429: Geometry.getVerticalScroll =
1430: function() { return document.documentElement.scrollTop; };
1431: }
1432: else if (document.body.clientHeight) {
1433: Geometry.getViewportHeight =
1434: function() { return document.body.clientHeight; };
1435: Geometry.getViewportWidth =
1436: function() { return document.body.clientWidth; };
1437: Geometry.getHorizontalScroll =
1438: function() { return document.body.scrollLeft; };
1439: Geometry.getVerticalScroll =
1440: function() { return document.body.scrollTop; };
1441: }
1442: }
1443:
1444: GEOMETRY
1445: }
1446:
1447: =pod
1448:
1.648 raeburn 1449: =item * &viewport_size_js()
1.590 raeburn 1450:
1451: 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.
1452:
1453: =cut
1454:
1455: sub viewport_size_js {
1456: my $geometry = &viewport_geometry_js();
1457: return <<"DIMS";
1458:
1459: $geometry
1460:
1461: function getViewportDims(width,height) {
1462: init_geometry();
1463: width.value = Geometry.getViewportWidth();
1464: height.value = Geometry.getViewportHeight();
1465: return;
1466: }
1467:
1468: DIMS
1469: }
1470:
1471: =pod
1472:
1.648 raeburn 1473: =item * &resize_textarea_js()
1.565 albertel 1474:
1475: emits the needed javascript to resize a textarea to be as big as possible
1476:
1477: creates a function resize_textrea that takes two IDs first should be
1478: the id of the element to resize, second should be the id of a div that
1479: surrounds everything that comes after the textarea, this routine needs
1480: to be attached to the <body> for the onload and onresize events.
1481:
1.648 raeburn 1482: =back
1.565 albertel 1483:
1484: =cut
1485:
1486: sub resize_textarea_js {
1.590 raeburn 1487: my $geometry = &viewport_geometry_js();
1.565 albertel 1488: return <<"RESIZE";
1489: <script type="text/javascript">
1.824 bisitz 1490: // <![CDATA[
1.590 raeburn 1491: $geometry
1.565 albertel 1492:
1.588 albertel 1493: function getX(element) {
1494: var x = 0;
1495: while (element) {
1496: x += element.offsetLeft;
1497: element = element.offsetParent;
1498: }
1499: return x;
1500: }
1501: function getY(element) {
1502: var y = 0;
1503: while (element) {
1504: y += element.offsetTop;
1505: element = element.offsetParent;
1506: }
1507: return y;
1508: }
1509:
1510:
1.565 albertel 1511: function resize_textarea(textarea_id,bottom_id) {
1512: init_geometry();
1513: var textarea = document.getElementById(textarea_id);
1514: //alert(textarea);
1515:
1.588 albertel 1516: var textarea_top = getY(textarea);
1.565 albertel 1517: var textarea_height = textarea.offsetHeight;
1518: var bottom = document.getElementById(bottom_id);
1.588 albertel 1519: var bottom_top = getY(bottom);
1.565 albertel 1520: var bottom_height = bottom.offsetHeight;
1521: var window_height = Geometry.getViewportHeight();
1.588 albertel 1522: var fudge = 23;
1.565 albertel 1523: var new_height = window_height-fudge-textarea_top-bottom_height;
1524: if (new_height < 300) {
1525: new_height = 300;
1526: }
1527: textarea.style.height=new_height+'px';
1528: }
1.824 bisitz 1529: // ]]>
1.565 albertel 1530: </script>
1531: RESIZE
1532:
1533: }
1534:
1535: =pod
1536:
1.256 matthew 1537: =head1 Excel and CSV file utility routines
1538:
1539: =over 4
1540:
1541: =cut
1542:
1543: ###############################################################
1544: ###############################################################
1545:
1546: =pod
1547:
1.648 raeburn 1548: =item * &csv_translate($text)
1.37 matthew 1549:
1.185 www 1550: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1551: format.
1552:
1553: =cut
1554:
1.180 matthew 1555: ###############################################################
1556: ###############################################################
1.37 matthew 1557: sub csv_translate {
1558: my $text = shift;
1559: $text =~ s/\"/\"\"/g;
1.209 albertel 1560: $text =~ s/\n/ /g;
1.37 matthew 1561: return $text;
1562: }
1.180 matthew 1563:
1564: ###############################################################
1565: ###############################################################
1566:
1567: =pod
1568:
1.648 raeburn 1569: =item * &define_excel_formats()
1.180 matthew 1570:
1571: Define some commonly used Excel cell formats.
1572:
1573: Currently supported formats:
1574:
1575: =over 4
1576:
1577: =item header
1578:
1579: =item bold
1580:
1581: =item h1
1582:
1583: =item h2
1584:
1585: =item h3
1586:
1.256 matthew 1587: =item h4
1588:
1589: =item i
1590:
1.180 matthew 1591: =item date
1592:
1593: =back
1594:
1595: Inputs: $workbook
1596:
1597: Returns: $format, a hash reference.
1598:
1599: =cut
1600:
1601: ###############################################################
1602: ###############################################################
1603: sub define_excel_formats {
1604: my ($workbook) = @_;
1605: my $format;
1606: $format->{'header'} = $workbook->add_format(bold => 1,
1607: bottom => 1,
1608: align => 'center');
1609: $format->{'bold'} = $workbook->add_format(bold=>1);
1610: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1611: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1612: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1613: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1614: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1615: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1616: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1617: return $format;
1618: }
1619:
1620: ###############################################################
1621: ###############################################################
1.113 bowersj2 1622:
1623: =pod
1624:
1.648 raeburn 1625: =item * &create_workbook()
1.255 matthew 1626:
1627: Create an Excel worksheet. If it fails, output message on the
1628: request object and return undefs.
1629:
1630: Inputs: Apache request object
1631:
1632: Returns (undef) on failure,
1633: Excel worksheet object, scalar with filename, and formats
1634: from &Apache::loncommon::define_excel_formats on success
1635:
1636: =cut
1637:
1638: ###############################################################
1639: ###############################################################
1640: sub create_workbook {
1641: my ($r) = @_;
1642: #
1643: # Create the excel spreadsheet
1644: my $filename = '/prtspool/'.
1.258 albertel 1645: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1646: time.'_'.rand(1000000000).'.xls';
1647: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1648: if (! defined($workbook)) {
1649: $r->log_error("Error creating excel spreadsheet $filename: $!");
1650: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1651: "This error has been logged. ".
1652: "Please alert your LON-CAPA administrator").
1653: '</p>');
1654: return (undef);
1655: }
1656: #
1657: $workbook->set_tempdir('/home/httpd/perl/tmp');
1658: #
1659: my $format = &Apache::loncommon::define_excel_formats($workbook);
1660: return ($workbook,$filename,$format);
1661: }
1662:
1663: ###############################################################
1664: ###############################################################
1665:
1666: =pod
1667:
1.648 raeburn 1668: =item * &create_text_file()
1.113 bowersj2 1669:
1.542 raeburn 1670: Create a file to write to and eventually make available to the user.
1.256 matthew 1671: If file creation fails, outputs an error message on the request object and
1672: return undefs.
1.113 bowersj2 1673:
1.256 matthew 1674: Inputs: Apache request object, and file suffix
1.113 bowersj2 1675:
1.256 matthew 1676: Returns (undef) on failure,
1677: Filehandle and filename on success.
1.113 bowersj2 1678:
1679: =cut
1680:
1.256 matthew 1681: ###############################################################
1682: ###############################################################
1683: sub create_text_file {
1684: my ($r,$suffix) = @_;
1685: if (! defined($suffix)) { $suffix = 'txt'; };
1686: my $fh;
1687: my $filename = '/prtspool/'.
1.258 albertel 1688: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1689: time.'_'.rand(1000000000).'.'.$suffix;
1690: $fh = Apache::File->new('>/home/httpd'.$filename);
1691: if (! defined($fh)) {
1692: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1693: $r->print(&mt('Problems occurred in creating the output file. '
1694: .'This error has been logged. '
1695: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1696: }
1.256 matthew 1697: return ($fh,$filename)
1.113 bowersj2 1698: }
1699:
1700:
1.256 matthew 1701: =pod
1.113 bowersj2 1702:
1703: =back
1704:
1705: =cut
1.37 matthew 1706:
1707: ###############################################################
1.33 matthew 1708: ## Home server <option> list generating code ##
1709: ###############################################################
1.35 matthew 1710:
1.169 www 1711: # ------------------------------------------
1712:
1713: sub domain_select {
1714: my ($name,$value,$multiple)=@_;
1715: my %domains=map {
1.514 albertel 1716: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1717: } &Apache::lonnet::all_domains();
1.169 www 1718: if ($multiple) {
1719: $domains{''}=&mt('Any domain');
1.550 albertel 1720: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1721: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1722: } else {
1.550 albertel 1723: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1724: return &select_form($name,$value,%domains);
1725: }
1726: }
1727:
1.282 albertel 1728: #-------------------------------------------
1729:
1730: =pod
1731:
1.519 raeburn 1732: =head1 Routines for form select boxes
1733:
1734: =over 4
1735:
1.648 raeburn 1736: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1737:
1738: Returns a string containing a <select> element int multiple mode
1739:
1740:
1741: Args:
1742: $name - name of the <select> element
1.506 raeburn 1743: $value - scalar or array ref of values that should already be selected
1.282 albertel 1744: $size - number of rows long the select element is
1.283 albertel 1745: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1746: (shown text should already have been &mt())
1.506 raeburn 1747: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1748:
1.282 albertel 1749: =cut
1750:
1751: #-------------------------------------------
1.169 www 1752: sub multiple_select_form {
1.284 albertel 1753: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1754: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1755: my $output='';
1.191 matthew 1756: if (! defined($size)) {
1757: $size = 4;
1.283 albertel 1758: if (scalar(keys(%$hash))<4) {
1759: $size = scalar(keys(%$hash));
1.191 matthew 1760: }
1761: }
1.734 bisitz 1762: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1763: my @order;
1.506 raeburn 1764: if (ref($order) eq 'ARRAY') {
1765: @order = @{$order};
1766: } else {
1767: @order = sort(keys(%$hash));
1.501 banghart 1768: }
1769: if (exists($$hash{'select_form_order'})) {
1770: @order = @{$$hash{'select_form_order'}};
1771: }
1772:
1.284 albertel 1773: foreach my $key (@order) {
1.356 albertel 1774: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1775: $output.='selected="selected" ' if ($selected{$key});
1776: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1777: }
1778: $output.="</select>\n";
1779: return $output;
1780: }
1781:
1.88 www 1782: #-------------------------------------------
1783:
1784: =pod
1785:
1.648 raeburn 1786: =item * &select_form($defdom,$name,%hash)
1.88 www 1787:
1788: Returns a string containing a <select name='$name' size='1'> form to
1789: allow a user to select options from a hash option_name => displayed text.
1790: See lonrights.pm for an example invocation and use.
1791:
1792: =cut
1793:
1794: #-------------------------------------------
1795: sub select_form {
1796: my ($def,$name,%hash) = @_;
1797: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1798: my @keys;
1799: if (exists($hash{'select_form_order'})) {
1800: @keys=@{$hash{'select_form_order'}};
1801: } else {
1802: @keys=sort(keys(%hash));
1803: }
1.356 albertel 1804: foreach my $key (@keys) {
1805: $selectform.=
1806: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1807: ($key eq $def ? 'selected="selected" ' : '').
1808: ">".&mt($hash{$key})."</option>\n";
1.88 www 1809: }
1810: $selectform.="</select>";
1811: return $selectform;
1812: }
1813:
1.475 www 1814: # For display filters
1815:
1816: sub display_filter {
1817: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1818: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1819: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1820: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1821: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1822: '</label></span> <span class="LC_nobreak">'.
1.475 www 1823: &mt('Filter [_1]',
1.477 www 1824: &select_form($env{'form.displayfilter'},
1825: 'displayfilter',
1826: ('currentfolder' => 'Current folder/page',
1827: 'containing' => 'Containing phrase',
1828: 'none' => 'None'))).
1.714 bisitz 1829: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1830: }
1831:
1.167 www 1832: sub gradeleveldescription {
1833: my $gradelevel=shift;
1834: my %gradelevels=(0 => 'Not specified',
1835: 1 => 'Grade 1',
1836: 2 => 'Grade 2',
1837: 3 => 'Grade 3',
1838: 4 => 'Grade 4',
1839: 5 => 'Grade 5',
1840: 6 => 'Grade 6',
1841: 7 => 'Grade 7',
1842: 8 => 'Grade 8',
1843: 9 => 'Grade 9',
1844: 10 => 'Grade 10',
1845: 11 => 'Grade 11',
1846: 12 => 'Grade 12',
1847: 13 => 'Grade 13',
1848: 14 => '100 Level',
1849: 15 => '200 Level',
1850: 16 => '300 Level',
1851: 17 => '400 Level',
1852: 18 => 'Graduate Level');
1853: return &mt($gradelevels{$gradelevel});
1854: }
1855:
1.163 www 1856: sub select_level_form {
1857: my ($deflevel,$name)=@_;
1858: unless ($deflevel) { $deflevel=0; }
1.167 www 1859: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1860: for (my $i=0; $i<=18; $i++) {
1861: $selectform.="<option value=\"$i\" ".
1.253 albertel 1862: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1863: ">".&gradeleveldescription($i)."</option>\n";
1864: }
1865: $selectform.="</select>";
1866: return $selectform;
1.163 www 1867: }
1.167 www 1868:
1.35 matthew 1869: #-------------------------------------------
1870:
1.45 matthew 1871: =pod
1872:
1.873 raeburn 1873: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35 matthew 1874:
1875: Returns a string containing a <select name='$name' size='1'> form to
1876: allow a user to select the domain to preform an operation in.
1877: See loncreateuser.pm for an example invocation and use.
1878:
1.90 www 1879: If the $includeempty flag is set, it also includes an empty choice ("no domain
1880: selected");
1881:
1.743 raeburn 1882: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1883:
1.872 raeburn 1884: The optional $onchange argumnet specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
1.563 raeburn 1885:
1.35 matthew 1886: =cut
1887:
1888: #-------------------------------------------
1.34 matthew 1889: sub select_dom_form {
1.872 raeburn 1890: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
1891: if ($onchange) {
1.874 raeburn 1892: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1893: }
1.550 albertel 1894: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1895: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1896: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1897: foreach my $dom (@domains) {
1898: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1899: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1900: if ($showdomdesc) {
1901: if ($dom ne '') {
1902: my $domdesc = &Apache::lonnet::domain($dom,'description');
1903: if ($domdesc ne '') {
1904: $selectdomain .= ' ('.$domdesc.')';
1905: }
1906: }
1907: }
1908: $selectdomain .= "</option>\n";
1.34 matthew 1909: }
1910: $selectdomain.="</select>";
1911: return $selectdomain;
1912: }
1913:
1.35 matthew 1914: #-------------------------------------------
1915:
1.45 matthew 1916: =pod
1917:
1.648 raeburn 1918: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1919:
1.586 raeburn 1920: input: 4 arguments (two required, two optional) -
1921: $domain - domain of new user
1922: $name - name of form element
1923: $default - Value of 'default' causes a default item to be first
1924: option, and selected by default.
1925: $hide - Value of 'hide' causes hiding of the name of the server,
1926: if 1 server found, or default, if 0 found.
1.594 raeburn 1927: output: returns 2 items:
1.586 raeburn 1928: (a) form element which contains either:
1929: (i) <select name="$name">
1930: <option value="$hostid1">$hostid $servers{$hostid}</option>
1931: <option value="$hostid2">$hostid $servers{$hostid}</option>
1932: </select>
1933: form item if there are multiple library servers in $domain, or
1934: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1935: if there is only one library server in $domain.
1936:
1937: (b) number of library servers found.
1938:
1939: See loncreateuser.pm for example of use.
1.35 matthew 1940:
1941: =cut
1942:
1943: #-------------------------------------------
1.586 raeburn 1944: sub home_server_form_item {
1945: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1946: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1947: my $result;
1948: my $numlib = keys(%servers);
1949: if ($numlib > 1) {
1950: $result .= '<select name="'.$name.'" />'."\n";
1951: if ($default) {
1.804 bisitz 1952: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1953: '</option>'."\n";
1954: }
1955: foreach my $hostid (sort(keys(%servers))) {
1956: $result.= '<option value="'.$hostid.'">'.
1957: $hostid.' '.$servers{$hostid}."</option>\n";
1958: }
1959: $result .= '</select>'."\n";
1960: } elsif ($numlib == 1) {
1961: my $hostid;
1962: foreach my $item (keys(%servers)) {
1963: $hostid = $item;
1964: }
1965: $result .= '<input type="hidden" name="'.$name.'" value="'.
1966: $hostid.'" />';
1967: if (!$hide) {
1968: $result .= $hostid.' '.$servers{$hostid};
1969: }
1970: $result .= "\n";
1971: } elsif ($default) {
1972: $result .= '<input type="hidden" name="'.$name.
1973: '" value="default" />';
1974: if (!$hide) {
1975: $result .= &mt('default');
1976: }
1977: $result .= "\n";
1.33 matthew 1978: }
1.586 raeburn 1979: return ($result,$numlib);
1.33 matthew 1980: }
1.112 bowersj2 1981:
1982: =pod
1983:
1.534 albertel 1984: =back
1985:
1.112 bowersj2 1986: =cut
1.87 matthew 1987:
1988: ###############################################################
1.112 bowersj2 1989: ## Decoding User Agent ##
1.87 matthew 1990: ###############################################################
1991:
1992: =pod
1993:
1.112 bowersj2 1994: =head1 Decoding the User Agent
1995:
1996: =over 4
1997:
1998: =item * &decode_user_agent()
1.87 matthew 1999:
2000: Inputs: $r
2001:
2002: Outputs:
2003:
2004: =over 4
2005:
1.112 bowersj2 2006: =item * $httpbrowser
1.87 matthew 2007:
1.112 bowersj2 2008: =item * $clientbrowser
1.87 matthew 2009:
1.112 bowersj2 2010: =item * $clientversion
1.87 matthew 2011:
1.112 bowersj2 2012: =item * $clientmathml
1.87 matthew 2013:
1.112 bowersj2 2014: =item * $clientunicode
1.87 matthew 2015:
1.112 bowersj2 2016: =item * $clientos
1.87 matthew 2017:
2018: =back
2019:
1.157 matthew 2020: =back
2021:
1.87 matthew 2022: =cut
2023:
2024: ###############################################################
2025: ###############################################################
2026: sub decode_user_agent {
1.247 albertel 2027: my ($r)=@_;
1.87 matthew 2028: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2029: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2030: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2031: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2032: my $clientbrowser='unknown';
2033: my $clientversion='0';
2034: my $clientmathml='';
2035: my $clientunicode='0';
2036: for (my $i=0;$i<=$#browsertype;$i++) {
2037: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2038: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2039: $clientbrowser=$bname;
2040: $httpbrowser=~/$vreg/i;
2041: $clientversion=$1;
2042: $clientmathml=($clientversion>=$minv);
2043: $clientunicode=($clientversion>=$univ);
2044: }
2045: }
2046: my $clientos='unknown';
2047: if (($httpbrowser=~/linux/i) ||
2048: ($httpbrowser=~/unix/i) ||
2049: ($httpbrowser=~/ux/i) ||
2050: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2051: if (($httpbrowser=~/vax/i) ||
2052: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2053: if ($httpbrowser=~/next/i) { $clientos='next'; }
2054: if (($httpbrowser=~/mac/i) ||
2055: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2056: if ($httpbrowser=~/win/i) { $clientos='win'; }
2057: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2058: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2059: $clientunicode,$clientos,);
2060: }
2061:
1.32 matthew 2062: ###############################################################
2063: ## Authentication changing form generation subroutines ##
2064: ###############################################################
2065: ##
2066: ## All of the authform_xxxxxxx subroutines take their inputs in a
2067: ## hash, and have reasonable default values.
2068: ##
2069: ## formname = the name given in the <form> tag.
1.35 matthew 2070: #-------------------------------------------
2071:
1.45 matthew 2072: =pod
2073:
1.112 bowersj2 2074: =head1 Authentication Routines
2075:
2076: =over 4
2077:
1.648 raeburn 2078: =item * &authform_xxxxxx()
1.35 matthew 2079:
2080: The authform_xxxxxx subroutines provide javascript and html forms which
2081: handle some of the conveniences required for authentication forms.
2082: This is not an optimal method, but it works.
2083:
2084: =over 4
2085:
1.112 bowersj2 2086: =item * authform_header
1.35 matthew 2087:
1.112 bowersj2 2088: =item * authform_authorwarning
1.35 matthew 2089:
1.112 bowersj2 2090: =item * authform_nochange
1.35 matthew 2091:
1.112 bowersj2 2092: =item * authform_kerberos
1.35 matthew 2093:
1.112 bowersj2 2094: =item * authform_internal
1.35 matthew 2095:
1.112 bowersj2 2096: =item * authform_filesystem
1.35 matthew 2097:
2098: =back
2099:
1.648 raeburn 2100: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2101:
1.35 matthew 2102: =cut
2103:
2104: #-------------------------------------------
1.32 matthew 2105: sub authform_header{
2106: my %in = (
2107: formname => 'cu',
1.80 albertel 2108: kerb_def_dom => '',
1.32 matthew 2109: @_,
2110: );
2111: $in{'formname'} = 'document.' . $in{'formname'};
2112: my $result='';
1.80 albertel 2113:
2114: #---------------------------------------------- Code for upper case translation
2115: my $Javascript_toUpperCase;
2116: unless ($in{kerb_def_dom}) {
2117: $Javascript_toUpperCase =<<"END";
2118: switch (choice) {
2119: case 'krb': currentform.elements[choicearg].value =
2120: currentform.elements[choicearg].value.toUpperCase();
2121: break;
2122: default:
2123: }
2124: END
2125: } else {
2126: $Javascript_toUpperCase = "";
2127: }
2128:
1.165 raeburn 2129: my $radioval = "'nochange'";
1.591 raeburn 2130: if (defined($in{'curr_authtype'})) {
2131: if ($in{'curr_authtype'} ne '') {
2132: $radioval = "'".$in{'curr_authtype'}."arg'";
2133: }
1.174 matthew 2134: }
1.165 raeburn 2135: my $argfield = 'null';
1.591 raeburn 2136: if (defined($in{'mode'})) {
1.165 raeburn 2137: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2138: if (defined($in{'curr_autharg'})) {
2139: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2140: $argfield = "'$in{'curr_autharg'}'";
2141: }
2142: }
2143: }
2144: }
2145:
1.32 matthew 2146: $result.=<<"END";
2147: var current = new Object();
1.165 raeburn 2148: current.radiovalue = $radioval;
2149: current.argfield = $argfield;
1.32 matthew 2150:
2151: function changed_radio(choice,currentform) {
2152: var choicearg = choice + 'arg';
2153: // If a radio button in changed, we need to change the argfield
2154: if (current.radiovalue != choice) {
2155: current.radiovalue = choice;
2156: if (current.argfield != null) {
2157: currentform.elements[current.argfield].value = '';
2158: }
2159: if (choice == 'nochange') {
2160: current.argfield = null;
2161: } else {
2162: current.argfield = choicearg;
2163: switch(choice) {
2164: case 'krb':
2165: currentform.elements[current.argfield].value =
2166: "$in{'kerb_def_dom'}";
2167: break;
2168: default:
2169: break;
2170: }
2171: }
2172: }
2173: return;
2174: }
1.22 www 2175:
1.32 matthew 2176: function changed_text(choice,currentform) {
2177: var choicearg = choice + 'arg';
2178: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2179: $Javascript_toUpperCase
1.32 matthew 2180: // clear old field
2181: if ((current.argfield != choicearg) && (current.argfield != null)) {
2182: currentform.elements[current.argfield].value = '';
2183: }
2184: current.argfield = choicearg;
2185: }
2186: set_auth_radio_buttons(choice,currentform);
2187: return;
1.20 www 2188: }
1.32 matthew 2189:
2190: function set_auth_radio_buttons(newvalue,currentform) {
2191: var i=0;
2192: while (i < currentform.login.length) {
2193: if (currentform.login[i].value == newvalue) { break; }
2194: i++;
2195: }
2196: if (i == currentform.login.length) {
2197: return;
2198: }
2199: current.radiovalue = newvalue;
2200: currentform.login[i].checked = true;
2201: return;
2202: }
2203: END
2204: return $result;
2205: }
2206:
2207: sub authform_authorwarning{
2208: my $result='';
1.144 matthew 2209: $result='<i>'.
2210: &mt('As a general rule, only authors or co-authors should be '.
2211: 'filesystem authenticated '.
2212: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2213: return $result;
2214: }
2215:
2216: sub authform_nochange{
2217: my %in = (
2218: formname => 'document.cu',
2219: kerb_def_dom => 'MSU.EDU',
2220: @_,
2221: );
1.586 raeburn 2222: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2223: my $result;
2224: if (keys(%can_assign) == 0) {
2225: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2226: } else {
2227: $result = '<label>'.&mt('[_1] Do not change login data',
2228: '<input type="radio" name="login" value="nochange" '.
2229: 'checked="checked" onclick="'.
1.281 albertel 2230: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2231: '</label>';
1.586 raeburn 2232: }
1.32 matthew 2233: return $result;
2234: }
2235:
1.591 raeburn 2236: sub authform_kerberos {
1.32 matthew 2237: my %in = (
2238: formname => 'document.cu',
2239: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2240: kerb_def_auth => 'krb4',
1.32 matthew 2241: @_,
2242: );
1.586 raeburn 2243: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2244: $autharg,$jscall);
2245: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2246: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2247: $check5 = ' checked="checked"';
1.80 albertel 2248: } else {
1.772 bisitz 2249: $check4 = ' checked="checked"';
1.80 albertel 2250: }
1.165 raeburn 2251: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2252: if (defined($in{'curr_authtype'})) {
2253: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2254: $krbcheck = ' checked="checked"';
1.623 raeburn 2255: if (defined($in{'mode'})) {
2256: if ($in{'mode'} eq 'modifyuser') {
2257: $krbcheck = '';
2258: }
2259: }
1.591 raeburn 2260: if (defined($in{'curr_kerb_ver'})) {
2261: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2262: $check5 = ' checked="checked"';
1.591 raeburn 2263: $check4 = '';
2264: } else {
1.772 bisitz 2265: $check4 = ' checked="checked"';
1.591 raeburn 2266: $check5 = '';
2267: }
1.586 raeburn 2268: }
1.591 raeburn 2269: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2270: $krbarg = $in{'curr_autharg'};
2271: }
1.586 raeburn 2272: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2273: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2274: $result =
2275: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2276: $in{'curr_autharg'},$krbver);
2277: } else {
2278: $result =
2279: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2280: }
2281: return $result;
2282: }
2283: }
2284: } else {
2285: if ($authnum == 1) {
1.784 bisitz 2286: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2287: }
2288: }
1.586 raeburn 2289: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2290: return;
1.587 raeburn 2291: } elsif ($authtype eq '') {
1.591 raeburn 2292: if (defined($in{'mode'})) {
1.587 raeburn 2293: if ($in{'mode'} eq 'modifycourse') {
2294: if ($authnum == 1) {
1.784 bisitz 2295: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2296: }
2297: }
2298: }
1.586 raeburn 2299: }
2300: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2301: if ($authtype eq '') {
2302: $authtype = '<input type="radio" name="login" value="krb" '.
2303: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2304: $krbcheck.' />';
2305: }
2306: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2307: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2308: $in{'curr_authtype'} eq 'krb5') ||
2309: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2310: $in{'curr_authtype'} eq 'krb4')) {
2311: $result .= &mt
1.144 matthew 2312: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2313: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2314: '<label>'.$authtype,
1.281 albertel 2315: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2316: 'value="'.$krbarg.'" '.
1.144 matthew 2317: 'onchange="'.$jscall.'" />',
1.281 albertel 2318: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2319: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2320: '</label>');
1.586 raeburn 2321: } elsif ($can_assign{'krb4'}) {
2322: $result .= &mt
2323: ('[_1] Kerberos authenticated with domain [_2] '.
2324: '[_3] Version 4 [_4]',
2325: '<label>'.$authtype,
2326: '</label><input type="text" size="10" name="krbarg" '.
2327: 'value="'.$krbarg.'" '.
2328: 'onchange="'.$jscall.'" />',
2329: '<label><input type="hidden" name="krbver" value="4" />',
2330: '</label>');
2331: } elsif ($can_assign{'krb5'}) {
2332: $result .= &mt
2333: ('[_1] Kerberos authenticated with domain [_2] '.
2334: '[_3] Version 5 [_4]',
2335: '<label>'.$authtype,
2336: '</label><input type="text" size="10" name="krbarg" '.
2337: 'value="'.$krbarg.'" '.
2338: 'onchange="'.$jscall.'" />',
2339: '<label><input type="hidden" name="krbver" value="5" />',
2340: '</label>');
2341: }
1.32 matthew 2342: return $result;
2343: }
2344:
2345: sub authform_internal{
1.586 raeburn 2346: my %in = (
1.32 matthew 2347: formname => 'document.cu',
2348: kerb_def_dom => 'MSU.EDU',
2349: @_,
2350: );
1.586 raeburn 2351: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2352: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2353: if (defined($in{'curr_authtype'})) {
2354: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2355: if ($can_assign{'int'}) {
1.772 bisitz 2356: $intcheck = 'checked="checked" ';
1.623 raeburn 2357: if (defined($in{'mode'})) {
2358: if ($in{'mode'} eq 'modifyuser') {
2359: $intcheck = '';
2360: }
2361: }
1.591 raeburn 2362: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2363: $intarg = $in{'curr_autharg'};
2364: }
2365: } else {
2366: $result = &mt('Currently internally authenticated.');
2367: return $result;
1.165 raeburn 2368: }
2369: }
1.586 raeburn 2370: } else {
2371: if ($authnum == 1) {
1.784 bisitz 2372: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2373: }
2374: }
2375: if (!$can_assign{'int'}) {
2376: return;
1.587 raeburn 2377: } elsif ($authtype eq '') {
1.591 raeburn 2378: if (defined($in{'mode'})) {
1.587 raeburn 2379: if ($in{'mode'} eq 'modifycourse') {
2380: if ($authnum == 1) {
1.784 bisitz 2381: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2382: }
2383: }
2384: }
1.165 raeburn 2385: }
1.586 raeburn 2386: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2387: if ($authtype eq '') {
2388: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2389: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2390: }
1.605 bisitz 2391: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2392: $intarg.'" onchange="'.$jscall.'" />';
2393: $result = &mt
1.144 matthew 2394: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2395: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2396: $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 2397: return $result;
2398: }
2399:
2400: sub authform_local{
2401: my %in = (
2402: formname => 'document.cu',
2403: kerb_def_dom => 'MSU.EDU',
2404: @_,
2405: );
1.586 raeburn 2406: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2407: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2408: if (defined($in{'curr_authtype'})) {
2409: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2410: if ($can_assign{'loc'}) {
1.772 bisitz 2411: $loccheck = 'checked="checked" ';
1.623 raeburn 2412: if (defined($in{'mode'})) {
2413: if ($in{'mode'} eq 'modifyuser') {
2414: $loccheck = '';
2415: }
2416: }
1.591 raeburn 2417: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2418: $locarg = $in{'curr_autharg'};
2419: }
2420: } else {
2421: $result = &mt('Currently using local (institutional) authentication.');
2422: return $result;
1.165 raeburn 2423: }
2424: }
1.586 raeburn 2425: } else {
2426: if ($authnum == 1) {
1.784 bisitz 2427: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2428: }
2429: }
2430: if (!$can_assign{'loc'}) {
2431: return;
1.587 raeburn 2432: } elsif ($authtype eq '') {
1.591 raeburn 2433: if (defined($in{'mode'})) {
1.587 raeburn 2434: if ($in{'mode'} eq 'modifycourse') {
2435: if ($authnum == 1) {
1.784 bisitz 2436: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2437: }
2438: }
2439: }
1.165 raeburn 2440: }
1.586 raeburn 2441: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2442: if ($authtype eq '') {
2443: $authtype = '<input type="radio" name="login" value="loc" '.
2444: $loccheck.' onchange="'.$jscall.'" onclick="'.
2445: $jscall.'" />';
2446: }
2447: $autharg = '<input type="text" size="10" name="locarg" value="'.
2448: $locarg.'" onchange="'.$jscall.'" />';
2449: $result = &mt('[_1] Local Authentication with argument [_2]',
2450: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2451: return $result;
2452: }
2453:
2454: sub authform_filesystem{
2455: my %in = (
2456: formname => 'document.cu',
2457: kerb_def_dom => 'MSU.EDU',
2458: @_,
2459: );
1.586 raeburn 2460: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2461: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2462: if (defined($in{'curr_authtype'})) {
2463: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2464: if ($can_assign{'fsys'}) {
1.772 bisitz 2465: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2466: if (defined($in{'mode'})) {
2467: if ($in{'mode'} eq 'modifyuser') {
2468: $fsyscheck = '';
2469: }
2470: }
1.586 raeburn 2471: } else {
2472: $result = &mt('Currently Filesystem Authenticated.');
2473: return $result;
2474: }
2475: }
2476: } else {
2477: if ($authnum == 1) {
1.784 bisitz 2478: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2479: }
2480: }
2481: if (!$can_assign{'fsys'}) {
2482: return;
1.587 raeburn 2483: } elsif ($authtype eq '') {
1.591 raeburn 2484: if (defined($in{'mode'})) {
1.587 raeburn 2485: if ($in{'mode'} eq 'modifycourse') {
2486: if ($authnum == 1) {
1.784 bisitz 2487: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2488: }
2489: }
2490: }
1.586 raeburn 2491: }
2492: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2493: if ($authtype eq '') {
2494: $authtype = '<input type="radio" name="login" value="fsys" '.
2495: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2496: $jscall.'" />';
2497: }
2498: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2499: ' onchange="'.$jscall.'" />';
2500: $result = &mt
1.144 matthew 2501: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2502: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2503: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2504: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2505: 'onchange="'.$jscall.'" />');
1.32 matthew 2506: return $result;
2507: }
2508:
1.586 raeburn 2509: sub get_assignable_auth {
2510: my ($dom) = @_;
2511: if ($dom eq '') {
2512: $dom = $env{'request.role.domain'};
2513: }
2514: my %can_assign = (
2515: krb4 => 1,
2516: krb5 => 1,
2517: int => 1,
2518: loc => 1,
2519: );
2520: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2521: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2522: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2523: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2524: my $context;
2525: if ($env{'request.role'} =~ /^au/) {
2526: $context = 'author';
2527: } elsif ($env{'request.role'} =~ /^dc/) {
2528: $context = 'domain';
2529: } elsif ($env{'request.course.id'}) {
2530: $context = 'course';
2531: }
2532: if ($context) {
2533: if (ref($authhash->{$context}) eq 'HASH') {
2534: %can_assign = %{$authhash->{$context}};
2535: }
2536: }
2537: }
2538: }
2539: my $authnum = 0;
2540: foreach my $key (keys(%can_assign)) {
2541: if ($can_assign{$key}) {
2542: $authnum ++;
2543: }
2544: }
2545: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2546: $authnum --;
2547: }
2548: return ($authnum,%can_assign);
2549: }
2550:
1.80 albertel 2551: ###############################################################
2552: ## Get Kerberos Defaults for Domain ##
2553: ###############################################################
2554: ##
2555: ## Returns default kerberos version and an associated argument
2556: ## as listed in file domain.tab. If not listed, provides
2557: ## appropriate default domain and kerberos version.
2558: ##
2559: #-------------------------------------------
2560:
2561: =pod
2562:
1.648 raeburn 2563: =item * &get_kerberos_defaults()
1.80 albertel 2564:
2565: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2566: version and domain. If not found, it defaults to version 4 and the
2567: domain of the server.
1.80 albertel 2568:
1.648 raeburn 2569: =over 4
2570:
1.80 albertel 2571: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2572:
1.648 raeburn 2573: =back
2574:
2575: =back
2576:
1.80 albertel 2577: =cut
2578:
2579: #-------------------------------------------
2580: sub get_kerberos_defaults {
2581: my $domain=shift;
1.641 raeburn 2582: my ($krbdef,$krbdefdom);
2583: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2584: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2585: $krbdef = $domdefaults{'auth_def'};
2586: $krbdefdom = $domdefaults{'auth_arg_def'};
2587: } else {
1.80 albertel 2588: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2589: my $krbdefdom=$1;
2590: $krbdefdom=~tr/a-z/A-Z/;
2591: $krbdef = "krb4";
2592: }
2593: return ($krbdef,$krbdefdom);
2594: }
1.112 bowersj2 2595:
1.32 matthew 2596:
1.46 matthew 2597: ###############################################################
2598: ## Thesaurus Functions ##
2599: ###############################################################
1.20 www 2600:
1.46 matthew 2601: =pod
1.20 www 2602:
1.112 bowersj2 2603: =head1 Thesaurus Functions
2604:
2605: =over 4
2606:
1.648 raeburn 2607: =item * &initialize_keywords()
1.46 matthew 2608:
2609: Initializes the package variable %Keywords if it is empty. Uses the
2610: package variable $thesaurus_db_file.
2611:
2612: =cut
2613:
2614: ###################################################
2615:
2616: sub initialize_keywords {
2617: return 1 if (scalar keys(%Keywords));
2618: # If we are here, %Keywords is empty, so fill it up
2619: # Make sure the file we need exists...
2620: if (! -e $thesaurus_db_file) {
2621: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2622: " failed because it does not exist");
2623: return 0;
2624: }
2625: # Set up the hash as a database
2626: my %thesaurus_db;
2627: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2628: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2629: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2630: $thesaurus_db_file);
2631: return 0;
2632: }
2633: # Get the average number of appearances of a word.
2634: my $avecount = $thesaurus_db{'average.count'};
2635: # Put keywords (those that appear > average) into %Keywords
2636: while (my ($word,$data)=each (%thesaurus_db)) {
2637: my ($count,undef) = split /:/,$data;
2638: $Keywords{$word}++ if ($count > $avecount);
2639: }
2640: untie %thesaurus_db;
2641: # Remove special values from %Keywords.
1.356 albertel 2642: foreach my $value ('total.count','average.count') {
2643: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2644: }
1.46 matthew 2645: return 1;
2646: }
2647:
2648: ###################################################
2649:
2650: =pod
2651:
1.648 raeburn 2652: =item * &keyword($word)
1.46 matthew 2653:
2654: Returns true if $word is a keyword. A keyword is a word that appears more
2655: than the average number of times in the thesaurus database. Calls
2656: &initialize_keywords
2657:
2658: =cut
2659:
2660: ###################################################
1.20 www 2661:
2662: sub keyword {
1.46 matthew 2663: return if (!&initialize_keywords());
2664: my $word=lc(shift());
2665: $word=~s/\W//g;
2666: return exists($Keywords{$word});
1.20 www 2667: }
1.46 matthew 2668:
2669: ###############################################################
2670:
2671: =pod
1.20 www 2672:
1.648 raeburn 2673: =item * &get_related_words()
1.46 matthew 2674:
1.160 matthew 2675: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2676: an array of words. If the keyword is not in the thesaurus, an empty array
2677: will be returned. The order of the words returned is determined by the
2678: database which holds them.
2679:
2680: Uses global $thesaurus_db_file.
2681:
2682: =cut
2683:
2684: ###############################################################
2685: sub get_related_words {
2686: my $keyword = shift;
2687: my %thesaurus_db;
2688: if (! -e $thesaurus_db_file) {
2689: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2690: "failed because the file does not exist");
2691: return ();
2692: }
2693: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2694: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2695: return ();
2696: }
2697: my @Words=();
1.429 www 2698: my $count=0;
1.46 matthew 2699: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2700: # The first element is the number of times
2701: # the word appears. We do not need it now.
1.429 www 2702: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2703: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2704: my $threshold=$mostfrequentcount/10;
2705: foreach my $possibleword (@RelatedWords) {
2706: my ($word,$wordcount)=split(/\,/,$possibleword);
2707: if ($wordcount>$threshold) {
2708: push(@Words,$word);
2709: $count++;
2710: if ($count>10) { last; }
2711: }
1.20 www 2712: }
2713: }
1.46 matthew 2714: untie %thesaurus_db;
2715: return @Words;
1.14 harris41 2716: }
1.46 matthew 2717:
1.112 bowersj2 2718: =pod
2719:
2720: =back
2721:
2722: =cut
1.61 www 2723:
2724: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2725: =pod
2726:
1.112 bowersj2 2727: =head1 User Name Functions
2728:
2729: =over 4
2730:
1.648 raeburn 2731: =item * &plainname($uname,$udom,$first)
1.81 albertel 2732:
1.112 bowersj2 2733: Takes a users logon name and returns it as a string in
1.226 albertel 2734: "first middle last generation" form
2735: if $first is set to 'lastname' then it returns it as
2736: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2737:
2738: =cut
1.61 www 2739:
1.295 www 2740:
1.81 albertel 2741: ###############################################################
1.61 www 2742: sub plainname {
1.226 albertel 2743: my ($uname,$udom,$first)=@_;
1.537 albertel 2744: return if (!defined($uname) || !defined($udom));
1.295 www 2745: my %names=&getnames($uname,$udom);
1.226 albertel 2746: my $name=&Apache::lonnet::format_name($names{'firstname'},
2747: $names{'middlename'},
2748: $names{'lastname'},
2749: $names{'generation'},$first);
2750: $name=~s/^\s+//;
1.62 www 2751: $name=~s/\s+$//;
2752: $name=~s/\s+/ /g;
1.353 albertel 2753: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2754: return $name;
1.61 www 2755: }
1.66 www 2756:
2757: # -------------------------------------------------------------------- Nickname
1.81 albertel 2758: =pod
2759:
1.648 raeburn 2760: =item * &nickname($uname,$udom)
1.81 albertel 2761:
2762: Gets a users name and returns it as a string as
2763:
2764: ""nickname""
1.66 www 2765:
1.81 albertel 2766: if the user has a nickname or
2767:
2768: "first middle last generation"
2769:
2770: if the user does not
2771:
2772: =cut
1.66 www 2773:
2774: sub nickname {
2775: my ($uname,$udom)=@_;
1.537 albertel 2776: return if (!defined($uname) || !defined($udom));
1.295 www 2777: my %names=&getnames($uname,$udom);
1.68 albertel 2778: my $name=$names{'nickname'};
1.66 www 2779: if ($name) {
2780: $name='"'.$name.'"';
2781: } else {
2782: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2783: $names{'lastname'}.' '.$names{'generation'};
2784: $name=~s/\s+$//;
2785: $name=~s/\s+/ /g;
2786: }
2787: return $name;
2788: }
2789:
1.295 www 2790: sub getnames {
2791: my ($uname,$udom)=@_;
1.537 albertel 2792: return if (!defined($uname) || !defined($udom));
1.433 albertel 2793: if ($udom eq 'public' && $uname eq 'public') {
2794: return ('lastname' => &mt('Public'));
2795: }
1.295 www 2796: my $id=$uname.':'.$udom;
2797: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2798: if ($cached) {
2799: return %{$names};
2800: } else {
2801: my %loadnames=&Apache::lonnet::get('environment',
2802: ['firstname','middlename','lastname','generation','nickname'],
2803: $udom,$uname);
2804: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2805: return %loadnames;
2806: }
2807: }
1.61 www 2808:
1.542 raeburn 2809: # -------------------------------------------------------------------- getemails
1.648 raeburn 2810:
1.542 raeburn 2811: =pod
2812:
1.648 raeburn 2813: =item * &getemails($uname,$udom)
1.542 raeburn 2814:
2815: Gets a user's email information and returns it as a hash with keys:
2816: notification, critnotification, permanentemail
2817:
2818: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2819: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2820:
1.648 raeburn 2821:
1.542 raeburn 2822: =cut
2823:
1.648 raeburn 2824:
1.466 albertel 2825: sub getemails {
2826: my ($uname,$udom)=@_;
2827: if ($udom eq 'public' && $uname eq 'public') {
2828: return;
2829: }
1.467 www 2830: if (!$udom) { $udom=$env{'user.domain'}; }
2831: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2832: my $id=$uname.':'.$udom;
2833: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2834: if ($cached) {
2835: return %{$names};
2836: } else {
2837: my %loadnames=&Apache::lonnet::get('environment',
2838: ['notification','critnotification',
2839: 'permanentemail'],
2840: $udom,$uname);
2841: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2842: return %loadnames;
2843: }
2844: }
2845:
1.551 albertel 2846: sub flush_email_cache {
2847: my ($uname,$udom)=@_;
2848: if (!$udom) { $udom =$env{'user.domain'}; }
2849: if (!$uname) { $uname=$env{'user.name'}; }
2850: return if ($udom eq 'public' && $uname eq 'public');
2851: my $id=$uname.':'.$udom;
2852: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2853: }
2854:
1.728 raeburn 2855: # -------------------------------------------------------------------- getlangs
2856:
2857: =pod
2858:
2859: =item * &getlangs($uname,$udom)
2860:
2861: Gets a user's language preference and returns it as a hash with key:
2862: language.
2863:
2864: =cut
2865:
2866:
2867: sub getlangs {
2868: my ($uname,$udom) = @_;
2869: if (!$udom) { $udom =$env{'user.domain'}; }
2870: if (!$uname) { $uname=$env{'user.name'}; }
2871: my $id=$uname.':'.$udom;
2872: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2873: if ($cached) {
2874: return %{$langs};
2875: } else {
2876: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2877: $udom,$uname);
2878: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2879: return %loadlangs;
2880: }
2881: }
2882:
2883: sub flush_langs_cache {
2884: my ($uname,$udom)=@_;
2885: if (!$udom) { $udom =$env{'user.domain'}; }
2886: if (!$uname) { $uname=$env{'user.name'}; }
2887: return if ($udom eq 'public' && $uname eq 'public');
2888: my $id=$uname.':'.$udom;
2889: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2890: }
2891:
1.61 www 2892: # ------------------------------------------------------------------ Screenname
1.81 albertel 2893:
2894: =pod
2895:
1.648 raeburn 2896: =item * &screenname($uname,$udom)
1.81 albertel 2897:
2898: Gets a users screenname and returns it as a string
2899:
2900: =cut
1.61 www 2901:
2902: sub screenname {
2903: my ($uname,$udom)=@_;
1.258 albertel 2904: if ($uname eq $env{'user.name'} &&
2905: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2906: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2907: return $names{'screenname'};
1.62 www 2908: }
2909:
1.212 albertel 2910:
1.802 bisitz 2911: # ------------------------------------------------------------- Confirm Wrapper
2912: =pod
2913:
2914: =item confirmwrapper
2915:
2916: Wrap messages about completion of operation in box
2917:
2918: =cut
2919:
2920: sub confirmwrapper {
2921: my ($message)=@_;
2922: if ($message) {
2923: return "\n".'<div class="LC_confirm_box">'."\n"
2924: .$message."\n"
2925: .'</div>'."\n";
2926: } else {
2927: return $message;
2928: }
2929: }
2930:
1.62 www 2931: # ------------------------------------------------------------- Message Wrapper
2932:
2933: sub messagewrapper {
1.369 www 2934: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2935: return
1.441 albertel 2936: '<a href="/adm/email?compose=individual&'.
2937: 'recname='.$username.'&recdom='.$domain.
2938: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2939: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2940: }
1.802 bisitz 2941:
1.74 www 2942: # --------------------------------------------------------------- Notes Wrapper
2943:
2944: sub noteswrapper {
2945: my ($link,$un,$do)=@_;
2946: return
2947: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2948: }
1.802 bisitz 2949:
1.62 www 2950: # ------------------------------------------------------------- Aboutme Wrapper
2951:
2952: sub aboutmewrapper {
1.166 www 2953: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2954: if (!defined($username) && !defined($domain)) {
2955: return;
2956: }
1.205 www 2957: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2958: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2959: }
2960:
2961: # ------------------------------------------------------------ Syllabus Wrapper
2962:
2963: sub syllabuswrapper {
1.707 bisitz 2964: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2965: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2966: }
1.14 harris41 2967:
1.802 bisitz 2968: # -----------------------------------------------------------------------------
2969:
1.208 matthew 2970: sub track_student_link {
1.268 albertel 2971: my ($linktext,$sname,$sdom,$target,$start) = @_;
2972: my $link ="/adm/trackstudent?";
1.208 matthew 2973: my $title = 'View recent activity';
2974: if (defined($sname) && $sname !~ /^\s*$/ &&
2975: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2976: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2977: $title .= ' of this student';
1.268 albertel 2978: }
1.208 matthew 2979: if (defined($target) && $target !~ /^\s*$/) {
2980: $target = qq{target="$target"};
2981: } else {
2982: $target = '';
2983: }
1.268 albertel 2984: if ($start) { $link.='&start='.$start; }
1.554 albertel 2985: $title = &mt($title);
2986: $linktext = &mt($linktext);
1.448 albertel 2987: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2988: &help_open_topic('View_recent_activity');
1.208 matthew 2989: }
2990:
1.781 raeburn 2991: sub slot_reservations_link {
2992: my ($linktext,$sname,$sdom,$target) = @_;
2993: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2994: my $title = 'View slot reservation history';
2995: if (defined($sname) && $sname !~ /^\s*$/ &&
2996: defined($sdom) && $sdom !~ /^\s*$/) {
2997: $link .= "&uname=$sname&udom=$sdom";
2998: $title .= ' of this student';
2999: }
3000: if (defined($target) && $target !~ /^\s*$/) {
3001: $target = qq{target="$target"};
3002: } else {
3003: $target = '';
3004: }
3005: $title = &mt($title);
3006: $linktext = &mt($linktext);
3007: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3008: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3009:
3010: }
3011:
1.508 www 3012: # ===================================================== Display a student photo
3013:
3014:
1.509 albertel 3015: sub student_image_tag {
1.508 www 3016: my ($domain,$user)=@_;
3017: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3018: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3019: return '<img src="'.$imgsrc.'" align="right" />';
3020: } else {
3021: return '';
3022: }
3023: }
3024:
1.112 bowersj2 3025: =pod
3026:
3027: =back
3028:
3029: =head1 Access .tab File Data
3030:
3031: =over 4
3032:
1.648 raeburn 3033: =item * &languageids()
1.112 bowersj2 3034:
3035: returns list of all language ids
3036:
3037: =cut
3038:
1.14 harris41 3039: sub languageids {
1.16 harris41 3040: return sort(keys(%language));
1.14 harris41 3041: }
3042:
1.112 bowersj2 3043: =pod
3044:
1.648 raeburn 3045: =item * &languagedescription()
1.112 bowersj2 3046:
3047: returns description of a specified language id
3048:
3049: =cut
3050:
1.14 harris41 3051: sub languagedescription {
1.125 www 3052: my $code=shift;
3053: return ($supported_language{$code}?'* ':'').
3054: $language{$code}.
1.126 www 3055: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3056: }
3057:
3058: sub plainlanguagedescription {
3059: my $code=shift;
3060: return $language{$code};
3061: }
3062:
3063: sub supportedlanguagecode {
3064: my $code=shift;
3065: return $supported_language{$code};
1.97 www 3066: }
3067:
1.112 bowersj2 3068: =pod
3069:
1.648 raeburn 3070: =item * ©rightids()
1.112 bowersj2 3071:
3072: returns list of all copyrights
3073:
3074: =cut
3075:
3076: sub copyrightids {
3077: return sort(keys(%cprtag));
3078: }
3079:
3080: =pod
3081:
1.648 raeburn 3082: =item * ©rightdescription()
1.112 bowersj2 3083:
3084: returns description of a specified copyright id
3085:
3086: =cut
3087:
3088: sub copyrightdescription {
1.166 www 3089: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3090: }
1.197 matthew 3091:
3092: =pod
3093:
1.648 raeburn 3094: =item * &source_copyrightids()
1.192 taceyjo1 3095:
3096: returns list of all source copyrights
3097:
3098: =cut
3099:
3100: sub source_copyrightids {
3101: return sort(keys(%scprtag));
3102: }
3103:
3104: =pod
3105:
1.648 raeburn 3106: =item * &source_copyrightdescription()
1.192 taceyjo1 3107:
3108: returns description of a specified source copyright id
3109:
3110: =cut
3111:
3112: sub source_copyrightdescription {
3113: return &mt($scprtag{shift(@_)});
3114: }
1.112 bowersj2 3115:
3116: =pod
3117:
1.648 raeburn 3118: =item * &filecategories()
1.112 bowersj2 3119:
3120: returns list of all file categories
3121:
3122: =cut
3123:
3124: sub filecategories {
3125: return sort(keys(%category_extensions));
3126: }
3127:
3128: =pod
3129:
1.648 raeburn 3130: =item * &filecategorytypes()
1.112 bowersj2 3131:
3132: returns list of file types belonging to a given file
3133: category
3134:
3135: =cut
3136:
3137: sub filecategorytypes {
1.356 albertel 3138: my ($cat) = @_;
3139: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3140: }
3141:
3142: =pod
3143:
1.648 raeburn 3144: =item * &fileembstyle()
1.112 bowersj2 3145:
3146: returns embedding style for a specified file type
3147:
3148: =cut
3149:
3150: sub fileembstyle {
3151: return $fe{lc(shift(@_))};
1.169 www 3152: }
3153:
1.351 www 3154: sub filemimetype {
3155: return $fm{lc(shift(@_))};
3156: }
3157:
1.169 www 3158:
3159: sub filecategoryselect {
3160: my ($name,$value)=@_;
1.189 matthew 3161: return &select_form($value,$name,
1.169 www 3162: '' => &mt('Any category'),
3163: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3164: }
3165:
3166: =pod
3167:
1.648 raeburn 3168: =item * &filedescription()
1.112 bowersj2 3169:
3170: returns description for a specified file type
3171:
3172: =cut
3173:
3174: sub filedescription {
1.188 matthew 3175: my $file_description = $fd{lc(shift())};
3176: $file_description =~ s:([\[\]]):~$1:g;
3177: return &mt($file_description);
1.112 bowersj2 3178: }
3179:
3180: =pod
3181:
1.648 raeburn 3182: =item * &filedescriptionex()
1.112 bowersj2 3183:
3184: returns description for a specified file type with
3185: extra formatting
3186:
3187: =cut
3188:
3189: sub filedescriptionex {
3190: my $ex=shift;
1.188 matthew 3191: my $file_description = $fd{lc($ex)};
3192: $file_description =~ s:([\[\]]):~$1:g;
3193: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3194: }
3195:
3196: # End of .tab access
3197: =pod
3198:
3199: =back
3200:
3201: =cut
3202:
3203: # ------------------------------------------------------------------ File Types
3204: sub fileextensions {
3205: return sort(keys(%fe));
3206: }
3207:
1.97 www 3208: # ----------------------------------------------------------- Display Languages
3209: # returns a hash with all desired display languages
3210: #
3211:
3212: sub display_languages {
3213: my %languages=();
1.695 raeburn 3214: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3215: $languages{$lang}=1;
1.97 www 3216: }
3217: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3218: if ($env{'form.displaylanguage'}) {
1.356 albertel 3219: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3220: $languages{$lang}=1;
1.97 www 3221: }
3222: }
3223: return %languages;
1.14 harris41 3224: }
3225:
1.582 albertel 3226: sub languages {
3227: my ($possible_langs) = @_;
1.695 raeburn 3228: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3229: if (!ref($possible_langs)) {
3230: if( wantarray ) {
3231: return @preferred_langs;
3232: } else {
3233: return $preferred_langs[0];
3234: }
3235: }
3236: my %possibilities = map { $_ => 1 } (@$possible_langs);
3237: my @preferred_possibilities;
3238: foreach my $preferred_lang (@preferred_langs) {
3239: if (exists($possibilities{$preferred_lang})) {
3240: push(@preferred_possibilities, $preferred_lang);
3241: }
3242: }
3243: if( wantarray ) {
3244: return @preferred_possibilities;
3245: }
3246: return $preferred_possibilities[0];
3247: }
3248:
1.742 raeburn 3249: sub user_lang {
3250: my ($touname,$toudom,$fromcid) = @_;
3251: my @userlangs;
3252: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3253: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3254: $env{'course.'.$fromcid.'.languages'}));
3255: } else {
3256: my %langhash = &getlangs($touname,$toudom);
3257: if ($langhash{'languages'} ne '') {
3258: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3259: } else {
3260: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3261: if ($domdefs{'lang_def'} ne '') {
3262: @userlangs = ($domdefs{'lang_def'});
3263: }
3264: }
3265: }
3266: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3267: my $user_lh = Apache::localize->get_handle(@languages);
3268: return $user_lh;
3269: }
3270:
3271:
1.112 bowersj2 3272: ###############################################################
3273: ## Student Answer Attempts ##
3274: ###############################################################
3275:
3276: =pod
3277:
3278: =head1 Alternate Problem Views
3279:
3280: =over 4
3281:
1.648 raeburn 3282: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3283: $getattempt, $regexp, $gradesub)
3284:
3285: Return string with previous attempt on problem. Arguments:
3286:
3287: =over 4
3288:
3289: =item * $symb: Problem, including path
3290:
3291: =item * $username: username of the desired student
3292:
3293: =item * $domain: domain of the desired student
1.14 harris41 3294:
1.112 bowersj2 3295: =item * $course: Course ID
1.14 harris41 3296:
1.112 bowersj2 3297: =item * $getattempt: Leave blank for all attempts, otherwise put
3298: something
1.14 harris41 3299:
1.112 bowersj2 3300: =item * $regexp: if string matches this regexp, the string will be
3301: sent to $gradesub
1.14 harris41 3302:
1.112 bowersj2 3303: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3304:
1.112 bowersj2 3305: =back
1.14 harris41 3306:
1.112 bowersj2 3307: The output string is a table containing all desired attempts, if any.
1.16 harris41 3308:
1.112 bowersj2 3309: =cut
1.1 albertel 3310:
3311: sub get_previous_attempt {
1.43 ng 3312: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3313: my $prevattempts='';
1.43 ng 3314: no strict 'refs';
1.1 albertel 3315: if ($symb) {
1.3 albertel 3316: my (%returnhash)=
3317: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3318: if ($returnhash{'version'}) {
3319: my %lasthash=();
3320: my $version;
3321: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3322: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3323: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3324: }
1.1 albertel 3325: }
1.596 albertel 3326: $prevattempts=&start_data_table().&start_data_table_header_row();
3327: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3328: foreach my $key (sort(keys(%lasthash))) {
3329: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3330: if ($#parts > 0) {
1.31 albertel 3331: my $data=$parts[-1];
3332: pop(@parts);
1.596 albertel 3333: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3334: } else {
1.41 ng 3335: if ($#parts == 0) {
3336: $prevattempts.='<th>'.$parts[0].'</th>';
3337: } else {
3338: $prevattempts.='<th>'.$ign.'</th>';
3339: }
1.31 albertel 3340: }
1.16 harris41 3341: }
1.596 albertel 3342: $prevattempts.=&end_data_table_header_row();
1.40 ng 3343: if ($getattempt eq '') {
3344: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3345: $prevattempts.=&start_data_table_row().
3346: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3347: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3348: my $value = &format_previous_attempt_value($key,
3349: $returnhash{$version.':'.$key});
3350: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3351: }
1.596 albertel 3352: $prevattempts.=&end_data_table_row();
1.40 ng 3353: }
1.1 albertel 3354: }
1.596 albertel 3355: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3356: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3357: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3358: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3359: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3360: }
1.596 albertel 3361: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3362: } else {
1.596 albertel 3363: $prevattempts=
3364: &start_data_table().&start_data_table_row().
3365: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3366: &end_data_table_row().&end_data_table();
1.1 albertel 3367: }
3368: } else {
1.596 albertel 3369: $prevattempts=
3370: &start_data_table().&start_data_table_row().
3371: '<td>'.&mt('No data.').'</td>'.
3372: &end_data_table_row().&end_data_table();
1.1 albertel 3373: }
1.10 albertel 3374: }
3375:
1.581 albertel 3376: sub format_previous_attempt_value {
3377: my ($key,$value) = @_;
3378: if ($key =~ /timestamp/) {
3379: $value = &Apache::lonlocal::locallocaltime($value);
3380: } elsif (ref($value) eq 'ARRAY') {
3381: $value = '('.join(', ', @{ $value }).')';
3382: } else {
3383: $value = &unescape($value);
3384: }
3385: return $value;
3386: }
3387:
3388:
1.107 albertel 3389: sub relative_to_absolute {
3390: my ($url,$output)=@_;
3391: my $parser=HTML::TokeParser->new(\$output);
3392: my $token;
3393: my $thisdir=$url;
3394: my @rlinks=();
3395: while ($token=$parser->get_token) {
3396: if ($token->[0] eq 'S') {
3397: if ($token->[1] eq 'a') {
3398: if ($token->[2]->{'href'}) {
3399: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3400: }
3401: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3402: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3403: } elsif ($token->[1] eq 'base') {
3404: $thisdir=$token->[2]->{'href'};
3405: }
3406: }
3407: }
3408: $thisdir=~s-/[^/]*$--;
1.356 albertel 3409: foreach my $link (@rlinks) {
1.726 raeburn 3410: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3411: ($link=~/^\//) ||
3412: ($link=~/^javascript:/i) ||
3413: ($link=~/^mailto:/i) ||
3414: ($link=~/^\#/)) {
3415: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3416: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3417: }
3418: }
3419: # -------------------------------------------------- Deal with Applet codebases
3420: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3421: return $output;
3422: }
3423:
1.112 bowersj2 3424: =pod
3425:
1.648 raeburn 3426: =item * &get_student_view()
1.112 bowersj2 3427:
3428: show a snapshot of what student was looking at
3429:
3430: =cut
3431:
1.10 albertel 3432: sub get_student_view {
1.186 albertel 3433: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3434: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3435: my (%form);
1.10 albertel 3436: my @elements=('symb','courseid','domain','username');
3437: foreach my $element (@elements) {
1.186 albertel 3438: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3439: }
1.186 albertel 3440: if (defined($moreenv)) {
3441: %form=(%form,%{$moreenv});
3442: }
1.236 albertel 3443: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3444: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3445: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3446: $userview=~s/\<body[^\>]*\>//gi;
3447: $userview=~s/\<\/body\>//gi;
3448: $userview=~s/\<html\>//gi;
3449: $userview=~s/\<\/html\>//gi;
3450: $userview=~s/\<head\>//gi;
3451: $userview=~s/\<\/head\>//gi;
3452: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3453: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3454: if (wantarray) {
3455: return ($userview,$response);
3456: } else {
3457: return $userview;
3458: }
3459: }
3460:
3461: sub get_student_view_with_retries {
3462: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3463:
3464: my $ok = 0; # True if we got a good response.
3465: my $content;
3466: my $response;
3467:
3468: # Try to get the student_view done. within the retries count:
3469:
3470: do {
3471: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3472: $ok = $response->is_success;
3473: if (!$ok) {
3474: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3475: }
3476: $retries--;
3477: } while (!$ok && ($retries > 0));
3478:
3479: if (!$ok) {
3480: $content = ''; # On error return an empty content.
3481: }
1.651 www 3482: if (wantarray) {
3483: return ($content, $response);
3484: } else {
3485: return $content;
3486: }
1.11 albertel 3487: }
3488:
1.112 bowersj2 3489: =pod
3490:
1.648 raeburn 3491: =item * &get_student_answers()
1.112 bowersj2 3492:
3493: show a snapshot of how student was answering problem
3494:
3495: =cut
3496:
1.11 albertel 3497: sub get_student_answers {
1.100 sakharuk 3498: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3499: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3500: my (%moreenv);
1.11 albertel 3501: my @elements=('symb','courseid','domain','username');
3502: foreach my $element (@elements) {
1.186 albertel 3503: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3504: }
1.186 albertel 3505: $moreenv{'grade_target'}='answer';
3506: %moreenv=(%form,%moreenv);
1.497 raeburn 3507: $feedurl = &Apache::lonnet::clutter($feedurl);
3508: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3509: return $userview;
1.1 albertel 3510: }
1.116 albertel 3511:
3512: =pod
3513:
3514: =item * &submlink()
3515:
1.242 albertel 3516: Inputs: $text $uname $udom $symb $target
1.116 albertel 3517:
3518: Returns: A link to grades.pm such as to see the SUBM view of a student
3519:
3520: =cut
3521:
3522: ###############################################
3523: sub submlink {
1.242 albertel 3524: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3525: if (!($uname && $udom)) {
3526: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3527: &Apache::lonnet::whichuser($symb);
1.116 albertel 3528: if (!$symb) { $symb=$cursymb; }
3529: }
1.254 matthew 3530: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3531: $symb=&escape($symb);
1.242 albertel 3532: if ($target) { $target="target=\"$target\""; }
3533: return '<a href="/adm/grades?&command=submission&'.
3534: 'symb='.$symb.'&student='.$uname.
3535: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3536: }
3537: ##############################################
3538:
3539: =pod
3540:
3541: =item * &pgrdlink()
3542:
3543: Inputs: $text $uname $udom $symb $target
3544:
3545: Returns: A link to grades.pm such as to see the PGRD view of a student
3546:
3547: =cut
3548:
3549: ###############################################
3550: sub pgrdlink {
3551: my $link=&submlink(@_);
3552: $link=~s/(&command=submission)/$1&showgrading=yes/;
3553: return $link;
3554: }
3555: ##############################################
3556:
3557: =pod
3558:
3559: =item * &pprmlink()
3560:
3561: Inputs: $text $uname $udom $symb $target
3562:
3563: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3564: student and a specific resource
1.242 albertel 3565:
3566: =cut
3567:
3568: ###############################################
3569: sub pprmlink {
3570: my ($text,$uname,$udom,$symb,$target)=@_;
3571: if (!($uname && $udom)) {
3572: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3573: &Apache::lonnet::whichuser($symb);
1.242 albertel 3574: if (!$symb) { $symb=$cursymb; }
3575: }
1.254 matthew 3576: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3577: $symb=&escape($symb);
1.242 albertel 3578: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3579: return '<a href="/adm/parmset?command=set&'.
3580: 'symb='.$symb.'&uname='.$uname.
3581: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3582: }
3583: ##############################################
1.37 matthew 3584:
1.112 bowersj2 3585: =pod
3586:
3587: =back
3588:
3589: =cut
3590:
1.37 matthew 3591: ###############################################
1.51 www 3592:
3593:
3594: sub timehash {
1.687 raeburn 3595: my ($thistime) = @_;
3596: my $timezone = &Apache::lonlocal::gettimezone();
3597: my $dt = DateTime->from_epoch(epoch => $thistime)
3598: ->set_time_zone($timezone);
3599: my $wday = $dt->day_of_week();
3600: if ($wday == 7) { $wday = 0; }
3601: return ( 'second' => $dt->second(),
3602: 'minute' => $dt->minute(),
3603: 'hour' => $dt->hour(),
3604: 'day' => $dt->day_of_month(),
3605: 'month' => $dt->month(),
3606: 'year' => $dt->year(),
3607: 'weekday' => $wday,
3608: 'dayyear' => $dt->day_of_year(),
3609: 'dlsav' => $dt->is_dst() );
1.51 www 3610: }
3611:
1.370 www 3612: sub utc_string {
3613: my ($date)=@_;
1.371 www 3614: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3615: }
3616:
1.51 www 3617: sub maketime {
3618: my %th=@_;
1.687 raeburn 3619: my ($epoch_time,$timezone,$dt);
3620: $timezone = &Apache::lonlocal::gettimezone();
3621: eval {
3622: $dt = DateTime->new( year => $th{'year'},
3623: month => $th{'month'},
3624: day => $th{'day'},
3625: hour => $th{'hour'},
3626: minute => $th{'minute'},
3627: second => $th{'second'},
3628: time_zone => $timezone,
3629: );
3630: };
3631: if (!$@) {
3632: $epoch_time = $dt->epoch;
3633: if ($epoch_time) {
3634: return $epoch_time;
3635: }
3636: }
1.51 www 3637: return POSIX::mktime(
3638: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3639: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3640: }
3641:
3642: #########################################
1.51 www 3643:
3644: sub findallcourses {
1.482 raeburn 3645: my ($roles,$uname,$udom) = @_;
1.355 albertel 3646: my %roles;
3647: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3648: my %courses;
1.51 www 3649: my $now=time;
1.482 raeburn 3650: if (!defined($uname)) {
3651: $uname = $env{'user.name'};
3652: }
3653: if (!defined($udom)) {
3654: $udom = $env{'user.domain'};
3655: }
3656: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3657: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3658: if (!%roles) {
3659: %roles = (
3660: cc => 1,
3661: in => 1,
3662: ep => 1,
3663: ta => 1,
3664: cr => 1,
3665: st => 1,
3666: );
3667: }
3668: foreach my $entry (keys(%roleshash)) {
3669: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3670: if ($trole =~ /^cr/) {
3671: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3672: } else {
3673: next if (!exists($roles{$trole}));
3674: }
3675: if ($tend) {
3676: next if ($tend < $now);
3677: }
3678: if ($tstart) {
3679: next if ($tstart > $now);
3680: }
3681: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3682: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3683: if ($secpart eq '') {
3684: ($cnum,$role) = split(/_/,$cnumpart);
3685: $sec = 'none';
3686: $realsec = '';
3687: } else {
3688: $cnum = $cnumpart;
3689: ($sec,$role) = split(/_/,$secpart);
3690: $realsec = $sec;
1.490 raeburn 3691: }
1.482 raeburn 3692: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3693: }
3694: } else {
3695: foreach my $key (keys(%env)) {
1.483 albertel 3696: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3697: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3698: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3699: next if ($role eq 'ca' || $role eq 'aa');
3700: next if (%roles && !exists($roles{$role}));
3701: my ($starttime,$endtime)=split(/\./,$env{$key});
3702: my $active=1;
3703: if ($starttime) {
3704: if ($now<$starttime) { $active=0; }
3705: }
3706: if ($endtime) {
3707: if ($now>$endtime) { $active=0; }
3708: }
3709: if ($active) {
3710: if ($sec eq '') {
3711: $sec = 'none';
3712: }
3713: $courses{$cdom.'_'.$cnum}{$sec} =
3714: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3715: }
3716: }
1.51 www 3717: }
3718: }
1.474 raeburn 3719: return %courses;
1.51 www 3720: }
1.37 matthew 3721:
1.54 www 3722: ###############################################
1.474 raeburn 3723:
3724: sub blockcheck {
1.482 raeburn 3725: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3726:
3727: if (!defined($udom)) {
3728: $udom = $env{'user.domain'};
3729: }
3730: if (!defined($uname)) {
3731: $uname = $env{'user.name'};
3732: }
3733:
3734: # If uname and udom are for a course, check for blocks in the course.
3735:
3736: if (&Apache::lonnet::is_course($udom,$uname)) {
3737: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3738: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3739: return ($startblock,$endblock);
3740: }
1.474 raeburn 3741:
1.502 raeburn 3742: my $startblock = 0;
3743: my $endblock = 0;
1.482 raeburn 3744: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3745:
1.490 raeburn 3746: # If uname is for a user, and activity is course-specific, i.e.,
3747: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3748:
1.490 raeburn 3749: if (($activity eq 'boards' || $activity eq 'chat' ||
3750: $activity eq 'groups') && ($env{'request.course.id'})) {
3751: foreach my $key (keys(%live_courses)) {
3752: if ($key ne $env{'request.course.id'}) {
3753: delete($live_courses{$key});
3754: }
3755: }
3756: }
3757:
3758: my $otheruser = 0;
3759: my %own_courses;
3760: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3761: # Resource belongs to user other than current user.
3762: $otheruser = 1;
3763: # Gather courses for current user
3764: %own_courses =
3765: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3766: }
3767:
3768: # Gather active course roles - course coordinator, instructor,
3769: # exam proctor, ta, student, or custom role.
1.474 raeburn 3770:
3771: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3772: my ($cdom,$cnum);
3773: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3774: $cdom = $env{'course.'.$course.'.domain'};
3775: $cnum = $env{'course.'.$course.'.num'};
3776: } else {
1.490 raeburn 3777: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3778: }
3779: my $no_ownblock = 0;
3780: my $no_userblock = 0;
1.533 raeburn 3781: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3782: # Check if current user has 'evb' priv for this
3783: if (defined($own_courses{$course})) {
3784: foreach my $sec (keys(%{$own_courses{$course}})) {
3785: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3786: if ($sec ne 'none') {
3787: $checkrole .= '/'.$sec;
3788: }
3789: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3790: $no_ownblock = 1;
3791: last;
3792: }
3793: }
3794: }
3795: # if they have 'evb' priv and are currently not playing student
3796: next if (($no_ownblock) &&
3797: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3798: }
1.474 raeburn 3799: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3800: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3801: if ($sec ne 'none') {
1.482 raeburn 3802: $checkrole .= '/'.$sec;
1.474 raeburn 3803: }
1.490 raeburn 3804: if ($otheruser) {
3805: # Resource belongs to user other than current user.
3806: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3807: my ($trole,$tdom,$tnum,$tsec);
3808: my $entry = $live_courses{$course}{$sec};
3809: if ($entry =~ /^cr/) {
3810: ($trole,$tdom,$tnum,$tsec) =
3811: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3812: } else {
3813: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3814: }
3815: my ($spec,$area,$trest,%allroles,%userroles);
3816: $area = '/'.$tdom.'/'.$tnum;
3817: $trest = $tnum;
3818: if ($tsec ne '') {
3819: $area .= '/'.$tsec;
3820: $trest .= '/'.$tsec;
3821: }
3822: $spec = $trole.'.'.$area;
3823: if ($trole =~ /^cr/) {
3824: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3825: $tdom,$spec,$trest,$area);
3826: } else {
3827: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3828: $tdom,$spec,$trest,$area);
3829: }
3830: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3831: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3832: if ($1) {
3833: $no_userblock = 1;
3834: last;
3835: }
3836: }
1.490 raeburn 3837: } else {
3838: # Resource belongs to current user
3839: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3840: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3841: $no_ownblock = 1;
3842: last;
3843: }
1.474 raeburn 3844: }
3845: }
3846: # if they have the evb priv and are currently not playing student
1.482 raeburn 3847: next if (($no_ownblock) &&
1.491 albertel 3848: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3849: next if ($no_userblock);
1.474 raeburn 3850:
1.866 kalberla 3851: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3852: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3853:
3854: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3855: if (($start != 0) &&
3856: (($startblock == 0) || ($startblock > $start))) {
3857: $startblock = $start;
3858: }
3859: if (($end != 0) &&
3860: (($endblock == 0) || ($endblock < $end))) {
3861: $endblock = $end;
3862: }
1.490 raeburn 3863: }
3864: return ($startblock,$endblock);
3865: }
3866:
3867: sub get_blocks {
3868: my ($setters,$activity,$cdom,$cnum) = @_;
3869: my $startblock = 0;
3870: my $endblock = 0;
3871: my $course = $cdom.'_'.$cnum;
3872: $setters->{$course} = {};
3873: $setters->{$course}{'staff'} = [];
3874: $setters->{$course}{'times'} = [];
3875: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3876: foreach my $record (keys(%records)) {
3877: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3878: if ($start <= time && $end >= time) {
3879: my ($staff_name,$staff_dom,$title,$blocks) =
3880: &parse_block_record($records{$record});
3881: if ($blocks->{$activity} eq 'on') {
3882: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3883: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3884: if ( ($startblock == 0) || ($startblock > $start) ) {
3885: $startblock = $start;
1.490 raeburn 3886: }
1.491 albertel 3887: if ( ($endblock == 0) || ($endblock < $end) ) {
3888: $endblock = $end;
1.474 raeburn 3889: }
3890: }
3891: }
3892: }
3893: return ($startblock,$endblock);
3894: }
3895:
3896: sub parse_block_record {
3897: my ($record) = @_;
3898: my ($setuname,$setudom,$title,$blocks);
3899: if (ref($record) eq 'HASH') {
3900: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3901: $title = &unescape($record->{'event'});
3902: $blocks = $record->{'blocks'};
3903: } else {
3904: my @data = split(/:/,$record,3);
3905: if (scalar(@data) eq 2) {
3906: $title = $data[1];
3907: ($setuname,$setudom) = split(/@/,$data[0]);
3908: } else {
3909: ($setuname,$setudom,$title) = @data;
3910: }
3911: $blocks = { 'com' => 'on' };
3912: }
3913: return ($setuname,$setudom,$title,$blocks);
3914: }
3915:
1.854 kalberla 3916: sub blocking_status {
1.867 kalberla 3917: my $blocked;
1.854 kalberla 3918: my ($activity,$uname,$udom) = @_;
1.867 kalberla 3919: my %setters;
3920: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3921: if ($startblock && $endblock) {
3922: $blocked = 1;
3923: }
1.854 kalberla 3924: if(!wantarray) {
3925: return $blocked;
3926: }
3927: my $output;
3928: my $querystring;
3929: $querystring = "?activity=$activity";
3930:
3931: $output .= <<"END_MYBLOCK";
3932: <script type="text/javascript">
3933: // <![CDATA[
3934: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3935: var options = "width=" + w + ",height=" + h + ",";
3936: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3937: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3938: var newWin = window.open(url, wdwName, options);
3939: newWin.focus();
3940: }
3941:
3942: // ]]>
3943: </script>
3944: END_MYBLOCK
3945: my $popupUrl = "/adm/blockingstatus/$querystring";
1.867 kalberla 3946: $output .= <<"END_BLOCK";
3947: <div class='LC_comblock'>
1.869 kalberla 3948: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
3949: title='Communication Blocked'>
3950: <img class='LC_noBorder LC_middle' title='Communication Blocked' src='/res/adm/pages/comblock.png' alt='Communication Blocked'/></a>
3951: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
3952: title='Communication Blocked'>Communication Blocked</a>
1.867 kalberla 3953: </div>
3954:
3955: END_BLOCK
1.474 raeburn 3956:
1.854 kalberla 3957: return ($blocked, $output);
3958: }
1.490 raeburn 3959:
1.60 matthew 3960: ###############################################
3961:
1.682 raeburn 3962: sub check_ip_acc {
3963: my ($acc)=@_;
3964: &Apache::lonxml::debug("acc is $acc");
3965: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3966: return 1;
3967: }
3968: my $allowed=0;
3969: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3970:
3971: my $name;
3972: foreach my $pattern (split(',',$acc)) {
3973: $pattern =~ s/^\s*//;
3974: $pattern =~ s/\s*$//;
3975: if ($pattern =~ /\*$/) {
3976: #35.8.*
3977: $pattern=~s/\*//;
3978: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3979: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3980: #35.8.3.[34-56]
3981: my $low=$2;
3982: my $high=$3;
3983: $pattern=$1;
3984: if ($ip =~ /^\Q$pattern\E/) {
3985: my $last=(split(/\./,$ip))[3];
3986: if ($last <=$high && $last >=$low) { $allowed=1; }
3987: }
3988: } elsif ($pattern =~ /^\*/) {
3989: #*.msu.edu
3990: $pattern=~s/\*//;
3991: if (!defined($name)) {
3992: use Socket;
3993: my $netaddr=inet_aton($ip);
3994: ($name)=gethostbyaddr($netaddr,AF_INET);
3995: }
3996: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3997: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3998: #127.0.0.1
3999: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4000: } else {
4001: #some.name.com
4002: if (!defined($name)) {
4003: use Socket;
4004: my $netaddr=inet_aton($ip);
4005: ($name)=gethostbyaddr($netaddr,AF_INET);
4006: }
4007: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4008: }
4009: if ($allowed) { last; }
4010: }
4011: return $allowed;
4012: }
4013:
4014: ###############################################
4015:
1.60 matthew 4016: =pod
4017:
1.112 bowersj2 4018: =head1 Domain Template Functions
4019:
4020: =over 4
4021:
4022: =item * &determinedomain()
1.60 matthew 4023:
4024: Inputs: $domain (usually will be undef)
4025:
1.63 www 4026: Returns: Determines which domain should be used for designs
1.60 matthew 4027:
4028: =cut
1.54 www 4029:
1.60 matthew 4030: ###############################################
1.63 www 4031: sub determinedomain {
4032: my $domain=shift;
1.531 albertel 4033: if (! $domain) {
1.60 matthew 4034: # Determine domain if we have not been given one
4035: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 4036: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4037: if ($env{'request.role.domain'}) {
4038: $domain=$env{'request.role.domain'};
1.60 matthew 4039: }
4040: }
1.63 www 4041: return $domain;
4042: }
4043: ###############################################
1.517 raeburn 4044:
1.518 albertel 4045: sub devalidate_domconfig_cache {
4046: my ($udom)=@_;
4047: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4048: }
4049:
4050: # ---------------------- Get domain configuration for a domain
4051: sub get_domainconf {
4052: my ($udom) = @_;
4053: my $cachetime=1800;
4054: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4055: if (defined($cached)) { return %{$result}; }
4056:
4057: my %domconfig = &Apache::lonnet::get_dom('configuration',
4058: ['login','rolecolors'],$udom);
1.632 raeburn 4059: my (%designhash,%legacy);
1.518 albertel 4060: if (keys(%domconfig) > 0) {
4061: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4062: if (keys(%{$domconfig{'login'}})) {
4063: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4064: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4065: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4066: $designhash{$udom.'.login.'.$key.'_'.$img} =
4067: $domconfig{'login'}{$key}{$img};
4068: }
4069: } else {
4070: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4071: }
1.632 raeburn 4072: }
4073: } else {
4074: $legacy{'login'} = 1;
1.518 albertel 4075: }
1.632 raeburn 4076: } else {
4077: $legacy{'login'} = 1;
1.518 albertel 4078: }
4079: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4080: if (keys(%{$domconfig{'rolecolors'}})) {
4081: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4082: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4083: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4084: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4085: }
1.518 albertel 4086: }
4087: }
1.632 raeburn 4088: } else {
4089: $legacy{'rolecolors'} = 1;
1.518 albertel 4090: }
1.632 raeburn 4091: } else {
4092: $legacy{'rolecolors'} = 1;
1.518 albertel 4093: }
1.632 raeburn 4094: if (keys(%legacy) > 0) {
4095: my %legacyhash = &get_legacy_domconf($udom);
4096: foreach my $item (keys(%legacyhash)) {
4097: if ($item =~ /^\Q$udom\E\.login/) {
4098: if ($legacy{'login'}) {
4099: $designhash{$item} = $legacyhash{$item};
4100: }
4101: } else {
4102: if ($legacy{'rolecolors'}) {
4103: $designhash{$item} = $legacyhash{$item};
4104: }
1.518 albertel 4105: }
4106: }
4107: }
1.632 raeburn 4108: } else {
4109: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4110: }
4111: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4112: $cachetime);
4113: return %designhash;
4114: }
4115:
1.632 raeburn 4116: sub get_legacy_domconf {
4117: my ($udom) = @_;
4118: my %legacyhash;
4119: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4120: my $designfile = $designdir.'/'.$udom.'.tab';
4121: if (-e $designfile) {
4122: if ( open (my $fh,"<$designfile") ) {
4123: while (my $line = <$fh>) {
4124: next if ($line =~ /^\#/);
4125: chomp($line);
4126: my ($key,$val)=(split(/\=/,$line));
4127: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4128: }
4129: close($fh);
4130: }
4131: }
4132: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4133: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4134: }
4135: return %legacyhash;
4136: }
4137:
1.63 www 4138: =pod
4139:
1.112 bowersj2 4140: =item * &domainlogo()
1.63 www 4141:
4142: Inputs: $domain (usually will be undef)
4143:
4144: Returns: A link to a domain logo, if the domain logo exists.
4145: If the domain logo does not exist, a description of the domain.
4146:
4147: =cut
1.112 bowersj2 4148:
1.63 www 4149: ###############################################
4150: sub domainlogo {
1.517 raeburn 4151: my $domain = &determinedomain(shift);
1.518 albertel 4152: my %designhash = &get_domainconf($domain);
1.517 raeburn 4153: # See if there is a logo
4154: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4155: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4156: if ($imgsrc =~ m{^/(adm|res)/}) {
4157: if ($imgsrc =~ m{^/res/}) {
4158: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4159: &Apache::lonnet::repcopy($local_name);
4160: }
4161: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4162: }
4163: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4164: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4165: return &Apache::lonnet::domain($domain,'description');
1.59 www 4166: } else {
1.60 matthew 4167: return '';
1.59 www 4168: }
4169: }
1.63 www 4170: ##############################################
4171:
4172: =pod
4173:
1.112 bowersj2 4174: =item * &designparm()
1.63 www 4175:
4176: Inputs: $which parameter; $domain (usually will be undef)
4177:
4178: Returns: value of designparamter $which
4179:
4180: =cut
1.112 bowersj2 4181:
1.397 albertel 4182:
1.400 albertel 4183: ##############################################
1.397 albertel 4184: sub designparm {
4185: my ($which,$domain)=@_;
4186: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4187: return $env{'environment.color.'.$which};
1.96 www 4188: }
1.63 www 4189: $domain=&determinedomain($domain);
1.518 albertel 4190: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4191: my $output;
1.517 raeburn 4192: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4193: $output = $domdesign{$domain.'.'.$which};
1.63 www 4194: } else {
1.520 raeburn 4195: $output = $defaultdesign{$which};
4196: }
4197: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4198: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4199: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4200: if ($output =~ m{^/res/}) {
4201: my $local_name = &Apache::lonnet::filelocation('',$output);
4202: &Apache::lonnet::repcopy($local_name);
4203: }
1.520 raeburn 4204: $output = &lonhttpdurl($output);
4205: }
1.63 www 4206: }
1.520 raeburn 4207: return $output;
1.63 www 4208: }
1.59 www 4209:
1.822 bisitz 4210: ##############################################
4211: =pod
4212:
1.832 bisitz 4213: =item * &authorspace()
4214:
4215: Inputs: ./.
4216:
4217: Returns: Path to the Construction Space of the current user's
4218: accessed author space
4219: The author space will be that of the current user
4220: when accessing the own author space
4221: and that of the co-author/assistent co-author
4222: when accessing the co-author's/assistent co-author's
4223: space
4224:
4225: =cut
4226:
4227: sub authorspace {
4228: my $caname = '';
4229: if ($env{'request.role'} =~ /^ca|^aa/) {
4230: (undef,$caname) =
4231: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4232: } else {
4233: $caname = $env{'user.name'};
4234: }
4235: return '/priv/'.$caname.'/';
4236: }
4237:
4238: ##############################################
4239: =pod
4240:
1.822 bisitz 4241: =item * &head_subbox()
4242:
4243: Inputs: $content (contains HTML code with page functions, etc.)
4244:
4245: Returns: HTML div with $content
4246: To be included in page header
4247:
4248: =cut
4249:
4250: sub head_subbox {
4251: my ($content)=@_;
4252: my $output =
1.844 bisitz 4253: '<div id="LC_head_subbox">'
1.822 bisitz 4254: .$content
4255: .'</div>'
4256: }
4257:
4258: ##############################################
4259: =pod
4260:
4261: =item * &CSTR_pageheader()
4262:
4263: Inputs: ./.
4264:
4265: Returns: HTML div with CSTR path and recent box
4266: To be included on Construction Space pages
4267:
4268: =cut
4269:
4270: sub CSTR_pageheader {
4271: # this is for resources; directories have customtitle, and crumbs
4272: # and select recent are created in lonpubdir.pm
4273: my ($uname,$thisdisfn)=
4274: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4275: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4276: $formaction=~s/\/+/\//g;
4277:
4278: my $parentpath = '';
4279: my $lastitem = '';
4280: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4281: $parentpath = $1;
4282: $lastitem = $2;
4283: } else {
4284: $lastitem = $thisdisfn;
4285: }
4286: return
4287: '<div>'
4288: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4289: .'<b>'.&mt('Construction Space:').'</b> '
4290: .'<form name="dirs" method="post" action="'.$formaction
4291: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4292: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4293: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4294: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4295: .'</form>'
4296: .&Apache::lonmenu::constspaceform()
4297: .'</div>';
4298: }
4299:
1.60 matthew 4300: ###############################################
4301: ###############################################
4302:
4303: =pod
4304:
1.112 bowersj2 4305: =back
4306:
1.549 albertel 4307: =head1 HTML Helpers
1.112 bowersj2 4308:
4309: =over 4
4310:
4311: =item * &bodytag()
1.60 matthew 4312:
4313: Returns a uniform header for LON-CAPA web pages.
4314:
4315: Inputs:
4316:
1.112 bowersj2 4317: =over 4
4318:
4319: =item * $title, A title to be displayed on the page.
4320:
4321: =item * $function, the current role (can be undef).
4322:
4323: =item * $addentries, extra parameters for the <body> tag.
4324:
4325: =item * $bodyonly, if defined, only return the <body> tag.
4326:
4327: =item * $domain, if defined, force a given domain.
4328:
4329: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4330: text interface only)
1.60 matthew 4331:
1.814 bisitz 4332: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4333: navigational links
1.317 albertel 4334:
1.338 albertel 4335: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4336:
1.361 albertel 4337: =item * $no_inline_link, if true and in remote mode, don't show the
4338: 'Switch To Inline Menu' link
4339:
1.460 albertel 4340: =item * $args, optional argument valid values are
4341: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4342: inherit_jsmath -> when creating popup window in a page,
4343: should it have jsmath forced on by the
4344: current page
1.460 albertel 4345:
1.112 bowersj2 4346: =back
4347:
1.60 matthew 4348: Returns: A uniform header for LON-CAPA web pages.
4349: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4350: If $bodyonly is undef or zero, an html string containing a <body> tag and
4351: other decorations will be returned.
4352:
4353: =cut
4354:
1.54 www 4355: sub bodytag {
1.831 bisitz 4356: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4357: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4358:
1.460 albertel 4359: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4360:
1.183 matthew 4361: $function = &get_users_function() if (!$function);
1.339 albertel 4362: my $img = &designparm($function.'.img',$domain);
4363: my $font = &designparm($function.'.font',$domain);
4364: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4365:
1.803 bisitz 4366: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4367: 'bgcolor' => $pgbg,
1.339 albertel 4368: 'text' => $font,
4369: 'alink' => &designparm($function.'.alink',$domain),
4370: 'vlink' => &designparm($function.'.vlink',$domain),
4371: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4372: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4373:
1.63 www 4374: # role and realm
1.378 raeburn 4375: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4376: if ($role eq 'ca') {
1.479 albertel 4377: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4378: $realm = &plainname($rname,$rdom);
1.378 raeburn 4379: }
1.55 www 4380: # realm
1.258 albertel 4381: if ($env{'request.course.id'}) {
1.378 raeburn 4382: if ($env{'request.role'} !~ /^cr/) {
4383: $role = &Apache::lonnet::plaintext($role,&course_type());
4384: }
1.359 albertel 4385: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4386: } else {
4387: $role = &Apache::lonnet::plaintext($role);
1.54 www 4388: }
1.433 albertel 4389:
1.359 albertel 4390: if (!$realm) { $realm=' '; }
1.55 www 4391: # Set messages
1.60 matthew 4392: my $messages=&domainlogo($domain);
1.330 albertel 4393:
1.438 albertel 4394: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4395:
1.101 www 4396: # construct main body tag
1.359 albertel 4397: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4398: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4399:
1.530 albertel 4400: if ($bodyonly) {
1.60 matthew 4401: return $bodytag;
1.798 tempelho 4402: }
1.359 albertel 4403:
1.410 albertel 4404: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4405: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4406: undef($role);
1.434 albertel 4407: } else {
4408: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4409: }
1.359 albertel 4410:
1.762 bisitz 4411: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4412: #
4413: # Extra info if you are the DC
4414: my $dc_info = '';
4415: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4416: $env{'course.'.$env{'request.course.id'}.
4417: '.domain'}.'/'})) {
4418: my $cid = $env{'request.course.id'};
4419: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4420: $dc_info =~ s/\s+$//;
1.359 albertel 4421: $dc_info = '('.$dc_info.')';
4422: }
4423:
1.853 droeschl 4424: $role = "($role)" if $role;
4425: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4426:
1.837 bisitz 4427: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4428: # No Remote
1.258 albertel 4429: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4430: $forcereg=1;
4431: }
4432:
1.836 bisitz 4433: # if ($env{'request.state'} eq 'construct') {
4434: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4435: # }
1.359 albertel 4436:
1.816 bisitz 4437: my $titletable = '<table id="LC_title_bar">'
1.836 bisitz 4438: ."<tr><td> $titleinfo $dc_info</td>"
1.816 bisitz 4439: .'</tr></table>';
4440:
1.814 bisitz 4441: if ($no_nav_bar) {
1.359 albertel 4442: $bodytag .= $titletable;
4443: } else {
1.852 droeschl 4444: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4445: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4446:
1.359 albertel 4447: if ($env{'request.state'} eq 'construct') {
1.863 droeschl 4448: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
1.272 raeburn 4449: } else {
1.863 droeschl 4450: $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
1.272 raeburn 4451: }
1.235 raeburn 4452: }
4453: return $bodytag;
1.94 www 4454: }
1.95 www 4455:
1.93 www 4456: #
1.95 www 4457: # Top frame rendering, Remote is up
1.93 www 4458: #
1.359 albertel 4459:
1.517 raeburn 4460: my $imgsrc = $img;
4461: if ($img =~ /^\/adm/) {
1.575 albertel 4462: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4463: }
4464: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4465:
1.305 www 4466: # Explicit link to get inline menu
1.361 albertel 4467: my $menu= ($no_inline_link?''
1.853 droeschl 4468: :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4469: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4470: <em>$realm</em> $dc_info </div>
4471: <ol class="LC_smallMenu LC_right">
4472: <li>$menu</li>
4473: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4474: #
1.94 www 4475: return(<<ENDBODY);
1.60 matthew 4476: $bodytag
1.359 albertel 4477: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4478: <tr><td>$upperleft</td>
4479: <td>$messages </td>
1.54 www 4480: </tr>
1.359 albertel 4481: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4482: </tr>
1.356 albertel 4483: </table>
1.54 www 4484: ENDBODY
1.182 matthew 4485: }
4486:
1.330 albertel 4487: sub make_attr_string {
4488: my ($register,$attr_ref) = @_;
4489:
4490: if ($attr_ref && !ref($attr_ref)) {
4491: die("addentries Must be a hash ref ".
4492: join(':',caller(1))." ".
4493: join(':',caller(0))." ");
4494: }
4495:
4496: if ($register) {
1.339 albertel 4497: my ($on_load,$on_unload);
4498: foreach my $key (keys(%{$attr_ref})) {
4499: if (lc($key) eq 'onload') {
4500: $on_load.=$attr_ref->{$key}.';';
4501: delete($attr_ref->{$key});
4502:
4503: } elsif (lc($key) eq 'onunload') {
4504: $on_unload.=$attr_ref->{$key}.';';
4505: delete($attr_ref->{$key});
4506: }
4507: }
4508: $attr_ref->{'onload'} =
4509: &Apache::lonmenu::loadevents(). $on_load;
4510: $attr_ref->{'onunload'}=
4511: &Apache::lonmenu::unloadevents().$on_unload;
4512: }
4513:
4514: # Accessibility font enhance
4515: if ($env{'browser.fontenhance'} eq 'on') {
4516: my $style;
4517: foreach my $key (keys(%{$attr_ref})) {
4518: if (lc($key) eq 'style') {
4519: $style.=$attr_ref->{$key}.';';
4520: delete($attr_ref->{$key});
4521: }
4522: }
4523: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4524: }
1.339 albertel 4525:
1.330 albertel 4526: my $attr_string;
4527: foreach my $attr (keys(%$attr_ref)) {
4528: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4529: }
4530: return $attr_string;
4531: }
4532:
4533:
1.182 matthew 4534: ###############################################
1.251 albertel 4535: ###############################################
4536:
4537: =pod
4538:
4539: =item * &endbodytag()
4540:
4541: Returns a uniform footer for LON-CAPA web pages.
4542:
1.635 raeburn 4543: Inputs: 1 - optional reference to an args hash
4544: If in the hash, key for noredirectlink has a value which evaluates to true,
4545: a 'Continue' link is not displayed if the page contains an
4546: internal redirect in the <head></head> section,
4547: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4548:
4549: =cut
4550:
4551: sub endbodytag {
1.635 raeburn 4552: my ($args) = @_;
1.251 albertel 4553: my $endbodytag='</body>';
1.269 albertel 4554: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4555: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4556: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4557: $endbodytag=
4558: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4559: &mt('Continue').'</a>'.
4560: $endbodytag;
4561: }
1.315 albertel 4562: }
1.251 albertel 4563: return $endbodytag;
4564: }
4565:
1.352 albertel 4566: =pod
4567:
4568: =item * &standard_css()
4569:
4570: Returns a style sheet
4571:
4572: Inputs: (all optional)
4573: domain -> force to color decorate a page for a specific
4574: domain
4575: function -> force usage of a specific rolish color scheme
4576: bgcolor -> override the default page bgcolor
4577:
4578: =cut
4579:
1.343 albertel 4580: sub standard_css {
1.345 albertel 4581: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4582: $function = &get_users_function() if (!$function);
4583: my $img = &designparm($function.'.img', $domain);
4584: my $tabbg = &designparm($function.'.tabbg', $domain);
4585: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4586: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4587: #second colour for later usage
1.345 albertel 4588: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4589: my $pgbg_or_bgcolor =
4590: $bgcolor ||
1.352 albertel 4591: &designparm($function.'.pgbg', $domain);
1.382 albertel 4592: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4593: my $alink = &designparm($function.'.alink', $domain);
4594: my $vlink = &designparm($function.'.vlink', $domain);
4595: my $link = &designparm($function.'.link', $domain);
4596:
1.704 muellerd 4597: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4598: my $bgcol = &designparm('login.bgcol',$domain);
4599: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4600:
1.602 albertel 4601: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4602: my $mono = 'monospace';
1.850 bisitz 4603: my $data_table_head = $sidebg;
4604: my $data_table_light = '#FAFAFA';
4605: my $data_table_dark = '#F0F0F0';
1.470 banghart 4606: my $data_table_darker = '#CCCCCC';
1.349 albertel 4607: my $data_table_highlight = '#FFFF00';
1.352 albertel 4608: my $mail_new = '#FFBB77';
4609: my $mail_new_hover = '#DD9955';
4610: my $mail_read = '#BBBB77';
4611: my $mail_read_hover = '#999944';
4612: my $mail_replied = '#AAAA88';
4613: my $mail_replied_hover = '#888855';
4614: my $mail_other = '#99BBBB';
4615: my $mail_other_hover = '#669999';
1.391 albertel 4616: my $table_header = '#DDDDDD';
1.489 raeburn 4617: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4618: my $lg_border_color = '#C8C8C8';
1.392 albertel 4619:
1.608 albertel 4620: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4621: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4622: : '0 3px 0 4px';
1.448 albertel 4623:
1.523 albertel 4624:
1.343 albertel 4625: return <<END;
1.795 www 4626: body {
4627: font-family: $sans;
4628: line-height:130%;
4629: font-size:0.83em;
4630: color:$font;
4631: }
4632:
4633: a:link, a:visited {
4634: font-size:100%;
4635: }
4636:
4637: a:focus {
4638: color: red;
4639: background: yellow
4640: }
1.698 harmsja 4641:
1.846 bisitz 4642: hr {
4643: clear: both;
4644: color: $tabbg;
4645: background-color: $tabbg;
4646: height: 3px;
4647: border: none;
4648: }
4649:
1.795 www 4650: form, .inline {
4651: display: inline;
4652: }
1.721 harmsja 4653:
1.795 www 4654: .LC_right {
4655: text-align:right;
4656: }
4657:
4658: .LC_middle {
4659: vertical-align:middle;
4660: }
1.721 harmsja 4661:
4662: /* just for tests */
1.754 droeschl 4663: .LC_400Box {width:400px; }
1.721 harmsja 4664: /* end */
4665:
1.778 bisitz 4666: .LC_filename {
4667: font-family: $mono;
4668: white-space:pre;
4669: }
4670:
4671: .LC_fileicon {
4672: border: none;
4673: height: 1.3em;
4674: vertical-align: text-bottom;
4675: margin-right: 0.3em;
4676: text-decoration:none;
4677: }
4678:
1.350 albertel 4679: .LC_error {
4680: color: red;
4681: font-size: larger;
4682: }
1.795 www 4683:
1.457 albertel 4684: .LC_warning,
4685: .LC_diff_removed {
1.733 bisitz 4686: color: red;
1.394 albertel 4687: }
1.532 albertel 4688:
4689: .LC_info,
1.457 albertel 4690: .LC_success,
4691: .LC_diff_added {
1.350 albertel 4692: color: green;
4693: }
1.795 www 4694:
1.802 bisitz 4695: div.LC_confirm_box {
4696: background-color: #FAFAFA;
4697: border: 1px solid $lg_border_color;
4698: margin-right: 0;
4699: padding: 5px;
4700: }
4701:
4702: div.LC_confirm_box .LC_error img,
4703: div.LC_confirm_box .LC_success img {
4704: vertical-align: middle;
4705: }
4706:
1.440 albertel 4707: .LC_icon {
1.771 droeschl 4708: border: none;
1.790 droeschl 4709: vertical-align: middle;
1.771 droeschl 4710: }
4711:
1.543 albertel 4712: .LC_docs_spacer {
4713: width: 25px;
4714: height: 1px;
1.771 droeschl 4715: border: none;
1.543 albertel 4716: }
1.346 albertel 4717:
1.532 albertel 4718: .LC_internal_info {
1.735 bisitz 4719: color: #999999;
1.532 albertel 4720: }
4721:
1.794 www 4722: .LC_discussion {
4723: background: $tabbg;
4724: border: 1px solid black;
4725: margin: 2px;
4726: }
4727:
4728: .LC_disc_action_links_bar {
4729: background: $tabbg;
1.803 bisitz 4730: border: none;
1.795 www 4731: margin: 4px;
1.794 www 4732: }
4733:
4734: .LC_disc_action_left {
4735: text-align: left;
4736: }
4737:
4738: .LC_disc_action_right {
4739: text-align: right;
4740: }
4741:
4742: .LC_disc_new_item {
4743: background: white;
4744: border: 2px solid red;
4745: margin: 2px;
4746: }
4747:
4748: .LC_disc_old_item {
4749: background: white;
4750: border: 1px solid black;
4751: margin: 2px;
4752: }
4753:
1.458 albertel 4754: table.LC_pastsubmission {
4755: border: 1px solid black;
4756: margin: 2px;
4757: }
4758:
1.795 www 4759: table#LC_top_nav,
4760: table#LC_menubuttons,
4761: table#LC_nav_location {
1.345 albertel 4762: width: 100%;
4763: background: $pgbg;
1.392 albertel 4764: border: 2px;
1.402 albertel 4765: border-collapse: separate;
1.803 bisitz 4766: padding: 0;
1.345 albertel 4767: }
1.392 albertel 4768:
1.801 tempelho 4769: table#LC_title_bar a {
4770: color: $fontmenu;
4771: }
1.836 bisitz 4772:
1.807 droeschl 4773: table#LC_title_bar {
1.819 tempelho 4774: clear: both;
1.836 bisitz 4775: display: none;
1.807 droeschl 4776: }
4777:
1.795 www 4778: table#LC_title_bar,
4779: table.LC_breadcrumbs,
1.393 albertel 4780: table#LC_title_bar.LC_with_remote {
1.359 albertel 4781: width: 100%;
1.392 albertel 4782: border-color: $pgbg;
4783: border-style: solid;
4784: border-width: $border;
1.379 albertel 4785: background: $pgbg;
1.801 tempelho 4786: color: $fontmenu;
1.392 albertel 4787: border-collapse: collapse;
1.803 bisitz 4788: padding: 0;
1.819 tempelho 4789: margin: 0;
1.359 albertel 4790: }
1.795 www 4791:
1.359 albertel 4792: table#LC_title_bar td {
4793: background: $tabbg;
4794: }
1.795 www 4795:
1.706 harmsja 4796: table#LC_menubuttons img{
1.803 bisitz 4797: border: none;
1.346 albertel 4798: }
1.795 www 4799:
1.345 albertel 4800: table#LC_top_nav td {
4801: background: $tabbg;
1.803 bisitz 4802: border: none;
1.407 albertel 4803: font-size: small;
1.706 harmsja 4804: vertical-align:top;
4805: padding:2px 5px 2px 5px;
1.345 albertel 4806: }
1.795 www 4807:
4808: table#LC_top_nav td a,
4809: div#LC_top_nav a {
1.345 albertel 4810: color: $font;
4811: }
1.795 www 4812:
1.364 albertel 4813: table#LC_top_nav td.LC_top_nav_logo {
4814: background: $tabbg;
1.432 albertel 4815: text-align: left;
1.408 albertel 4816: white-space: nowrap;
1.432 albertel 4817: width: 31px;
1.408 albertel 4818: }
1.795 www 4819:
1.408 albertel 4820: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4821: border: none;
1.408 albertel 4822: vertical-align: bottom;
1.364 albertel 4823: }
1.795 www 4824:
1.777 tempelho 4825: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4826: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4827: width: 2.0em;
4828: }
1.795 www 4829:
1.442 albertel 4830: table#LC_top_nav td.LC_top_nav_login {
4831: width: 4.0em;
4832: text-align: center;
4833: }
1.795 www 4834:
1.842 droeschl 4835: .LC_breadcrumbs_component {
4836: float: right;
4837: margin: 0 1em;
1.357 albertel 4838: }
1.842 droeschl 4839: .LC_breadcrumbs_component img {
4840: vertical-align: middle;
1.777 tempelho 4841: }
1.795 www 4842:
1.383 albertel 4843: td.LC_table_cell_checkbox {
4844: text-align: center;
4845: }
1.795 www 4846:
1.779 bisitz 4847: table#LC_mainmenu td.LC_mainmenu_column {
4848: vertical-align: top;
1.777 tempelho 4849: }
1.522 albertel 4850:
1.795 www 4851: .LC_fontsize_small {
1.705 tempelho 4852: font-size: 70%;
4853: }
4854:
1.844 bisitz 4855: #LC_breadcrumbs {
1.819 tempelho 4856: clear:both;
4857: background: $sidebg;
1.822 bisitz 4858: border-bottom: 1px solid $lg_border_color;
1.819 tempelho 4859: line-height: 32px;
1.822 bisitz 4860: margin: 0;
1.819 tempelho 4861: padding: 0;
4862: }
1.862 bisitz 4863:
1.839 droeschl 4864: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4865: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4866: display:none;
4867: }
1.819 tempelho 4868:
1.844 bisitz 4869: #LC_head_subbox {
1.822 bisitz 4870: clear:both;
4871: background: #F8F8F8; /* $sidebg; */
4872: border-bottom: 1px solid $lg_border_color;
4873: margin: 0 0 10px 0;
4874: padding: 5px;
4875: }
4876:
1.795 www 4877: .LC_fontsize_medium {
1.705 tempelho 4878: font-size: 85%;
4879: }
4880:
1.795 www 4881: .LC_fontsize_large {
1.705 tempelho 4882: font-size: 120%;
4883: }
4884:
1.346 albertel 4885: .LC_menubuttons_inline_text {
4886: color: $font;
1.698 harmsja 4887: font-size: 90%;
1.701 harmsja 4888: padding-left:3px;
1.346 albertel 4889: }
4890:
1.526 www 4891: .LC_menubuttons_link {
4892: text-decoration: none;
4893: }
1.795 www 4894:
1.522 albertel 4895: .LC_menubuttons_category {
1.521 www 4896: color: $font;
1.526 www 4897: background: $pgbg;
1.521 www 4898: font-size: larger;
4899: font-weight: bold;
4900: }
4901:
1.346 albertel 4902: td.LC_menubuttons_text {
1.779 bisitz 4903: color: $font;
1.346 albertel 4904: }
1.706 harmsja 4905:
1.346 albertel 4906: .LC_current_location {
4907: background: $tabbg;
4908: }
1.795 www 4909:
1.346 albertel 4910: .LC_new_mail {
1.634 www 4911: background: $tabbg;
1.346 albertel 4912: font-weight: bold;
4913: }
1.347 albertel 4914:
1.795 www 4915: table.LC_data_table,
4916: table.LC_mail_list {
1.347 albertel 4917: border: 1px solid #000000;
1.402 albertel 4918: border-collapse: separate;
1.426 albertel 4919: border-spacing: 1px;
1.610 albertel 4920: background: $pgbg;
1.347 albertel 4921: }
1.795 www 4922:
1.422 albertel 4923: .LC_data_table_dense {
4924: font-size: small;
4925: }
1.795 www 4926:
1.507 raeburn 4927: table.LC_nested_outer {
4928: border: 1px solid #000000;
1.589 raeburn 4929: border-collapse: collapse;
1.803 bisitz 4930: border-spacing: 0;
1.507 raeburn 4931: width: 100%;
4932: }
1.795 www 4933:
1.507 raeburn 4934: table.LC_nested {
1.803 bisitz 4935: border: none;
1.589 raeburn 4936: border-collapse: collapse;
1.803 bisitz 4937: border-spacing: 0;
1.507 raeburn 4938: width: 100%;
4939: }
1.795 www 4940:
4941: table.LC_data_table tr th,
4942: table.LC_calendar tr th,
4943: table.LC_mail_list tr th,
1.523 albertel 4944: table.LC_prior_tries tr th {
1.349 albertel 4945: font-weight: bold;
4946: background-color: $data_table_head;
1.801 tempelho 4947: color:$fontmenu;
1.701 harmsja 4948: font-size:90%;
1.347 albertel 4949: }
1.795 www 4950:
1.711 raeburn 4951: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4952: background-color: #CCCCCC;
1.711 raeburn 4953: font-weight: bold;
4954: text-align: left;
4955: }
1.795 www 4956:
1.779 bisitz 4957: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4958: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4959: background-color: $data_table_light;
1.425 albertel 4960: padding: 2px;
1.347 albertel 4961: }
1.795 www 4962:
1.610 albertel 4963: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4964: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4965: background-color: $data_table_dark;
1.709 bisitz 4966: padding: 2px;
1.347 albertel 4967: }
1.795 www 4968:
1.425 albertel 4969: table.LC_data_table tr.LC_data_table_highlight td {
4970: background-color: $data_table_darker;
4971: }
1.795 www 4972:
1.639 raeburn 4973: table.LC_data_table tr td.LC_leftcol_header {
4974: background-color: $data_table_head;
4975: font-weight: bold;
4976: }
1.795 www 4977:
1.451 albertel 4978: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4979: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4980: background-color: #FFFFFF;
1.421 albertel 4981: font-weight: bold;
4982: font-style: italic;
4983: text-align: center;
4984: padding: 8px;
1.347 albertel 4985: }
1.795 www 4986:
1.507 raeburn 4987: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4988: padding: 4ex
4989: }
1.795 www 4990:
1.507 raeburn 4991: table.LC_nested_outer tr th {
4992: font-weight: bold;
1.801 tempelho 4993: color:$fontmenu;
1.507 raeburn 4994: background-color: $data_table_head;
1.701 harmsja 4995: font-size: small;
1.507 raeburn 4996: border-bottom: 1px solid #000000;
4997: }
1.795 www 4998:
1.507 raeburn 4999: table.LC_nested_outer tr td.LC_subheader {
5000: background-color: $data_table_head;
5001: font-weight: bold;
5002: font-size: small;
5003: border-bottom: 1px solid #000000;
5004: text-align: right;
1.451 albertel 5005: }
1.795 www 5006:
1.507 raeburn 5007: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5008: background-color: #CCCCCC;
1.451 albertel 5009: font-weight: bold;
5010: font-size: small;
1.507 raeburn 5011: text-align: center;
5012: }
1.795 www 5013:
1.589 raeburn 5014: table.LC_nested tr.LC_info_row td.LC_left_item,
5015: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5016: text-align: left;
1.451 albertel 5017: }
1.795 www 5018:
1.507 raeburn 5019: table.LC_nested td {
1.735 bisitz 5020: background-color: #FFFFFF;
1.451 albertel 5021: font-size: small;
1.507 raeburn 5022: }
1.795 www 5023:
1.507 raeburn 5024: table.LC_nested_outer tr th.LC_right_item,
5025: table.LC_nested tr.LC_info_row td.LC_right_item,
5026: table.LC_nested tr.LC_odd_row td.LC_right_item,
5027: table.LC_nested tr td.LC_right_item {
1.451 albertel 5028: text-align: right;
5029: }
5030:
1.507 raeburn 5031: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5032: background-color: #EEEEEE;
1.451 albertel 5033: }
5034:
1.473 raeburn 5035: table.LC_createuser {
5036: }
5037:
5038: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5039: font-size: small;
1.473 raeburn 5040: }
5041:
5042: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5043: background-color: #CCCCCC;
1.473 raeburn 5044: font-weight: bold;
5045: text-align: center;
5046: }
5047:
1.349 albertel 5048: table.LC_calendar {
5049: border: 1px solid #000000;
5050: border-collapse: collapse;
5051: }
1.795 www 5052:
1.349 albertel 5053: table.LC_calendar_pickdate {
5054: font-size: xx-small;
5055: }
1.795 www 5056:
1.349 albertel 5057: table.LC_calendar tr td {
5058: border: 1px solid #000000;
5059: vertical-align: top;
5060: }
1.795 www 5061:
1.349 albertel 5062: table.LC_calendar tr td.LC_calendar_day_empty {
5063: background-color: $data_table_dark;
5064: }
1.795 www 5065:
1.779 bisitz 5066: table.LC_calendar tr td.LC_calendar_day_current {
5067: background-color: $data_table_highlight;
1.777 tempelho 5068: }
1.795 www 5069:
1.349 albertel 5070: table.LC_mail_list tr.LC_mail_new {
5071: background-color: $mail_new;
5072: }
1.795 www 5073:
1.349 albertel 5074: table.LC_mail_list tr.LC_mail_new:hover {
5075: background-color: $mail_new_hover;
5076: }
1.795 www 5077:
5078: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5079: }
1.795 www 5080:
5081: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5082: }
1.795 www 5083:
1.349 albertel 5084: table.LC_mail_list tr.LC_mail_read {
5085: background-color: $mail_read;
5086: }
1.795 www 5087:
1.349 albertel 5088: table.LC_mail_list tr.LC_mail_read:hover {
5089: background-color: $mail_read_hover;
5090: }
1.795 www 5091:
1.349 albertel 5092: table.LC_mail_list tr.LC_mail_replied {
5093: background-color: $mail_replied;
5094: }
1.795 www 5095:
1.349 albertel 5096: table.LC_mail_list tr.LC_mail_replied:hover {
5097: background-color: $mail_replied_hover;
5098: }
1.795 www 5099:
1.349 albertel 5100: table.LC_mail_list tr.LC_mail_other {
5101: background-color: $mail_other;
5102: }
1.795 www 5103:
1.349 albertel 5104: table.LC_mail_list tr.LC_mail_other:hover {
5105: background-color: $mail_other_hover;
5106: }
1.494 raeburn 5107:
1.777 tempelho 5108: table.LC_data_table tr > td.LC_browser_file,
5109: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5110: background: #CCFF88;
5111: }
1.795 www 5112:
1.777 tempelho 5113: table.LC_data_table tr > td.LC_browser_file_locked,
5114: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5115: background: #FFAA99;
1.387 albertel 5116: }
1.795 www 5117:
1.777 tempelho 5118: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5119: background: #AAAAAA;
5120: }
1.795 www 5121:
1.777 tempelho 5122: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5123: table.LC_data_table tr > td.LC_browser_file_metamodified {
5124: background: #FFFF77;
1.777 tempelho 5125: }
1.795 www 5126:
1.696 bisitz 5127: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5128: background: #CCCCFF;
1.387 albertel 5129: }
1.696 bisitz 5130:
1.707 bisitz 5131: table.LC_data_table tr > td.LC_roles_is {
5132: /* background: #77FF77; */
5133: }
1.795 www 5134:
1.707 bisitz 5135: table.LC_data_table tr > td.LC_roles_future {
5136: background: #FFFF77;
5137: }
1.795 www 5138:
1.707 bisitz 5139: table.LC_data_table tr > td.LC_roles_will {
5140: background: #FFAA77;
5141: }
1.795 www 5142:
1.707 bisitz 5143: table.LC_data_table tr > td.LC_roles_expired {
5144: background: #FF7777;
5145: }
1.795 www 5146:
1.707 bisitz 5147: table.LC_data_table tr > td.LC_roles_will_not {
5148: background: #AAFF77;
5149: }
1.795 www 5150:
1.707 bisitz 5151: table.LC_data_table tr > td.LC_roles_selected {
5152: background: #11CC55;
5153: }
5154:
1.388 albertel 5155: span.LC_current_location {
1.701 harmsja 5156: font-size:larger;
1.388 albertel 5157: background: $pgbg;
5158: }
1.387 albertel 5159:
1.395 albertel 5160: span.LC_parm_menu_item {
5161: font-size: larger;
5162: }
1.795 www 5163:
1.395 albertel 5164: span.LC_parm_scope_all {
5165: color: red;
5166: }
1.795 www 5167:
1.395 albertel 5168: span.LC_parm_scope_folder {
5169: color: green;
5170: }
1.795 www 5171:
1.395 albertel 5172: span.LC_parm_scope_resource {
5173: color: orange;
5174: }
1.795 www 5175:
1.395 albertel 5176: span.LC_parm_part {
5177: color: blue;
5178: }
1.795 www 5179:
1.395 albertel 5180: span.LC_parm_folder, span.LC_parm_symb {
5181: font-size: x-small;
5182: font-family: $mono;
5183: color: #AAAAAA;
5184: }
5185:
1.795 www 5186: td.LC_parm_overview_level_menu,
5187: td.LC_parm_overview_map_menu,
5188: td.LC_parm_overview_parm_selectors,
5189: td.LC_parm_overview_restrictions {
1.396 albertel 5190: border: 1px solid black;
5191: border-collapse: collapse;
5192: }
1.795 www 5193:
1.396 albertel 5194: table.LC_parm_overview_restrictions td {
5195: border-width: 1px 4px 1px 4px;
5196: border-style: solid;
5197: border-color: $pgbg;
5198: text-align: center;
5199: }
1.795 www 5200:
1.396 albertel 5201: table.LC_parm_overview_restrictions th {
5202: background: $tabbg;
5203: border-width: 1px 4px 1px 4px;
5204: border-style: solid;
5205: border-color: $pgbg;
5206: }
1.795 www 5207:
1.398 albertel 5208: table#LC_helpmenu {
1.803 bisitz 5209: border: none;
1.398 albertel 5210: height: 55px;
1.803 bisitz 5211: border-spacing: 0;
1.398 albertel 5212: }
5213:
5214: table#LC_helpmenu fieldset legend {
5215: font-size: larger;
5216: }
1.795 www 5217:
1.397 albertel 5218: table#LC_helpmenu_links {
5219: width: 100%;
5220: border: 1px solid black;
5221: background: $pgbg;
1.803 bisitz 5222: padding: 0;
1.397 albertel 5223: border-spacing: 1px;
5224: }
1.795 www 5225:
1.397 albertel 5226: table#LC_helpmenu_links tr td {
5227: padding: 1px;
5228: background: $tabbg;
1.399 albertel 5229: text-align: center;
5230: font-weight: bold;
1.397 albertel 5231: }
1.396 albertel 5232:
1.795 www 5233: table#LC_helpmenu_links a:link,
5234: table#LC_helpmenu_links a:visited,
1.397 albertel 5235: table#LC_helpmenu_links a:active {
5236: text-decoration: none;
5237: color: $font;
5238: }
1.795 www 5239:
1.397 albertel 5240: table#LC_helpmenu_links a:hover {
5241: text-decoration: underline;
5242: color: $vlink;
5243: }
1.396 albertel 5244:
1.417 albertel 5245: .LC_chrt_popup_exists {
5246: border: 1px solid #339933;
5247: margin: -1px;
5248: }
1.795 www 5249:
1.417 albertel 5250: .LC_chrt_popup_up {
5251: border: 1px solid yellow;
5252: margin: -1px;
5253: }
1.795 www 5254:
1.417 albertel 5255: .LC_chrt_popup {
5256: border: 1px solid #8888FF;
5257: background: #CCCCFF;
5258: }
1.795 www 5259:
1.421 albertel 5260: table.LC_pick_box {
5261: border-collapse: separate;
5262: background: white;
5263: border: 1px solid black;
5264: border-spacing: 1px;
5265: }
1.795 www 5266:
1.421 albertel 5267: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5268: background: $sidebg;
1.421 albertel 5269: font-weight: bold;
5270: text-align: right;
1.740 bisitz 5271: vertical-align: top;
1.421 albertel 5272: width: 184px;
5273: padding: 8px;
5274: }
1.795 www 5275:
1.579 raeburn 5276: table.LC_pick_box td.LC_pick_box_value {
5277: text-align: left;
5278: padding: 8px;
5279: }
1.795 www 5280:
1.579 raeburn 5281: table.LC_pick_box td.LC_pick_box_select {
5282: text-align: left;
5283: padding: 8px;
5284: }
1.795 www 5285:
1.424 albertel 5286: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5287: padding: 0;
1.421 albertel 5288: height: 1px;
5289: background: black;
5290: }
1.795 www 5291:
1.421 albertel 5292: table.LC_pick_box td.LC_pick_box_submit {
5293: text-align: right;
5294: }
1.795 www 5295:
1.579 raeburn 5296: table.LC_pick_box td.LC_evenrow_value {
5297: text-align: left;
5298: padding: 8px;
5299: background-color: $data_table_light;
5300: }
1.795 www 5301:
1.579 raeburn 5302: table.LC_pick_box td.LC_oddrow_value {
5303: text-align: left;
5304: padding: 8px;
5305: background-color: $data_table_light;
5306: }
1.795 www 5307:
1.579 raeburn 5308: table.LC_helpform_receipt {
5309: width: 620px;
5310: border-collapse: separate;
5311: background: white;
5312: border: 1px solid black;
5313: border-spacing: 1px;
5314: }
1.795 www 5315:
1.579 raeburn 5316: table.LC_helpform_receipt td.LC_pick_box_title {
5317: background: $tabbg;
5318: font-weight: bold;
5319: text-align: right;
5320: width: 184px;
5321: padding: 8px;
5322: }
1.795 www 5323:
1.579 raeburn 5324: table.LC_helpform_receipt td.LC_evenrow_value {
5325: text-align: left;
5326: padding: 8px;
5327: background-color: $data_table_light;
5328: }
1.795 www 5329:
1.579 raeburn 5330: table.LC_helpform_receipt td.LC_oddrow_value {
5331: text-align: left;
5332: padding: 8px;
5333: background-color: $data_table_light;
5334: }
1.795 www 5335:
1.579 raeburn 5336: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5337: padding: 0;
1.579 raeburn 5338: height: 1px;
5339: background: black;
5340: }
1.795 www 5341:
1.579 raeburn 5342: span.LC_helpform_receipt_cat {
5343: font-weight: bold;
5344: }
1.795 www 5345:
1.424 albertel 5346: table.LC_group_priv_box {
5347: background: white;
5348: border: 1px solid black;
5349: border-spacing: 1px;
5350: }
1.795 www 5351:
1.424 albertel 5352: table.LC_group_priv_box td.LC_pick_box_title {
5353: background: $tabbg;
5354: font-weight: bold;
5355: text-align: right;
5356: width: 184px;
5357: }
1.795 www 5358:
1.424 albertel 5359: table.LC_group_priv_box td.LC_groups_fixed {
5360: background: $data_table_light;
5361: text-align: center;
5362: }
1.795 www 5363:
1.424 albertel 5364: table.LC_group_priv_box td.LC_groups_optional {
5365: background: $data_table_dark;
5366: text-align: center;
5367: }
1.795 www 5368:
1.424 albertel 5369: table.LC_group_priv_box td.LC_groups_functionality {
5370: background: $data_table_darker;
5371: text-align: center;
5372: font-weight: bold;
5373: }
1.795 www 5374:
1.424 albertel 5375: table.LC_group_priv td {
5376: text-align: left;
1.803 bisitz 5377: padding: 0;
1.424 albertel 5378: }
5379:
1.421 albertel 5380: table.LC_notify_front_page {
5381: background: white;
5382: border: 1px solid black;
5383: padding: 8px;
5384: }
1.795 www 5385:
1.421 albertel 5386: table.LC_notify_front_page td {
5387: padding: 8px;
5388: }
1.795 www 5389:
1.424 albertel 5390: .LC_navbuttons {
5391: margin: 2ex 0ex 2ex 0ex;
5392: }
1.795 www 5393:
1.423 albertel 5394: .LC_topic_bar {
5395: font-weight: bold;
5396: width: 100%;
5397: background: $tabbg;
5398: vertical-align: middle;
5399: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5400: padding: 3px;
1.423 albertel 5401: }
1.795 www 5402:
1.423 albertel 5403: .LC_topic_bar span {
5404: vertical-align: middle;
5405: }
1.795 www 5406:
1.423 albertel 5407: .LC_topic_bar img {
5408: vertical-align: bottom;
5409: }
1.795 www 5410:
1.423 albertel 5411: table.LC_course_group_status {
5412: margin: 20px;
5413: }
1.795 www 5414:
1.423 albertel 5415: table.LC_status_selector td {
5416: vertical-align: top;
5417: text-align: center;
1.424 albertel 5418: padding: 4px;
5419: }
1.795 www 5420:
1.599 albertel 5421: div.LC_feedback_link {
1.616 albertel 5422: clear: both;
1.829 kalberla 5423: background: $sidebg;
1.779 bisitz 5424: width: 100%;
1.829 kalberla 5425: padding-bottom: 10px;
5426: border: 1px $tabbg solid;
1.833 kalberla 5427: height: 22px;
5428: line-height: 22px;
5429: padding-top: 5px;
5430: }
5431:
5432: div.LC_feedback_link img {
5433: height: 22px;
1.867 kalberla 5434: vertical-align:middle;
1.829 kalberla 5435: }
5436:
5437: div.LC_feedback_link a{
5438: text-decoration: none;
1.489 raeburn 5439: }
1.795 www 5440:
1.867 kalberla 5441: div.LC_comblock {
5442: display:inline;
5443: color:$font;
5444: font-size:90%;
5445: }
5446:
5447: div.LC_feedback_link div.LC_comblock {
5448: padding-left:5px;
5449: }
5450:
5451: div.LC_feedback_link div.LC_comblock a {
5452: color:$font;
5453: }
5454:
1.489 raeburn 5455: span.LC_feedback_link {
1.858 bisitz 5456: /* background: $feedback_link_bg; */
1.599 albertel 5457: font-size: larger;
5458: }
1.795 www 5459:
1.599 albertel 5460: span.LC_message_link {
1.858 bisitz 5461: /* background: $feedback_link_bg; */
1.599 albertel 5462: font-size: larger;
5463: position: absolute;
5464: right: 1em;
1.489 raeburn 5465: }
1.421 albertel 5466:
1.515 albertel 5467: table.LC_prior_tries {
1.524 albertel 5468: border: 1px solid #000000;
5469: border-collapse: separate;
5470: border-spacing: 1px;
1.515 albertel 5471: }
1.523 albertel 5472:
1.515 albertel 5473: table.LC_prior_tries td {
1.524 albertel 5474: padding: 2px;
1.515 albertel 5475: }
1.523 albertel 5476:
5477: .LC_answer_correct {
1.795 www 5478: background: lightgreen;
5479: color: darkgreen;
5480: padding: 6px;
1.523 albertel 5481: }
1.795 www 5482:
1.523 albertel 5483: .LC_answer_charged_try {
1.797 www 5484: background: #FFAAAA;
1.795 www 5485: color: darkred;
5486: padding: 6px;
1.523 albertel 5487: }
1.795 www 5488:
1.779 bisitz 5489: .LC_answer_not_charged_try,
1.523 albertel 5490: .LC_answer_no_grade,
5491: .LC_answer_late {
1.795 www 5492: background: lightyellow;
1.523 albertel 5493: color: black;
1.795 www 5494: padding: 6px;
1.523 albertel 5495: }
1.795 www 5496:
1.523 albertel 5497: .LC_answer_previous {
1.795 www 5498: background: lightblue;
5499: color: darkblue;
5500: padding: 6px;
1.523 albertel 5501: }
1.795 www 5502:
1.779 bisitz 5503: .LC_answer_no_message {
1.777 tempelho 5504: background: #FFFFFF;
5505: color: black;
1.795 www 5506: padding: 6px;
1.779 bisitz 5507: }
1.795 www 5508:
1.779 bisitz 5509: .LC_answer_unknown {
5510: background: orange;
5511: color: black;
1.795 www 5512: padding: 6px;
1.777 tempelho 5513: }
1.795 www 5514:
1.529 albertel 5515: span.LC_prior_numerical,
5516: span.LC_prior_string,
5517: span.LC_prior_custom,
5518: span.LC_prior_reaction,
5519: span.LC_prior_math {
1.523 albertel 5520: font-family: monospace;
5521: white-space: pre;
5522: }
5523:
1.525 albertel 5524: span.LC_prior_string {
5525: font-family: monospace;
5526: white-space: pre;
5527: }
5528:
1.523 albertel 5529: table.LC_prior_option {
5530: width: 100%;
5531: border-collapse: collapse;
5532: }
1.795 www 5533:
5534: table.LC_prior_rank,
5535: table.LC_prior_match {
1.528 albertel 5536: border-collapse: collapse;
5537: }
1.795 www 5538:
1.528 albertel 5539: table.LC_prior_option tr td,
5540: table.LC_prior_rank tr td,
5541: table.LC_prior_match tr td {
1.524 albertel 5542: border: 1px solid #000000;
1.515 albertel 5543: }
5544:
1.855 bisitz 5545: .LC_nobreak {
1.544 albertel 5546: white-space: nowrap;
1.519 raeburn 5547: }
5548:
1.576 raeburn 5549: span.LC_cusr_emph {
5550: font-style: italic;
5551: }
5552:
1.633 raeburn 5553: span.LC_cusr_subheading {
5554: font-weight: normal;
5555: font-size: 85%;
5556: }
5557:
1.545 albertel 5558: table.LC_docs_documents {
5559: background: #BBBBBB;
1.803 bisitz 5560: border-width: 0;
1.545 albertel 5561: border-collapse: collapse;
5562: }
1.795 www 5563:
1.777 tempelho 5564: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5565: border: 2px solid black;
5566: padding: 4px;
1.777 tempelho 5567: }
1.795 www 5568:
1.861 bisitz 5569: div.LC_docs_entry_move {
1.859 bisitz 5570: border: 1px solid #BBBBBB;
1.545 albertel 5571: background: #DDDDDD;
1.861 bisitz 5572: width: 22px;
1.859 bisitz 5573: padding: 1px;
5574: margin: 0;
1.545 albertel 5575: }
5576:
1.861 bisitz 5577: table.LC_data_table tr > td.LC_docs_entry_commands,
5578: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5579: background: #DDDDDD;
5580: font-size: x-small;
5581: }
1.795 www 5582:
1.861 bisitz 5583: .LC_docs_entry_parameter {
5584: white-space: nowrap;
5585: }
5586:
1.544 albertel 5587: .LC_docs_copy {
1.545 albertel 5588: color: #000099;
1.544 albertel 5589: }
1.795 www 5590:
1.544 albertel 5591: .LC_docs_cut {
1.545 albertel 5592: color: #550044;
1.544 albertel 5593: }
1.795 www 5594:
1.544 albertel 5595: .LC_docs_rename {
1.545 albertel 5596: color: #009900;
1.544 albertel 5597: }
1.795 www 5598:
1.544 albertel 5599: .LC_docs_remove {
1.545 albertel 5600: color: #990000;
5601: }
5602:
1.547 albertel 5603: .LC_docs_reinit_warn,
5604: .LC_docs_ext_edit {
5605: font-size: x-small;
5606: }
5607:
1.545 albertel 5608: table.LC_docs_adddocs td,
5609: table.LC_docs_adddocs th {
5610: border: 1px solid #BBBBBB;
5611: padding: 4px;
5612: background: #DDDDDD;
1.543 albertel 5613: }
5614:
1.584 albertel 5615: table.LC_sty_begin {
5616: background: #BBFFBB;
5617: }
1.795 www 5618:
1.584 albertel 5619: table.LC_sty_end {
5620: background: #FFBBBB;
5621: }
5622:
1.589 raeburn 5623: table.LC_double_column {
1.803 bisitz 5624: border-width: 0;
1.589 raeburn 5625: border-collapse: collapse;
5626: width: 100%;
5627: padding: 2px;
5628: }
5629:
5630: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5631: top: 2px;
1.589 raeburn 5632: left: 2px;
5633: width: 47%;
5634: vertical-align: top;
5635: }
5636:
5637: table.LC_double_column tr td.LC_right_col {
5638: top: 2px;
1.779 bisitz 5639: right: 2px;
1.589 raeburn 5640: width: 47%;
5641: vertical-align: top;
5642: }
5643:
1.591 raeburn 5644: div.LC_left_float {
5645: float: left;
5646: padding-right: 5%;
1.597 albertel 5647: padding-bottom: 4px;
1.591 raeburn 5648: }
5649:
5650: div.LC_clear_float_header {
1.597 albertel 5651: padding-bottom: 2px;
1.591 raeburn 5652: }
5653:
5654: div.LC_clear_float_footer {
1.597 albertel 5655: padding-top: 10px;
1.591 raeburn 5656: clear: both;
5657: }
5658:
1.597 albertel 5659: div.LC_grade_show_user {
5660: margin-top: 20px;
5661: border: 1px solid black;
5662: }
1.795 www 5663:
1.597 albertel 5664: div.LC_grade_user_name {
5665: background: #DDDDEE;
5666: border-bottom: 1px solid black;
1.705 tempelho 5667: font-weight: bold;
5668: font-size: large;
1.597 albertel 5669: }
1.795 www 5670:
1.597 albertel 5671: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5672: background: #DDEEDD;
5673: }
5674:
5675: div.LC_grade_show_problem,
5676: div.LC_grade_submissions,
5677: div.LC_grade_message_center,
5678: div.LC_grade_info_links,
5679: div.LC_grade_assign {
5680: margin: 5px;
5681: width: 99%;
5682: background: #FFFFFF;
5683: }
1.795 www 5684:
1.597 albertel 5685: div.LC_grade_show_problem_header,
5686: div.LC_grade_submissions_header,
5687: div.LC_grade_message_center_header,
5688: div.LC_grade_assign_header {
1.705 tempelho 5689: font-weight: bold;
5690: font-size: large;
1.597 albertel 5691: }
1.795 www 5692:
1.597 albertel 5693: div.LC_grade_show_problem_problem,
5694: div.LC_grade_submissions_body,
5695: div.LC_grade_message_center_body,
5696: div.LC_grade_assign_body {
5697: border: 1px solid black;
5698: width: 99%;
5699: background: #FFFFFF;
5700: }
1.795 www 5701:
1.598 albertel 5702: span.LC_grade_check_note {
1.705 tempelho 5703: font-weight: normal;
5704: font-size: medium;
1.598 albertel 5705: display: inline;
5706: position: absolute;
5707: right: 1em;
5708: }
1.597 albertel 5709:
1.613 albertel 5710: table.LC_scantron_action {
5711: width: 100%;
5712: }
1.795 www 5713:
1.613 albertel 5714: table.LC_scantron_action tr th {
1.698 harmsja 5715: font-weight:bold;
5716: font-style:normal;
1.613 albertel 5717: }
1.795 www 5718:
1.779 bisitz 5719: .LC_edit_problem_header,
1.614 albertel 5720: div.LC_edit_problem_footer {
1.705 tempelho 5721: font-weight: normal;
5722: font-size: medium;
1.602 albertel 5723: margin: 2px;
1.600 albertel 5724: }
1.795 www 5725:
1.600 albertel 5726: div.LC_edit_problem_header,
1.602 albertel 5727: div.LC_edit_problem_header div,
1.614 albertel 5728: div.LC_edit_problem_footer,
5729: div.LC_edit_problem_footer div,
1.602 albertel 5730: div.LC_edit_problem_editxml_header,
5731: div.LC_edit_problem_editxml_header div {
1.600 albertel 5732: margin-top: 5px;
5733: }
1.795 www 5734:
1.600 albertel 5735: div.LC_edit_problem_header_title {
1.705 tempelho 5736: font-weight: bold;
5737: font-size: larger;
1.602 albertel 5738: background: $tabbg;
5739: padding: 3px;
5740: }
1.795 www 5741:
1.602 albertel 5742: table.LC_edit_problem_header_title {
1.705 tempelho 5743: font-size: larger;
5744: font-weight: bold;
1.602 albertel 5745: width: 100%;
5746: border-color: $pgbg;
5747: border-style: solid;
5748: border-width: $border;
1.600 albertel 5749: background: $tabbg;
1.602 albertel 5750: border-collapse: collapse;
1.803 bisitz 5751: padding: 0;
1.602 albertel 5752: }
5753:
5754: div.LC_edit_problem_discards {
5755: float: left;
5756: padding-bottom: 5px;
5757: }
1.795 www 5758:
1.602 albertel 5759: div.LC_edit_problem_saves {
5760: float: right;
5761: padding-bottom: 5px;
1.600 albertel 5762: }
1.795 www 5763:
1.679 riegler 5764: img.stift{
1.803 bisitz 5765: border-width: 0;
5766: vertical-align: middle;
1.677 riegler 5767: }
1.680 riegler 5768:
1.681 riegler 5769: table#LC_mainmenu{
5770: margin-top:10px;
5771: width:80%;
5772: }
5773:
1.680 riegler 5774: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5775: vertical-align: top;
5776: width: 45%;
5777: }
1.795 www 5778:
1.779 bisitz 5779: .LC_mainmenu_fieldset_category {
5780: color: $font;
5781: background: $pgbg;
5782: font-size: small;
5783: font-weight: bold;
1.777 tempelho 5784: }
1.795 www 5785:
1.716 raeburn 5786: div.LC_createcourse {
5787: margin: 10px 10px 10px 10px;
5788: }
5789:
1.693 droeschl 5790: /* ---- Remove when done ----
5791: # The following styles is part of the redesign of LON-CAPA and are
5792: # subject to change during this project.
5793: # Don't rely on their current functionality as they might be
5794: # changed or removed.
5795: # --------------------------*/
5796:
1.698 harmsja 5797: a:hover,
1.721 harmsja 5798: ol.LC_smallMenu a:hover,
5799: ol#LC_MenuBreadcrumbs a:hover,
5800: ol#LC_PathBreadcrumbs a:hover,
5801: ul#LC_TabMainMenuContent a:hover,
5802: .LC_FormSectionClearButton input:hover
1.795 www 5803: ul.LC_TabContent li:hover a {
1.698 harmsja 5804: color:#BF2317;
5805: text-decoration:none;
1.693 droeschl 5806: }
5807:
1.779 bisitz 5808: h1 {
1.813 bisitz 5809: padding: 0;
1.693 droeschl 5810: line-height:130%;
5811: }
1.698 harmsja 5812:
1.795 www 5813: h2,h3,h4,h5,h6 {
1.803 bisitz 5814: margin: 5px 0 5px 0;
5815: padding: 0;
1.721 harmsja 5816: line-height:130%;
1.693 droeschl 5817: }
1.795 www 5818:
5819: .LC_hcell {
1.698 harmsja 5820: padding:3px 15px 3px 15px;
1.803 bisitz 5821: margin: 0;
1.703 harmsja 5822: background-color:$tabbg;
1.801 tempelho 5823: color:$fontmenu;
1.779 bisitz 5824: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5825: }
1.795 www 5826:
1.840 bisitz 5827: .LC_Box > .LC_hcell {
1.847 tempelho 5828: margin: 0 -10px 10px -10px;
1.835 bisitz 5829: }
5830:
1.721 harmsja 5831: .LC_noBorder {
1.803 bisitz 5832: border: 0;
1.698 harmsja 5833: }
1.693 droeschl 5834:
1.761 tempelho 5835: .LC_Right {
5836: float: right;
1.803 bisitz 5837: margin: 0;
5838: padding: 0;
1.761 tempelho 5839: }
5840:
1.721 harmsja 5841: .LC_FormSectionClearButton input {
1.779 bisitz 5842: background-color:transparent;
1.803 bisitz 5843: border: none;
1.698 harmsja 5844: cursor:pointer;
5845: text-decoration:underline;
1.693 droeschl 5846: }
1.763 bisitz 5847:
5848: .LC_help_open_topic {
5849: color: #FFFFFF;
5850: background-color: #EEEEFF;
5851: margin: 1px;
5852: padding: 4px;
5853: border: 1px solid #000033;
5854: white-space: nowrap;
1.783 amueller 5855: /* vertical-align: middle; */
1.759 neumanie 5856: }
1.693 droeschl 5857:
1.698 harmsja 5858: dl,ul,div,fieldset {
1.803 bisitz 5859: margin: 10px 10px 10px 0;
1.806 bisitz 5860: /* overflow: hidden; */
1.693 droeschl 5861: }
1.795 www 5862:
1.838 bisitz 5863: fieldset > legend {
5864: font-weight: bold;
5865: padding: 0 5px 0 5px;
5866: }
5867:
1.813 bisitz 5868: #LC_nav_bar {
1.807 droeschl 5869: float: left;
1.852 droeschl 5870: margin: 0.2em 0 0 0;
1.807 droeschl 5871: }
5872:
1.813 bisitz 5873: #LC_nav_bar em{
1.807 droeschl 5874: font-weight: bold;
5875: font-style: normal;
5876: }
5877:
5878: ol.LC_smallMenu {
5879: float: right;
1.852 droeschl 5880: margin: 0.2em 0 0 0;
1.807 droeschl 5881: }
5882:
1.852 droeschl 5883: ol#LC_PathBreadcrumbs {
1.803 bisitz 5884: margin: 0;
1.693 droeschl 5885: }
5886:
1.721 harmsja 5887: ol.LC_smallMenu li {
1.693 droeschl 5888: display: inline;
1.803 bisitz 5889: padding: 5px 5px 0 10px;
1.693 droeschl 5890: vertical-align: top;
5891: }
5892:
1.721 harmsja 5893: ol.LC_smallMenu li img {
1.693 droeschl 5894: vertical-align: bottom;
5895: }
5896:
1.721 harmsja 5897: ol.LC_smallMenu a {
1.693 droeschl 5898: font-size: 90%;
5899: color: RGB(80, 80, 80);
5900: text-decoration: none;
5901: }
1.795 www 5902:
1.808 droeschl 5903: ul#LC_TabMainMenuContent {
1.807 droeschl 5904: clear: both;
1.808 droeschl 5905: color: $fontmenu;
5906: background: $tabbg;
5907: list-style: none;
5908: padding: 0;
5909: margin: 0;
5910: width: 100%;
5911: }
5912:
5913: ul#LC_TabMainMenuContent li {
5914: font-weight: bold;
5915: line-height: 1.8em;
5916: padding: 0 0.8em;
5917: border-right: 1px solid black;
5918: display: inline;
5919: vertical-align: middle;
1.807 droeschl 5920: }
5921:
1.847 tempelho 5922: ul.LC_TabContent {
1.721 harmsja 5923: display:block;
1.847 tempelho 5924: background: $sidebg;
1.858 bisitz 5925: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5926: list-style:none;
1.870 tempelho 5927: margin: 0 -10px;
1.803 bisitz 5928: padding: 0;
1.693 droeschl 5929: }
5930:
1.795 www 5931: ul.LC_TabContent li,
5932: ul.LC_TabContentBigger li {
1.741 harmsja 5933: float:left;
5934: }
1.795 www 5935:
1.808 droeschl 5936: ul#LC_TabMainMenuContent li a {
5937: color: $fontmenu;
1.693 droeschl 5938: text-decoration: none;
5939: }
1.795 www 5940:
1.721 harmsja 5941: ul.LC_TabContent {
1.847 tempelho 5942: min-height:1.5em;
1.721 harmsja 5943: }
1.795 www 5944:
5945: ul.LC_TabContent li {
1.741 harmsja 5946: vertical-align:middle;
1.803 bisitz 5947: padding: 0 10px 0 10px;
1.745 ehlerst 5948: background-color:$tabbg;
5949: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5950: }
1.795 www 5951:
1.847 tempelho 5952: ul.LC_TabContent .right {
5953: float:right;
5954: }
5955:
1.795 www 5956: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5957: color:rgb(47,47,47);
5958: text-decoration:none;
5959: font-size:95%;
5960: font-weight:bold;
1.761 tempelho 5961: padding-right: 16px;
1.721 harmsja 5962: }
1.795 www 5963:
5964: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5965: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5966: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5967: padding-right: 16px;
1.744 ehlerst 5968: }
1.795 www 5969:
1.870 tempelho 5970: #maincoursedoc {
5971: clear:both;
5972: }
5973:
5974: ul.LC_TabContentBigger {
5975: display:block;
5976: list-style:none;
5977: padding: 0;
5978: }
5979:
1.795 www 5980: ul.LC_TabContentBigger li {
1.870 tempelho 5981: vertical-align:bottom;
5982: height: 30px;
5983: font-size:110%;
5984: font-weight:bold;
5985: color: #737373;
1.841 tempelho 5986: }
5987:
1.870 tempelho 5988:
5989: ul.LC_TabContentBigger li a {
5990: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
5991: height: 30px;
5992: line-height: 30px;
5993: text-align: center;
5994: display: block;
5995: text-decoration: none;
1.741 harmsja 5996: }
1.795 www 5997:
1.870 tempelho 5998: ul.LC_TabContentBigger li:hover a,
5999: ul.LC_TabContentBigger li.active a {
6000: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857 tempelho 6001: color:$font;
1.870 tempelho 6002: text-decoration: underline;
1.744 ehlerst 6003: }
1.795 www 6004:
1.870 tempelho 6005:
6006: ul.LC_TabContentBigger li b {
6007: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6008: display: block;
6009: float: left;
6010: padding: 0 30px;
6011: }
6012:
6013: ul.LC_TabContentBigger li:hover b,
6014: ul.LC_TabContentBigger li.active b {
6015: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6016: color:$font;
6017: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6018: }
1.693 droeschl 6019:
1.870 tempelho 6020:
1.862 bisitz 6021: ul.LC_CourseBreadcrumbs {
6022: background: $sidebg;
6023: line-height: 32px;
6024: padding-left: 10px;
6025: margin: 0 0 10px 0;
6026: list-style-position: inside;
6027:
6028: }
6029:
1.795 www 6030: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6031: ol#LC_PathBreadcrumbs {
1.693 droeschl 6032: padding-left: 10px;
1.819 tempelho 6033: margin: 0;
1.693 droeschl 6034: list-style-position: inside;
6035: }
6036:
1.795 www 6037: ol#LC_MenuBreadcrumbs li,
6038: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6039: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 6040: display: inline;
6041: white-space: nowrap;
1.693 droeschl 6042: }
6043:
1.823 bisitz 6044: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6045: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 6046: text-decoration: none;
6047: font-size:90%;
6048: }
1.795 www 6049:
6050: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6051: text-decoration:none;
6052: font-size:100%;
6053: font-weight:bold;
1.693 droeschl 6054: }
1.795 www 6055:
1.840 bisitz 6056: .LC_Box {
1.835 bisitz 6057: border: solid 1px $lg_border_color;
6058: padding: 0 10px 10px 10px;
1.746 neumanie 6059: }
1.795 www 6060:
6061: .LC_AboutMe_Image {
1.747 neumanie 6062: float:left;
6063: margin-right:10px;
6064: }
1.795 www 6065:
6066: .LC_Clear_AboutMe_Image {
1.747 neumanie 6067: clear:left;
6068: }
1.795 www 6069:
1.721 harmsja 6070: dl.LC_ListStyleClean dt {
1.693 droeschl 6071: padding-right: 5px;
6072: display: table-header-group;
6073: }
6074:
1.721 harmsja 6075: dl.LC_ListStyleClean dd {
1.693 droeschl 6076: display: table-row;
6077: }
6078:
1.721 harmsja 6079: .LC_ListStyleClean,
6080: .LC_ListStyleSimple,
6081: .LC_ListStyleNormal,
1.777 tempelho 6082: .LC_ListStyle_Border,
1.795 www 6083: .LC_ListStyleSpecial {
1.693 droeschl 6084: /*display:block; */
6085: list-style-position: inside;
6086: list-style-type: none;
6087: overflow: hidden;
1.803 bisitz 6088: padding: 0;
1.693 droeschl 6089: }
6090:
1.721 harmsja 6091: .LC_ListStyleSimple li,
6092: .LC_ListStyleSimple dd,
6093: .LC_ListStyleNormal li,
6094: .LC_ListStyleNormal dd,
6095: .LC_ListStyleSpecial li,
1.795 www 6096: .LC_ListStyleSpecial dd {
1.803 bisitz 6097: margin: 0;
1.693 droeschl 6098: padding: 5px 5px 5px 10px;
6099: clear: both;
6100: }
6101:
1.721 harmsja 6102: .LC_ListStyleClean li,
6103: .LC_ListStyleClean dd {
1.803 bisitz 6104: padding-top: 0;
6105: padding-bottom: 0;
1.693 droeschl 6106: }
6107:
1.721 harmsja 6108: .LC_ListStyleSimple dd,
1.795 www 6109: .LC_ListStyleSimple li {
1.698 harmsja 6110: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6111: }
6112:
1.721 harmsja 6113: .LC_ListStyleSpecial li,
6114: .LC_ListStyleSpecial dd {
1.693 droeschl 6115: list-style-type: none;
6116: background-color: RGB(220, 220, 220);
6117: margin-bottom: 4px;
6118: }
6119:
1.721 harmsja 6120: table.LC_SimpleTable {
1.698 harmsja 6121: margin:5px;
6122: border:solid 1px $lg_border_color;
1.795 www 6123: }
1.693 droeschl 6124:
1.721 harmsja 6125: table.LC_SimpleTable tr {
1.803 bisitz 6126: padding: 0;
1.698 harmsja 6127: border:solid 1px $lg_border_color;
1.693 droeschl 6128: }
1.795 www 6129:
6130: table.LC_SimpleTable thead {
1.698 harmsja 6131: background:rgb(220,220,220);
1.693 droeschl 6132: }
6133:
1.721 harmsja 6134: div.LC_columnSection {
1.693 droeschl 6135: display: block;
6136: clear: both;
6137: overflow: hidden;
1.803 bisitz 6138: margin: 0;
1.693 droeschl 6139: }
6140:
1.721 harmsja 6141: div.LC_columnSection>* {
1.693 droeschl 6142: float: left;
1.803 bisitz 6143: margin: 10px 20px 10px 0;
1.747 neumanie 6144: overflow:hidden;
1.693 droeschl 6145: }
1.721 harmsja 6146:
1.694 tempelho 6147: .LC_loginpage_container {
6148: text-align:left;
6149: margin : 0 auto;
1.785 tempelho 6150: width:90%;
1.694 tempelho 6151: padding: 10px;
6152: height: auto;
1.712 muellerd 6153: background-color:#FFFFFF;
1.694 tempelho 6154: border:1px solid #CCCCCC;
6155: }
6156:
6157:
6158: .LC_loginpage_loginContainer {
6159: float:left;
1.712 muellerd 6160: width: 182px;
1.785 tempelho 6161: padding: 2px;
1.712 muellerd 6162: border:1px solid #CCCCCC;
6163: background-color:$loginbg;
1.694 tempelho 6164: }
6165:
1.795 www 6166: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6167: margin-top: 0;
1.712 muellerd 6168: display:block;
6169: background:$bgcol;
6170: color:$textcol;
6171: padding-left:5px;
6172: }
1.785 tempelho 6173:
1.694 tempelho 6174: .LC_loginpage_loginInfo {
6175: float:left;
1.785 tempelho 6176: width:182px;
1.694 tempelho 6177: border:1px solid #CCCCCC;
1.785 tempelho 6178: padding:2px;
1.712 muellerd 6179: }
6180:
1.694 tempelho 6181: .LC_loginpage_space {
1.754 droeschl 6182: clear: both;
6183: margin-bottom: 20px;
1.694 tempelho 6184: border-bottom: 1px solid #CCCCCC;
6185: }
6186:
1.785 tempelho 6187: .LC_loginpage_floatLeft {
6188: float: left;
6189: width: 200px;
6190: margin: 0;
6191: }
6192:
1.795 www 6193: table em {
1.754 droeschl 6194: font-weight: bold;
6195: font-style: normal;
1.748 schulted 6196: }
1.795 www 6197:
1.779 bisitz 6198: table.LC_tableBrowseRes,
1.795 www 6199: table.LC_tableOfContent {
1.769 schulted 6200: border:none;
1.858 bisitz 6201: border-spacing: 1px;
1.754 droeschl 6202: padding: 3px;
6203: background-color: #FFFFFF;
6204: font-size: 90%;
1.753 droeschl 6205: }
1.789 droeschl 6206:
6207: table.LC_tableOfContent{
6208: border-collapse: collapse;
6209: }
6210:
1.771 droeschl 6211: table.LC_tableBrowseRes a,
1.768 schulted 6212: table.LC_tableOfContent a {
1.771 droeschl 6213: background-color: transparent;
1.753 droeschl 6214: text-decoration: none;
6215: }
6216:
1.771 droeschl 6217: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6218: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6219: background-color: #EEEEEE;
1.753 droeschl 6220: }
6221:
1.795 www 6222: table.LC_tableOfContent img {
1.753 droeschl 6223: border: none;
6224: height: 1.3em;
6225: vertical-align: text-bottom;
6226: margin-right: 0.3em;
6227: }
1.757 schulted 6228:
1.795 www 6229: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6230: background-image:url(/res/adm/pages/open-first-problem.gif);
6231: }
6232:
1.795 www 6233: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6234: background-image:url(/res/adm/pages/start-navigation.gif);
6235: }
6236:
1.795 www 6237: a#LC_content_toolbar_closenav {
1.774 ehlerst 6238: background-image:url(/res/adm/pages/close-navigation.gif);
6239: }
6240:
1.795 www 6241: a#LC_content_toolbar_everything {
1.774 ehlerst 6242: background-image:url(/res/adm/pages/show-all.gif);
6243: }
6244:
1.795 www 6245: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6246: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6247: }
6248:
1.795 www 6249: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6250: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6251: }
6252:
1.795 www 6253: a#LC_content_toolbar_changefolder {
1.757 schulted 6254: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6255: }
6256:
1.795 www 6257: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6258: background-image:url(/res/adm/pages/open-all-folders.gif);
6259: }
6260:
1.795 www 6261: ul#LC_toolbar li a:hover {
1.757 schulted 6262: background-position: bottom center;
6263: }
6264:
1.795 www 6265: ul#LC_toolbar {
1.803 bisitz 6266: padding: 0;
1.757 schulted 6267: margin: 2px;
6268: list-style:none;
6269: position:relative;
6270: background-color:white;
6271: }
6272:
1.795 www 6273: ul#LC_toolbar li {
1.757 schulted 6274: border:1px solid white;
1.803 bisitz 6275: padding: 0;
1.757 schulted 6276: margin: 0;
1.795 www 6277: float: left;
1.767 droeschl 6278: display:inline;
1.757 schulted 6279: vertical-align:middle;
1.795 www 6280: }
1.757 schulted 6281:
1.783 amueller 6282:
1.795 www 6283: a.LC_toolbarItem {
1.767 droeschl 6284: display:block;
1.803 bisitz 6285: padding: 0;
6286: margin: 0;
1.757 schulted 6287: height: 32px;
6288: width: 32px;
1.779 bisitz 6289: color:white;
1.803 bisitz 6290: border: none;
1.757 schulted 6291: background-repeat:no-repeat;
6292: background-color:transparent;
6293: }
6294:
1.843 bisitz 6295: ul.LC_funclist li {
1.782 bisitz 6296: float: left;
6297: white-space: nowrap;
6298: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6299: margin: 0 15px 15px 10px;
1.782 bisitz 6300: }
6301:
1.757 schulted 6302:
1.343 albertel 6303: END
6304: }
6305:
1.306 albertel 6306: =pod
6307:
6308: =item * &headtag()
6309:
6310: Returns a uniform footer for LON-CAPA web pages.
6311:
1.307 albertel 6312: Inputs: $title - optional title for the head
6313: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6314: $args - optional arguments
1.319 albertel 6315: force_register - if is true call registerurl so the remote is
6316: informed
1.415 albertel 6317: redirect -> array ref of
6318: 1- seconds before redirect occurs
6319: 2- url to redirect to
6320: 3- whether the side effect should occur
1.315 albertel 6321: (side effect of setting
6322: $env{'internal.head.redirect'} to the url
6323: redirected too)
1.352 albertel 6324: domain -> force to color decorate a page for a specific
6325: domain
6326: function -> force usage of a specific rolish color scheme
6327: bgcolor -> override the default page bgcolor
1.460 albertel 6328: no_auto_mt_title
6329: -> prevent &mt()ing the title arg
1.464 albertel 6330:
1.306 albertel 6331: =cut
6332:
6333: sub headtag {
1.313 albertel 6334: my ($title,$head_extra,$args) = @_;
1.306 albertel 6335:
1.363 albertel 6336: my $function = $args->{'function'} || &get_users_function();
6337: my $domain = $args->{'domain'} || &determinedomain();
6338: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6339: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6340: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6341: #time(),
1.418 albertel 6342: $env{'environment.color.timestamp'},
1.363 albertel 6343: $function,$domain,$bgcolor);
6344:
1.369 www 6345: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6346:
1.308 albertel 6347: my $result =
6348: '<head>'.
1.461 albertel 6349: &font_settings();
1.319 albertel 6350:
1.461 albertel 6351: if (!$args->{'frameset'}) {
6352: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6353: }
1.319 albertel 6354: if ($args->{'force_register'}) {
6355: $result .= &Apache::lonmenu::registerurl(1);
6356: }
1.436 albertel 6357: if (!$args->{'no_nav_bar'}
6358: && !$args->{'only_body'}
6359: && !$args->{'frameset'}) {
6360: $result .= &help_menu_js();
6361: }
1.319 albertel 6362:
1.314 albertel 6363: if (ref($args->{'redirect'})) {
1.414 albertel 6364: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6365: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6366: if (!$inhibit_continue) {
6367: $env{'internal.head.redirect'} = $url;
6368: }
1.313 albertel 6369: $result.=<<ADDMETA
6370: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6371: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6372: ADDMETA
6373: }
1.306 albertel 6374: if (!defined($title)) {
6375: $title = 'The LearningOnline Network with CAPA';
6376: }
1.460 albertel 6377: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6378: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6379: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6380: .$head_extra;
1.306 albertel 6381: return $result;
6382: }
6383:
6384: =pod
6385:
1.340 albertel 6386: =item * &font_settings()
6387:
6388: Returns neccessary <meta> to set the proper encoding
6389:
6390: Inputs: none
6391:
6392: =cut
6393:
6394: sub font_settings {
6395: my $headerstring='';
1.647 www 6396: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6397: $headerstring.=
6398: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6399: }
6400: return $headerstring;
6401: }
6402:
1.341 albertel 6403: =pod
6404:
6405: =item * &xml_begin()
6406:
6407: Returns the needed doctype and <html>
6408:
6409: Inputs: none
6410:
6411: =cut
6412:
6413: sub xml_begin {
6414: my $output='';
6415:
1.592 albertel 6416: if ($env{'internal.start_page'}==1) {
6417: &Apache::lonhtmlcommon::init_htmlareafields();
6418: }
1.342 albertel 6419:
1.341 albertel 6420: if ($env{'browser.mathml'}) {
6421: $output='<?xml version="1.0"?>'
6422: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6423: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6424:
6425: # .'<!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">] >'
6426: .'<!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">'
6427: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6428: .'xmlns="http://www.w3.org/1999/xhtml">';
6429: } else {
1.849 bisitz 6430: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6431: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6432: }
6433: return $output;
6434: }
1.340 albertel 6435:
6436: =pod
6437:
1.306 albertel 6438: =item * &endheadtag()
6439:
6440: Returns a uniform </head> for LON-CAPA web pages.
6441:
6442: Inputs: none
6443:
6444: =cut
6445:
6446: sub endheadtag {
6447: return '</head>';
6448: }
6449:
6450: =pod
6451:
6452: =item * &head()
6453:
6454: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6455:
1.648 raeburn 6456: Inputs:
6457:
6458: =over 4
6459:
6460: $title - optional title for the page
6461:
6462: $head_extra - optional extra HTML to put inside the <head>
6463:
6464: =back
1.405 albertel 6465:
1.306 albertel 6466: =cut
6467:
6468: sub head {
1.325 albertel 6469: my ($title,$head_extra,$args) = @_;
6470: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6471: }
6472:
6473: =pod
6474:
6475: =item * &start_page()
6476:
6477: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6478:
1.648 raeburn 6479: Inputs:
6480:
6481: =over 4
6482:
6483: $title - optional title for the page
6484:
6485: $head_extra - optional extra HTML to incude inside the <head>
6486:
6487: $args - additional optional args supported are:
6488:
6489: =over 8
6490:
6491: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6492: arg on
1.814 bisitz 6493: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6494: add_entries -> additional attributes to add to the <body>
6495: domain -> force to color decorate a page for a
1.317 albertel 6496: specific domain
1.648 raeburn 6497: function -> force usage of a specific rolish color
1.317 albertel 6498: scheme
1.648 raeburn 6499: redirect -> see &headtag()
6500: bgcolor -> override the default page bg color
6501: js_ready -> return a string ready for being used in
1.317 albertel 6502: a javascript writeln
1.648 raeburn 6503: html_encode -> return a string ready for being used in
1.320 albertel 6504: a html attribute
1.648 raeburn 6505: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6506: $forcereg arg
1.648 raeburn 6507: frameset -> if true will start with a <frameset>
1.330 albertel 6508: rather than <body>
1.648 raeburn 6509: skip_phases -> hash ref of
1.338 albertel 6510: head -> skip the <html><head> generation
6511: body -> skip all <body> generation
1.648 raeburn 6512: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6513: 'Switch To Inline Menu' link
1.648 raeburn 6514: no_auto_mt_title -> prevent &mt()ing the title arg
6515: inherit_jsmath -> when creating popup window in a page,
6516: should it have jsmath forced on by the
6517: current page
1.867 kalberla 6518: bread_crumbs -> Array containing breadcrumbs
6519: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6520:
1.648 raeburn 6521: =back
1.460 albertel 6522:
1.648 raeburn 6523: =back
1.562 albertel 6524:
1.306 albertel 6525: =cut
6526:
6527: sub start_page {
1.309 albertel 6528: my ($title,$head_extra,$args) = @_;
1.318 albertel 6529: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6530: my %head_args;
1.352 albertel 6531: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6532: 'bgcolor','frameset','no_nav_bar','only_body',
6533: 'no_auto_mt_title') {
1.319 albertel 6534: if (defined($args->{$arg})) {
1.324 raeburn 6535: $head_args{$arg} = $args->{$arg};
1.319 albertel 6536: }
1.313 albertel 6537: }
1.319 albertel 6538:
1.315 albertel 6539: $env{'internal.start_page'}++;
1.338 albertel 6540: my $result;
6541: if (! exists($args->{'skip_phases'}{'head'}) ) {
6542: $result.=
1.341 albertel 6543: &xml_begin().
1.338 albertel 6544: &headtag($title,$head_extra,\%head_args).&endheadtag();
6545: }
6546:
6547: if (! exists($args->{'skip_phases'}{'body'}) ) {
6548: if ($args->{'frameset'}) {
6549: my $attr_string = &make_attr_string($args->{'force_register'},
6550: $args->{'add_entries'});
6551: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6552: } else {
6553: $result .=
6554: &bodytag($title,
6555: $args->{'function'}, $args->{'add_entries'},
6556: $args->{'only_body'}, $args->{'domain'},
6557: $args->{'force_register'}, $args->{'no_nav_bar'},
6558: $args->{'bgcolor'}, $args->{'no_inline_link'},
6559: $args);
6560: }
1.330 albertel 6561: }
1.338 albertel 6562:
1.315 albertel 6563: if ($args->{'js_ready'}) {
1.713 kaisler 6564: $result = &js_ready($result);
1.315 albertel 6565: }
1.320 albertel 6566: if ($args->{'html_encode'}) {
1.713 kaisler 6567: $result = &html_encode($result);
6568: }
6569:
1.813 bisitz 6570: # Preparation for new and consistent functionlist at top of screen
6571: # if ($args->{'functionlist'}) {
6572: # $result .= &build_functionlist();
6573: #}
6574:
6575: # Don't add anything more if only_body wanted
6576: return $result if $args->{'only_body'};
6577:
6578: #Breadcrumbs
1.758 kaisler 6579: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6580: &Apache::lonhtmlcommon::clear_breadcrumbs();
6581: #if any br links exists, add them to the breadcrumbs
6582: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6583: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6584: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6585: }
6586: }
6587:
6588: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6589: if(exists($args->{'bread_crumbs_component'})){
6590: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6591: }else{
6592: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6593: }
1.320 albertel 6594: }
1.315 albertel 6595: return $result;
1.306 albertel 6596: }
6597:
1.330 albertel 6598:
1.306 albertel 6599: =pod
6600:
6601: =item * &head()
6602:
6603: Returns a complete </body></html> section for LON-CAPA web pages.
6604:
1.315 albertel 6605: Inputs: $args - additional optional args supported are:
6606: js_ready -> return a string ready for being used in
6607: a javascript writeln
1.320 albertel 6608: html_encode -> return a string ready for being used in
6609: a html attribute
1.330 albertel 6610: frameset -> if true will start with a <frameset>
6611: rather than <body>
1.493 albertel 6612: dicsussion -> if true will get discussion from
6613: lonxml::xmlend
6614: (you can pass the target and parser arguments
6615: through optional 'target' and 'parser' args
6616: to this routine)
1.306 albertel 6617:
6618: =cut
6619:
6620: sub end_page {
1.315 albertel 6621: my ($args) = @_;
6622: $env{'internal.end_page'}++;
1.330 albertel 6623: my $result;
1.335 albertel 6624: if ($args->{'discussion'}) {
6625: my ($target,$parser);
6626: if (ref($args->{'discussion'})) {
6627: ($target,$parser) =($args->{'discussion'}{'target'},
6628: $args->{'discussion'}{'parser'});
6629: }
6630: $result .= &Apache::lonxml::xmlend($target,$parser);
6631: }
6632:
1.330 albertel 6633: if ($args->{'frameset'}) {
6634: $result .= '</frameset>';
6635: } else {
1.635 raeburn 6636: $result .= &endbodytag($args);
1.330 albertel 6637: }
6638: $result .= "\n</html>";
6639:
1.315 albertel 6640: if ($args->{'js_ready'}) {
1.317 albertel 6641: $result = &js_ready($result);
1.315 albertel 6642: }
1.335 albertel 6643:
1.320 albertel 6644: if ($args->{'html_encode'}) {
6645: $result = &html_encode($result);
6646: }
1.335 albertel 6647:
1.315 albertel 6648: return $result;
6649: }
6650:
1.320 albertel 6651: sub html_encode {
6652: my ($result) = @_;
6653:
1.322 albertel 6654: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6655:
6656: return $result;
6657: }
1.317 albertel 6658: sub js_ready {
6659: my ($result) = @_;
6660:
1.323 albertel 6661: $result =~ s/[\n\r]/ /xmsg;
6662: $result =~ s/\\/\\\\/xmsg;
6663: $result =~ s/'/\\'/xmsg;
1.372 albertel 6664: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6665:
6666: return $result;
6667: }
6668:
1.315 albertel 6669: sub validate_page {
6670: if ( exists($env{'internal.start_page'})
1.316 albertel 6671: && $env{'internal.start_page'} > 1) {
6672: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6673: $env{'internal.start_page'}.' '.
1.316 albertel 6674: $ENV{'request.filename'});
1.315 albertel 6675: }
6676: if ( exists($env{'internal.end_page'})
1.316 albertel 6677: && $env{'internal.end_page'} > 1) {
6678: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6679: $env{'internal.end_page'}.' '.
1.316 albertel 6680: $env{'request.filename'});
1.315 albertel 6681: }
6682: if ( exists($env{'internal.start_page'})
6683: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6684: &Apache::lonnet::logthis('start_page called without end_page '.
6685: $env{'request.filename'});
1.315 albertel 6686: }
6687: if ( ! exists($env{'internal.start_page'})
6688: && exists($env{'internal.end_page'})) {
1.316 albertel 6689: &Apache::lonnet::logthis('end_page called without start_page'.
6690: $env{'request.filename'});
1.315 albertel 6691: }
1.306 albertel 6692: }
1.315 albertel 6693:
1.318 albertel 6694: sub simple_error_page {
6695: my ($r,$title,$msg) = @_;
6696: my $page =
6697: &Apache::loncommon::start_page($title).
6698: &mt($msg).
6699: &Apache::loncommon::end_page();
6700: if (ref($r)) {
6701: $r->print($page);
1.327 albertel 6702: return;
1.318 albertel 6703: }
6704: return $page;
6705: }
1.347 albertel 6706:
6707: {
1.610 albertel 6708: my @row_count;
1.347 albertel 6709: sub start_data_table {
1.422 albertel 6710: my ($add_class) = @_;
6711: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6712: unshift(@row_count,0);
1.422 albertel 6713: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6714: }
6715:
6716: sub end_data_table {
1.610 albertel 6717: shift(@row_count);
1.389 albertel 6718: return '</table>'."\n";;
1.347 albertel 6719: }
6720:
6721: sub start_data_table_row {
1.422 albertel 6722: my ($add_class) = @_;
1.610 albertel 6723: $row_count[0]++;
6724: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6725: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6726: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6727: }
1.471 banghart 6728:
6729: sub continue_data_table_row {
6730: my ($add_class) = @_;
1.610 albertel 6731: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6732: $css_class = (join(' ',$css_class,$add_class));
6733: return '<tr class="'.$css_class.'">'."\n";;
6734: }
1.347 albertel 6735:
6736: sub end_data_table_row {
1.389 albertel 6737: return '</tr>'."\n";;
1.347 albertel 6738: }
1.367 www 6739:
1.421 albertel 6740: sub start_data_table_empty_row {
1.707 bisitz 6741: # $row_count[0]++;
1.421 albertel 6742: return '<tr class="LC_empty_row" >'."\n";;
6743: }
6744:
6745: sub end_data_table_empty_row {
6746: return '</tr>'."\n";;
6747: }
6748:
1.367 www 6749: sub start_data_table_header_row {
1.389 albertel 6750: return '<tr class="LC_header_row">'."\n";;
1.367 www 6751: }
6752:
6753: sub end_data_table_header_row {
1.389 albertel 6754: return '</tr>'."\n";;
1.367 www 6755: }
1.347 albertel 6756: }
6757:
1.548 albertel 6758: =pod
6759:
6760: =item * &inhibit_menu_check($arg)
6761:
6762: Checks for a inhibitmenu state and generates output to preserve it
6763:
6764: Inputs: $arg - can be any of
6765: - undef - in which case the return value is a string
6766: to add into arguments list of a uri
6767: - 'input' - in which case the return value is a HTML
6768: <form> <input> field of type hidden to
6769: preserve the value
6770: - a url - in which case the return value is the url with
6771: the neccesary cgi args added to preserve the
6772: inhibitmenu state
6773: - a ref to a url - no return value, but the string is
6774: updated to include the neccessary cgi
6775: args to preserve the inhibitmenu state
6776:
6777: =cut
6778:
6779: sub inhibit_menu_check {
6780: my ($arg) = @_;
6781: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6782: if ($arg eq 'input') {
6783: if ($env{'form.inhibitmenu'}) {
6784: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6785: } else {
6786: return
6787: }
6788: }
6789: if ($env{'form.inhibitmenu'}) {
6790: if (ref($arg)) {
6791: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6792: } elsif ($arg eq '') {
6793: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6794: } else {
6795: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6796: }
6797: }
6798: if (!ref($arg)) {
6799: return $arg;
6800: }
6801: }
6802:
1.251 albertel 6803: ###############################################
1.182 matthew 6804:
6805: =pod
6806:
1.549 albertel 6807: =back
6808:
6809: =head1 User Information Routines
6810:
6811: =over 4
6812:
1.405 albertel 6813: =item * &get_users_function()
1.182 matthew 6814:
6815: Used by &bodytag to determine the current users primary role.
6816: Returns either 'student','coordinator','admin', or 'author'.
6817:
6818: =cut
6819:
6820: ###############################################
6821: sub get_users_function {
1.815 tempelho 6822: my $function = 'norole';
1.818 tempelho 6823: if ($env{'request.role'}=~/^(st)/) {
6824: $function='student';
6825: }
1.258 albertel 6826: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6827: $function='coordinator';
6828: }
1.258 albertel 6829: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6830: $function='admin';
6831: }
1.826 bisitz 6832: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6833: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6834: $function='author';
6835: }
6836: return $function;
1.54 www 6837: }
1.99 www 6838:
6839: ###############################################
6840:
1.233 raeburn 6841: =pod
6842:
1.821 raeburn 6843: =item * &show_course()
6844:
6845: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6846: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6847:
6848: Inputs:
6849: None
6850:
6851: Outputs:
6852: Scalar: 1 if 'Course' to be used, 0 otherwise.
6853:
6854: =cut
6855:
6856: ###############################################
6857: sub show_course {
6858: my $course = !$env{'user.adv'};
6859: if (!$env{'user.adv'}) {
6860: foreach my $env (keys(%env)) {
6861: next if ($env !~ m/^user\.priv\./);
6862: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6863: $course = 0;
6864: last;
6865: }
6866: }
6867: }
6868: return $course;
6869: }
6870:
6871: ###############################################
6872:
6873: =pod
6874:
1.542 raeburn 6875: =item * &check_user_status()
1.274 raeburn 6876:
6877: Determines current status of supplied role for a
6878: specific user. Roles can be active, previous or future.
6879:
6880: Inputs:
6881: user's domain, user's username, course's domain,
1.375 raeburn 6882: course's number, optional section ID.
1.274 raeburn 6883:
6884: Outputs:
6885: role status: active, previous or future.
6886:
6887: =cut
6888:
6889: sub check_user_status {
1.412 raeburn 6890: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6891: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6892: my @uroles = keys %userinfo;
6893: my $srchstr;
6894: my $active_chk = 'none';
1.412 raeburn 6895: my $now = time;
1.274 raeburn 6896: if (@uroles > 0) {
1.412 raeburn 6897: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6898: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6899: } else {
1.412 raeburn 6900: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6901: }
6902: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6903: my $role_end = 0;
6904: my $role_start = 0;
6905: $active_chk = 'active';
1.412 raeburn 6906: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6907: $role_end = $1;
6908: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6909: $role_start = $1;
1.274 raeburn 6910: }
6911: }
6912: if ($role_start > 0) {
1.412 raeburn 6913: if ($now < $role_start) {
1.274 raeburn 6914: $active_chk = 'future';
6915: }
6916: }
6917: if ($role_end > 0) {
1.412 raeburn 6918: if ($now > $role_end) {
1.274 raeburn 6919: $active_chk = 'previous';
6920: }
6921: }
6922: }
6923: }
6924: return $active_chk;
6925: }
6926:
6927: ###############################################
6928:
6929: =pod
6930:
1.405 albertel 6931: =item * &get_sections()
1.233 raeburn 6932:
6933: Determines all the sections for a course including
6934: sections with students and sections containing other roles.
1.419 raeburn 6935: Incoming parameters:
6936:
6937: 1. domain
6938: 2. course number
6939: 3. reference to array containing roles for which sections should
6940: be gathered (optional).
6941: 4. reference to array containing status types for which sections
6942: should be gathered (optional).
6943:
6944: If the third argument is undefined, sections are gathered for any role.
6945: If the fourth argument is undefined, sections are gathered for any status.
6946: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6947:
1.374 raeburn 6948: Returns section hash (keys are section IDs, values are
6949: number of users in each section), subject to the
1.419 raeburn 6950: optional roles filter, optional status filter
1.233 raeburn 6951:
6952: =cut
6953:
6954: ###############################################
6955: sub get_sections {
1.419 raeburn 6956: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6957: if (!defined($cdom) || !defined($cnum)) {
6958: my $cid = $env{'request.course.id'};
6959:
6960: return if (!defined($cid));
6961:
6962: $cdom = $env{'course.'.$cid.'.domain'};
6963: $cnum = $env{'course.'.$cid.'.num'};
6964: }
6965:
6966: my %sectioncount;
1.419 raeburn 6967: my $now = time;
1.240 albertel 6968:
1.366 albertel 6969: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6970: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6971: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6972: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6973: my $start_index = &Apache::loncoursedata::CL_START();
6974: my $end_index = &Apache::loncoursedata::CL_END();
6975: my $status;
1.366 albertel 6976: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6977: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6978: $data->[$status_index],
6979: $data->[$start_index],
6980: $data->[$end_index]);
6981: if ($stu_status eq 'Active') {
6982: $status = 'active';
6983: } elsif ($end < $now) {
6984: $status = 'previous';
6985: } elsif ($start > $now) {
6986: $status = 'future';
6987: }
6988: if ($section ne '-1' && $section !~ /^\s*$/) {
6989: if ((!defined($possible_status)) || (($status ne '') &&
6990: (grep/^\Q$status\E$/,@{$possible_status}))) {
6991: $sectioncount{$section}++;
6992: }
1.240 albertel 6993: }
6994: }
6995: }
6996: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6997: foreach my $user (sort(keys(%courseroles))) {
6998: if ($user !~ /^(\w{2})/) { next; }
6999: my ($role) = ($user =~ /^(\w{2})/);
7000: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7001: my ($section,$status);
1.240 albertel 7002: if ($role eq 'cr' &&
7003: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7004: $section=$1;
7005: }
7006: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7007: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7008: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7009: if ($end == -1 && $start == -1) {
7010: next; #deleted role
7011: }
7012: if (!defined($possible_status)) {
7013: $sectioncount{$section}++;
7014: } else {
7015: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7016: $status = 'active';
7017: } elsif ($end < $now) {
7018: $status = 'future';
7019: } elsif ($start > $now) {
7020: $status = 'previous';
7021: }
7022: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7023: $sectioncount{$section}++;
7024: }
7025: }
1.233 raeburn 7026: }
1.366 albertel 7027: return %sectioncount;
1.233 raeburn 7028: }
7029:
1.274 raeburn 7030: ###############################################
1.294 raeburn 7031:
7032: =pod
1.405 albertel 7033:
7034: =item * &get_course_users()
7035:
1.275 raeburn 7036: Retrieves usernames:domains for users in the specified course
7037: with specific role(s), and access status.
7038:
7039: Incoming parameters:
1.277 albertel 7040: 1. course domain
7041: 2. course number
7042: 3. access status: users must have - either active,
1.275 raeburn 7043: previous, future, or all.
1.277 albertel 7044: 4. reference to array of permissible roles
1.288 raeburn 7045: 5. reference to array of section restrictions (optional)
7046: 6. reference to results object (hash of hashes).
7047: 7. reference to optional userdata hash
1.609 raeburn 7048: 8. reference to optional statushash
1.630 raeburn 7049: 9. flag if privileged users (except those set to unhide in
7050: course settings) should be excluded
1.609 raeburn 7051: Keys of top level results hash are roles.
1.275 raeburn 7052: Keys of inner hashes are username:domain, with
7053: values set to access type.
1.288 raeburn 7054: Optional userdata hash returns an array with arguments in the
7055: same order as loncoursedata::get_classlist() for student data.
7056:
1.609 raeburn 7057: Optional statushash returns
7058:
1.288 raeburn 7059: Entries for end, start, section and status are blank because
7060: of the possibility of multiple values for non-student roles.
7061:
1.275 raeburn 7062: =cut
1.405 albertel 7063:
1.275 raeburn 7064: ###############################################
1.405 albertel 7065:
1.275 raeburn 7066: sub get_course_users {
1.630 raeburn 7067: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7068: my %idx = ();
1.419 raeburn 7069: my %seclists;
1.288 raeburn 7070:
7071: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7072: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7073: $idx{end} = &Apache::loncoursedata::CL_END();
7074: $idx{start} = &Apache::loncoursedata::CL_START();
7075: $idx{id} = &Apache::loncoursedata::CL_ID();
7076: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7077: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7078: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7079:
1.290 albertel 7080: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7081: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7082: my $now = time;
1.277 albertel 7083: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7084: my $match = 0;
1.412 raeburn 7085: my $secmatch = 0;
1.419 raeburn 7086: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7087: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7088: if ($section eq '') {
7089: $section = 'none';
7090: }
1.291 albertel 7091: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7092: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7093: $secmatch = 1;
7094: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7095: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7096: $secmatch = 1;
7097: }
7098: } else {
1.419 raeburn 7099: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7100: $secmatch = 1;
7101: }
1.290 albertel 7102: }
1.412 raeburn 7103: if (!$secmatch) {
7104: next;
7105: }
1.419 raeburn 7106: }
1.275 raeburn 7107: if (defined($$types{'active'})) {
1.288 raeburn 7108: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7109: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7110: $match = 1;
1.275 raeburn 7111: }
7112: }
7113: if (defined($$types{'previous'})) {
1.609 raeburn 7114: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7115: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7116: $match = 1;
1.275 raeburn 7117: }
7118: }
7119: if (defined($$types{'future'})) {
1.609 raeburn 7120: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7121: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7122: $match = 1;
1.275 raeburn 7123: }
7124: }
1.609 raeburn 7125: if ($match) {
7126: push(@{$seclists{$student}},$section);
7127: if (ref($userdata) eq 'HASH') {
7128: $$userdata{$student} = $$classlist{$student};
7129: }
7130: if (ref($statushash) eq 'HASH') {
7131: $statushash->{$student}{'st'}{$section} = $status;
7132: }
1.288 raeburn 7133: }
1.275 raeburn 7134: }
7135: }
1.412 raeburn 7136: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7137: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7138: my $now = time;
1.609 raeburn 7139: my %displaystatus = ( previous => 'Expired',
7140: active => 'Active',
7141: future => 'Future',
7142: );
1.630 raeburn 7143: my %nothide;
7144: if ($hidepriv) {
7145: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7146: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7147: if ($user !~ /:/) {
7148: $nothide{join(':',split(/[\@]/,$user))}=1;
7149: } else {
7150: $nothide{$user} = 1;
7151: }
7152: }
7153: }
1.439 raeburn 7154: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7155: my $match = 0;
1.412 raeburn 7156: my $secmatch = 0;
1.439 raeburn 7157: my $status;
1.412 raeburn 7158: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7159: $user =~ s/:$//;
1.439 raeburn 7160: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7161: if ($end == -1 || $start == -1) {
7162: next;
7163: }
7164: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7165: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7166: my ($uname,$udom) = split(/:/,$user);
7167: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7168: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7169: $secmatch = 1;
7170: } elsif ($usec eq '') {
1.420 albertel 7171: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7172: $secmatch = 1;
7173: }
7174: } else {
7175: if (grep(/^\Q$usec\E$/,@{$sections})) {
7176: $secmatch = 1;
7177: }
7178: }
7179: if (!$secmatch) {
7180: next;
7181: }
1.288 raeburn 7182: }
1.419 raeburn 7183: if ($usec eq '') {
7184: $usec = 'none';
7185: }
1.275 raeburn 7186: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7187: if ($hidepriv) {
7188: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7189: (!$nothide{$uname.':'.$udom})) {
7190: next;
7191: }
7192: }
1.503 raeburn 7193: if ($end > 0 && $end < $now) {
1.439 raeburn 7194: $status = 'previous';
7195: } elsif ($start > $now) {
7196: $status = 'future';
7197: } else {
7198: $status = 'active';
7199: }
1.277 albertel 7200: foreach my $type (keys(%{$types})) {
1.275 raeburn 7201: if ($status eq $type) {
1.420 albertel 7202: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7203: push(@{$$users{$role}{$user}},$type);
7204: }
1.288 raeburn 7205: $match = 1;
7206: }
7207: }
1.419 raeburn 7208: if (($match) && (ref($userdata) eq 'HASH')) {
7209: if (!exists($$userdata{$uname.':'.$udom})) {
7210: &get_user_info($udom,$uname,\%idx,$userdata);
7211: }
1.420 albertel 7212: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7213: push(@{$seclists{$uname.':'.$udom}},$usec);
7214: }
1.609 raeburn 7215: if (ref($statushash) eq 'HASH') {
7216: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7217: }
1.275 raeburn 7218: }
7219: }
7220: }
7221: }
1.290 albertel 7222: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7223: if ((defined($cdom)) && (defined($cnum))) {
7224: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7225: if ( defined($csettings{'internal.courseowner'}) ) {
7226: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7227: next if ($owner eq '');
7228: my ($ownername,$ownerdom);
7229: if ($owner =~ /^([^:]+):([^:]+)$/) {
7230: $ownername = $1;
7231: $ownerdom = $2;
7232: } else {
7233: $ownername = $owner;
7234: $ownerdom = $cdom;
7235: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7236: }
7237: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7238: if (defined($userdata) &&
1.609 raeburn 7239: !exists($$userdata{$owner})) {
7240: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7241: if (!grep(/^none$/,@{$seclists{$owner}})) {
7242: push(@{$seclists{$owner}},'none');
7243: }
7244: if (ref($statushash) eq 'HASH') {
7245: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7246: }
1.290 albertel 7247: }
1.279 raeburn 7248: }
7249: }
7250: }
1.419 raeburn 7251: foreach my $user (keys(%seclists)) {
7252: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7253: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7254: }
1.275 raeburn 7255: }
7256: return;
7257: }
7258:
1.288 raeburn 7259: sub get_user_info {
7260: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7261: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7262: &plainname($uname,$udom,'lastname');
1.291 albertel 7263: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7264: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7265: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7266: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7267: return;
7268: }
1.275 raeburn 7269:
1.472 raeburn 7270: ###############################################
7271:
7272: =pod
7273:
7274: =item * &get_user_quota()
7275:
7276: Retrieves quota assigned for storage of portfolio files for a user
7277:
7278: Incoming parameters:
7279: 1. user's username
7280: 2. user's domain
7281:
7282: Returns:
1.536 raeburn 7283: 1. Disk quota (in Mb) assigned to student.
7284: 2. (Optional) Type of setting: custom or default
7285: (individually assigned or default for user's
7286: institutional status).
7287: 3. (Optional) - User's institutional status (e.g., faculty, staff
7288: or student - types as defined in localenroll::inst_usertypes
7289: for user's domain, which determines default quota for user.
7290: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7291:
7292: If a value has been stored in the user's environment,
1.536 raeburn 7293: it will return that, otherwise it returns the maximal default
7294: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7295:
7296: =cut
7297:
7298: ###############################################
7299:
7300:
7301: sub get_user_quota {
7302: my ($uname,$udom) = @_;
1.536 raeburn 7303: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7304: if (!defined($udom)) {
7305: $udom = $env{'user.domain'};
7306: }
7307: if (!defined($uname)) {
7308: $uname = $env{'user.name'};
7309: }
7310: if (($udom eq '' || $uname eq '') ||
7311: ($udom eq 'public') && ($uname eq 'public')) {
7312: $quota = 0;
1.536 raeburn 7313: $quotatype = 'default';
7314: $defquota = 0;
1.472 raeburn 7315: } else {
1.536 raeburn 7316: my $inststatus;
1.472 raeburn 7317: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7318: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7319: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7320: } else {
1.536 raeburn 7321: my %userenv =
7322: &Apache::lonnet::get('environment',['portfolioquota',
7323: 'inststatus'],$udom,$uname);
1.472 raeburn 7324: my ($tmp) = keys(%userenv);
7325: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7326: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7327: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7328: } else {
7329: undef(%userenv);
7330: }
7331: }
1.536 raeburn 7332: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7333: if ($quota eq '') {
1.536 raeburn 7334: $quota = $defquota;
7335: $quotatype = 'default';
7336: } else {
7337: $quotatype = 'custom';
1.472 raeburn 7338: }
7339: }
1.536 raeburn 7340: if (wantarray) {
7341: return ($quota,$quotatype,$settingstatus,$defquota);
7342: } else {
7343: return $quota;
7344: }
1.472 raeburn 7345: }
7346:
7347: ###############################################
7348:
7349: =pod
7350:
7351: =item * &default_quota()
7352:
1.536 raeburn 7353: Retrieves default quota assigned for storage of user portfolio files,
7354: given an (optional) user's institutional status.
1.472 raeburn 7355:
7356: Incoming parameters:
7357: 1. domain
1.536 raeburn 7358: 2. (Optional) institutional status(es). This is a : separated list of
7359: status types (e.g., faculty, staff, student etc.)
7360: which apply to the user for whom the default is being retrieved.
7361: If the institutional status string in undefined, the domain
7362: default quota will be returned.
1.472 raeburn 7363:
7364: Returns:
7365: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7366: 2. (Optional) institutional type which determined the value of the
7367: default quota.
1.472 raeburn 7368:
7369: If a value has been stored in the domain's configuration db,
7370: it will return that, otherwise it returns 20 (for backwards
7371: compatibility with domains which have not set up a configuration
7372: db file; the original statically defined portfolio quota was 20 Mb).
7373:
1.536 raeburn 7374: If the user's status includes multiple types (e.g., staff and student),
7375: the largest default quota which applies to the user determines the
7376: default quota returned.
7377:
1.780 raeburn 7378: =back
7379:
1.472 raeburn 7380: =cut
7381:
7382: ###############################################
7383:
7384:
7385: sub default_quota {
1.536 raeburn 7386: my ($udom,$inststatus) = @_;
7387: my ($defquota,$settingstatus);
7388: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7389: ['quotas'],$udom);
7390: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7391: if ($inststatus ne '') {
1.765 raeburn 7392: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7393: foreach my $item (@statuses) {
1.711 raeburn 7394: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7395: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7396: if ($defquota eq '') {
7397: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7398: $settingstatus = $item;
7399: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7400: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7401: $settingstatus = $item;
7402: }
7403: }
7404: } else {
7405: if ($quotahash{'quotas'}{$item} ne '') {
7406: if ($defquota eq '') {
7407: $defquota = $quotahash{'quotas'}{$item};
7408: $settingstatus = $item;
7409: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7410: $defquota = $quotahash{'quotas'}{$item};
7411: $settingstatus = $item;
7412: }
1.536 raeburn 7413: }
7414: }
7415: }
7416: }
7417: if ($defquota eq '') {
1.711 raeburn 7418: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7419: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7420: } else {
7421: $defquota = $quotahash{'quotas'}{'default'};
7422: }
1.536 raeburn 7423: $settingstatus = 'default';
7424: }
7425: } else {
7426: $settingstatus = 'default';
7427: $defquota = 20;
7428: }
7429: if (wantarray) {
7430: return ($defquota,$settingstatus);
1.472 raeburn 7431: } else {
1.536 raeburn 7432: return $defquota;
1.472 raeburn 7433: }
7434: }
7435:
1.384 raeburn 7436: sub get_secgrprole_info {
7437: my ($cdom,$cnum,$needroles,$type) = @_;
7438: my %sections_count = &get_sections($cdom,$cnum);
7439: my @sections = (sort {$a <=> $b} keys(%sections_count));
7440: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7441: my @groups = sort(keys(%curr_groups));
7442: my $allroles = [];
7443: my $rolehash;
7444: my $accesshash = {
7445: active => 'Currently has access',
7446: future => 'Will have future access',
7447: previous => 'Previously had access',
7448: };
7449: if ($needroles) {
7450: $rolehash = {'all' => 'all'};
1.385 albertel 7451: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7452: if (&Apache::lonnet::error(%user_roles)) {
7453: undef(%user_roles);
7454: }
7455: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7456: my ($role)=split(/\:/,$item,2);
7457: if ($role eq 'cr') { next; }
7458: if ($role =~ /^cr/) {
7459: $$rolehash{$role} = (split('/',$role))[3];
7460: } else {
7461: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7462: }
7463: }
7464: foreach my $key (sort(keys(%{$rolehash}))) {
7465: push(@{$allroles},$key);
7466: }
7467: push (@{$allroles},'st');
7468: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7469: }
7470: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7471: }
7472:
1.555 raeburn 7473: sub user_picker {
1.627 raeburn 7474: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7475: my $currdom = $dom;
7476: my %curr_selected = (
7477: srchin => 'dom',
1.580 raeburn 7478: srchby => 'lastname',
1.555 raeburn 7479: );
7480: my $srchterm;
1.625 raeburn 7481: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7482: if ($srch->{'srchby'} ne '') {
7483: $curr_selected{'srchby'} = $srch->{'srchby'};
7484: }
7485: if ($srch->{'srchin'} ne '') {
7486: $curr_selected{'srchin'} = $srch->{'srchin'};
7487: }
7488: if ($srch->{'srchtype'} ne '') {
7489: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7490: }
7491: if ($srch->{'srchdomain'} ne '') {
7492: $currdom = $srch->{'srchdomain'};
7493: }
7494: $srchterm = $srch->{'srchterm'};
7495: }
7496: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7497: 'usr' => 'Search criteria',
1.563 raeburn 7498: 'doma' => 'Domain/institution to search',
1.558 albertel 7499: 'uname' => 'username',
7500: 'lastname' => 'last name',
1.555 raeburn 7501: 'lastfirst' => 'last name, first name',
1.558 albertel 7502: 'crs' => 'in this course',
1.576 raeburn 7503: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7504: 'alc' => 'all LON-CAPA',
1.573 raeburn 7505: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7506: 'exact' => 'is',
7507: 'contains' => 'contains',
1.569 raeburn 7508: 'begins' => 'begins with',
1.571 raeburn 7509: 'youm' => "You must include some text to search for.",
7510: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7511: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7512: 'yomc' => "You must choose a domain when using an institutional directory search.",
7513: 'ymcd' => "You must choose a domain when using a domain search.",
7514: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7515: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7516: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7517: );
1.563 raeburn 7518: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7519: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7520:
7521: my @srchins = ('crs','dom','alc','instd');
7522:
7523: foreach my $option (@srchins) {
7524: # FIXME 'alc' option unavailable until
7525: # loncreateuser::print_user_query_page()
7526: # has been completed.
7527: next if ($option eq 'alc');
7528: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7529: if ($curr_selected{'srchin'} eq $option) {
7530: $srchinsel .= '
7531: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7532: } else {
7533: $srchinsel .= '
7534: <option value="'.$option.'">'.$lt{$option}.'</option>';
7535: }
1.555 raeburn 7536: }
1.563 raeburn 7537: $srchinsel .= "\n </select>\n";
1.555 raeburn 7538:
7539: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7540: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7541: if ($curr_selected{'srchby'} eq $option) {
7542: $srchbysel .= '
7543: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7544: } else {
7545: $srchbysel .= '
7546: <option value="'.$option.'">'.$lt{$option}.'</option>';
7547: }
7548: }
7549: $srchbysel .= "\n </select>\n";
7550:
7551: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7552: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7553: if ($curr_selected{'srchtype'} eq $option) {
7554: $srchtypesel .= '
7555: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7556: } else {
7557: $srchtypesel .= '
7558: <option value="'.$option.'">'.$lt{$option}.'</option>';
7559: }
7560: }
7561: $srchtypesel .= "\n </select>\n";
7562:
1.558 albertel 7563: my ($newuserscript,$new_user_create);
1.556 raeburn 7564:
7565: if ($forcenewuser) {
1.576 raeburn 7566: if (ref($srch) eq 'HASH') {
7567: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7568: if ($cancreate) {
7569: $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>';
7570: } else {
1.799 bisitz 7571: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7572: my %usertypetext = (
7573: official => 'institutional',
7574: unofficial => 'non-institutional',
7575: );
1.799 bisitz 7576: $new_user_create = '<p class="LC_warning">'
7577: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7578: .' '
7579: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7580: ,'<a href="'.$helplink.'">','</a>')
7581: .'</p><br />';
1.627 raeburn 7582: }
1.576 raeburn 7583: }
7584: }
7585:
1.556 raeburn 7586: $newuserscript = <<"ENDSCRIPT";
7587:
1.570 raeburn 7588: function setSearch(createnew,callingForm) {
1.556 raeburn 7589: if (createnew == 1) {
1.570 raeburn 7590: for (var i=0; i<callingForm.srchby.length; i++) {
7591: if (callingForm.srchby.options[i].value == 'uname') {
7592: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7593: }
7594: }
1.570 raeburn 7595: for (var i=0; i<callingForm.srchin.length; i++) {
7596: if ( callingForm.srchin.options[i].value == 'dom') {
7597: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7598: }
7599: }
1.570 raeburn 7600: for (var i=0; i<callingForm.srchtype.length; i++) {
7601: if (callingForm.srchtype.options[i].value == 'exact') {
7602: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7603: }
7604: }
1.570 raeburn 7605: for (var i=0; i<callingForm.srchdomain.length; i++) {
7606: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7607: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7608: }
7609: }
7610: }
7611: }
7612: ENDSCRIPT
1.558 albertel 7613:
1.556 raeburn 7614: }
7615:
1.555 raeburn 7616: my $output = <<"END_BLOCK";
1.556 raeburn 7617: <script type="text/javascript">
1.824 bisitz 7618: // <![CDATA[
1.570 raeburn 7619: function validateEntry(callingForm) {
1.558 albertel 7620:
1.556 raeburn 7621: var checkok = 1;
1.558 albertel 7622: var srchin;
1.570 raeburn 7623: for (var i=0; i<callingForm.srchin.length; i++) {
7624: if ( callingForm.srchin[i].checked ) {
7625: srchin = callingForm.srchin[i].value;
1.558 albertel 7626: }
7627: }
7628:
1.570 raeburn 7629: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7630: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7631: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7632: var srchterm = callingForm.srchterm.value;
7633: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7634: var msg = "";
7635:
7636: if (srchterm == "") {
7637: checkok = 0;
1.571 raeburn 7638: msg += "$lt{'youm'}\\n";
1.556 raeburn 7639: }
7640:
1.569 raeburn 7641: if (srchtype== 'begins') {
7642: if (srchterm.length < 2) {
7643: checkok = 0;
1.571 raeburn 7644: msg += "$lt{'thte'}\\n";
1.569 raeburn 7645: }
7646: }
7647:
1.556 raeburn 7648: if (srchtype== 'contains') {
7649: if (srchterm.length < 3) {
7650: checkok = 0;
1.571 raeburn 7651: msg += "$lt{'thet'}\\n";
1.556 raeburn 7652: }
7653: }
7654: if (srchin == 'instd') {
7655: if (srchdomain == '') {
7656: checkok = 0;
1.571 raeburn 7657: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7658: }
7659: }
7660: if (srchin == 'dom') {
7661: if (srchdomain == '') {
7662: checkok = 0;
1.571 raeburn 7663: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7664: }
7665: }
7666: if (srchby == 'lastfirst') {
7667: if (srchterm.indexOf(",") == -1) {
7668: checkok = 0;
1.571 raeburn 7669: msg += "$lt{'whus'}\\n";
1.556 raeburn 7670: }
7671: if (srchterm.indexOf(",") == srchterm.length -1) {
7672: checkok = 0;
1.571 raeburn 7673: msg += "$lt{'whse'}\\n";
1.556 raeburn 7674: }
7675: }
7676: if (checkok == 0) {
1.571 raeburn 7677: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7678: return;
7679: }
7680: if (checkok == 1) {
1.570 raeburn 7681: callingForm.submit();
1.556 raeburn 7682: }
7683: }
7684:
7685: $newuserscript
7686:
1.824 bisitz 7687: // ]]>
1.556 raeburn 7688: </script>
1.558 albertel 7689:
7690: $new_user_create
7691:
1.555 raeburn 7692: END_BLOCK
1.558 albertel 7693:
1.876 raeburn 7694: $output .= &Apache::lonhtmlcommon::start_pick_box().
7695: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7696: $domform.
7697: &Apache::lonhtmlcommon::row_closure().
7698: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7699: $srchbysel.
7700: $srchtypesel.
7701: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7702: $srchinsel.
7703: &Apache::lonhtmlcommon::row_closure(1).
7704: &Apache::lonhtmlcommon::end_pick_box().
7705: '<br />';
1.555 raeburn 7706: return $output;
7707: }
7708:
1.612 raeburn 7709: sub user_rule_check {
1.615 raeburn 7710: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7711: my $response;
7712: if (ref($usershash) eq 'HASH') {
7713: foreach my $user (keys(%{$usershash})) {
7714: my ($uname,$udom) = split(/:/,$user);
7715: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7716: my ($id,$newuser);
1.612 raeburn 7717: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7718: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7719: $id = $usershash->{$user}->{'id'};
7720: }
7721: my $inst_response;
7722: if (ref($checks) eq 'HASH') {
7723: if (defined($checks->{'username'})) {
1.615 raeburn 7724: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7725: &Apache::lonnet::get_instuser($udom,$uname);
7726: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7727: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7728: &Apache::lonnet::get_instuser($udom,undef,$id);
7729: }
1.615 raeburn 7730: } else {
7731: ($inst_response,%{$inst_results->{$user}}) =
7732: &Apache::lonnet::get_instuser($udom,$uname);
7733: return;
1.612 raeburn 7734: }
1.615 raeburn 7735: if (!$got_rules->{$udom}) {
1.612 raeburn 7736: my %domconfig = &Apache::lonnet::get_dom('configuration',
7737: ['usercreation'],$udom);
7738: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7739: foreach my $item ('username','id') {
1.612 raeburn 7740: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7741: $$curr_rules{$udom}{$item} =
7742: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7743: }
7744: }
7745: }
1.615 raeburn 7746: $got_rules->{$udom} = 1;
1.585 raeburn 7747: }
1.612 raeburn 7748: foreach my $item (keys(%{$checks})) {
7749: if (ref($$curr_rules{$udom}) eq 'HASH') {
7750: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7751: if (@{$$curr_rules{$udom}{$item}} > 0) {
7752: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7753: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7754: if ($rule_check{$rule}) {
7755: $$rulematch{$user}{$item} = $rule;
7756: if ($inst_response eq 'ok') {
1.615 raeburn 7757: if (ref($inst_results) eq 'HASH') {
7758: if (ref($inst_results->{$user}) eq 'HASH') {
7759: if (keys(%{$inst_results->{$user}}) == 0) {
7760: $$alerts{$item}{$udom}{$uname} = 1;
7761: }
1.612 raeburn 7762: }
7763: }
1.615 raeburn 7764: }
7765: last;
1.585 raeburn 7766: }
7767: }
7768: }
7769: }
7770: }
7771: }
7772: }
7773: }
1.612 raeburn 7774: return;
7775: }
7776:
7777: sub user_rule_formats {
7778: my ($domain,$domdesc,$curr_rules,$check) = @_;
7779: my %text = (
7780: 'username' => 'Usernames',
7781: 'id' => 'IDs',
7782: );
7783: my $output;
7784: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7785: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7786: if (@{$ruleorder} > 0) {
7787: $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>';
7788: foreach my $rule (@{$ruleorder}) {
7789: if (ref($curr_rules) eq 'ARRAY') {
7790: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7791: if (ref($rules->{$rule}) eq 'HASH') {
7792: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7793: $rules->{$rule}{'desc'}.'</li>';
7794: }
7795: }
7796: }
7797: }
7798: $output .= '</ul>';
7799: }
7800: }
7801: return $output;
7802: }
7803:
7804: sub instrule_disallow_msg {
1.615 raeburn 7805: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7806: my $response;
7807: my %text = (
7808: item => 'username',
7809: items => 'usernames',
7810: match => 'matches',
7811: do => 'does',
7812: action => 'a username',
7813: one => 'one',
7814: );
7815: if ($count > 1) {
7816: $text{'item'} = 'usernames';
7817: $text{'match'} ='match';
7818: $text{'do'} = 'do';
7819: $text{'action'} = 'usernames',
7820: $text{'one'} = 'ones';
7821: }
7822: if ($checkitem eq 'id') {
7823: $text{'items'} = 'IDs';
7824: $text{'item'} = 'ID';
7825: $text{'action'} = 'an ID';
1.615 raeburn 7826: if ($count > 1) {
7827: $text{'item'} = 'IDs';
7828: $text{'action'} = 'IDs';
7829: }
1.612 raeburn 7830: }
1.674 bisitz 7831: $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 7832: if ($mode eq 'upload') {
7833: if ($checkitem eq 'username') {
7834: $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'}.");
7835: } elsif ($checkitem eq 'id') {
1.674 bisitz 7836: $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 7837: }
1.669 raeburn 7838: } elsif ($mode eq 'selfcreate') {
7839: if ($checkitem eq 'id') {
7840: $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.");
7841: }
1.615 raeburn 7842: } else {
7843: if ($checkitem eq 'username') {
7844: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7845: } elsif ($checkitem eq 'id') {
7846: $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.");
7847: }
1.612 raeburn 7848: }
7849: return $response;
1.585 raeburn 7850: }
7851:
1.624 raeburn 7852: sub personal_data_fieldtitles {
7853: my %fieldtitles = &Apache::lonlocal::texthash (
7854: id => 'Student/Employee ID',
7855: permanentemail => 'E-mail address',
7856: lastname => 'Last Name',
7857: firstname => 'First Name',
7858: middlename => 'Middle Name',
7859: generation => 'Generation',
7860: gen => 'Generation',
1.765 raeburn 7861: inststatus => 'Affiliation',
1.624 raeburn 7862: );
7863: return %fieldtitles;
7864: }
7865:
1.642 raeburn 7866: sub sorted_inst_types {
7867: my ($dom) = @_;
7868: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7869: my $othertitle = &mt('All users');
7870: if ($env{'request.course.id'}) {
1.668 raeburn 7871: $othertitle = &mt('Any users');
1.642 raeburn 7872: }
7873: my @types;
7874: if (ref($order) eq 'ARRAY') {
7875: @types = @{$order};
7876: }
7877: if (@types == 0) {
7878: if (ref($usertypes) eq 'HASH') {
7879: @types = sort(keys(%{$usertypes}));
7880: }
7881: }
7882: if (keys(%{$usertypes}) > 0) {
7883: $othertitle = &mt('Other users');
7884: }
7885: return ($othertitle,$usertypes,\@types);
7886: }
7887:
1.645 raeburn 7888: sub get_institutional_codes {
7889: my ($settings,$allcourses,$LC_code) = @_;
7890: # Get complete list of course sections to update
7891: my @currsections = ();
7892: my @currxlists = ();
7893: my $coursecode = $$settings{'internal.coursecode'};
7894:
7895: if ($$settings{'internal.sectionnums'} ne '') {
7896: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7897: }
7898:
7899: if ($$settings{'internal.crosslistings'} ne '') {
7900: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7901: }
7902:
7903: if (@currxlists > 0) {
7904: foreach (@currxlists) {
7905: if (m/^([^:]+):(\w*)$/) {
7906: unless (grep/^$1$/,@{$allcourses}) {
7907: push @{$allcourses},$1;
7908: $$LC_code{$1} = $2;
7909: }
7910: }
7911: }
7912: }
7913:
7914: if (@currsections > 0) {
7915: foreach (@currsections) {
7916: if (m/^(\w+):(\w*)$/) {
7917: my $sec = $coursecode.$1;
7918: my $lc_sec = $2;
7919: unless (grep/^$sec$/,@{$allcourses}) {
7920: push @{$allcourses},$sec;
7921: $$LC_code{$sec} = $lc_sec;
7922: }
7923: }
7924: }
7925: }
7926: return;
7927: }
7928:
1.112 bowersj2 7929: =pod
7930:
1.780 raeburn 7931: =head1 Slot Helpers
7932:
7933: =over 4
7934:
7935: =item * sorted_slots()
7936:
7937: Sorts an array of slot names in order of slot start time (earliest first).
7938:
7939: Inputs:
7940:
7941: =over 4
7942:
7943: slotsarr - Reference to array of unsorted slot names.
7944:
7945: slots - Reference to hash of hash, where outer hash keys are slot names.
7946:
1.549 albertel 7947: =back
7948:
1.780 raeburn 7949: Returns:
7950:
7951: =over 4
7952:
7953: sorted - An array of slot names sorted by the start time of the slot.
7954:
7955: =back
7956:
7957: =back
7958:
7959: =cut
7960:
7961:
7962: sub sorted_slots {
7963: my ($slotsarr,$slots) = @_;
7964: my @sorted;
7965: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7966: @sorted =
7967: sort {
7968: if (ref($slots->{$a}) && ref($slots->{$b})) {
7969: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7970: }
7971: if (ref($slots->{$a})) { return -1;}
7972: if (ref($slots->{$b})) { return 1;}
7973: return 0;
7974: } @{$slotsarr};
7975: }
7976: return @sorted;
7977: }
7978:
7979:
7980: =pod
7981:
1.549 albertel 7982: =head1 HTTP Helpers
7983:
7984: =over 4
7985:
1.648 raeburn 7986: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7987:
1.258 albertel 7988: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7989: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7990: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7991:
7992: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7993: $possible_names is an ref to an array of form element names. As an example:
7994: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7995: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7996:
7997: =cut
1.1 albertel 7998:
1.6 albertel 7999: sub get_unprocessed_cgi {
1.25 albertel 8000: my ($query,$possible_names)= @_;
1.26 matthew 8001: # $Apache::lonxml::debug=1;
1.356 albertel 8002: foreach my $pair (split(/&/,$query)) {
8003: my ($name, $value) = split(/=/,$pair);
1.369 www 8004: $name = &unescape($name);
1.25 albertel 8005: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8006: $value =~ tr/+/ /;
8007: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8008: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8009: }
1.16 harris41 8010: }
1.6 albertel 8011: }
8012:
1.112 bowersj2 8013: =pod
8014:
1.648 raeburn 8015: =item * &cacheheader()
1.112 bowersj2 8016:
8017: returns cache-controlling header code
8018:
8019: =cut
8020:
1.7 albertel 8021: sub cacheheader {
1.258 albertel 8022: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8023: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8024: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8025: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8026: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8027: return $output;
1.7 albertel 8028: }
8029:
1.112 bowersj2 8030: =pod
8031:
1.648 raeburn 8032: =item * &no_cache($r)
1.112 bowersj2 8033:
8034: specifies header code to not have cache
8035:
8036: =cut
8037:
1.9 albertel 8038: sub no_cache {
1.216 albertel 8039: my ($r) = @_;
8040: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8041: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8042: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8043: $r->no_cache(1);
8044: $r->header_out("Expires" => $date);
8045: $r->header_out("Pragma" => "no-cache");
1.123 www 8046: }
8047:
8048: sub content_type {
1.181 albertel 8049: my ($r,$type,$charset) = @_;
1.299 foxr 8050: if ($r) {
8051: # Note that printout.pl calls this with undef for $r.
8052: &no_cache($r);
8053: }
1.258 albertel 8054: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8055: unless ($charset) {
8056: $charset=&Apache::lonlocal::current_encoding;
8057: }
8058: if ($charset) { $type.='; charset='.$charset; }
8059: if ($r) {
8060: $r->content_type($type);
8061: } else {
8062: print("Content-type: $type\n\n");
8063: }
1.9 albertel 8064: }
1.25 albertel 8065:
1.112 bowersj2 8066: =pod
8067:
1.648 raeburn 8068: =item * &add_to_env($name,$value)
1.112 bowersj2 8069:
1.258 albertel 8070: adds $name to the %env hash with value
1.112 bowersj2 8071: $value, if $name already exists, the entry is converted to an array
8072: reference and $value is added to the array.
8073:
8074: =cut
8075:
1.25 albertel 8076: sub add_to_env {
8077: my ($name,$value)=@_;
1.258 albertel 8078: if (defined($env{$name})) {
8079: if (ref($env{$name})) {
1.25 albertel 8080: #already have multiple values
1.258 albertel 8081: push(@{ $env{$name} },$value);
1.25 albertel 8082: } else {
8083: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8084: my $first=$env{$name};
8085: undef($env{$name});
8086: push(@{ $env{$name} },$first,$value);
1.25 albertel 8087: }
8088: } else {
1.258 albertel 8089: $env{$name}=$value;
1.25 albertel 8090: }
1.31 albertel 8091: }
1.149 albertel 8092:
8093: =pod
8094:
1.648 raeburn 8095: =item * &get_env_multiple($name)
1.149 albertel 8096:
1.258 albertel 8097: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8098: values may be defined and end up as an array ref.
8099:
8100: returns an array of values
8101:
8102: =cut
8103:
8104: sub get_env_multiple {
8105: my ($name) = @_;
8106: my @values;
1.258 albertel 8107: if (defined($env{$name})) {
1.149 albertel 8108: # exists is it an array
1.258 albertel 8109: if (ref($env{$name})) {
8110: @values=@{ $env{$name} };
1.149 albertel 8111: } else {
1.258 albertel 8112: $values[0]=$env{$name};
1.149 albertel 8113: }
8114: }
8115: return(@values);
8116: }
8117:
1.660 raeburn 8118: sub ask_for_embedded_content {
8119: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8120: my $upload_output = '
8121: <form name="upload_embedded" action="'.$actionurl.'"
8122: method="post" enctype="multipart/form-data">';
8123: $upload_output .= $state;
1.661 raeburn 8124: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8125:
8126: my $num = 0;
8127: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8128: $upload_output .= &start_data_table_row().
8129: '<td>'.$embed_file.'</td><td>';
8130: if ($args->{'ignore_remote_references'}
8131: && $embed_file =~ m{^\w+://}) {
8132: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8133: } elsif ($args->{'error_on_invalid_names'}
8134: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8135:
8136: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8137:
8138: } else {
8139: $upload_output .='
1.661 raeburn 8140: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8141: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8142: my $attrib = join(':',@{$$allfiles{$embed_file}});
8143: $upload_output .=
8144: "\n\t\t".
8145: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8146: $attrib.'" />';
8147: if (exists($$codebase{$embed_file})) {
8148: $upload_output .=
8149: "\n\t\t".
8150: '<input name="codebase_'.$num.'" type="hidden" value="'.
8151: &escape($$codebase{$embed_file}).'" />';
8152: }
8153: }
8154: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8155: $num++;
8156: }
8157: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8158: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8159: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8160: '.&mt('(only files for which a location has been provided will be uploaded)').'
8161: </form>';
8162: return $upload_output;
8163: }
8164:
1.661 raeburn 8165: sub upload_embedded {
8166: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8167: $current_disk_usage) = @_;
8168: my $output;
8169: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8170: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8171: my $orig_uploaded_filename =
8172: $env{'form.embedded_item_'.$i.'.filename'};
8173:
8174: $env{'form.embedded_orig_'.$i} =
8175: &unescape($env{'form.embedded_orig_'.$i});
8176: my ($path,$fname) =
8177: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8178: # no path, whole string is fname
8179: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8180:
8181: $path = $env{'form.currentpath'}.$path;
8182: $fname = &Apache::lonnet::clean_filename($fname);
8183: # See if there is anything left
8184: next if ($fname eq '');
8185:
8186: # Check if file already exists as a file or directory.
8187: my ($state,$msg);
8188: if ($context eq 'portfolio') {
8189: my $port_path = $dirpath;
8190: if ($group ne '') {
8191: $port_path = "groups/$group/$port_path";
8192: }
8193: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8194: $dir_root,$port_path,$disk_quota,
8195: $current_disk_usage,$uname,$udom);
8196: if ($state eq 'will_exceed_quota'
8197: || $state eq 'file_locked'
8198: || $state eq 'file_exists' ) {
8199: $output .= $msg;
8200: next;
8201: }
8202: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8203: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8204: if ($state eq 'exists') {
8205: $output .= $msg;
8206: next;
8207: }
8208: }
8209: # Check if extension is valid
8210: if (($fname =~ /\.(\w+)$/) &&
8211: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8212: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8213: next;
8214: } elsif (($fname =~ /\.(\w+)$/) &&
8215: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8216: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8217: next;
8218: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8219: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8220: next;
8221: }
8222:
8223: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8224: if ($context eq 'portfolio') {
8225: my $result=
8226: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8227: $dirpath.$path);
8228: if ($result !~ m|^/uploaded/|) {
8229: $output .= '<span class="LC_error">'
8230: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8231: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8232: .'</span><br />';
8233: next;
8234: } else {
8235: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8236: $path.$fname.'</span>').'</p>';
8237: }
8238: } else {
8239: # Save the file
8240: my $target = $env{'form.embedded_item_'.$i};
8241: my $fullpath = $dir_root.$dirpath.'/'.$path;
8242: my $dest = $fullpath.$fname;
8243: my $url = $url_root.$dirpath.'/'.$path.$fname;
8244: my @parts=split(/\//,$fullpath);
8245: my $count;
8246: my $filepath = $dir_root;
8247: for ($count=4;$count<=$#parts;$count++) {
8248: $filepath .= "/$parts[$count]";
8249: if ((-e $filepath)!=1) {
8250: mkdir($filepath,0770);
8251: }
8252: }
8253: my $fh;
8254: if (!open($fh,'>'.$dest)) {
8255: &Apache::lonnet::logthis('Failed to create '.$dest);
8256: $output .= '<span class="LC_error">'.
8257: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8258: '</span><br />';
8259: } else {
8260: if (!print $fh $env{'form.embedded_item_'.$i}) {
8261: &Apache::lonnet::logthis('Failed to write to '.$dest);
8262: $output .= '<span class="LC_error">'.
8263: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8264: '</span><br />';
8265: } else {
8266: if ($context eq 'testbank') {
8267: $output .= &mt('Embedded file uploaded successfully:').
8268: ' <a href="'.$url.'">'.
8269: $orig_uploaded_filename.'</a><br />';
8270: } else {
1.705 tempelho 8271: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8272: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8273: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8274: }
8275: }
8276: close($fh);
8277: }
8278: }
8279: }
8280: return $output;
8281: }
8282:
8283: sub check_for_existing {
8284: my ($path,$fname,$element) = @_;
8285: my ($state,$msg);
8286: if (-d $path.'/'.$fname) {
8287: $state = 'exists';
8288: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8289: } elsif (-e $path.'/'.$fname) {
8290: $state = 'exists';
8291: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8292: }
8293: if ($state eq 'exists') {
8294: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8295: }
8296: return ($state,$msg);
8297: }
8298:
8299: sub check_for_upload {
8300: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8301: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8302: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8303: my $getpropath = 1;
8304: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8305: $getpropath);
8306: my $found_file = 0;
8307: my $locked_file = 0;
8308: foreach my $line (@dir_list) {
8309: my ($file_name)=split(/\&/,$line,2);
8310: if ($file_name eq $fname){
8311: $file_name = $path.$file_name;
8312: if ($group ne '') {
8313: $file_name = $group.$file_name;
8314: }
8315: $found_file = 1;
8316: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8317: $locked_file = 1;
8318: }
8319: }
8320: }
8321: if (($current_disk_usage + $filesize) > $disk_quota){
8322: my $msg = '<span class="LC_error">'.
8323: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8324: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8325: return ('will_exceed_quota',$msg);
8326: } elsif ($found_file) {
8327: if ($locked_file) {
8328: my $msg = '<span class="LC_error">';
8329: $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>');
8330: $msg .= '</span><br />';
8331: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8332: return ('file_locked',$msg);
8333: } else {
8334: my $msg = '<span class="LC_error">';
8335: $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'});
8336: $msg .= '</span>';
8337: $msg .= '<br />';
8338: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8339: return ('file_exists',$msg);
8340: }
8341: }
8342: }
8343:
1.31 albertel 8344:
1.41 ng 8345: =pod
1.45 matthew 8346:
1.464 albertel 8347: =back
1.41 ng 8348:
1.112 bowersj2 8349: =head1 CSV Upload/Handling functions
1.38 albertel 8350:
1.41 ng 8351: =over 4
8352:
1.648 raeburn 8353: =item * &upfile_store($r)
1.41 ng 8354:
8355: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8356: needs $env{'form.upfile'}
1.41 ng 8357: returns $datatoken to be put into hidden field
8358:
8359: =cut
1.31 albertel 8360:
8361: sub upfile_store {
8362: my $r=shift;
1.258 albertel 8363: $env{'form.upfile'}=~s/\r/\n/gs;
8364: $env{'form.upfile'}=~s/\f/\n/gs;
8365: $env{'form.upfile'}=~s/\n+/\n/gs;
8366: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8367:
1.258 albertel 8368: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8369: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8370: {
1.158 raeburn 8371: my $datafile = $r->dir_config('lonDaemons').
8372: '/tmp/'.$datatoken.'.tmp';
8373: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8374: print $fh $env{'form.upfile'};
1.158 raeburn 8375: close($fh);
8376: }
1.31 albertel 8377: }
8378: return $datatoken;
8379: }
8380:
1.56 matthew 8381: =pod
8382:
1.648 raeburn 8383: =item * &load_tmp_file($r)
1.41 ng 8384:
8385: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8386: needs $env{'form.datatoken'},
8387: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8388:
8389: =cut
1.31 albertel 8390:
8391: sub load_tmp_file {
8392: my $r=shift;
8393: my @studentdata=();
8394: {
1.158 raeburn 8395: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8396: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8397: if ( open(my $fh,"<$studentfile") ) {
8398: @studentdata=<$fh>;
8399: close($fh);
8400: }
1.31 albertel 8401: }
1.258 albertel 8402: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8403: }
8404:
1.56 matthew 8405: =pod
8406:
1.648 raeburn 8407: =item * &upfile_record_sep()
1.41 ng 8408:
8409: Separate uploaded file into records
8410: returns array of records,
1.258 albertel 8411: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8412:
8413: =cut
1.31 albertel 8414:
8415: sub upfile_record_sep {
1.258 albertel 8416: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8417: } else {
1.248 albertel 8418: my @records;
1.258 albertel 8419: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8420: if ($line=~/^\s*$/) { next; }
8421: push(@records,$line);
8422: }
8423: return @records;
1.31 albertel 8424: }
8425: }
8426:
1.56 matthew 8427: =pod
8428:
1.648 raeburn 8429: =item * &record_sep($record)
1.41 ng 8430:
1.258 albertel 8431: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8432:
8433: =cut
8434:
1.263 www 8435: sub takeleft {
8436: my $index=shift;
8437: return substr('0000'.$index,-4,4);
8438: }
8439:
1.31 albertel 8440: sub record_sep {
8441: my $record=shift;
8442: my %components=();
1.258 albertel 8443: if ($env{'form.upfiletype'} eq 'xml') {
8444: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8445: my $i=0;
1.356 albertel 8446: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8447: $field=~s/^(\"|\')//;
8448: $field=~s/(\"|\')$//;
1.263 www 8449: $components{&takeleft($i)}=$field;
1.31 albertel 8450: $i++;
8451: }
1.258 albertel 8452: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8453: my $i=0;
1.356 albertel 8454: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8455: $field=~s/^(\"|\')//;
8456: $field=~s/(\"|\')$//;
1.263 www 8457: $components{&takeleft($i)}=$field;
1.31 albertel 8458: $i++;
8459: }
8460: } else {
1.561 www 8461: my $separator=',';
1.480 banghart 8462: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8463: $separator=';';
1.480 banghart 8464: }
1.31 albertel 8465: my $i=0;
1.561 www 8466: # the character we are looking for to indicate the end of a quote or a record
8467: my $looking_for=$separator;
8468: # do not add the characters to the fields
8469: my $ignore=0;
8470: # we just encountered a separator (or the beginning of the record)
8471: my $just_found_separator=1;
8472: # store the field we are working on here
8473: my $field='';
8474: # work our way through all characters in record
8475: foreach my $character ($record=~/(.)/g) {
8476: if ($character eq $looking_for) {
8477: if ($character ne $separator) {
8478: # Found the end of a quote, again looking for separator
8479: $looking_for=$separator;
8480: $ignore=1;
8481: } else {
8482: # Found a separator, store away what we got
8483: $components{&takeleft($i)}=$field;
8484: $i++;
8485: $just_found_separator=1;
8486: $ignore=0;
8487: $field='';
8488: }
8489: next;
8490: }
8491: # single or double quotation marks after a separator indicate beginning of a quote
8492: # we are now looking for the end of the quote and need to ignore separators
8493: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8494: $looking_for=$character;
8495: next;
8496: }
8497: # ignore would be true after we reached the end of a quote
8498: if ($ignore) { next; }
8499: if (($just_found_separator) && ($character=~/\s/)) { next; }
8500: $field.=$character;
8501: $just_found_separator=0;
1.31 albertel 8502: }
1.561 www 8503: # catch the very last entry, since we never encountered the separator
8504: $components{&takeleft($i)}=$field;
1.31 albertel 8505: }
8506: return %components;
8507: }
8508:
1.144 matthew 8509: ######################################################
8510: ######################################################
8511:
1.56 matthew 8512: =pod
8513:
1.648 raeburn 8514: =item * &upfile_select_html()
1.41 ng 8515:
1.144 matthew 8516: Return HTML code to select a file from the users machine and specify
8517: the file type.
1.41 ng 8518:
8519: =cut
8520:
1.144 matthew 8521: ######################################################
8522: ######################################################
1.31 albertel 8523: sub upfile_select_html {
1.144 matthew 8524: my %Types = (
8525: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8526: semisv => &mt('Semicolon separated values'),
1.144 matthew 8527: space => &mt('Space separated'),
8528: tab => &mt('Tabulator separated'),
8529: # xml => &mt('HTML/XML'),
8530: );
8531: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8532: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8533: foreach my $type (sort(keys(%Types))) {
8534: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8535: }
8536: $Str .= "</select>\n";
8537: return $Str;
1.31 albertel 8538: }
8539:
1.301 albertel 8540: sub get_samples {
8541: my ($records,$toget) = @_;
8542: my @samples=({});
8543: my $got=0;
8544: foreach my $rec (@$records) {
8545: my %temp = &record_sep($rec);
8546: if (! grep(/\S/, values(%temp))) { next; }
8547: if (%temp) {
8548: $samples[$got]=\%temp;
8549: $got++;
8550: if ($got == $toget) { last; }
8551: }
8552: }
8553: return \@samples;
8554: }
8555:
1.144 matthew 8556: ######################################################
8557: ######################################################
8558:
1.56 matthew 8559: =pod
8560:
1.648 raeburn 8561: =item * &csv_print_samples($r,$records)
1.41 ng 8562:
8563: Prints a table of sample values from each column uploaded $r is an
8564: Apache Request ref, $records is an arrayref from
8565: &Apache::loncommon::upfile_record_sep
8566:
8567: =cut
8568:
1.144 matthew 8569: ######################################################
8570: ######################################################
1.31 albertel 8571: sub csv_print_samples {
8572: my ($r,$records) = @_;
1.662 bisitz 8573: my $samples = &get_samples($records,5);
1.301 albertel 8574:
1.594 raeburn 8575: $r->print(&mt('Samples').'<br />'.&start_data_table().
8576: &start_data_table_header_row());
1.356 albertel 8577: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8578: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8579: $r->print(&end_data_table_header_row());
1.301 albertel 8580: foreach my $hash (@$samples) {
1.594 raeburn 8581: $r->print(&start_data_table_row());
1.356 albertel 8582: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8583: $r->print('<td>');
1.356 albertel 8584: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8585: $r->print('</td>');
8586: }
1.594 raeburn 8587: $r->print(&end_data_table_row());
1.31 albertel 8588: }
1.594 raeburn 8589: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8590: }
8591:
1.144 matthew 8592: ######################################################
8593: ######################################################
8594:
1.56 matthew 8595: =pod
8596:
1.648 raeburn 8597: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8598:
8599: Prints a table to create associations between values and table columns.
1.144 matthew 8600:
1.41 ng 8601: $r is an Apache Request ref,
8602: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8603: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8604:
8605: =cut
8606:
1.144 matthew 8607: ######################################################
8608: ######################################################
1.31 albertel 8609: sub csv_print_select_table {
8610: my ($r,$records,$d) = @_;
1.301 albertel 8611: my $i=0;
8612: my $samples = &get_samples($records,1);
1.144 matthew 8613: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8614: &start_data_table().&start_data_table_header_row().
1.144 matthew 8615: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8616: '<th>'.&mt('Column').'</th>'.
8617: &end_data_table_header_row()."\n");
1.356 albertel 8618: foreach my $array_ref (@$d) {
8619: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8620: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8621:
1.875 bisitz 8622: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8623: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8624: $r->print('<option value="none"></option>');
1.356 albertel 8625: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8626: $r->print('<option value="'.$sample.'"'.
8627: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8628: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8629: }
1.594 raeburn 8630: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8631: $i++;
8632: }
1.594 raeburn 8633: $r->print(&end_data_table());
1.31 albertel 8634: $i--;
8635: return $i;
8636: }
1.56 matthew 8637:
1.144 matthew 8638: ######################################################
8639: ######################################################
8640:
1.56 matthew 8641: =pod
1.31 albertel 8642:
1.648 raeburn 8643: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8644:
8645: Prints a table of sample values from the upload and can make associate samples to internal names.
8646:
8647: $r is an Apache Request ref,
8648: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8649: $d is an array of 2 element arrays (internal name, displayed name)
8650:
8651: =cut
8652:
1.144 matthew 8653: ######################################################
8654: ######################################################
1.31 albertel 8655: sub csv_samples_select_table {
8656: my ($r,$records,$d) = @_;
8657: my $i=0;
1.144 matthew 8658: #
1.662 bisitz 8659: my $max_samples = 5;
8660: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8661: $r->print(&start_data_table().
8662: &start_data_table_header_row().'<th>'.
8663: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8664: &end_data_table_header_row());
1.301 albertel 8665:
8666: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8667: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8668: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8669: foreach my $option (@$d) {
8670: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8671: $r->print('<option value="'.$value.'"'.
1.253 albertel 8672: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8673: $display.'</option>');
1.31 albertel 8674: }
8675: $r->print('</select></td><td>');
1.662 bisitz 8676: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8677: if (defined($samples->[$line]{$key})) {
8678: $r->print($samples->[$line]{$key}."<br />\n");
8679: }
8680: }
1.594 raeburn 8681: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8682: $i++;
8683: }
1.594 raeburn 8684: $r->print(&end_data_table());
1.31 albertel 8685: $i--;
8686: return($i);
1.115 matthew 8687: }
8688:
1.144 matthew 8689: ######################################################
8690: ######################################################
8691:
1.115 matthew 8692: =pod
8693:
1.648 raeburn 8694: =item * &clean_excel_name($name)
1.115 matthew 8695:
8696: Returns a replacement for $name which does not contain any illegal characters.
8697:
8698: =cut
8699:
1.144 matthew 8700: ######################################################
8701: ######################################################
1.115 matthew 8702: sub clean_excel_name {
8703: my ($name) = @_;
8704: $name =~ s/[:\*\?\/\\]//g;
8705: if (length($name) > 31) {
8706: $name = substr($name,0,31);
8707: }
8708: return $name;
1.25 albertel 8709: }
1.84 albertel 8710:
1.85 albertel 8711: =pod
8712:
1.648 raeburn 8713: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8714:
8715: Returns either 1 or undef
8716:
8717: 1 if the part is to be hidden, undef if it is to be shown
8718:
8719: Arguments are:
8720:
8721: $id the id of the part to be checked
8722: $symb, optional the symb of the resource to check
8723: $udom, optional the domain of the user to check for
8724: $uname, optional the username of the user to check for
8725:
8726: =cut
1.84 albertel 8727:
8728: sub check_if_partid_hidden {
8729: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8730: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8731: $symb,$udom,$uname);
1.141 albertel 8732: my $truth=1;
8733: #if the string starts with !, then the list is the list to show not hide
8734: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8735: my @hiddenlist=split(/,/,$hiddenparts);
8736: foreach my $checkid (@hiddenlist) {
1.141 albertel 8737: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8738: }
1.141 albertel 8739: return !$truth;
1.84 albertel 8740: }
1.127 matthew 8741:
1.138 matthew 8742:
8743: ############################################################
8744: ############################################################
8745:
8746: =pod
8747:
1.157 matthew 8748: =back
8749:
1.138 matthew 8750: =head1 cgi-bin script and graphing routines
8751:
1.157 matthew 8752: =over 4
8753:
1.648 raeburn 8754: =item * &get_cgi_id()
1.138 matthew 8755:
8756: Inputs: none
8757:
8758: Returns an id which can be used to pass environment variables
8759: to various cgi-bin scripts. These environment variables will
8760: be removed from the users environment after a given time by
8761: the routine &Apache::lonnet::transfer_profile_to_env.
8762:
8763: =cut
8764:
8765: ############################################################
8766: ############################################################
1.152 albertel 8767: my $uniq=0;
1.136 matthew 8768: sub get_cgi_id {
1.154 albertel 8769: $uniq=($uniq+1)%100000;
1.280 albertel 8770: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8771: }
8772:
1.127 matthew 8773: ############################################################
8774: ############################################################
8775:
8776: =pod
8777:
1.648 raeburn 8778: =item * &DrawBarGraph()
1.127 matthew 8779:
1.138 matthew 8780: Facilitates the plotting of data in a (stacked) bar graph.
8781: Puts plot definition data into the users environment in order for
8782: graph.png to plot it. Returns an <img> tag for the plot.
8783: The bars on the plot are labeled '1','2',...,'n'.
8784:
8785: Inputs:
8786:
8787: =over 4
8788:
8789: =item $Title: string, the title of the plot
8790:
8791: =item $xlabel: string, text describing the X-axis of the plot
8792:
8793: =item $ylabel: string, text describing the Y-axis of the plot
8794:
8795: =item $Max: scalar, the maximum Y value to use in the plot
8796: If $Max is < any data point, the graph will not be rendered.
8797:
1.140 matthew 8798: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8799: they are plotted. If undefined, default values will be used.
8800:
1.178 matthew 8801: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8802:
1.138 matthew 8803: =item @Values: An array of array references. Each array reference holds data
8804: to be plotted in a stacked bar chart.
8805:
1.239 matthew 8806: =item If the final element of @Values is a hash reference the key/value
8807: pairs will be added to the graph definition.
8808:
1.138 matthew 8809: =back
8810:
8811: Returns:
8812:
8813: An <img> tag which references graph.png and the appropriate identifying
8814: information for the plot.
8815:
1.127 matthew 8816: =cut
8817:
8818: ############################################################
8819: ############################################################
1.134 matthew 8820: sub DrawBarGraph {
1.178 matthew 8821: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8822: #
8823: if (! defined($colors)) {
8824: $colors = ['#33ff00',
8825: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8826: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8827: ];
8828: }
1.228 matthew 8829: my $extra_settings = {};
8830: if (ref($Values[-1]) eq 'HASH') {
8831: $extra_settings = pop(@Values);
8832: }
1.127 matthew 8833: #
1.136 matthew 8834: my $identifier = &get_cgi_id();
8835: my $id = 'cgi.'.$identifier;
1.129 matthew 8836: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8837: return '';
8838: }
1.225 matthew 8839: #
8840: my @Labels;
8841: if (defined($labels)) {
8842: @Labels = @$labels;
8843: } else {
8844: for (my $i=0;$i<@{$Values[0]};$i++) {
8845: push (@Labels,$i+1);
8846: }
8847: }
8848: #
1.129 matthew 8849: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8850: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8851: my %ValuesHash;
8852: my $NumSets=1;
8853: foreach my $array (@Values) {
8854: next if (! ref($array));
1.136 matthew 8855: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8856: join(',',@$array);
1.129 matthew 8857: }
1.127 matthew 8858: #
1.136 matthew 8859: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8860: if ($NumBars < 3) {
8861: $width = 120+$NumBars*32;
1.220 matthew 8862: $xskip = 1;
1.225 matthew 8863: $bar_width = 30;
8864: } elsif ($NumBars < 5) {
8865: $width = 120+$NumBars*20;
8866: $xskip = 1;
8867: $bar_width = 20;
1.220 matthew 8868: } elsif ($NumBars < 10) {
1.136 matthew 8869: $width = 120+$NumBars*15;
8870: $xskip = 1;
8871: $bar_width = 15;
8872: } elsif ($NumBars <= 25) {
8873: $width = 120+$NumBars*11;
8874: $xskip = 5;
8875: $bar_width = 8;
8876: } elsif ($NumBars <= 50) {
8877: $width = 120+$NumBars*8;
8878: $xskip = 5;
8879: $bar_width = 4;
8880: } else {
8881: $width = 120+$NumBars*8;
8882: $xskip = 5;
8883: $bar_width = 4;
8884: }
8885: #
1.137 matthew 8886: $Max = 1 if ($Max < 1);
8887: if ( int($Max) < $Max ) {
8888: $Max++;
8889: $Max = int($Max);
8890: }
1.127 matthew 8891: $Title = '' if (! defined($Title));
8892: $xlabel = '' if (! defined($xlabel));
8893: $ylabel = '' if (! defined($ylabel));
1.369 www 8894: $ValuesHash{$id.'.title'} = &escape($Title);
8895: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8896: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8897: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8898: $ValuesHash{$id.'.NumBars'} = $NumBars;
8899: $ValuesHash{$id.'.NumSets'} = $NumSets;
8900: $ValuesHash{$id.'.PlotType'} = 'bar';
8901: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8902: $ValuesHash{$id.'.height'} = $height;
8903: $ValuesHash{$id.'.width'} = $width;
8904: $ValuesHash{$id.'.xskip'} = $xskip;
8905: $ValuesHash{$id.'.bar_width'} = $bar_width;
8906: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8907: #
1.228 matthew 8908: # Deal with other parameters
8909: while (my ($key,$value) = each(%$extra_settings)) {
8910: $ValuesHash{$id.'.'.$key} = $value;
8911: }
8912: #
1.646 raeburn 8913: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8914: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8915: }
8916:
8917: ############################################################
8918: ############################################################
8919:
8920: =pod
8921:
1.648 raeburn 8922: =item * &DrawXYGraph()
1.137 matthew 8923:
1.138 matthew 8924: Facilitates the plotting of data in an XY graph.
8925: Puts plot definition data into the users environment in order for
8926: graph.png to plot it. Returns an <img> tag for the plot.
8927:
8928: Inputs:
8929:
8930: =over 4
8931:
8932: =item $Title: string, the title of the plot
8933:
8934: =item $xlabel: string, text describing the X-axis of the plot
8935:
8936: =item $ylabel: string, text describing the Y-axis of the plot
8937:
8938: =item $Max: scalar, the maximum Y value to use in the plot
8939: If $Max is < any data point, the graph will not be rendered.
8940:
8941: =item $colors: Array ref containing the hex color codes for the data to be
8942: plotted in. If undefined, default values will be used.
8943:
8944: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8945:
8946: =item $Ydata: Array ref containing Array refs.
1.185 www 8947: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8948:
8949: =item %Values: hash indicating or overriding any default values which are
8950: passed to graph.png.
8951: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8952:
8953: =back
8954:
8955: Returns:
8956:
8957: An <img> tag which references graph.png and the appropriate identifying
8958: information for the plot.
8959:
1.137 matthew 8960: =cut
8961:
8962: ############################################################
8963: ############################################################
8964: sub DrawXYGraph {
8965: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8966: #
8967: # Create the identifier for the graph
8968: my $identifier = &get_cgi_id();
8969: my $id = 'cgi.'.$identifier;
8970: #
8971: $Title = '' if (! defined($Title));
8972: $xlabel = '' if (! defined($xlabel));
8973: $ylabel = '' if (! defined($ylabel));
8974: my %ValuesHash =
8975: (
1.369 www 8976: $id.'.title' => &escape($Title),
8977: $id.'.xlabel' => &escape($xlabel),
8978: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8979: $id.'.y_max_value'=> $Max,
8980: $id.'.labels' => join(',',@$Xlabels),
8981: $id.'.PlotType' => 'XY',
8982: );
8983: #
8984: if (defined($colors) && ref($colors) eq 'ARRAY') {
8985: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8986: }
8987: #
8988: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8989: return '';
8990: }
8991: my $NumSets=1;
1.138 matthew 8992: foreach my $array (@{$Ydata}){
1.137 matthew 8993: next if (! ref($array));
8994: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8995: }
1.138 matthew 8996: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8997: #
8998: # Deal with other parameters
8999: while (my ($key,$value) = each(%Values)) {
9000: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9001: }
9002: #
1.646 raeburn 9003: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9004: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9005: }
9006:
9007: ############################################################
9008: ############################################################
9009:
9010: =pod
9011:
1.648 raeburn 9012: =item * &DrawXYYGraph()
1.138 matthew 9013:
9014: Facilitates the plotting of data in an XY graph with two Y axes.
9015: Puts plot definition data into the users environment in order for
9016: graph.png to plot it. Returns an <img> tag for the plot.
9017:
9018: Inputs:
9019:
9020: =over 4
9021:
9022: =item $Title: string, the title of the plot
9023:
9024: =item $xlabel: string, text describing the X-axis of the plot
9025:
9026: =item $ylabel: string, text describing the Y-axis of the plot
9027:
9028: =item $colors: Array ref containing the hex color codes for the data to be
9029: plotted in. If undefined, default values will be used.
9030:
9031: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9032:
9033: =item $Ydata1: The first data set
9034:
9035: =item $Min1: The minimum value of the left Y-axis
9036:
9037: =item $Max1: The maximum value of the left Y-axis
9038:
9039: =item $Ydata2: The second data set
9040:
9041: =item $Min2: The minimum value of the right Y-axis
9042:
9043: =item $Max2: The maximum value of the left Y-axis
9044:
9045: =item %Values: hash indicating or overriding any default values which are
9046: passed to graph.png.
9047: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9048:
9049: =back
9050:
9051: Returns:
9052:
9053: An <img> tag which references graph.png and the appropriate identifying
9054: information for the plot.
1.136 matthew 9055:
9056: =cut
9057:
9058: ############################################################
9059: ############################################################
1.137 matthew 9060: sub DrawXYYGraph {
9061: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9062: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9063: #
9064: # Create the identifier for the graph
9065: my $identifier = &get_cgi_id();
9066: my $id = 'cgi.'.$identifier;
9067: #
9068: $Title = '' if (! defined($Title));
9069: $xlabel = '' if (! defined($xlabel));
9070: $ylabel = '' if (! defined($ylabel));
9071: my %ValuesHash =
9072: (
1.369 www 9073: $id.'.title' => &escape($Title),
9074: $id.'.xlabel' => &escape($xlabel),
9075: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9076: $id.'.labels' => join(',',@$Xlabels),
9077: $id.'.PlotType' => 'XY',
9078: $id.'.NumSets' => 2,
1.137 matthew 9079: $id.'.two_axes' => 1,
9080: $id.'.y1_max_value' => $Max1,
9081: $id.'.y1_min_value' => $Min1,
9082: $id.'.y2_max_value' => $Max2,
9083: $id.'.y2_min_value' => $Min2,
1.136 matthew 9084: );
9085: #
1.137 matthew 9086: if (defined($colors) && ref($colors) eq 'ARRAY') {
9087: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9088: }
9089: #
9090: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9091: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9092: return '';
9093: }
9094: my $NumSets=1;
1.137 matthew 9095: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9096: next if (! ref($array));
9097: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9098: }
9099: #
9100: # Deal with other parameters
9101: while (my ($key,$value) = each(%Values)) {
9102: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9103: }
9104: #
1.646 raeburn 9105: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9106: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9107: }
9108:
9109: ############################################################
9110: ############################################################
9111:
9112: =pod
9113:
1.157 matthew 9114: =back
9115:
1.139 matthew 9116: =head1 Statistics helper routines?
9117:
9118: Bad place for them but what the hell.
9119:
1.157 matthew 9120: =over 4
9121:
1.648 raeburn 9122: =item * &chartlink()
1.139 matthew 9123:
9124: Returns a link to the chart for a specific student.
9125:
9126: Inputs:
9127:
9128: =over 4
9129:
9130: =item $linktext: The text of the link
9131:
9132: =item $sname: The students username
9133:
9134: =item $sdomain: The students domain
9135:
9136: =back
9137:
1.157 matthew 9138: =back
9139:
1.139 matthew 9140: =cut
9141:
9142: ############################################################
9143: ############################################################
9144: sub chartlink {
9145: my ($linktext, $sname, $sdomain) = @_;
9146: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9147: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9148: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9149: '">'.$linktext.'</a>';
1.153 matthew 9150: }
9151:
9152: #######################################################
9153: #######################################################
9154:
9155: =pod
9156:
9157: =head1 Course Environment Routines
1.157 matthew 9158:
9159: =over 4
1.153 matthew 9160:
1.648 raeburn 9161: =item * &restore_course_settings()
1.153 matthew 9162:
1.648 raeburn 9163: =item * &store_course_settings()
1.153 matthew 9164:
9165: Restores/Store indicated form parameters from the course environment.
9166: Will not overwrite existing values of the form parameters.
9167:
9168: Inputs:
9169: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9170:
9171: a hash ref describing the data to be stored. For example:
9172:
9173: %Save_Parameters = ('Status' => 'scalar',
9174: 'chartoutputmode' => 'scalar',
9175: 'chartoutputdata' => 'scalar',
9176: 'Section' => 'array',
1.373 raeburn 9177: 'Group' => 'array',
1.153 matthew 9178: 'StudentData' => 'array',
9179: 'Maps' => 'array');
9180:
9181: Returns: both routines return nothing
9182:
1.631 raeburn 9183: =back
9184:
1.153 matthew 9185: =cut
9186:
9187: #######################################################
9188: #######################################################
9189: sub store_course_settings {
1.496 albertel 9190: return &store_settings($env{'request.course.id'},@_);
9191: }
9192:
9193: sub store_settings {
1.153 matthew 9194: # save to the environment
9195: # appenv the same items, just to be safe
1.300 albertel 9196: my $udom = $env{'user.domain'};
9197: my $uname = $env{'user.name'};
1.496 albertel 9198: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9199: my %SaveHash;
9200: my %AppHash;
9201: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9202: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9203: my $envname = 'environment.'.$basename;
1.258 albertel 9204: if (exists($env{'form.'.$setting})) {
1.153 matthew 9205: # Save this value away
9206: if ($type eq 'scalar' &&
1.258 albertel 9207: (! exists($env{$envname}) ||
9208: $env{$envname} ne $env{'form.'.$setting})) {
9209: $SaveHash{$basename} = $env{'form.'.$setting};
9210: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9211: } elsif ($type eq 'array') {
9212: my $stored_form;
1.258 albertel 9213: if (ref($env{'form.'.$setting})) {
1.153 matthew 9214: $stored_form = join(',',
9215: map {
1.369 www 9216: &escape($_);
1.258 albertel 9217: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9218: } else {
9219: $stored_form =
1.369 www 9220: &escape($env{'form.'.$setting});
1.153 matthew 9221: }
9222: # Determine if the array contents are the same.
1.258 albertel 9223: if ($stored_form ne $env{$envname}) {
1.153 matthew 9224: $SaveHash{$basename} = $stored_form;
9225: $AppHash{$envname} = $stored_form;
9226: }
9227: }
9228: }
9229: }
9230: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9231: $udom,$uname);
1.153 matthew 9232: if ($put_result !~ /^(ok|delayed)/) {
9233: &Apache::lonnet::logthis('unable to save form parameters, '.
9234: 'got error:'.$put_result);
9235: }
9236: # Make sure these settings stick around in this session, too
1.646 raeburn 9237: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9238: return;
9239: }
9240:
9241: sub restore_course_settings {
1.499 albertel 9242: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9243: }
9244:
9245: sub restore_settings {
9246: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9247: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9248: next if (exists($env{'form.'.$setting}));
1.496 albertel 9249: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9250: '.'.$setting;
1.258 albertel 9251: if (exists($env{$envname})) {
1.153 matthew 9252: if ($type eq 'scalar') {
1.258 albertel 9253: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9254: } elsif ($type eq 'array') {
1.258 albertel 9255: $env{'form.'.$setting} = [
1.153 matthew 9256: map {
1.369 www 9257: &unescape($_);
1.258 albertel 9258: } split(',',$env{$envname})
1.153 matthew 9259: ];
9260: }
9261: }
9262: }
1.127 matthew 9263: }
9264:
1.618 raeburn 9265: #######################################################
9266: #######################################################
9267:
9268: =pod
9269:
9270: =head1 Domain E-mail Routines
9271:
9272: =over 4
9273:
1.648 raeburn 9274: =item * &build_recipient_list()
1.618 raeburn 9275:
1.766 raeburn 9276: Build recipient lists for four types of e-mail:
9277: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9278: (d) Help requests, generated by
9279: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9280:
9281: Inputs:
1.619 raeburn 9282: defmail (scalar - email address of default recipient),
1.618 raeburn 9283: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9284: defdom (domain for which to retrieve configuration settings),
9285: origmail (scalar - email address of recipient from loncapa.conf,
9286: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9287:
1.655 raeburn 9288: Returns: comma separated list of addresses to which to send e-mail.
9289:
9290: =back
1.618 raeburn 9291:
9292: =cut
9293:
9294: ############################################################
9295: ############################################################
9296: sub build_recipient_list {
1.619 raeburn 9297: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9298: my @recipients;
9299: my $otheremails;
9300: my %domconfig =
9301: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9302: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9303: if (exists($domconfig{'contacts'}{$mailing})) {
9304: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9305: my @contacts = ('adminemail','supportemail');
9306: foreach my $item (@contacts) {
9307: if ($domconfig{'contacts'}{$mailing}{$item}) {
9308: my $addr = $domconfig{'contacts'}{$item};
9309: if (!grep(/^\Q$addr\E$/,@recipients)) {
9310: push(@recipients,$addr);
9311: }
1.619 raeburn 9312: }
1.766 raeburn 9313: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9314: }
9315: }
1.766 raeburn 9316: } elsif ($origmail ne '') {
9317: push(@recipients,$origmail);
1.618 raeburn 9318: }
1.619 raeburn 9319: } elsif ($origmail ne '') {
9320: push(@recipients,$origmail);
1.618 raeburn 9321: }
1.688 raeburn 9322: if (defined($defmail)) {
9323: if ($defmail ne '') {
9324: push(@recipients,$defmail);
9325: }
1.618 raeburn 9326: }
9327: if ($otheremails) {
1.619 raeburn 9328: my @others;
9329: if ($otheremails =~ /,/) {
9330: @others = split(/,/,$otheremails);
1.618 raeburn 9331: } else {
1.619 raeburn 9332: push(@others,$otheremails);
9333: }
9334: foreach my $addr (@others) {
9335: if (!grep(/^\Q$addr\E$/,@recipients)) {
9336: push(@recipients,$addr);
9337: }
1.618 raeburn 9338: }
9339: }
1.619 raeburn 9340: my $recipientlist = join(',',@recipients);
1.618 raeburn 9341: return $recipientlist;
9342: }
9343:
1.127 matthew 9344: ############################################################
9345: ############################################################
1.154 albertel 9346:
1.655 raeburn 9347: =pod
9348:
9349: =head1 Course Catalog Routines
9350:
9351: =over 4
9352:
9353: =item * &gather_categories()
9354:
9355: Converts category definitions - keys of categories hash stored in
9356: coursecategories in configuration.db on the primary library server in a
9357: domain - to an array. Also generates javascript and idx hash used to
9358: generate Domain Coordinator interface for editing Course Categories.
9359:
9360: Inputs:
1.663 raeburn 9361:
1.655 raeburn 9362: categories (reference to hash of category definitions).
1.663 raeburn 9363:
1.655 raeburn 9364: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9365: categories and subcategories).
1.663 raeburn 9366:
1.655 raeburn 9367: idx (reference to hash of counters used in Domain Coordinator interface for
9368: editing Course Categories).
1.663 raeburn 9369:
1.655 raeburn 9370: jsarray (reference to array of categories used to create Javascript arrays for
9371: Domain Coordinator interface for editing Course Categories).
9372:
9373: Returns: nothing
9374:
9375: Side effects: populates cats, idx and jsarray.
9376:
9377: =cut
9378:
9379: sub gather_categories {
9380: my ($categories,$cats,$idx,$jsarray) = @_;
9381: my %counters;
9382: my $num = 0;
9383: foreach my $item (keys(%{$categories})) {
9384: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9385: if ($container eq '' && $depth == 0) {
9386: $cats->[$depth][$categories->{$item}] = $cat;
9387: } else {
9388: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9389: }
9390: my ($escitem,$tail) = split(/:/,$item,2);
9391: if ($counters{$tail} eq '') {
9392: $counters{$tail} = $num;
9393: $num ++;
9394: }
9395: if (ref($idx) eq 'HASH') {
9396: $idx->{$item} = $counters{$tail};
9397: }
9398: if (ref($jsarray) eq 'ARRAY') {
9399: push(@{$jsarray->[$counters{$tail}]},$item);
9400: }
9401: }
9402: return;
9403: }
9404:
9405: =pod
9406:
9407: =item * &extract_categories()
9408:
9409: Used to generate breadcrumb trails for course categories.
9410:
9411: Inputs:
1.663 raeburn 9412:
1.655 raeburn 9413: categories (reference to hash of category definitions).
1.663 raeburn 9414:
1.655 raeburn 9415: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9416: categories and subcategories).
1.663 raeburn 9417:
1.655 raeburn 9418: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9419:
1.655 raeburn 9420: allitems (reference to hash - key is category key
9421: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9422:
1.655 raeburn 9423: idx (reference to hash of counters used in Domain Coordinator interface for
9424: editing Course Categories).
1.663 raeburn 9425:
1.655 raeburn 9426: jsarray (reference to array of categories used to create Javascript arrays for
9427: Domain Coordinator interface for editing Course Categories).
9428:
1.665 raeburn 9429: subcats (reference to hash of arrays containing all subcategories within each
9430: category, -recursive)
9431:
1.655 raeburn 9432: Returns: nothing
9433:
9434: Side effects: populates trails and allitems hash references.
9435:
9436: =cut
9437:
9438: sub extract_categories {
1.665 raeburn 9439: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9440: if (ref($categories) eq 'HASH') {
9441: &gather_categories($categories,$cats,$idx,$jsarray);
9442: if (ref($cats->[0]) eq 'ARRAY') {
9443: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9444: my $name = $cats->[0][$i];
9445: my $item = &escape($name).'::0';
9446: my $trailstr;
9447: if ($name eq 'instcode') {
9448: $trailstr = &mt('Official courses (with institutional codes)');
9449: } else {
9450: $trailstr = $name;
9451: }
9452: if ($allitems->{$item} eq '') {
9453: push(@{$trails},$trailstr);
9454: $allitems->{$item} = scalar(@{$trails})-1;
9455: }
9456: my @parents = ($name);
9457: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9458: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9459: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9460: if (ref($subcats) eq 'HASH') {
9461: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9462: }
9463: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9464: }
9465: } else {
9466: if (ref($subcats) eq 'HASH') {
9467: $subcats->{$item} = [];
1.655 raeburn 9468: }
9469: }
9470: }
9471: }
9472: }
9473: return;
9474: }
9475:
9476: =pod
9477:
9478: =item *&recurse_categories()
9479:
9480: Recursively used to generate breadcrumb trails for course categories.
9481:
9482: Inputs:
1.663 raeburn 9483:
1.655 raeburn 9484: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9485: categories and subcategories).
1.663 raeburn 9486:
1.655 raeburn 9487: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9488:
9489: category (current course category, for which breadcrumb trail is being generated).
9490:
9491: trails (reference to array of breadcrumb trails for each category).
9492:
1.655 raeburn 9493: allitems (reference to hash - key is category key
9494: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9495:
1.655 raeburn 9496: parents (array containing containers directories for current category,
9497: back to top level).
9498:
9499: Returns: nothing
9500:
9501: Side effects: populates trails and allitems hash references
9502:
9503: =cut
9504:
9505: sub recurse_categories {
1.665 raeburn 9506: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9507: my $shallower = $depth - 1;
9508: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9509: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9510: my $name = $cats->[$depth]{$category}[$k];
9511: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9512: my $trailstr = join(' -> ',(@{$parents},$category));
9513: if ($allitems->{$item} eq '') {
9514: push(@{$trails},$trailstr);
9515: $allitems->{$item} = scalar(@{$trails})-1;
9516: }
9517: my $deeper = $depth+1;
9518: push(@{$parents},$category);
1.665 raeburn 9519: if (ref($subcats) eq 'HASH') {
9520: my $subcat = &escape($name).':'.$category.':'.$depth;
9521: for (my $j=@{$parents}; $j>=0; $j--) {
9522: my $higher;
9523: if ($j > 0) {
9524: $higher = &escape($parents->[$j]).':'.
9525: &escape($parents->[$j-1]).':'.$j;
9526: } else {
9527: $higher = &escape($parents->[$j]).'::'.$j;
9528: }
9529: push(@{$subcats->{$higher}},$subcat);
9530: }
9531: }
9532: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9533: $subcats);
1.655 raeburn 9534: pop(@{$parents});
9535: }
9536: } else {
9537: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9538: my $trailstr = join(' -> ',(@{$parents},$category));
9539: if ($allitems->{$item} eq '') {
9540: push(@{$trails},$trailstr);
9541: $allitems->{$item} = scalar(@{$trails})-1;
9542: }
9543: }
9544: return;
9545: }
9546:
1.663 raeburn 9547: =pod
9548:
9549: =item *&assign_categories_table()
9550:
9551: Create a datatable for display of hierarchical categories in a domain,
9552: with checkboxes to allow a course to be categorized.
9553:
9554: Inputs:
9555:
9556: cathash - reference to hash of categories defined for the domain (from
9557: configuration.db)
9558:
9559: currcat - scalar with an & separated list of categories assigned to a course.
9560:
9561: Returns: $output (markup to be displayed)
9562:
9563: =cut
9564:
9565: sub assign_categories_table {
9566: my ($cathash,$currcat) = @_;
9567: my $output;
9568: if (ref($cathash) eq 'HASH') {
9569: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9570: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9571: $maxdepth = scalar(@cats);
9572: if (@cats > 0) {
9573: my $itemcount = 0;
9574: if (ref($cats[0]) eq 'ARRAY') {
9575: $output = &Apache::loncommon::start_data_table();
9576: my @currcategories;
9577: if ($currcat ne '') {
9578: @currcategories = split('&',$currcat);
9579: }
9580: for (my $i=0; $i<@{$cats[0]}; $i++) {
9581: my $parent = $cats[0][$i];
9582: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9583: next if ($parent eq 'instcode');
9584: my $item = &escape($parent).'::0';
9585: my $checked = '';
9586: if (@currcategories > 0) {
9587: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9588: $checked = ' checked="checked"';
1.663 raeburn 9589: }
9590: }
1.675 raeburn 9591: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9592: '<input type="checkbox" name="usecategory" value="'.
9593: $item.'"'.$checked.' />'.$parent.'</span>'.
9594: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9595: my $depth = 1;
9596: push(@path,$parent);
9597: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9598: pop(@path);
9599: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9600: $itemcount ++;
9601: }
9602: $output .= &Apache::loncommon::end_data_table();
9603: }
9604: }
9605: }
9606: return $output;
9607: }
9608:
9609: =pod
9610:
9611: =item *&assign_category_rows()
9612:
9613: Create a datatable row for display of nested categories in a domain,
9614: with checkboxes to allow a course to be categorized,called recursively.
9615:
9616: Inputs:
9617:
9618: itemcount - track row number for alternating colors
9619:
9620: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9621: categories and subcategories.
9622:
9623: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9624:
9625: parent - parent of current category item
9626:
9627: path - Array containing all categories back up through the hierarchy from the
9628: current category to the top level.
9629:
9630: currcategories - reference to array of current categories assigned to the course
9631:
9632: Returns: $output (markup to be displayed).
9633:
9634: =cut
9635:
9636: sub assign_category_rows {
9637: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9638: my ($text,$name,$item,$chgstr);
9639: if (ref($cats) eq 'ARRAY') {
9640: my $maxdepth = scalar(@{$cats});
9641: if (ref($cats->[$depth]) eq 'HASH') {
9642: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9643: my $numchildren = @{$cats->[$depth]{$parent}};
9644: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9645: $text .= '<td><table class="LC_datatable">';
9646: for (my $j=0; $j<$numchildren; $j++) {
9647: $name = $cats->[$depth]{$parent}[$j];
9648: $item = &escape($name).':'.&escape($parent).':'.$depth;
9649: my $deeper = $depth+1;
9650: my $checked = '';
9651: if (ref($currcategories) eq 'ARRAY') {
9652: if (@{$currcategories} > 0) {
9653: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9654: $checked = ' checked="checked"';
1.663 raeburn 9655: }
9656: }
9657: }
1.664 raeburn 9658: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9659: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9660: $item.'"'.$checked.' />'.$name.'</label></span>'.
9661: '<input type="hidden" name="catname" value="'.$name.'" />'.
9662: '</td><td>';
1.663 raeburn 9663: if (ref($path) eq 'ARRAY') {
9664: push(@{$path},$name);
9665: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9666: pop(@{$path});
9667: }
9668: $text .= '</td></tr>';
9669: }
9670: $text .= '</table></td>';
9671: }
9672: }
9673: }
9674: return $text;
9675: }
9676:
1.655 raeburn 9677: ############################################################
9678: ############################################################
9679:
9680:
1.443 albertel 9681: sub commit_customrole {
1.664 raeburn 9682: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9683: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9684: ($start?', '.&mt('starting').' '.localtime($start):'').
9685: ($end?', ending '.localtime($end):'').': <b>'.
9686: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9687: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9688: '</b><br />';
9689: return $output;
9690: }
9691:
9692: sub commit_standardrole {
1.541 raeburn 9693: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9694: my ($output,$logmsg,$linefeed);
9695: if ($context eq 'auto') {
9696: $linefeed = "\n";
9697: } else {
9698: $linefeed = "<br />\n";
9699: }
1.443 albertel 9700: if ($three eq 'st') {
1.541 raeburn 9701: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9702: $one,$two,$sec,$context);
9703: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9704: ($result eq 'unknown_course') || ($result eq 'refused')) {
9705: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9706: } else {
1.541 raeburn 9707: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9708: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9709: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9710: if ($context eq 'auto') {
9711: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9712: } else {
9713: $output .= '<b>'.$result.'</b>'.$linefeed.
9714: &mt('Add to classlist').': <b>ok</b>';
9715: }
9716: $output .= $linefeed;
1.443 albertel 9717: }
9718: } else {
9719: $output = &mt('Assigning').' '.$three.' in '.$url.
9720: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9721: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9722: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9723: if ($context eq 'auto') {
9724: $output .= $result.$linefeed;
9725: } else {
9726: $output .= '<b>'.$result.'</b>'.$linefeed;
9727: }
1.443 albertel 9728: }
9729: return $output;
9730: }
9731:
9732: sub commit_studentrole {
1.541 raeburn 9733: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9734: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9735: if ($context eq 'auto') {
9736: $linefeed = "\n";
9737: } else {
9738: $linefeed = '<br />'."\n";
9739: }
1.443 albertel 9740: if (defined($one) && defined($two)) {
9741: my $cid=$one.'_'.$two;
9742: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9743: my $secchange = 0;
9744: my $expire_role_result;
9745: my $modify_section_result;
1.628 raeburn 9746: if ($oldsec ne '-1') {
9747: if ($oldsec ne $sec) {
1.443 albertel 9748: $secchange = 1;
1.628 raeburn 9749: my $now = time;
1.443 albertel 9750: my $uurl='/'.$cid;
9751: $uurl=~s/\_/\//g;
9752: if ($oldsec) {
9753: $uurl.='/'.$oldsec;
9754: }
1.626 raeburn 9755: $oldsecurl = $uurl;
1.628 raeburn 9756: $expire_role_result =
1.652 raeburn 9757: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9758: if ($env{'request.course.sec'} ne '') {
9759: if ($expire_role_result eq 'refused') {
9760: my @roles = ('st');
9761: my @statuses = ('previous');
9762: my @roledoms = ($one);
9763: my $withsec = 1;
9764: my %roleshash =
9765: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9766: \@statuses,\@roles,\@roledoms,$withsec);
9767: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9768: my ($oldstart,$oldend) =
9769: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9770: if ($oldend > 0 && $oldend <= $now) {
9771: $expire_role_result = 'ok';
9772: }
9773: }
9774: }
9775: }
1.443 albertel 9776: $result = $expire_role_result;
9777: }
9778: }
9779: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9780: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9781: if ($modify_section_result =~ /^ok/) {
9782: if ($secchange == 1) {
1.628 raeburn 9783: if ($sec eq '') {
9784: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9785: } else {
9786: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9787: }
1.443 albertel 9788: } elsif ($oldsec eq '-1') {
1.628 raeburn 9789: if ($sec eq '') {
9790: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9791: } else {
9792: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9793: }
1.443 albertel 9794: } else {
1.628 raeburn 9795: if ($sec eq '') {
9796: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9797: } else {
9798: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9799: }
1.443 albertel 9800: }
9801: } else {
1.628 raeburn 9802: if ($secchange) {
9803: $$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;
9804: } else {
9805: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9806: }
1.443 albertel 9807: }
9808: $result = $modify_section_result;
9809: } elsif ($secchange == 1) {
1.628 raeburn 9810: if ($oldsec eq '') {
9811: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9812: } else {
9813: $$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;
9814: }
1.626 raeburn 9815: if ($expire_role_result eq 'refused') {
9816: my $newsecurl = '/'.$cid;
9817: $newsecurl =~ s/\_/\//g;
9818: if ($sec ne '') {
9819: $newsecurl.='/'.$sec;
9820: }
9821: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9822: if ($sec eq '') {
9823: $$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;
9824: } else {
9825: $$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;
9826: }
9827: }
9828: }
1.443 albertel 9829: }
9830: } else {
1.626 raeburn 9831: $$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 9832: $result = "error: incomplete course id\n";
9833: }
9834: return $result;
9835: }
9836:
9837: ############################################################
9838: ############################################################
9839:
1.566 albertel 9840: sub check_clone {
1.578 raeburn 9841: my ($args,$linefeed) = @_;
1.566 albertel 9842: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9843: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9844: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9845: my $clonemsg;
9846: my $can_clone = 0;
9847:
9848: if ($clonehome eq 'no_host') {
1.578 raeburn 9849: $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 9850: } else {
9851: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9852: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9853: $can_clone = 1;
9854: } else {
9855: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9856: $args->{'clonedomain'},$args->{'clonecourse'});
9857: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9858: if (grep(/^\*$/,@cloners)) {
9859: $can_clone = 1;
9860: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9861: $can_clone = 1;
9862: } else {
9863: my %roleshash =
9864: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9865: $args->{'ccdomain'},
9866: 'userroles',['active'],['cc'],
9867: [$args->{'clonedomain'}]);
9868: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9869: $can_clone = 1;
9870: } else {
9871: $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'});
9872: }
1.566 albertel 9873: }
1.578 raeburn 9874: }
1.566 albertel 9875: }
9876: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9877: }
9878:
1.444 albertel 9879: sub construct_course {
1.541 raeburn 9880: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9881: my $outcome;
1.541 raeburn 9882: my $linefeed = '<br />'."\n";
9883: if ($context eq 'auto') {
9884: $linefeed = "\n";
9885: }
1.566 albertel 9886:
9887: #
9888: # Are we cloning?
9889: #
9890: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9891: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9892: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9893: if ($context ne 'auto') {
1.578 raeburn 9894: if ($clonemsg ne '') {
9895: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9896: }
1.566 albertel 9897: }
9898: $outcome .= $clonemsg.$linefeed;
9899:
9900: if (!$can_clone) {
9901: return (0,$outcome);
9902: }
9903: }
9904:
1.444 albertel 9905: #
9906: # Open course
9907: #
9908: my $crstype = lc($args->{'crstype'});
9909: my %cenv=();
9910: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9911: $args->{'cdescr'},
9912: $args->{'curl'},
9913: $args->{'course_home'},
9914: $args->{'nonstandard'},
9915: $args->{'crscode'},
9916: $args->{'ccuname'}.':'.
9917: $args->{'ccdomain'},
9918: $args->{'crstype'});
9919:
9920: # Note: The testing routines depend on this being output; see
9921: # Utils::Course. This needs to at least be output as a comment
9922: # if anyone ever decides to not show this, and Utils::Course::new
9923: # will need to be suitably modified.
1.541 raeburn 9924: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9925: #
9926: # Check if created correctly
9927: #
1.479 albertel 9928: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9929: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9930: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9931:
1.444 albertel 9932: #
1.566 albertel 9933: # Do the cloning
9934: #
9935: if ($can_clone && $cloneid) {
9936: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9937: if ($context ne 'auto') {
9938: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9939: }
9940: $outcome .= $clonemsg.$linefeed;
9941: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9942: # Copy all files
1.637 www 9943: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9944: # Restore URL
1.566 albertel 9945: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9946: # Restore title
1.566 albertel 9947: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9948: # Mark as cloned
1.566 albertel 9949: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9950: # Need to clone grading mode
9951: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9952: $cenv{'grading'}=$newenv{'grading'};
9953: # Do not clone these environment entries
9954: &Apache::lonnet::del('environment',
9955: ['default_enrollment_start_date',
9956: 'default_enrollment_end_date',
9957: 'question.email',
9958: 'policy.email',
9959: 'comment.email',
9960: 'pch.users.denied',
1.725 raeburn 9961: 'plc.users.denied',
9962: 'hidefromcat',
9963: 'categories'],
1.638 www 9964: $$crsudom,$$crsunum);
1.444 albertel 9965: }
1.566 albertel 9966:
1.444 albertel 9967: #
9968: # Set environment (will override cloned, if existing)
9969: #
9970: my @sections = ();
9971: my @xlists = ();
9972: if ($args->{'crstype'}) {
9973: $cenv{'type'}=$args->{'crstype'};
9974: }
9975: if ($args->{'crsid'}) {
9976: $cenv{'courseid'}=$args->{'crsid'};
9977: }
9978: if ($args->{'crscode'}) {
9979: $cenv{'internal.coursecode'}=$args->{'crscode'};
9980: }
9981: if ($args->{'crsquota'} ne '') {
9982: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9983: } else {
9984: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9985: }
9986: if ($args->{'ccuname'}) {
9987: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9988: ':'.$args->{'ccdomain'};
9989: } else {
9990: $cenv{'internal.courseowner'} = $args->{'curruser'};
9991: }
9992: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9993: if ($args->{'crssections'}) {
9994: $cenv{'internal.sectionnums'} = '';
9995: if ($args->{'crssections'} =~ m/,/) {
9996: @sections = split/,/,$args->{'crssections'};
9997: } else {
9998: $sections[0] = $args->{'crssections'};
9999: }
10000: if (@sections > 0) {
10001: foreach my $item (@sections) {
10002: my ($sec,$gp) = split/:/,$item;
10003: my $class = $args->{'crscode'}.$sec;
10004: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10005: $cenv{'internal.sectionnums'} .= $item.',';
10006: unless ($addcheck eq 'ok') {
10007: push @badclasses, $class;
10008: }
10009: }
10010: $cenv{'internal.sectionnums'} =~ s/,$//;
10011: }
10012: }
10013: # do not hide course coordinator from staff listing,
10014: # even if privileged
10015: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10016: # add crosslistings
10017: if ($args->{'crsxlist'}) {
10018: $cenv{'internal.crosslistings'}='';
10019: if ($args->{'crsxlist'} =~ m/,/) {
10020: @xlists = split/,/,$args->{'crsxlist'};
10021: } else {
10022: $xlists[0] = $args->{'crsxlist'};
10023: }
10024: if (@xlists > 0) {
10025: foreach my $item (@xlists) {
10026: my ($xl,$gp) = split/:/,$item;
10027: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10028: $cenv{'internal.crosslistings'} .= $item.',';
10029: unless ($addcheck eq 'ok') {
10030: push @badclasses, $xl;
10031: }
10032: }
10033: $cenv{'internal.crosslistings'} =~ s/,$//;
10034: }
10035: }
10036: if ($args->{'autoadds'}) {
10037: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10038: }
10039: if ($args->{'autodrops'}) {
10040: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10041: }
10042: # check for notification of enrollment changes
10043: my @notified = ();
10044: if ($args->{'notify_owner'}) {
10045: if ($args->{'ccuname'} ne '') {
10046: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10047: }
10048: }
10049: if ($args->{'notify_dc'}) {
10050: if ($uname ne '') {
1.630 raeburn 10051: push(@notified,$uname.':'.$udom);
1.444 albertel 10052: }
10053: }
10054: if (@notified > 0) {
10055: my $notifylist;
10056: if (@notified > 1) {
10057: $notifylist = join(',',@notified);
10058: } else {
10059: $notifylist = $notified[0];
10060: }
10061: $cenv{'internal.notifylist'} = $notifylist;
10062: }
10063: if (@badclasses > 0) {
10064: my %lt=&Apache::lonlocal::texthash(
10065: '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',
10066: 'dnhr' => 'does not have rights to access enrollment in these classes',
10067: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10068: );
1.541 raeburn 10069: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10070: ' ('.$lt{'adby'}.')';
10071: if ($context eq 'auto') {
10072: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10073: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10074: foreach my $item (@badclasses) {
10075: if ($context eq 'auto') {
10076: $outcome .= " - $item\n";
10077: } else {
10078: $outcome .= "<li>$item</li>\n";
10079: }
10080: }
10081: if ($context eq 'auto') {
10082: $outcome .= $linefeed;
10083: } else {
1.566 albertel 10084: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10085: }
10086: }
1.444 albertel 10087: }
10088: if ($args->{'no_end_date'}) {
10089: $args->{'endaccess'} = 0;
10090: }
10091: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10092: $cenv{'internal.autoend'}=$args->{'enrollend'};
10093: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10094: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10095: if ($args->{'showphotos'}) {
10096: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10097: }
10098: $cenv{'internal.authtype'} = $args->{'authtype'};
10099: $cenv{'internal.autharg'} = $args->{'autharg'};
10100: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10101: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10102: 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');
10103: if ($context eq 'auto') {
10104: $outcome .= $krb_msg;
10105: } else {
1.566 albertel 10106: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10107: }
10108: $outcome .= $linefeed;
1.444 albertel 10109: }
10110: }
10111: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10112: if ($args->{'setpolicy'}) {
10113: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10114: }
10115: if ($args->{'setcontent'}) {
10116: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10117: }
10118: }
10119: if ($args->{'reshome'}) {
10120: $cenv{'reshome'}=$args->{'reshome'}.'/';
10121: $cenv{'reshome'}=~s/\/+$/\//;
10122: }
10123: #
10124: # course has keyed access
10125: #
10126: if ($args->{'setkeys'}) {
10127: $cenv{'keyaccess'}='yes';
10128: }
10129: # if specified, key authority is not course, but user
10130: # only active if keyaccess is yes
10131: if ($args->{'keyauth'}) {
1.487 albertel 10132: my ($user,$domain) = split(':',$args->{'keyauth'});
10133: $user = &LONCAPA::clean_username($user);
10134: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10135: if ($user ne '' && $domain ne '') {
1.487 albertel 10136: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10137: }
10138: }
10139:
10140: if ($args->{'disresdis'}) {
10141: $cenv{'pch.roles.denied'}='st';
10142: }
10143: if ($args->{'disablechat'}) {
10144: $cenv{'plc.roles.denied'}='st';
10145: }
10146:
10147: # Record we've not yet viewed the Course Initialization Helper for this
10148: # course
10149: $cenv{'course.helper.not.run'} = 1;
10150: #
10151: # Use new Randomseed
10152: #
10153: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10154: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10155: #
10156: # The encryption code and receipt prefix for this course
10157: #
10158: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10159: $cenv{'internal.encpref'}=100+int(9*rand(99));
10160: #
10161: # By default, use standard grading
10162: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10163:
1.541 raeburn 10164: $outcome .= $linefeed.&mt('Setting environment').': '.
10165: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10166: #
10167: # Open all assignments
10168: #
10169: if ($args->{'openall'}) {
10170: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10171: my %storecontent = ($storeunder => time,
10172: $storeunder.'.type' => 'date_start');
10173:
10174: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10175: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10176: }
10177: #
10178: # Set first page
10179: #
10180: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10181: || ($cloneid)) {
1.445 albertel 10182: use LONCAPA::map;
1.444 albertel 10183: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10184:
10185: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10186: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10187:
1.444 albertel 10188: $outcome .= ($fatal?$errtext:'read ok').' - ';
10189: my $title; my $url;
10190: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10191: $title=&mt('Syllabus');
1.444 albertel 10192: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10193: } else {
1.690 bisitz 10194: $title=&mt('Navigate Contents');
1.444 albertel 10195: $url='/adm/navmaps';
10196: }
1.445 albertel 10197:
10198: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10199: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10200:
10201: if ($errtext) { $fatal=2; }
1.541 raeburn 10202: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10203: }
1.566 albertel 10204:
10205: return (1,$outcome);
1.444 albertel 10206: }
10207:
10208: ############################################################
10209: ############################################################
10210:
1.378 raeburn 10211: sub course_type {
10212: my ($cid) = @_;
10213: if (!defined($cid)) {
10214: $cid = $env{'request.course.id'};
10215: }
1.404 albertel 10216: if (defined($env{'course.'.$cid.'.type'})) {
10217: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10218: } else {
10219: return 'Course';
1.377 raeburn 10220: }
10221: }
1.156 albertel 10222:
1.406 raeburn 10223: sub group_term {
10224: my $crstype = &course_type();
10225: my %names = (
10226: 'Course' => 'group',
1.865 raeburn 10227: 'Community' => 'group',
1.406 raeburn 10228: );
10229: return $names{$crstype};
10230: }
10231:
1.156 albertel 10232: sub icon {
10233: my ($file)=@_;
1.505 albertel 10234: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10235: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10236: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10237: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10238: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10239: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10240: $curfext.".gif") {
10241: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10242: $curfext.".gif";
10243: }
10244: }
1.249 albertel 10245: return &lonhttpdurl($iconname);
1.154 albertel 10246: }
1.84 albertel 10247:
1.575 albertel 10248: sub lonhttpdurl {
1.692 www 10249: #
10250: # Had been used for "small fry" static images on separate port 8080.
10251: # Modify here if lightweight http functionality desired again.
10252: # Currently eliminated due to increasing firewall issues.
10253: #
1.575 albertel 10254: my ($url)=@_;
1.692 www 10255: return $url;
1.215 albertel 10256: }
10257:
1.213 albertel 10258: sub connection_aborted {
10259: my ($r)=@_;
10260: $r->print(" ");$r->rflush();
10261: my $c = $r->connection;
10262: return $c->aborted();
10263: }
10264:
1.221 foxr 10265: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10266: # strings as 'strings'.
10267: sub escape_single {
1.221 foxr 10268: my ($input) = @_;
1.223 albertel 10269: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10270: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10271: return $input;
10272: }
1.223 albertel 10273:
1.222 foxr 10274: # Same as escape_single, but escape's "'s This
10275: # can be used for "strings"
10276: sub escape_double {
10277: my ($input) = @_;
10278: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10279: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10280: return $input;
10281: }
1.223 albertel 10282:
1.222 foxr 10283: # Escapes the last element of a full URL.
10284: sub escape_url {
10285: my ($url) = @_;
1.238 raeburn 10286: my @urlslices = split(/\//, $url,-1);
1.369 www 10287: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10288: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10289: }
1.462 albertel 10290:
1.820 raeburn 10291: sub compare_arrays {
10292: my ($arrayref1,$arrayref2) = @_;
10293: my (@difference,%count);
10294: @difference = ();
10295: %count = ();
10296: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10297: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10298: foreach my $element (keys(%count)) {
10299: if ($count{$element} == 1) {
10300: push(@difference,$element);
10301: }
10302: }
10303: }
10304: return @difference;
10305: }
10306:
1.817 bisitz 10307: # -------------------------------------------------------- Initialize user login
1.462 albertel 10308: sub init_user_environment {
1.463 albertel 10309: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10310: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10311:
10312: my $public=($username eq 'public' && $domain eq 'public');
10313:
10314: # See if old ID present, if so, remove
10315:
10316: my ($filename,$cookie,$userroles);
10317: my $now=time;
10318:
10319: if ($public) {
10320: my $max_public=100;
10321: my $oldest;
10322: my $oldest_time=0;
10323: for(my $next=1;$next<=$max_public;$next++) {
10324: if (-e $lonids."/publicuser_$next.id") {
10325: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10326: if ($mtime<$oldest_time || !$oldest_time) {
10327: $oldest_time=$mtime;
10328: $oldest=$next;
10329: }
10330: } else {
10331: $cookie="publicuser_$next";
10332: last;
10333: }
10334: }
10335: if (!$cookie) { $cookie="publicuser_$oldest"; }
10336: } else {
1.463 albertel 10337: # if this isn't a robot, kill any existing non-robot sessions
10338: if (!$args->{'robot'}) {
10339: opendir(DIR,$lonids);
10340: while ($filename=readdir(DIR)) {
10341: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10342: unlink($lonids.'/'.$filename);
10343: }
1.462 albertel 10344: }
1.463 albertel 10345: closedir(DIR);
1.462 albertel 10346: }
10347: # Give them a new cookie
1.463 albertel 10348: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10349: : $now.$$.int(rand(10000)));
1.463 albertel 10350: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10351:
10352: # Initialize roles
10353:
10354: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10355: }
10356: # ------------------------------------ Check browser type and MathML capability
10357:
10358: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10359: $clientunicode,$clientos) = &decode_user_agent($r);
10360:
10361: # ------------------------------------------------------------- Get environment
10362:
10363: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10364: my ($tmp) = keys(%userenv);
10365: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10366: # default remote control to off
10367: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10368: } else {
10369: undef(%userenv);
10370: }
10371: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10372: $form->{'interface'}=$userenv{'interface'};
10373: }
10374: $env{'environment.remote'}=$userenv{'remote'};
10375: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10376:
10377: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10378: foreach my $option ('interface','localpath','localres') {
10379: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10380: }
10381: # --------------------------------------------------------- Write first profile
10382:
10383: {
10384: my %initial_env =
10385: ("user.name" => $username,
10386: "user.domain" => $domain,
10387: "user.home" => $authhost,
10388: "browser.type" => $clientbrowser,
10389: "browser.version" => $clientversion,
10390: "browser.mathml" => $clientmathml,
10391: "browser.unicode" => $clientunicode,
10392: "browser.os" => $clientos,
10393: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10394: "request.course.fn" => '',
10395: "request.course.uri" => '',
10396: "request.course.sec" => '',
10397: "request.role" => 'cm',
10398: "request.role.adv" => $env{'user.adv'},
10399: "request.host" => $ENV{'REMOTE_ADDR'},);
10400:
10401: if ($form->{'localpath'}) {
10402: $initial_env{"browser.localpath"} = $form->{'localpath'};
10403: $initial_env{"browser.localres"} = $form->{'localres'};
10404: }
10405:
10406: if ($public) {
10407: $initial_env{"environment.remote"} = "off";
10408: }
10409: if ($form->{'interface'}) {
10410: $form->{'interface'}=~s/\W//gs;
10411: $initial_env{"browser.interface"} = $form->{'interface'};
10412: $env{'browser.interface'}=$form->{'interface'};
10413: }
10414:
1.724 raeburn 10415: foreach my $tool ('aboutme','blog','portfolio') {
10416: $userenv{'availabletools.'.$tool} =
10417: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10418: }
10419:
1.864 raeburn 10420: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10421: $userenv{'canrequest.'.$crstype} =
10422: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10423: 'reload','requestcourses');
10424: }
10425:
1.462 albertel 10426: $env{'user.environment'} = "$lonids/$cookie.id";
10427:
10428: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10429: &GDBM_WRCREAT(),0640)) {
10430: &_add_to_env(\%disk_env,\%initial_env);
10431: &_add_to_env(\%disk_env,\%userenv,'environment.');
10432: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10433: if (ref($args->{'extra_env'})) {
10434: &_add_to_env(\%disk_env,$args->{'extra_env'});
10435: }
1.462 albertel 10436: untie(%disk_env);
10437: } else {
1.705 tempelho 10438: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10439: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10440: return 'error: '.$!;
10441: }
10442: }
10443: $env{'request.role'}='cm';
10444: $env{'request.role.adv'}=$env{'user.adv'};
10445: $env{'browser.type'}=$clientbrowser;
10446:
10447: return $cookie;
10448:
10449: }
10450:
10451: sub _add_to_env {
10452: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10453: if (ref($env_data) eq 'HASH') {
10454: while (my ($key,$value) = each(%$env_data)) {
10455: $idf->{$prefix.$key} = $value;
10456: $env{$prefix.$key} = $value;
10457: }
1.462 albertel 10458: }
10459: }
10460:
1.685 tempelho 10461: # --- Get the symbolic name of a problem and the url
10462: sub get_symb {
10463: my ($request,$silent) = @_;
1.726 raeburn 10464: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10465: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10466: if ($symb eq '') {
10467: if (!$silent) {
10468: $request->print("Unable to handle ambiguous references:$url:.");
10469: return ();
10470: }
10471: }
10472: &Apache::lonenc::check_decrypt(\$symb);
10473: return ($symb);
10474: }
10475:
10476: # --------------------------------------------------------------Get annotation
10477:
10478: sub get_annotation {
10479: my ($symb,$enc) = @_;
10480:
10481: my $key = $symb;
10482: if (!$enc) {
10483: $key =
10484: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10485: }
10486: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10487: return $annotation{$key};
10488: }
10489:
10490: sub clean_symb {
1.731 raeburn 10491: my ($symb,$delete_enc) = @_;
1.685 tempelho 10492:
10493: &Apache::lonenc::check_decrypt(\$symb);
10494: my $enc = $env{'request.enc'};
1.731 raeburn 10495: if ($delete_enc) {
1.730 raeburn 10496: delete($env{'request.enc'});
10497: }
1.685 tempelho 10498:
10499: return ($symb,$enc);
10500: }
1.462 albertel 10501:
1.41 ng 10502: =pod
10503:
10504: =back
10505:
1.112 bowersj2 10506: =cut
1.41 ng 10507:
1.112 bowersj2 10508: 1;
10509: __END__;
1.41 ng 10510:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>