Annotation of loncom/interface/loncommon.pm, revision 1.877
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.877 ! bisitz 4: # $Id: loncommon.pm,v 1.876 2009/08/04 19:53:42 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.468 raeburn 485: my ($domainfilter,$sec_element,$formname)=@_;
1.865 raeburn 486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role');
1.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.666 raeburn 4915: .LC_roleslog_note {
1.701 harmsja 4916: font-size: small;
1.666 raeburn 4917: }
4918:
1.795 www 4919: table.LC_data_table,
4920: table.LC_mail_list {
1.347 albertel 4921: border: 1px solid #000000;
1.402 albertel 4922: border-collapse: separate;
1.426 albertel 4923: border-spacing: 1px;
1.610 albertel 4924: background: $pgbg;
1.347 albertel 4925: }
1.795 www 4926:
1.422 albertel 4927: .LC_data_table_dense {
4928: font-size: small;
4929: }
1.795 www 4930:
1.507 raeburn 4931: table.LC_nested_outer {
4932: border: 1px solid #000000;
1.589 raeburn 4933: border-collapse: collapse;
1.803 bisitz 4934: border-spacing: 0;
1.507 raeburn 4935: width: 100%;
4936: }
1.795 www 4937:
1.507 raeburn 4938: table.LC_nested {
1.803 bisitz 4939: border: none;
1.589 raeburn 4940: border-collapse: collapse;
1.803 bisitz 4941: border-spacing: 0;
1.507 raeburn 4942: width: 100%;
4943: }
1.795 www 4944:
4945: table.LC_data_table tr th,
4946: table.LC_calendar tr th,
4947: table.LC_mail_list tr th,
1.523 albertel 4948: table.LC_prior_tries tr th {
1.349 albertel 4949: font-weight: bold;
4950: background-color: $data_table_head;
1.801 tempelho 4951: color:$fontmenu;
1.701 harmsja 4952: font-size:90%;
1.347 albertel 4953: }
1.795 www 4954:
1.711 raeburn 4955: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4956: background-color: #CCCCCC;
1.711 raeburn 4957: font-weight: bold;
4958: text-align: left;
4959: }
1.795 www 4960:
1.779 bisitz 4961: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4962: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4963: background-color: $data_table_light;
1.425 albertel 4964: padding: 2px;
1.347 albertel 4965: }
1.795 www 4966:
1.610 albertel 4967: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4968: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4969: background-color: $data_table_dark;
1.709 bisitz 4970: padding: 2px;
1.347 albertel 4971: }
1.795 www 4972:
1.425 albertel 4973: table.LC_data_table tr.LC_data_table_highlight td {
4974: background-color: $data_table_darker;
4975: }
1.795 www 4976:
1.639 raeburn 4977: table.LC_data_table tr td.LC_leftcol_header {
4978: background-color: $data_table_head;
4979: font-weight: bold;
4980: }
1.795 www 4981:
1.451 albertel 4982: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4983: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4984: background-color: #FFFFFF;
1.421 albertel 4985: font-weight: bold;
4986: font-style: italic;
4987: text-align: center;
4988: padding: 8px;
1.347 albertel 4989: }
1.795 www 4990:
1.507 raeburn 4991: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4992: padding: 4ex
4993: }
1.795 www 4994:
1.507 raeburn 4995: table.LC_nested_outer tr th {
4996: font-weight: bold;
1.801 tempelho 4997: color:$fontmenu;
1.507 raeburn 4998: background-color: $data_table_head;
1.701 harmsja 4999: font-size: small;
1.507 raeburn 5000: border-bottom: 1px solid #000000;
5001: }
1.795 www 5002:
1.507 raeburn 5003: table.LC_nested_outer tr td.LC_subheader {
5004: background-color: $data_table_head;
5005: font-weight: bold;
5006: font-size: small;
5007: border-bottom: 1px solid #000000;
5008: text-align: right;
1.451 albertel 5009: }
1.795 www 5010:
1.507 raeburn 5011: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5012: background-color: #CCCCCC;
1.451 albertel 5013: font-weight: bold;
5014: font-size: small;
1.507 raeburn 5015: text-align: center;
5016: }
1.795 www 5017:
1.589 raeburn 5018: table.LC_nested tr.LC_info_row td.LC_left_item,
5019: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5020: text-align: left;
1.451 albertel 5021: }
1.795 www 5022:
1.507 raeburn 5023: table.LC_nested td {
1.735 bisitz 5024: background-color: #FFFFFF;
1.451 albertel 5025: font-size: small;
1.507 raeburn 5026: }
1.795 www 5027:
1.507 raeburn 5028: table.LC_nested_outer tr th.LC_right_item,
5029: table.LC_nested tr.LC_info_row td.LC_right_item,
5030: table.LC_nested tr.LC_odd_row td.LC_right_item,
5031: table.LC_nested tr td.LC_right_item {
1.451 albertel 5032: text-align: right;
5033: }
5034:
1.507 raeburn 5035: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5036: background-color: #EEEEEE;
1.451 albertel 5037: }
5038:
1.473 raeburn 5039: table.LC_createuser {
5040: }
5041:
5042: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5043: font-size: small;
1.473 raeburn 5044: }
5045:
5046: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5047: background-color: #CCCCCC;
1.473 raeburn 5048: font-weight: bold;
5049: text-align: center;
5050: }
5051:
1.349 albertel 5052: table.LC_calendar {
5053: border: 1px solid #000000;
5054: border-collapse: collapse;
5055: }
1.795 www 5056:
1.349 albertel 5057: table.LC_calendar_pickdate {
5058: font-size: xx-small;
5059: }
1.795 www 5060:
1.349 albertel 5061: table.LC_calendar tr td {
5062: border: 1px solid #000000;
5063: vertical-align: top;
5064: }
1.795 www 5065:
1.349 albertel 5066: table.LC_calendar tr td.LC_calendar_day_empty {
5067: background-color: $data_table_dark;
5068: }
1.795 www 5069:
1.779 bisitz 5070: table.LC_calendar tr td.LC_calendar_day_current {
5071: background-color: $data_table_highlight;
1.777 tempelho 5072: }
1.795 www 5073:
1.349 albertel 5074: table.LC_mail_list tr.LC_mail_new {
5075: background-color: $mail_new;
5076: }
1.795 www 5077:
1.349 albertel 5078: table.LC_mail_list tr.LC_mail_new:hover {
5079: background-color: $mail_new_hover;
5080: }
1.795 www 5081:
5082: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5083: }
1.795 www 5084:
5085: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5086: }
1.795 www 5087:
1.349 albertel 5088: table.LC_mail_list tr.LC_mail_read {
5089: background-color: $mail_read;
5090: }
1.795 www 5091:
1.349 albertel 5092: table.LC_mail_list tr.LC_mail_read:hover {
5093: background-color: $mail_read_hover;
5094: }
1.795 www 5095:
1.349 albertel 5096: table.LC_mail_list tr.LC_mail_replied {
5097: background-color: $mail_replied;
5098: }
1.795 www 5099:
1.349 albertel 5100: table.LC_mail_list tr.LC_mail_replied:hover {
5101: background-color: $mail_replied_hover;
5102: }
1.795 www 5103:
1.349 albertel 5104: table.LC_mail_list tr.LC_mail_other {
5105: background-color: $mail_other;
5106: }
1.795 www 5107:
1.349 albertel 5108: table.LC_mail_list tr.LC_mail_other:hover {
5109: background-color: $mail_other_hover;
5110: }
1.494 raeburn 5111:
1.777 tempelho 5112: table.LC_data_table tr > td.LC_browser_file,
5113: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5114: background: #CCFF88;
5115: }
1.795 www 5116:
1.777 tempelho 5117: table.LC_data_table tr > td.LC_browser_file_locked,
5118: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5119: background: #FFAA99;
1.387 albertel 5120: }
1.795 www 5121:
1.777 tempelho 5122: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5123: background: #AAAAAA;
5124: }
1.795 www 5125:
1.777 tempelho 5126: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5127: table.LC_data_table tr > td.LC_browser_file_metamodified {
5128: background: #FFFF77;
1.777 tempelho 5129: }
1.795 www 5130:
1.696 bisitz 5131: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5132: background: #CCCCFF;
1.387 albertel 5133: }
1.696 bisitz 5134:
1.707 bisitz 5135: table.LC_data_table tr > td.LC_roles_is {
5136: /* background: #77FF77; */
5137: }
1.795 www 5138:
1.707 bisitz 5139: table.LC_data_table tr > td.LC_roles_future {
5140: background: #FFFF77;
5141: }
1.795 www 5142:
1.707 bisitz 5143: table.LC_data_table tr > td.LC_roles_will {
5144: background: #FFAA77;
5145: }
1.795 www 5146:
1.707 bisitz 5147: table.LC_data_table tr > td.LC_roles_expired {
5148: background: #FF7777;
5149: }
1.795 www 5150:
1.707 bisitz 5151: table.LC_data_table tr > td.LC_roles_will_not {
5152: background: #AAFF77;
5153: }
1.795 www 5154:
1.707 bisitz 5155: table.LC_data_table tr > td.LC_roles_selected {
5156: background: #11CC55;
5157: }
5158:
1.388 albertel 5159: span.LC_current_location {
1.701 harmsja 5160: font-size:larger;
1.388 albertel 5161: background: $pgbg;
5162: }
1.387 albertel 5163:
1.395 albertel 5164: span.LC_parm_menu_item {
5165: font-size: larger;
5166: }
1.795 www 5167:
1.395 albertel 5168: span.LC_parm_scope_all {
5169: color: red;
5170: }
1.795 www 5171:
1.395 albertel 5172: span.LC_parm_scope_folder {
5173: color: green;
5174: }
1.795 www 5175:
1.395 albertel 5176: span.LC_parm_scope_resource {
5177: color: orange;
5178: }
1.795 www 5179:
1.395 albertel 5180: span.LC_parm_part {
5181: color: blue;
5182: }
1.795 www 5183:
1.395 albertel 5184: span.LC_parm_folder, span.LC_parm_symb {
5185: font-size: x-small;
5186: font-family: $mono;
5187: color: #AAAAAA;
5188: }
5189:
1.795 www 5190: td.LC_parm_overview_level_menu,
5191: td.LC_parm_overview_map_menu,
5192: td.LC_parm_overview_parm_selectors,
5193: td.LC_parm_overview_restrictions {
1.396 albertel 5194: border: 1px solid black;
5195: border-collapse: collapse;
5196: }
1.795 www 5197:
1.396 albertel 5198: table.LC_parm_overview_restrictions td {
5199: border-width: 1px 4px 1px 4px;
5200: border-style: solid;
5201: border-color: $pgbg;
5202: text-align: center;
5203: }
1.795 www 5204:
1.396 albertel 5205: table.LC_parm_overview_restrictions th {
5206: background: $tabbg;
5207: border-width: 1px 4px 1px 4px;
5208: border-style: solid;
5209: border-color: $pgbg;
5210: }
1.795 www 5211:
1.398 albertel 5212: table#LC_helpmenu {
1.803 bisitz 5213: border: none;
1.398 albertel 5214: height: 55px;
1.803 bisitz 5215: border-spacing: 0;
1.398 albertel 5216: }
5217:
5218: table#LC_helpmenu fieldset legend {
5219: font-size: larger;
5220: }
1.795 www 5221:
1.397 albertel 5222: table#LC_helpmenu_links {
5223: width: 100%;
5224: border: 1px solid black;
5225: background: $pgbg;
1.803 bisitz 5226: padding: 0;
1.397 albertel 5227: border-spacing: 1px;
5228: }
1.795 www 5229:
1.397 albertel 5230: table#LC_helpmenu_links tr td {
5231: padding: 1px;
5232: background: $tabbg;
1.399 albertel 5233: text-align: center;
5234: font-weight: bold;
1.397 albertel 5235: }
1.396 albertel 5236:
1.795 www 5237: table#LC_helpmenu_links a:link,
5238: table#LC_helpmenu_links a:visited,
1.397 albertel 5239: table#LC_helpmenu_links a:active {
5240: text-decoration: none;
5241: color: $font;
5242: }
1.795 www 5243:
1.397 albertel 5244: table#LC_helpmenu_links a:hover {
5245: text-decoration: underline;
5246: color: $vlink;
5247: }
1.396 albertel 5248:
1.417 albertel 5249: .LC_chrt_popup_exists {
5250: border: 1px solid #339933;
5251: margin: -1px;
5252: }
1.795 www 5253:
1.417 albertel 5254: .LC_chrt_popup_up {
5255: border: 1px solid yellow;
5256: margin: -1px;
5257: }
1.795 www 5258:
1.417 albertel 5259: .LC_chrt_popup {
5260: border: 1px solid #8888FF;
5261: background: #CCCCFF;
5262: }
1.795 www 5263:
1.421 albertel 5264: table.LC_pick_box {
5265: border-collapse: separate;
5266: background: white;
5267: border: 1px solid black;
5268: border-spacing: 1px;
5269: }
1.795 www 5270:
1.421 albertel 5271: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5272: background: $sidebg;
1.421 albertel 5273: font-weight: bold;
5274: text-align: right;
1.740 bisitz 5275: vertical-align: top;
1.421 albertel 5276: width: 184px;
5277: padding: 8px;
5278: }
1.795 www 5279:
1.579 raeburn 5280: table.LC_pick_box td.LC_pick_box_value {
5281: text-align: left;
5282: padding: 8px;
5283: }
1.795 www 5284:
1.579 raeburn 5285: table.LC_pick_box td.LC_pick_box_select {
5286: text-align: left;
5287: padding: 8px;
5288: }
1.795 www 5289:
1.424 albertel 5290: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5291: padding: 0;
1.421 albertel 5292: height: 1px;
5293: background: black;
5294: }
1.795 www 5295:
1.421 albertel 5296: table.LC_pick_box td.LC_pick_box_submit {
5297: text-align: right;
5298: }
1.795 www 5299:
1.579 raeburn 5300: table.LC_pick_box td.LC_evenrow_value {
5301: text-align: left;
5302: padding: 8px;
5303: background-color: $data_table_light;
5304: }
1.795 www 5305:
1.579 raeburn 5306: table.LC_pick_box td.LC_oddrow_value {
5307: text-align: left;
5308: padding: 8px;
5309: background-color: $data_table_light;
5310: }
1.795 www 5311:
1.579 raeburn 5312: table.LC_helpform_receipt {
5313: width: 620px;
5314: border-collapse: separate;
5315: background: white;
5316: border: 1px solid black;
5317: border-spacing: 1px;
5318: }
1.795 www 5319:
1.579 raeburn 5320: table.LC_helpform_receipt td.LC_pick_box_title {
5321: background: $tabbg;
5322: font-weight: bold;
5323: text-align: right;
5324: width: 184px;
5325: padding: 8px;
5326: }
1.795 www 5327:
1.579 raeburn 5328: table.LC_helpform_receipt td.LC_evenrow_value {
5329: text-align: left;
5330: padding: 8px;
5331: background-color: $data_table_light;
5332: }
1.795 www 5333:
1.579 raeburn 5334: table.LC_helpform_receipt td.LC_oddrow_value {
5335: text-align: left;
5336: padding: 8px;
5337: background-color: $data_table_light;
5338: }
1.795 www 5339:
1.579 raeburn 5340: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5341: padding: 0;
1.579 raeburn 5342: height: 1px;
5343: background: black;
5344: }
1.795 www 5345:
1.579 raeburn 5346: span.LC_helpform_receipt_cat {
5347: font-weight: bold;
5348: }
1.795 www 5349:
1.424 albertel 5350: table.LC_group_priv_box {
5351: background: white;
5352: border: 1px solid black;
5353: border-spacing: 1px;
5354: }
1.795 www 5355:
1.424 albertel 5356: table.LC_group_priv_box td.LC_pick_box_title {
5357: background: $tabbg;
5358: font-weight: bold;
5359: text-align: right;
5360: width: 184px;
5361: }
1.795 www 5362:
1.424 albertel 5363: table.LC_group_priv_box td.LC_groups_fixed {
5364: background: $data_table_light;
5365: text-align: center;
5366: }
1.795 www 5367:
1.424 albertel 5368: table.LC_group_priv_box td.LC_groups_optional {
5369: background: $data_table_dark;
5370: text-align: center;
5371: }
1.795 www 5372:
1.424 albertel 5373: table.LC_group_priv_box td.LC_groups_functionality {
5374: background: $data_table_darker;
5375: text-align: center;
5376: font-weight: bold;
5377: }
1.795 www 5378:
1.424 albertel 5379: table.LC_group_priv td {
5380: text-align: left;
1.803 bisitz 5381: padding: 0;
1.424 albertel 5382: }
5383:
1.421 albertel 5384: table.LC_notify_front_page {
5385: background: white;
5386: border: 1px solid black;
5387: padding: 8px;
5388: }
1.795 www 5389:
1.421 albertel 5390: table.LC_notify_front_page td {
5391: padding: 8px;
5392: }
1.795 www 5393:
1.424 albertel 5394: .LC_navbuttons {
5395: margin: 2ex 0ex 2ex 0ex;
5396: }
1.795 www 5397:
1.423 albertel 5398: .LC_topic_bar {
5399: font-weight: bold;
5400: width: 100%;
5401: background: $tabbg;
5402: vertical-align: middle;
5403: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5404: padding: 3px;
1.423 albertel 5405: }
1.795 www 5406:
1.423 albertel 5407: .LC_topic_bar span {
5408: vertical-align: middle;
5409: }
1.795 www 5410:
1.423 albertel 5411: .LC_topic_bar img {
5412: vertical-align: bottom;
5413: }
1.795 www 5414:
1.423 albertel 5415: table.LC_course_group_status {
5416: margin: 20px;
5417: }
1.795 www 5418:
1.423 albertel 5419: table.LC_status_selector td {
5420: vertical-align: top;
5421: text-align: center;
1.424 albertel 5422: padding: 4px;
5423: }
1.795 www 5424:
1.599 albertel 5425: div.LC_feedback_link {
1.616 albertel 5426: clear: both;
1.829 kalberla 5427: background: $sidebg;
1.779 bisitz 5428: width: 100%;
1.829 kalberla 5429: padding-bottom: 10px;
5430: border: 1px $tabbg solid;
1.833 kalberla 5431: height: 22px;
5432: line-height: 22px;
5433: padding-top: 5px;
5434: }
5435:
5436: div.LC_feedback_link img {
5437: height: 22px;
1.867 kalberla 5438: vertical-align:middle;
1.829 kalberla 5439: }
5440:
5441: div.LC_feedback_link a{
5442: text-decoration: none;
1.489 raeburn 5443: }
1.795 www 5444:
1.867 kalberla 5445: div.LC_comblock {
5446: display:inline;
5447: color:$font;
5448: font-size:90%;
5449: }
5450:
5451: div.LC_feedback_link div.LC_comblock {
5452: padding-left:5px;
5453: }
5454:
5455: div.LC_feedback_link div.LC_comblock a {
5456: color:$font;
5457: }
5458:
1.489 raeburn 5459: span.LC_feedback_link {
1.858 bisitz 5460: /* background: $feedback_link_bg; */
1.599 albertel 5461: font-size: larger;
5462: }
1.795 www 5463:
1.599 albertel 5464: span.LC_message_link {
1.858 bisitz 5465: /* background: $feedback_link_bg; */
1.599 albertel 5466: font-size: larger;
5467: position: absolute;
5468: right: 1em;
1.489 raeburn 5469: }
1.421 albertel 5470:
1.515 albertel 5471: table.LC_prior_tries {
1.524 albertel 5472: border: 1px solid #000000;
5473: border-collapse: separate;
5474: border-spacing: 1px;
1.515 albertel 5475: }
1.523 albertel 5476:
1.515 albertel 5477: table.LC_prior_tries td {
1.524 albertel 5478: padding: 2px;
1.515 albertel 5479: }
1.523 albertel 5480:
5481: .LC_answer_correct {
1.795 www 5482: background: lightgreen;
5483: color: darkgreen;
5484: padding: 6px;
1.523 albertel 5485: }
1.795 www 5486:
1.523 albertel 5487: .LC_answer_charged_try {
1.797 www 5488: background: #FFAAAA;
1.795 www 5489: color: darkred;
5490: padding: 6px;
1.523 albertel 5491: }
1.795 www 5492:
1.779 bisitz 5493: .LC_answer_not_charged_try,
1.523 albertel 5494: .LC_answer_no_grade,
5495: .LC_answer_late {
1.795 www 5496: background: lightyellow;
1.523 albertel 5497: color: black;
1.795 www 5498: padding: 6px;
1.523 albertel 5499: }
1.795 www 5500:
1.523 albertel 5501: .LC_answer_previous {
1.795 www 5502: background: lightblue;
5503: color: darkblue;
5504: padding: 6px;
1.523 albertel 5505: }
1.795 www 5506:
1.779 bisitz 5507: .LC_answer_no_message {
1.777 tempelho 5508: background: #FFFFFF;
5509: color: black;
1.795 www 5510: padding: 6px;
1.779 bisitz 5511: }
1.795 www 5512:
1.779 bisitz 5513: .LC_answer_unknown {
5514: background: orange;
5515: color: black;
1.795 www 5516: padding: 6px;
1.777 tempelho 5517: }
1.795 www 5518:
1.529 albertel 5519: span.LC_prior_numerical,
5520: span.LC_prior_string,
5521: span.LC_prior_custom,
5522: span.LC_prior_reaction,
5523: span.LC_prior_math {
1.523 albertel 5524: font-family: monospace;
5525: white-space: pre;
5526: }
5527:
1.525 albertel 5528: span.LC_prior_string {
5529: font-family: monospace;
5530: white-space: pre;
5531: }
5532:
1.523 albertel 5533: table.LC_prior_option {
5534: width: 100%;
5535: border-collapse: collapse;
5536: }
1.795 www 5537:
5538: table.LC_prior_rank,
5539: table.LC_prior_match {
1.528 albertel 5540: border-collapse: collapse;
5541: }
1.795 www 5542:
1.528 albertel 5543: table.LC_prior_option tr td,
5544: table.LC_prior_rank tr td,
5545: table.LC_prior_match tr td {
1.524 albertel 5546: border: 1px solid #000000;
1.515 albertel 5547: }
5548:
1.855 bisitz 5549: .LC_nobreak {
1.544 albertel 5550: white-space: nowrap;
1.519 raeburn 5551: }
5552:
1.576 raeburn 5553: span.LC_cusr_emph {
5554: font-style: italic;
5555: }
5556:
1.633 raeburn 5557: span.LC_cusr_subheading {
5558: font-weight: normal;
5559: font-size: 85%;
5560: }
5561:
1.545 albertel 5562: table.LC_docs_documents {
5563: background: #BBBBBB;
1.803 bisitz 5564: border-width: 0;
1.545 albertel 5565: border-collapse: collapse;
5566: }
1.795 www 5567:
1.777 tempelho 5568: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5569: border: 2px solid black;
5570: padding: 4px;
1.777 tempelho 5571: }
1.795 www 5572:
1.861 bisitz 5573: div.LC_docs_entry_move {
1.859 bisitz 5574: border: 1px solid #BBBBBB;
1.545 albertel 5575: background: #DDDDDD;
1.861 bisitz 5576: width: 22px;
1.859 bisitz 5577: padding: 1px;
5578: margin: 0;
1.545 albertel 5579: }
5580:
1.861 bisitz 5581: table.LC_data_table tr > td.LC_docs_entry_commands,
5582: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5583: background: #DDDDDD;
5584: font-size: x-small;
5585: }
1.795 www 5586:
1.861 bisitz 5587: .LC_docs_entry_parameter {
5588: white-space: nowrap;
5589: }
5590:
1.544 albertel 5591: .LC_docs_copy {
1.545 albertel 5592: color: #000099;
1.544 albertel 5593: }
1.795 www 5594:
1.544 albertel 5595: .LC_docs_cut {
1.545 albertel 5596: color: #550044;
1.544 albertel 5597: }
1.795 www 5598:
1.544 albertel 5599: .LC_docs_rename {
1.545 albertel 5600: color: #009900;
1.544 albertel 5601: }
1.795 www 5602:
1.544 albertel 5603: .LC_docs_remove {
1.545 albertel 5604: color: #990000;
5605: }
5606:
1.547 albertel 5607: .LC_docs_reinit_warn,
5608: .LC_docs_ext_edit {
5609: font-size: x-small;
5610: }
5611:
1.545 albertel 5612: table.LC_docs_adddocs td,
5613: table.LC_docs_adddocs th {
5614: border: 1px solid #BBBBBB;
5615: padding: 4px;
5616: background: #DDDDDD;
1.543 albertel 5617: }
5618:
1.584 albertel 5619: table.LC_sty_begin {
5620: background: #BBFFBB;
5621: }
1.795 www 5622:
1.584 albertel 5623: table.LC_sty_end {
5624: background: #FFBBBB;
5625: }
5626:
1.589 raeburn 5627: table.LC_double_column {
1.803 bisitz 5628: border-width: 0;
1.589 raeburn 5629: border-collapse: collapse;
5630: width: 100%;
5631: padding: 2px;
5632: }
5633:
5634: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5635: top: 2px;
1.589 raeburn 5636: left: 2px;
5637: width: 47%;
5638: vertical-align: top;
5639: }
5640:
5641: table.LC_double_column tr td.LC_right_col {
5642: top: 2px;
1.779 bisitz 5643: right: 2px;
1.589 raeburn 5644: width: 47%;
5645: vertical-align: top;
5646: }
5647:
1.591 raeburn 5648: div.LC_left_float {
5649: float: left;
5650: padding-right: 5%;
1.597 albertel 5651: padding-bottom: 4px;
1.591 raeburn 5652: }
5653:
5654: div.LC_clear_float_header {
1.597 albertel 5655: padding-bottom: 2px;
1.591 raeburn 5656: }
5657:
5658: div.LC_clear_float_footer {
1.597 albertel 5659: padding-top: 10px;
1.591 raeburn 5660: clear: both;
5661: }
5662:
1.597 albertel 5663: div.LC_grade_show_user {
5664: margin-top: 20px;
5665: border: 1px solid black;
5666: }
1.795 www 5667:
1.597 albertel 5668: div.LC_grade_user_name {
5669: background: #DDDDEE;
5670: border-bottom: 1px solid black;
1.705 tempelho 5671: font-weight: bold;
5672: font-size: large;
1.597 albertel 5673: }
1.795 www 5674:
1.597 albertel 5675: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5676: background: #DDEEDD;
5677: }
5678:
5679: div.LC_grade_show_problem,
5680: div.LC_grade_submissions,
5681: div.LC_grade_message_center,
5682: div.LC_grade_info_links,
5683: div.LC_grade_assign {
5684: margin: 5px;
5685: width: 99%;
5686: background: #FFFFFF;
5687: }
1.795 www 5688:
1.597 albertel 5689: div.LC_grade_show_problem_header,
5690: div.LC_grade_submissions_header,
5691: div.LC_grade_message_center_header,
5692: div.LC_grade_assign_header {
1.705 tempelho 5693: font-weight: bold;
5694: font-size: large;
1.597 albertel 5695: }
1.795 www 5696:
1.597 albertel 5697: div.LC_grade_show_problem_problem,
5698: div.LC_grade_submissions_body,
5699: div.LC_grade_message_center_body,
5700: div.LC_grade_assign_body {
5701: border: 1px solid black;
5702: width: 99%;
5703: background: #FFFFFF;
5704: }
1.795 www 5705:
1.598 albertel 5706: span.LC_grade_check_note {
1.705 tempelho 5707: font-weight: normal;
5708: font-size: medium;
1.598 albertel 5709: display: inline;
5710: position: absolute;
5711: right: 1em;
5712: }
1.597 albertel 5713:
1.613 albertel 5714: table.LC_scantron_action {
5715: width: 100%;
5716: }
1.795 www 5717:
1.613 albertel 5718: table.LC_scantron_action tr th {
1.698 harmsja 5719: font-weight:bold;
5720: font-style:normal;
1.613 albertel 5721: }
1.795 www 5722:
1.779 bisitz 5723: .LC_edit_problem_header,
1.614 albertel 5724: div.LC_edit_problem_footer {
1.705 tempelho 5725: font-weight: normal;
5726: font-size: medium;
1.602 albertel 5727: margin: 2px;
1.600 albertel 5728: }
1.795 www 5729:
1.600 albertel 5730: div.LC_edit_problem_header,
1.602 albertel 5731: div.LC_edit_problem_header div,
1.614 albertel 5732: div.LC_edit_problem_footer,
5733: div.LC_edit_problem_footer div,
1.602 albertel 5734: div.LC_edit_problem_editxml_header,
5735: div.LC_edit_problem_editxml_header div {
1.600 albertel 5736: margin-top: 5px;
5737: }
1.795 www 5738:
1.600 albertel 5739: div.LC_edit_problem_header_title {
1.705 tempelho 5740: font-weight: bold;
5741: font-size: larger;
1.602 albertel 5742: background: $tabbg;
5743: padding: 3px;
5744: }
1.795 www 5745:
1.602 albertel 5746: table.LC_edit_problem_header_title {
1.705 tempelho 5747: font-size: larger;
5748: font-weight: bold;
1.602 albertel 5749: width: 100%;
5750: border-color: $pgbg;
5751: border-style: solid;
5752: border-width: $border;
1.600 albertel 5753: background: $tabbg;
1.602 albertel 5754: border-collapse: collapse;
1.803 bisitz 5755: padding: 0;
1.602 albertel 5756: }
5757:
5758: div.LC_edit_problem_discards {
5759: float: left;
5760: padding-bottom: 5px;
5761: }
1.795 www 5762:
1.602 albertel 5763: div.LC_edit_problem_saves {
5764: float: right;
5765: padding-bottom: 5px;
1.600 albertel 5766: }
1.795 www 5767:
1.679 riegler 5768: img.stift{
1.803 bisitz 5769: border-width: 0;
5770: vertical-align: middle;
1.677 riegler 5771: }
1.680 riegler 5772:
1.681 riegler 5773: table#LC_mainmenu{
5774: margin-top:10px;
5775: width:80%;
5776: }
5777:
1.680 riegler 5778: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5779: vertical-align: top;
5780: width: 45%;
5781: }
1.795 www 5782:
1.779 bisitz 5783: .LC_mainmenu_fieldset_category {
5784: color: $font;
5785: background: $pgbg;
5786: font-size: small;
5787: font-weight: bold;
1.777 tempelho 5788: }
1.795 www 5789:
1.716 raeburn 5790: div.LC_createcourse {
5791: margin: 10px 10px 10px 10px;
5792: }
5793:
1.693 droeschl 5794: /* ---- Remove when done ----
5795: # The following styles is part of the redesign of LON-CAPA and are
5796: # subject to change during this project.
5797: # Don't rely on their current functionality as they might be
5798: # changed or removed.
5799: # --------------------------*/
5800:
1.698 harmsja 5801: a:hover,
1.721 harmsja 5802: ol.LC_smallMenu a:hover,
5803: ol#LC_MenuBreadcrumbs a:hover,
5804: ol#LC_PathBreadcrumbs a:hover,
5805: ul#LC_TabMainMenuContent a:hover,
5806: .LC_FormSectionClearButton input:hover
1.795 www 5807: ul.LC_TabContent li:hover a {
1.698 harmsja 5808: color:#BF2317;
5809: text-decoration:none;
1.693 droeschl 5810: }
5811:
1.779 bisitz 5812: h1 {
1.813 bisitz 5813: padding: 0;
1.693 droeschl 5814: line-height:130%;
5815: }
1.698 harmsja 5816:
1.795 www 5817: h2,h3,h4,h5,h6 {
1.803 bisitz 5818: margin: 5px 0 5px 0;
5819: padding: 0;
1.721 harmsja 5820: line-height:130%;
1.693 droeschl 5821: }
1.795 www 5822:
5823: .LC_hcell {
1.698 harmsja 5824: padding:3px 15px 3px 15px;
1.803 bisitz 5825: margin: 0;
1.703 harmsja 5826: background-color:$tabbg;
1.801 tempelho 5827: color:$fontmenu;
1.779 bisitz 5828: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5829: }
1.795 www 5830:
1.840 bisitz 5831: .LC_Box > .LC_hcell {
1.847 tempelho 5832: margin: 0 -10px 10px -10px;
1.835 bisitz 5833: }
5834:
1.721 harmsja 5835: .LC_noBorder {
1.803 bisitz 5836: border: 0;
1.698 harmsja 5837: }
1.693 droeschl 5838:
1.761 tempelho 5839: .LC_Right {
5840: float: right;
1.803 bisitz 5841: margin: 0;
5842: padding: 0;
1.761 tempelho 5843: }
5844:
1.721 harmsja 5845: .LC_FormSectionClearButton input {
1.779 bisitz 5846: background-color:transparent;
1.803 bisitz 5847: border: none;
1.698 harmsja 5848: cursor:pointer;
5849: text-decoration:underline;
1.693 droeschl 5850: }
1.763 bisitz 5851:
5852: .LC_help_open_topic {
5853: color: #FFFFFF;
5854: background-color: #EEEEFF;
5855: margin: 1px;
5856: padding: 4px;
5857: border: 1px solid #000033;
5858: white-space: nowrap;
1.783 amueller 5859: /* vertical-align: middle; */
1.759 neumanie 5860: }
1.693 droeschl 5861:
1.698 harmsja 5862: dl,ul,div,fieldset {
1.803 bisitz 5863: margin: 10px 10px 10px 0;
1.806 bisitz 5864: /* overflow: hidden; */
1.693 droeschl 5865: }
1.795 www 5866:
1.838 bisitz 5867: fieldset > legend {
5868: font-weight: bold;
5869: padding: 0 5px 0 5px;
5870: }
5871:
1.813 bisitz 5872: #LC_nav_bar {
1.807 droeschl 5873: float: left;
1.852 droeschl 5874: margin: 0.2em 0 0 0;
1.807 droeschl 5875: }
5876:
1.813 bisitz 5877: #LC_nav_bar em{
1.807 droeschl 5878: font-weight: bold;
5879: font-style: normal;
5880: }
5881:
5882: ol.LC_smallMenu {
5883: float: right;
1.852 droeschl 5884: margin: 0.2em 0 0 0;
1.807 droeschl 5885: }
5886:
1.852 droeschl 5887: ol#LC_PathBreadcrumbs {
1.803 bisitz 5888: margin: 0;
1.693 droeschl 5889: }
5890:
1.721 harmsja 5891: ol.LC_smallMenu li {
1.693 droeschl 5892: display: inline;
1.803 bisitz 5893: padding: 5px 5px 0 10px;
1.693 droeschl 5894: vertical-align: top;
5895: }
5896:
1.721 harmsja 5897: ol.LC_smallMenu li img {
1.693 droeschl 5898: vertical-align: bottom;
5899: }
5900:
1.721 harmsja 5901: ol.LC_smallMenu a {
1.693 droeschl 5902: font-size: 90%;
5903: color: RGB(80, 80, 80);
5904: text-decoration: none;
5905: }
1.795 www 5906:
1.808 droeschl 5907: ul#LC_TabMainMenuContent {
1.807 droeschl 5908: clear: both;
1.808 droeschl 5909: color: $fontmenu;
5910: background: $tabbg;
5911: list-style: none;
5912: padding: 0;
5913: margin: 0;
5914: width: 100%;
5915: }
5916:
5917: ul#LC_TabMainMenuContent li {
5918: font-weight: bold;
5919: line-height: 1.8em;
5920: padding: 0 0.8em;
5921: border-right: 1px solid black;
5922: display: inline;
5923: vertical-align: middle;
1.807 droeschl 5924: }
5925:
1.847 tempelho 5926: ul.LC_TabContent {
1.721 harmsja 5927: display:block;
1.847 tempelho 5928: background: $sidebg;
1.858 bisitz 5929: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5930: list-style:none;
1.870 tempelho 5931: margin: 0 -10px;
1.803 bisitz 5932: padding: 0;
1.693 droeschl 5933: }
5934:
1.795 www 5935: ul.LC_TabContent li,
5936: ul.LC_TabContentBigger li {
1.741 harmsja 5937: float:left;
5938: }
1.795 www 5939:
1.808 droeschl 5940: ul#LC_TabMainMenuContent li a {
5941: color: $fontmenu;
1.693 droeschl 5942: text-decoration: none;
5943: }
1.795 www 5944:
1.721 harmsja 5945: ul.LC_TabContent {
1.847 tempelho 5946: min-height:1.5em;
1.721 harmsja 5947: }
1.795 www 5948:
5949: ul.LC_TabContent li {
1.741 harmsja 5950: vertical-align:middle;
1.803 bisitz 5951: padding: 0 10px 0 10px;
1.745 ehlerst 5952: background-color:$tabbg;
5953: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5954: }
1.795 www 5955:
1.847 tempelho 5956: ul.LC_TabContent .right {
5957: float:right;
5958: }
5959:
1.795 www 5960: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5961: color:rgb(47,47,47);
5962: text-decoration:none;
5963: font-size:95%;
5964: font-weight:bold;
1.761 tempelho 5965: padding-right: 16px;
1.721 harmsja 5966: }
1.795 www 5967:
5968: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5969: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5970: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5971: padding-right: 16px;
1.744 ehlerst 5972: }
1.795 www 5973:
1.870 tempelho 5974: #maincoursedoc {
5975: clear:both;
5976: }
5977:
5978: ul.LC_TabContentBigger {
5979: display:block;
5980: list-style:none;
5981: padding: 0;
5982: }
5983:
1.795 www 5984: ul.LC_TabContentBigger li {
1.870 tempelho 5985: vertical-align:bottom;
5986: height: 30px;
5987: font-size:110%;
5988: font-weight:bold;
5989: color: #737373;
1.841 tempelho 5990: }
5991:
1.870 tempelho 5992:
5993: ul.LC_TabContentBigger li a {
5994: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
5995: height: 30px;
5996: line-height: 30px;
5997: text-align: center;
5998: display: block;
5999: text-decoration: none;
1.741 harmsja 6000: }
1.795 www 6001:
1.870 tempelho 6002: ul.LC_TabContentBigger li:hover a,
6003: ul.LC_TabContentBigger li.active a {
6004: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857 tempelho 6005: color:$font;
1.870 tempelho 6006: text-decoration: underline;
1.744 ehlerst 6007: }
1.795 www 6008:
1.870 tempelho 6009:
6010: ul.LC_TabContentBigger li b {
6011: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6012: display: block;
6013: float: left;
6014: padding: 0 30px;
6015: }
6016:
6017: ul.LC_TabContentBigger li:hover b,
6018: ul.LC_TabContentBigger li.active b {
6019: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6020: color:$font;
6021: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6022: }
1.693 droeschl 6023:
1.870 tempelho 6024:
1.862 bisitz 6025: ul.LC_CourseBreadcrumbs {
6026: background: $sidebg;
6027: line-height: 32px;
6028: padding-left: 10px;
6029: margin: 0 0 10px 0;
6030: list-style-position: inside;
6031:
6032: }
6033:
1.795 www 6034: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6035: ol#LC_PathBreadcrumbs {
1.693 droeschl 6036: padding-left: 10px;
1.819 tempelho 6037: margin: 0;
1.693 droeschl 6038: list-style-position: inside;
6039: }
6040:
1.795 www 6041: ol#LC_MenuBreadcrumbs li,
6042: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6043: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 6044: display: inline;
6045: white-space: nowrap;
1.693 droeschl 6046: }
6047:
1.823 bisitz 6048: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6049: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 6050: text-decoration: none;
6051: font-size:90%;
6052: }
1.795 www 6053:
6054: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6055: text-decoration:none;
6056: font-size:100%;
6057: font-weight:bold;
1.693 droeschl 6058: }
1.795 www 6059:
1.840 bisitz 6060: .LC_Box {
1.835 bisitz 6061: border: solid 1px $lg_border_color;
6062: padding: 0 10px 10px 10px;
1.746 neumanie 6063: }
1.795 www 6064:
6065: .LC_AboutMe_Image {
1.747 neumanie 6066: float:left;
6067: margin-right:10px;
6068: }
1.795 www 6069:
6070: .LC_Clear_AboutMe_Image {
1.747 neumanie 6071: clear:left;
6072: }
1.795 www 6073:
1.721 harmsja 6074: dl.LC_ListStyleClean dt {
1.693 droeschl 6075: padding-right: 5px;
6076: display: table-header-group;
6077: }
6078:
1.721 harmsja 6079: dl.LC_ListStyleClean dd {
1.693 droeschl 6080: display: table-row;
6081: }
6082:
1.721 harmsja 6083: .LC_ListStyleClean,
6084: .LC_ListStyleSimple,
6085: .LC_ListStyleNormal,
1.777 tempelho 6086: .LC_ListStyle_Border,
1.795 www 6087: .LC_ListStyleSpecial {
1.693 droeschl 6088: /*display:block; */
6089: list-style-position: inside;
6090: list-style-type: none;
6091: overflow: hidden;
1.803 bisitz 6092: padding: 0;
1.693 droeschl 6093: }
6094:
1.721 harmsja 6095: .LC_ListStyleSimple li,
6096: .LC_ListStyleSimple dd,
6097: .LC_ListStyleNormal li,
6098: .LC_ListStyleNormal dd,
6099: .LC_ListStyleSpecial li,
1.795 www 6100: .LC_ListStyleSpecial dd {
1.803 bisitz 6101: margin: 0;
1.693 droeschl 6102: padding: 5px 5px 5px 10px;
6103: clear: both;
6104: }
6105:
1.721 harmsja 6106: .LC_ListStyleClean li,
6107: .LC_ListStyleClean dd {
1.803 bisitz 6108: padding-top: 0;
6109: padding-bottom: 0;
1.693 droeschl 6110: }
6111:
1.721 harmsja 6112: .LC_ListStyleSimple dd,
1.795 www 6113: .LC_ListStyleSimple li {
1.698 harmsja 6114: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6115: }
6116:
1.721 harmsja 6117: .LC_ListStyleSpecial li,
6118: .LC_ListStyleSpecial dd {
1.693 droeschl 6119: list-style-type: none;
6120: background-color: RGB(220, 220, 220);
6121: margin-bottom: 4px;
6122: }
6123:
1.721 harmsja 6124: table.LC_SimpleTable {
1.698 harmsja 6125: margin:5px;
6126: border:solid 1px $lg_border_color;
1.795 www 6127: }
1.693 droeschl 6128:
1.721 harmsja 6129: table.LC_SimpleTable tr {
1.803 bisitz 6130: padding: 0;
1.698 harmsja 6131: border:solid 1px $lg_border_color;
1.693 droeschl 6132: }
1.795 www 6133:
6134: table.LC_SimpleTable thead {
1.698 harmsja 6135: background:rgb(220,220,220);
1.693 droeschl 6136: }
6137:
1.721 harmsja 6138: div.LC_columnSection {
1.693 droeschl 6139: display: block;
6140: clear: both;
6141: overflow: hidden;
1.803 bisitz 6142: margin: 0;
1.693 droeschl 6143: }
6144:
1.721 harmsja 6145: div.LC_columnSection>* {
1.693 droeschl 6146: float: left;
1.803 bisitz 6147: margin: 10px 20px 10px 0;
1.747 neumanie 6148: overflow:hidden;
1.693 droeschl 6149: }
1.721 harmsja 6150:
1.694 tempelho 6151: .LC_loginpage_container {
6152: text-align:left;
6153: margin : 0 auto;
1.785 tempelho 6154: width:90%;
1.694 tempelho 6155: padding: 10px;
6156: height: auto;
1.712 muellerd 6157: background-color:#FFFFFF;
1.694 tempelho 6158: border:1px solid #CCCCCC;
6159: }
6160:
6161:
6162: .LC_loginpage_loginContainer {
6163: float:left;
1.712 muellerd 6164: width: 182px;
1.785 tempelho 6165: padding: 2px;
1.712 muellerd 6166: border:1px solid #CCCCCC;
6167: background-color:$loginbg;
1.694 tempelho 6168: }
6169:
1.795 www 6170: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6171: margin-top: 0;
1.712 muellerd 6172: display:block;
6173: background:$bgcol;
6174: color:$textcol;
6175: padding-left:5px;
6176: }
1.785 tempelho 6177:
1.694 tempelho 6178: .LC_loginpage_loginInfo {
6179: float:left;
1.785 tempelho 6180: width:182px;
1.694 tempelho 6181: border:1px solid #CCCCCC;
1.785 tempelho 6182: padding:2px;
1.712 muellerd 6183: }
6184:
1.694 tempelho 6185: .LC_loginpage_space {
1.754 droeschl 6186: clear: both;
6187: margin-bottom: 20px;
1.694 tempelho 6188: border-bottom: 1px solid #CCCCCC;
6189: }
6190:
1.785 tempelho 6191: .LC_loginpage_floatLeft {
6192: float: left;
6193: width: 200px;
6194: margin: 0;
6195: }
6196:
1.795 www 6197: table em {
1.754 droeschl 6198: font-weight: bold;
6199: font-style: normal;
1.748 schulted 6200: }
1.795 www 6201:
1.779 bisitz 6202: table.LC_tableBrowseRes,
1.795 www 6203: table.LC_tableOfContent {
1.769 schulted 6204: border:none;
1.858 bisitz 6205: border-spacing: 1px;
1.754 droeschl 6206: padding: 3px;
6207: background-color: #FFFFFF;
6208: font-size: 90%;
1.753 droeschl 6209: }
1.789 droeschl 6210:
6211: table.LC_tableOfContent{
6212: border-collapse: collapse;
6213: }
6214:
1.771 droeschl 6215: table.LC_tableBrowseRes a,
1.768 schulted 6216: table.LC_tableOfContent a {
1.771 droeschl 6217: background-color: transparent;
1.753 droeschl 6218: text-decoration: none;
6219: }
6220:
1.771 droeschl 6221: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6222: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6223: background-color: #EEEEEE;
1.753 droeschl 6224: }
6225:
1.795 www 6226: table.LC_tableOfContent img {
1.753 droeschl 6227: border: none;
6228: height: 1.3em;
6229: vertical-align: text-bottom;
6230: margin-right: 0.3em;
6231: }
1.757 schulted 6232:
1.795 www 6233: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6234: background-image:url(/res/adm/pages/open-first-problem.gif);
6235: }
6236:
1.795 www 6237: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6238: background-image:url(/res/adm/pages/start-navigation.gif);
6239: }
6240:
1.795 www 6241: a#LC_content_toolbar_closenav {
1.774 ehlerst 6242: background-image:url(/res/adm/pages/close-navigation.gif);
6243: }
6244:
1.795 www 6245: a#LC_content_toolbar_everything {
1.774 ehlerst 6246: background-image:url(/res/adm/pages/show-all.gif);
6247: }
6248:
1.795 www 6249: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6250: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6251: }
6252:
1.795 www 6253: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6254: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6255: }
6256:
1.795 www 6257: a#LC_content_toolbar_changefolder {
1.757 schulted 6258: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6259: }
6260:
1.795 www 6261: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6262: background-image:url(/res/adm/pages/open-all-folders.gif);
6263: }
6264:
1.795 www 6265: ul#LC_toolbar li a:hover {
1.757 schulted 6266: background-position: bottom center;
6267: }
6268:
1.795 www 6269: ul#LC_toolbar {
1.803 bisitz 6270: padding: 0;
1.757 schulted 6271: margin: 2px;
6272: list-style:none;
6273: position:relative;
6274: background-color:white;
6275: }
6276:
1.795 www 6277: ul#LC_toolbar li {
1.757 schulted 6278: border:1px solid white;
1.803 bisitz 6279: padding: 0;
1.757 schulted 6280: margin: 0;
1.795 www 6281: float: left;
1.767 droeschl 6282: display:inline;
1.757 schulted 6283: vertical-align:middle;
1.795 www 6284: }
1.757 schulted 6285:
1.783 amueller 6286:
1.795 www 6287: a.LC_toolbarItem {
1.767 droeschl 6288: display:block;
1.803 bisitz 6289: padding: 0;
6290: margin: 0;
1.757 schulted 6291: height: 32px;
6292: width: 32px;
1.779 bisitz 6293: color:white;
1.803 bisitz 6294: border: none;
1.757 schulted 6295: background-repeat:no-repeat;
6296: background-color:transparent;
6297: }
6298:
1.843 bisitz 6299: ul.LC_funclist li {
1.782 bisitz 6300: float: left;
6301: white-space: nowrap;
6302: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6303: margin: 0 15px 15px 10px;
1.782 bisitz 6304: }
6305:
1.757 schulted 6306:
1.343 albertel 6307: END
6308: }
6309:
1.306 albertel 6310: =pod
6311:
6312: =item * &headtag()
6313:
6314: Returns a uniform footer for LON-CAPA web pages.
6315:
1.307 albertel 6316: Inputs: $title - optional title for the head
6317: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6318: $args - optional arguments
1.319 albertel 6319: force_register - if is true call registerurl so the remote is
6320: informed
1.415 albertel 6321: redirect -> array ref of
6322: 1- seconds before redirect occurs
6323: 2- url to redirect to
6324: 3- whether the side effect should occur
1.315 albertel 6325: (side effect of setting
6326: $env{'internal.head.redirect'} to the url
6327: redirected too)
1.352 albertel 6328: domain -> force to color decorate a page for a specific
6329: domain
6330: function -> force usage of a specific rolish color scheme
6331: bgcolor -> override the default page bgcolor
1.460 albertel 6332: no_auto_mt_title
6333: -> prevent &mt()ing the title arg
1.464 albertel 6334:
1.306 albertel 6335: =cut
6336:
6337: sub headtag {
1.313 albertel 6338: my ($title,$head_extra,$args) = @_;
1.306 albertel 6339:
1.363 albertel 6340: my $function = $args->{'function'} || &get_users_function();
6341: my $domain = $args->{'domain'} || &determinedomain();
6342: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6343: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6344: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6345: #time(),
1.418 albertel 6346: $env{'environment.color.timestamp'},
1.363 albertel 6347: $function,$domain,$bgcolor);
6348:
1.369 www 6349: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6350:
1.308 albertel 6351: my $result =
6352: '<head>'.
1.461 albertel 6353: &font_settings();
1.319 albertel 6354:
1.461 albertel 6355: if (!$args->{'frameset'}) {
6356: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6357: }
1.319 albertel 6358: if ($args->{'force_register'}) {
6359: $result .= &Apache::lonmenu::registerurl(1);
6360: }
1.436 albertel 6361: if (!$args->{'no_nav_bar'}
6362: && !$args->{'only_body'}
6363: && !$args->{'frameset'}) {
6364: $result .= &help_menu_js();
6365: }
1.319 albertel 6366:
1.314 albertel 6367: if (ref($args->{'redirect'})) {
1.414 albertel 6368: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6369: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6370: if (!$inhibit_continue) {
6371: $env{'internal.head.redirect'} = $url;
6372: }
1.313 albertel 6373: $result.=<<ADDMETA
6374: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6375: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6376: ADDMETA
6377: }
1.306 albertel 6378: if (!defined($title)) {
6379: $title = 'The LearningOnline Network with CAPA';
6380: }
1.460 albertel 6381: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6382: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6383: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6384: .$head_extra;
1.306 albertel 6385: return $result;
6386: }
6387:
6388: =pod
6389:
1.340 albertel 6390: =item * &font_settings()
6391:
6392: Returns neccessary <meta> to set the proper encoding
6393:
6394: Inputs: none
6395:
6396: =cut
6397:
6398: sub font_settings {
6399: my $headerstring='';
1.647 www 6400: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6401: $headerstring.=
6402: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6403: }
6404: return $headerstring;
6405: }
6406:
1.341 albertel 6407: =pod
6408:
6409: =item * &xml_begin()
6410:
6411: Returns the needed doctype and <html>
6412:
6413: Inputs: none
6414:
6415: =cut
6416:
6417: sub xml_begin {
6418: my $output='';
6419:
1.592 albertel 6420: if ($env{'internal.start_page'}==1) {
6421: &Apache::lonhtmlcommon::init_htmlareafields();
6422: }
1.342 albertel 6423:
1.341 albertel 6424: if ($env{'browser.mathml'}) {
6425: $output='<?xml version="1.0"?>'
6426: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6427: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6428:
6429: # .'<!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">] >'
6430: .'<!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">'
6431: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6432: .'xmlns="http://www.w3.org/1999/xhtml">';
6433: } else {
1.849 bisitz 6434: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6435: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6436: }
6437: return $output;
6438: }
1.340 albertel 6439:
6440: =pod
6441:
1.306 albertel 6442: =item * &endheadtag()
6443:
6444: Returns a uniform </head> for LON-CAPA web pages.
6445:
6446: Inputs: none
6447:
6448: =cut
6449:
6450: sub endheadtag {
6451: return '</head>';
6452: }
6453:
6454: =pod
6455:
6456: =item * &head()
6457:
6458: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6459:
1.648 raeburn 6460: Inputs:
6461:
6462: =over 4
6463:
6464: $title - optional title for the page
6465:
6466: $head_extra - optional extra HTML to put inside the <head>
6467:
6468: =back
1.405 albertel 6469:
1.306 albertel 6470: =cut
6471:
6472: sub head {
1.325 albertel 6473: my ($title,$head_extra,$args) = @_;
6474: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6475: }
6476:
6477: =pod
6478:
6479: =item * &start_page()
6480:
6481: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6482:
1.648 raeburn 6483: Inputs:
6484:
6485: =over 4
6486:
6487: $title - optional title for the page
6488:
6489: $head_extra - optional extra HTML to incude inside the <head>
6490:
6491: $args - additional optional args supported are:
6492:
6493: =over 8
6494:
6495: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6496: arg on
1.814 bisitz 6497: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6498: add_entries -> additional attributes to add to the <body>
6499: domain -> force to color decorate a page for a
1.317 albertel 6500: specific domain
1.648 raeburn 6501: function -> force usage of a specific rolish color
1.317 albertel 6502: scheme
1.648 raeburn 6503: redirect -> see &headtag()
6504: bgcolor -> override the default page bg color
6505: js_ready -> return a string ready for being used in
1.317 albertel 6506: a javascript writeln
1.648 raeburn 6507: html_encode -> return a string ready for being used in
1.320 albertel 6508: a html attribute
1.648 raeburn 6509: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6510: $forcereg arg
1.648 raeburn 6511: frameset -> if true will start with a <frameset>
1.330 albertel 6512: rather than <body>
1.648 raeburn 6513: skip_phases -> hash ref of
1.338 albertel 6514: head -> skip the <html><head> generation
6515: body -> skip all <body> generation
1.648 raeburn 6516: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6517: 'Switch To Inline Menu' link
1.648 raeburn 6518: no_auto_mt_title -> prevent &mt()ing the title arg
6519: inherit_jsmath -> when creating popup window in a page,
6520: should it have jsmath forced on by the
6521: current page
1.867 kalberla 6522: bread_crumbs -> Array containing breadcrumbs
6523: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6524:
1.648 raeburn 6525: =back
1.460 albertel 6526:
1.648 raeburn 6527: =back
1.562 albertel 6528:
1.306 albertel 6529: =cut
6530:
6531: sub start_page {
1.309 albertel 6532: my ($title,$head_extra,$args) = @_;
1.318 albertel 6533: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6534: my %head_args;
1.352 albertel 6535: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6536: 'bgcolor','frameset','no_nav_bar','only_body',
6537: 'no_auto_mt_title') {
1.319 albertel 6538: if (defined($args->{$arg})) {
1.324 raeburn 6539: $head_args{$arg} = $args->{$arg};
1.319 albertel 6540: }
1.313 albertel 6541: }
1.319 albertel 6542:
1.315 albertel 6543: $env{'internal.start_page'}++;
1.338 albertel 6544: my $result;
6545: if (! exists($args->{'skip_phases'}{'head'}) ) {
6546: $result.=
1.341 albertel 6547: &xml_begin().
1.338 albertel 6548: &headtag($title,$head_extra,\%head_args).&endheadtag();
6549: }
6550:
6551: if (! exists($args->{'skip_phases'}{'body'}) ) {
6552: if ($args->{'frameset'}) {
6553: my $attr_string = &make_attr_string($args->{'force_register'},
6554: $args->{'add_entries'});
6555: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6556: } else {
6557: $result .=
6558: &bodytag($title,
6559: $args->{'function'}, $args->{'add_entries'},
6560: $args->{'only_body'}, $args->{'domain'},
6561: $args->{'force_register'}, $args->{'no_nav_bar'},
6562: $args->{'bgcolor'}, $args->{'no_inline_link'},
6563: $args);
6564: }
1.330 albertel 6565: }
1.338 albertel 6566:
1.315 albertel 6567: if ($args->{'js_ready'}) {
1.713 kaisler 6568: $result = &js_ready($result);
1.315 albertel 6569: }
1.320 albertel 6570: if ($args->{'html_encode'}) {
1.713 kaisler 6571: $result = &html_encode($result);
6572: }
6573:
1.813 bisitz 6574: # Preparation for new and consistent functionlist at top of screen
6575: # if ($args->{'functionlist'}) {
6576: # $result .= &build_functionlist();
6577: #}
6578:
6579: # Don't add anything more if only_body wanted
6580: return $result if $args->{'only_body'};
6581:
6582: #Breadcrumbs
1.758 kaisler 6583: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6584: &Apache::lonhtmlcommon::clear_breadcrumbs();
6585: #if any br links exists, add them to the breadcrumbs
6586: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6587: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6588: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6589: }
6590: }
6591:
6592: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6593: if(exists($args->{'bread_crumbs_component'})){
6594: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6595: }else{
6596: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6597: }
1.320 albertel 6598: }
1.315 albertel 6599: return $result;
1.306 albertel 6600: }
6601:
1.330 albertel 6602:
1.306 albertel 6603: =pod
6604:
6605: =item * &head()
6606:
6607: Returns a complete </body></html> section for LON-CAPA web pages.
6608:
1.315 albertel 6609: Inputs: $args - additional optional args supported are:
6610: js_ready -> return a string ready for being used in
6611: a javascript writeln
1.320 albertel 6612: html_encode -> return a string ready for being used in
6613: a html attribute
1.330 albertel 6614: frameset -> if true will start with a <frameset>
6615: rather than <body>
1.493 albertel 6616: dicsussion -> if true will get discussion from
6617: lonxml::xmlend
6618: (you can pass the target and parser arguments
6619: through optional 'target' and 'parser' args
6620: to this routine)
1.306 albertel 6621:
6622: =cut
6623:
6624: sub end_page {
1.315 albertel 6625: my ($args) = @_;
6626: $env{'internal.end_page'}++;
1.330 albertel 6627: my $result;
1.335 albertel 6628: if ($args->{'discussion'}) {
6629: my ($target,$parser);
6630: if (ref($args->{'discussion'})) {
6631: ($target,$parser) =($args->{'discussion'}{'target'},
6632: $args->{'discussion'}{'parser'});
6633: }
6634: $result .= &Apache::lonxml::xmlend($target,$parser);
6635: }
6636:
1.330 albertel 6637: if ($args->{'frameset'}) {
6638: $result .= '</frameset>';
6639: } else {
1.635 raeburn 6640: $result .= &endbodytag($args);
1.330 albertel 6641: }
6642: $result .= "\n</html>";
6643:
1.315 albertel 6644: if ($args->{'js_ready'}) {
1.317 albertel 6645: $result = &js_ready($result);
1.315 albertel 6646: }
1.335 albertel 6647:
1.320 albertel 6648: if ($args->{'html_encode'}) {
6649: $result = &html_encode($result);
6650: }
1.335 albertel 6651:
1.315 albertel 6652: return $result;
6653: }
6654:
1.320 albertel 6655: sub html_encode {
6656: my ($result) = @_;
6657:
1.322 albertel 6658: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6659:
6660: return $result;
6661: }
1.317 albertel 6662: sub js_ready {
6663: my ($result) = @_;
6664:
1.323 albertel 6665: $result =~ s/[\n\r]/ /xmsg;
6666: $result =~ s/\\/\\\\/xmsg;
6667: $result =~ s/'/\\'/xmsg;
1.372 albertel 6668: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6669:
6670: return $result;
6671: }
6672:
1.315 albertel 6673: sub validate_page {
6674: if ( exists($env{'internal.start_page'})
1.316 albertel 6675: && $env{'internal.start_page'} > 1) {
6676: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6677: $env{'internal.start_page'}.' '.
1.316 albertel 6678: $ENV{'request.filename'});
1.315 albertel 6679: }
6680: if ( exists($env{'internal.end_page'})
1.316 albertel 6681: && $env{'internal.end_page'} > 1) {
6682: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6683: $env{'internal.end_page'}.' '.
1.316 albertel 6684: $env{'request.filename'});
1.315 albertel 6685: }
6686: if ( exists($env{'internal.start_page'})
6687: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6688: &Apache::lonnet::logthis('start_page called without end_page '.
6689: $env{'request.filename'});
1.315 albertel 6690: }
6691: if ( ! exists($env{'internal.start_page'})
6692: && exists($env{'internal.end_page'})) {
1.316 albertel 6693: &Apache::lonnet::logthis('end_page called without start_page'.
6694: $env{'request.filename'});
1.315 albertel 6695: }
1.306 albertel 6696: }
1.315 albertel 6697:
1.318 albertel 6698: sub simple_error_page {
6699: my ($r,$title,$msg) = @_;
6700: my $page =
6701: &Apache::loncommon::start_page($title).
6702: &mt($msg).
6703: &Apache::loncommon::end_page();
6704: if (ref($r)) {
6705: $r->print($page);
1.327 albertel 6706: return;
1.318 albertel 6707: }
6708: return $page;
6709: }
1.347 albertel 6710:
6711: {
1.610 albertel 6712: my @row_count;
1.347 albertel 6713: sub start_data_table {
1.422 albertel 6714: my ($add_class) = @_;
6715: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6716: unshift(@row_count,0);
1.422 albertel 6717: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6718: }
6719:
6720: sub end_data_table {
1.610 albertel 6721: shift(@row_count);
1.389 albertel 6722: return '</table>'."\n";;
1.347 albertel 6723: }
6724:
6725: sub start_data_table_row {
1.422 albertel 6726: my ($add_class) = @_;
1.610 albertel 6727: $row_count[0]++;
6728: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6729: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6730: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6731: }
1.471 banghart 6732:
6733: sub continue_data_table_row {
6734: my ($add_class) = @_;
1.610 albertel 6735: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6736: $css_class = (join(' ',$css_class,$add_class));
6737: return '<tr class="'.$css_class.'">'."\n";;
6738: }
1.347 albertel 6739:
6740: sub end_data_table_row {
1.389 albertel 6741: return '</tr>'."\n";;
1.347 albertel 6742: }
1.367 www 6743:
1.421 albertel 6744: sub start_data_table_empty_row {
1.707 bisitz 6745: # $row_count[0]++;
1.421 albertel 6746: return '<tr class="LC_empty_row" >'."\n";;
6747: }
6748:
6749: sub end_data_table_empty_row {
6750: return '</tr>'."\n";;
6751: }
6752:
1.367 www 6753: sub start_data_table_header_row {
1.389 albertel 6754: return '<tr class="LC_header_row">'."\n";;
1.367 www 6755: }
6756:
6757: sub end_data_table_header_row {
1.389 albertel 6758: return '</tr>'."\n";;
1.367 www 6759: }
1.347 albertel 6760: }
6761:
1.548 albertel 6762: =pod
6763:
6764: =item * &inhibit_menu_check($arg)
6765:
6766: Checks for a inhibitmenu state and generates output to preserve it
6767:
6768: Inputs: $arg - can be any of
6769: - undef - in which case the return value is a string
6770: to add into arguments list of a uri
6771: - 'input' - in which case the return value is a HTML
6772: <form> <input> field of type hidden to
6773: preserve the value
6774: - a url - in which case the return value is the url with
6775: the neccesary cgi args added to preserve the
6776: inhibitmenu state
6777: - a ref to a url - no return value, but the string is
6778: updated to include the neccessary cgi
6779: args to preserve the inhibitmenu state
6780:
6781: =cut
6782:
6783: sub inhibit_menu_check {
6784: my ($arg) = @_;
6785: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6786: if ($arg eq 'input') {
6787: if ($env{'form.inhibitmenu'}) {
6788: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6789: } else {
6790: return
6791: }
6792: }
6793: if ($env{'form.inhibitmenu'}) {
6794: if (ref($arg)) {
6795: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6796: } elsif ($arg eq '') {
6797: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6798: } else {
6799: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6800: }
6801: }
6802: if (!ref($arg)) {
6803: return $arg;
6804: }
6805: }
6806:
1.251 albertel 6807: ###############################################
1.182 matthew 6808:
6809: =pod
6810:
1.549 albertel 6811: =back
6812:
6813: =head1 User Information Routines
6814:
6815: =over 4
6816:
1.405 albertel 6817: =item * &get_users_function()
1.182 matthew 6818:
6819: Used by &bodytag to determine the current users primary role.
6820: Returns either 'student','coordinator','admin', or 'author'.
6821:
6822: =cut
6823:
6824: ###############################################
6825: sub get_users_function {
1.815 tempelho 6826: my $function = 'norole';
1.818 tempelho 6827: if ($env{'request.role'}=~/^(st)/) {
6828: $function='student';
6829: }
1.258 albertel 6830: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6831: $function='coordinator';
6832: }
1.258 albertel 6833: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6834: $function='admin';
6835: }
1.826 bisitz 6836: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6837: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6838: $function='author';
6839: }
6840: return $function;
1.54 www 6841: }
1.99 www 6842:
6843: ###############################################
6844:
1.233 raeburn 6845: =pod
6846:
1.821 raeburn 6847: =item * &show_course()
6848:
6849: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6850: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6851:
6852: Inputs:
6853: None
6854:
6855: Outputs:
6856: Scalar: 1 if 'Course' to be used, 0 otherwise.
6857:
6858: =cut
6859:
6860: ###############################################
6861: sub show_course {
6862: my $course = !$env{'user.adv'};
6863: if (!$env{'user.adv'}) {
6864: foreach my $env (keys(%env)) {
6865: next if ($env !~ m/^user\.priv\./);
6866: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6867: $course = 0;
6868: last;
6869: }
6870: }
6871: }
6872: return $course;
6873: }
6874:
6875: ###############################################
6876:
6877: =pod
6878:
1.542 raeburn 6879: =item * &check_user_status()
1.274 raeburn 6880:
6881: Determines current status of supplied role for a
6882: specific user. Roles can be active, previous or future.
6883:
6884: Inputs:
6885: user's domain, user's username, course's domain,
1.375 raeburn 6886: course's number, optional section ID.
1.274 raeburn 6887:
6888: Outputs:
6889: role status: active, previous or future.
6890:
6891: =cut
6892:
6893: sub check_user_status {
1.412 raeburn 6894: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6895: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6896: my @uroles = keys %userinfo;
6897: my $srchstr;
6898: my $active_chk = 'none';
1.412 raeburn 6899: my $now = time;
1.274 raeburn 6900: if (@uroles > 0) {
1.412 raeburn 6901: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6902: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6903: } else {
1.412 raeburn 6904: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6905: }
6906: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6907: my $role_end = 0;
6908: my $role_start = 0;
6909: $active_chk = 'active';
1.412 raeburn 6910: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6911: $role_end = $1;
6912: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6913: $role_start = $1;
1.274 raeburn 6914: }
6915: }
6916: if ($role_start > 0) {
1.412 raeburn 6917: if ($now < $role_start) {
1.274 raeburn 6918: $active_chk = 'future';
6919: }
6920: }
6921: if ($role_end > 0) {
1.412 raeburn 6922: if ($now > $role_end) {
1.274 raeburn 6923: $active_chk = 'previous';
6924: }
6925: }
6926: }
6927: }
6928: return $active_chk;
6929: }
6930:
6931: ###############################################
6932:
6933: =pod
6934:
1.405 albertel 6935: =item * &get_sections()
1.233 raeburn 6936:
6937: Determines all the sections for a course including
6938: sections with students and sections containing other roles.
1.419 raeburn 6939: Incoming parameters:
6940:
6941: 1. domain
6942: 2. course number
6943: 3. reference to array containing roles for which sections should
6944: be gathered (optional).
6945: 4. reference to array containing status types for which sections
6946: should be gathered (optional).
6947:
6948: If the third argument is undefined, sections are gathered for any role.
6949: If the fourth argument is undefined, sections are gathered for any status.
6950: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6951:
1.374 raeburn 6952: Returns section hash (keys are section IDs, values are
6953: number of users in each section), subject to the
1.419 raeburn 6954: optional roles filter, optional status filter
1.233 raeburn 6955:
6956: =cut
6957:
6958: ###############################################
6959: sub get_sections {
1.419 raeburn 6960: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6961: if (!defined($cdom) || !defined($cnum)) {
6962: my $cid = $env{'request.course.id'};
6963:
6964: return if (!defined($cid));
6965:
6966: $cdom = $env{'course.'.$cid.'.domain'};
6967: $cnum = $env{'course.'.$cid.'.num'};
6968: }
6969:
6970: my %sectioncount;
1.419 raeburn 6971: my $now = time;
1.240 albertel 6972:
1.366 albertel 6973: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6974: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6975: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6976: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6977: my $start_index = &Apache::loncoursedata::CL_START();
6978: my $end_index = &Apache::loncoursedata::CL_END();
6979: my $status;
1.366 albertel 6980: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6981: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6982: $data->[$status_index],
6983: $data->[$start_index],
6984: $data->[$end_index]);
6985: if ($stu_status eq 'Active') {
6986: $status = 'active';
6987: } elsif ($end < $now) {
6988: $status = 'previous';
6989: } elsif ($start > $now) {
6990: $status = 'future';
6991: }
6992: if ($section ne '-1' && $section !~ /^\s*$/) {
6993: if ((!defined($possible_status)) || (($status ne '') &&
6994: (grep/^\Q$status\E$/,@{$possible_status}))) {
6995: $sectioncount{$section}++;
6996: }
1.240 albertel 6997: }
6998: }
6999: }
7000: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7001: foreach my $user (sort(keys(%courseroles))) {
7002: if ($user !~ /^(\w{2})/) { next; }
7003: my ($role) = ($user =~ /^(\w{2})/);
7004: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7005: my ($section,$status);
1.240 albertel 7006: if ($role eq 'cr' &&
7007: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7008: $section=$1;
7009: }
7010: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7011: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7012: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7013: if ($end == -1 && $start == -1) {
7014: next; #deleted role
7015: }
7016: if (!defined($possible_status)) {
7017: $sectioncount{$section}++;
7018: } else {
7019: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7020: $status = 'active';
7021: } elsif ($end < $now) {
7022: $status = 'future';
7023: } elsif ($start > $now) {
7024: $status = 'previous';
7025: }
7026: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7027: $sectioncount{$section}++;
7028: }
7029: }
1.233 raeburn 7030: }
1.366 albertel 7031: return %sectioncount;
1.233 raeburn 7032: }
7033:
1.274 raeburn 7034: ###############################################
1.294 raeburn 7035:
7036: =pod
1.405 albertel 7037:
7038: =item * &get_course_users()
7039:
1.275 raeburn 7040: Retrieves usernames:domains for users in the specified course
7041: with specific role(s), and access status.
7042:
7043: Incoming parameters:
1.277 albertel 7044: 1. course domain
7045: 2. course number
7046: 3. access status: users must have - either active,
1.275 raeburn 7047: previous, future, or all.
1.277 albertel 7048: 4. reference to array of permissible roles
1.288 raeburn 7049: 5. reference to array of section restrictions (optional)
7050: 6. reference to results object (hash of hashes).
7051: 7. reference to optional userdata hash
1.609 raeburn 7052: 8. reference to optional statushash
1.630 raeburn 7053: 9. flag if privileged users (except those set to unhide in
7054: course settings) should be excluded
1.609 raeburn 7055: Keys of top level results hash are roles.
1.275 raeburn 7056: Keys of inner hashes are username:domain, with
7057: values set to access type.
1.288 raeburn 7058: Optional userdata hash returns an array with arguments in the
7059: same order as loncoursedata::get_classlist() for student data.
7060:
1.609 raeburn 7061: Optional statushash returns
7062:
1.288 raeburn 7063: Entries for end, start, section and status are blank because
7064: of the possibility of multiple values for non-student roles.
7065:
1.275 raeburn 7066: =cut
1.405 albertel 7067:
1.275 raeburn 7068: ###############################################
1.405 albertel 7069:
1.275 raeburn 7070: sub get_course_users {
1.630 raeburn 7071: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7072: my %idx = ();
1.419 raeburn 7073: my %seclists;
1.288 raeburn 7074:
7075: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7076: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7077: $idx{end} = &Apache::loncoursedata::CL_END();
7078: $idx{start} = &Apache::loncoursedata::CL_START();
7079: $idx{id} = &Apache::loncoursedata::CL_ID();
7080: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7081: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7082: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7083:
1.290 albertel 7084: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7085: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7086: my $now = time;
1.277 albertel 7087: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7088: my $match = 0;
1.412 raeburn 7089: my $secmatch = 0;
1.419 raeburn 7090: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7091: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7092: if ($section eq '') {
7093: $section = 'none';
7094: }
1.291 albertel 7095: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7096: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7097: $secmatch = 1;
7098: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7099: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7100: $secmatch = 1;
7101: }
7102: } else {
1.419 raeburn 7103: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7104: $secmatch = 1;
7105: }
1.290 albertel 7106: }
1.412 raeburn 7107: if (!$secmatch) {
7108: next;
7109: }
1.419 raeburn 7110: }
1.275 raeburn 7111: if (defined($$types{'active'})) {
1.288 raeburn 7112: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7113: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7114: $match = 1;
1.275 raeburn 7115: }
7116: }
7117: if (defined($$types{'previous'})) {
1.609 raeburn 7118: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7119: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7120: $match = 1;
1.275 raeburn 7121: }
7122: }
7123: if (defined($$types{'future'})) {
1.609 raeburn 7124: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7125: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7126: $match = 1;
1.275 raeburn 7127: }
7128: }
1.609 raeburn 7129: if ($match) {
7130: push(@{$seclists{$student}},$section);
7131: if (ref($userdata) eq 'HASH') {
7132: $$userdata{$student} = $$classlist{$student};
7133: }
7134: if (ref($statushash) eq 'HASH') {
7135: $statushash->{$student}{'st'}{$section} = $status;
7136: }
1.288 raeburn 7137: }
1.275 raeburn 7138: }
7139: }
1.412 raeburn 7140: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7141: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7142: my $now = time;
1.609 raeburn 7143: my %displaystatus = ( previous => 'Expired',
7144: active => 'Active',
7145: future => 'Future',
7146: );
1.630 raeburn 7147: my %nothide;
7148: if ($hidepriv) {
7149: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7150: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7151: if ($user !~ /:/) {
7152: $nothide{join(':',split(/[\@]/,$user))}=1;
7153: } else {
7154: $nothide{$user} = 1;
7155: }
7156: }
7157: }
1.439 raeburn 7158: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7159: my $match = 0;
1.412 raeburn 7160: my $secmatch = 0;
1.439 raeburn 7161: my $status;
1.412 raeburn 7162: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7163: $user =~ s/:$//;
1.439 raeburn 7164: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7165: if ($end == -1 || $start == -1) {
7166: next;
7167: }
7168: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7169: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7170: my ($uname,$udom) = split(/:/,$user);
7171: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7172: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7173: $secmatch = 1;
7174: } elsif ($usec eq '') {
1.420 albertel 7175: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7176: $secmatch = 1;
7177: }
7178: } else {
7179: if (grep(/^\Q$usec\E$/,@{$sections})) {
7180: $secmatch = 1;
7181: }
7182: }
7183: if (!$secmatch) {
7184: next;
7185: }
1.288 raeburn 7186: }
1.419 raeburn 7187: if ($usec eq '') {
7188: $usec = 'none';
7189: }
1.275 raeburn 7190: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7191: if ($hidepriv) {
7192: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7193: (!$nothide{$uname.':'.$udom})) {
7194: next;
7195: }
7196: }
1.503 raeburn 7197: if ($end > 0 && $end < $now) {
1.439 raeburn 7198: $status = 'previous';
7199: } elsif ($start > $now) {
7200: $status = 'future';
7201: } else {
7202: $status = 'active';
7203: }
1.277 albertel 7204: foreach my $type (keys(%{$types})) {
1.275 raeburn 7205: if ($status eq $type) {
1.420 albertel 7206: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7207: push(@{$$users{$role}{$user}},$type);
7208: }
1.288 raeburn 7209: $match = 1;
7210: }
7211: }
1.419 raeburn 7212: if (($match) && (ref($userdata) eq 'HASH')) {
7213: if (!exists($$userdata{$uname.':'.$udom})) {
7214: &get_user_info($udom,$uname,\%idx,$userdata);
7215: }
1.420 albertel 7216: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7217: push(@{$seclists{$uname.':'.$udom}},$usec);
7218: }
1.609 raeburn 7219: if (ref($statushash) eq 'HASH') {
7220: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7221: }
1.275 raeburn 7222: }
7223: }
7224: }
7225: }
1.290 albertel 7226: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7227: if ((defined($cdom)) && (defined($cnum))) {
7228: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7229: if ( defined($csettings{'internal.courseowner'}) ) {
7230: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7231: next if ($owner eq '');
7232: my ($ownername,$ownerdom);
7233: if ($owner =~ /^([^:]+):([^:]+)$/) {
7234: $ownername = $1;
7235: $ownerdom = $2;
7236: } else {
7237: $ownername = $owner;
7238: $ownerdom = $cdom;
7239: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7240: }
7241: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7242: if (defined($userdata) &&
1.609 raeburn 7243: !exists($$userdata{$owner})) {
7244: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7245: if (!grep(/^none$/,@{$seclists{$owner}})) {
7246: push(@{$seclists{$owner}},'none');
7247: }
7248: if (ref($statushash) eq 'HASH') {
7249: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7250: }
1.290 albertel 7251: }
1.279 raeburn 7252: }
7253: }
7254: }
1.419 raeburn 7255: foreach my $user (keys(%seclists)) {
7256: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7257: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7258: }
1.275 raeburn 7259: }
7260: return;
7261: }
7262:
1.288 raeburn 7263: sub get_user_info {
7264: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7265: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7266: &plainname($uname,$udom,'lastname');
1.291 albertel 7267: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7268: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7269: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7270: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7271: return;
7272: }
1.275 raeburn 7273:
1.472 raeburn 7274: ###############################################
7275:
7276: =pod
7277:
7278: =item * &get_user_quota()
7279:
7280: Retrieves quota assigned for storage of portfolio files for a user
7281:
7282: Incoming parameters:
7283: 1. user's username
7284: 2. user's domain
7285:
7286: Returns:
1.536 raeburn 7287: 1. Disk quota (in Mb) assigned to student.
7288: 2. (Optional) Type of setting: custom or default
7289: (individually assigned or default for user's
7290: institutional status).
7291: 3. (Optional) - User's institutional status (e.g., faculty, staff
7292: or student - types as defined in localenroll::inst_usertypes
7293: for user's domain, which determines default quota for user.
7294: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7295:
7296: If a value has been stored in the user's environment,
1.536 raeburn 7297: it will return that, otherwise it returns the maximal default
7298: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7299:
7300: =cut
7301:
7302: ###############################################
7303:
7304:
7305: sub get_user_quota {
7306: my ($uname,$udom) = @_;
1.536 raeburn 7307: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7308: if (!defined($udom)) {
7309: $udom = $env{'user.domain'};
7310: }
7311: if (!defined($uname)) {
7312: $uname = $env{'user.name'};
7313: }
7314: if (($udom eq '' || $uname eq '') ||
7315: ($udom eq 'public') && ($uname eq 'public')) {
7316: $quota = 0;
1.536 raeburn 7317: $quotatype = 'default';
7318: $defquota = 0;
1.472 raeburn 7319: } else {
1.536 raeburn 7320: my $inststatus;
1.472 raeburn 7321: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7322: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7323: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7324: } else {
1.536 raeburn 7325: my %userenv =
7326: &Apache::lonnet::get('environment',['portfolioquota',
7327: 'inststatus'],$udom,$uname);
1.472 raeburn 7328: my ($tmp) = keys(%userenv);
7329: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7330: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7331: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7332: } else {
7333: undef(%userenv);
7334: }
7335: }
1.536 raeburn 7336: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7337: if ($quota eq '') {
1.536 raeburn 7338: $quota = $defquota;
7339: $quotatype = 'default';
7340: } else {
7341: $quotatype = 'custom';
1.472 raeburn 7342: }
7343: }
1.536 raeburn 7344: if (wantarray) {
7345: return ($quota,$quotatype,$settingstatus,$defquota);
7346: } else {
7347: return $quota;
7348: }
1.472 raeburn 7349: }
7350:
7351: ###############################################
7352:
7353: =pod
7354:
7355: =item * &default_quota()
7356:
1.536 raeburn 7357: Retrieves default quota assigned for storage of user portfolio files,
7358: given an (optional) user's institutional status.
1.472 raeburn 7359:
7360: Incoming parameters:
7361: 1. domain
1.536 raeburn 7362: 2. (Optional) institutional status(es). This is a : separated list of
7363: status types (e.g., faculty, staff, student etc.)
7364: which apply to the user for whom the default is being retrieved.
7365: If the institutional status string in undefined, the domain
7366: default quota will be returned.
1.472 raeburn 7367:
7368: Returns:
7369: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7370: 2. (Optional) institutional type which determined the value of the
7371: default quota.
1.472 raeburn 7372:
7373: If a value has been stored in the domain's configuration db,
7374: it will return that, otherwise it returns 20 (for backwards
7375: compatibility with domains which have not set up a configuration
7376: db file; the original statically defined portfolio quota was 20 Mb).
7377:
1.536 raeburn 7378: If the user's status includes multiple types (e.g., staff and student),
7379: the largest default quota which applies to the user determines the
7380: default quota returned.
7381:
1.780 raeburn 7382: =back
7383:
1.472 raeburn 7384: =cut
7385:
7386: ###############################################
7387:
7388:
7389: sub default_quota {
1.536 raeburn 7390: my ($udom,$inststatus) = @_;
7391: my ($defquota,$settingstatus);
7392: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7393: ['quotas'],$udom);
7394: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7395: if ($inststatus ne '') {
1.765 raeburn 7396: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7397: foreach my $item (@statuses) {
1.711 raeburn 7398: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7399: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7400: if ($defquota eq '') {
7401: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7402: $settingstatus = $item;
7403: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7404: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7405: $settingstatus = $item;
7406: }
7407: }
7408: } else {
7409: if ($quotahash{'quotas'}{$item} ne '') {
7410: if ($defquota eq '') {
7411: $defquota = $quotahash{'quotas'}{$item};
7412: $settingstatus = $item;
7413: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7414: $defquota = $quotahash{'quotas'}{$item};
7415: $settingstatus = $item;
7416: }
1.536 raeburn 7417: }
7418: }
7419: }
7420: }
7421: if ($defquota eq '') {
1.711 raeburn 7422: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7423: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7424: } else {
7425: $defquota = $quotahash{'quotas'}{'default'};
7426: }
1.536 raeburn 7427: $settingstatus = 'default';
7428: }
7429: } else {
7430: $settingstatus = 'default';
7431: $defquota = 20;
7432: }
7433: if (wantarray) {
7434: return ($defquota,$settingstatus);
1.472 raeburn 7435: } else {
1.536 raeburn 7436: return $defquota;
1.472 raeburn 7437: }
7438: }
7439:
1.384 raeburn 7440: sub get_secgrprole_info {
7441: my ($cdom,$cnum,$needroles,$type) = @_;
7442: my %sections_count = &get_sections($cdom,$cnum);
7443: my @sections = (sort {$a <=> $b} keys(%sections_count));
7444: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7445: my @groups = sort(keys(%curr_groups));
7446: my $allroles = [];
7447: my $rolehash;
7448: my $accesshash = {
7449: active => 'Currently has access',
7450: future => 'Will have future access',
7451: previous => 'Previously had access',
7452: };
7453: if ($needroles) {
7454: $rolehash = {'all' => 'all'};
1.385 albertel 7455: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7456: if (&Apache::lonnet::error(%user_roles)) {
7457: undef(%user_roles);
7458: }
7459: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7460: my ($role)=split(/\:/,$item,2);
7461: if ($role eq 'cr') { next; }
7462: if ($role =~ /^cr/) {
7463: $$rolehash{$role} = (split('/',$role))[3];
7464: } else {
7465: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7466: }
7467: }
7468: foreach my $key (sort(keys(%{$rolehash}))) {
7469: push(@{$allroles},$key);
7470: }
7471: push (@{$allroles},'st');
7472: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7473: }
7474: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7475: }
7476:
1.555 raeburn 7477: sub user_picker {
1.627 raeburn 7478: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7479: my $currdom = $dom;
7480: my %curr_selected = (
7481: srchin => 'dom',
1.580 raeburn 7482: srchby => 'lastname',
1.555 raeburn 7483: );
7484: my $srchterm;
1.625 raeburn 7485: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7486: if ($srch->{'srchby'} ne '') {
7487: $curr_selected{'srchby'} = $srch->{'srchby'};
7488: }
7489: if ($srch->{'srchin'} ne '') {
7490: $curr_selected{'srchin'} = $srch->{'srchin'};
7491: }
7492: if ($srch->{'srchtype'} ne '') {
7493: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7494: }
7495: if ($srch->{'srchdomain'} ne '') {
7496: $currdom = $srch->{'srchdomain'};
7497: }
7498: $srchterm = $srch->{'srchterm'};
7499: }
7500: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7501: 'usr' => 'Search criteria',
1.563 raeburn 7502: 'doma' => 'Domain/institution to search',
1.558 albertel 7503: 'uname' => 'username',
7504: 'lastname' => 'last name',
1.555 raeburn 7505: 'lastfirst' => 'last name, first name',
1.558 albertel 7506: 'crs' => 'in this course',
1.576 raeburn 7507: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7508: 'alc' => 'all LON-CAPA',
1.573 raeburn 7509: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7510: 'exact' => 'is',
7511: 'contains' => 'contains',
1.569 raeburn 7512: 'begins' => 'begins with',
1.571 raeburn 7513: 'youm' => "You must include some text to search for.",
7514: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7515: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7516: 'yomc' => "You must choose a domain when using an institutional directory search.",
7517: 'ymcd' => "You must choose a domain when using a domain search.",
7518: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7519: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7520: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7521: );
1.563 raeburn 7522: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7523: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7524:
7525: my @srchins = ('crs','dom','alc','instd');
7526:
7527: foreach my $option (@srchins) {
7528: # FIXME 'alc' option unavailable until
7529: # loncreateuser::print_user_query_page()
7530: # has been completed.
7531: next if ($option eq 'alc');
7532: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7533: if ($curr_selected{'srchin'} eq $option) {
7534: $srchinsel .= '
7535: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7536: } else {
7537: $srchinsel .= '
7538: <option value="'.$option.'">'.$lt{$option}.'</option>';
7539: }
1.555 raeburn 7540: }
1.563 raeburn 7541: $srchinsel .= "\n </select>\n";
1.555 raeburn 7542:
7543: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7544: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7545: if ($curr_selected{'srchby'} eq $option) {
7546: $srchbysel .= '
7547: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7548: } else {
7549: $srchbysel .= '
7550: <option value="'.$option.'">'.$lt{$option}.'</option>';
7551: }
7552: }
7553: $srchbysel .= "\n </select>\n";
7554:
7555: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7556: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7557: if ($curr_selected{'srchtype'} eq $option) {
7558: $srchtypesel .= '
7559: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7560: } else {
7561: $srchtypesel .= '
7562: <option value="'.$option.'">'.$lt{$option}.'</option>';
7563: }
7564: }
7565: $srchtypesel .= "\n </select>\n";
7566:
1.558 albertel 7567: my ($newuserscript,$new_user_create);
1.556 raeburn 7568:
7569: if ($forcenewuser) {
1.576 raeburn 7570: if (ref($srch) eq 'HASH') {
7571: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7572: if ($cancreate) {
7573: $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>';
7574: } else {
1.799 bisitz 7575: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7576: my %usertypetext = (
7577: official => 'institutional',
7578: unofficial => 'non-institutional',
7579: );
1.799 bisitz 7580: $new_user_create = '<p class="LC_warning">'
7581: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7582: .' '
7583: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7584: ,'<a href="'.$helplink.'">','</a>')
7585: .'</p><br />';
1.627 raeburn 7586: }
1.576 raeburn 7587: }
7588: }
7589:
1.556 raeburn 7590: $newuserscript = <<"ENDSCRIPT";
7591:
1.570 raeburn 7592: function setSearch(createnew,callingForm) {
1.556 raeburn 7593: if (createnew == 1) {
1.570 raeburn 7594: for (var i=0; i<callingForm.srchby.length; i++) {
7595: if (callingForm.srchby.options[i].value == 'uname') {
7596: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7597: }
7598: }
1.570 raeburn 7599: for (var i=0; i<callingForm.srchin.length; i++) {
7600: if ( callingForm.srchin.options[i].value == 'dom') {
7601: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7602: }
7603: }
1.570 raeburn 7604: for (var i=0; i<callingForm.srchtype.length; i++) {
7605: if (callingForm.srchtype.options[i].value == 'exact') {
7606: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7607: }
7608: }
1.570 raeburn 7609: for (var i=0; i<callingForm.srchdomain.length; i++) {
7610: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7611: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7612: }
7613: }
7614: }
7615: }
7616: ENDSCRIPT
1.558 albertel 7617:
1.556 raeburn 7618: }
7619:
1.555 raeburn 7620: my $output = <<"END_BLOCK";
1.556 raeburn 7621: <script type="text/javascript">
1.824 bisitz 7622: // <![CDATA[
1.570 raeburn 7623: function validateEntry(callingForm) {
1.558 albertel 7624:
1.556 raeburn 7625: var checkok = 1;
1.558 albertel 7626: var srchin;
1.570 raeburn 7627: for (var i=0; i<callingForm.srchin.length; i++) {
7628: if ( callingForm.srchin[i].checked ) {
7629: srchin = callingForm.srchin[i].value;
1.558 albertel 7630: }
7631: }
7632:
1.570 raeburn 7633: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7634: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7635: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7636: var srchterm = callingForm.srchterm.value;
7637: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7638: var msg = "";
7639:
7640: if (srchterm == "") {
7641: checkok = 0;
1.571 raeburn 7642: msg += "$lt{'youm'}\\n";
1.556 raeburn 7643: }
7644:
1.569 raeburn 7645: if (srchtype== 'begins') {
7646: if (srchterm.length < 2) {
7647: checkok = 0;
1.571 raeburn 7648: msg += "$lt{'thte'}\\n";
1.569 raeburn 7649: }
7650: }
7651:
1.556 raeburn 7652: if (srchtype== 'contains') {
7653: if (srchterm.length < 3) {
7654: checkok = 0;
1.571 raeburn 7655: msg += "$lt{'thet'}\\n";
1.556 raeburn 7656: }
7657: }
7658: if (srchin == 'instd') {
7659: if (srchdomain == '') {
7660: checkok = 0;
1.571 raeburn 7661: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7662: }
7663: }
7664: if (srchin == 'dom') {
7665: if (srchdomain == '') {
7666: checkok = 0;
1.571 raeburn 7667: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7668: }
7669: }
7670: if (srchby == 'lastfirst') {
7671: if (srchterm.indexOf(",") == -1) {
7672: checkok = 0;
1.571 raeburn 7673: msg += "$lt{'whus'}\\n";
1.556 raeburn 7674: }
7675: if (srchterm.indexOf(",") == srchterm.length -1) {
7676: checkok = 0;
1.571 raeburn 7677: msg += "$lt{'whse'}\\n";
1.556 raeburn 7678: }
7679: }
7680: if (checkok == 0) {
1.571 raeburn 7681: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7682: return;
7683: }
7684: if (checkok == 1) {
1.570 raeburn 7685: callingForm.submit();
1.556 raeburn 7686: }
7687: }
7688:
7689: $newuserscript
7690:
1.824 bisitz 7691: // ]]>
1.556 raeburn 7692: </script>
1.558 albertel 7693:
7694: $new_user_create
7695:
1.555 raeburn 7696: END_BLOCK
1.558 albertel 7697:
1.876 raeburn 7698: $output .= &Apache::lonhtmlcommon::start_pick_box().
7699: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7700: $domform.
7701: &Apache::lonhtmlcommon::row_closure().
7702: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7703: $srchbysel.
7704: $srchtypesel.
7705: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7706: $srchinsel.
7707: &Apache::lonhtmlcommon::row_closure(1).
7708: &Apache::lonhtmlcommon::end_pick_box().
7709: '<br />';
1.555 raeburn 7710: return $output;
7711: }
7712:
1.612 raeburn 7713: sub user_rule_check {
1.615 raeburn 7714: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7715: my $response;
7716: if (ref($usershash) eq 'HASH') {
7717: foreach my $user (keys(%{$usershash})) {
7718: my ($uname,$udom) = split(/:/,$user);
7719: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7720: my ($id,$newuser);
1.612 raeburn 7721: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7722: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7723: $id = $usershash->{$user}->{'id'};
7724: }
7725: my $inst_response;
7726: if (ref($checks) eq 'HASH') {
7727: if (defined($checks->{'username'})) {
1.615 raeburn 7728: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7729: &Apache::lonnet::get_instuser($udom,$uname);
7730: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7731: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7732: &Apache::lonnet::get_instuser($udom,undef,$id);
7733: }
1.615 raeburn 7734: } else {
7735: ($inst_response,%{$inst_results->{$user}}) =
7736: &Apache::lonnet::get_instuser($udom,$uname);
7737: return;
1.612 raeburn 7738: }
1.615 raeburn 7739: if (!$got_rules->{$udom}) {
1.612 raeburn 7740: my %domconfig = &Apache::lonnet::get_dom('configuration',
7741: ['usercreation'],$udom);
7742: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7743: foreach my $item ('username','id') {
1.612 raeburn 7744: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7745: $$curr_rules{$udom}{$item} =
7746: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7747: }
7748: }
7749: }
1.615 raeburn 7750: $got_rules->{$udom} = 1;
1.585 raeburn 7751: }
1.612 raeburn 7752: foreach my $item (keys(%{$checks})) {
7753: if (ref($$curr_rules{$udom}) eq 'HASH') {
7754: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7755: if (@{$$curr_rules{$udom}{$item}} > 0) {
7756: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7757: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7758: if ($rule_check{$rule}) {
7759: $$rulematch{$user}{$item} = $rule;
7760: if ($inst_response eq 'ok') {
1.615 raeburn 7761: if (ref($inst_results) eq 'HASH') {
7762: if (ref($inst_results->{$user}) eq 'HASH') {
7763: if (keys(%{$inst_results->{$user}}) == 0) {
7764: $$alerts{$item}{$udom}{$uname} = 1;
7765: }
1.612 raeburn 7766: }
7767: }
1.615 raeburn 7768: }
7769: last;
1.585 raeburn 7770: }
7771: }
7772: }
7773: }
7774: }
7775: }
7776: }
7777: }
1.612 raeburn 7778: return;
7779: }
7780:
7781: sub user_rule_formats {
7782: my ($domain,$domdesc,$curr_rules,$check) = @_;
7783: my %text = (
7784: 'username' => 'Usernames',
7785: 'id' => 'IDs',
7786: );
7787: my $output;
7788: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7789: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7790: if (@{$ruleorder} > 0) {
7791: $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>';
7792: foreach my $rule (@{$ruleorder}) {
7793: if (ref($curr_rules) eq 'ARRAY') {
7794: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7795: if (ref($rules->{$rule}) eq 'HASH') {
7796: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7797: $rules->{$rule}{'desc'}.'</li>';
7798: }
7799: }
7800: }
7801: }
7802: $output .= '</ul>';
7803: }
7804: }
7805: return $output;
7806: }
7807:
7808: sub instrule_disallow_msg {
1.615 raeburn 7809: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7810: my $response;
7811: my %text = (
7812: item => 'username',
7813: items => 'usernames',
7814: match => 'matches',
7815: do => 'does',
7816: action => 'a username',
7817: one => 'one',
7818: );
7819: if ($count > 1) {
7820: $text{'item'} = 'usernames';
7821: $text{'match'} ='match';
7822: $text{'do'} = 'do';
7823: $text{'action'} = 'usernames',
7824: $text{'one'} = 'ones';
7825: }
7826: if ($checkitem eq 'id') {
7827: $text{'items'} = 'IDs';
7828: $text{'item'} = 'ID';
7829: $text{'action'} = 'an ID';
1.615 raeburn 7830: if ($count > 1) {
7831: $text{'item'} = 'IDs';
7832: $text{'action'} = 'IDs';
7833: }
1.612 raeburn 7834: }
1.674 bisitz 7835: $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 7836: if ($mode eq 'upload') {
7837: if ($checkitem eq 'username') {
7838: $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'}.");
7839: } elsif ($checkitem eq 'id') {
1.674 bisitz 7840: $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 7841: }
1.669 raeburn 7842: } elsif ($mode eq 'selfcreate') {
7843: if ($checkitem eq 'id') {
7844: $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.");
7845: }
1.615 raeburn 7846: } else {
7847: if ($checkitem eq 'username') {
7848: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7849: } elsif ($checkitem eq 'id') {
7850: $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.");
7851: }
1.612 raeburn 7852: }
7853: return $response;
1.585 raeburn 7854: }
7855:
1.624 raeburn 7856: sub personal_data_fieldtitles {
7857: my %fieldtitles = &Apache::lonlocal::texthash (
7858: id => 'Student/Employee ID',
7859: permanentemail => 'E-mail address',
7860: lastname => 'Last Name',
7861: firstname => 'First Name',
7862: middlename => 'Middle Name',
7863: generation => 'Generation',
7864: gen => 'Generation',
1.765 raeburn 7865: inststatus => 'Affiliation',
1.624 raeburn 7866: );
7867: return %fieldtitles;
7868: }
7869:
1.642 raeburn 7870: sub sorted_inst_types {
7871: my ($dom) = @_;
7872: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7873: my $othertitle = &mt('All users');
7874: if ($env{'request.course.id'}) {
1.668 raeburn 7875: $othertitle = &mt('Any users');
1.642 raeburn 7876: }
7877: my @types;
7878: if (ref($order) eq 'ARRAY') {
7879: @types = @{$order};
7880: }
7881: if (@types == 0) {
7882: if (ref($usertypes) eq 'HASH') {
7883: @types = sort(keys(%{$usertypes}));
7884: }
7885: }
7886: if (keys(%{$usertypes}) > 0) {
7887: $othertitle = &mt('Other users');
7888: }
7889: return ($othertitle,$usertypes,\@types);
7890: }
7891:
1.645 raeburn 7892: sub get_institutional_codes {
7893: my ($settings,$allcourses,$LC_code) = @_;
7894: # Get complete list of course sections to update
7895: my @currsections = ();
7896: my @currxlists = ();
7897: my $coursecode = $$settings{'internal.coursecode'};
7898:
7899: if ($$settings{'internal.sectionnums'} ne '') {
7900: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7901: }
7902:
7903: if ($$settings{'internal.crosslistings'} ne '') {
7904: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7905: }
7906:
7907: if (@currxlists > 0) {
7908: foreach (@currxlists) {
7909: if (m/^([^:]+):(\w*)$/) {
7910: unless (grep/^$1$/,@{$allcourses}) {
7911: push @{$allcourses},$1;
7912: $$LC_code{$1} = $2;
7913: }
7914: }
7915: }
7916: }
7917:
7918: if (@currsections > 0) {
7919: foreach (@currsections) {
7920: if (m/^(\w+):(\w*)$/) {
7921: my $sec = $coursecode.$1;
7922: my $lc_sec = $2;
7923: unless (grep/^$sec$/,@{$allcourses}) {
7924: push @{$allcourses},$sec;
7925: $$LC_code{$sec} = $lc_sec;
7926: }
7927: }
7928: }
7929: }
7930: return;
7931: }
7932:
1.112 bowersj2 7933: =pod
7934:
1.780 raeburn 7935: =head1 Slot Helpers
7936:
7937: =over 4
7938:
7939: =item * sorted_slots()
7940:
7941: Sorts an array of slot names in order of slot start time (earliest first).
7942:
7943: Inputs:
7944:
7945: =over 4
7946:
7947: slotsarr - Reference to array of unsorted slot names.
7948:
7949: slots - Reference to hash of hash, where outer hash keys are slot names.
7950:
1.549 albertel 7951: =back
7952:
1.780 raeburn 7953: Returns:
7954:
7955: =over 4
7956:
7957: sorted - An array of slot names sorted by the start time of the slot.
7958:
7959: =back
7960:
7961: =back
7962:
7963: =cut
7964:
7965:
7966: sub sorted_slots {
7967: my ($slotsarr,$slots) = @_;
7968: my @sorted;
7969: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7970: @sorted =
7971: sort {
7972: if (ref($slots->{$a}) && ref($slots->{$b})) {
7973: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7974: }
7975: if (ref($slots->{$a})) { return -1;}
7976: if (ref($slots->{$b})) { return 1;}
7977: return 0;
7978: } @{$slotsarr};
7979: }
7980: return @sorted;
7981: }
7982:
7983:
7984: =pod
7985:
1.549 albertel 7986: =head1 HTTP Helpers
7987:
7988: =over 4
7989:
1.648 raeburn 7990: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7991:
1.258 albertel 7992: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7993: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7994: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7995:
7996: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7997: $possible_names is an ref to an array of form element names. As an example:
7998: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7999: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8000:
8001: =cut
1.1 albertel 8002:
1.6 albertel 8003: sub get_unprocessed_cgi {
1.25 albertel 8004: my ($query,$possible_names)= @_;
1.26 matthew 8005: # $Apache::lonxml::debug=1;
1.356 albertel 8006: foreach my $pair (split(/&/,$query)) {
8007: my ($name, $value) = split(/=/,$pair);
1.369 www 8008: $name = &unescape($name);
1.25 albertel 8009: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8010: $value =~ tr/+/ /;
8011: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8012: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8013: }
1.16 harris41 8014: }
1.6 albertel 8015: }
8016:
1.112 bowersj2 8017: =pod
8018:
1.648 raeburn 8019: =item * &cacheheader()
1.112 bowersj2 8020:
8021: returns cache-controlling header code
8022:
8023: =cut
8024:
1.7 albertel 8025: sub cacheheader {
1.258 albertel 8026: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8027: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8028: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8029: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8030: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8031: return $output;
1.7 albertel 8032: }
8033:
1.112 bowersj2 8034: =pod
8035:
1.648 raeburn 8036: =item * &no_cache($r)
1.112 bowersj2 8037:
8038: specifies header code to not have cache
8039:
8040: =cut
8041:
1.9 albertel 8042: sub no_cache {
1.216 albertel 8043: my ($r) = @_;
8044: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8045: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8046: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8047: $r->no_cache(1);
8048: $r->header_out("Expires" => $date);
8049: $r->header_out("Pragma" => "no-cache");
1.123 www 8050: }
8051:
8052: sub content_type {
1.181 albertel 8053: my ($r,$type,$charset) = @_;
1.299 foxr 8054: if ($r) {
8055: # Note that printout.pl calls this with undef for $r.
8056: &no_cache($r);
8057: }
1.258 albertel 8058: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8059: unless ($charset) {
8060: $charset=&Apache::lonlocal::current_encoding;
8061: }
8062: if ($charset) { $type.='; charset='.$charset; }
8063: if ($r) {
8064: $r->content_type($type);
8065: } else {
8066: print("Content-type: $type\n\n");
8067: }
1.9 albertel 8068: }
1.25 albertel 8069:
1.112 bowersj2 8070: =pod
8071:
1.648 raeburn 8072: =item * &add_to_env($name,$value)
1.112 bowersj2 8073:
1.258 albertel 8074: adds $name to the %env hash with value
1.112 bowersj2 8075: $value, if $name already exists, the entry is converted to an array
8076: reference and $value is added to the array.
8077:
8078: =cut
8079:
1.25 albertel 8080: sub add_to_env {
8081: my ($name,$value)=@_;
1.258 albertel 8082: if (defined($env{$name})) {
8083: if (ref($env{$name})) {
1.25 albertel 8084: #already have multiple values
1.258 albertel 8085: push(@{ $env{$name} },$value);
1.25 albertel 8086: } else {
8087: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8088: my $first=$env{$name};
8089: undef($env{$name});
8090: push(@{ $env{$name} },$first,$value);
1.25 albertel 8091: }
8092: } else {
1.258 albertel 8093: $env{$name}=$value;
1.25 albertel 8094: }
1.31 albertel 8095: }
1.149 albertel 8096:
8097: =pod
8098:
1.648 raeburn 8099: =item * &get_env_multiple($name)
1.149 albertel 8100:
1.258 albertel 8101: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8102: values may be defined and end up as an array ref.
8103:
8104: returns an array of values
8105:
8106: =cut
8107:
8108: sub get_env_multiple {
8109: my ($name) = @_;
8110: my @values;
1.258 albertel 8111: if (defined($env{$name})) {
1.149 albertel 8112: # exists is it an array
1.258 albertel 8113: if (ref($env{$name})) {
8114: @values=@{ $env{$name} };
1.149 albertel 8115: } else {
1.258 albertel 8116: $values[0]=$env{$name};
1.149 albertel 8117: }
8118: }
8119: return(@values);
8120: }
8121:
1.660 raeburn 8122: sub ask_for_embedded_content {
8123: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8124: my $upload_output = '
8125: <form name="upload_embedded" action="'.$actionurl.'"
8126: method="post" enctype="multipart/form-data">';
8127: $upload_output .= $state;
1.661 raeburn 8128: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8129:
8130: my $num = 0;
8131: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8132: $upload_output .= &start_data_table_row().
8133: '<td>'.$embed_file.'</td><td>';
8134: if ($args->{'ignore_remote_references'}
8135: && $embed_file =~ m{^\w+://}) {
8136: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8137: } elsif ($args->{'error_on_invalid_names'}
8138: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8139:
8140: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8141:
8142: } else {
8143: $upload_output .='
1.661 raeburn 8144: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8145: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8146: my $attrib = join(':',@{$$allfiles{$embed_file}});
8147: $upload_output .=
8148: "\n\t\t".
8149: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8150: $attrib.'" />';
8151: if (exists($$codebase{$embed_file})) {
8152: $upload_output .=
8153: "\n\t\t".
8154: '<input name="codebase_'.$num.'" type="hidden" value="'.
8155: &escape($$codebase{$embed_file}).'" />';
8156: }
8157: }
8158: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8159: $num++;
8160: }
8161: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8162: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8163: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8164: '.&mt('(only files for which a location has been provided will be uploaded)').'
8165: </form>';
8166: return $upload_output;
8167: }
8168:
1.661 raeburn 8169: sub upload_embedded {
8170: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8171: $current_disk_usage) = @_;
8172: my $output;
8173: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8174: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8175: my $orig_uploaded_filename =
8176: $env{'form.embedded_item_'.$i.'.filename'};
8177:
8178: $env{'form.embedded_orig_'.$i} =
8179: &unescape($env{'form.embedded_orig_'.$i});
8180: my ($path,$fname) =
8181: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8182: # no path, whole string is fname
8183: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8184:
8185: $path = $env{'form.currentpath'}.$path;
8186: $fname = &Apache::lonnet::clean_filename($fname);
8187: # See if there is anything left
8188: next if ($fname eq '');
8189:
8190: # Check if file already exists as a file or directory.
8191: my ($state,$msg);
8192: if ($context eq 'portfolio') {
8193: my $port_path = $dirpath;
8194: if ($group ne '') {
8195: $port_path = "groups/$group/$port_path";
8196: }
8197: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8198: $dir_root,$port_path,$disk_quota,
8199: $current_disk_usage,$uname,$udom);
8200: if ($state eq 'will_exceed_quota'
8201: || $state eq 'file_locked'
8202: || $state eq 'file_exists' ) {
8203: $output .= $msg;
8204: next;
8205: }
8206: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8207: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8208: if ($state eq 'exists') {
8209: $output .= $msg;
8210: next;
8211: }
8212: }
8213: # Check if extension is valid
8214: if (($fname =~ /\.(\w+)$/) &&
8215: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8216: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8217: next;
8218: } elsif (($fname =~ /\.(\w+)$/) &&
8219: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8220: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8221: next;
8222: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8223: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8224: next;
8225: }
8226:
8227: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8228: if ($context eq 'portfolio') {
8229: my $result=
8230: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8231: $dirpath.$path);
8232: if ($result !~ m|^/uploaded/|) {
8233: $output .= '<span class="LC_error">'
8234: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8235: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8236: .'</span><br />';
8237: next;
8238: } else {
8239: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8240: $path.$fname.'</span>').'</p>';
8241: }
8242: } else {
8243: # Save the file
8244: my $target = $env{'form.embedded_item_'.$i};
8245: my $fullpath = $dir_root.$dirpath.'/'.$path;
8246: my $dest = $fullpath.$fname;
8247: my $url = $url_root.$dirpath.'/'.$path.$fname;
8248: my @parts=split(/\//,$fullpath);
8249: my $count;
8250: my $filepath = $dir_root;
8251: for ($count=4;$count<=$#parts;$count++) {
8252: $filepath .= "/$parts[$count]";
8253: if ((-e $filepath)!=1) {
8254: mkdir($filepath,0770);
8255: }
8256: }
8257: my $fh;
8258: if (!open($fh,'>'.$dest)) {
8259: &Apache::lonnet::logthis('Failed to create '.$dest);
8260: $output .= '<span class="LC_error">'.
8261: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8262: '</span><br />';
8263: } else {
8264: if (!print $fh $env{'form.embedded_item_'.$i}) {
8265: &Apache::lonnet::logthis('Failed to write to '.$dest);
8266: $output .= '<span class="LC_error">'.
8267: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8268: '</span><br />';
8269: } else {
8270: if ($context eq 'testbank') {
8271: $output .= &mt('Embedded file uploaded successfully:').
8272: ' <a href="'.$url.'">'.
8273: $orig_uploaded_filename.'</a><br />';
8274: } else {
1.705 tempelho 8275: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8276: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8277: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8278: }
8279: }
8280: close($fh);
8281: }
8282: }
8283: }
8284: return $output;
8285: }
8286:
8287: sub check_for_existing {
8288: my ($path,$fname,$element) = @_;
8289: my ($state,$msg);
8290: if (-d $path.'/'.$fname) {
8291: $state = 'exists';
8292: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8293: } elsif (-e $path.'/'.$fname) {
8294: $state = 'exists';
8295: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8296: }
8297: if ($state eq 'exists') {
8298: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8299: }
8300: return ($state,$msg);
8301: }
8302:
8303: sub check_for_upload {
8304: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8305: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8306: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8307: my $getpropath = 1;
8308: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8309: $getpropath);
8310: my $found_file = 0;
8311: my $locked_file = 0;
8312: foreach my $line (@dir_list) {
8313: my ($file_name)=split(/\&/,$line,2);
8314: if ($file_name eq $fname){
8315: $file_name = $path.$file_name;
8316: if ($group ne '') {
8317: $file_name = $group.$file_name;
8318: }
8319: $found_file = 1;
8320: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8321: $locked_file = 1;
8322: }
8323: }
8324: }
8325: if (($current_disk_usage + $filesize) > $disk_quota){
8326: my $msg = '<span class="LC_error">'.
8327: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8328: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8329: return ('will_exceed_quota',$msg);
8330: } elsif ($found_file) {
8331: if ($locked_file) {
8332: my $msg = '<span class="LC_error">';
8333: $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>');
8334: $msg .= '</span><br />';
8335: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8336: return ('file_locked',$msg);
8337: } else {
8338: my $msg = '<span class="LC_error">';
8339: $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'});
8340: $msg .= '</span>';
8341: $msg .= '<br />';
8342: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8343: return ('file_exists',$msg);
8344: }
8345: }
8346: }
8347:
1.31 albertel 8348:
1.41 ng 8349: =pod
1.45 matthew 8350:
1.464 albertel 8351: =back
1.41 ng 8352:
1.112 bowersj2 8353: =head1 CSV Upload/Handling functions
1.38 albertel 8354:
1.41 ng 8355: =over 4
8356:
1.648 raeburn 8357: =item * &upfile_store($r)
1.41 ng 8358:
8359: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8360: needs $env{'form.upfile'}
1.41 ng 8361: returns $datatoken to be put into hidden field
8362:
8363: =cut
1.31 albertel 8364:
8365: sub upfile_store {
8366: my $r=shift;
1.258 albertel 8367: $env{'form.upfile'}=~s/\r/\n/gs;
8368: $env{'form.upfile'}=~s/\f/\n/gs;
8369: $env{'form.upfile'}=~s/\n+/\n/gs;
8370: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8371:
1.258 albertel 8372: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8373: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8374: {
1.158 raeburn 8375: my $datafile = $r->dir_config('lonDaemons').
8376: '/tmp/'.$datatoken.'.tmp';
8377: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8378: print $fh $env{'form.upfile'};
1.158 raeburn 8379: close($fh);
8380: }
1.31 albertel 8381: }
8382: return $datatoken;
8383: }
8384:
1.56 matthew 8385: =pod
8386:
1.648 raeburn 8387: =item * &load_tmp_file($r)
1.41 ng 8388:
8389: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8390: needs $env{'form.datatoken'},
8391: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8392:
8393: =cut
1.31 albertel 8394:
8395: sub load_tmp_file {
8396: my $r=shift;
8397: my @studentdata=();
8398: {
1.158 raeburn 8399: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8400: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8401: if ( open(my $fh,"<$studentfile") ) {
8402: @studentdata=<$fh>;
8403: close($fh);
8404: }
1.31 albertel 8405: }
1.258 albertel 8406: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8407: }
8408:
1.56 matthew 8409: =pod
8410:
1.648 raeburn 8411: =item * &upfile_record_sep()
1.41 ng 8412:
8413: Separate uploaded file into records
8414: returns array of records,
1.258 albertel 8415: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8416:
8417: =cut
1.31 albertel 8418:
8419: sub upfile_record_sep {
1.258 albertel 8420: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8421: } else {
1.248 albertel 8422: my @records;
1.258 albertel 8423: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8424: if ($line=~/^\s*$/) { next; }
8425: push(@records,$line);
8426: }
8427: return @records;
1.31 albertel 8428: }
8429: }
8430:
1.56 matthew 8431: =pod
8432:
1.648 raeburn 8433: =item * &record_sep($record)
1.41 ng 8434:
1.258 albertel 8435: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8436:
8437: =cut
8438:
1.263 www 8439: sub takeleft {
8440: my $index=shift;
8441: return substr('0000'.$index,-4,4);
8442: }
8443:
1.31 albertel 8444: sub record_sep {
8445: my $record=shift;
8446: my %components=();
1.258 albertel 8447: if ($env{'form.upfiletype'} eq 'xml') {
8448: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8449: my $i=0;
1.356 albertel 8450: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8451: $field=~s/^(\"|\')//;
8452: $field=~s/(\"|\')$//;
1.263 www 8453: $components{&takeleft($i)}=$field;
1.31 albertel 8454: $i++;
8455: }
1.258 albertel 8456: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8457: my $i=0;
1.356 albertel 8458: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8459: $field=~s/^(\"|\')//;
8460: $field=~s/(\"|\')$//;
1.263 www 8461: $components{&takeleft($i)}=$field;
1.31 albertel 8462: $i++;
8463: }
8464: } else {
1.561 www 8465: my $separator=',';
1.480 banghart 8466: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8467: $separator=';';
1.480 banghart 8468: }
1.31 albertel 8469: my $i=0;
1.561 www 8470: # the character we are looking for to indicate the end of a quote or a record
8471: my $looking_for=$separator;
8472: # do not add the characters to the fields
8473: my $ignore=0;
8474: # we just encountered a separator (or the beginning of the record)
8475: my $just_found_separator=1;
8476: # store the field we are working on here
8477: my $field='';
8478: # work our way through all characters in record
8479: foreach my $character ($record=~/(.)/g) {
8480: if ($character eq $looking_for) {
8481: if ($character ne $separator) {
8482: # Found the end of a quote, again looking for separator
8483: $looking_for=$separator;
8484: $ignore=1;
8485: } else {
8486: # Found a separator, store away what we got
8487: $components{&takeleft($i)}=$field;
8488: $i++;
8489: $just_found_separator=1;
8490: $ignore=0;
8491: $field='';
8492: }
8493: next;
8494: }
8495: # single or double quotation marks after a separator indicate beginning of a quote
8496: # we are now looking for the end of the quote and need to ignore separators
8497: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8498: $looking_for=$character;
8499: next;
8500: }
8501: # ignore would be true after we reached the end of a quote
8502: if ($ignore) { next; }
8503: if (($just_found_separator) && ($character=~/\s/)) { next; }
8504: $field.=$character;
8505: $just_found_separator=0;
1.31 albertel 8506: }
1.561 www 8507: # catch the very last entry, since we never encountered the separator
8508: $components{&takeleft($i)}=$field;
1.31 albertel 8509: }
8510: return %components;
8511: }
8512:
1.144 matthew 8513: ######################################################
8514: ######################################################
8515:
1.56 matthew 8516: =pod
8517:
1.648 raeburn 8518: =item * &upfile_select_html()
1.41 ng 8519:
1.144 matthew 8520: Return HTML code to select a file from the users machine and specify
8521: the file type.
1.41 ng 8522:
8523: =cut
8524:
1.144 matthew 8525: ######################################################
8526: ######################################################
1.31 albertel 8527: sub upfile_select_html {
1.144 matthew 8528: my %Types = (
8529: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8530: semisv => &mt('Semicolon separated values'),
1.144 matthew 8531: space => &mt('Space separated'),
8532: tab => &mt('Tabulator separated'),
8533: # xml => &mt('HTML/XML'),
8534: );
8535: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8536: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8537: foreach my $type (sort(keys(%Types))) {
8538: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8539: }
8540: $Str .= "</select>\n";
8541: return $Str;
1.31 albertel 8542: }
8543:
1.301 albertel 8544: sub get_samples {
8545: my ($records,$toget) = @_;
8546: my @samples=({});
8547: my $got=0;
8548: foreach my $rec (@$records) {
8549: my %temp = &record_sep($rec);
8550: if (! grep(/\S/, values(%temp))) { next; }
8551: if (%temp) {
8552: $samples[$got]=\%temp;
8553: $got++;
8554: if ($got == $toget) { last; }
8555: }
8556: }
8557: return \@samples;
8558: }
8559:
1.144 matthew 8560: ######################################################
8561: ######################################################
8562:
1.56 matthew 8563: =pod
8564:
1.648 raeburn 8565: =item * &csv_print_samples($r,$records)
1.41 ng 8566:
8567: Prints a table of sample values from each column uploaded $r is an
8568: Apache Request ref, $records is an arrayref from
8569: &Apache::loncommon::upfile_record_sep
8570:
8571: =cut
8572:
1.144 matthew 8573: ######################################################
8574: ######################################################
1.31 albertel 8575: sub csv_print_samples {
8576: my ($r,$records) = @_;
1.662 bisitz 8577: my $samples = &get_samples($records,5);
1.301 albertel 8578:
1.594 raeburn 8579: $r->print(&mt('Samples').'<br />'.&start_data_table().
8580: &start_data_table_header_row());
1.356 albertel 8581: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8582: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8583: $r->print(&end_data_table_header_row());
1.301 albertel 8584: foreach my $hash (@$samples) {
1.594 raeburn 8585: $r->print(&start_data_table_row());
1.356 albertel 8586: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8587: $r->print('<td>');
1.356 albertel 8588: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8589: $r->print('</td>');
8590: }
1.594 raeburn 8591: $r->print(&end_data_table_row());
1.31 albertel 8592: }
1.594 raeburn 8593: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8594: }
8595:
1.144 matthew 8596: ######################################################
8597: ######################################################
8598:
1.56 matthew 8599: =pod
8600:
1.648 raeburn 8601: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8602:
8603: Prints a table to create associations between values and table columns.
1.144 matthew 8604:
1.41 ng 8605: $r is an Apache Request ref,
8606: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8607: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8608:
8609: =cut
8610:
1.144 matthew 8611: ######################################################
8612: ######################################################
1.31 albertel 8613: sub csv_print_select_table {
8614: my ($r,$records,$d) = @_;
1.301 albertel 8615: my $i=0;
8616: my $samples = &get_samples($records,1);
1.144 matthew 8617: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8618: &start_data_table().&start_data_table_header_row().
1.144 matthew 8619: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8620: '<th>'.&mt('Column').'</th>'.
8621: &end_data_table_header_row()."\n");
1.356 albertel 8622: foreach my $array_ref (@$d) {
8623: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8624: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8625:
1.875 bisitz 8626: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8627: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8628: $r->print('<option value="none"></option>');
1.356 albertel 8629: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8630: $r->print('<option value="'.$sample.'"'.
8631: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8632: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8633: }
1.594 raeburn 8634: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8635: $i++;
8636: }
1.594 raeburn 8637: $r->print(&end_data_table());
1.31 albertel 8638: $i--;
8639: return $i;
8640: }
1.56 matthew 8641:
1.144 matthew 8642: ######################################################
8643: ######################################################
8644:
1.56 matthew 8645: =pod
1.31 albertel 8646:
1.648 raeburn 8647: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8648:
8649: Prints a table of sample values from the upload and can make associate samples to internal names.
8650:
8651: $r is an Apache Request ref,
8652: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8653: $d is an array of 2 element arrays (internal name, displayed name)
8654:
8655: =cut
8656:
1.144 matthew 8657: ######################################################
8658: ######################################################
1.31 albertel 8659: sub csv_samples_select_table {
8660: my ($r,$records,$d) = @_;
8661: my $i=0;
1.144 matthew 8662: #
1.662 bisitz 8663: my $max_samples = 5;
8664: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8665: $r->print(&start_data_table().
8666: &start_data_table_header_row().'<th>'.
8667: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8668: &end_data_table_header_row());
1.301 albertel 8669:
8670: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8671: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8672: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8673: foreach my $option (@$d) {
8674: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8675: $r->print('<option value="'.$value.'"'.
1.253 albertel 8676: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8677: $display.'</option>');
1.31 albertel 8678: }
8679: $r->print('</select></td><td>');
1.662 bisitz 8680: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8681: if (defined($samples->[$line]{$key})) {
8682: $r->print($samples->[$line]{$key}."<br />\n");
8683: }
8684: }
1.594 raeburn 8685: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8686: $i++;
8687: }
1.594 raeburn 8688: $r->print(&end_data_table());
1.31 albertel 8689: $i--;
8690: return($i);
1.115 matthew 8691: }
8692:
1.144 matthew 8693: ######################################################
8694: ######################################################
8695:
1.115 matthew 8696: =pod
8697:
1.648 raeburn 8698: =item * &clean_excel_name($name)
1.115 matthew 8699:
8700: Returns a replacement for $name which does not contain any illegal characters.
8701:
8702: =cut
8703:
1.144 matthew 8704: ######################################################
8705: ######################################################
1.115 matthew 8706: sub clean_excel_name {
8707: my ($name) = @_;
8708: $name =~ s/[:\*\?\/\\]//g;
8709: if (length($name) > 31) {
8710: $name = substr($name,0,31);
8711: }
8712: return $name;
1.25 albertel 8713: }
1.84 albertel 8714:
1.85 albertel 8715: =pod
8716:
1.648 raeburn 8717: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8718:
8719: Returns either 1 or undef
8720:
8721: 1 if the part is to be hidden, undef if it is to be shown
8722:
8723: Arguments are:
8724:
8725: $id the id of the part to be checked
8726: $symb, optional the symb of the resource to check
8727: $udom, optional the domain of the user to check for
8728: $uname, optional the username of the user to check for
8729:
8730: =cut
1.84 albertel 8731:
8732: sub check_if_partid_hidden {
8733: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8734: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8735: $symb,$udom,$uname);
1.141 albertel 8736: my $truth=1;
8737: #if the string starts with !, then the list is the list to show not hide
8738: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8739: my @hiddenlist=split(/,/,$hiddenparts);
8740: foreach my $checkid (@hiddenlist) {
1.141 albertel 8741: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8742: }
1.141 albertel 8743: return !$truth;
1.84 albertel 8744: }
1.127 matthew 8745:
1.138 matthew 8746:
8747: ############################################################
8748: ############################################################
8749:
8750: =pod
8751:
1.157 matthew 8752: =back
8753:
1.138 matthew 8754: =head1 cgi-bin script and graphing routines
8755:
1.157 matthew 8756: =over 4
8757:
1.648 raeburn 8758: =item * &get_cgi_id()
1.138 matthew 8759:
8760: Inputs: none
8761:
8762: Returns an id which can be used to pass environment variables
8763: to various cgi-bin scripts. These environment variables will
8764: be removed from the users environment after a given time by
8765: the routine &Apache::lonnet::transfer_profile_to_env.
8766:
8767: =cut
8768:
8769: ############################################################
8770: ############################################################
1.152 albertel 8771: my $uniq=0;
1.136 matthew 8772: sub get_cgi_id {
1.154 albertel 8773: $uniq=($uniq+1)%100000;
1.280 albertel 8774: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8775: }
8776:
1.127 matthew 8777: ############################################################
8778: ############################################################
8779:
8780: =pod
8781:
1.648 raeburn 8782: =item * &DrawBarGraph()
1.127 matthew 8783:
1.138 matthew 8784: Facilitates the plotting of data in a (stacked) bar graph.
8785: Puts plot definition data into the users environment in order for
8786: graph.png to plot it. Returns an <img> tag for the plot.
8787: The bars on the plot are labeled '1','2',...,'n'.
8788:
8789: Inputs:
8790:
8791: =over 4
8792:
8793: =item $Title: string, the title of the plot
8794:
8795: =item $xlabel: string, text describing the X-axis of the plot
8796:
8797: =item $ylabel: string, text describing the Y-axis of the plot
8798:
8799: =item $Max: scalar, the maximum Y value to use in the plot
8800: If $Max is < any data point, the graph will not be rendered.
8801:
1.140 matthew 8802: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8803: they are plotted. If undefined, default values will be used.
8804:
1.178 matthew 8805: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8806:
1.138 matthew 8807: =item @Values: An array of array references. Each array reference holds data
8808: to be plotted in a stacked bar chart.
8809:
1.239 matthew 8810: =item If the final element of @Values is a hash reference the key/value
8811: pairs will be added to the graph definition.
8812:
1.138 matthew 8813: =back
8814:
8815: Returns:
8816:
8817: An <img> tag which references graph.png and the appropriate identifying
8818: information for the plot.
8819:
1.127 matthew 8820: =cut
8821:
8822: ############################################################
8823: ############################################################
1.134 matthew 8824: sub DrawBarGraph {
1.178 matthew 8825: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8826: #
8827: if (! defined($colors)) {
8828: $colors = ['#33ff00',
8829: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8830: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8831: ];
8832: }
1.228 matthew 8833: my $extra_settings = {};
8834: if (ref($Values[-1]) eq 'HASH') {
8835: $extra_settings = pop(@Values);
8836: }
1.127 matthew 8837: #
1.136 matthew 8838: my $identifier = &get_cgi_id();
8839: my $id = 'cgi.'.$identifier;
1.129 matthew 8840: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8841: return '';
8842: }
1.225 matthew 8843: #
8844: my @Labels;
8845: if (defined($labels)) {
8846: @Labels = @$labels;
8847: } else {
8848: for (my $i=0;$i<@{$Values[0]};$i++) {
8849: push (@Labels,$i+1);
8850: }
8851: }
8852: #
1.129 matthew 8853: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8854: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8855: my %ValuesHash;
8856: my $NumSets=1;
8857: foreach my $array (@Values) {
8858: next if (! ref($array));
1.136 matthew 8859: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8860: join(',',@$array);
1.129 matthew 8861: }
1.127 matthew 8862: #
1.136 matthew 8863: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8864: if ($NumBars < 3) {
8865: $width = 120+$NumBars*32;
1.220 matthew 8866: $xskip = 1;
1.225 matthew 8867: $bar_width = 30;
8868: } elsif ($NumBars < 5) {
8869: $width = 120+$NumBars*20;
8870: $xskip = 1;
8871: $bar_width = 20;
1.220 matthew 8872: } elsif ($NumBars < 10) {
1.136 matthew 8873: $width = 120+$NumBars*15;
8874: $xskip = 1;
8875: $bar_width = 15;
8876: } elsif ($NumBars <= 25) {
8877: $width = 120+$NumBars*11;
8878: $xskip = 5;
8879: $bar_width = 8;
8880: } elsif ($NumBars <= 50) {
8881: $width = 120+$NumBars*8;
8882: $xskip = 5;
8883: $bar_width = 4;
8884: } else {
8885: $width = 120+$NumBars*8;
8886: $xskip = 5;
8887: $bar_width = 4;
8888: }
8889: #
1.137 matthew 8890: $Max = 1 if ($Max < 1);
8891: if ( int($Max) < $Max ) {
8892: $Max++;
8893: $Max = int($Max);
8894: }
1.127 matthew 8895: $Title = '' if (! defined($Title));
8896: $xlabel = '' if (! defined($xlabel));
8897: $ylabel = '' if (! defined($ylabel));
1.369 www 8898: $ValuesHash{$id.'.title'} = &escape($Title);
8899: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8900: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8901: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8902: $ValuesHash{$id.'.NumBars'} = $NumBars;
8903: $ValuesHash{$id.'.NumSets'} = $NumSets;
8904: $ValuesHash{$id.'.PlotType'} = 'bar';
8905: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8906: $ValuesHash{$id.'.height'} = $height;
8907: $ValuesHash{$id.'.width'} = $width;
8908: $ValuesHash{$id.'.xskip'} = $xskip;
8909: $ValuesHash{$id.'.bar_width'} = $bar_width;
8910: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8911: #
1.228 matthew 8912: # Deal with other parameters
8913: while (my ($key,$value) = each(%$extra_settings)) {
8914: $ValuesHash{$id.'.'.$key} = $value;
8915: }
8916: #
1.646 raeburn 8917: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8918: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8919: }
8920:
8921: ############################################################
8922: ############################################################
8923:
8924: =pod
8925:
1.648 raeburn 8926: =item * &DrawXYGraph()
1.137 matthew 8927:
1.138 matthew 8928: Facilitates the plotting of data in an XY graph.
8929: Puts plot definition data into the users environment in order for
8930: graph.png to plot it. Returns an <img> tag for the plot.
8931:
8932: Inputs:
8933:
8934: =over 4
8935:
8936: =item $Title: string, the title of the plot
8937:
8938: =item $xlabel: string, text describing the X-axis of the plot
8939:
8940: =item $ylabel: string, text describing the Y-axis of the plot
8941:
8942: =item $Max: scalar, the maximum Y value to use in the plot
8943: If $Max is < any data point, the graph will not be rendered.
8944:
8945: =item $colors: Array ref containing the hex color codes for the data to be
8946: plotted in. If undefined, default values will be used.
8947:
8948: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8949:
8950: =item $Ydata: Array ref containing Array refs.
1.185 www 8951: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8952:
8953: =item %Values: hash indicating or overriding any default values which are
8954: passed to graph.png.
8955: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8956:
8957: =back
8958:
8959: Returns:
8960:
8961: An <img> tag which references graph.png and the appropriate identifying
8962: information for the plot.
8963:
1.137 matthew 8964: =cut
8965:
8966: ############################################################
8967: ############################################################
8968: sub DrawXYGraph {
8969: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8970: #
8971: # Create the identifier for the graph
8972: my $identifier = &get_cgi_id();
8973: my $id = 'cgi.'.$identifier;
8974: #
8975: $Title = '' if (! defined($Title));
8976: $xlabel = '' if (! defined($xlabel));
8977: $ylabel = '' if (! defined($ylabel));
8978: my %ValuesHash =
8979: (
1.369 www 8980: $id.'.title' => &escape($Title),
8981: $id.'.xlabel' => &escape($xlabel),
8982: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8983: $id.'.y_max_value'=> $Max,
8984: $id.'.labels' => join(',',@$Xlabels),
8985: $id.'.PlotType' => 'XY',
8986: );
8987: #
8988: if (defined($colors) && ref($colors) eq 'ARRAY') {
8989: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8990: }
8991: #
8992: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8993: return '';
8994: }
8995: my $NumSets=1;
1.138 matthew 8996: foreach my $array (@{$Ydata}){
1.137 matthew 8997: next if (! ref($array));
8998: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8999: }
1.138 matthew 9000: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9001: #
9002: # Deal with other parameters
9003: while (my ($key,$value) = each(%Values)) {
9004: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9005: }
9006: #
1.646 raeburn 9007: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9008: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9009: }
9010:
9011: ############################################################
9012: ############################################################
9013:
9014: =pod
9015:
1.648 raeburn 9016: =item * &DrawXYYGraph()
1.138 matthew 9017:
9018: Facilitates the plotting of data in an XY graph with two Y axes.
9019: Puts plot definition data into the users environment in order for
9020: graph.png to plot it. Returns an <img> tag for the plot.
9021:
9022: Inputs:
9023:
9024: =over 4
9025:
9026: =item $Title: string, the title of the plot
9027:
9028: =item $xlabel: string, text describing the X-axis of the plot
9029:
9030: =item $ylabel: string, text describing the Y-axis of the plot
9031:
9032: =item $colors: Array ref containing the hex color codes for the data to be
9033: plotted in. If undefined, default values will be used.
9034:
9035: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9036:
9037: =item $Ydata1: The first data set
9038:
9039: =item $Min1: The minimum value of the left Y-axis
9040:
9041: =item $Max1: The maximum value of the left Y-axis
9042:
9043: =item $Ydata2: The second data set
9044:
9045: =item $Min2: The minimum value of the right Y-axis
9046:
9047: =item $Max2: The maximum value of the left Y-axis
9048:
9049: =item %Values: hash indicating or overriding any default values which are
9050: passed to graph.png.
9051: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9052:
9053: =back
9054:
9055: Returns:
9056:
9057: An <img> tag which references graph.png and the appropriate identifying
9058: information for the plot.
1.136 matthew 9059:
9060: =cut
9061:
9062: ############################################################
9063: ############################################################
1.137 matthew 9064: sub DrawXYYGraph {
9065: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9066: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9067: #
9068: # Create the identifier for the graph
9069: my $identifier = &get_cgi_id();
9070: my $id = 'cgi.'.$identifier;
9071: #
9072: $Title = '' if (! defined($Title));
9073: $xlabel = '' if (! defined($xlabel));
9074: $ylabel = '' if (! defined($ylabel));
9075: my %ValuesHash =
9076: (
1.369 www 9077: $id.'.title' => &escape($Title),
9078: $id.'.xlabel' => &escape($xlabel),
9079: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9080: $id.'.labels' => join(',',@$Xlabels),
9081: $id.'.PlotType' => 'XY',
9082: $id.'.NumSets' => 2,
1.137 matthew 9083: $id.'.two_axes' => 1,
9084: $id.'.y1_max_value' => $Max1,
9085: $id.'.y1_min_value' => $Min1,
9086: $id.'.y2_max_value' => $Max2,
9087: $id.'.y2_min_value' => $Min2,
1.136 matthew 9088: );
9089: #
1.137 matthew 9090: if (defined($colors) && ref($colors) eq 'ARRAY') {
9091: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9092: }
9093: #
9094: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9095: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9096: return '';
9097: }
9098: my $NumSets=1;
1.137 matthew 9099: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9100: next if (! ref($array));
9101: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9102: }
9103: #
9104: # Deal with other parameters
9105: while (my ($key,$value) = each(%Values)) {
9106: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9107: }
9108: #
1.646 raeburn 9109: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9110: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9111: }
9112:
9113: ############################################################
9114: ############################################################
9115:
9116: =pod
9117:
1.157 matthew 9118: =back
9119:
1.139 matthew 9120: =head1 Statistics helper routines?
9121:
9122: Bad place for them but what the hell.
9123:
1.157 matthew 9124: =over 4
9125:
1.648 raeburn 9126: =item * &chartlink()
1.139 matthew 9127:
9128: Returns a link to the chart for a specific student.
9129:
9130: Inputs:
9131:
9132: =over 4
9133:
9134: =item $linktext: The text of the link
9135:
9136: =item $sname: The students username
9137:
9138: =item $sdomain: The students domain
9139:
9140: =back
9141:
1.157 matthew 9142: =back
9143:
1.139 matthew 9144: =cut
9145:
9146: ############################################################
9147: ############################################################
9148: sub chartlink {
9149: my ($linktext, $sname, $sdomain) = @_;
9150: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9151: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9152: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9153: '">'.$linktext.'</a>';
1.153 matthew 9154: }
9155:
9156: #######################################################
9157: #######################################################
9158:
9159: =pod
9160:
9161: =head1 Course Environment Routines
1.157 matthew 9162:
9163: =over 4
1.153 matthew 9164:
1.648 raeburn 9165: =item * &restore_course_settings()
1.153 matthew 9166:
1.648 raeburn 9167: =item * &store_course_settings()
1.153 matthew 9168:
9169: Restores/Store indicated form parameters from the course environment.
9170: Will not overwrite existing values of the form parameters.
9171:
9172: Inputs:
9173: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9174:
9175: a hash ref describing the data to be stored. For example:
9176:
9177: %Save_Parameters = ('Status' => 'scalar',
9178: 'chartoutputmode' => 'scalar',
9179: 'chartoutputdata' => 'scalar',
9180: 'Section' => 'array',
1.373 raeburn 9181: 'Group' => 'array',
1.153 matthew 9182: 'StudentData' => 'array',
9183: 'Maps' => 'array');
9184:
9185: Returns: both routines return nothing
9186:
1.631 raeburn 9187: =back
9188:
1.153 matthew 9189: =cut
9190:
9191: #######################################################
9192: #######################################################
9193: sub store_course_settings {
1.496 albertel 9194: return &store_settings($env{'request.course.id'},@_);
9195: }
9196:
9197: sub store_settings {
1.153 matthew 9198: # save to the environment
9199: # appenv the same items, just to be safe
1.300 albertel 9200: my $udom = $env{'user.domain'};
9201: my $uname = $env{'user.name'};
1.496 albertel 9202: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9203: my %SaveHash;
9204: my %AppHash;
9205: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9206: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9207: my $envname = 'environment.'.$basename;
1.258 albertel 9208: if (exists($env{'form.'.$setting})) {
1.153 matthew 9209: # Save this value away
9210: if ($type eq 'scalar' &&
1.258 albertel 9211: (! exists($env{$envname}) ||
9212: $env{$envname} ne $env{'form.'.$setting})) {
9213: $SaveHash{$basename} = $env{'form.'.$setting};
9214: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9215: } elsif ($type eq 'array') {
9216: my $stored_form;
1.258 albertel 9217: if (ref($env{'form.'.$setting})) {
1.153 matthew 9218: $stored_form = join(',',
9219: map {
1.369 www 9220: &escape($_);
1.258 albertel 9221: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9222: } else {
9223: $stored_form =
1.369 www 9224: &escape($env{'form.'.$setting});
1.153 matthew 9225: }
9226: # Determine if the array contents are the same.
1.258 albertel 9227: if ($stored_form ne $env{$envname}) {
1.153 matthew 9228: $SaveHash{$basename} = $stored_form;
9229: $AppHash{$envname} = $stored_form;
9230: }
9231: }
9232: }
9233: }
9234: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9235: $udom,$uname);
1.153 matthew 9236: if ($put_result !~ /^(ok|delayed)/) {
9237: &Apache::lonnet::logthis('unable to save form parameters, '.
9238: 'got error:'.$put_result);
9239: }
9240: # Make sure these settings stick around in this session, too
1.646 raeburn 9241: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9242: return;
9243: }
9244:
9245: sub restore_course_settings {
1.499 albertel 9246: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9247: }
9248:
9249: sub restore_settings {
9250: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9251: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9252: next if (exists($env{'form.'.$setting}));
1.496 albertel 9253: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9254: '.'.$setting;
1.258 albertel 9255: if (exists($env{$envname})) {
1.153 matthew 9256: if ($type eq 'scalar') {
1.258 albertel 9257: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9258: } elsif ($type eq 'array') {
1.258 albertel 9259: $env{'form.'.$setting} = [
1.153 matthew 9260: map {
1.369 www 9261: &unescape($_);
1.258 albertel 9262: } split(',',$env{$envname})
1.153 matthew 9263: ];
9264: }
9265: }
9266: }
1.127 matthew 9267: }
9268:
1.618 raeburn 9269: #######################################################
9270: #######################################################
9271:
9272: =pod
9273:
9274: =head1 Domain E-mail Routines
9275:
9276: =over 4
9277:
1.648 raeburn 9278: =item * &build_recipient_list()
1.618 raeburn 9279:
1.766 raeburn 9280: Build recipient lists for four types of e-mail:
9281: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9282: (d) Help requests, generated by
9283: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9284:
9285: Inputs:
1.619 raeburn 9286: defmail (scalar - email address of default recipient),
1.618 raeburn 9287: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9288: defdom (domain for which to retrieve configuration settings),
9289: origmail (scalar - email address of recipient from loncapa.conf,
9290: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9291:
1.655 raeburn 9292: Returns: comma separated list of addresses to which to send e-mail.
9293:
9294: =back
1.618 raeburn 9295:
9296: =cut
9297:
9298: ############################################################
9299: ############################################################
9300: sub build_recipient_list {
1.619 raeburn 9301: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9302: my @recipients;
9303: my $otheremails;
9304: my %domconfig =
9305: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9306: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9307: if (exists($domconfig{'contacts'}{$mailing})) {
9308: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9309: my @contacts = ('adminemail','supportemail');
9310: foreach my $item (@contacts) {
9311: if ($domconfig{'contacts'}{$mailing}{$item}) {
9312: my $addr = $domconfig{'contacts'}{$item};
9313: if (!grep(/^\Q$addr\E$/,@recipients)) {
9314: push(@recipients,$addr);
9315: }
1.619 raeburn 9316: }
1.766 raeburn 9317: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9318: }
9319: }
1.766 raeburn 9320: } elsif ($origmail ne '') {
9321: push(@recipients,$origmail);
1.618 raeburn 9322: }
1.619 raeburn 9323: } elsif ($origmail ne '') {
9324: push(@recipients,$origmail);
1.618 raeburn 9325: }
1.688 raeburn 9326: if (defined($defmail)) {
9327: if ($defmail ne '') {
9328: push(@recipients,$defmail);
9329: }
1.618 raeburn 9330: }
9331: if ($otheremails) {
1.619 raeburn 9332: my @others;
9333: if ($otheremails =~ /,/) {
9334: @others = split(/,/,$otheremails);
1.618 raeburn 9335: } else {
1.619 raeburn 9336: push(@others,$otheremails);
9337: }
9338: foreach my $addr (@others) {
9339: if (!grep(/^\Q$addr\E$/,@recipients)) {
9340: push(@recipients,$addr);
9341: }
1.618 raeburn 9342: }
9343: }
1.619 raeburn 9344: my $recipientlist = join(',',@recipients);
1.618 raeburn 9345: return $recipientlist;
9346: }
9347:
1.127 matthew 9348: ############################################################
9349: ############################################################
1.154 albertel 9350:
1.655 raeburn 9351: =pod
9352:
9353: =head1 Course Catalog Routines
9354:
9355: =over 4
9356:
9357: =item * &gather_categories()
9358:
9359: Converts category definitions - keys of categories hash stored in
9360: coursecategories in configuration.db on the primary library server in a
9361: domain - to an array. Also generates javascript and idx hash used to
9362: generate Domain Coordinator interface for editing Course Categories.
9363:
9364: Inputs:
1.663 raeburn 9365:
1.655 raeburn 9366: categories (reference to hash of category definitions).
1.663 raeburn 9367:
1.655 raeburn 9368: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9369: categories and subcategories).
1.663 raeburn 9370:
1.655 raeburn 9371: idx (reference to hash of counters used in Domain Coordinator interface for
9372: editing Course Categories).
1.663 raeburn 9373:
1.655 raeburn 9374: jsarray (reference to array of categories used to create Javascript arrays for
9375: Domain Coordinator interface for editing Course Categories).
9376:
9377: Returns: nothing
9378:
9379: Side effects: populates cats, idx and jsarray.
9380:
9381: =cut
9382:
9383: sub gather_categories {
9384: my ($categories,$cats,$idx,$jsarray) = @_;
9385: my %counters;
9386: my $num = 0;
9387: foreach my $item (keys(%{$categories})) {
9388: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9389: if ($container eq '' && $depth == 0) {
9390: $cats->[$depth][$categories->{$item}] = $cat;
9391: } else {
9392: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9393: }
9394: my ($escitem,$tail) = split(/:/,$item,2);
9395: if ($counters{$tail} eq '') {
9396: $counters{$tail} = $num;
9397: $num ++;
9398: }
9399: if (ref($idx) eq 'HASH') {
9400: $idx->{$item} = $counters{$tail};
9401: }
9402: if (ref($jsarray) eq 'ARRAY') {
9403: push(@{$jsarray->[$counters{$tail}]},$item);
9404: }
9405: }
9406: return;
9407: }
9408:
9409: =pod
9410:
9411: =item * &extract_categories()
9412:
9413: Used to generate breadcrumb trails for course categories.
9414:
9415: Inputs:
1.663 raeburn 9416:
1.655 raeburn 9417: categories (reference to hash of category definitions).
1.663 raeburn 9418:
1.655 raeburn 9419: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9420: categories and subcategories).
1.663 raeburn 9421:
1.655 raeburn 9422: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9423:
1.655 raeburn 9424: allitems (reference to hash - key is category key
9425: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9426:
1.655 raeburn 9427: idx (reference to hash of counters used in Domain Coordinator interface for
9428: editing Course Categories).
1.663 raeburn 9429:
1.655 raeburn 9430: jsarray (reference to array of categories used to create Javascript arrays for
9431: Domain Coordinator interface for editing Course Categories).
9432:
1.665 raeburn 9433: subcats (reference to hash of arrays containing all subcategories within each
9434: category, -recursive)
9435:
1.655 raeburn 9436: Returns: nothing
9437:
9438: Side effects: populates trails and allitems hash references.
9439:
9440: =cut
9441:
9442: sub extract_categories {
1.665 raeburn 9443: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9444: if (ref($categories) eq 'HASH') {
9445: &gather_categories($categories,$cats,$idx,$jsarray);
9446: if (ref($cats->[0]) eq 'ARRAY') {
9447: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9448: my $name = $cats->[0][$i];
9449: my $item = &escape($name).'::0';
9450: my $trailstr;
9451: if ($name eq 'instcode') {
9452: $trailstr = &mt('Official courses (with institutional codes)');
9453: } else {
9454: $trailstr = $name;
9455: }
9456: if ($allitems->{$item} eq '') {
9457: push(@{$trails},$trailstr);
9458: $allitems->{$item} = scalar(@{$trails})-1;
9459: }
9460: my @parents = ($name);
9461: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9462: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9463: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9464: if (ref($subcats) eq 'HASH') {
9465: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9466: }
9467: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9468: }
9469: } else {
9470: if (ref($subcats) eq 'HASH') {
9471: $subcats->{$item} = [];
1.655 raeburn 9472: }
9473: }
9474: }
9475: }
9476: }
9477: return;
9478: }
9479:
9480: =pod
9481:
9482: =item *&recurse_categories()
9483:
9484: Recursively used to generate breadcrumb trails for course categories.
9485:
9486: Inputs:
1.663 raeburn 9487:
1.655 raeburn 9488: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9489: categories and subcategories).
1.663 raeburn 9490:
1.655 raeburn 9491: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9492:
9493: category (current course category, for which breadcrumb trail is being generated).
9494:
9495: trails (reference to array of breadcrumb trails for each category).
9496:
1.655 raeburn 9497: allitems (reference to hash - key is category key
9498: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9499:
1.655 raeburn 9500: parents (array containing containers directories for current category,
9501: back to top level).
9502:
9503: Returns: nothing
9504:
9505: Side effects: populates trails and allitems hash references
9506:
9507: =cut
9508:
9509: sub recurse_categories {
1.665 raeburn 9510: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9511: my $shallower = $depth - 1;
9512: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9513: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9514: my $name = $cats->[$depth]{$category}[$k];
9515: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9516: my $trailstr = join(' -> ',(@{$parents},$category));
9517: if ($allitems->{$item} eq '') {
9518: push(@{$trails},$trailstr);
9519: $allitems->{$item} = scalar(@{$trails})-1;
9520: }
9521: my $deeper = $depth+1;
9522: push(@{$parents},$category);
1.665 raeburn 9523: if (ref($subcats) eq 'HASH') {
9524: my $subcat = &escape($name).':'.$category.':'.$depth;
9525: for (my $j=@{$parents}; $j>=0; $j--) {
9526: my $higher;
9527: if ($j > 0) {
9528: $higher = &escape($parents->[$j]).':'.
9529: &escape($parents->[$j-1]).':'.$j;
9530: } else {
9531: $higher = &escape($parents->[$j]).'::'.$j;
9532: }
9533: push(@{$subcats->{$higher}},$subcat);
9534: }
9535: }
9536: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9537: $subcats);
1.655 raeburn 9538: pop(@{$parents});
9539: }
9540: } else {
9541: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9542: my $trailstr = join(' -> ',(@{$parents},$category));
9543: if ($allitems->{$item} eq '') {
9544: push(@{$trails},$trailstr);
9545: $allitems->{$item} = scalar(@{$trails})-1;
9546: }
9547: }
9548: return;
9549: }
9550:
1.663 raeburn 9551: =pod
9552:
9553: =item *&assign_categories_table()
9554:
9555: Create a datatable for display of hierarchical categories in a domain,
9556: with checkboxes to allow a course to be categorized.
9557:
9558: Inputs:
9559:
9560: cathash - reference to hash of categories defined for the domain (from
9561: configuration.db)
9562:
9563: currcat - scalar with an & separated list of categories assigned to a course.
9564:
9565: Returns: $output (markup to be displayed)
9566:
9567: =cut
9568:
9569: sub assign_categories_table {
9570: my ($cathash,$currcat) = @_;
9571: my $output;
9572: if (ref($cathash) eq 'HASH') {
9573: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9574: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9575: $maxdepth = scalar(@cats);
9576: if (@cats > 0) {
9577: my $itemcount = 0;
9578: if (ref($cats[0]) eq 'ARRAY') {
9579: $output = &Apache::loncommon::start_data_table();
9580: my @currcategories;
9581: if ($currcat ne '') {
9582: @currcategories = split('&',$currcat);
9583: }
9584: for (my $i=0; $i<@{$cats[0]}; $i++) {
9585: my $parent = $cats[0][$i];
9586: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9587: next if ($parent eq 'instcode');
9588: my $item = &escape($parent).'::0';
9589: my $checked = '';
9590: if (@currcategories > 0) {
9591: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9592: $checked = ' checked="checked"';
1.663 raeburn 9593: }
9594: }
1.675 raeburn 9595: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9596: '<input type="checkbox" name="usecategory" value="'.
9597: $item.'"'.$checked.' />'.$parent.'</span>'.
9598: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9599: my $depth = 1;
9600: push(@path,$parent);
9601: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9602: pop(@path);
9603: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9604: $itemcount ++;
9605: }
9606: $output .= &Apache::loncommon::end_data_table();
9607: }
9608: }
9609: }
9610: return $output;
9611: }
9612:
9613: =pod
9614:
9615: =item *&assign_category_rows()
9616:
9617: Create a datatable row for display of nested categories in a domain,
9618: with checkboxes to allow a course to be categorized,called recursively.
9619:
9620: Inputs:
9621:
9622: itemcount - track row number for alternating colors
9623:
9624: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9625: categories and subcategories.
9626:
9627: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9628:
9629: parent - parent of current category item
9630:
9631: path - Array containing all categories back up through the hierarchy from the
9632: current category to the top level.
9633:
9634: currcategories - reference to array of current categories assigned to the course
9635:
9636: Returns: $output (markup to be displayed).
9637:
9638: =cut
9639:
9640: sub assign_category_rows {
9641: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9642: my ($text,$name,$item,$chgstr);
9643: if (ref($cats) eq 'ARRAY') {
9644: my $maxdepth = scalar(@{$cats});
9645: if (ref($cats->[$depth]) eq 'HASH') {
9646: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9647: my $numchildren = @{$cats->[$depth]{$parent}};
9648: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9649: $text .= '<td><table class="LC_datatable">';
9650: for (my $j=0; $j<$numchildren; $j++) {
9651: $name = $cats->[$depth]{$parent}[$j];
9652: $item = &escape($name).':'.&escape($parent).':'.$depth;
9653: my $deeper = $depth+1;
9654: my $checked = '';
9655: if (ref($currcategories) eq 'ARRAY') {
9656: if (@{$currcategories} > 0) {
9657: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9658: $checked = ' checked="checked"';
1.663 raeburn 9659: }
9660: }
9661: }
1.664 raeburn 9662: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9663: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9664: $item.'"'.$checked.' />'.$name.'</label></span>'.
9665: '<input type="hidden" name="catname" value="'.$name.'" />'.
9666: '</td><td>';
1.663 raeburn 9667: if (ref($path) eq 'ARRAY') {
9668: push(@{$path},$name);
9669: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9670: pop(@{$path});
9671: }
9672: $text .= '</td></tr>';
9673: }
9674: $text .= '</table></td>';
9675: }
9676: }
9677: }
9678: return $text;
9679: }
9680:
1.655 raeburn 9681: ############################################################
9682: ############################################################
9683:
9684:
1.443 albertel 9685: sub commit_customrole {
1.664 raeburn 9686: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9687: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9688: ($start?', '.&mt('starting').' '.localtime($start):'').
9689: ($end?', ending '.localtime($end):'').': <b>'.
9690: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9691: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9692: '</b><br />';
9693: return $output;
9694: }
9695:
9696: sub commit_standardrole {
1.541 raeburn 9697: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9698: my ($output,$logmsg,$linefeed);
9699: if ($context eq 'auto') {
9700: $linefeed = "\n";
9701: } else {
9702: $linefeed = "<br />\n";
9703: }
1.443 albertel 9704: if ($three eq 'st') {
1.541 raeburn 9705: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9706: $one,$two,$sec,$context);
9707: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9708: ($result eq 'unknown_course') || ($result eq 'refused')) {
9709: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9710: } else {
1.541 raeburn 9711: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9712: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9713: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9714: if ($context eq 'auto') {
9715: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9716: } else {
9717: $output .= '<b>'.$result.'</b>'.$linefeed.
9718: &mt('Add to classlist').': <b>ok</b>';
9719: }
9720: $output .= $linefeed;
1.443 albertel 9721: }
9722: } else {
9723: $output = &mt('Assigning').' '.$three.' in '.$url.
9724: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9725: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9726: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9727: if ($context eq 'auto') {
9728: $output .= $result.$linefeed;
9729: } else {
9730: $output .= '<b>'.$result.'</b>'.$linefeed;
9731: }
1.443 albertel 9732: }
9733: return $output;
9734: }
9735:
9736: sub commit_studentrole {
1.541 raeburn 9737: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9738: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9739: if ($context eq 'auto') {
9740: $linefeed = "\n";
9741: } else {
9742: $linefeed = '<br />'."\n";
9743: }
1.443 albertel 9744: if (defined($one) && defined($two)) {
9745: my $cid=$one.'_'.$two;
9746: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9747: my $secchange = 0;
9748: my $expire_role_result;
9749: my $modify_section_result;
1.628 raeburn 9750: if ($oldsec ne '-1') {
9751: if ($oldsec ne $sec) {
1.443 albertel 9752: $secchange = 1;
1.628 raeburn 9753: my $now = time;
1.443 albertel 9754: my $uurl='/'.$cid;
9755: $uurl=~s/\_/\//g;
9756: if ($oldsec) {
9757: $uurl.='/'.$oldsec;
9758: }
1.626 raeburn 9759: $oldsecurl = $uurl;
1.628 raeburn 9760: $expire_role_result =
1.652 raeburn 9761: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9762: if ($env{'request.course.sec'} ne '') {
9763: if ($expire_role_result eq 'refused') {
9764: my @roles = ('st');
9765: my @statuses = ('previous');
9766: my @roledoms = ($one);
9767: my $withsec = 1;
9768: my %roleshash =
9769: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9770: \@statuses,\@roles,\@roledoms,$withsec);
9771: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9772: my ($oldstart,$oldend) =
9773: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9774: if ($oldend > 0 && $oldend <= $now) {
9775: $expire_role_result = 'ok';
9776: }
9777: }
9778: }
9779: }
1.443 albertel 9780: $result = $expire_role_result;
9781: }
9782: }
9783: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9784: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9785: if ($modify_section_result =~ /^ok/) {
9786: if ($secchange == 1) {
1.628 raeburn 9787: if ($sec eq '') {
9788: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9789: } else {
9790: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9791: }
1.443 albertel 9792: } elsif ($oldsec eq '-1') {
1.628 raeburn 9793: if ($sec eq '') {
9794: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9795: } else {
9796: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9797: }
1.443 albertel 9798: } else {
1.628 raeburn 9799: if ($sec eq '') {
9800: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9801: } else {
9802: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9803: }
1.443 albertel 9804: }
9805: } else {
1.628 raeburn 9806: if ($secchange) {
9807: $$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;
9808: } else {
9809: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9810: }
1.443 albertel 9811: }
9812: $result = $modify_section_result;
9813: } elsif ($secchange == 1) {
1.628 raeburn 9814: if ($oldsec eq '') {
9815: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9816: } else {
9817: $$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;
9818: }
1.626 raeburn 9819: if ($expire_role_result eq 'refused') {
9820: my $newsecurl = '/'.$cid;
9821: $newsecurl =~ s/\_/\//g;
9822: if ($sec ne '') {
9823: $newsecurl.='/'.$sec;
9824: }
9825: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9826: if ($sec eq '') {
9827: $$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;
9828: } else {
9829: $$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;
9830: }
9831: }
9832: }
1.443 albertel 9833: }
9834: } else {
1.626 raeburn 9835: $$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 9836: $result = "error: incomplete course id\n";
9837: }
9838: return $result;
9839: }
9840:
9841: ############################################################
9842: ############################################################
9843:
1.566 albertel 9844: sub check_clone {
1.578 raeburn 9845: my ($args,$linefeed) = @_;
1.566 albertel 9846: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9847: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9848: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9849: my $clonemsg;
9850: my $can_clone = 0;
9851:
9852: if ($clonehome eq 'no_host') {
1.578 raeburn 9853: $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 9854: } else {
9855: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9856: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9857: $can_clone = 1;
9858: } else {
9859: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9860: $args->{'clonedomain'},$args->{'clonecourse'});
9861: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9862: if (grep(/^\*$/,@cloners)) {
9863: $can_clone = 1;
9864: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9865: $can_clone = 1;
9866: } else {
9867: my %roleshash =
9868: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9869: $args->{'ccdomain'},
9870: 'userroles',['active'],['cc'],
9871: [$args->{'clonedomain'}]);
9872: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9873: $can_clone = 1;
9874: } else {
9875: $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'});
9876: }
1.566 albertel 9877: }
1.578 raeburn 9878: }
1.566 albertel 9879: }
9880: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9881: }
9882:
1.444 albertel 9883: sub construct_course {
1.541 raeburn 9884: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9885: my $outcome;
1.541 raeburn 9886: my $linefeed = '<br />'."\n";
9887: if ($context eq 'auto') {
9888: $linefeed = "\n";
9889: }
1.566 albertel 9890:
9891: #
9892: # Are we cloning?
9893: #
9894: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9895: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9896: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9897: if ($context ne 'auto') {
1.578 raeburn 9898: if ($clonemsg ne '') {
9899: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9900: }
1.566 albertel 9901: }
9902: $outcome .= $clonemsg.$linefeed;
9903:
9904: if (!$can_clone) {
9905: return (0,$outcome);
9906: }
9907: }
9908:
1.444 albertel 9909: #
9910: # Open course
9911: #
9912: my $crstype = lc($args->{'crstype'});
9913: my %cenv=();
9914: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9915: $args->{'cdescr'},
9916: $args->{'curl'},
9917: $args->{'course_home'},
9918: $args->{'nonstandard'},
9919: $args->{'crscode'},
9920: $args->{'ccuname'}.':'.
9921: $args->{'ccdomain'},
9922: $args->{'crstype'});
9923:
9924: # Note: The testing routines depend on this being output; see
9925: # Utils::Course. This needs to at least be output as a comment
9926: # if anyone ever decides to not show this, and Utils::Course::new
9927: # will need to be suitably modified.
1.541 raeburn 9928: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9929: #
9930: # Check if created correctly
9931: #
1.479 albertel 9932: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9933: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9934: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9935:
1.444 albertel 9936: #
1.566 albertel 9937: # Do the cloning
9938: #
9939: if ($can_clone && $cloneid) {
9940: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9941: if ($context ne 'auto') {
9942: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9943: }
9944: $outcome .= $clonemsg.$linefeed;
9945: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9946: # Copy all files
1.637 www 9947: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9948: # Restore URL
1.566 albertel 9949: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9950: # Restore title
1.566 albertel 9951: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9952: # Mark as cloned
1.566 albertel 9953: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9954: # Need to clone grading mode
9955: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9956: $cenv{'grading'}=$newenv{'grading'};
9957: # Do not clone these environment entries
9958: &Apache::lonnet::del('environment',
9959: ['default_enrollment_start_date',
9960: 'default_enrollment_end_date',
9961: 'question.email',
9962: 'policy.email',
9963: 'comment.email',
9964: 'pch.users.denied',
1.725 raeburn 9965: 'plc.users.denied',
9966: 'hidefromcat',
9967: 'categories'],
1.638 www 9968: $$crsudom,$$crsunum);
1.444 albertel 9969: }
1.566 albertel 9970:
1.444 albertel 9971: #
9972: # Set environment (will override cloned, if existing)
9973: #
9974: my @sections = ();
9975: my @xlists = ();
9976: if ($args->{'crstype'}) {
9977: $cenv{'type'}=$args->{'crstype'};
9978: }
9979: if ($args->{'crsid'}) {
9980: $cenv{'courseid'}=$args->{'crsid'};
9981: }
9982: if ($args->{'crscode'}) {
9983: $cenv{'internal.coursecode'}=$args->{'crscode'};
9984: }
9985: if ($args->{'crsquota'} ne '') {
9986: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9987: } else {
9988: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9989: }
9990: if ($args->{'ccuname'}) {
9991: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9992: ':'.$args->{'ccdomain'};
9993: } else {
9994: $cenv{'internal.courseowner'} = $args->{'curruser'};
9995: }
9996: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9997: if ($args->{'crssections'}) {
9998: $cenv{'internal.sectionnums'} = '';
9999: if ($args->{'crssections'} =~ m/,/) {
10000: @sections = split/,/,$args->{'crssections'};
10001: } else {
10002: $sections[0] = $args->{'crssections'};
10003: }
10004: if (@sections > 0) {
10005: foreach my $item (@sections) {
10006: my ($sec,$gp) = split/:/,$item;
10007: my $class = $args->{'crscode'}.$sec;
10008: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10009: $cenv{'internal.sectionnums'} .= $item.',';
10010: unless ($addcheck eq 'ok') {
10011: push @badclasses, $class;
10012: }
10013: }
10014: $cenv{'internal.sectionnums'} =~ s/,$//;
10015: }
10016: }
10017: # do not hide course coordinator from staff listing,
10018: # even if privileged
10019: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10020: # add crosslistings
10021: if ($args->{'crsxlist'}) {
10022: $cenv{'internal.crosslistings'}='';
10023: if ($args->{'crsxlist'} =~ m/,/) {
10024: @xlists = split/,/,$args->{'crsxlist'};
10025: } else {
10026: $xlists[0] = $args->{'crsxlist'};
10027: }
10028: if (@xlists > 0) {
10029: foreach my $item (@xlists) {
10030: my ($xl,$gp) = split/:/,$item;
10031: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10032: $cenv{'internal.crosslistings'} .= $item.',';
10033: unless ($addcheck eq 'ok') {
10034: push @badclasses, $xl;
10035: }
10036: }
10037: $cenv{'internal.crosslistings'} =~ s/,$//;
10038: }
10039: }
10040: if ($args->{'autoadds'}) {
10041: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10042: }
10043: if ($args->{'autodrops'}) {
10044: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10045: }
10046: # check for notification of enrollment changes
10047: my @notified = ();
10048: if ($args->{'notify_owner'}) {
10049: if ($args->{'ccuname'} ne '') {
10050: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10051: }
10052: }
10053: if ($args->{'notify_dc'}) {
10054: if ($uname ne '') {
1.630 raeburn 10055: push(@notified,$uname.':'.$udom);
1.444 albertel 10056: }
10057: }
10058: if (@notified > 0) {
10059: my $notifylist;
10060: if (@notified > 1) {
10061: $notifylist = join(',',@notified);
10062: } else {
10063: $notifylist = $notified[0];
10064: }
10065: $cenv{'internal.notifylist'} = $notifylist;
10066: }
10067: if (@badclasses > 0) {
10068: my %lt=&Apache::lonlocal::texthash(
10069: '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',
10070: 'dnhr' => 'does not have rights to access enrollment in these classes',
10071: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10072: );
1.541 raeburn 10073: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10074: ' ('.$lt{'adby'}.')';
10075: if ($context eq 'auto') {
10076: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10077: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10078: foreach my $item (@badclasses) {
10079: if ($context eq 'auto') {
10080: $outcome .= " - $item\n";
10081: } else {
10082: $outcome .= "<li>$item</li>\n";
10083: }
10084: }
10085: if ($context eq 'auto') {
10086: $outcome .= $linefeed;
10087: } else {
1.566 albertel 10088: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10089: }
10090: }
1.444 albertel 10091: }
10092: if ($args->{'no_end_date'}) {
10093: $args->{'endaccess'} = 0;
10094: }
10095: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10096: $cenv{'internal.autoend'}=$args->{'enrollend'};
10097: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10098: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10099: if ($args->{'showphotos'}) {
10100: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10101: }
10102: $cenv{'internal.authtype'} = $args->{'authtype'};
10103: $cenv{'internal.autharg'} = $args->{'autharg'};
10104: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10105: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10106: 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');
10107: if ($context eq 'auto') {
10108: $outcome .= $krb_msg;
10109: } else {
1.566 albertel 10110: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10111: }
10112: $outcome .= $linefeed;
1.444 albertel 10113: }
10114: }
10115: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10116: if ($args->{'setpolicy'}) {
10117: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10118: }
10119: if ($args->{'setcontent'}) {
10120: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10121: }
10122: }
10123: if ($args->{'reshome'}) {
10124: $cenv{'reshome'}=$args->{'reshome'}.'/';
10125: $cenv{'reshome'}=~s/\/+$/\//;
10126: }
10127: #
10128: # course has keyed access
10129: #
10130: if ($args->{'setkeys'}) {
10131: $cenv{'keyaccess'}='yes';
10132: }
10133: # if specified, key authority is not course, but user
10134: # only active if keyaccess is yes
10135: if ($args->{'keyauth'}) {
1.487 albertel 10136: my ($user,$domain) = split(':',$args->{'keyauth'});
10137: $user = &LONCAPA::clean_username($user);
10138: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10139: if ($user ne '' && $domain ne '') {
1.487 albertel 10140: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10141: }
10142: }
10143:
10144: if ($args->{'disresdis'}) {
10145: $cenv{'pch.roles.denied'}='st';
10146: }
10147: if ($args->{'disablechat'}) {
10148: $cenv{'plc.roles.denied'}='st';
10149: }
10150:
10151: # Record we've not yet viewed the Course Initialization Helper for this
10152: # course
10153: $cenv{'course.helper.not.run'} = 1;
10154: #
10155: # Use new Randomseed
10156: #
10157: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10158: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10159: #
10160: # The encryption code and receipt prefix for this course
10161: #
10162: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10163: $cenv{'internal.encpref'}=100+int(9*rand(99));
10164: #
10165: # By default, use standard grading
10166: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10167:
1.541 raeburn 10168: $outcome .= $linefeed.&mt('Setting environment').': '.
10169: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10170: #
10171: # Open all assignments
10172: #
10173: if ($args->{'openall'}) {
10174: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10175: my %storecontent = ($storeunder => time,
10176: $storeunder.'.type' => 'date_start');
10177:
10178: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10179: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10180: }
10181: #
10182: # Set first page
10183: #
10184: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10185: || ($cloneid)) {
1.445 albertel 10186: use LONCAPA::map;
1.444 albertel 10187: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10188:
10189: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10190: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10191:
1.444 albertel 10192: $outcome .= ($fatal?$errtext:'read ok').' - ';
10193: my $title; my $url;
10194: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10195: $title=&mt('Syllabus');
1.444 albertel 10196: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10197: } else {
1.690 bisitz 10198: $title=&mt('Navigate Contents');
1.444 albertel 10199: $url='/adm/navmaps';
10200: }
1.445 albertel 10201:
10202: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10203: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10204:
10205: if ($errtext) { $fatal=2; }
1.541 raeburn 10206: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10207: }
1.566 albertel 10208:
10209: return (1,$outcome);
1.444 albertel 10210: }
10211:
10212: ############################################################
10213: ############################################################
10214:
1.378 raeburn 10215: sub course_type {
10216: my ($cid) = @_;
10217: if (!defined($cid)) {
10218: $cid = $env{'request.course.id'};
10219: }
1.404 albertel 10220: if (defined($env{'course.'.$cid.'.type'})) {
10221: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10222: } else {
10223: return 'Course';
1.377 raeburn 10224: }
10225: }
1.156 albertel 10226:
1.406 raeburn 10227: sub group_term {
10228: my $crstype = &course_type();
10229: my %names = (
10230: 'Course' => 'group',
1.865 raeburn 10231: 'Community' => 'group',
1.406 raeburn 10232: );
10233: return $names{$crstype};
10234: }
10235:
1.156 albertel 10236: sub icon {
10237: my ($file)=@_;
1.505 albertel 10238: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10239: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10240: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10241: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10242: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10243: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10244: $curfext.".gif") {
10245: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10246: $curfext.".gif";
10247: }
10248: }
1.249 albertel 10249: return &lonhttpdurl($iconname);
1.154 albertel 10250: }
1.84 albertel 10251:
1.575 albertel 10252: sub lonhttpdurl {
1.692 www 10253: #
10254: # Had been used for "small fry" static images on separate port 8080.
10255: # Modify here if lightweight http functionality desired again.
10256: # Currently eliminated due to increasing firewall issues.
10257: #
1.575 albertel 10258: my ($url)=@_;
1.692 www 10259: return $url;
1.215 albertel 10260: }
10261:
1.213 albertel 10262: sub connection_aborted {
10263: my ($r)=@_;
10264: $r->print(" ");$r->rflush();
10265: my $c = $r->connection;
10266: return $c->aborted();
10267: }
10268:
1.221 foxr 10269: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10270: # strings as 'strings'.
10271: sub escape_single {
1.221 foxr 10272: my ($input) = @_;
1.223 albertel 10273: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10274: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10275: return $input;
10276: }
1.223 albertel 10277:
1.222 foxr 10278: # Same as escape_single, but escape's "'s This
10279: # can be used for "strings"
10280: sub escape_double {
10281: my ($input) = @_;
10282: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10283: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10284: return $input;
10285: }
1.223 albertel 10286:
1.222 foxr 10287: # Escapes the last element of a full URL.
10288: sub escape_url {
10289: my ($url) = @_;
1.238 raeburn 10290: my @urlslices = split(/\//, $url,-1);
1.369 www 10291: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10292: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10293: }
1.462 albertel 10294:
1.820 raeburn 10295: sub compare_arrays {
10296: my ($arrayref1,$arrayref2) = @_;
10297: my (@difference,%count);
10298: @difference = ();
10299: %count = ();
10300: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10301: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10302: foreach my $element (keys(%count)) {
10303: if ($count{$element} == 1) {
10304: push(@difference,$element);
10305: }
10306: }
10307: }
10308: return @difference;
10309: }
10310:
1.817 bisitz 10311: # -------------------------------------------------------- Initialize user login
1.462 albertel 10312: sub init_user_environment {
1.463 albertel 10313: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10314: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10315:
10316: my $public=($username eq 'public' && $domain eq 'public');
10317:
10318: # See if old ID present, if so, remove
10319:
10320: my ($filename,$cookie,$userroles);
10321: my $now=time;
10322:
10323: if ($public) {
10324: my $max_public=100;
10325: my $oldest;
10326: my $oldest_time=0;
10327: for(my $next=1;$next<=$max_public;$next++) {
10328: if (-e $lonids."/publicuser_$next.id") {
10329: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10330: if ($mtime<$oldest_time || !$oldest_time) {
10331: $oldest_time=$mtime;
10332: $oldest=$next;
10333: }
10334: } else {
10335: $cookie="publicuser_$next";
10336: last;
10337: }
10338: }
10339: if (!$cookie) { $cookie="publicuser_$oldest"; }
10340: } else {
1.463 albertel 10341: # if this isn't a robot, kill any existing non-robot sessions
10342: if (!$args->{'robot'}) {
10343: opendir(DIR,$lonids);
10344: while ($filename=readdir(DIR)) {
10345: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10346: unlink($lonids.'/'.$filename);
10347: }
1.462 albertel 10348: }
1.463 albertel 10349: closedir(DIR);
1.462 albertel 10350: }
10351: # Give them a new cookie
1.463 albertel 10352: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10353: : $now.$$.int(rand(10000)));
1.463 albertel 10354: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10355:
10356: # Initialize roles
10357:
10358: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10359: }
10360: # ------------------------------------ Check browser type and MathML capability
10361:
10362: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10363: $clientunicode,$clientos) = &decode_user_agent($r);
10364:
10365: # ------------------------------------------------------------- Get environment
10366:
10367: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10368: my ($tmp) = keys(%userenv);
10369: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10370: # default remote control to off
10371: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10372: } else {
10373: undef(%userenv);
10374: }
10375: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10376: $form->{'interface'}=$userenv{'interface'};
10377: }
10378: $env{'environment.remote'}=$userenv{'remote'};
10379: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10380:
10381: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10382: foreach my $option ('interface','localpath','localres') {
10383: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10384: }
10385: # --------------------------------------------------------- Write first profile
10386:
10387: {
10388: my %initial_env =
10389: ("user.name" => $username,
10390: "user.domain" => $domain,
10391: "user.home" => $authhost,
10392: "browser.type" => $clientbrowser,
10393: "browser.version" => $clientversion,
10394: "browser.mathml" => $clientmathml,
10395: "browser.unicode" => $clientunicode,
10396: "browser.os" => $clientos,
10397: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10398: "request.course.fn" => '',
10399: "request.course.uri" => '',
10400: "request.course.sec" => '',
10401: "request.role" => 'cm',
10402: "request.role.adv" => $env{'user.adv'},
10403: "request.host" => $ENV{'REMOTE_ADDR'},);
10404:
10405: if ($form->{'localpath'}) {
10406: $initial_env{"browser.localpath"} = $form->{'localpath'};
10407: $initial_env{"browser.localres"} = $form->{'localres'};
10408: }
10409:
10410: if ($public) {
10411: $initial_env{"environment.remote"} = "off";
10412: }
10413: if ($form->{'interface'}) {
10414: $form->{'interface'}=~s/\W//gs;
10415: $initial_env{"browser.interface"} = $form->{'interface'};
10416: $env{'browser.interface'}=$form->{'interface'};
10417: }
10418:
1.724 raeburn 10419: foreach my $tool ('aboutme','blog','portfolio') {
10420: $userenv{'availabletools.'.$tool} =
10421: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10422: }
10423:
1.864 raeburn 10424: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10425: $userenv{'canrequest.'.$crstype} =
10426: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10427: 'reload','requestcourses');
10428: }
10429:
1.462 albertel 10430: $env{'user.environment'} = "$lonids/$cookie.id";
10431:
10432: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10433: &GDBM_WRCREAT(),0640)) {
10434: &_add_to_env(\%disk_env,\%initial_env);
10435: &_add_to_env(\%disk_env,\%userenv,'environment.');
10436: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10437: if (ref($args->{'extra_env'})) {
10438: &_add_to_env(\%disk_env,$args->{'extra_env'});
10439: }
1.462 albertel 10440: untie(%disk_env);
10441: } else {
1.705 tempelho 10442: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10443: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10444: return 'error: '.$!;
10445: }
10446: }
10447: $env{'request.role'}='cm';
10448: $env{'request.role.adv'}=$env{'user.adv'};
10449: $env{'browser.type'}=$clientbrowser;
10450:
10451: return $cookie;
10452:
10453: }
10454:
10455: sub _add_to_env {
10456: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10457: if (ref($env_data) eq 'HASH') {
10458: while (my ($key,$value) = each(%$env_data)) {
10459: $idf->{$prefix.$key} = $value;
10460: $env{$prefix.$key} = $value;
10461: }
1.462 albertel 10462: }
10463: }
10464:
1.685 tempelho 10465: # --- Get the symbolic name of a problem and the url
10466: sub get_symb {
10467: my ($request,$silent) = @_;
1.726 raeburn 10468: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10469: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10470: if ($symb eq '') {
10471: if (!$silent) {
10472: $request->print("Unable to handle ambiguous references:$url:.");
10473: return ();
10474: }
10475: }
10476: &Apache::lonenc::check_decrypt(\$symb);
10477: return ($symb);
10478: }
10479:
10480: # --------------------------------------------------------------Get annotation
10481:
10482: sub get_annotation {
10483: my ($symb,$enc) = @_;
10484:
10485: my $key = $symb;
10486: if (!$enc) {
10487: $key =
10488: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10489: }
10490: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10491: return $annotation{$key};
10492: }
10493:
10494: sub clean_symb {
1.731 raeburn 10495: my ($symb,$delete_enc) = @_;
1.685 tempelho 10496:
10497: &Apache::lonenc::check_decrypt(\$symb);
10498: my $enc = $env{'request.enc'};
1.731 raeburn 10499: if ($delete_enc) {
1.730 raeburn 10500: delete($env{'request.enc'});
10501: }
1.685 tempelho 10502:
10503: return ($symb,$enc);
10504: }
1.462 albertel 10505:
1.41 ng 10506: =pod
10507:
10508: =back
10509:
1.112 bowersj2 10510: =cut
1.41 ng 10511:
1.112 bowersj2 10512: 1;
10513: __END__;
1.41 ng 10514:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>