Annotation of loncom/interface/loncommon.pm, revision 1.887
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.887 ! raeburn 4: # $Id: loncommon.pm,v 1.886 2009/08/19 19:43:38 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.886 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:
1.881 raeburn 605: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom) {
1.876 raeburn 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+
1.881 raeburn 618: '&hideudomelement='+hideudom+
619: '&coursedom='+crsdom;
1.876 raeburn 620: var title = 'User_Browser';
621: var options = 'scrollbars=1,resizable=1,menubar=0';
622: options += ',width=700,height=600';
623: var stdeditbrowser = open(url,title,options,'1');
624: stdeditbrowser.focus();
625: }
626:
627: function fix_domain (formname,udom,origdom) {
628: var formid = getFormIdByName(formname);
629: if (formid > -1) {
630: var domid = getIndexByName(formid,udom);
631: var hidedomid = getIndexByName(formid,origdom);
632: if (hidedomid > -1) {
633: var fixeddom = document.forms[formid].elements[hidedomid].value;
634: if (domid > -1) {
635: var slct = document.forms[formid].elements[domid];
636: if (slct.type == 'select-one') {
637: var i;
638: for (i=0;i<slct.length;i++) {
639: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
640: }
641: }
642: if (slct.type == 'hidden') {
643: slct.value = fixeddom;
644: }
1.468 raeburn 645: }
646: }
647: }
1.876 raeburn 648: return;
649: }
650:
651: $id_functions
652: ENDUSERBRW
1.468 raeburn 653: }
654:
655: sub setsec_javascript {
656: my ($sec_element,$formname) = @_;
657: my $setsections = qq|
658: function setSect(sectionlist) {
1.629 raeburn 659: var sectionsArray = new Array();
660: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
661: sectionsArray = sectionlist.split(",");
662: }
1.468 raeburn 663: var numSections = sectionsArray.length;
664: document.$formname.$sec_element.length = 0;
665: if (numSections == 0) {
666: document.$formname.$sec_element.multiple=false;
667: document.$formname.$sec_element.size=1;
668: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
669: } else {
670: if (numSections == 1) {
671: document.$formname.$sec_element.multiple=false;
672: document.$formname.$sec_element.size=1;
673: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
674: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
675: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
676: } else {
677: for (var i=0; i<numSections; i++) {
678: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
679: }
680: document.$formname.$sec_element.multiple=true
681: if (numSections < 3) {
682: document.$formname.$sec_element.size=numSections;
683: } else {
684: document.$formname.$sec_element.size=3;
685: }
686: document.$formname.$sec_element.options[0].selected = false
687: }
688: }
1.91 www 689: }
1.468 raeburn 690: |;
691: return $setsections;
692: }
693:
1.91 www 694:
695: sub selectcourse_link {
1.377 raeburn 696: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.871 raeburn 697: my $linktext = &mt('Select Course');
698: if ($selecttype eq 'Community') {
699: $linktext = &mt('Select Community');
700: }
1.787 bisitz 701: return '<span class="LC_nobreak">'
702: ."<a href='"
703: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
704: .'","'.$udomele.'","'.$desc.'","'.$extra_element
705: .'","'.$multflag.'","'.$selecttype.'");'
1.871 raeburn 706: ."'>".$linktext.'</a>'
1.787 bisitz 707: .'</span>';
1.74 www 708: }
1.42 matthew 709:
1.653 raeburn 710: sub selectauthor_link {
711: my ($form,$udom)=@_;
712: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
713: &mt('Select Author').'</a>';
714: }
715:
1.876 raeburn 716: sub selectuser_link {
1.881 raeburn 717: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
718: $coursedom,$linktext) = @_;
1.876 raeburn 719: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.881 raeburn 720: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom'".
721: ');">'.$linktext.'</a>';
1.876 raeburn 722: }
723:
1.273 raeburn 724: sub check_uncheck_jscript {
725: my $jscript = <<"ENDSCRT";
726: function checkAll(field) {
727: if (field.length > 0) {
728: for (i = 0; i < field.length; i++) {
729: field[i].checked = true ;
730: }
731: } else {
732: field.checked = true
733: }
734: }
735:
736: function uncheckAll(field) {
737: if (field.length > 0) {
738: for (i = 0; i < field.length; i++) {
739: field[i].checked = false ;
1.543 albertel 740: }
741: } else {
1.273 raeburn 742: field.checked = false ;
743: }
744: }
745: ENDSCRT
746: return $jscript;
747: }
748:
1.656 www 749: sub select_timezone {
1.659 raeburn 750: my ($name,$selected,$onchange,$includeempty)=@_;
751: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
752: if ($includeempty) {
753: $output .= '<option value=""';
754: if (($selected eq '') || ($selected eq 'local')) {
755: $output .= ' selected="selected" ';
756: }
757: $output .= '> </option>';
758: }
1.657 raeburn 759: my @timezones = DateTime::TimeZone->all_names;
760: foreach my $tzone (@timezones) {
761: $output.= '<option value="'.$tzone.'"';
762: if ($tzone eq $selected) {
763: $output.=' selected="selected"';
764: }
765: $output.=">$tzone</option>\n";
1.656 www 766: }
767: $output.="</select>";
768: return $output;
769: }
1.273 raeburn 770:
1.687 raeburn 771: sub select_datelocale {
772: my ($name,$selected,$onchange,$includeempty)=@_;
773: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
774: if ($includeempty) {
775: $output .= '<option value=""';
776: if ($selected eq '') {
777: $output .= ' selected="selected" ';
778: }
779: $output .= '> </option>';
780: }
781: my (@possibles,%locale_names);
782: my @locales = DateTime::Locale::Catalog::Locales;
783: foreach my $locale (@locales) {
784: if (ref($locale) eq 'HASH') {
785: my $id = $locale->{'id'};
786: if ($id ne '') {
787: my $en_terr = $locale->{'en_territory'};
788: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 789: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 790: if (grep(/^en$/,@languages) || !@languages) {
791: if ($en_terr ne '') {
792: $locale_names{$id} = '('.$en_terr.')';
793: } elsif ($native_terr ne '') {
794: $locale_names{$id} = $native_terr;
795: }
796: } else {
797: if ($native_terr ne '') {
798: $locale_names{$id} = $native_terr.' ';
799: } elsif ($en_terr ne '') {
800: $locale_names{$id} = '('.$en_terr.')';
801: }
802: }
803: push (@possibles,$id);
804: }
805: }
806: }
807: foreach my $item (sort(@possibles)) {
808: $output.= '<option value="'.$item.'"';
809: if ($item eq $selected) {
810: $output.=' selected="selected"';
811: }
812: $output.=">$item";
813: if ($locale_names{$item} ne '') {
814: $output.=" $locale_names{$item}</option>\n";
815: }
816: $output.="</option>\n";
817: }
818: $output.="</select>";
819: return $output;
820: }
821:
1.792 raeburn 822: sub select_language {
823: my ($name,$selected,$includeempty) = @_;
824: my %langchoices;
825: if ($includeempty) {
826: %langchoices = ('' => 'No language preference');
827: }
828: foreach my $id (&languageids()) {
829: my $code = &supportedlanguagecode($id);
830: if ($code) {
831: $langchoices{$code} = &plainlanguagedescription($id);
832: }
833: }
834: return &select_form($selected,$name,%langchoices);
835: }
836:
1.42 matthew 837: =pod
1.36 matthew 838:
1.648 raeburn 839: =item * &linked_select_forms(...)
1.36 matthew 840:
841: linked_select_forms returns a string containing a <script></script> block
842: and html for two <select> menus. The select menus will be linked in that
843: changing the value of the first menu will result in new values being placed
844: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 845: order unless a defined order is provided.
1.36 matthew 846:
847: linked_select_forms takes the following ordered inputs:
848:
849: =over 4
850:
1.112 bowersj2 851: =item * $formname, the name of the <form> tag
1.36 matthew 852:
1.112 bowersj2 853: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 854:
1.112 bowersj2 855: =item * $firstdefault, the default value for the first menu
1.36 matthew 856:
1.112 bowersj2 857: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 858:
1.112 bowersj2 859: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 860:
1.112 bowersj2 861: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 862:
1.609 raeburn 863: =item * $menuorder, the order of values in the first menu
864:
1.41 ng 865: =back
866:
1.36 matthew 867: Below is an example of such a hash. Only the 'text', 'default', and
868: 'select2' keys must appear as stated. keys(%menu) are the possible
869: values for the first select menu. The text that coincides with the
1.41 ng 870: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 871: and text for the second menu are given in the hash pointed to by
872: $menu{$choice1}->{'select2'}.
873:
1.112 bowersj2 874: my %menu = ( A1 => { text =>"Choice A1" ,
875: default => "B3",
876: select2 => {
877: B1 => "Choice B1",
878: B2 => "Choice B2",
879: B3 => "Choice B3",
880: B4 => "Choice B4"
1.609 raeburn 881: },
882: order => ['B4','B3','B1','B2'],
1.112 bowersj2 883: },
884: A2 => { text =>"Choice A2" ,
885: default => "C2",
886: select2 => {
887: C1 => "Choice C1",
888: C2 => "Choice C2",
889: C3 => "Choice C3"
1.609 raeburn 890: },
891: order => ['C2','C1','C3'],
1.112 bowersj2 892: },
893: A3 => { text =>"Choice A3" ,
894: default => "D6",
895: select2 => {
896: D1 => "Choice D1",
897: D2 => "Choice D2",
898: D3 => "Choice D3",
899: D4 => "Choice D4",
900: D5 => "Choice D5",
901: D6 => "Choice D6",
902: D7 => "Choice D7"
1.609 raeburn 903: },
904: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 905: }
906: );
1.36 matthew 907:
908: =cut
909:
910: sub linked_select_forms {
911: my ($formname,
912: $middletext,
913: $firstdefault,
914: $firstselectname,
915: $secondselectname,
1.609 raeburn 916: $hashref,
917: $menuorder,
1.36 matthew 918: ) = @_;
919: my $second = "document.$formname.$secondselectname";
920: my $first = "document.$formname.$firstselectname";
921: # output the javascript to do the changing
922: my $result = '';
1.776 bisitz 923: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 924: $result.="// <![CDATA[\n";
1.36 matthew 925: $result.="var select2data = new Object();\n";
926: $" = '","';
927: my $debug = '';
928: foreach my $s1 (sort(keys(%$hashref))) {
929: $result.="select2data.d_$s1 = new Object();\n";
930: $result.="select2data.d_$s1.def = new String('".
931: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 932: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 933: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 934: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
935: @s2values = @{$hashref->{$s1}->{'order'}};
936: }
1.36 matthew 937: $result.="\"@s2values\");\n";
938: $result.="select2data.d_$s1.texts = new Array(";
939: my @s2texts;
940: foreach my $value (@s2values) {
941: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
942: }
943: $result.="\"@s2texts\");\n";
944: }
945: $"=' ';
946: $result.= <<"END";
947:
948: function select1_changed() {
949: // Determine new choice
950: var newvalue = "d_" + $first.value;
951: // update select2
952: var values = select2data[newvalue].values;
953: var texts = select2data[newvalue].texts;
954: var select2def = select2data[newvalue].def;
955: var i;
956: // out with the old
957: for (i = 0; i < $second.options.length; i++) {
958: $second.options[i] = null;
959: }
960: // in with the nuclear
961: for (i=0;i<values.length; i++) {
962: $second.options[i] = new Option(values[i]);
1.143 matthew 963: $second.options[i].value = values[i];
1.36 matthew 964: $second.options[i].text = texts[i];
965: if (values[i] == select2def) {
966: $second.options[i].selected = true;
967: }
968: }
969: }
1.824 bisitz 970: // ]]>
1.36 matthew 971: </script>
972: END
973: # output the initial values for the selection lists
974: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 975: my @order = sort(keys(%{$hashref}));
976: if (ref($menuorder) eq 'ARRAY') {
977: @order = @{$menuorder};
978: }
979: foreach my $value (@order) {
1.36 matthew 980: $result.=" <option value=\"$value\" ";
1.253 albertel 981: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 982: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 983: }
984: $result .= "</select>\n";
985: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
986: $result .= $middletext;
987: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
988: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 989:
990: my @secondorder = sort(keys(%select2));
991: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
992: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
993: }
994: foreach my $value (@secondorder) {
1.36 matthew 995: $result.=" <option value=\"$value\" ";
1.253 albertel 996: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 997: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 998: }
999: $result .= "</select>\n";
1000: # return $debug;
1001: return $result;
1002: } # end of sub linked_select_forms {
1003:
1.45 matthew 1004: =pod
1.44 bowersj2 1005:
1.648 raeburn 1006: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 1007:
1.112 bowersj2 1008: Returns a string corresponding to an HTML link to the given help
1009: $topic, where $topic corresponds to the name of a .tex file in
1010: /home/httpd/html/adm/help/tex, with underscores replaced by
1011: spaces.
1012:
1013: $text will optionally be linked to the same topic, allowing you to
1014: link text in addition to the graphic. If you do not want to link
1015: text, but wish to specify one of the later parameters, pass an
1016: empty string.
1017:
1018: $stayOnPage is a value that will be interpreted as a boolean. If true,
1019: the link will not open a new window. If false, the link will open
1020: a new window using Javascript. (Default is false.)
1021:
1022: $width and $height are optional numerical parameters that will
1023: override the width and height of the popped up window, which may
1024: be useful for certain help topics with big pictures included.
1.44 bowersj2 1025:
1026: =cut
1027:
1028: sub help_open_topic {
1.48 bowersj2 1029: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1030: $text = "" if (not defined $text);
1.44 bowersj2 1031: $stayOnPage = 0 if (not defined $stayOnPage);
1032: $width = 350 if (not defined $width);
1033: $height = 400 if (not defined $height);
1034: my $filename = $topic;
1035: $filename =~ s/ /_/g;
1036:
1.48 bowersj2 1037: my $template = "";
1038: my $link;
1.572 banghart 1039:
1.159 www 1040: $topic=~s/\W/\_/g;
1.44 bowersj2 1041:
1.572 banghart 1042: if (!$stayOnPage) {
1.72 bowersj2 1043: $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 1044: } else {
1.48 bowersj2 1045: $link = "/adm/help/${filename}.hlp";
1046: }
1047:
1048: # Add the text
1.755 neumanie 1049: if ($text ne "") {
1.763 bisitz 1050: $template.='<span class="LC_help_open_topic">'
1051: .'<a target="_top" href="'.$link.'">'
1052: .$text.'</a>';
1.48 bowersj2 1053: }
1054:
1.763 bisitz 1055: # (Always) Add the graphic
1.179 matthew 1056: my $title = &mt('Online Help');
1.667 raeburn 1057: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 1058: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1059: .'<img src="'.$helpicon.'" border="0"'
1060: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 1061: .' title="'.$title.'"'
1.763 bisitz 1062: .' /></a>';
1063: if ($text ne "") {
1064: $template.='</span>';
1065: }
1.44 bowersj2 1066: return $template;
1067:
1.106 bowersj2 1068: }
1069:
1070: # This is a quicky function for Latex cheatsheet editing, since it
1071: # appears in at least four places
1072: sub helpLatexCheatsheet {
1.732 raeburn 1073: my ($topic,$text,$not_author) = @_;
1074: my $out;
1.106 bowersj2 1075: my $addOther = '';
1.732 raeburn 1076: if ($topic) {
1.763 bisitz 1077: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1078: undef, undef, 600).
1079: '</span> ';
1080: }
1081: $out = '<span>' # Start cheatsheet
1082: .$addOther
1083: .'<span>'
1084: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1085: undef,undef,600)
1086: .'</span> <span>'
1087: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1088: undef,undef,600)
1089: .'</span>';
1.732 raeburn 1090: unless ($not_author) {
1.763 bisitz 1091: $out .= ' <span>'
1092: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1093: undef,undef,600)
1094: .'</span>';
1.732 raeburn 1095: }
1.763 bisitz 1096: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1097: return $out;
1.172 www 1098: }
1099:
1.430 albertel 1100: sub general_help {
1101: my $helptopic='Student_Intro';
1102: if ($env{'request.role'}=~/^(ca|au)/) {
1103: $helptopic='Authoring_Intro';
1104: } elsif ($env{'request.role'}=~/^cc/) {
1105: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1106: } elsif ($env{'request.role'}=~/^dc/) {
1107: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1108: }
1109: return $helptopic;
1110: }
1111:
1112: sub update_help_link {
1113: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1114: my $origurl = $ENV{'REQUEST_URI'};
1115: $origurl=~s|^/~|/priv/|;
1116: my $timestamp = time;
1117: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1118: $$datum = &escape($$datum);
1119: }
1120:
1121: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1122: my $output .= <<"ENDOUTPUT";
1123: <script type="text/javascript">
1.824 bisitz 1124: // <![CDATA[
1.430 albertel 1125: banner_link = '$banner_link';
1.824 bisitz 1126: // ]]>
1.430 albertel 1127: </script>
1128: ENDOUTPUT
1129: return $output;
1130: }
1131:
1132: # now just updates the help link and generates a blue icon
1.193 raeburn 1133: sub help_open_menu {
1.430 albertel 1134: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1135: = @_;
1.430 albertel 1136: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1137: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1138: # if environment.remote is on (using remote control UI)
1.798 tempelho 1139: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1140: $stayOnPage=1;
1.430 albertel 1141: }
1142: my $output;
1143: if ($component_help) {
1144: if (!$text) {
1145: $output=&help_open_topic($component_help,undef,$stayOnPage,
1146: $width,$height);
1147: } else {
1148: my $help_text;
1149: $help_text=&unescape($topic);
1150: $output='<table><tr><td>'.
1151: &help_open_topic($component_help,$help_text,$stayOnPage,
1152: $width,$height).'</td></tr></table>';
1153: }
1154: }
1155: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1156: return $output.$banner_link;
1157: }
1158:
1159: sub top_nav_help {
1160: my ($text) = @_;
1.436 albertel 1161: $text = &mt($text);
1.572 banghart 1162: my $stay_on_page =
1.798 tempelho 1163: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1164: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1165: : "javascript:helpMenu('open')";
1.572 banghart 1166: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1167:
1.201 raeburn 1168: my $title = &mt('Get help');
1.436 albertel 1169:
1170: return <<"END";
1171: $banner_link
1172: <a href="$link" title="$title">$text</a>
1173: END
1174: }
1175:
1176: sub help_menu_js {
1177: my ($text) = @_;
1178:
1179: my $stayOnPage =
1.798 tempelho 1180: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1181:
1182: my $width = 620;
1183: my $height = 600;
1.430 albertel 1184: my $helptopic=&general_help();
1185: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1186: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1187: my $start_page =
1188: &Apache::loncommon::start_page('Help Menu', undef,
1189: {'frameset' => 1,
1190: 'js_ready' => 1,
1191: 'add_entries' => {
1192: 'border' => '0',
1.579 raeburn 1193: 'rows' => "110,*",},});
1.331 albertel 1194: my $end_page =
1195: &Apache::loncommon::end_page({'frameset' => 1,
1196: 'js_ready' => 1,});
1197:
1.436 albertel 1198: my $template .= <<"ENDTEMPLATE";
1199: <script type="text/javascript">
1.877 bisitz 1200: // <![CDATA[
1.253 albertel 1201: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1202: var banner_link = '';
1.243 raeburn 1203: function helpMenu(target) {
1204: var caller = this;
1205: if (target == 'open') {
1206: var newWindow = null;
1207: try {
1.262 albertel 1208: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1209: }
1210: catch(error) {
1211: writeHelp(caller);
1212: return;
1213: }
1214: if (newWindow) {
1215: caller = newWindow;
1216: }
1.193 raeburn 1217: }
1.243 raeburn 1218: writeHelp(caller);
1219: return;
1220: }
1221: function writeHelp(caller) {
1.430 albertel 1222: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1223: caller.document.close()
1224: caller.focus()
1.193 raeburn 1225: }
1.877 bisitz 1226: // END LON-CAPA Internal -->
1.253 albertel 1227: // ]]>
1.436 albertel 1228: </script>
1.193 raeburn 1229: ENDTEMPLATE
1230: return $template;
1231: }
1232:
1.172 www 1233: sub help_open_bug {
1234: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1235: unless ($env{'user.adv'}) { return ''; }
1.172 www 1236: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1237: $text = "" if (not defined $text);
1238: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1239: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1240: $stayOnPage=1;
1241: }
1.184 albertel 1242: $width = 600 if (not defined $width);
1243: $height = 600 if (not defined $height);
1.172 www 1244:
1245: $topic=~s/\W+/\+/g;
1246: my $link='';
1247: my $template='';
1.379 albertel 1248: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1249: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1250: if (!$stayOnPage)
1251: {
1252: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1253: }
1254: else
1255: {
1256: $link = $url;
1257: }
1258: # Add the text
1259: if ($text ne "")
1260: {
1261: $template .=
1262: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1263: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1264: }
1265:
1266: # Add the graphic
1.179 matthew 1267: my $title = &mt('Report a Bug');
1.215 albertel 1268: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1269: $template .= <<"ENDTEMPLATE";
1.436 albertel 1270: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1271: ENDTEMPLATE
1272: if ($text ne '') { $template.='</td></tr></table>' };
1273: return $template;
1274:
1275: }
1276:
1277: sub help_open_faq {
1278: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1279: unless ($env{'user.adv'}) { return ''; }
1.172 www 1280: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1281: $text = "" if (not defined $text);
1282: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1283: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1284: $stayOnPage=1;
1285: }
1286: $width = 350 if (not defined $width);
1287: $height = 400 if (not defined $height);
1288:
1289: $topic=~s/\W+/\+/g;
1290: my $link='';
1291: my $template='';
1292: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1293: if (!$stayOnPage)
1294: {
1295: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1296: }
1297: else
1298: {
1299: $link = $url;
1300: }
1301:
1302: # Add the text
1303: if ($text ne "")
1304: {
1305: $template .=
1.173 www 1306: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1307: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1308: }
1309:
1310: # Add the graphic
1.179 matthew 1311: my $title = &mt('View the FAQ');
1.215 albertel 1312: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1313: $template .= <<"ENDTEMPLATE";
1.436 albertel 1314: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1315: ENDTEMPLATE
1316: if ($text ne '') { $template.='</td></tr></table>' };
1317: return $template;
1318:
1.44 bowersj2 1319: }
1.37 matthew 1320:
1.180 matthew 1321: ###############################################################
1322: ###############################################################
1323:
1.45 matthew 1324: =pod
1325:
1.648 raeburn 1326: =item * &change_content_javascript():
1.256 matthew 1327:
1328: This and the next function allow you to create small sections of an
1329: otherwise static HTML page that you can update on the fly with
1330: Javascript, even in Netscape 4.
1331:
1332: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1333: must be written to the HTML page once. It will prove the Javascript
1334: function "change(name, content)". Calling the change function with the
1335: name of the section
1336: you want to update, matching the name passed to C<changable_area>, and
1337: the new content you want to put in there, will put the content into
1338: that area.
1339:
1340: B<Note>: Netscape 4 only reserves enough space for the changable area
1341: to contain room for the original contents. You need to "make space"
1342: for whatever changes you wish to make, and be B<sure> to check your
1343: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1344: it's adequate for updating a one-line status display, but little more.
1345: This script will set the space to 100% width, so you only need to
1346: worry about height in Netscape 4.
1347:
1348: Modern browsers are much less limiting, and if you can commit to the
1349: user not using Netscape 4, this feature may be used freely with
1350: pretty much any HTML.
1351:
1352: =cut
1353:
1354: sub change_content_javascript {
1355: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1356: if ($env{'browser.type'} eq 'netscape' &&
1357: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1358: return (<<NETSCAPE4);
1359: function change(name, content) {
1360: doc = document.layers[name+"___escape"].layers[0].document;
1361: doc.open();
1362: doc.write(content);
1363: doc.close();
1364: }
1365: NETSCAPE4
1366: } else {
1367: # Otherwise, we need to use semi-standards-compliant code
1368: # (technically, "innerHTML" isn't standard but the equivalent
1369: # is really scary, and every useful browser supports it
1370: return (<<DOMBASED);
1371: function change(name, content) {
1372: element = document.getElementById(name);
1373: element.innerHTML = content;
1374: }
1375: DOMBASED
1376: }
1377: }
1378:
1379: =pod
1380:
1.648 raeburn 1381: =item * &changable_area($name,$origContent):
1.256 matthew 1382:
1383: This provides a "changable area" that can be modified on the fly via
1384: the Javascript code provided in C<change_content_javascript>. $name is
1385: the name you will use to reference the area later; do not repeat the
1386: same name on a given HTML page more then once. $origContent is what
1387: the area will originally contain, which can be left blank.
1388:
1389: =cut
1390:
1391: sub changable_area {
1392: my ($name, $origContent) = @_;
1393:
1.258 albertel 1394: if ($env{'browser.type'} eq 'netscape' &&
1395: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1396: # If this is netscape 4, we need to use the Layer tag
1397: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1398: } else {
1399: return "<span id='$name'>$origContent</span>";
1400: }
1401: }
1402:
1403: =pod
1404:
1.648 raeburn 1405: =item * &viewport_geometry_js
1.590 raeburn 1406:
1407: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1408:
1409: =cut
1410:
1411:
1412: sub viewport_geometry_js {
1413: return <<"GEOMETRY";
1414: var Geometry = {};
1415: function init_geometry() {
1416: if (Geometry.init) { return };
1417: Geometry.init=1;
1418: if (window.innerHeight) {
1419: Geometry.getViewportHeight = function() { return window.innerHeight; };
1420: Geometry.getViewportWidth = function() { return window.innerWidth; };
1421: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1422: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1423: }
1424: else if (document.documentElement && document.documentElement.clientHeight) {
1425: Geometry.getViewportHeight =
1426: function() { return document.documentElement.clientHeight; };
1427: Geometry.getViewportWidth =
1428: function() { return document.documentElement.clientWidth; };
1429:
1430: Geometry.getHorizontalScroll =
1431: function() { return document.documentElement.scrollLeft; };
1432: Geometry.getVerticalScroll =
1433: function() { return document.documentElement.scrollTop; };
1434: }
1435: else if (document.body.clientHeight) {
1436: Geometry.getViewportHeight =
1437: function() { return document.body.clientHeight; };
1438: Geometry.getViewportWidth =
1439: function() { return document.body.clientWidth; };
1440: Geometry.getHorizontalScroll =
1441: function() { return document.body.scrollLeft; };
1442: Geometry.getVerticalScroll =
1443: function() { return document.body.scrollTop; };
1444: }
1445: }
1446:
1447: GEOMETRY
1448: }
1449:
1450: =pod
1451:
1.648 raeburn 1452: =item * &viewport_size_js()
1.590 raeburn 1453:
1454: 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.
1455:
1456: =cut
1457:
1458: sub viewport_size_js {
1459: my $geometry = &viewport_geometry_js();
1460: return <<"DIMS";
1461:
1462: $geometry
1463:
1464: function getViewportDims(width,height) {
1465: init_geometry();
1466: width.value = Geometry.getViewportWidth();
1467: height.value = Geometry.getViewportHeight();
1468: return;
1469: }
1470:
1471: DIMS
1472: }
1473:
1474: =pod
1475:
1.648 raeburn 1476: =item * &resize_textarea_js()
1.565 albertel 1477:
1478: emits the needed javascript to resize a textarea to be as big as possible
1479:
1480: creates a function resize_textrea that takes two IDs first should be
1481: the id of the element to resize, second should be the id of a div that
1482: surrounds everything that comes after the textarea, this routine needs
1483: to be attached to the <body> for the onload and onresize events.
1484:
1.648 raeburn 1485: =back
1.565 albertel 1486:
1487: =cut
1488:
1489: sub resize_textarea_js {
1.590 raeburn 1490: my $geometry = &viewport_geometry_js();
1.565 albertel 1491: return <<"RESIZE";
1492: <script type="text/javascript">
1.824 bisitz 1493: // <![CDATA[
1.590 raeburn 1494: $geometry
1.565 albertel 1495:
1.588 albertel 1496: function getX(element) {
1497: var x = 0;
1498: while (element) {
1499: x += element.offsetLeft;
1500: element = element.offsetParent;
1501: }
1502: return x;
1503: }
1504: function getY(element) {
1505: var y = 0;
1506: while (element) {
1507: y += element.offsetTop;
1508: element = element.offsetParent;
1509: }
1510: return y;
1511: }
1512:
1513:
1.565 albertel 1514: function resize_textarea(textarea_id,bottom_id) {
1515: init_geometry();
1516: var textarea = document.getElementById(textarea_id);
1517: //alert(textarea);
1518:
1.588 albertel 1519: var textarea_top = getY(textarea);
1.565 albertel 1520: var textarea_height = textarea.offsetHeight;
1521: var bottom = document.getElementById(bottom_id);
1.588 albertel 1522: var bottom_top = getY(bottom);
1.565 albertel 1523: var bottom_height = bottom.offsetHeight;
1524: var window_height = Geometry.getViewportHeight();
1.588 albertel 1525: var fudge = 23;
1.565 albertel 1526: var new_height = window_height-fudge-textarea_top-bottom_height;
1527: if (new_height < 300) {
1528: new_height = 300;
1529: }
1530: textarea.style.height=new_height+'px';
1531: }
1.824 bisitz 1532: // ]]>
1.565 albertel 1533: </script>
1534: RESIZE
1535:
1536: }
1537:
1538: =pod
1539:
1.256 matthew 1540: =head1 Excel and CSV file utility routines
1541:
1542: =over 4
1543:
1544: =cut
1545:
1546: ###############################################################
1547: ###############################################################
1548:
1549: =pod
1550:
1.648 raeburn 1551: =item * &csv_translate($text)
1.37 matthew 1552:
1.185 www 1553: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1554: format.
1555:
1556: =cut
1557:
1.180 matthew 1558: ###############################################################
1559: ###############################################################
1.37 matthew 1560: sub csv_translate {
1561: my $text = shift;
1562: $text =~ s/\"/\"\"/g;
1.209 albertel 1563: $text =~ s/\n/ /g;
1.37 matthew 1564: return $text;
1565: }
1.180 matthew 1566:
1567: ###############################################################
1568: ###############################################################
1569:
1570: =pod
1571:
1.648 raeburn 1572: =item * &define_excel_formats()
1.180 matthew 1573:
1574: Define some commonly used Excel cell formats.
1575:
1576: Currently supported formats:
1577:
1578: =over 4
1579:
1580: =item header
1581:
1582: =item bold
1583:
1584: =item h1
1585:
1586: =item h2
1587:
1588: =item h3
1589:
1.256 matthew 1590: =item h4
1591:
1592: =item i
1593:
1.180 matthew 1594: =item date
1595:
1596: =back
1597:
1598: Inputs: $workbook
1599:
1600: Returns: $format, a hash reference.
1601:
1602: =cut
1603:
1604: ###############################################################
1605: ###############################################################
1606: sub define_excel_formats {
1607: my ($workbook) = @_;
1608: my $format;
1609: $format->{'header'} = $workbook->add_format(bold => 1,
1610: bottom => 1,
1611: align => 'center');
1612: $format->{'bold'} = $workbook->add_format(bold=>1);
1613: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1614: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1615: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1616: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1617: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1618: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1619: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1620: return $format;
1621: }
1622:
1623: ###############################################################
1624: ###############################################################
1.113 bowersj2 1625:
1626: =pod
1627:
1.648 raeburn 1628: =item * &create_workbook()
1.255 matthew 1629:
1630: Create an Excel worksheet. If it fails, output message on the
1631: request object and return undefs.
1632:
1633: Inputs: Apache request object
1634:
1635: Returns (undef) on failure,
1636: Excel worksheet object, scalar with filename, and formats
1637: from &Apache::loncommon::define_excel_formats on success
1638:
1639: =cut
1640:
1641: ###############################################################
1642: ###############################################################
1643: sub create_workbook {
1644: my ($r) = @_;
1645: #
1646: # Create the excel spreadsheet
1647: my $filename = '/prtspool/'.
1.258 albertel 1648: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1649: time.'_'.rand(1000000000).'.xls';
1650: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1651: if (! defined($workbook)) {
1652: $r->log_error("Error creating excel spreadsheet $filename: $!");
1653: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1654: "This error has been logged. ".
1655: "Please alert your LON-CAPA administrator").
1656: '</p>');
1657: return (undef);
1658: }
1659: #
1660: $workbook->set_tempdir('/home/httpd/perl/tmp');
1661: #
1662: my $format = &Apache::loncommon::define_excel_formats($workbook);
1663: return ($workbook,$filename,$format);
1664: }
1665:
1666: ###############################################################
1667: ###############################################################
1668:
1669: =pod
1670:
1.648 raeburn 1671: =item * &create_text_file()
1.113 bowersj2 1672:
1.542 raeburn 1673: Create a file to write to and eventually make available to the user.
1.256 matthew 1674: If file creation fails, outputs an error message on the request object and
1675: return undefs.
1.113 bowersj2 1676:
1.256 matthew 1677: Inputs: Apache request object, and file suffix
1.113 bowersj2 1678:
1.256 matthew 1679: Returns (undef) on failure,
1680: Filehandle and filename on success.
1.113 bowersj2 1681:
1682: =cut
1683:
1.256 matthew 1684: ###############################################################
1685: ###############################################################
1686: sub create_text_file {
1687: my ($r,$suffix) = @_;
1688: if (! defined($suffix)) { $suffix = 'txt'; };
1689: my $fh;
1690: my $filename = '/prtspool/'.
1.258 albertel 1691: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1692: time.'_'.rand(1000000000).'.'.$suffix;
1693: $fh = Apache::File->new('>/home/httpd'.$filename);
1694: if (! defined($fh)) {
1695: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1696: $r->print(&mt('Problems occurred in creating the output file. '
1697: .'This error has been logged. '
1698: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1699: }
1.256 matthew 1700: return ($fh,$filename)
1.113 bowersj2 1701: }
1702:
1703:
1.256 matthew 1704: =pod
1.113 bowersj2 1705:
1706: =back
1707:
1708: =cut
1.37 matthew 1709:
1710: ###############################################################
1.33 matthew 1711: ## Home server <option> list generating code ##
1712: ###############################################################
1.35 matthew 1713:
1.169 www 1714: # ------------------------------------------
1715:
1716: sub domain_select {
1717: my ($name,$value,$multiple)=@_;
1718: my %domains=map {
1.514 albertel 1719: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1720: } &Apache::lonnet::all_domains();
1.169 www 1721: if ($multiple) {
1722: $domains{''}=&mt('Any domain');
1.550 albertel 1723: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1724: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1725: } else {
1.550 albertel 1726: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1727: return &select_form($name,$value,%domains);
1728: }
1729: }
1730:
1.282 albertel 1731: #-------------------------------------------
1732:
1733: =pod
1734:
1.519 raeburn 1735: =head1 Routines for form select boxes
1736:
1737: =over 4
1738:
1.648 raeburn 1739: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1740:
1741: Returns a string containing a <select> element int multiple mode
1742:
1743:
1744: Args:
1745: $name - name of the <select> element
1.506 raeburn 1746: $value - scalar or array ref of values that should already be selected
1.282 albertel 1747: $size - number of rows long the select element is
1.283 albertel 1748: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1749: (shown text should already have been &mt())
1.506 raeburn 1750: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1751:
1.282 albertel 1752: =cut
1753:
1754: #-------------------------------------------
1.169 www 1755: sub multiple_select_form {
1.284 albertel 1756: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1757: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1758: my $output='';
1.191 matthew 1759: if (! defined($size)) {
1760: $size = 4;
1.283 albertel 1761: if (scalar(keys(%$hash))<4) {
1762: $size = scalar(keys(%$hash));
1.191 matthew 1763: }
1764: }
1.734 bisitz 1765: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1766: my @order;
1.506 raeburn 1767: if (ref($order) eq 'ARRAY') {
1768: @order = @{$order};
1769: } else {
1770: @order = sort(keys(%$hash));
1.501 banghart 1771: }
1772: if (exists($$hash{'select_form_order'})) {
1773: @order = @{$$hash{'select_form_order'}};
1774: }
1775:
1.284 albertel 1776: foreach my $key (@order) {
1.356 albertel 1777: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1778: $output.='selected="selected" ' if ($selected{$key});
1779: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1780: }
1781: $output.="</select>\n";
1782: return $output;
1783: }
1784:
1.88 www 1785: #-------------------------------------------
1786:
1787: =pod
1788:
1.648 raeburn 1789: =item * &select_form($defdom,$name,%hash)
1.88 www 1790:
1791: Returns a string containing a <select name='$name' size='1'> form to
1792: allow a user to select options from a hash option_name => displayed text.
1793: See lonrights.pm for an example invocation and use.
1794:
1795: =cut
1796:
1797: #-------------------------------------------
1798: sub select_form {
1799: my ($def,$name,%hash) = @_;
1800: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1801: my @keys;
1802: if (exists($hash{'select_form_order'})) {
1803: @keys=@{$hash{'select_form_order'}};
1804: } else {
1805: @keys=sort(keys(%hash));
1806: }
1.356 albertel 1807: foreach my $key (@keys) {
1808: $selectform.=
1809: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1810: ($key eq $def ? 'selected="selected" ' : '').
1811: ">".&mt($hash{$key})."</option>\n";
1.88 www 1812: }
1813: $selectform.="</select>";
1814: return $selectform;
1815: }
1816:
1.475 www 1817: # For display filters
1818:
1819: sub display_filter {
1820: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1821: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1822: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1823: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1824: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1825: '</label></span> <span class="LC_nobreak">'.
1.475 www 1826: &mt('Filter [_1]',
1.477 www 1827: &select_form($env{'form.displayfilter'},
1828: 'displayfilter',
1829: ('currentfolder' => 'Current folder/page',
1830: 'containing' => 'Containing phrase',
1831: 'none' => 'None'))).
1.714 bisitz 1832: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1833: }
1834:
1.167 www 1835: sub gradeleveldescription {
1836: my $gradelevel=shift;
1837: my %gradelevels=(0 => 'Not specified',
1838: 1 => 'Grade 1',
1839: 2 => 'Grade 2',
1840: 3 => 'Grade 3',
1841: 4 => 'Grade 4',
1842: 5 => 'Grade 5',
1843: 6 => 'Grade 6',
1844: 7 => 'Grade 7',
1845: 8 => 'Grade 8',
1846: 9 => 'Grade 9',
1847: 10 => 'Grade 10',
1848: 11 => 'Grade 11',
1849: 12 => 'Grade 12',
1850: 13 => 'Grade 13',
1851: 14 => '100 Level',
1852: 15 => '200 Level',
1853: 16 => '300 Level',
1854: 17 => '400 Level',
1855: 18 => 'Graduate Level');
1856: return &mt($gradelevels{$gradelevel});
1857: }
1858:
1.163 www 1859: sub select_level_form {
1860: my ($deflevel,$name)=@_;
1861: unless ($deflevel) { $deflevel=0; }
1.167 www 1862: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1863: for (my $i=0; $i<=18; $i++) {
1864: $selectform.="<option value=\"$i\" ".
1.253 albertel 1865: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1866: ">".&gradeleveldescription($i)."</option>\n";
1867: }
1868: $selectform.="</select>";
1869: return $selectform;
1.163 www 1870: }
1.167 www 1871:
1.35 matthew 1872: #-------------------------------------------
1873:
1.45 matthew 1874: =pod
1875:
1.873 raeburn 1876: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35 matthew 1877:
1878: Returns a string containing a <select name='$name' size='1'> form to
1879: allow a user to select the domain to preform an operation in.
1880: See loncreateuser.pm for an example invocation and use.
1881:
1.90 www 1882: If the $includeempty flag is set, it also includes an empty choice ("no domain
1883: selected");
1884:
1.743 raeburn 1885: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1886:
1.872 raeburn 1887: 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 1888:
1.35 matthew 1889: =cut
1890:
1891: #-------------------------------------------
1.34 matthew 1892: sub select_dom_form {
1.872 raeburn 1893: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
1894: if ($onchange) {
1.874 raeburn 1895: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1896: }
1.550 albertel 1897: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1898: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1899: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1900: foreach my $dom (@domains) {
1901: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1902: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1903: if ($showdomdesc) {
1904: if ($dom ne '') {
1905: my $domdesc = &Apache::lonnet::domain($dom,'description');
1906: if ($domdesc ne '') {
1907: $selectdomain .= ' ('.$domdesc.')';
1908: }
1909: }
1910: }
1911: $selectdomain .= "</option>\n";
1.34 matthew 1912: }
1913: $selectdomain.="</select>";
1914: return $selectdomain;
1915: }
1916:
1.35 matthew 1917: #-------------------------------------------
1918:
1.45 matthew 1919: =pod
1920:
1.648 raeburn 1921: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1922:
1.586 raeburn 1923: input: 4 arguments (two required, two optional) -
1924: $domain - domain of new user
1925: $name - name of form element
1926: $default - Value of 'default' causes a default item to be first
1927: option, and selected by default.
1928: $hide - Value of 'hide' causes hiding of the name of the server,
1929: if 1 server found, or default, if 0 found.
1.594 raeburn 1930: output: returns 2 items:
1.586 raeburn 1931: (a) form element which contains either:
1932: (i) <select name="$name">
1933: <option value="$hostid1">$hostid $servers{$hostid}</option>
1934: <option value="$hostid2">$hostid $servers{$hostid}</option>
1935: </select>
1936: form item if there are multiple library servers in $domain, or
1937: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1938: if there is only one library server in $domain.
1939:
1940: (b) number of library servers found.
1941:
1942: See loncreateuser.pm for example of use.
1.35 matthew 1943:
1944: =cut
1945:
1946: #-------------------------------------------
1.586 raeburn 1947: sub home_server_form_item {
1948: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1949: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1950: my $result;
1951: my $numlib = keys(%servers);
1952: if ($numlib > 1) {
1953: $result .= '<select name="'.$name.'" />'."\n";
1954: if ($default) {
1.804 bisitz 1955: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1956: '</option>'."\n";
1957: }
1958: foreach my $hostid (sort(keys(%servers))) {
1959: $result.= '<option value="'.$hostid.'">'.
1960: $hostid.' '.$servers{$hostid}."</option>\n";
1961: }
1962: $result .= '</select>'."\n";
1963: } elsif ($numlib == 1) {
1964: my $hostid;
1965: foreach my $item (keys(%servers)) {
1966: $hostid = $item;
1967: }
1968: $result .= '<input type="hidden" name="'.$name.'" value="'.
1969: $hostid.'" />';
1970: if (!$hide) {
1971: $result .= $hostid.' '.$servers{$hostid};
1972: }
1973: $result .= "\n";
1974: } elsif ($default) {
1975: $result .= '<input type="hidden" name="'.$name.
1976: '" value="default" />';
1977: if (!$hide) {
1978: $result .= &mt('default');
1979: }
1980: $result .= "\n";
1.33 matthew 1981: }
1.586 raeburn 1982: return ($result,$numlib);
1.33 matthew 1983: }
1.112 bowersj2 1984:
1985: =pod
1986:
1.534 albertel 1987: =back
1988:
1.112 bowersj2 1989: =cut
1.87 matthew 1990:
1991: ###############################################################
1.112 bowersj2 1992: ## Decoding User Agent ##
1.87 matthew 1993: ###############################################################
1994:
1995: =pod
1996:
1.112 bowersj2 1997: =head1 Decoding the User Agent
1998:
1999: =over 4
2000:
2001: =item * &decode_user_agent()
1.87 matthew 2002:
2003: Inputs: $r
2004:
2005: Outputs:
2006:
2007: =over 4
2008:
1.112 bowersj2 2009: =item * $httpbrowser
1.87 matthew 2010:
1.112 bowersj2 2011: =item * $clientbrowser
1.87 matthew 2012:
1.112 bowersj2 2013: =item * $clientversion
1.87 matthew 2014:
1.112 bowersj2 2015: =item * $clientmathml
1.87 matthew 2016:
1.112 bowersj2 2017: =item * $clientunicode
1.87 matthew 2018:
1.112 bowersj2 2019: =item * $clientos
1.87 matthew 2020:
2021: =back
2022:
1.157 matthew 2023: =back
2024:
1.87 matthew 2025: =cut
2026:
2027: ###############################################################
2028: ###############################################################
2029: sub decode_user_agent {
1.247 albertel 2030: my ($r)=@_;
1.87 matthew 2031: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2032: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2033: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2034: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2035: my $clientbrowser='unknown';
2036: my $clientversion='0';
2037: my $clientmathml='';
2038: my $clientunicode='0';
2039: for (my $i=0;$i<=$#browsertype;$i++) {
2040: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2041: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2042: $clientbrowser=$bname;
2043: $httpbrowser=~/$vreg/i;
2044: $clientversion=$1;
2045: $clientmathml=($clientversion>=$minv);
2046: $clientunicode=($clientversion>=$univ);
2047: }
2048: }
2049: my $clientos='unknown';
2050: if (($httpbrowser=~/linux/i) ||
2051: ($httpbrowser=~/unix/i) ||
2052: ($httpbrowser=~/ux/i) ||
2053: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2054: if (($httpbrowser=~/vax/i) ||
2055: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2056: if ($httpbrowser=~/next/i) { $clientos='next'; }
2057: if (($httpbrowser=~/mac/i) ||
2058: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2059: if ($httpbrowser=~/win/i) { $clientos='win'; }
2060: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2061: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2062: $clientunicode,$clientos,);
2063: }
2064:
1.32 matthew 2065: ###############################################################
2066: ## Authentication changing form generation subroutines ##
2067: ###############################################################
2068: ##
2069: ## All of the authform_xxxxxxx subroutines take their inputs in a
2070: ## hash, and have reasonable default values.
2071: ##
2072: ## formname = the name given in the <form> tag.
1.35 matthew 2073: #-------------------------------------------
2074:
1.45 matthew 2075: =pod
2076:
1.112 bowersj2 2077: =head1 Authentication Routines
2078:
2079: =over 4
2080:
1.648 raeburn 2081: =item * &authform_xxxxxx()
1.35 matthew 2082:
2083: The authform_xxxxxx subroutines provide javascript and html forms which
2084: handle some of the conveniences required for authentication forms.
2085: This is not an optimal method, but it works.
2086:
2087: =over 4
2088:
1.112 bowersj2 2089: =item * authform_header
1.35 matthew 2090:
1.112 bowersj2 2091: =item * authform_authorwarning
1.35 matthew 2092:
1.112 bowersj2 2093: =item * authform_nochange
1.35 matthew 2094:
1.112 bowersj2 2095: =item * authform_kerberos
1.35 matthew 2096:
1.112 bowersj2 2097: =item * authform_internal
1.35 matthew 2098:
1.112 bowersj2 2099: =item * authform_filesystem
1.35 matthew 2100:
2101: =back
2102:
1.648 raeburn 2103: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2104:
1.35 matthew 2105: =cut
2106:
2107: #-------------------------------------------
1.32 matthew 2108: sub authform_header{
2109: my %in = (
2110: formname => 'cu',
1.80 albertel 2111: kerb_def_dom => '',
1.32 matthew 2112: @_,
2113: );
2114: $in{'formname'} = 'document.' . $in{'formname'};
2115: my $result='';
1.80 albertel 2116:
2117: #---------------------------------------------- Code for upper case translation
2118: my $Javascript_toUpperCase;
2119: unless ($in{kerb_def_dom}) {
2120: $Javascript_toUpperCase =<<"END";
2121: switch (choice) {
2122: case 'krb': currentform.elements[choicearg].value =
2123: currentform.elements[choicearg].value.toUpperCase();
2124: break;
2125: default:
2126: }
2127: END
2128: } else {
2129: $Javascript_toUpperCase = "";
2130: }
2131:
1.165 raeburn 2132: my $radioval = "'nochange'";
1.591 raeburn 2133: if (defined($in{'curr_authtype'})) {
2134: if ($in{'curr_authtype'} ne '') {
2135: $radioval = "'".$in{'curr_authtype'}."arg'";
2136: }
1.174 matthew 2137: }
1.165 raeburn 2138: my $argfield = 'null';
1.591 raeburn 2139: if (defined($in{'mode'})) {
1.165 raeburn 2140: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2141: if (defined($in{'curr_autharg'})) {
2142: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2143: $argfield = "'$in{'curr_autharg'}'";
2144: }
2145: }
2146: }
2147: }
2148:
1.32 matthew 2149: $result.=<<"END";
2150: var current = new Object();
1.165 raeburn 2151: current.radiovalue = $radioval;
2152: current.argfield = $argfield;
1.32 matthew 2153:
2154: function changed_radio(choice,currentform) {
2155: var choicearg = choice + 'arg';
2156: // If a radio button in changed, we need to change the argfield
2157: if (current.radiovalue != choice) {
2158: current.radiovalue = choice;
2159: if (current.argfield != null) {
2160: currentform.elements[current.argfield].value = '';
2161: }
2162: if (choice == 'nochange') {
2163: current.argfield = null;
2164: } else {
2165: current.argfield = choicearg;
2166: switch(choice) {
2167: case 'krb':
2168: currentform.elements[current.argfield].value =
2169: "$in{'kerb_def_dom'}";
2170: break;
2171: default:
2172: break;
2173: }
2174: }
2175: }
2176: return;
2177: }
1.22 www 2178:
1.32 matthew 2179: function changed_text(choice,currentform) {
2180: var choicearg = choice + 'arg';
2181: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2182: $Javascript_toUpperCase
1.32 matthew 2183: // clear old field
2184: if ((current.argfield != choicearg) && (current.argfield != null)) {
2185: currentform.elements[current.argfield].value = '';
2186: }
2187: current.argfield = choicearg;
2188: }
2189: set_auth_radio_buttons(choice,currentform);
2190: return;
1.20 www 2191: }
1.32 matthew 2192:
2193: function set_auth_radio_buttons(newvalue,currentform) {
2194: var i=0;
2195: while (i < currentform.login.length) {
2196: if (currentform.login[i].value == newvalue) { break; }
2197: i++;
2198: }
2199: if (i == currentform.login.length) {
2200: return;
2201: }
2202: current.radiovalue = newvalue;
2203: currentform.login[i].checked = true;
2204: return;
2205: }
2206: END
2207: return $result;
2208: }
2209:
2210: sub authform_authorwarning{
2211: my $result='';
1.144 matthew 2212: $result='<i>'.
2213: &mt('As a general rule, only authors or co-authors should be '.
2214: 'filesystem authenticated '.
2215: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2216: return $result;
2217: }
2218:
2219: sub authform_nochange{
2220: my %in = (
2221: formname => 'document.cu',
2222: kerb_def_dom => 'MSU.EDU',
2223: @_,
2224: );
1.586 raeburn 2225: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2226: my $result;
2227: if (keys(%can_assign) == 0) {
2228: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2229: } else {
2230: $result = '<label>'.&mt('[_1] Do not change login data',
2231: '<input type="radio" name="login" value="nochange" '.
2232: 'checked="checked" onclick="'.
1.281 albertel 2233: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2234: '</label>';
1.586 raeburn 2235: }
1.32 matthew 2236: return $result;
2237: }
2238:
1.591 raeburn 2239: sub authform_kerberos {
1.32 matthew 2240: my %in = (
2241: formname => 'document.cu',
2242: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2243: kerb_def_auth => 'krb4',
1.32 matthew 2244: @_,
2245: );
1.586 raeburn 2246: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2247: $autharg,$jscall);
2248: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2249: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2250: $check5 = ' checked="checked"';
1.80 albertel 2251: } else {
1.772 bisitz 2252: $check4 = ' checked="checked"';
1.80 albertel 2253: }
1.165 raeburn 2254: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2255: if (defined($in{'curr_authtype'})) {
2256: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2257: $krbcheck = ' checked="checked"';
1.623 raeburn 2258: if (defined($in{'mode'})) {
2259: if ($in{'mode'} eq 'modifyuser') {
2260: $krbcheck = '';
2261: }
2262: }
1.591 raeburn 2263: if (defined($in{'curr_kerb_ver'})) {
2264: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2265: $check5 = ' checked="checked"';
1.591 raeburn 2266: $check4 = '';
2267: } else {
1.772 bisitz 2268: $check4 = ' checked="checked"';
1.591 raeburn 2269: $check5 = '';
2270: }
1.586 raeburn 2271: }
1.591 raeburn 2272: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2273: $krbarg = $in{'curr_autharg'};
2274: }
1.586 raeburn 2275: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2276: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2277: $result =
2278: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2279: $in{'curr_autharg'},$krbver);
2280: } else {
2281: $result =
2282: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2283: }
2284: return $result;
2285: }
2286: }
2287: } else {
2288: if ($authnum == 1) {
1.784 bisitz 2289: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2290: }
2291: }
1.586 raeburn 2292: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2293: return;
1.587 raeburn 2294: } elsif ($authtype eq '') {
1.591 raeburn 2295: if (defined($in{'mode'})) {
1.587 raeburn 2296: if ($in{'mode'} eq 'modifycourse') {
2297: if ($authnum == 1) {
1.784 bisitz 2298: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2299: }
2300: }
2301: }
1.586 raeburn 2302: }
2303: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2304: if ($authtype eq '') {
2305: $authtype = '<input type="radio" name="login" value="krb" '.
2306: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2307: $krbcheck.' />';
2308: }
2309: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2310: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2311: $in{'curr_authtype'} eq 'krb5') ||
2312: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2313: $in{'curr_authtype'} eq 'krb4')) {
2314: $result .= &mt
1.144 matthew 2315: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2316: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2317: '<label>'.$authtype,
1.281 albertel 2318: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2319: 'value="'.$krbarg.'" '.
1.144 matthew 2320: 'onchange="'.$jscall.'" />',
1.281 albertel 2321: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2322: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2323: '</label>');
1.586 raeburn 2324: } elsif ($can_assign{'krb4'}) {
2325: $result .= &mt
2326: ('[_1] Kerberos authenticated with domain [_2] '.
2327: '[_3] Version 4 [_4]',
2328: '<label>'.$authtype,
2329: '</label><input type="text" size="10" name="krbarg" '.
2330: 'value="'.$krbarg.'" '.
2331: 'onchange="'.$jscall.'" />',
2332: '<label><input type="hidden" name="krbver" value="4" />',
2333: '</label>');
2334: } elsif ($can_assign{'krb5'}) {
2335: $result .= &mt
2336: ('[_1] Kerberos authenticated with domain [_2] '.
2337: '[_3] Version 5 [_4]',
2338: '<label>'.$authtype,
2339: '</label><input type="text" size="10" name="krbarg" '.
2340: 'value="'.$krbarg.'" '.
2341: 'onchange="'.$jscall.'" />',
2342: '<label><input type="hidden" name="krbver" value="5" />',
2343: '</label>');
2344: }
1.32 matthew 2345: return $result;
2346: }
2347:
2348: sub authform_internal{
1.586 raeburn 2349: my %in = (
1.32 matthew 2350: formname => 'document.cu',
2351: kerb_def_dom => 'MSU.EDU',
2352: @_,
2353: );
1.586 raeburn 2354: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2355: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2356: if (defined($in{'curr_authtype'})) {
2357: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2358: if ($can_assign{'int'}) {
1.772 bisitz 2359: $intcheck = 'checked="checked" ';
1.623 raeburn 2360: if (defined($in{'mode'})) {
2361: if ($in{'mode'} eq 'modifyuser') {
2362: $intcheck = '';
2363: }
2364: }
1.591 raeburn 2365: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2366: $intarg = $in{'curr_autharg'};
2367: }
2368: } else {
2369: $result = &mt('Currently internally authenticated.');
2370: return $result;
1.165 raeburn 2371: }
2372: }
1.586 raeburn 2373: } else {
2374: if ($authnum == 1) {
1.784 bisitz 2375: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2376: }
2377: }
2378: if (!$can_assign{'int'}) {
2379: return;
1.587 raeburn 2380: } elsif ($authtype eq '') {
1.591 raeburn 2381: if (defined($in{'mode'})) {
1.587 raeburn 2382: if ($in{'mode'} eq 'modifycourse') {
2383: if ($authnum == 1) {
1.784 bisitz 2384: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2385: }
2386: }
2387: }
1.165 raeburn 2388: }
1.586 raeburn 2389: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2390: if ($authtype eq '') {
2391: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2392: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2393: }
1.605 bisitz 2394: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2395: $intarg.'" onchange="'.$jscall.'" />';
2396: $result = &mt
1.144 matthew 2397: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2398: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2399: $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 2400: return $result;
2401: }
2402:
2403: sub authform_local{
2404: my %in = (
2405: formname => 'document.cu',
2406: kerb_def_dom => 'MSU.EDU',
2407: @_,
2408: );
1.586 raeburn 2409: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2410: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2411: if (defined($in{'curr_authtype'})) {
2412: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2413: if ($can_assign{'loc'}) {
1.772 bisitz 2414: $loccheck = 'checked="checked" ';
1.623 raeburn 2415: if (defined($in{'mode'})) {
2416: if ($in{'mode'} eq 'modifyuser') {
2417: $loccheck = '';
2418: }
2419: }
1.591 raeburn 2420: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2421: $locarg = $in{'curr_autharg'};
2422: }
2423: } else {
2424: $result = &mt('Currently using local (institutional) authentication.');
2425: return $result;
1.165 raeburn 2426: }
2427: }
1.586 raeburn 2428: } else {
2429: if ($authnum == 1) {
1.784 bisitz 2430: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2431: }
2432: }
2433: if (!$can_assign{'loc'}) {
2434: return;
1.587 raeburn 2435: } elsif ($authtype eq '') {
1.591 raeburn 2436: if (defined($in{'mode'})) {
1.587 raeburn 2437: if ($in{'mode'} eq 'modifycourse') {
2438: if ($authnum == 1) {
1.784 bisitz 2439: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2440: }
2441: }
2442: }
1.165 raeburn 2443: }
1.586 raeburn 2444: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2445: if ($authtype eq '') {
2446: $authtype = '<input type="radio" name="login" value="loc" '.
2447: $loccheck.' onchange="'.$jscall.'" onclick="'.
2448: $jscall.'" />';
2449: }
2450: $autharg = '<input type="text" size="10" name="locarg" value="'.
2451: $locarg.'" onchange="'.$jscall.'" />';
2452: $result = &mt('[_1] Local Authentication with argument [_2]',
2453: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2454: return $result;
2455: }
2456:
2457: sub authform_filesystem{
2458: my %in = (
2459: formname => 'document.cu',
2460: kerb_def_dom => 'MSU.EDU',
2461: @_,
2462: );
1.586 raeburn 2463: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2464: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2465: if (defined($in{'curr_authtype'})) {
2466: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2467: if ($can_assign{'fsys'}) {
1.772 bisitz 2468: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2469: if (defined($in{'mode'})) {
2470: if ($in{'mode'} eq 'modifyuser') {
2471: $fsyscheck = '';
2472: }
2473: }
1.586 raeburn 2474: } else {
2475: $result = &mt('Currently Filesystem Authenticated.');
2476: return $result;
2477: }
2478: }
2479: } else {
2480: if ($authnum == 1) {
1.784 bisitz 2481: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2482: }
2483: }
2484: if (!$can_assign{'fsys'}) {
2485: return;
1.587 raeburn 2486: } elsif ($authtype eq '') {
1.591 raeburn 2487: if (defined($in{'mode'})) {
1.587 raeburn 2488: if ($in{'mode'} eq 'modifycourse') {
2489: if ($authnum == 1) {
1.784 bisitz 2490: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2491: }
2492: }
2493: }
1.586 raeburn 2494: }
2495: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2496: if ($authtype eq '') {
2497: $authtype = '<input type="radio" name="login" value="fsys" '.
2498: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2499: $jscall.'" />';
2500: }
2501: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2502: ' onchange="'.$jscall.'" />';
2503: $result = &mt
1.144 matthew 2504: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2505: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2506: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2507: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2508: 'onchange="'.$jscall.'" />');
1.32 matthew 2509: return $result;
2510: }
2511:
1.586 raeburn 2512: sub get_assignable_auth {
2513: my ($dom) = @_;
2514: if ($dom eq '') {
2515: $dom = $env{'request.role.domain'};
2516: }
2517: my %can_assign = (
2518: krb4 => 1,
2519: krb5 => 1,
2520: int => 1,
2521: loc => 1,
2522: );
2523: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2524: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2525: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2526: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2527: my $context;
2528: if ($env{'request.role'} =~ /^au/) {
2529: $context = 'author';
2530: } elsif ($env{'request.role'} =~ /^dc/) {
2531: $context = 'domain';
2532: } elsif ($env{'request.course.id'}) {
2533: $context = 'course';
2534: }
2535: if ($context) {
2536: if (ref($authhash->{$context}) eq 'HASH') {
2537: %can_assign = %{$authhash->{$context}};
2538: }
2539: }
2540: }
2541: }
2542: my $authnum = 0;
2543: foreach my $key (keys(%can_assign)) {
2544: if ($can_assign{$key}) {
2545: $authnum ++;
2546: }
2547: }
2548: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2549: $authnum --;
2550: }
2551: return ($authnum,%can_assign);
2552: }
2553:
1.80 albertel 2554: ###############################################################
2555: ## Get Kerberos Defaults for Domain ##
2556: ###############################################################
2557: ##
2558: ## Returns default kerberos version and an associated argument
2559: ## as listed in file domain.tab. If not listed, provides
2560: ## appropriate default domain and kerberos version.
2561: ##
2562: #-------------------------------------------
2563:
2564: =pod
2565:
1.648 raeburn 2566: =item * &get_kerberos_defaults()
1.80 albertel 2567:
2568: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2569: version and domain. If not found, it defaults to version 4 and the
2570: domain of the server.
1.80 albertel 2571:
1.648 raeburn 2572: =over 4
2573:
1.80 albertel 2574: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2575:
1.648 raeburn 2576: =back
2577:
2578: =back
2579:
1.80 albertel 2580: =cut
2581:
2582: #-------------------------------------------
2583: sub get_kerberos_defaults {
2584: my $domain=shift;
1.641 raeburn 2585: my ($krbdef,$krbdefdom);
2586: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2587: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2588: $krbdef = $domdefaults{'auth_def'};
2589: $krbdefdom = $domdefaults{'auth_arg_def'};
2590: } else {
1.80 albertel 2591: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2592: my $krbdefdom=$1;
2593: $krbdefdom=~tr/a-z/A-Z/;
2594: $krbdef = "krb4";
2595: }
2596: return ($krbdef,$krbdefdom);
2597: }
1.112 bowersj2 2598:
1.32 matthew 2599:
1.46 matthew 2600: ###############################################################
2601: ## Thesaurus Functions ##
2602: ###############################################################
1.20 www 2603:
1.46 matthew 2604: =pod
1.20 www 2605:
1.112 bowersj2 2606: =head1 Thesaurus Functions
2607:
2608: =over 4
2609:
1.648 raeburn 2610: =item * &initialize_keywords()
1.46 matthew 2611:
2612: Initializes the package variable %Keywords if it is empty. Uses the
2613: package variable $thesaurus_db_file.
2614:
2615: =cut
2616:
2617: ###################################################
2618:
2619: sub initialize_keywords {
2620: return 1 if (scalar keys(%Keywords));
2621: # If we are here, %Keywords is empty, so fill it up
2622: # Make sure the file we need exists...
2623: if (! -e $thesaurus_db_file) {
2624: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2625: " failed because it does not exist");
2626: return 0;
2627: }
2628: # Set up the hash as a database
2629: my %thesaurus_db;
2630: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2631: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2632: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2633: $thesaurus_db_file);
2634: return 0;
2635: }
2636: # Get the average number of appearances of a word.
2637: my $avecount = $thesaurus_db{'average.count'};
2638: # Put keywords (those that appear > average) into %Keywords
2639: while (my ($word,$data)=each (%thesaurus_db)) {
2640: my ($count,undef) = split /:/,$data;
2641: $Keywords{$word}++ if ($count > $avecount);
2642: }
2643: untie %thesaurus_db;
2644: # Remove special values from %Keywords.
1.356 albertel 2645: foreach my $value ('total.count','average.count') {
2646: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2647: }
1.46 matthew 2648: return 1;
2649: }
2650:
2651: ###################################################
2652:
2653: =pod
2654:
1.648 raeburn 2655: =item * &keyword($word)
1.46 matthew 2656:
2657: Returns true if $word is a keyword. A keyword is a word that appears more
2658: than the average number of times in the thesaurus database. Calls
2659: &initialize_keywords
2660:
2661: =cut
2662:
2663: ###################################################
1.20 www 2664:
2665: sub keyword {
1.46 matthew 2666: return if (!&initialize_keywords());
2667: my $word=lc(shift());
2668: $word=~s/\W//g;
2669: return exists($Keywords{$word});
1.20 www 2670: }
1.46 matthew 2671:
2672: ###############################################################
2673:
2674: =pod
1.20 www 2675:
1.648 raeburn 2676: =item * &get_related_words()
1.46 matthew 2677:
1.160 matthew 2678: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2679: an array of words. If the keyword is not in the thesaurus, an empty array
2680: will be returned. The order of the words returned is determined by the
2681: database which holds them.
2682:
2683: Uses global $thesaurus_db_file.
2684:
2685: =cut
2686:
2687: ###############################################################
2688: sub get_related_words {
2689: my $keyword = shift;
2690: my %thesaurus_db;
2691: if (! -e $thesaurus_db_file) {
2692: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2693: "failed because the file does not exist");
2694: return ();
2695: }
2696: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2697: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2698: return ();
2699: }
2700: my @Words=();
1.429 www 2701: my $count=0;
1.46 matthew 2702: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2703: # The first element is the number of times
2704: # the word appears. We do not need it now.
1.429 www 2705: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2706: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2707: my $threshold=$mostfrequentcount/10;
2708: foreach my $possibleword (@RelatedWords) {
2709: my ($word,$wordcount)=split(/\,/,$possibleword);
2710: if ($wordcount>$threshold) {
2711: push(@Words,$word);
2712: $count++;
2713: if ($count>10) { last; }
2714: }
1.20 www 2715: }
2716: }
1.46 matthew 2717: untie %thesaurus_db;
2718: return @Words;
1.14 harris41 2719: }
1.46 matthew 2720:
1.112 bowersj2 2721: =pod
2722:
2723: =back
2724:
2725: =cut
1.61 www 2726:
2727: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2728: =pod
2729:
1.112 bowersj2 2730: =head1 User Name Functions
2731:
2732: =over 4
2733:
1.648 raeburn 2734: =item * &plainname($uname,$udom,$first)
1.81 albertel 2735:
1.112 bowersj2 2736: Takes a users logon name and returns it as a string in
1.226 albertel 2737: "first middle last generation" form
2738: if $first is set to 'lastname' then it returns it as
2739: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2740:
2741: =cut
1.61 www 2742:
1.295 www 2743:
1.81 albertel 2744: ###############################################################
1.61 www 2745: sub plainname {
1.226 albertel 2746: my ($uname,$udom,$first)=@_;
1.537 albertel 2747: return if (!defined($uname) || !defined($udom));
1.295 www 2748: my %names=&getnames($uname,$udom);
1.226 albertel 2749: my $name=&Apache::lonnet::format_name($names{'firstname'},
2750: $names{'middlename'},
2751: $names{'lastname'},
2752: $names{'generation'},$first);
2753: $name=~s/^\s+//;
1.62 www 2754: $name=~s/\s+$//;
2755: $name=~s/\s+/ /g;
1.353 albertel 2756: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2757: return $name;
1.61 www 2758: }
1.66 www 2759:
2760: # -------------------------------------------------------------------- Nickname
1.81 albertel 2761: =pod
2762:
1.648 raeburn 2763: =item * &nickname($uname,$udom)
1.81 albertel 2764:
2765: Gets a users name and returns it as a string as
2766:
2767: ""nickname""
1.66 www 2768:
1.81 albertel 2769: if the user has a nickname or
2770:
2771: "first middle last generation"
2772:
2773: if the user does not
2774:
2775: =cut
1.66 www 2776:
2777: sub nickname {
2778: my ($uname,$udom)=@_;
1.537 albertel 2779: return if (!defined($uname) || !defined($udom));
1.295 www 2780: my %names=&getnames($uname,$udom);
1.68 albertel 2781: my $name=$names{'nickname'};
1.66 www 2782: if ($name) {
2783: $name='"'.$name.'"';
2784: } else {
2785: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2786: $names{'lastname'}.' '.$names{'generation'};
2787: $name=~s/\s+$//;
2788: $name=~s/\s+/ /g;
2789: }
2790: return $name;
2791: }
2792:
1.295 www 2793: sub getnames {
2794: my ($uname,$udom)=@_;
1.537 albertel 2795: return if (!defined($uname) || !defined($udom));
1.433 albertel 2796: if ($udom eq 'public' && $uname eq 'public') {
2797: return ('lastname' => &mt('Public'));
2798: }
1.295 www 2799: my $id=$uname.':'.$udom;
2800: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2801: if ($cached) {
2802: return %{$names};
2803: } else {
2804: my %loadnames=&Apache::lonnet::get('environment',
2805: ['firstname','middlename','lastname','generation','nickname'],
2806: $udom,$uname);
2807: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2808: return %loadnames;
2809: }
2810: }
1.61 www 2811:
1.542 raeburn 2812: # -------------------------------------------------------------------- getemails
1.648 raeburn 2813:
1.542 raeburn 2814: =pod
2815:
1.648 raeburn 2816: =item * &getemails($uname,$udom)
1.542 raeburn 2817:
2818: Gets a user's email information and returns it as a hash with keys:
2819: notification, critnotification, permanentemail
2820:
2821: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2822: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2823:
1.648 raeburn 2824:
1.542 raeburn 2825: =cut
2826:
1.648 raeburn 2827:
1.466 albertel 2828: sub getemails {
2829: my ($uname,$udom)=@_;
2830: if ($udom eq 'public' && $uname eq 'public') {
2831: return;
2832: }
1.467 www 2833: if (!$udom) { $udom=$env{'user.domain'}; }
2834: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2835: my $id=$uname.':'.$udom;
2836: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2837: if ($cached) {
2838: return %{$names};
2839: } else {
2840: my %loadnames=&Apache::lonnet::get('environment',
2841: ['notification','critnotification',
2842: 'permanentemail'],
2843: $udom,$uname);
2844: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2845: return %loadnames;
2846: }
2847: }
2848:
1.551 albertel 2849: sub flush_email_cache {
2850: my ($uname,$udom)=@_;
2851: if (!$udom) { $udom =$env{'user.domain'}; }
2852: if (!$uname) { $uname=$env{'user.name'}; }
2853: return if ($udom eq 'public' && $uname eq 'public');
2854: my $id=$uname.':'.$udom;
2855: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2856: }
2857:
1.728 raeburn 2858: # -------------------------------------------------------------------- getlangs
2859:
2860: =pod
2861:
2862: =item * &getlangs($uname,$udom)
2863:
2864: Gets a user's language preference and returns it as a hash with key:
2865: language.
2866:
2867: =cut
2868:
2869:
2870: sub getlangs {
2871: my ($uname,$udom) = @_;
2872: if (!$udom) { $udom =$env{'user.domain'}; }
2873: if (!$uname) { $uname=$env{'user.name'}; }
2874: my $id=$uname.':'.$udom;
2875: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2876: if ($cached) {
2877: return %{$langs};
2878: } else {
2879: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2880: $udom,$uname);
2881: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2882: return %loadlangs;
2883: }
2884: }
2885:
2886: sub flush_langs_cache {
2887: my ($uname,$udom)=@_;
2888: if (!$udom) { $udom =$env{'user.domain'}; }
2889: if (!$uname) { $uname=$env{'user.name'}; }
2890: return if ($udom eq 'public' && $uname eq 'public');
2891: my $id=$uname.':'.$udom;
2892: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2893: }
2894:
1.61 www 2895: # ------------------------------------------------------------------ Screenname
1.81 albertel 2896:
2897: =pod
2898:
1.648 raeburn 2899: =item * &screenname($uname,$udom)
1.81 albertel 2900:
2901: Gets a users screenname and returns it as a string
2902:
2903: =cut
1.61 www 2904:
2905: sub screenname {
2906: my ($uname,$udom)=@_;
1.258 albertel 2907: if ($uname eq $env{'user.name'} &&
2908: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2909: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2910: return $names{'screenname'};
1.62 www 2911: }
2912:
1.212 albertel 2913:
1.802 bisitz 2914: # ------------------------------------------------------------- Confirm Wrapper
2915: =pod
2916:
2917: =item confirmwrapper
2918:
2919: Wrap messages about completion of operation in box
2920:
2921: =cut
2922:
2923: sub confirmwrapper {
2924: my ($message)=@_;
2925: if ($message) {
2926: return "\n".'<div class="LC_confirm_box">'."\n"
2927: .$message."\n"
2928: .'</div>'."\n";
2929: } else {
2930: return $message;
2931: }
2932: }
2933:
1.62 www 2934: # ------------------------------------------------------------- Message Wrapper
2935:
2936: sub messagewrapper {
1.369 www 2937: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2938: return
1.441 albertel 2939: '<a href="/adm/email?compose=individual&'.
2940: 'recname='.$username.'&recdom='.$domain.
2941: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2942: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2943: }
1.802 bisitz 2944:
1.74 www 2945: # --------------------------------------------------------------- Notes Wrapper
2946:
2947: sub noteswrapper {
2948: my ($link,$un,$do)=@_;
2949: return
2950: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2951: }
1.802 bisitz 2952:
1.62 www 2953: # ------------------------------------------------------------- Aboutme Wrapper
2954:
2955: sub aboutmewrapper {
1.166 www 2956: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2957: if (!defined($username) && !defined($domain)) {
2958: return;
2959: }
1.205 www 2960: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2961: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2962: }
2963:
2964: # ------------------------------------------------------------ Syllabus Wrapper
2965:
2966: sub syllabuswrapper {
1.707 bisitz 2967: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2968: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2969: }
1.14 harris41 2970:
1.802 bisitz 2971: # -----------------------------------------------------------------------------
2972:
1.208 matthew 2973: sub track_student_link {
1.887 ! raeburn 2974: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 2975: my $link ="/adm/trackstudent?";
1.208 matthew 2976: my $title = 'View recent activity';
2977: if (defined($sname) && $sname !~ /^\s*$/ &&
2978: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2979: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2980: $title .= ' of this student';
1.268 albertel 2981: }
1.208 matthew 2982: if (defined($target) && $target !~ /^\s*$/) {
2983: $target = qq{target="$target"};
2984: } else {
2985: $target = '';
2986: }
1.268 albertel 2987: if ($start) { $link.='&start='.$start; }
1.887 ! raeburn 2988: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 2989: $title = &mt($title);
2990: $linktext = &mt($linktext);
1.448 albertel 2991: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2992: &help_open_topic('View_recent_activity');
1.208 matthew 2993: }
2994:
1.781 raeburn 2995: sub slot_reservations_link {
2996: my ($linktext,$sname,$sdom,$target) = @_;
2997: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2998: my $title = 'View slot reservation history';
2999: if (defined($sname) && $sname !~ /^\s*$/ &&
3000: defined($sdom) && $sdom !~ /^\s*$/) {
3001: $link .= "&uname=$sname&udom=$sdom";
3002: $title .= ' of this student';
3003: }
3004: if (defined($target) && $target !~ /^\s*$/) {
3005: $target = qq{target="$target"};
3006: } else {
3007: $target = '';
3008: }
3009: $title = &mt($title);
3010: $linktext = &mt($linktext);
3011: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3012: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3013:
3014: }
3015:
1.508 www 3016: # ===================================================== Display a student photo
3017:
3018:
1.509 albertel 3019: sub student_image_tag {
1.508 www 3020: my ($domain,$user)=@_;
3021: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3022: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3023: return '<img src="'.$imgsrc.'" align="right" />';
3024: } else {
3025: return '';
3026: }
3027: }
3028:
1.112 bowersj2 3029: =pod
3030:
3031: =back
3032:
3033: =head1 Access .tab File Data
3034:
3035: =over 4
3036:
1.648 raeburn 3037: =item * &languageids()
1.112 bowersj2 3038:
3039: returns list of all language ids
3040:
3041: =cut
3042:
1.14 harris41 3043: sub languageids {
1.16 harris41 3044: return sort(keys(%language));
1.14 harris41 3045: }
3046:
1.112 bowersj2 3047: =pod
3048:
1.648 raeburn 3049: =item * &languagedescription()
1.112 bowersj2 3050:
3051: returns description of a specified language id
3052:
3053: =cut
3054:
1.14 harris41 3055: sub languagedescription {
1.125 www 3056: my $code=shift;
3057: return ($supported_language{$code}?'* ':'').
3058: $language{$code}.
1.126 www 3059: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3060: }
3061:
3062: sub plainlanguagedescription {
3063: my $code=shift;
3064: return $language{$code};
3065: }
3066:
3067: sub supportedlanguagecode {
3068: my $code=shift;
3069: return $supported_language{$code};
1.97 www 3070: }
3071:
1.112 bowersj2 3072: =pod
3073:
1.648 raeburn 3074: =item * ©rightids()
1.112 bowersj2 3075:
3076: returns list of all copyrights
3077:
3078: =cut
3079:
3080: sub copyrightids {
3081: return sort(keys(%cprtag));
3082: }
3083:
3084: =pod
3085:
1.648 raeburn 3086: =item * ©rightdescription()
1.112 bowersj2 3087:
3088: returns description of a specified copyright id
3089:
3090: =cut
3091:
3092: sub copyrightdescription {
1.166 www 3093: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3094: }
1.197 matthew 3095:
3096: =pod
3097:
1.648 raeburn 3098: =item * &source_copyrightids()
1.192 taceyjo1 3099:
3100: returns list of all source copyrights
3101:
3102: =cut
3103:
3104: sub source_copyrightids {
3105: return sort(keys(%scprtag));
3106: }
3107:
3108: =pod
3109:
1.648 raeburn 3110: =item * &source_copyrightdescription()
1.192 taceyjo1 3111:
3112: returns description of a specified source copyright id
3113:
3114: =cut
3115:
3116: sub source_copyrightdescription {
3117: return &mt($scprtag{shift(@_)});
3118: }
1.112 bowersj2 3119:
3120: =pod
3121:
1.648 raeburn 3122: =item * &filecategories()
1.112 bowersj2 3123:
3124: returns list of all file categories
3125:
3126: =cut
3127:
3128: sub filecategories {
3129: return sort(keys(%category_extensions));
3130: }
3131:
3132: =pod
3133:
1.648 raeburn 3134: =item * &filecategorytypes()
1.112 bowersj2 3135:
3136: returns list of file types belonging to a given file
3137: category
3138:
3139: =cut
3140:
3141: sub filecategorytypes {
1.356 albertel 3142: my ($cat) = @_;
3143: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3144: }
3145:
3146: =pod
3147:
1.648 raeburn 3148: =item * &fileembstyle()
1.112 bowersj2 3149:
3150: returns embedding style for a specified file type
3151:
3152: =cut
3153:
3154: sub fileembstyle {
3155: return $fe{lc(shift(@_))};
1.169 www 3156: }
3157:
1.351 www 3158: sub filemimetype {
3159: return $fm{lc(shift(@_))};
3160: }
3161:
1.169 www 3162:
3163: sub filecategoryselect {
3164: my ($name,$value)=@_;
1.189 matthew 3165: return &select_form($value,$name,
1.169 www 3166: '' => &mt('Any category'),
3167: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3168: }
3169:
3170: =pod
3171:
1.648 raeburn 3172: =item * &filedescription()
1.112 bowersj2 3173:
3174: returns description for a specified file type
3175:
3176: =cut
3177:
3178: sub filedescription {
1.188 matthew 3179: my $file_description = $fd{lc(shift())};
3180: $file_description =~ s:([\[\]]):~$1:g;
3181: return &mt($file_description);
1.112 bowersj2 3182: }
3183:
3184: =pod
3185:
1.648 raeburn 3186: =item * &filedescriptionex()
1.112 bowersj2 3187:
3188: returns description for a specified file type with
3189: extra formatting
3190:
3191: =cut
3192:
3193: sub filedescriptionex {
3194: my $ex=shift;
1.188 matthew 3195: my $file_description = $fd{lc($ex)};
3196: $file_description =~ s:([\[\]]):~$1:g;
3197: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3198: }
3199:
3200: # End of .tab access
3201: =pod
3202:
3203: =back
3204:
3205: =cut
3206:
3207: # ------------------------------------------------------------------ File Types
3208: sub fileextensions {
3209: return sort(keys(%fe));
3210: }
3211:
1.97 www 3212: # ----------------------------------------------------------- Display Languages
3213: # returns a hash with all desired display languages
3214: #
3215:
3216: sub display_languages {
3217: my %languages=();
1.695 raeburn 3218: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3219: $languages{$lang}=1;
1.97 www 3220: }
3221: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3222: if ($env{'form.displaylanguage'}) {
1.356 albertel 3223: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3224: $languages{$lang}=1;
1.97 www 3225: }
3226: }
3227: return %languages;
1.14 harris41 3228: }
3229:
1.582 albertel 3230: sub languages {
3231: my ($possible_langs) = @_;
1.695 raeburn 3232: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3233: if (!ref($possible_langs)) {
3234: if( wantarray ) {
3235: return @preferred_langs;
3236: } else {
3237: return $preferred_langs[0];
3238: }
3239: }
3240: my %possibilities = map { $_ => 1 } (@$possible_langs);
3241: my @preferred_possibilities;
3242: foreach my $preferred_lang (@preferred_langs) {
3243: if (exists($possibilities{$preferred_lang})) {
3244: push(@preferred_possibilities, $preferred_lang);
3245: }
3246: }
3247: if( wantarray ) {
3248: return @preferred_possibilities;
3249: }
3250: return $preferred_possibilities[0];
3251: }
3252:
1.742 raeburn 3253: sub user_lang {
3254: my ($touname,$toudom,$fromcid) = @_;
3255: my @userlangs;
3256: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3257: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3258: $env{'course.'.$fromcid.'.languages'}));
3259: } else {
3260: my %langhash = &getlangs($touname,$toudom);
3261: if ($langhash{'languages'} ne '') {
3262: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3263: } else {
3264: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3265: if ($domdefs{'lang_def'} ne '') {
3266: @userlangs = ($domdefs{'lang_def'});
3267: }
3268: }
3269: }
3270: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3271: my $user_lh = Apache::localize->get_handle(@languages);
3272: return $user_lh;
3273: }
3274:
3275:
1.112 bowersj2 3276: ###############################################################
3277: ## Student Answer Attempts ##
3278: ###############################################################
3279:
3280: =pod
3281:
3282: =head1 Alternate Problem Views
3283:
3284: =over 4
3285:
1.648 raeburn 3286: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3287: $getattempt, $regexp, $gradesub)
3288:
3289: Return string with previous attempt on problem. Arguments:
3290:
3291: =over 4
3292:
3293: =item * $symb: Problem, including path
3294:
3295: =item * $username: username of the desired student
3296:
3297: =item * $domain: domain of the desired student
1.14 harris41 3298:
1.112 bowersj2 3299: =item * $course: Course ID
1.14 harris41 3300:
1.112 bowersj2 3301: =item * $getattempt: Leave blank for all attempts, otherwise put
3302: something
1.14 harris41 3303:
1.112 bowersj2 3304: =item * $regexp: if string matches this regexp, the string will be
3305: sent to $gradesub
1.14 harris41 3306:
1.112 bowersj2 3307: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3308:
1.112 bowersj2 3309: =back
1.14 harris41 3310:
1.112 bowersj2 3311: The output string is a table containing all desired attempts, if any.
1.16 harris41 3312:
1.112 bowersj2 3313: =cut
1.1 albertel 3314:
3315: sub get_previous_attempt {
1.43 ng 3316: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3317: my $prevattempts='';
1.43 ng 3318: no strict 'refs';
1.1 albertel 3319: if ($symb) {
1.3 albertel 3320: my (%returnhash)=
3321: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3322: if ($returnhash{'version'}) {
3323: my %lasthash=();
3324: my $version;
3325: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3326: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3327: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3328: }
1.1 albertel 3329: }
1.596 albertel 3330: $prevattempts=&start_data_table().&start_data_table_header_row();
3331: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3332: foreach my $key (sort(keys(%lasthash))) {
3333: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3334: if ($#parts > 0) {
1.31 albertel 3335: my $data=$parts[-1];
3336: pop(@parts);
1.596 albertel 3337: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3338: } else {
1.41 ng 3339: if ($#parts == 0) {
3340: $prevattempts.='<th>'.$parts[0].'</th>';
3341: } else {
3342: $prevattempts.='<th>'.$ign.'</th>';
3343: }
1.31 albertel 3344: }
1.16 harris41 3345: }
1.596 albertel 3346: $prevattempts.=&end_data_table_header_row();
1.40 ng 3347: if ($getattempt eq '') {
3348: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3349: $prevattempts.=&start_data_table_row().
3350: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3351: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3352: my $value = &format_previous_attempt_value($key,
3353: $returnhash{$version.':'.$key});
3354: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3355: }
1.596 albertel 3356: $prevattempts.=&end_data_table_row();
1.40 ng 3357: }
1.1 albertel 3358: }
1.596 albertel 3359: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3360: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3361: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3362: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3363: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3364: }
1.596 albertel 3365: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3366: } else {
1.596 albertel 3367: $prevattempts=
3368: &start_data_table().&start_data_table_row().
3369: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3370: &end_data_table_row().&end_data_table();
1.1 albertel 3371: }
3372: } else {
1.596 albertel 3373: $prevattempts=
3374: &start_data_table().&start_data_table_row().
3375: '<td>'.&mt('No data.').'</td>'.
3376: &end_data_table_row().&end_data_table();
1.1 albertel 3377: }
1.10 albertel 3378: }
3379:
1.581 albertel 3380: sub format_previous_attempt_value {
3381: my ($key,$value) = @_;
3382: if ($key =~ /timestamp/) {
3383: $value = &Apache::lonlocal::locallocaltime($value);
3384: } elsif (ref($value) eq 'ARRAY') {
3385: $value = '('.join(', ', @{ $value }).')';
3386: } else {
3387: $value = &unescape($value);
3388: }
3389: return $value;
3390: }
3391:
3392:
1.107 albertel 3393: sub relative_to_absolute {
3394: my ($url,$output)=@_;
3395: my $parser=HTML::TokeParser->new(\$output);
3396: my $token;
3397: my $thisdir=$url;
3398: my @rlinks=();
3399: while ($token=$parser->get_token) {
3400: if ($token->[0] eq 'S') {
3401: if ($token->[1] eq 'a') {
3402: if ($token->[2]->{'href'}) {
3403: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3404: }
3405: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3406: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3407: } elsif ($token->[1] eq 'base') {
3408: $thisdir=$token->[2]->{'href'};
3409: }
3410: }
3411: }
3412: $thisdir=~s-/[^/]*$--;
1.356 albertel 3413: foreach my $link (@rlinks) {
1.726 raeburn 3414: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3415: ($link=~/^\//) ||
3416: ($link=~/^javascript:/i) ||
3417: ($link=~/^mailto:/i) ||
3418: ($link=~/^\#/)) {
3419: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3420: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3421: }
3422: }
3423: # -------------------------------------------------- Deal with Applet codebases
3424: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3425: return $output;
3426: }
3427:
1.112 bowersj2 3428: =pod
3429:
1.648 raeburn 3430: =item * &get_student_view()
1.112 bowersj2 3431:
3432: show a snapshot of what student was looking at
3433:
3434: =cut
3435:
1.10 albertel 3436: sub get_student_view {
1.186 albertel 3437: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3438: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3439: my (%form);
1.10 albertel 3440: my @elements=('symb','courseid','domain','username');
3441: foreach my $element (@elements) {
1.186 albertel 3442: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3443: }
1.186 albertel 3444: if (defined($moreenv)) {
3445: %form=(%form,%{$moreenv});
3446: }
1.236 albertel 3447: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3448: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3449: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3450: $userview=~s/\<body[^\>]*\>//gi;
3451: $userview=~s/\<\/body\>//gi;
3452: $userview=~s/\<html\>//gi;
3453: $userview=~s/\<\/html\>//gi;
3454: $userview=~s/\<head\>//gi;
3455: $userview=~s/\<\/head\>//gi;
3456: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3457: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3458: if (wantarray) {
3459: return ($userview,$response);
3460: } else {
3461: return $userview;
3462: }
3463: }
3464:
3465: sub get_student_view_with_retries {
3466: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3467:
3468: my $ok = 0; # True if we got a good response.
3469: my $content;
3470: my $response;
3471:
3472: # Try to get the student_view done. within the retries count:
3473:
3474: do {
3475: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3476: $ok = $response->is_success;
3477: if (!$ok) {
3478: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3479: }
3480: $retries--;
3481: } while (!$ok && ($retries > 0));
3482:
3483: if (!$ok) {
3484: $content = ''; # On error return an empty content.
3485: }
1.651 www 3486: if (wantarray) {
3487: return ($content, $response);
3488: } else {
3489: return $content;
3490: }
1.11 albertel 3491: }
3492:
1.112 bowersj2 3493: =pod
3494:
1.648 raeburn 3495: =item * &get_student_answers()
1.112 bowersj2 3496:
3497: show a snapshot of how student was answering problem
3498:
3499: =cut
3500:
1.11 albertel 3501: sub get_student_answers {
1.100 sakharuk 3502: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3503: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3504: my (%moreenv);
1.11 albertel 3505: my @elements=('symb','courseid','domain','username');
3506: foreach my $element (@elements) {
1.186 albertel 3507: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3508: }
1.186 albertel 3509: $moreenv{'grade_target'}='answer';
3510: %moreenv=(%form,%moreenv);
1.497 raeburn 3511: $feedurl = &Apache::lonnet::clutter($feedurl);
3512: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3513: return $userview;
1.1 albertel 3514: }
1.116 albertel 3515:
3516: =pod
3517:
3518: =item * &submlink()
3519:
1.242 albertel 3520: Inputs: $text $uname $udom $symb $target
1.116 albertel 3521:
3522: Returns: A link to grades.pm such as to see the SUBM view of a student
3523:
3524: =cut
3525:
3526: ###############################################
3527: sub submlink {
1.242 albertel 3528: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3529: if (!($uname && $udom)) {
3530: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3531: &Apache::lonnet::whichuser($symb);
1.116 albertel 3532: if (!$symb) { $symb=$cursymb; }
3533: }
1.254 matthew 3534: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3535: $symb=&escape($symb);
1.242 albertel 3536: if ($target) { $target="target=\"$target\""; }
3537: return '<a href="/adm/grades?&command=submission&'.
3538: 'symb='.$symb.'&student='.$uname.
3539: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3540: }
3541: ##############################################
3542:
3543: =pod
3544:
3545: =item * &pgrdlink()
3546:
3547: Inputs: $text $uname $udom $symb $target
3548:
3549: Returns: A link to grades.pm such as to see the PGRD view of a student
3550:
3551: =cut
3552:
3553: ###############################################
3554: sub pgrdlink {
3555: my $link=&submlink(@_);
3556: $link=~s/(&command=submission)/$1&showgrading=yes/;
3557: return $link;
3558: }
3559: ##############################################
3560:
3561: =pod
3562:
3563: =item * &pprmlink()
3564:
3565: Inputs: $text $uname $udom $symb $target
3566:
3567: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3568: student and a specific resource
1.242 albertel 3569:
3570: =cut
3571:
3572: ###############################################
3573: sub pprmlink {
3574: my ($text,$uname,$udom,$symb,$target)=@_;
3575: if (!($uname && $udom)) {
3576: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3577: &Apache::lonnet::whichuser($symb);
1.242 albertel 3578: if (!$symb) { $symb=$cursymb; }
3579: }
1.254 matthew 3580: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3581: $symb=&escape($symb);
1.242 albertel 3582: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3583: return '<a href="/adm/parmset?command=set&'.
3584: 'symb='.$symb.'&uname='.$uname.
3585: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3586: }
3587: ##############################################
1.37 matthew 3588:
1.112 bowersj2 3589: =pod
3590:
3591: =back
3592:
3593: =cut
3594:
1.37 matthew 3595: ###############################################
1.51 www 3596:
3597:
3598: sub timehash {
1.687 raeburn 3599: my ($thistime) = @_;
3600: my $timezone = &Apache::lonlocal::gettimezone();
3601: my $dt = DateTime->from_epoch(epoch => $thistime)
3602: ->set_time_zone($timezone);
3603: my $wday = $dt->day_of_week();
3604: if ($wday == 7) { $wday = 0; }
3605: return ( 'second' => $dt->second(),
3606: 'minute' => $dt->minute(),
3607: 'hour' => $dt->hour(),
3608: 'day' => $dt->day_of_month(),
3609: 'month' => $dt->month(),
3610: 'year' => $dt->year(),
3611: 'weekday' => $wday,
3612: 'dayyear' => $dt->day_of_year(),
3613: 'dlsav' => $dt->is_dst() );
1.51 www 3614: }
3615:
1.370 www 3616: sub utc_string {
3617: my ($date)=@_;
1.371 www 3618: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3619: }
3620:
1.51 www 3621: sub maketime {
3622: my %th=@_;
1.687 raeburn 3623: my ($epoch_time,$timezone,$dt);
3624: $timezone = &Apache::lonlocal::gettimezone();
3625: eval {
3626: $dt = DateTime->new( year => $th{'year'},
3627: month => $th{'month'},
3628: day => $th{'day'},
3629: hour => $th{'hour'},
3630: minute => $th{'minute'},
3631: second => $th{'second'},
3632: time_zone => $timezone,
3633: );
3634: };
3635: if (!$@) {
3636: $epoch_time = $dt->epoch;
3637: if ($epoch_time) {
3638: return $epoch_time;
3639: }
3640: }
1.51 www 3641: return POSIX::mktime(
3642: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3643: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3644: }
3645:
3646: #########################################
1.51 www 3647:
3648: sub findallcourses {
1.482 raeburn 3649: my ($roles,$uname,$udom) = @_;
1.355 albertel 3650: my %roles;
3651: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3652: my %courses;
1.51 www 3653: my $now=time;
1.482 raeburn 3654: if (!defined($uname)) {
3655: $uname = $env{'user.name'};
3656: }
3657: if (!defined($udom)) {
3658: $udom = $env{'user.domain'};
3659: }
3660: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3661: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3662: if (!%roles) {
3663: %roles = (
3664: cc => 1,
3665: in => 1,
3666: ep => 1,
3667: ta => 1,
3668: cr => 1,
3669: st => 1,
3670: );
3671: }
3672: foreach my $entry (keys(%roleshash)) {
3673: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3674: if ($trole =~ /^cr/) {
3675: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3676: } else {
3677: next if (!exists($roles{$trole}));
3678: }
3679: if ($tend) {
3680: next if ($tend < $now);
3681: }
3682: if ($tstart) {
3683: next if ($tstart > $now);
3684: }
3685: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3686: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3687: if ($secpart eq '') {
3688: ($cnum,$role) = split(/_/,$cnumpart);
3689: $sec = 'none';
3690: $realsec = '';
3691: } else {
3692: $cnum = $cnumpart;
3693: ($sec,$role) = split(/_/,$secpart);
3694: $realsec = $sec;
1.490 raeburn 3695: }
1.482 raeburn 3696: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3697: }
3698: } else {
3699: foreach my $key (keys(%env)) {
1.483 albertel 3700: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3701: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3702: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3703: next if ($role eq 'ca' || $role eq 'aa');
3704: next if (%roles && !exists($roles{$role}));
3705: my ($starttime,$endtime)=split(/\./,$env{$key});
3706: my $active=1;
3707: if ($starttime) {
3708: if ($now<$starttime) { $active=0; }
3709: }
3710: if ($endtime) {
3711: if ($now>$endtime) { $active=0; }
3712: }
3713: if ($active) {
3714: if ($sec eq '') {
3715: $sec = 'none';
3716: }
3717: $courses{$cdom.'_'.$cnum}{$sec} =
3718: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3719: }
3720: }
1.51 www 3721: }
3722: }
1.474 raeburn 3723: return %courses;
1.51 www 3724: }
1.37 matthew 3725:
1.54 www 3726: ###############################################
1.474 raeburn 3727:
3728: sub blockcheck {
1.482 raeburn 3729: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3730:
3731: if (!defined($udom)) {
3732: $udom = $env{'user.domain'};
3733: }
3734: if (!defined($uname)) {
3735: $uname = $env{'user.name'};
3736: }
3737:
3738: # If uname and udom are for a course, check for blocks in the course.
3739:
3740: if (&Apache::lonnet::is_course($udom,$uname)) {
3741: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3742: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3743: return ($startblock,$endblock);
3744: }
1.474 raeburn 3745:
1.502 raeburn 3746: my $startblock = 0;
3747: my $endblock = 0;
1.482 raeburn 3748: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3749:
1.490 raeburn 3750: # If uname is for a user, and activity is course-specific, i.e.,
3751: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3752:
1.490 raeburn 3753: if (($activity eq 'boards' || $activity eq 'chat' ||
3754: $activity eq 'groups') && ($env{'request.course.id'})) {
3755: foreach my $key (keys(%live_courses)) {
3756: if ($key ne $env{'request.course.id'}) {
3757: delete($live_courses{$key});
3758: }
3759: }
3760: }
3761:
3762: my $otheruser = 0;
3763: my %own_courses;
3764: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3765: # Resource belongs to user other than current user.
3766: $otheruser = 1;
3767: # Gather courses for current user
3768: %own_courses =
3769: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3770: }
3771:
3772: # Gather active course roles - course coordinator, instructor,
3773: # exam proctor, ta, student, or custom role.
1.474 raeburn 3774:
3775: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3776: my ($cdom,$cnum);
3777: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3778: $cdom = $env{'course.'.$course.'.domain'};
3779: $cnum = $env{'course.'.$course.'.num'};
3780: } else {
1.490 raeburn 3781: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3782: }
3783: my $no_ownblock = 0;
3784: my $no_userblock = 0;
1.533 raeburn 3785: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3786: # Check if current user has 'evb' priv for this
3787: if (defined($own_courses{$course})) {
3788: foreach my $sec (keys(%{$own_courses{$course}})) {
3789: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3790: if ($sec ne 'none') {
3791: $checkrole .= '/'.$sec;
3792: }
3793: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3794: $no_ownblock = 1;
3795: last;
3796: }
3797: }
3798: }
3799: # if they have 'evb' priv and are currently not playing student
3800: next if (($no_ownblock) &&
3801: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3802: }
1.474 raeburn 3803: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3804: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3805: if ($sec ne 'none') {
1.482 raeburn 3806: $checkrole .= '/'.$sec;
1.474 raeburn 3807: }
1.490 raeburn 3808: if ($otheruser) {
3809: # Resource belongs to user other than current user.
3810: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3811: my ($trole,$tdom,$tnum,$tsec);
3812: my $entry = $live_courses{$course}{$sec};
3813: if ($entry =~ /^cr/) {
3814: ($trole,$tdom,$tnum,$tsec) =
3815: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3816: } else {
3817: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3818: }
3819: my ($spec,$area,$trest,%allroles,%userroles);
3820: $area = '/'.$tdom.'/'.$tnum;
3821: $trest = $tnum;
3822: if ($tsec ne '') {
3823: $area .= '/'.$tsec;
3824: $trest .= '/'.$tsec;
3825: }
3826: $spec = $trole.'.'.$area;
3827: if ($trole =~ /^cr/) {
3828: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3829: $tdom,$spec,$trest,$area);
3830: } else {
3831: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3832: $tdom,$spec,$trest,$area);
3833: }
3834: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3835: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3836: if ($1) {
3837: $no_userblock = 1;
3838: last;
3839: }
3840: }
1.490 raeburn 3841: } else {
3842: # Resource belongs to current user
3843: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3844: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3845: $no_ownblock = 1;
3846: last;
3847: }
1.474 raeburn 3848: }
3849: }
3850: # if they have the evb priv and are currently not playing student
1.482 raeburn 3851: next if (($no_ownblock) &&
1.491 albertel 3852: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3853: next if ($no_userblock);
1.474 raeburn 3854:
1.866 kalberla 3855: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3856: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3857:
3858: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3859: if (($start != 0) &&
3860: (($startblock == 0) || ($startblock > $start))) {
3861: $startblock = $start;
3862: }
3863: if (($end != 0) &&
3864: (($endblock == 0) || ($endblock < $end))) {
3865: $endblock = $end;
3866: }
1.490 raeburn 3867: }
3868: return ($startblock,$endblock);
3869: }
3870:
3871: sub get_blocks {
3872: my ($setters,$activity,$cdom,$cnum) = @_;
3873: my $startblock = 0;
3874: my $endblock = 0;
3875: my $course = $cdom.'_'.$cnum;
3876: $setters->{$course} = {};
3877: $setters->{$course}{'staff'} = [];
3878: $setters->{$course}{'times'} = [];
3879: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3880: foreach my $record (keys(%records)) {
3881: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3882: if ($start <= time && $end >= time) {
3883: my ($staff_name,$staff_dom,$title,$blocks) =
3884: &parse_block_record($records{$record});
3885: if ($blocks->{$activity} eq 'on') {
3886: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3887: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3888: if ( ($startblock == 0) || ($startblock > $start) ) {
3889: $startblock = $start;
1.490 raeburn 3890: }
1.491 albertel 3891: if ( ($endblock == 0) || ($endblock < $end) ) {
3892: $endblock = $end;
1.474 raeburn 3893: }
3894: }
3895: }
3896: }
3897: return ($startblock,$endblock);
3898: }
3899:
3900: sub parse_block_record {
3901: my ($record) = @_;
3902: my ($setuname,$setudom,$title,$blocks);
3903: if (ref($record) eq 'HASH') {
3904: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3905: $title = &unescape($record->{'event'});
3906: $blocks = $record->{'blocks'};
3907: } else {
3908: my @data = split(/:/,$record,3);
3909: if (scalar(@data) eq 2) {
3910: $title = $data[1];
3911: ($setuname,$setudom) = split(/@/,$data[0]);
3912: } else {
3913: ($setuname,$setudom,$title) = @data;
3914: }
3915: $blocks = { 'com' => 'on' };
3916: }
3917: return ($setuname,$setudom,$title,$blocks);
3918: }
3919:
1.854 kalberla 3920: sub blocking_status {
1.867 kalberla 3921: my $blocked;
1.854 kalberla 3922: my ($activity,$uname,$udom) = @_;
1.867 kalberla 3923: my %setters;
3924: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3925: if ($startblock && $endblock) {
3926: $blocked = 1;
3927: }
1.854 kalberla 3928: if(!wantarray) {
3929: return $blocked;
3930: }
3931: my $output;
3932: my $querystring;
3933: $querystring = "?activity=$activity";
3934:
3935: $output .= <<"END_MYBLOCK";
3936: <script type="text/javascript">
3937: // <![CDATA[
3938: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3939: var options = "width=" + w + ",height=" + h + ",";
3940: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3941: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3942: var newWin = window.open(url, wdwName, options);
3943: newWin.focus();
3944: }
3945:
3946: // ]]>
3947: </script>
3948: END_MYBLOCK
3949: my $popupUrl = "/adm/blockingstatus/$querystring";
1.867 kalberla 3950: $output .= <<"END_BLOCK";
3951: <div class='LC_comblock'>
1.869 kalberla 3952: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
3953: title='Communication Blocked'>
3954: <img class='LC_noBorder LC_middle' title='Communication Blocked' src='/res/adm/pages/comblock.png' alt='Communication Blocked'/></a>
3955: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
3956: title='Communication Blocked'>Communication Blocked</a>
1.867 kalberla 3957: </div>
3958:
3959: END_BLOCK
1.474 raeburn 3960:
1.854 kalberla 3961: return ($blocked, $output);
3962: }
1.490 raeburn 3963:
1.60 matthew 3964: ###############################################
3965:
1.682 raeburn 3966: sub check_ip_acc {
3967: my ($acc)=@_;
3968: &Apache::lonxml::debug("acc is $acc");
3969: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3970: return 1;
3971: }
3972: my $allowed=0;
3973: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3974:
3975: my $name;
3976: foreach my $pattern (split(',',$acc)) {
3977: $pattern =~ s/^\s*//;
3978: $pattern =~ s/\s*$//;
3979: if ($pattern =~ /\*$/) {
3980: #35.8.*
3981: $pattern=~s/\*//;
3982: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3983: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3984: #35.8.3.[34-56]
3985: my $low=$2;
3986: my $high=$3;
3987: $pattern=$1;
3988: if ($ip =~ /^\Q$pattern\E/) {
3989: my $last=(split(/\./,$ip))[3];
3990: if ($last <=$high && $last >=$low) { $allowed=1; }
3991: }
3992: } elsif ($pattern =~ /^\*/) {
3993: #*.msu.edu
3994: $pattern=~s/\*//;
3995: if (!defined($name)) {
3996: use Socket;
3997: my $netaddr=inet_aton($ip);
3998: ($name)=gethostbyaddr($netaddr,AF_INET);
3999: }
4000: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4001: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4002: #127.0.0.1
4003: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4004: } else {
4005: #some.name.com
4006: if (!defined($name)) {
4007: use Socket;
4008: my $netaddr=inet_aton($ip);
4009: ($name)=gethostbyaddr($netaddr,AF_INET);
4010: }
4011: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4012: }
4013: if ($allowed) { last; }
4014: }
4015: return $allowed;
4016: }
4017:
4018: ###############################################
4019:
1.60 matthew 4020: =pod
4021:
1.112 bowersj2 4022: =head1 Domain Template Functions
4023:
4024: =over 4
4025:
4026: =item * &determinedomain()
1.60 matthew 4027:
4028: Inputs: $domain (usually will be undef)
4029:
1.63 www 4030: Returns: Determines which domain should be used for designs
1.60 matthew 4031:
4032: =cut
1.54 www 4033:
1.60 matthew 4034: ###############################################
1.63 www 4035: sub determinedomain {
4036: my $domain=shift;
1.531 albertel 4037: if (! $domain) {
1.60 matthew 4038: # Determine domain if we have not been given one
4039: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 4040: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4041: if ($env{'request.role.domain'}) {
4042: $domain=$env{'request.role.domain'};
1.60 matthew 4043: }
4044: }
1.63 www 4045: return $domain;
4046: }
4047: ###############################################
1.517 raeburn 4048:
1.518 albertel 4049: sub devalidate_domconfig_cache {
4050: my ($udom)=@_;
4051: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4052: }
4053:
4054: # ---------------------- Get domain configuration for a domain
4055: sub get_domainconf {
4056: my ($udom) = @_;
4057: my $cachetime=1800;
4058: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4059: if (defined($cached)) { return %{$result}; }
4060:
4061: my %domconfig = &Apache::lonnet::get_dom('configuration',
4062: ['login','rolecolors'],$udom);
1.632 raeburn 4063: my (%designhash,%legacy);
1.518 albertel 4064: if (keys(%domconfig) > 0) {
4065: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4066: if (keys(%{$domconfig{'login'}})) {
4067: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4068: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4069: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4070: $designhash{$udom.'.login.'.$key.'_'.$img} =
4071: $domconfig{'login'}{$key}{$img};
4072: }
4073: } else {
4074: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4075: }
1.632 raeburn 4076: }
4077: } else {
4078: $legacy{'login'} = 1;
1.518 albertel 4079: }
1.632 raeburn 4080: } else {
4081: $legacy{'login'} = 1;
1.518 albertel 4082: }
4083: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4084: if (keys(%{$domconfig{'rolecolors'}})) {
4085: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4086: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4087: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4088: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4089: }
1.518 albertel 4090: }
4091: }
1.632 raeburn 4092: } else {
4093: $legacy{'rolecolors'} = 1;
1.518 albertel 4094: }
1.632 raeburn 4095: } else {
4096: $legacy{'rolecolors'} = 1;
1.518 albertel 4097: }
1.632 raeburn 4098: if (keys(%legacy) > 0) {
4099: my %legacyhash = &get_legacy_domconf($udom);
4100: foreach my $item (keys(%legacyhash)) {
4101: if ($item =~ /^\Q$udom\E\.login/) {
4102: if ($legacy{'login'}) {
4103: $designhash{$item} = $legacyhash{$item};
4104: }
4105: } else {
4106: if ($legacy{'rolecolors'}) {
4107: $designhash{$item} = $legacyhash{$item};
4108: }
1.518 albertel 4109: }
4110: }
4111: }
1.632 raeburn 4112: } else {
4113: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4114: }
4115: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4116: $cachetime);
4117: return %designhash;
4118: }
4119:
1.632 raeburn 4120: sub get_legacy_domconf {
4121: my ($udom) = @_;
4122: my %legacyhash;
4123: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4124: my $designfile = $designdir.'/'.$udom.'.tab';
4125: if (-e $designfile) {
4126: if ( open (my $fh,"<$designfile") ) {
4127: while (my $line = <$fh>) {
4128: next if ($line =~ /^\#/);
4129: chomp($line);
4130: my ($key,$val)=(split(/\=/,$line));
4131: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4132: }
4133: close($fh);
4134: }
4135: }
4136: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4137: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4138: }
4139: return %legacyhash;
4140: }
4141:
1.63 www 4142: =pod
4143:
1.112 bowersj2 4144: =item * &domainlogo()
1.63 www 4145:
4146: Inputs: $domain (usually will be undef)
4147:
4148: Returns: A link to a domain logo, if the domain logo exists.
4149: If the domain logo does not exist, a description of the domain.
4150:
4151: =cut
1.112 bowersj2 4152:
1.63 www 4153: ###############################################
4154: sub domainlogo {
1.517 raeburn 4155: my $domain = &determinedomain(shift);
1.518 albertel 4156: my %designhash = &get_domainconf($domain);
1.517 raeburn 4157: # See if there is a logo
4158: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4159: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4160: if ($imgsrc =~ m{^/(adm|res)/}) {
4161: if ($imgsrc =~ m{^/res/}) {
4162: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4163: &Apache::lonnet::repcopy($local_name);
4164: }
4165: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4166: }
4167: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4168: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4169: return &Apache::lonnet::domain($domain,'description');
1.59 www 4170: } else {
1.60 matthew 4171: return '';
1.59 www 4172: }
4173: }
1.63 www 4174: ##############################################
4175:
4176: =pod
4177:
1.112 bowersj2 4178: =item * &designparm()
1.63 www 4179:
4180: Inputs: $which parameter; $domain (usually will be undef)
4181:
4182: Returns: value of designparamter $which
4183:
4184: =cut
1.112 bowersj2 4185:
1.397 albertel 4186:
1.400 albertel 4187: ##############################################
1.397 albertel 4188: sub designparm {
4189: my ($which,$domain)=@_;
4190: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4191: return $env{'environment.color.'.$which};
1.96 www 4192: }
1.63 www 4193: $domain=&determinedomain($domain);
1.518 albertel 4194: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4195: my $output;
1.517 raeburn 4196: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4197: $output = $domdesign{$domain.'.'.$which};
1.63 www 4198: } else {
1.520 raeburn 4199: $output = $defaultdesign{$which};
4200: }
4201: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4202: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4203: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4204: if ($output =~ m{^/res/}) {
4205: my $local_name = &Apache::lonnet::filelocation('',$output);
4206: &Apache::lonnet::repcopy($local_name);
4207: }
1.520 raeburn 4208: $output = &lonhttpdurl($output);
4209: }
1.63 www 4210: }
1.520 raeburn 4211: return $output;
1.63 www 4212: }
1.59 www 4213:
1.822 bisitz 4214: ##############################################
4215: =pod
4216:
1.832 bisitz 4217: =item * &authorspace()
4218:
4219: Inputs: ./.
4220:
4221: Returns: Path to the Construction Space of the current user's
4222: accessed author space
4223: The author space will be that of the current user
4224: when accessing the own author space
4225: and that of the co-author/assistent co-author
4226: when accessing the co-author's/assistent co-author's
4227: space
4228:
4229: =cut
4230:
4231: sub authorspace {
4232: my $caname = '';
4233: if ($env{'request.role'} =~ /^ca|^aa/) {
4234: (undef,$caname) =
4235: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4236: } else {
4237: $caname = $env{'user.name'};
4238: }
4239: return '/priv/'.$caname.'/';
4240: }
4241:
4242: ##############################################
4243: =pod
4244:
1.822 bisitz 4245: =item * &head_subbox()
4246:
4247: Inputs: $content (contains HTML code with page functions, etc.)
4248:
4249: Returns: HTML div with $content
4250: To be included in page header
4251:
4252: =cut
4253:
4254: sub head_subbox {
4255: my ($content)=@_;
4256: my $output =
1.844 bisitz 4257: '<div id="LC_head_subbox">'
1.822 bisitz 4258: .$content
4259: .'</div>'
4260: }
4261:
4262: ##############################################
4263: =pod
4264:
4265: =item * &CSTR_pageheader()
4266:
4267: Inputs: ./.
4268:
4269: Returns: HTML div with CSTR path and recent box
4270: To be included on Construction Space pages
4271:
4272: =cut
4273:
4274: sub CSTR_pageheader {
4275: # this is for resources; directories have customtitle, and crumbs
4276: # and select recent are created in lonpubdir.pm
4277: my ($uname,$thisdisfn)=
4278: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4279: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4280: $formaction=~s/\/+/\//g;
4281:
4282: my $parentpath = '';
4283: my $lastitem = '';
4284: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4285: $parentpath = $1;
4286: $lastitem = $2;
4287: } else {
4288: $lastitem = $thisdisfn;
4289: }
4290: return
4291: '<div>'
4292: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4293: .'<b>'.&mt('Construction Space:').'</b> '
4294: .'<form name="dirs" method="post" action="'.$formaction
4295: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4296: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4297: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4298: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4299: .'</form>'
4300: .&Apache::lonmenu::constspaceform()
4301: .'</div>';
4302: }
4303:
1.60 matthew 4304: ###############################################
4305: ###############################################
4306:
4307: =pod
4308:
1.112 bowersj2 4309: =back
4310:
1.549 albertel 4311: =head1 HTML Helpers
1.112 bowersj2 4312:
4313: =over 4
4314:
4315: =item * &bodytag()
1.60 matthew 4316:
4317: Returns a uniform header for LON-CAPA web pages.
4318:
4319: Inputs:
4320:
1.112 bowersj2 4321: =over 4
4322:
4323: =item * $title, A title to be displayed on the page.
4324:
4325: =item * $function, the current role (can be undef).
4326:
4327: =item * $addentries, extra parameters for the <body> tag.
4328:
4329: =item * $bodyonly, if defined, only return the <body> tag.
4330:
4331: =item * $domain, if defined, force a given domain.
4332:
4333: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4334: text interface only)
1.60 matthew 4335:
1.814 bisitz 4336: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4337: navigational links
1.317 albertel 4338:
1.338 albertel 4339: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4340:
1.361 albertel 4341: =item * $no_inline_link, if true and in remote mode, don't show the
4342: 'Switch To Inline Menu' link
4343:
1.460 albertel 4344: =item * $args, optional argument valid values are
4345: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4346: inherit_jsmath -> when creating popup window in a page,
4347: should it have jsmath forced on by the
4348: current page
1.460 albertel 4349:
1.112 bowersj2 4350: =back
4351:
1.60 matthew 4352: Returns: A uniform header for LON-CAPA web pages.
4353: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4354: If $bodyonly is undef or zero, an html string containing a <body> tag and
4355: other decorations will be returned.
4356:
4357: =cut
4358:
1.54 www 4359: sub bodytag {
1.831 bisitz 4360: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4361: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4362:
1.460 albertel 4363: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4364:
1.183 matthew 4365: $function = &get_users_function() if (!$function);
1.339 albertel 4366: my $img = &designparm($function.'.img',$domain);
4367: my $font = &designparm($function.'.font',$domain);
4368: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4369:
1.803 bisitz 4370: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4371: 'bgcolor' => $pgbg,
1.339 albertel 4372: 'text' => $font,
4373: 'alink' => &designparm($function.'.alink',$domain),
4374: 'vlink' => &designparm($function.'.vlink',$domain),
4375: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4376: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4377:
1.63 www 4378: # role and realm
1.378 raeburn 4379: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4380: if ($role eq 'ca') {
1.479 albertel 4381: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4382: $realm = &plainname($rname,$rdom);
1.378 raeburn 4383: }
1.55 www 4384: # realm
1.258 albertel 4385: if ($env{'request.course.id'}) {
1.378 raeburn 4386: if ($env{'request.role'} !~ /^cr/) {
4387: $role = &Apache::lonnet::plaintext($role,&course_type());
4388: }
1.359 albertel 4389: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4390: } else {
4391: $role = &Apache::lonnet::plaintext($role);
1.54 www 4392: }
1.433 albertel 4393:
1.359 albertel 4394: if (!$realm) { $realm=' '; }
1.55 www 4395: # Set messages
1.60 matthew 4396: my $messages=&domainlogo($domain);
1.330 albertel 4397:
1.438 albertel 4398: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4399:
1.101 www 4400: # construct main body tag
1.359 albertel 4401: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4402: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4403:
1.530 albertel 4404: if ($bodyonly) {
1.60 matthew 4405: return $bodytag;
1.798 tempelho 4406: }
1.359 albertel 4407:
1.410 albertel 4408: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4409: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4410: undef($role);
1.434 albertel 4411: } else {
4412: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4413: }
1.359 albertel 4414:
1.762 bisitz 4415: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4416: #
4417: # Extra info if you are the DC
4418: my $dc_info = '';
4419: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4420: $env{'course.'.$env{'request.course.id'}.
4421: '.domain'}.'/'})) {
4422: my $cid = $env{'request.course.id'};
4423: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4424: $dc_info =~ s/\s+$//;
1.359 albertel 4425: $dc_info = '('.$dc_info.')';
4426: }
4427:
1.853 droeschl 4428: $role = "($role)" if $role;
4429: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4430:
1.837 bisitz 4431: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4432: # No Remote
1.258 albertel 4433: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4434: $forcereg=1;
4435: }
4436:
1.836 bisitz 4437: # if ($env{'request.state'} eq 'construct') {
4438: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4439: # }
1.359 albertel 4440:
1.816 bisitz 4441: my $titletable = '<table id="LC_title_bar">'
1.836 bisitz 4442: ."<tr><td> $titleinfo $dc_info</td>"
1.816 bisitz 4443: .'</tr></table>';
4444:
1.814 bisitz 4445: if ($no_nav_bar) {
1.359 albertel 4446: $bodytag .= $titletable;
4447: } else {
1.852 droeschl 4448: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4449: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4450:
1.359 albertel 4451: if ($env{'request.state'} eq 'construct') {
1.863 droeschl 4452: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
1.272 raeburn 4453: } else {
1.863 droeschl 4454: $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
1.272 raeburn 4455: }
1.235 raeburn 4456: }
4457: return $bodytag;
1.94 www 4458: }
1.95 www 4459:
1.93 www 4460: #
1.95 www 4461: # Top frame rendering, Remote is up
1.93 www 4462: #
1.359 albertel 4463:
1.517 raeburn 4464: my $imgsrc = $img;
4465: if ($img =~ /^\/adm/) {
1.575 albertel 4466: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4467: }
4468: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4469:
1.305 www 4470: # Explicit link to get inline menu
1.361 albertel 4471: my $menu= ($no_inline_link?''
1.883 droeschl 4472: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.853 droeschl 4473: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4474: <em>$realm</em> $dc_info </div>
4475: <ol class="LC_smallMenu LC_right">
4476: <li>$menu</li>
4477: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4478: #
1.94 www 4479: return(<<ENDBODY);
1.60 matthew 4480: $bodytag
1.359 albertel 4481: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4482: <tr><td>$upperleft</td>
4483: <td>$messages </td>
1.54 www 4484: </tr>
1.359 albertel 4485: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4486: </tr>
1.356 albertel 4487: </table>
1.54 www 4488: ENDBODY
1.182 matthew 4489: }
4490:
1.330 albertel 4491: sub make_attr_string {
4492: my ($register,$attr_ref) = @_;
4493:
4494: if ($attr_ref && !ref($attr_ref)) {
4495: die("addentries Must be a hash ref ".
4496: join(':',caller(1))." ".
4497: join(':',caller(0))." ");
4498: }
4499:
4500: if ($register) {
1.339 albertel 4501: my ($on_load,$on_unload);
4502: foreach my $key (keys(%{$attr_ref})) {
4503: if (lc($key) eq 'onload') {
4504: $on_load.=$attr_ref->{$key}.';';
4505: delete($attr_ref->{$key});
4506:
4507: } elsif (lc($key) eq 'onunload') {
4508: $on_unload.=$attr_ref->{$key}.';';
4509: delete($attr_ref->{$key});
4510: }
4511: }
4512: $attr_ref->{'onload'} =
4513: &Apache::lonmenu::loadevents(). $on_load;
4514: $attr_ref->{'onunload'}=
4515: &Apache::lonmenu::unloadevents().$on_unload;
4516: }
4517:
4518: # Accessibility font enhance
4519: if ($env{'browser.fontenhance'} eq 'on') {
4520: my $style;
4521: foreach my $key (keys(%{$attr_ref})) {
4522: if (lc($key) eq 'style') {
4523: $style.=$attr_ref->{$key}.';';
4524: delete($attr_ref->{$key});
4525: }
4526: }
4527: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4528: }
1.339 albertel 4529:
1.330 albertel 4530: my $attr_string;
4531: foreach my $attr (keys(%$attr_ref)) {
4532: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4533: }
4534: return $attr_string;
4535: }
4536:
4537:
1.182 matthew 4538: ###############################################
1.251 albertel 4539: ###############################################
4540:
4541: =pod
4542:
4543: =item * &endbodytag()
4544:
4545: Returns a uniform footer for LON-CAPA web pages.
4546:
1.635 raeburn 4547: Inputs: 1 - optional reference to an args hash
4548: If in the hash, key for noredirectlink has a value which evaluates to true,
4549: a 'Continue' link is not displayed if the page contains an
4550: internal redirect in the <head></head> section,
4551: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4552:
4553: =cut
4554:
4555: sub endbodytag {
1.635 raeburn 4556: my ($args) = @_;
1.251 albertel 4557: my $endbodytag='</body>';
1.269 albertel 4558: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4559: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4560: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4561: $endbodytag=
4562: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4563: &mt('Continue').'</a>'.
4564: $endbodytag;
4565: }
1.315 albertel 4566: }
1.251 albertel 4567: return $endbodytag;
4568: }
4569:
1.352 albertel 4570: =pod
4571:
4572: =item * &standard_css()
4573:
4574: Returns a style sheet
4575:
4576: Inputs: (all optional)
4577: domain -> force to color decorate a page for a specific
4578: domain
4579: function -> force usage of a specific rolish color scheme
4580: bgcolor -> override the default page bgcolor
4581:
4582: =cut
4583:
1.343 albertel 4584: sub standard_css {
1.345 albertel 4585: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4586: $function = &get_users_function() if (!$function);
4587: my $img = &designparm($function.'.img', $domain);
4588: my $tabbg = &designparm($function.'.tabbg', $domain);
4589: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4590: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4591: #second colour for later usage
1.345 albertel 4592: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4593: my $pgbg_or_bgcolor =
4594: $bgcolor ||
1.352 albertel 4595: &designparm($function.'.pgbg', $domain);
1.382 albertel 4596: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4597: my $alink = &designparm($function.'.alink', $domain);
4598: my $vlink = &designparm($function.'.vlink', $domain);
4599: my $link = &designparm($function.'.link', $domain);
4600:
1.704 muellerd 4601: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4602: my $bgcol = &designparm('login.bgcol',$domain);
4603: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4604:
1.602 albertel 4605: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4606: my $mono = 'monospace';
1.850 bisitz 4607: my $data_table_head = $sidebg;
4608: my $data_table_light = '#FAFAFA';
4609: my $data_table_dark = '#F0F0F0';
1.470 banghart 4610: my $data_table_darker = '#CCCCCC';
1.349 albertel 4611: my $data_table_highlight = '#FFFF00';
1.352 albertel 4612: my $mail_new = '#FFBB77';
4613: my $mail_new_hover = '#DD9955';
4614: my $mail_read = '#BBBB77';
4615: my $mail_read_hover = '#999944';
4616: my $mail_replied = '#AAAA88';
4617: my $mail_replied_hover = '#888855';
4618: my $mail_other = '#99BBBB';
4619: my $mail_other_hover = '#669999';
1.391 albertel 4620: my $table_header = '#DDDDDD';
1.489 raeburn 4621: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4622: my $lg_border_color = '#C8C8C8';
1.392 albertel 4623:
1.608 albertel 4624: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4625: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4626: : '0 3px 0 4px';
1.448 albertel 4627:
1.523 albertel 4628:
1.343 albertel 4629: return <<END;
1.795 www 4630: body {
4631: font-family: $sans;
4632: line-height:130%;
4633: font-size:0.83em;
4634: color:$font;
4635: }
4636:
4637: a:link, a:visited {
4638: font-size:100%;
4639: }
4640:
4641: a:focus {
4642: color: red;
4643: background: yellow
4644: }
1.698 harmsja 4645:
1.846 bisitz 4646: hr {
4647: clear: both;
4648: color: $tabbg;
4649: background-color: $tabbg;
4650: height: 3px;
4651: border: none;
4652: }
4653:
1.795 www 4654: form, .inline {
4655: display: inline;
4656: }
1.721 harmsja 4657:
1.795 www 4658: .LC_right {
4659: text-align:right;
4660: }
4661:
4662: .LC_middle {
4663: vertical-align:middle;
4664: }
1.721 harmsja 4665:
4666: /* just for tests */
1.754 droeschl 4667: .LC_400Box {width:400px; }
1.721 harmsja 4668: /* end */
4669:
1.778 bisitz 4670: .LC_filename {
4671: font-family: $mono;
4672: white-space:pre;
4673: }
4674:
4675: .LC_fileicon {
4676: border: none;
4677: height: 1.3em;
4678: vertical-align: text-bottom;
4679: margin-right: 0.3em;
4680: text-decoration:none;
4681: }
4682:
1.350 albertel 4683: .LC_error {
4684: color: red;
4685: font-size: larger;
4686: }
1.795 www 4687:
1.457 albertel 4688: .LC_warning,
4689: .LC_diff_removed {
1.733 bisitz 4690: color: red;
1.394 albertel 4691: }
1.532 albertel 4692:
4693: .LC_info,
1.457 albertel 4694: .LC_success,
4695: .LC_diff_added {
1.350 albertel 4696: color: green;
4697: }
1.795 www 4698:
1.802 bisitz 4699: div.LC_confirm_box {
4700: background-color: #FAFAFA;
4701: border: 1px solid $lg_border_color;
4702: margin-right: 0;
4703: padding: 5px;
4704: }
4705:
4706: div.LC_confirm_box .LC_error img,
4707: div.LC_confirm_box .LC_success img {
4708: vertical-align: middle;
4709: }
4710:
1.440 albertel 4711: .LC_icon {
1.771 droeschl 4712: border: none;
1.790 droeschl 4713: vertical-align: middle;
1.771 droeschl 4714: }
4715:
1.543 albertel 4716: .LC_docs_spacer {
4717: width: 25px;
4718: height: 1px;
1.771 droeschl 4719: border: none;
1.543 albertel 4720: }
1.346 albertel 4721:
1.532 albertel 4722: .LC_internal_info {
1.735 bisitz 4723: color: #999999;
1.532 albertel 4724: }
4725:
1.794 www 4726: .LC_discussion {
4727: background: $tabbg;
4728: border: 1px solid black;
4729: margin: 2px;
4730: }
4731:
4732: .LC_disc_action_links_bar {
4733: background: $tabbg;
1.803 bisitz 4734: border: none;
1.795 www 4735: margin: 4px;
1.794 www 4736: }
4737:
4738: .LC_disc_action_left {
4739: text-align: left;
4740: }
4741:
4742: .LC_disc_action_right {
4743: text-align: right;
4744: }
4745:
4746: .LC_disc_new_item {
4747: background: white;
4748: border: 2px solid red;
4749: margin: 2px;
4750: }
4751:
4752: .LC_disc_old_item {
4753: background: white;
4754: border: 1px solid black;
4755: margin: 2px;
4756: }
4757:
1.458 albertel 4758: table.LC_pastsubmission {
4759: border: 1px solid black;
4760: margin: 2px;
4761: }
4762:
1.795 www 4763: table#LC_top_nav,
4764: table#LC_menubuttons,
4765: table#LC_nav_location {
1.345 albertel 4766: width: 100%;
4767: background: $pgbg;
1.392 albertel 4768: border: 2px;
1.402 albertel 4769: border-collapse: separate;
1.803 bisitz 4770: padding: 0;
1.345 albertel 4771: }
1.392 albertel 4772:
1.801 tempelho 4773: table#LC_title_bar a {
4774: color: $fontmenu;
4775: }
1.836 bisitz 4776:
1.807 droeschl 4777: table#LC_title_bar {
1.819 tempelho 4778: clear: both;
1.836 bisitz 4779: display: none;
1.807 droeschl 4780: }
4781:
1.795 www 4782: table#LC_title_bar,
4783: table.LC_breadcrumbs,
1.393 albertel 4784: table#LC_title_bar.LC_with_remote {
1.359 albertel 4785: width: 100%;
1.392 albertel 4786: border-color: $pgbg;
4787: border-style: solid;
4788: border-width: $border;
1.379 albertel 4789: background: $pgbg;
1.801 tempelho 4790: color: $fontmenu;
1.392 albertel 4791: border-collapse: collapse;
1.803 bisitz 4792: padding: 0;
1.819 tempelho 4793: margin: 0;
1.359 albertel 4794: }
1.795 www 4795:
1.359 albertel 4796: table#LC_title_bar td {
4797: background: $tabbg;
4798: }
1.795 www 4799:
1.706 harmsja 4800: table#LC_menubuttons img{
1.803 bisitz 4801: border: none;
1.346 albertel 4802: }
1.795 www 4803:
1.345 albertel 4804: table#LC_top_nav td {
4805: background: $tabbg;
1.803 bisitz 4806: border: none;
1.407 albertel 4807: font-size: small;
1.706 harmsja 4808: vertical-align:top;
4809: padding:2px 5px 2px 5px;
1.345 albertel 4810: }
1.795 www 4811:
4812: table#LC_top_nav td a,
4813: div#LC_top_nav a {
1.345 albertel 4814: color: $font;
4815: }
1.795 www 4816:
1.364 albertel 4817: table#LC_top_nav td.LC_top_nav_logo {
4818: background: $tabbg;
1.432 albertel 4819: text-align: left;
1.408 albertel 4820: white-space: nowrap;
1.432 albertel 4821: width: 31px;
1.408 albertel 4822: }
1.795 www 4823:
1.408 albertel 4824: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4825: border: none;
1.408 albertel 4826: vertical-align: bottom;
1.364 albertel 4827: }
1.795 www 4828:
1.777 tempelho 4829: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4830: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4831: width: 2.0em;
4832: }
1.795 www 4833:
1.442 albertel 4834: table#LC_top_nav td.LC_top_nav_login {
4835: width: 4.0em;
4836: text-align: center;
4837: }
1.795 www 4838:
1.842 droeschl 4839: .LC_breadcrumbs_component {
4840: float: right;
4841: margin: 0 1em;
1.357 albertel 4842: }
1.842 droeschl 4843: .LC_breadcrumbs_component img {
4844: vertical-align: middle;
1.777 tempelho 4845: }
1.795 www 4846:
1.383 albertel 4847: td.LC_table_cell_checkbox {
4848: text-align: center;
4849: }
1.795 www 4850:
1.779 bisitz 4851: table#LC_mainmenu td.LC_mainmenu_column {
4852: vertical-align: top;
1.777 tempelho 4853: }
1.522 albertel 4854:
1.795 www 4855: .LC_fontsize_small {
1.705 tempelho 4856: font-size: 70%;
4857: }
4858:
1.844 bisitz 4859: #LC_breadcrumbs {
1.819 tempelho 4860: clear:both;
4861: background: $sidebg;
1.822 bisitz 4862: border-bottom: 1px solid $lg_border_color;
1.819 tempelho 4863: line-height: 32px;
1.822 bisitz 4864: margin: 0;
1.819 tempelho 4865: padding: 0;
4866: }
1.862 bisitz 4867:
1.839 droeschl 4868: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4869: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4870: display:none;
4871: }
1.819 tempelho 4872:
1.844 bisitz 4873: #LC_head_subbox {
1.822 bisitz 4874: clear:both;
4875: background: #F8F8F8; /* $sidebg; */
4876: border-bottom: 1px solid $lg_border_color;
4877: margin: 0 0 10px 0;
4878: padding: 5px;
4879: }
4880:
1.795 www 4881: .LC_fontsize_medium {
1.705 tempelho 4882: font-size: 85%;
4883: }
4884:
1.795 www 4885: .LC_fontsize_large {
1.705 tempelho 4886: font-size: 120%;
4887: }
4888:
1.346 albertel 4889: .LC_menubuttons_inline_text {
4890: color: $font;
1.698 harmsja 4891: font-size: 90%;
1.701 harmsja 4892: padding-left:3px;
1.346 albertel 4893: }
4894:
1.526 www 4895: .LC_menubuttons_link {
4896: text-decoration: none;
4897: }
1.795 www 4898:
1.522 albertel 4899: .LC_menubuttons_category {
1.521 www 4900: color: $font;
1.526 www 4901: background: $pgbg;
1.521 www 4902: font-size: larger;
4903: font-weight: bold;
4904: }
4905:
1.346 albertel 4906: td.LC_menubuttons_text {
1.779 bisitz 4907: color: $font;
1.346 albertel 4908: }
1.706 harmsja 4909:
1.346 albertel 4910: .LC_current_location {
4911: background: $tabbg;
4912: }
1.795 www 4913:
1.346 albertel 4914: .LC_new_mail {
1.634 www 4915: background: $tabbg;
1.346 albertel 4916: font-weight: bold;
4917: }
1.347 albertel 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.879 raeburn 4938: table.LC_innerpickbox,
1.507 raeburn 4939: table.LC_nested {
1.803 bisitz 4940: border: none;
1.589 raeburn 4941: border-collapse: collapse;
1.803 bisitz 4942: border-spacing: 0;
1.507 raeburn 4943: width: 100%;
4944: }
1.795 www 4945:
4946: table.LC_data_table tr th,
4947: table.LC_calendar tr th,
4948: table.LC_mail_list tr th,
1.879 raeburn 4949: table.LC_prior_tries tr th,
4950: table.LC_innerpickbox tr th {
1.349 albertel 4951: font-weight: bold;
4952: background-color: $data_table_head;
1.801 tempelho 4953: color:$fontmenu;
1.701 harmsja 4954: font-size:90%;
1.347 albertel 4955: }
1.795 www 4956:
1.879 raeburn 4957: table.LC_innerpickbox tr th,
4958: table.LC_innerpickbox tr td {
4959: vertical-align: top;
4960: }
4961:
1.711 raeburn 4962: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4963: background-color: #CCCCCC;
1.711 raeburn 4964: font-weight: bold;
4965: text-align: left;
4966: }
1.795 www 4967:
1.779 bisitz 4968: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4969: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4970: background-color: $data_table_light;
1.425 albertel 4971: padding: 2px;
1.347 albertel 4972: }
1.795 www 4973:
1.610 albertel 4974: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4975: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 4976: background-color: $data_table_dark;
1.709 bisitz 4977: padding: 2px;
1.347 albertel 4978: }
1.795 www 4979:
1.425 albertel 4980: table.LC_data_table tr.LC_data_table_highlight td {
4981: background-color: $data_table_darker;
4982: }
1.795 www 4983:
1.639 raeburn 4984: table.LC_data_table tr td.LC_leftcol_header {
4985: background-color: $data_table_head;
4986: font-weight: bold;
4987: }
1.795 www 4988:
1.451 albertel 4989: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4990: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4991: background-color: #FFFFFF;
1.421 albertel 4992: font-weight: bold;
4993: font-style: italic;
4994: text-align: center;
4995: padding: 8px;
1.347 albertel 4996: }
1.795 www 4997:
1.507 raeburn 4998: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4999: padding: 4ex
5000: }
1.795 www 5001:
1.507 raeburn 5002: table.LC_nested_outer tr th {
5003: font-weight: bold;
1.801 tempelho 5004: color:$fontmenu;
1.507 raeburn 5005: background-color: $data_table_head;
1.701 harmsja 5006: font-size: small;
1.507 raeburn 5007: border-bottom: 1px solid #000000;
5008: }
1.795 www 5009:
1.507 raeburn 5010: table.LC_nested_outer tr td.LC_subheader {
5011: background-color: $data_table_head;
5012: font-weight: bold;
5013: font-size: small;
5014: border-bottom: 1px solid #000000;
5015: text-align: right;
1.451 albertel 5016: }
1.795 www 5017:
1.507 raeburn 5018: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5019: background-color: #CCCCCC;
1.451 albertel 5020: font-weight: bold;
5021: font-size: small;
1.507 raeburn 5022: text-align: center;
5023: }
1.795 www 5024:
1.589 raeburn 5025: table.LC_nested tr.LC_info_row td.LC_left_item,
5026: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5027: text-align: left;
1.451 albertel 5028: }
1.795 www 5029:
1.507 raeburn 5030: table.LC_nested td {
1.735 bisitz 5031: background-color: #FFFFFF;
1.451 albertel 5032: font-size: small;
1.507 raeburn 5033: }
1.795 www 5034:
1.507 raeburn 5035: table.LC_nested_outer tr th.LC_right_item,
5036: table.LC_nested tr.LC_info_row td.LC_right_item,
5037: table.LC_nested tr.LC_odd_row td.LC_right_item,
5038: table.LC_nested tr td.LC_right_item {
1.451 albertel 5039: text-align: right;
5040: }
5041:
1.507 raeburn 5042: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5043: background-color: #EEEEEE;
1.451 albertel 5044: }
5045:
1.473 raeburn 5046: table.LC_createuser {
5047: }
5048:
5049: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5050: font-size: small;
1.473 raeburn 5051: }
5052:
5053: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5054: background-color: #CCCCCC;
1.473 raeburn 5055: font-weight: bold;
5056: text-align: center;
5057: }
5058:
1.349 albertel 5059: table.LC_calendar {
5060: border: 1px solid #000000;
5061: border-collapse: collapse;
5062: }
1.795 www 5063:
1.349 albertel 5064: table.LC_calendar_pickdate {
5065: font-size: xx-small;
5066: }
1.795 www 5067:
1.349 albertel 5068: table.LC_calendar tr td {
5069: border: 1px solid #000000;
5070: vertical-align: top;
5071: }
1.795 www 5072:
1.349 albertel 5073: table.LC_calendar tr td.LC_calendar_day_empty {
5074: background-color: $data_table_dark;
5075: }
1.795 www 5076:
1.779 bisitz 5077: table.LC_calendar tr td.LC_calendar_day_current {
5078: background-color: $data_table_highlight;
1.777 tempelho 5079: }
1.795 www 5080:
1.349 albertel 5081: table.LC_mail_list tr.LC_mail_new {
5082: background-color: $mail_new;
5083: }
1.795 www 5084:
1.349 albertel 5085: table.LC_mail_list tr.LC_mail_new:hover {
5086: background-color: $mail_new_hover;
5087: }
1.795 www 5088:
5089: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5090: }
1.795 www 5091:
5092: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5093: }
1.795 www 5094:
1.349 albertel 5095: table.LC_mail_list tr.LC_mail_read {
5096: background-color: $mail_read;
5097: }
1.795 www 5098:
1.349 albertel 5099: table.LC_mail_list tr.LC_mail_read:hover {
5100: background-color: $mail_read_hover;
5101: }
1.795 www 5102:
1.349 albertel 5103: table.LC_mail_list tr.LC_mail_replied {
5104: background-color: $mail_replied;
5105: }
1.795 www 5106:
1.349 albertel 5107: table.LC_mail_list tr.LC_mail_replied:hover {
5108: background-color: $mail_replied_hover;
5109: }
1.795 www 5110:
1.349 albertel 5111: table.LC_mail_list tr.LC_mail_other {
5112: background-color: $mail_other;
5113: }
1.795 www 5114:
1.349 albertel 5115: table.LC_mail_list tr.LC_mail_other:hover {
5116: background-color: $mail_other_hover;
5117: }
1.494 raeburn 5118:
1.777 tempelho 5119: table.LC_data_table tr > td.LC_browser_file,
5120: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5121: background: #CCFF88;
5122: }
1.795 www 5123:
1.777 tempelho 5124: table.LC_data_table tr > td.LC_browser_file_locked,
5125: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5126: background: #FFAA99;
1.387 albertel 5127: }
1.795 www 5128:
1.777 tempelho 5129: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5130: background: #AAAAAA;
5131: }
1.795 www 5132:
1.777 tempelho 5133: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5134: table.LC_data_table tr > td.LC_browser_file_metamodified {
5135: background: #FFFF77;
1.777 tempelho 5136: }
1.795 www 5137:
1.696 bisitz 5138: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5139: background: #CCCCFF;
1.387 albertel 5140: }
1.696 bisitz 5141:
1.707 bisitz 5142: table.LC_data_table tr > td.LC_roles_is {
5143: /* background: #77FF77; */
5144: }
1.795 www 5145:
1.707 bisitz 5146: table.LC_data_table tr > td.LC_roles_future {
5147: background: #FFFF77;
5148: }
1.795 www 5149:
1.707 bisitz 5150: table.LC_data_table tr > td.LC_roles_will {
5151: background: #FFAA77;
5152: }
1.795 www 5153:
1.707 bisitz 5154: table.LC_data_table tr > td.LC_roles_expired {
5155: background: #FF7777;
5156: }
1.795 www 5157:
1.707 bisitz 5158: table.LC_data_table tr > td.LC_roles_will_not {
5159: background: #AAFF77;
5160: }
1.795 www 5161:
1.707 bisitz 5162: table.LC_data_table tr > td.LC_roles_selected {
5163: background: #11CC55;
5164: }
5165:
1.388 albertel 5166: span.LC_current_location {
1.701 harmsja 5167: font-size:larger;
1.388 albertel 5168: background: $pgbg;
5169: }
1.387 albertel 5170:
1.395 albertel 5171: span.LC_parm_menu_item {
5172: font-size: larger;
5173: }
1.795 www 5174:
1.395 albertel 5175: span.LC_parm_scope_all {
5176: color: red;
5177: }
1.795 www 5178:
1.395 albertel 5179: span.LC_parm_scope_folder {
5180: color: green;
5181: }
1.795 www 5182:
1.395 albertel 5183: span.LC_parm_scope_resource {
5184: color: orange;
5185: }
1.795 www 5186:
1.395 albertel 5187: span.LC_parm_part {
5188: color: blue;
5189: }
1.795 www 5190:
1.395 albertel 5191: span.LC_parm_folder, span.LC_parm_symb {
5192: font-size: x-small;
5193: font-family: $mono;
5194: color: #AAAAAA;
5195: }
5196:
1.795 www 5197: td.LC_parm_overview_level_menu,
5198: td.LC_parm_overview_map_menu,
5199: td.LC_parm_overview_parm_selectors,
5200: td.LC_parm_overview_restrictions {
1.396 albertel 5201: border: 1px solid black;
5202: border-collapse: collapse;
5203: }
1.795 www 5204:
1.396 albertel 5205: table.LC_parm_overview_restrictions td {
5206: border-width: 1px 4px 1px 4px;
5207: border-style: solid;
5208: border-color: $pgbg;
5209: text-align: center;
5210: }
1.795 www 5211:
1.396 albertel 5212: table.LC_parm_overview_restrictions th {
5213: background: $tabbg;
5214: border-width: 1px 4px 1px 4px;
5215: border-style: solid;
5216: border-color: $pgbg;
5217: }
1.795 www 5218:
1.398 albertel 5219: table#LC_helpmenu {
1.803 bisitz 5220: border: none;
1.398 albertel 5221: height: 55px;
1.803 bisitz 5222: border-spacing: 0;
1.398 albertel 5223: }
5224:
5225: table#LC_helpmenu fieldset legend {
5226: font-size: larger;
5227: }
1.795 www 5228:
1.397 albertel 5229: table#LC_helpmenu_links {
5230: width: 100%;
5231: border: 1px solid black;
5232: background: $pgbg;
1.803 bisitz 5233: padding: 0;
1.397 albertel 5234: border-spacing: 1px;
5235: }
1.795 www 5236:
1.397 albertel 5237: table#LC_helpmenu_links tr td {
5238: padding: 1px;
5239: background: $tabbg;
1.399 albertel 5240: text-align: center;
5241: font-weight: bold;
1.397 albertel 5242: }
1.396 albertel 5243:
1.795 www 5244: table#LC_helpmenu_links a:link,
5245: table#LC_helpmenu_links a:visited,
1.397 albertel 5246: table#LC_helpmenu_links a:active {
5247: text-decoration: none;
5248: color: $font;
5249: }
1.795 www 5250:
1.397 albertel 5251: table#LC_helpmenu_links a:hover {
5252: text-decoration: underline;
5253: color: $vlink;
5254: }
1.396 albertel 5255:
1.417 albertel 5256: .LC_chrt_popup_exists {
5257: border: 1px solid #339933;
5258: margin: -1px;
5259: }
1.795 www 5260:
1.417 albertel 5261: .LC_chrt_popup_up {
5262: border: 1px solid yellow;
5263: margin: -1px;
5264: }
1.795 www 5265:
1.417 albertel 5266: .LC_chrt_popup {
5267: border: 1px solid #8888FF;
5268: background: #CCCCFF;
5269: }
1.795 www 5270:
1.421 albertel 5271: table.LC_pick_box {
5272: border-collapse: separate;
5273: background: white;
5274: border: 1px solid black;
5275: border-spacing: 1px;
5276: }
1.795 www 5277:
1.421 albertel 5278: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5279: background: $sidebg;
1.421 albertel 5280: font-weight: bold;
5281: text-align: right;
1.740 bisitz 5282: vertical-align: top;
1.421 albertel 5283: width: 184px;
5284: padding: 8px;
5285: }
1.795 www 5286:
1.579 raeburn 5287: table.LC_pick_box td.LC_pick_box_value {
5288: text-align: left;
5289: padding: 8px;
5290: }
1.795 www 5291:
1.579 raeburn 5292: table.LC_pick_box td.LC_pick_box_select {
5293: text-align: left;
5294: padding: 8px;
5295: }
1.795 www 5296:
1.424 albertel 5297: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5298: padding: 0;
1.421 albertel 5299: height: 1px;
5300: background: black;
5301: }
1.795 www 5302:
1.421 albertel 5303: table.LC_pick_box td.LC_pick_box_submit {
5304: text-align: right;
5305: }
1.795 www 5306:
1.579 raeburn 5307: table.LC_pick_box td.LC_evenrow_value {
5308: text-align: left;
5309: padding: 8px;
5310: background-color: $data_table_light;
5311: }
1.795 www 5312:
1.579 raeburn 5313: table.LC_pick_box td.LC_oddrow_value {
5314: text-align: left;
5315: padding: 8px;
5316: background-color: $data_table_light;
5317: }
1.795 www 5318:
1.579 raeburn 5319: table.LC_helpform_receipt {
5320: width: 620px;
5321: border-collapse: separate;
5322: background: white;
5323: border: 1px solid black;
5324: border-spacing: 1px;
5325: }
1.795 www 5326:
1.579 raeburn 5327: table.LC_helpform_receipt td.LC_pick_box_title {
5328: background: $tabbg;
5329: font-weight: bold;
5330: text-align: right;
5331: width: 184px;
5332: padding: 8px;
5333: }
1.795 www 5334:
1.579 raeburn 5335: table.LC_helpform_receipt td.LC_evenrow_value {
5336: text-align: left;
5337: padding: 8px;
5338: background-color: $data_table_light;
5339: }
1.795 www 5340:
1.579 raeburn 5341: table.LC_helpform_receipt td.LC_oddrow_value {
5342: text-align: left;
5343: padding: 8px;
5344: background-color: $data_table_light;
5345: }
1.795 www 5346:
1.579 raeburn 5347: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803 bisitz 5348: padding: 0;
1.579 raeburn 5349: height: 1px;
5350: background: black;
5351: }
1.795 www 5352:
1.579 raeburn 5353: span.LC_helpform_receipt_cat {
5354: font-weight: bold;
5355: }
1.795 www 5356:
1.424 albertel 5357: table.LC_group_priv_box {
5358: background: white;
5359: border: 1px solid black;
5360: border-spacing: 1px;
5361: }
1.795 www 5362:
1.424 albertel 5363: table.LC_group_priv_box td.LC_pick_box_title {
5364: background: $tabbg;
5365: font-weight: bold;
5366: text-align: right;
5367: width: 184px;
5368: }
1.795 www 5369:
1.424 albertel 5370: table.LC_group_priv_box td.LC_groups_fixed {
5371: background: $data_table_light;
5372: text-align: center;
5373: }
1.795 www 5374:
1.424 albertel 5375: table.LC_group_priv_box td.LC_groups_optional {
5376: background: $data_table_dark;
5377: text-align: center;
5378: }
1.795 www 5379:
1.424 albertel 5380: table.LC_group_priv_box td.LC_groups_functionality {
5381: background: $data_table_darker;
5382: text-align: center;
5383: font-weight: bold;
5384: }
1.795 www 5385:
1.424 albertel 5386: table.LC_group_priv td {
5387: text-align: left;
1.803 bisitz 5388: padding: 0;
1.424 albertel 5389: }
5390:
1.421 albertel 5391: table.LC_notify_front_page {
5392: background: white;
5393: border: 1px solid black;
5394: padding: 8px;
5395: }
1.795 www 5396:
1.421 albertel 5397: table.LC_notify_front_page td {
5398: padding: 8px;
5399: }
1.795 www 5400:
1.424 albertel 5401: .LC_navbuttons {
5402: margin: 2ex 0ex 2ex 0ex;
5403: }
1.795 www 5404:
1.423 albertel 5405: .LC_topic_bar {
5406: font-weight: bold;
5407: width: 100%;
5408: background: $tabbg;
5409: vertical-align: middle;
5410: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5411: padding: 3px;
1.423 albertel 5412: }
1.795 www 5413:
1.423 albertel 5414: .LC_topic_bar span {
5415: vertical-align: middle;
5416: }
1.795 www 5417:
1.423 albertel 5418: .LC_topic_bar img {
5419: vertical-align: bottom;
5420: }
1.795 www 5421:
1.423 albertel 5422: table.LC_course_group_status {
5423: margin: 20px;
5424: }
1.795 www 5425:
1.423 albertel 5426: table.LC_status_selector td {
5427: vertical-align: top;
5428: text-align: center;
1.424 albertel 5429: padding: 4px;
5430: }
1.795 www 5431:
1.599 albertel 5432: div.LC_feedback_link {
1.616 albertel 5433: clear: both;
1.829 kalberla 5434: background: $sidebg;
1.779 bisitz 5435: width: 100%;
1.829 kalberla 5436: padding-bottom: 10px;
5437: border: 1px $tabbg solid;
1.833 kalberla 5438: height: 22px;
5439: line-height: 22px;
5440: padding-top: 5px;
5441: }
5442:
5443: div.LC_feedback_link img {
5444: height: 22px;
1.867 kalberla 5445: vertical-align:middle;
1.829 kalberla 5446: }
5447:
5448: div.LC_feedback_link a{
5449: text-decoration: none;
1.489 raeburn 5450: }
1.795 www 5451:
1.867 kalberla 5452: div.LC_comblock {
5453: display:inline;
5454: color:$font;
5455: font-size:90%;
5456: }
5457:
5458: div.LC_feedback_link div.LC_comblock {
5459: padding-left:5px;
5460: }
5461:
5462: div.LC_feedback_link div.LC_comblock a {
5463: color:$font;
5464: }
5465:
1.489 raeburn 5466: span.LC_feedback_link {
1.858 bisitz 5467: /* background: $feedback_link_bg; */
1.599 albertel 5468: font-size: larger;
5469: }
1.795 www 5470:
1.599 albertel 5471: span.LC_message_link {
1.858 bisitz 5472: /* background: $feedback_link_bg; */
1.599 albertel 5473: font-size: larger;
5474: position: absolute;
5475: right: 1em;
1.489 raeburn 5476: }
1.421 albertel 5477:
1.515 albertel 5478: table.LC_prior_tries {
1.524 albertel 5479: border: 1px solid #000000;
5480: border-collapse: separate;
5481: border-spacing: 1px;
1.515 albertel 5482: }
1.523 albertel 5483:
1.515 albertel 5484: table.LC_prior_tries td {
1.524 albertel 5485: padding: 2px;
1.515 albertel 5486: }
1.523 albertel 5487:
5488: .LC_answer_correct {
1.795 www 5489: background: lightgreen;
5490: color: darkgreen;
5491: padding: 6px;
1.523 albertel 5492: }
1.795 www 5493:
1.523 albertel 5494: .LC_answer_charged_try {
1.797 www 5495: background: #FFAAAA;
1.795 www 5496: color: darkred;
5497: padding: 6px;
1.523 albertel 5498: }
1.795 www 5499:
1.779 bisitz 5500: .LC_answer_not_charged_try,
1.523 albertel 5501: .LC_answer_no_grade,
5502: .LC_answer_late {
1.795 www 5503: background: lightyellow;
1.523 albertel 5504: color: black;
1.795 www 5505: padding: 6px;
1.523 albertel 5506: }
1.795 www 5507:
1.523 albertel 5508: .LC_answer_previous {
1.795 www 5509: background: lightblue;
5510: color: darkblue;
5511: padding: 6px;
1.523 albertel 5512: }
1.795 www 5513:
1.779 bisitz 5514: .LC_answer_no_message {
1.777 tempelho 5515: background: #FFFFFF;
5516: color: black;
1.795 www 5517: padding: 6px;
1.779 bisitz 5518: }
1.795 www 5519:
1.779 bisitz 5520: .LC_answer_unknown {
5521: background: orange;
5522: color: black;
1.795 www 5523: padding: 6px;
1.777 tempelho 5524: }
1.795 www 5525:
1.529 albertel 5526: span.LC_prior_numerical,
5527: span.LC_prior_string,
5528: span.LC_prior_custom,
5529: span.LC_prior_reaction,
5530: span.LC_prior_math {
1.523 albertel 5531: font-family: monospace;
5532: white-space: pre;
5533: }
5534:
1.525 albertel 5535: span.LC_prior_string {
5536: font-family: monospace;
5537: white-space: pre;
5538: }
5539:
1.523 albertel 5540: table.LC_prior_option {
5541: width: 100%;
5542: border-collapse: collapse;
5543: }
1.795 www 5544:
5545: table.LC_prior_rank,
5546: table.LC_prior_match {
1.528 albertel 5547: border-collapse: collapse;
5548: }
1.795 www 5549:
1.528 albertel 5550: table.LC_prior_option tr td,
5551: table.LC_prior_rank tr td,
5552: table.LC_prior_match tr td {
1.524 albertel 5553: border: 1px solid #000000;
1.515 albertel 5554: }
5555:
1.855 bisitz 5556: .LC_nobreak {
1.544 albertel 5557: white-space: nowrap;
1.519 raeburn 5558: }
5559:
1.576 raeburn 5560: span.LC_cusr_emph {
5561: font-style: italic;
5562: }
5563:
1.633 raeburn 5564: span.LC_cusr_subheading {
5565: font-weight: normal;
5566: font-size: 85%;
5567: }
5568:
1.545 albertel 5569: table.LC_docs_documents {
5570: background: #BBBBBB;
1.803 bisitz 5571: border-width: 0;
1.545 albertel 5572: border-collapse: collapse;
5573: }
1.795 www 5574:
1.777 tempelho 5575: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5576: border: 2px solid black;
5577: padding: 4px;
1.777 tempelho 5578: }
1.795 www 5579:
1.861 bisitz 5580: div.LC_docs_entry_move {
1.859 bisitz 5581: border: 1px solid #BBBBBB;
1.545 albertel 5582: background: #DDDDDD;
1.861 bisitz 5583: width: 22px;
1.859 bisitz 5584: padding: 1px;
5585: margin: 0;
1.545 albertel 5586: }
5587:
1.861 bisitz 5588: table.LC_data_table tr > td.LC_docs_entry_commands,
5589: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5590: background: #DDDDDD;
5591: font-size: x-small;
5592: }
1.795 www 5593:
1.861 bisitz 5594: .LC_docs_entry_parameter {
5595: white-space: nowrap;
5596: }
5597:
1.544 albertel 5598: .LC_docs_copy {
1.545 albertel 5599: color: #000099;
1.544 albertel 5600: }
1.795 www 5601:
1.544 albertel 5602: .LC_docs_cut {
1.545 albertel 5603: color: #550044;
1.544 albertel 5604: }
1.795 www 5605:
1.544 albertel 5606: .LC_docs_rename {
1.545 albertel 5607: color: #009900;
1.544 albertel 5608: }
1.795 www 5609:
1.544 albertel 5610: .LC_docs_remove {
1.545 albertel 5611: color: #990000;
5612: }
5613:
1.547 albertel 5614: .LC_docs_reinit_warn,
5615: .LC_docs_ext_edit {
5616: font-size: x-small;
5617: }
5618:
1.545 albertel 5619: table.LC_docs_adddocs td,
5620: table.LC_docs_adddocs th {
5621: border: 1px solid #BBBBBB;
5622: padding: 4px;
5623: background: #DDDDDD;
1.543 albertel 5624: }
5625:
1.584 albertel 5626: table.LC_sty_begin {
5627: background: #BBFFBB;
5628: }
1.795 www 5629:
1.584 albertel 5630: table.LC_sty_end {
5631: background: #FFBBBB;
5632: }
5633:
1.589 raeburn 5634: table.LC_double_column {
1.803 bisitz 5635: border-width: 0;
1.589 raeburn 5636: border-collapse: collapse;
5637: width: 100%;
5638: padding: 2px;
5639: }
5640:
5641: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5642: top: 2px;
1.589 raeburn 5643: left: 2px;
5644: width: 47%;
5645: vertical-align: top;
5646: }
5647:
5648: table.LC_double_column tr td.LC_right_col {
5649: top: 2px;
1.779 bisitz 5650: right: 2px;
1.589 raeburn 5651: width: 47%;
5652: vertical-align: top;
5653: }
5654:
1.591 raeburn 5655: div.LC_left_float {
5656: float: left;
5657: padding-right: 5%;
1.597 albertel 5658: padding-bottom: 4px;
1.591 raeburn 5659: }
5660:
5661: div.LC_clear_float_header {
1.597 albertel 5662: padding-bottom: 2px;
1.591 raeburn 5663: }
5664:
5665: div.LC_clear_float_footer {
1.597 albertel 5666: padding-top: 10px;
1.591 raeburn 5667: clear: both;
5668: }
5669:
1.597 albertel 5670: div.LC_grade_show_user {
5671: margin-top: 20px;
5672: border: 1px solid black;
5673: }
1.795 www 5674:
1.597 albertel 5675: div.LC_grade_user_name {
5676: background: #DDDDEE;
5677: border-bottom: 1px solid black;
1.705 tempelho 5678: font-weight: bold;
5679: font-size: large;
1.597 albertel 5680: }
1.795 www 5681:
1.597 albertel 5682: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5683: background: #DDEEDD;
5684: }
5685:
5686: div.LC_grade_show_problem,
5687: div.LC_grade_submissions,
5688: div.LC_grade_message_center,
5689: div.LC_grade_info_links,
5690: div.LC_grade_assign {
5691: margin: 5px;
5692: width: 99%;
5693: background: #FFFFFF;
5694: }
1.795 www 5695:
1.597 albertel 5696: div.LC_grade_show_problem_header,
5697: div.LC_grade_submissions_header,
5698: div.LC_grade_message_center_header,
5699: div.LC_grade_assign_header {
1.705 tempelho 5700: font-weight: bold;
5701: font-size: large;
1.597 albertel 5702: }
1.795 www 5703:
1.597 albertel 5704: div.LC_grade_show_problem_problem,
5705: div.LC_grade_submissions_body,
5706: div.LC_grade_message_center_body,
5707: div.LC_grade_assign_body {
5708: border: 1px solid black;
5709: width: 99%;
5710: background: #FFFFFF;
5711: }
1.795 www 5712:
1.598 albertel 5713: span.LC_grade_check_note {
1.705 tempelho 5714: font-weight: normal;
5715: font-size: medium;
1.598 albertel 5716: display: inline;
5717: position: absolute;
5718: right: 1em;
5719: }
1.597 albertel 5720:
1.613 albertel 5721: table.LC_scantron_action {
5722: width: 100%;
5723: }
1.795 www 5724:
1.613 albertel 5725: table.LC_scantron_action tr th {
1.698 harmsja 5726: font-weight:bold;
5727: font-style:normal;
1.613 albertel 5728: }
1.795 www 5729:
1.779 bisitz 5730: .LC_edit_problem_header,
1.614 albertel 5731: div.LC_edit_problem_footer {
1.705 tempelho 5732: font-weight: normal;
5733: font-size: medium;
1.602 albertel 5734: margin: 2px;
1.600 albertel 5735: }
1.795 www 5736:
1.600 albertel 5737: div.LC_edit_problem_header,
1.602 albertel 5738: div.LC_edit_problem_header div,
1.614 albertel 5739: div.LC_edit_problem_footer,
5740: div.LC_edit_problem_footer div,
1.602 albertel 5741: div.LC_edit_problem_editxml_header,
5742: div.LC_edit_problem_editxml_header div {
1.600 albertel 5743: margin-top: 5px;
5744: }
1.795 www 5745:
1.600 albertel 5746: div.LC_edit_problem_header_title {
1.705 tempelho 5747: font-weight: bold;
5748: font-size: larger;
1.602 albertel 5749: background: $tabbg;
5750: padding: 3px;
5751: }
1.795 www 5752:
1.602 albertel 5753: table.LC_edit_problem_header_title {
1.705 tempelho 5754: font-size: larger;
5755: font-weight: bold;
1.602 albertel 5756: width: 100%;
5757: border-color: $pgbg;
5758: border-style: solid;
5759: border-width: $border;
1.600 albertel 5760: background: $tabbg;
1.602 albertel 5761: border-collapse: collapse;
1.803 bisitz 5762: padding: 0;
1.602 albertel 5763: }
5764:
5765: div.LC_edit_problem_discards {
5766: float: left;
5767: padding-bottom: 5px;
5768: }
1.795 www 5769:
1.602 albertel 5770: div.LC_edit_problem_saves {
5771: float: right;
5772: padding-bottom: 5px;
1.600 albertel 5773: }
1.795 www 5774:
1.679 riegler 5775: img.stift{
1.803 bisitz 5776: border-width: 0;
5777: vertical-align: middle;
1.677 riegler 5778: }
1.680 riegler 5779:
1.681 riegler 5780: table#LC_mainmenu{
5781: margin-top:10px;
5782: width:80%;
5783: }
5784:
1.680 riegler 5785: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5786: vertical-align: top;
5787: width: 45%;
5788: }
1.795 www 5789:
1.779 bisitz 5790: .LC_mainmenu_fieldset_category {
5791: color: $font;
5792: background: $pgbg;
5793: font-size: small;
5794: font-weight: bold;
1.777 tempelho 5795: }
1.795 www 5796:
1.716 raeburn 5797: div.LC_createcourse {
5798: margin: 10px 10px 10px 10px;
5799: }
5800:
1.693 droeschl 5801: /* ---- Remove when done ----
5802: # The following styles is part of the redesign of LON-CAPA and are
5803: # subject to change during this project.
5804: # Don't rely on their current functionality as they might be
5805: # changed or removed.
5806: # --------------------------*/
5807:
1.698 harmsja 5808: a:hover,
1.721 harmsja 5809: ol.LC_smallMenu a:hover,
5810: ol#LC_MenuBreadcrumbs a:hover,
5811: ol#LC_PathBreadcrumbs a:hover,
5812: ul#LC_TabMainMenuContent a:hover,
5813: .LC_FormSectionClearButton input:hover
1.795 www 5814: ul.LC_TabContent li:hover a {
1.698 harmsja 5815: color:#BF2317;
5816: text-decoration:none;
1.693 droeschl 5817: }
5818:
1.779 bisitz 5819: h1 {
1.813 bisitz 5820: padding: 0;
1.693 droeschl 5821: line-height:130%;
5822: }
1.698 harmsja 5823:
1.795 www 5824: h2,h3,h4,h5,h6 {
1.803 bisitz 5825: margin: 5px 0 5px 0;
5826: padding: 0;
1.721 harmsja 5827: line-height:130%;
1.693 droeschl 5828: }
1.795 www 5829:
5830: .LC_hcell {
1.698 harmsja 5831: padding:3px 15px 3px 15px;
1.803 bisitz 5832: margin: 0;
1.703 harmsja 5833: background-color:$tabbg;
1.801 tempelho 5834: color:$fontmenu;
1.779 bisitz 5835: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5836: }
1.795 www 5837:
1.840 bisitz 5838: .LC_Box > .LC_hcell {
1.847 tempelho 5839: margin: 0 -10px 10px -10px;
1.835 bisitz 5840: }
5841:
1.721 harmsja 5842: .LC_noBorder {
1.803 bisitz 5843: border: 0;
1.698 harmsja 5844: }
1.693 droeschl 5845:
1.761 tempelho 5846: .LC_Right {
5847: float: right;
1.803 bisitz 5848: margin: 0;
5849: padding: 0;
1.761 tempelho 5850: }
5851:
1.721 harmsja 5852: .LC_FormSectionClearButton input {
1.779 bisitz 5853: background-color:transparent;
1.803 bisitz 5854: border: none;
1.698 harmsja 5855: cursor:pointer;
5856: text-decoration:underline;
1.693 droeschl 5857: }
1.763 bisitz 5858:
5859: .LC_help_open_topic {
5860: color: #FFFFFF;
5861: background-color: #EEEEFF;
5862: margin: 1px;
5863: padding: 4px;
5864: border: 1px solid #000033;
5865: white-space: nowrap;
1.783 amueller 5866: /* vertical-align: middle; */
1.759 neumanie 5867: }
1.693 droeschl 5868:
1.698 harmsja 5869: dl,ul,div,fieldset {
1.803 bisitz 5870: margin: 10px 10px 10px 0;
1.806 bisitz 5871: /* overflow: hidden; */
1.693 droeschl 5872: }
1.795 www 5873:
1.838 bisitz 5874: fieldset > legend {
5875: font-weight: bold;
5876: padding: 0 5px 0 5px;
5877: }
5878:
1.813 bisitz 5879: #LC_nav_bar {
1.807 droeschl 5880: float: left;
1.852 droeschl 5881: margin: 0.2em 0 0 0;
1.807 droeschl 5882: }
5883:
1.813 bisitz 5884: #LC_nav_bar em{
1.807 droeschl 5885: font-weight: bold;
5886: font-style: normal;
5887: }
5888:
5889: ol.LC_smallMenu {
5890: float: right;
1.852 droeschl 5891: margin: 0.2em 0 0 0;
1.807 droeschl 5892: }
5893:
1.852 droeschl 5894: ol#LC_PathBreadcrumbs {
1.803 bisitz 5895: margin: 0;
1.693 droeschl 5896: }
5897:
1.721 harmsja 5898: ol.LC_smallMenu li {
1.693 droeschl 5899: display: inline;
1.803 bisitz 5900: padding: 5px 5px 0 10px;
1.693 droeschl 5901: vertical-align: top;
5902: }
5903:
1.721 harmsja 5904: ol.LC_smallMenu li img {
1.693 droeschl 5905: vertical-align: bottom;
5906: }
5907:
1.721 harmsja 5908: ol.LC_smallMenu a {
1.693 droeschl 5909: font-size: 90%;
5910: color: RGB(80, 80, 80);
5911: text-decoration: none;
5912: }
1.795 www 5913:
1.808 droeschl 5914: ul#LC_TabMainMenuContent {
1.807 droeschl 5915: clear: both;
1.808 droeschl 5916: color: $fontmenu;
5917: background: $tabbg;
5918: list-style: none;
5919: padding: 0;
5920: margin: 0;
5921: width: 100%;
5922: }
5923:
5924: ul#LC_TabMainMenuContent li {
5925: font-weight: bold;
5926: line-height: 1.8em;
5927: padding: 0 0.8em;
5928: border-right: 1px solid black;
5929: display: inline;
5930: vertical-align: middle;
1.807 droeschl 5931: }
5932:
1.847 tempelho 5933: ul.LC_TabContent {
1.721 harmsja 5934: display:block;
1.847 tempelho 5935: background: $sidebg;
1.858 bisitz 5936: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5937: list-style:none;
1.870 tempelho 5938: margin: 0 -10px;
1.803 bisitz 5939: padding: 0;
1.693 droeschl 5940: }
5941:
1.795 www 5942: ul.LC_TabContent li,
5943: ul.LC_TabContentBigger li {
1.741 harmsja 5944: float:left;
5945: }
1.795 www 5946:
1.808 droeschl 5947: ul#LC_TabMainMenuContent li a {
5948: color: $fontmenu;
1.693 droeschl 5949: text-decoration: none;
5950: }
1.795 www 5951:
1.721 harmsja 5952: ul.LC_TabContent {
1.847 tempelho 5953: min-height:1.5em;
1.721 harmsja 5954: }
1.795 www 5955:
5956: ul.LC_TabContent li {
1.741 harmsja 5957: vertical-align:middle;
1.803 bisitz 5958: padding: 0 10px 0 10px;
1.745 ehlerst 5959: background-color:$tabbg;
5960: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5961: }
1.795 www 5962:
1.847 tempelho 5963: ul.LC_TabContent .right {
5964: float:right;
5965: }
5966:
1.795 www 5967: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5968: color:rgb(47,47,47);
5969: text-decoration:none;
5970: font-size:95%;
5971: font-weight:bold;
1.761 tempelho 5972: padding-right: 16px;
1.721 harmsja 5973: }
1.795 www 5974:
5975: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5976: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5977: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5978: padding-right: 16px;
1.744 ehlerst 5979: }
1.795 www 5980:
1.870 tempelho 5981: #maincoursedoc {
5982: clear:both;
5983: }
5984:
5985: ul.LC_TabContentBigger {
5986: display:block;
5987: list-style:none;
5988: padding: 0;
5989: }
5990:
1.795 www 5991: ul.LC_TabContentBigger li {
1.870 tempelho 5992: vertical-align:bottom;
5993: height: 30px;
5994: font-size:110%;
5995: font-weight:bold;
5996: color: #737373;
1.841 tempelho 5997: }
5998:
1.870 tempelho 5999:
6000: ul.LC_TabContentBigger li a {
6001: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6002: height: 30px;
6003: line-height: 30px;
6004: text-align: center;
6005: display: block;
6006: text-decoration: none;
1.741 harmsja 6007: }
1.795 www 6008:
1.870 tempelho 6009: ul.LC_TabContentBigger li:hover a,
6010: ul.LC_TabContentBigger li.active a {
6011: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857 tempelho 6012: color:$font;
1.870 tempelho 6013: text-decoration: underline;
1.744 ehlerst 6014: }
1.795 www 6015:
1.870 tempelho 6016:
6017: ul.LC_TabContentBigger li b {
6018: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6019: display: block;
6020: float: left;
6021: padding: 0 30px;
6022: }
6023:
6024: ul.LC_TabContentBigger li:hover b,
6025: ul.LC_TabContentBigger li.active b {
6026: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6027: color:$font;
6028: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6029: }
1.693 droeschl 6030:
1.870 tempelho 6031:
1.862 bisitz 6032: ul.LC_CourseBreadcrumbs {
6033: background: $sidebg;
6034: line-height: 32px;
6035: padding-left: 10px;
6036: margin: 0 0 10px 0;
6037: list-style-position: inside;
6038:
6039: }
6040:
1.795 www 6041: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6042: ol#LC_PathBreadcrumbs {
1.693 droeschl 6043: padding-left: 10px;
1.819 tempelho 6044: margin: 0;
1.693 droeschl 6045: list-style-position: inside;
6046: }
6047:
1.795 www 6048: ol#LC_MenuBreadcrumbs li,
6049: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6050: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 6051: display: inline;
6052: white-space: nowrap;
1.693 droeschl 6053: }
6054:
1.823 bisitz 6055: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6056: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 6057: text-decoration: none;
6058: font-size:90%;
6059: }
1.795 www 6060:
6061: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6062: text-decoration:none;
6063: font-size:100%;
6064: font-weight:bold;
1.693 droeschl 6065: }
1.795 www 6066:
1.840 bisitz 6067: .LC_Box {
1.835 bisitz 6068: border: solid 1px $lg_border_color;
6069: padding: 0 10px 10px 10px;
1.746 neumanie 6070: }
1.795 www 6071:
6072: .LC_AboutMe_Image {
1.747 neumanie 6073: float:left;
6074: margin-right:10px;
6075: }
1.795 www 6076:
6077: .LC_Clear_AboutMe_Image {
1.747 neumanie 6078: clear:left;
6079: }
1.795 www 6080:
1.721 harmsja 6081: dl.LC_ListStyleClean dt {
1.693 droeschl 6082: padding-right: 5px;
6083: display: table-header-group;
6084: }
6085:
1.721 harmsja 6086: dl.LC_ListStyleClean dd {
1.693 droeschl 6087: display: table-row;
6088: }
6089:
1.721 harmsja 6090: .LC_ListStyleClean,
6091: .LC_ListStyleSimple,
6092: .LC_ListStyleNormal,
1.777 tempelho 6093: .LC_ListStyle_Border,
1.795 www 6094: .LC_ListStyleSpecial {
1.693 droeschl 6095: /*display:block; */
6096: list-style-position: inside;
6097: list-style-type: none;
6098: overflow: hidden;
1.803 bisitz 6099: padding: 0;
1.693 droeschl 6100: }
6101:
1.721 harmsja 6102: .LC_ListStyleSimple li,
6103: .LC_ListStyleSimple dd,
6104: .LC_ListStyleNormal li,
6105: .LC_ListStyleNormal dd,
6106: .LC_ListStyleSpecial li,
1.795 www 6107: .LC_ListStyleSpecial dd {
1.803 bisitz 6108: margin: 0;
1.693 droeschl 6109: padding: 5px 5px 5px 10px;
6110: clear: both;
6111: }
6112:
1.721 harmsja 6113: .LC_ListStyleClean li,
6114: .LC_ListStyleClean dd {
1.803 bisitz 6115: padding-top: 0;
6116: padding-bottom: 0;
1.693 droeschl 6117: }
6118:
1.721 harmsja 6119: .LC_ListStyleSimple dd,
1.795 www 6120: .LC_ListStyleSimple li {
1.698 harmsja 6121: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6122: }
6123:
1.721 harmsja 6124: .LC_ListStyleSpecial li,
6125: .LC_ListStyleSpecial dd {
1.693 droeschl 6126: list-style-type: none;
6127: background-color: RGB(220, 220, 220);
6128: margin-bottom: 4px;
6129: }
6130:
1.721 harmsja 6131: table.LC_SimpleTable {
1.698 harmsja 6132: margin:5px;
6133: border:solid 1px $lg_border_color;
1.795 www 6134: }
1.693 droeschl 6135:
1.721 harmsja 6136: table.LC_SimpleTable tr {
1.803 bisitz 6137: padding: 0;
1.698 harmsja 6138: border:solid 1px $lg_border_color;
1.693 droeschl 6139: }
1.795 www 6140:
6141: table.LC_SimpleTable thead {
1.698 harmsja 6142: background:rgb(220,220,220);
1.693 droeschl 6143: }
6144:
1.721 harmsja 6145: div.LC_columnSection {
1.693 droeschl 6146: display: block;
6147: clear: both;
6148: overflow: hidden;
1.803 bisitz 6149: margin: 0;
1.693 droeschl 6150: }
6151:
1.721 harmsja 6152: div.LC_columnSection>* {
1.693 droeschl 6153: float: left;
1.803 bisitz 6154: margin: 10px 20px 10px 0;
1.747 neumanie 6155: overflow:hidden;
1.693 droeschl 6156: }
1.721 harmsja 6157:
1.694 tempelho 6158: .LC_loginpage_container {
6159: text-align:left;
6160: margin : 0 auto;
1.785 tempelho 6161: width:90%;
1.694 tempelho 6162: padding: 10px;
6163: height: auto;
1.712 muellerd 6164: background-color:#FFFFFF;
1.694 tempelho 6165: border:1px solid #CCCCCC;
6166: }
6167:
6168:
6169: .LC_loginpage_loginContainer {
6170: float:left;
1.712 muellerd 6171: width: 182px;
1.785 tempelho 6172: padding: 2px;
1.712 muellerd 6173: border:1px solid #CCCCCC;
6174: background-color:$loginbg;
1.694 tempelho 6175: }
6176:
1.795 www 6177: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6178: margin-top: 0;
1.712 muellerd 6179: display:block;
6180: background:$bgcol;
6181: color:$textcol;
6182: padding-left:5px;
6183: }
1.785 tempelho 6184:
1.694 tempelho 6185: .LC_loginpage_loginInfo {
6186: float:left;
1.785 tempelho 6187: width:182px;
1.694 tempelho 6188: border:1px solid #CCCCCC;
1.785 tempelho 6189: padding:2px;
1.712 muellerd 6190: }
6191:
1.694 tempelho 6192: .LC_loginpage_space {
1.754 droeschl 6193: clear: both;
6194: margin-bottom: 20px;
1.694 tempelho 6195: border-bottom: 1px solid #CCCCCC;
6196: }
6197:
1.785 tempelho 6198: .LC_loginpage_floatLeft {
6199: float: left;
6200: width: 200px;
6201: margin: 0;
6202: }
6203:
1.795 www 6204: table em {
1.754 droeschl 6205: font-weight: bold;
6206: font-style: normal;
1.748 schulted 6207: }
1.795 www 6208:
1.779 bisitz 6209: table.LC_tableBrowseRes,
1.795 www 6210: table.LC_tableOfContent {
1.769 schulted 6211: border:none;
1.858 bisitz 6212: border-spacing: 1px;
1.754 droeschl 6213: padding: 3px;
6214: background-color: #FFFFFF;
6215: font-size: 90%;
1.753 droeschl 6216: }
1.789 droeschl 6217:
6218: table.LC_tableOfContent{
6219: border-collapse: collapse;
6220: }
6221:
1.771 droeschl 6222: table.LC_tableBrowseRes a,
1.768 schulted 6223: table.LC_tableOfContent a {
1.771 droeschl 6224: background-color: transparent;
1.753 droeschl 6225: text-decoration: none;
6226: }
6227:
1.771 droeschl 6228: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6229: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6230: background-color: #EEEEEE;
1.753 droeschl 6231: }
6232:
1.795 www 6233: table.LC_tableOfContent img {
1.753 droeschl 6234: border: none;
6235: height: 1.3em;
6236: vertical-align: text-bottom;
6237: margin-right: 0.3em;
6238: }
1.757 schulted 6239:
1.795 www 6240: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6241: background-image:url(/res/adm/pages/open-first-problem.gif);
6242: }
6243:
1.795 www 6244: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6245: background-image:url(/res/adm/pages/start-navigation.gif);
6246: }
6247:
1.795 www 6248: a#LC_content_toolbar_closenav {
1.774 ehlerst 6249: background-image:url(/res/adm/pages/close-navigation.gif);
6250: }
6251:
1.795 www 6252: a#LC_content_toolbar_everything {
1.774 ehlerst 6253: background-image:url(/res/adm/pages/show-all.gif);
6254: }
6255:
1.795 www 6256: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6257: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6258: }
6259:
1.795 www 6260: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6261: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6262: }
6263:
1.795 www 6264: a#LC_content_toolbar_changefolder {
1.757 schulted 6265: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6266: }
6267:
1.795 www 6268: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6269: background-image:url(/res/adm/pages/open-all-folders.gif);
6270: }
6271:
1.795 www 6272: ul#LC_toolbar li a:hover {
1.757 schulted 6273: background-position: bottom center;
6274: }
6275:
1.795 www 6276: ul#LC_toolbar {
1.803 bisitz 6277: padding: 0;
1.757 schulted 6278: margin: 2px;
6279: list-style:none;
6280: position:relative;
6281: background-color:white;
6282: }
6283:
1.795 www 6284: ul#LC_toolbar li {
1.757 schulted 6285: border:1px solid white;
1.803 bisitz 6286: padding: 0;
1.757 schulted 6287: margin: 0;
1.795 www 6288: float: left;
1.767 droeschl 6289: display:inline;
1.757 schulted 6290: vertical-align:middle;
1.795 www 6291: }
1.757 schulted 6292:
1.783 amueller 6293:
1.795 www 6294: a.LC_toolbarItem {
1.767 droeschl 6295: display:block;
1.803 bisitz 6296: padding: 0;
6297: margin: 0;
1.757 schulted 6298: height: 32px;
6299: width: 32px;
1.779 bisitz 6300: color:white;
1.803 bisitz 6301: border: none;
1.757 schulted 6302: background-repeat:no-repeat;
6303: background-color:transparent;
6304: }
6305:
1.843 bisitz 6306: ul.LC_funclist li {
1.782 bisitz 6307: float: left;
6308: white-space: nowrap;
6309: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6310: margin: 0 15px 15px 10px;
1.782 bisitz 6311: }
6312:
1.757 schulted 6313:
1.343 albertel 6314: END
6315: }
6316:
1.306 albertel 6317: =pod
6318:
6319: =item * &headtag()
6320:
6321: Returns a uniform footer for LON-CAPA web pages.
6322:
1.307 albertel 6323: Inputs: $title - optional title for the head
6324: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6325: $args - optional arguments
1.319 albertel 6326: force_register - if is true call registerurl so the remote is
6327: informed
1.415 albertel 6328: redirect -> array ref of
6329: 1- seconds before redirect occurs
6330: 2- url to redirect to
6331: 3- whether the side effect should occur
1.315 albertel 6332: (side effect of setting
6333: $env{'internal.head.redirect'} to the url
6334: redirected too)
1.352 albertel 6335: domain -> force to color decorate a page for a specific
6336: domain
6337: function -> force usage of a specific rolish color scheme
6338: bgcolor -> override the default page bgcolor
1.460 albertel 6339: no_auto_mt_title
6340: -> prevent &mt()ing the title arg
1.464 albertel 6341:
1.306 albertel 6342: =cut
6343:
6344: sub headtag {
1.313 albertel 6345: my ($title,$head_extra,$args) = @_;
1.306 albertel 6346:
1.363 albertel 6347: my $function = $args->{'function'} || &get_users_function();
6348: my $domain = $args->{'domain'} || &determinedomain();
6349: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6350: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6351: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6352: #time(),
1.418 albertel 6353: $env{'environment.color.timestamp'},
1.363 albertel 6354: $function,$domain,$bgcolor);
6355:
1.369 www 6356: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6357:
1.308 albertel 6358: my $result =
6359: '<head>'.
1.461 albertel 6360: &font_settings();
1.319 albertel 6361:
1.461 albertel 6362: if (!$args->{'frameset'}) {
6363: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6364: }
1.319 albertel 6365: if ($args->{'force_register'}) {
6366: $result .= &Apache::lonmenu::registerurl(1);
6367: }
1.436 albertel 6368: if (!$args->{'no_nav_bar'}
6369: && !$args->{'only_body'}
6370: && !$args->{'frameset'}) {
6371: $result .= &help_menu_js();
6372: }
1.319 albertel 6373:
1.314 albertel 6374: if (ref($args->{'redirect'})) {
1.414 albertel 6375: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6376: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6377: if (!$inhibit_continue) {
6378: $env{'internal.head.redirect'} = $url;
6379: }
1.313 albertel 6380: $result.=<<ADDMETA
6381: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6382: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6383: ADDMETA
6384: }
1.306 albertel 6385: if (!defined($title)) {
6386: $title = 'The LearningOnline Network with CAPA';
6387: }
1.460 albertel 6388: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6389: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6390: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6391: .$head_extra;
1.306 albertel 6392: return $result;
6393: }
6394:
6395: =pod
6396:
1.340 albertel 6397: =item * &font_settings()
6398:
6399: Returns neccessary <meta> to set the proper encoding
6400:
6401: Inputs: none
6402:
6403: =cut
6404:
6405: sub font_settings {
6406: my $headerstring='';
1.647 www 6407: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6408: $headerstring.=
6409: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6410: }
6411: return $headerstring;
6412: }
6413:
1.341 albertel 6414: =pod
6415:
6416: =item * &xml_begin()
6417:
6418: Returns the needed doctype and <html>
6419:
6420: Inputs: none
6421:
6422: =cut
6423:
6424: sub xml_begin {
6425: my $output='';
6426:
1.592 albertel 6427: if ($env{'internal.start_page'}==1) {
6428: &Apache::lonhtmlcommon::init_htmlareafields();
6429: }
1.342 albertel 6430:
1.341 albertel 6431: if ($env{'browser.mathml'}) {
6432: $output='<?xml version="1.0"?>'
6433: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6434: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6435:
6436: # .'<!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">] >'
6437: .'<!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">'
6438: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6439: .'xmlns="http://www.w3.org/1999/xhtml">';
6440: } else {
1.849 bisitz 6441: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6442: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6443: }
6444: return $output;
6445: }
1.340 albertel 6446:
6447: =pod
6448:
1.306 albertel 6449: =item * &endheadtag()
6450:
6451: Returns a uniform </head> for LON-CAPA web pages.
6452:
6453: Inputs: none
6454:
6455: =cut
6456:
6457: sub endheadtag {
6458: return '</head>';
6459: }
6460:
6461: =pod
6462:
6463: =item * &head()
6464:
6465: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6466:
1.648 raeburn 6467: Inputs:
6468:
6469: =over 4
6470:
6471: $title - optional title for the page
6472:
6473: $head_extra - optional extra HTML to put inside the <head>
6474:
6475: =back
1.405 albertel 6476:
1.306 albertel 6477: =cut
6478:
6479: sub head {
1.325 albertel 6480: my ($title,$head_extra,$args) = @_;
6481: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6482: }
6483:
6484: =pod
6485:
6486: =item * &start_page()
6487:
6488: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6489:
1.648 raeburn 6490: Inputs:
6491:
6492: =over 4
6493:
6494: $title - optional title for the page
6495:
6496: $head_extra - optional extra HTML to incude inside the <head>
6497:
6498: $args - additional optional args supported are:
6499:
6500: =over 8
6501:
6502: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6503: arg on
1.814 bisitz 6504: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6505: add_entries -> additional attributes to add to the <body>
6506: domain -> force to color decorate a page for a
1.317 albertel 6507: specific domain
1.648 raeburn 6508: function -> force usage of a specific rolish color
1.317 albertel 6509: scheme
1.648 raeburn 6510: redirect -> see &headtag()
6511: bgcolor -> override the default page bg color
6512: js_ready -> return a string ready for being used in
1.317 albertel 6513: a javascript writeln
1.648 raeburn 6514: html_encode -> return a string ready for being used in
1.320 albertel 6515: a html attribute
1.648 raeburn 6516: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6517: $forcereg arg
1.648 raeburn 6518: frameset -> if true will start with a <frameset>
1.330 albertel 6519: rather than <body>
1.648 raeburn 6520: skip_phases -> hash ref of
1.338 albertel 6521: head -> skip the <html><head> generation
6522: body -> skip all <body> generation
1.648 raeburn 6523: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6524: 'Switch To Inline Menu' link
1.648 raeburn 6525: no_auto_mt_title -> prevent &mt()ing the title arg
6526: inherit_jsmath -> when creating popup window in a page,
6527: should it have jsmath forced on by the
6528: current page
1.867 kalberla 6529: bread_crumbs -> Array containing breadcrumbs
6530: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6531:
1.648 raeburn 6532: =back
1.460 albertel 6533:
1.648 raeburn 6534: =back
1.562 albertel 6535:
1.306 albertel 6536: =cut
6537:
6538: sub start_page {
1.309 albertel 6539: my ($title,$head_extra,$args) = @_;
1.318 albertel 6540: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6541: my %head_args;
1.352 albertel 6542: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6543: 'bgcolor','frameset','no_nav_bar','only_body',
6544: 'no_auto_mt_title') {
1.319 albertel 6545: if (defined($args->{$arg})) {
1.324 raeburn 6546: $head_args{$arg} = $args->{$arg};
1.319 albertel 6547: }
1.313 albertel 6548: }
1.319 albertel 6549:
1.315 albertel 6550: $env{'internal.start_page'}++;
1.338 albertel 6551: my $result;
6552: if (! exists($args->{'skip_phases'}{'head'}) ) {
6553: $result.=
1.341 albertel 6554: &xml_begin().
1.338 albertel 6555: &headtag($title,$head_extra,\%head_args).&endheadtag();
6556: }
6557:
6558: if (! exists($args->{'skip_phases'}{'body'}) ) {
6559: if ($args->{'frameset'}) {
6560: my $attr_string = &make_attr_string($args->{'force_register'},
6561: $args->{'add_entries'});
6562: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6563: } else {
6564: $result .=
6565: &bodytag($title,
6566: $args->{'function'}, $args->{'add_entries'},
6567: $args->{'only_body'}, $args->{'domain'},
6568: $args->{'force_register'}, $args->{'no_nav_bar'},
6569: $args->{'bgcolor'}, $args->{'no_inline_link'},
6570: $args);
6571: }
1.330 albertel 6572: }
1.338 albertel 6573:
1.315 albertel 6574: if ($args->{'js_ready'}) {
1.713 kaisler 6575: $result = &js_ready($result);
1.315 albertel 6576: }
1.320 albertel 6577: if ($args->{'html_encode'}) {
1.713 kaisler 6578: $result = &html_encode($result);
6579: }
6580:
1.813 bisitz 6581: # Preparation for new and consistent functionlist at top of screen
6582: # if ($args->{'functionlist'}) {
6583: # $result .= &build_functionlist();
6584: #}
6585:
6586: # Don't add anything more if only_body wanted
6587: return $result if $args->{'only_body'};
6588:
6589: #Breadcrumbs
1.758 kaisler 6590: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6591: &Apache::lonhtmlcommon::clear_breadcrumbs();
6592: #if any br links exists, add them to the breadcrumbs
6593: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6594: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6595: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6596: }
6597: }
6598:
6599: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6600: if(exists($args->{'bread_crumbs_component'})){
6601: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6602: }else{
6603: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6604: }
1.320 albertel 6605: }
1.315 albertel 6606: return $result;
1.306 albertel 6607: }
6608:
1.330 albertel 6609:
1.306 albertel 6610: =pod
6611:
6612: =item * &head()
6613:
6614: Returns a complete </body></html> section for LON-CAPA web pages.
6615:
1.315 albertel 6616: Inputs: $args - additional optional args supported are:
6617: js_ready -> return a string ready for being used in
6618: a javascript writeln
1.320 albertel 6619: html_encode -> return a string ready for being used in
6620: a html attribute
1.330 albertel 6621: frameset -> if true will start with a <frameset>
6622: rather than <body>
1.493 albertel 6623: dicsussion -> if true will get discussion from
6624: lonxml::xmlend
6625: (you can pass the target and parser arguments
6626: through optional 'target' and 'parser' args
6627: to this routine)
1.306 albertel 6628:
6629: =cut
6630:
6631: sub end_page {
1.315 albertel 6632: my ($args) = @_;
6633: $env{'internal.end_page'}++;
1.330 albertel 6634: my $result;
1.335 albertel 6635: if ($args->{'discussion'}) {
6636: my ($target,$parser);
6637: if (ref($args->{'discussion'})) {
6638: ($target,$parser) =($args->{'discussion'}{'target'},
6639: $args->{'discussion'}{'parser'});
6640: }
6641: $result .= &Apache::lonxml::xmlend($target,$parser);
6642: }
6643:
1.330 albertel 6644: if ($args->{'frameset'}) {
6645: $result .= '</frameset>';
6646: } else {
1.635 raeburn 6647: $result .= &endbodytag($args);
1.330 albertel 6648: }
6649: $result .= "\n</html>";
6650:
1.315 albertel 6651: if ($args->{'js_ready'}) {
1.317 albertel 6652: $result = &js_ready($result);
1.315 albertel 6653: }
1.335 albertel 6654:
1.320 albertel 6655: if ($args->{'html_encode'}) {
6656: $result = &html_encode($result);
6657: }
1.335 albertel 6658:
1.315 albertel 6659: return $result;
6660: }
6661:
1.320 albertel 6662: sub html_encode {
6663: my ($result) = @_;
6664:
1.322 albertel 6665: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6666:
6667: return $result;
6668: }
1.317 albertel 6669: sub js_ready {
6670: my ($result) = @_;
6671:
1.323 albertel 6672: $result =~ s/[\n\r]/ /xmsg;
6673: $result =~ s/\\/\\\\/xmsg;
6674: $result =~ s/'/\\'/xmsg;
1.372 albertel 6675: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6676:
6677: return $result;
6678: }
6679:
1.315 albertel 6680: sub validate_page {
6681: if ( exists($env{'internal.start_page'})
1.316 albertel 6682: && $env{'internal.start_page'} > 1) {
6683: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6684: $env{'internal.start_page'}.' '.
1.316 albertel 6685: $ENV{'request.filename'});
1.315 albertel 6686: }
6687: if ( exists($env{'internal.end_page'})
1.316 albertel 6688: && $env{'internal.end_page'} > 1) {
6689: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6690: $env{'internal.end_page'}.' '.
1.316 albertel 6691: $env{'request.filename'});
1.315 albertel 6692: }
6693: if ( exists($env{'internal.start_page'})
6694: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6695: &Apache::lonnet::logthis('start_page called without end_page '.
6696: $env{'request.filename'});
1.315 albertel 6697: }
6698: if ( ! exists($env{'internal.start_page'})
6699: && exists($env{'internal.end_page'})) {
1.316 albertel 6700: &Apache::lonnet::logthis('end_page called without start_page'.
6701: $env{'request.filename'});
1.315 albertel 6702: }
1.306 albertel 6703: }
1.315 albertel 6704:
1.318 albertel 6705: sub simple_error_page {
6706: my ($r,$title,$msg) = @_;
6707: my $page =
6708: &Apache::loncommon::start_page($title).
6709: &mt($msg).
6710: &Apache::loncommon::end_page();
6711: if (ref($r)) {
6712: $r->print($page);
1.327 albertel 6713: return;
1.318 albertel 6714: }
6715: return $page;
6716: }
1.347 albertel 6717:
6718: {
1.610 albertel 6719: my @row_count;
1.347 albertel 6720: sub start_data_table {
1.422 albertel 6721: my ($add_class) = @_;
6722: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6723: unshift(@row_count,0);
1.422 albertel 6724: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6725: }
6726:
6727: sub end_data_table {
1.610 albertel 6728: shift(@row_count);
1.389 albertel 6729: return '</table>'."\n";;
1.347 albertel 6730: }
6731:
6732: sub start_data_table_row {
1.422 albertel 6733: my ($add_class) = @_;
1.610 albertel 6734: $row_count[0]++;
6735: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6736: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6737: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6738: }
1.471 banghart 6739:
6740: sub continue_data_table_row {
6741: my ($add_class) = @_;
1.610 albertel 6742: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6743: $css_class = (join(' ',$css_class,$add_class));
6744: return '<tr class="'.$css_class.'">'."\n";;
6745: }
1.347 albertel 6746:
6747: sub end_data_table_row {
1.389 albertel 6748: return '</tr>'."\n";;
1.347 albertel 6749: }
1.367 www 6750:
1.421 albertel 6751: sub start_data_table_empty_row {
1.707 bisitz 6752: # $row_count[0]++;
1.421 albertel 6753: return '<tr class="LC_empty_row" >'."\n";;
6754: }
6755:
6756: sub end_data_table_empty_row {
6757: return '</tr>'."\n";;
6758: }
6759:
1.367 www 6760: sub start_data_table_header_row {
1.389 albertel 6761: return '<tr class="LC_header_row">'."\n";;
1.367 www 6762: }
6763:
6764: sub end_data_table_header_row {
1.389 albertel 6765: return '</tr>'."\n";;
1.367 www 6766: }
1.347 albertel 6767: }
6768:
1.548 albertel 6769: =pod
6770:
6771: =item * &inhibit_menu_check($arg)
6772:
6773: Checks for a inhibitmenu state and generates output to preserve it
6774:
6775: Inputs: $arg - can be any of
6776: - undef - in which case the return value is a string
6777: to add into arguments list of a uri
6778: - 'input' - in which case the return value is a HTML
6779: <form> <input> field of type hidden to
6780: preserve the value
6781: - a url - in which case the return value is the url with
6782: the neccesary cgi args added to preserve the
6783: inhibitmenu state
6784: - a ref to a url - no return value, but the string is
6785: updated to include the neccessary cgi
6786: args to preserve the inhibitmenu state
6787:
6788: =cut
6789:
6790: sub inhibit_menu_check {
6791: my ($arg) = @_;
6792: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6793: if ($arg eq 'input') {
6794: if ($env{'form.inhibitmenu'}) {
6795: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6796: } else {
6797: return
6798: }
6799: }
6800: if ($env{'form.inhibitmenu'}) {
6801: if (ref($arg)) {
6802: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6803: } elsif ($arg eq '') {
6804: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6805: } else {
6806: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6807: }
6808: }
6809: if (!ref($arg)) {
6810: return $arg;
6811: }
6812: }
6813:
1.251 albertel 6814: ###############################################
1.182 matthew 6815:
6816: =pod
6817:
1.549 albertel 6818: =back
6819:
6820: =head1 User Information Routines
6821:
6822: =over 4
6823:
1.405 albertel 6824: =item * &get_users_function()
1.182 matthew 6825:
6826: Used by &bodytag to determine the current users primary role.
6827: Returns either 'student','coordinator','admin', or 'author'.
6828:
6829: =cut
6830:
6831: ###############################################
6832: sub get_users_function {
1.815 tempelho 6833: my $function = 'norole';
1.818 tempelho 6834: if ($env{'request.role'}=~/^(st)/) {
6835: $function='student';
6836: }
1.258 albertel 6837: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6838: $function='coordinator';
6839: }
1.258 albertel 6840: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6841: $function='admin';
6842: }
1.826 bisitz 6843: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6844: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6845: $function='author';
6846: }
6847: return $function;
1.54 www 6848: }
1.99 www 6849:
6850: ###############################################
6851:
1.233 raeburn 6852: =pod
6853:
1.821 raeburn 6854: =item * &show_course()
6855:
6856: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6857: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6858:
6859: Inputs:
6860: None
6861:
6862: Outputs:
6863: Scalar: 1 if 'Course' to be used, 0 otherwise.
6864:
6865: =cut
6866:
6867: ###############################################
6868: sub show_course {
6869: my $course = !$env{'user.adv'};
6870: if (!$env{'user.adv'}) {
6871: foreach my $env (keys(%env)) {
6872: next if ($env !~ m/^user\.priv\./);
6873: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6874: $course = 0;
6875: last;
6876: }
6877: }
6878: }
6879: return $course;
6880: }
6881:
6882: ###############################################
6883:
6884: =pod
6885:
1.542 raeburn 6886: =item * &check_user_status()
1.274 raeburn 6887:
6888: Determines current status of supplied role for a
6889: specific user. Roles can be active, previous or future.
6890:
6891: Inputs:
6892: user's domain, user's username, course's domain,
1.375 raeburn 6893: course's number, optional section ID.
1.274 raeburn 6894:
6895: Outputs:
6896: role status: active, previous or future.
6897:
6898: =cut
6899:
6900: sub check_user_status {
1.412 raeburn 6901: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6902: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6903: my @uroles = keys %userinfo;
6904: my $srchstr;
6905: my $active_chk = 'none';
1.412 raeburn 6906: my $now = time;
1.274 raeburn 6907: if (@uroles > 0) {
1.412 raeburn 6908: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6909: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6910: } else {
1.412 raeburn 6911: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6912: }
6913: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6914: my $role_end = 0;
6915: my $role_start = 0;
6916: $active_chk = 'active';
1.412 raeburn 6917: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6918: $role_end = $1;
6919: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6920: $role_start = $1;
1.274 raeburn 6921: }
6922: }
6923: if ($role_start > 0) {
1.412 raeburn 6924: if ($now < $role_start) {
1.274 raeburn 6925: $active_chk = 'future';
6926: }
6927: }
6928: if ($role_end > 0) {
1.412 raeburn 6929: if ($now > $role_end) {
1.274 raeburn 6930: $active_chk = 'previous';
6931: }
6932: }
6933: }
6934: }
6935: return $active_chk;
6936: }
6937:
6938: ###############################################
6939:
6940: =pod
6941:
1.405 albertel 6942: =item * &get_sections()
1.233 raeburn 6943:
6944: Determines all the sections for a course including
6945: sections with students and sections containing other roles.
1.419 raeburn 6946: Incoming parameters:
6947:
6948: 1. domain
6949: 2. course number
6950: 3. reference to array containing roles for which sections should
6951: be gathered (optional).
6952: 4. reference to array containing status types for which sections
6953: should be gathered (optional).
6954:
6955: If the third argument is undefined, sections are gathered for any role.
6956: If the fourth argument is undefined, sections are gathered for any status.
6957: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6958:
1.374 raeburn 6959: Returns section hash (keys are section IDs, values are
6960: number of users in each section), subject to the
1.419 raeburn 6961: optional roles filter, optional status filter
1.233 raeburn 6962:
6963: =cut
6964:
6965: ###############################################
6966: sub get_sections {
1.419 raeburn 6967: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6968: if (!defined($cdom) || !defined($cnum)) {
6969: my $cid = $env{'request.course.id'};
6970:
6971: return if (!defined($cid));
6972:
6973: $cdom = $env{'course.'.$cid.'.domain'};
6974: $cnum = $env{'course.'.$cid.'.num'};
6975: }
6976:
6977: my %sectioncount;
1.419 raeburn 6978: my $now = time;
1.240 albertel 6979:
1.366 albertel 6980: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6981: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6982: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6983: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6984: my $start_index = &Apache::loncoursedata::CL_START();
6985: my $end_index = &Apache::loncoursedata::CL_END();
6986: my $status;
1.366 albertel 6987: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6988: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6989: $data->[$status_index],
6990: $data->[$start_index],
6991: $data->[$end_index]);
6992: if ($stu_status eq 'Active') {
6993: $status = 'active';
6994: } elsif ($end < $now) {
6995: $status = 'previous';
6996: } elsif ($start > $now) {
6997: $status = 'future';
6998: }
6999: if ($section ne '-1' && $section !~ /^\s*$/) {
7000: if ((!defined($possible_status)) || (($status ne '') &&
7001: (grep/^\Q$status\E$/,@{$possible_status}))) {
7002: $sectioncount{$section}++;
7003: }
1.240 albertel 7004: }
7005: }
7006: }
7007: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7008: foreach my $user (sort(keys(%courseroles))) {
7009: if ($user !~ /^(\w{2})/) { next; }
7010: my ($role) = ($user =~ /^(\w{2})/);
7011: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7012: my ($section,$status);
1.240 albertel 7013: if ($role eq 'cr' &&
7014: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7015: $section=$1;
7016: }
7017: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7018: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7019: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7020: if ($end == -1 && $start == -1) {
7021: next; #deleted role
7022: }
7023: if (!defined($possible_status)) {
7024: $sectioncount{$section}++;
7025: } else {
7026: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7027: $status = 'active';
7028: } elsif ($end < $now) {
7029: $status = 'future';
7030: } elsif ($start > $now) {
7031: $status = 'previous';
7032: }
7033: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7034: $sectioncount{$section}++;
7035: }
7036: }
1.233 raeburn 7037: }
1.366 albertel 7038: return %sectioncount;
1.233 raeburn 7039: }
7040:
1.274 raeburn 7041: ###############################################
1.294 raeburn 7042:
7043: =pod
1.405 albertel 7044:
7045: =item * &get_course_users()
7046:
1.275 raeburn 7047: Retrieves usernames:domains for users in the specified course
7048: with specific role(s), and access status.
7049:
7050: Incoming parameters:
1.277 albertel 7051: 1. course domain
7052: 2. course number
7053: 3. access status: users must have - either active,
1.275 raeburn 7054: previous, future, or all.
1.277 albertel 7055: 4. reference to array of permissible roles
1.288 raeburn 7056: 5. reference to array of section restrictions (optional)
7057: 6. reference to results object (hash of hashes).
7058: 7. reference to optional userdata hash
1.609 raeburn 7059: 8. reference to optional statushash
1.630 raeburn 7060: 9. flag if privileged users (except those set to unhide in
7061: course settings) should be excluded
1.609 raeburn 7062: Keys of top level results hash are roles.
1.275 raeburn 7063: Keys of inner hashes are username:domain, with
7064: values set to access type.
1.288 raeburn 7065: Optional userdata hash returns an array with arguments in the
7066: same order as loncoursedata::get_classlist() for student data.
7067:
1.609 raeburn 7068: Optional statushash returns
7069:
1.288 raeburn 7070: Entries for end, start, section and status are blank because
7071: of the possibility of multiple values for non-student roles.
7072:
1.275 raeburn 7073: =cut
1.405 albertel 7074:
1.275 raeburn 7075: ###############################################
1.405 albertel 7076:
1.275 raeburn 7077: sub get_course_users {
1.630 raeburn 7078: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7079: my %idx = ();
1.419 raeburn 7080: my %seclists;
1.288 raeburn 7081:
7082: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7083: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7084: $idx{end} = &Apache::loncoursedata::CL_END();
7085: $idx{start} = &Apache::loncoursedata::CL_START();
7086: $idx{id} = &Apache::loncoursedata::CL_ID();
7087: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7088: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7089: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7090:
1.290 albertel 7091: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7092: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7093: my $now = time;
1.277 albertel 7094: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7095: my $match = 0;
1.412 raeburn 7096: my $secmatch = 0;
1.419 raeburn 7097: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7098: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7099: if ($section eq '') {
7100: $section = 'none';
7101: }
1.291 albertel 7102: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7103: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7104: $secmatch = 1;
7105: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7106: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7107: $secmatch = 1;
7108: }
7109: } else {
1.419 raeburn 7110: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7111: $secmatch = 1;
7112: }
1.290 albertel 7113: }
1.412 raeburn 7114: if (!$secmatch) {
7115: next;
7116: }
1.419 raeburn 7117: }
1.275 raeburn 7118: if (defined($$types{'active'})) {
1.288 raeburn 7119: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7120: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7121: $match = 1;
1.275 raeburn 7122: }
7123: }
7124: if (defined($$types{'previous'})) {
1.609 raeburn 7125: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7126: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7127: $match = 1;
1.275 raeburn 7128: }
7129: }
7130: if (defined($$types{'future'})) {
1.609 raeburn 7131: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7132: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7133: $match = 1;
1.275 raeburn 7134: }
7135: }
1.609 raeburn 7136: if ($match) {
7137: push(@{$seclists{$student}},$section);
7138: if (ref($userdata) eq 'HASH') {
7139: $$userdata{$student} = $$classlist{$student};
7140: }
7141: if (ref($statushash) eq 'HASH') {
7142: $statushash->{$student}{'st'}{$section} = $status;
7143: }
1.288 raeburn 7144: }
1.275 raeburn 7145: }
7146: }
1.412 raeburn 7147: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7148: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7149: my $now = time;
1.609 raeburn 7150: my %displaystatus = ( previous => 'Expired',
7151: active => 'Active',
7152: future => 'Future',
7153: );
1.630 raeburn 7154: my %nothide;
7155: if ($hidepriv) {
7156: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7157: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7158: if ($user !~ /:/) {
7159: $nothide{join(':',split(/[\@]/,$user))}=1;
7160: } else {
7161: $nothide{$user} = 1;
7162: }
7163: }
7164: }
1.439 raeburn 7165: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7166: my $match = 0;
1.412 raeburn 7167: my $secmatch = 0;
1.439 raeburn 7168: my $status;
1.412 raeburn 7169: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7170: $user =~ s/:$//;
1.439 raeburn 7171: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7172: if ($end == -1 || $start == -1) {
7173: next;
7174: }
7175: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7176: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7177: my ($uname,$udom) = split(/:/,$user);
7178: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7179: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7180: $secmatch = 1;
7181: } elsif ($usec eq '') {
1.420 albertel 7182: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7183: $secmatch = 1;
7184: }
7185: } else {
7186: if (grep(/^\Q$usec\E$/,@{$sections})) {
7187: $secmatch = 1;
7188: }
7189: }
7190: if (!$secmatch) {
7191: next;
7192: }
1.288 raeburn 7193: }
1.419 raeburn 7194: if ($usec eq '') {
7195: $usec = 'none';
7196: }
1.275 raeburn 7197: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7198: if ($hidepriv) {
7199: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7200: (!$nothide{$uname.':'.$udom})) {
7201: next;
7202: }
7203: }
1.503 raeburn 7204: if ($end > 0 && $end < $now) {
1.439 raeburn 7205: $status = 'previous';
7206: } elsif ($start > $now) {
7207: $status = 'future';
7208: } else {
7209: $status = 'active';
7210: }
1.277 albertel 7211: foreach my $type (keys(%{$types})) {
1.275 raeburn 7212: if ($status eq $type) {
1.420 albertel 7213: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7214: push(@{$$users{$role}{$user}},$type);
7215: }
1.288 raeburn 7216: $match = 1;
7217: }
7218: }
1.419 raeburn 7219: if (($match) && (ref($userdata) eq 'HASH')) {
7220: if (!exists($$userdata{$uname.':'.$udom})) {
7221: &get_user_info($udom,$uname,\%idx,$userdata);
7222: }
1.420 albertel 7223: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7224: push(@{$seclists{$uname.':'.$udom}},$usec);
7225: }
1.609 raeburn 7226: if (ref($statushash) eq 'HASH') {
7227: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7228: }
1.275 raeburn 7229: }
7230: }
7231: }
7232: }
1.290 albertel 7233: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7234: if ((defined($cdom)) && (defined($cnum))) {
7235: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7236: if ( defined($csettings{'internal.courseowner'}) ) {
7237: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7238: next if ($owner eq '');
7239: my ($ownername,$ownerdom);
7240: if ($owner =~ /^([^:]+):([^:]+)$/) {
7241: $ownername = $1;
7242: $ownerdom = $2;
7243: } else {
7244: $ownername = $owner;
7245: $ownerdom = $cdom;
7246: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7247: }
7248: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7249: if (defined($userdata) &&
1.609 raeburn 7250: !exists($$userdata{$owner})) {
7251: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7252: if (!grep(/^none$/,@{$seclists{$owner}})) {
7253: push(@{$seclists{$owner}},'none');
7254: }
7255: if (ref($statushash) eq 'HASH') {
7256: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7257: }
1.290 albertel 7258: }
1.279 raeburn 7259: }
7260: }
7261: }
1.419 raeburn 7262: foreach my $user (keys(%seclists)) {
7263: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7264: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7265: }
1.275 raeburn 7266: }
7267: return;
7268: }
7269:
1.288 raeburn 7270: sub get_user_info {
7271: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7272: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7273: &plainname($uname,$udom,'lastname');
1.291 albertel 7274: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7275: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7276: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7277: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7278: return;
7279: }
1.275 raeburn 7280:
1.472 raeburn 7281: ###############################################
7282:
7283: =pod
7284:
7285: =item * &get_user_quota()
7286:
7287: Retrieves quota assigned for storage of portfolio files for a user
7288:
7289: Incoming parameters:
7290: 1. user's username
7291: 2. user's domain
7292:
7293: Returns:
1.536 raeburn 7294: 1. Disk quota (in Mb) assigned to student.
7295: 2. (Optional) Type of setting: custom or default
7296: (individually assigned or default for user's
7297: institutional status).
7298: 3. (Optional) - User's institutional status (e.g., faculty, staff
7299: or student - types as defined in localenroll::inst_usertypes
7300: for user's domain, which determines default quota for user.
7301: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7302:
7303: If a value has been stored in the user's environment,
1.536 raeburn 7304: it will return that, otherwise it returns the maximal default
7305: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7306:
7307: =cut
7308:
7309: ###############################################
7310:
7311:
7312: sub get_user_quota {
7313: my ($uname,$udom) = @_;
1.536 raeburn 7314: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7315: if (!defined($udom)) {
7316: $udom = $env{'user.domain'};
7317: }
7318: if (!defined($uname)) {
7319: $uname = $env{'user.name'};
7320: }
7321: if (($udom eq '' || $uname eq '') ||
7322: ($udom eq 'public') && ($uname eq 'public')) {
7323: $quota = 0;
1.536 raeburn 7324: $quotatype = 'default';
7325: $defquota = 0;
1.472 raeburn 7326: } else {
1.536 raeburn 7327: my $inststatus;
1.472 raeburn 7328: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7329: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7330: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7331: } else {
1.536 raeburn 7332: my %userenv =
7333: &Apache::lonnet::get('environment',['portfolioquota',
7334: 'inststatus'],$udom,$uname);
1.472 raeburn 7335: my ($tmp) = keys(%userenv);
7336: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7337: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7338: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7339: } else {
7340: undef(%userenv);
7341: }
7342: }
1.536 raeburn 7343: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7344: if ($quota eq '') {
1.536 raeburn 7345: $quota = $defquota;
7346: $quotatype = 'default';
7347: } else {
7348: $quotatype = 'custom';
1.472 raeburn 7349: }
7350: }
1.536 raeburn 7351: if (wantarray) {
7352: return ($quota,$quotatype,$settingstatus,$defquota);
7353: } else {
7354: return $quota;
7355: }
1.472 raeburn 7356: }
7357:
7358: ###############################################
7359:
7360: =pod
7361:
7362: =item * &default_quota()
7363:
1.536 raeburn 7364: Retrieves default quota assigned for storage of user portfolio files,
7365: given an (optional) user's institutional status.
1.472 raeburn 7366:
7367: Incoming parameters:
7368: 1. domain
1.536 raeburn 7369: 2. (Optional) institutional status(es). This is a : separated list of
7370: status types (e.g., faculty, staff, student etc.)
7371: which apply to the user for whom the default is being retrieved.
7372: If the institutional status string in undefined, the domain
7373: default quota will be returned.
1.472 raeburn 7374:
7375: Returns:
7376: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7377: 2. (Optional) institutional type which determined the value of the
7378: default quota.
1.472 raeburn 7379:
7380: If a value has been stored in the domain's configuration db,
7381: it will return that, otherwise it returns 20 (for backwards
7382: compatibility with domains which have not set up a configuration
7383: db file; the original statically defined portfolio quota was 20 Mb).
7384:
1.536 raeburn 7385: If the user's status includes multiple types (e.g., staff and student),
7386: the largest default quota which applies to the user determines the
7387: default quota returned.
7388:
1.780 raeburn 7389: =back
7390:
1.472 raeburn 7391: =cut
7392:
7393: ###############################################
7394:
7395:
7396: sub default_quota {
1.536 raeburn 7397: my ($udom,$inststatus) = @_;
7398: my ($defquota,$settingstatus);
7399: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7400: ['quotas'],$udom);
7401: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7402: if ($inststatus ne '') {
1.765 raeburn 7403: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7404: foreach my $item (@statuses) {
1.711 raeburn 7405: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7406: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7407: if ($defquota eq '') {
7408: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7409: $settingstatus = $item;
7410: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7411: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7412: $settingstatus = $item;
7413: }
7414: }
7415: } else {
7416: if ($quotahash{'quotas'}{$item} ne '') {
7417: if ($defquota eq '') {
7418: $defquota = $quotahash{'quotas'}{$item};
7419: $settingstatus = $item;
7420: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7421: $defquota = $quotahash{'quotas'}{$item};
7422: $settingstatus = $item;
7423: }
1.536 raeburn 7424: }
7425: }
7426: }
7427: }
7428: if ($defquota eq '') {
1.711 raeburn 7429: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7430: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7431: } else {
7432: $defquota = $quotahash{'quotas'}{'default'};
7433: }
1.536 raeburn 7434: $settingstatus = 'default';
7435: }
7436: } else {
7437: $settingstatus = 'default';
7438: $defquota = 20;
7439: }
7440: if (wantarray) {
7441: return ($defquota,$settingstatus);
1.472 raeburn 7442: } else {
1.536 raeburn 7443: return $defquota;
1.472 raeburn 7444: }
7445: }
7446:
1.384 raeburn 7447: sub get_secgrprole_info {
7448: my ($cdom,$cnum,$needroles,$type) = @_;
7449: my %sections_count = &get_sections($cdom,$cnum);
7450: my @sections = (sort {$a <=> $b} keys(%sections_count));
7451: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7452: my @groups = sort(keys(%curr_groups));
7453: my $allroles = [];
7454: my $rolehash;
7455: my $accesshash = {
7456: active => 'Currently has access',
7457: future => 'Will have future access',
7458: previous => 'Previously had access',
7459: };
7460: if ($needroles) {
7461: $rolehash = {'all' => 'all'};
1.385 albertel 7462: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7463: if (&Apache::lonnet::error(%user_roles)) {
7464: undef(%user_roles);
7465: }
7466: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7467: my ($role)=split(/\:/,$item,2);
7468: if ($role eq 'cr') { next; }
7469: if ($role =~ /^cr/) {
7470: $$rolehash{$role} = (split('/',$role))[3];
7471: } else {
7472: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7473: }
7474: }
7475: foreach my $key (sort(keys(%{$rolehash}))) {
7476: push(@{$allroles},$key);
7477: }
7478: push (@{$allroles},'st');
7479: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7480: }
7481: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7482: }
7483:
1.555 raeburn 7484: sub user_picker {
1.627 raeburn 7485: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7486: my $currdom = $dom;
7487: my %curr_selected = (
7488: srchin => 'dom',
1.580 raeburn 7489: srchby => 'lastname',
1.555 raeburn 7490: );
7491: my $srchterm;
1.625 raeburn 7492: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7493: if ($srch->{'srchby'} ne '') {
7494: $curr_selected{'srchby'} = $srch->{'srchby'};
7495: }
7496: if ($srch->{'srchin'} ne '') {
7497: $curr_selected{'srchin'} = $srch->{'srchin'};
7498: }
7499: if ($srch->{'srchtype'} ne '') {
7500: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7501: }
7502: if ($srch->{'srchdomain'} ne '') {
7503: $currdom = $srch->{'srchdomain'};
7504: }
7505: $srchterm = $srch->{'srchterm'};
7506: }
7507: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7508: 'usr' => 'Search criteria',
1.563 raeburn 7509: 'doma' => 'Domain/institution to search',
1.558 albertel 7510: 'uname' => 'username',
7511: 'lastname' => 'last name',
1.555 raeburn 7512: 'lastfirst' => 'last name, first name',
1.558 albertel 7513: 'crs' => 'in this course',
1.576 raeburn 7514: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7515: 'alc' => 'all LON-CAPA',
1.573 raeburn 7516: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7517: 'exact' => 'is',
7518: 'contains' => 'contains',
1.569 raeburn 7519: 'begins' => 'begins with',
1.571 raeburn 7520: 'youm' => "You must include some text to search for.",
7521: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7522: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7523: 'yomc' => "You must choose a domain when using an institutional directory search.",
7524: 'ymcd' => "You must choose a domain when using a domain search.",
7525: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7526: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7527: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7528: );
1.563 raeburn 7529: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7530: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7531:
7532: my @srchins = ('crs','dom','alc','instd');
7533:
7534: foreach my $option (@srchins) {
7535: # FIXME 'alc' option unavailable until
7536: # loncreateuser::print_user_query_page()
7537: # has been completed.
7538: next if ($option eq 'alc');
1.880 raeburn 7539: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7540: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7541: if ($curr_selected{'srchin'} eq $option) {
7542: $srchinsel .= '
7543: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7544: } else {
7545: $srchinsel .= '
7546: <option value="'.$option.'">'.$lt{$option}.'</option>';
7547: }
1.555 raeburn 7548: }
1.563 raeburn 7549: $srchinsel .= "\n </select>\n";
1.555 raeburn 7550:
7551: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7552: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7553: if ($curr_selected{'srchby'} eq $option) {
7554: $srchbysel .= '
7555: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7556: } else {
7557: $srchbysel .= '
7558: <option value="'.$option.'">'.$lt{$option}.'</option>';
7559: }
7560: }
7561: $srchbysel .= "\n </select>\n";
7562:
7563: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7564: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7565: if ($curr_selected{'srchtype'} eq $option) {
7566: $srchtypesel .= '
7567: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7568: } else {
7569: $srchtypesel .= '
7570: <option value="'.$option.'">'.$lt{$option}.'</option>';
7571: }
7572: }
7573: $srchtypesel .= "\n </select>\n";
7574:
1.558 albertel 7575: my ($newuserscript,$new_user_create);
1.556 raeburn 7576:
7577: if ($forcenewuser) {
1.576 raeburn 7578: if (ref($srch) eq 'HASH') {
7579: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7580: if ($cancreate) {
7581: $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>';
7582: } else {
1.799 bisitz 7583: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7584: my %usertypetext = (
7585: official => 'institutional',
7586: unofficial => 'non-institutional',
7587: );
1.799 bisitz 7588: $new_user_create = '<p class="LC_warning">'
7589: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7590: .' '
7591: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7592: ,'<a href="'.$helplink.'">','</a>')
7593: .'</p><br />';
1.627 raeburn 7594: }
1.576 raeburn 7595: }
7596: }
7597:
1.556 raeburn 7598: $newuserscript = <<"ENDSCRIPT";
7599:
1.570 raeburn 7600: function setSearch(createnew,callingForm) {
1.556 raeburn 7601: if (createnew == 1) {
1.570 raeburn 7602: for (var i=0; i<callingForm.srchby.length; i++) {
7603: if (callingForm.srchby.options[i].value == 'uname') {
7604: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7605: }
7606: }
1.570 raeburn 7607: for (var i=0; i<callingForm.srchin.length; i++) {
7608: if ( callingForm.srchin.options[i].value == 'dom') {
7609: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7610: }
7611: }
1.570 raeburn 7612: for (var i=0; i<callingForm.srchtype.length; i++) {
7613: if (callingForm.srchtype.options[i].value == 'exact') {
7614: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7615: }
7616: }
1.570 raeburn 7617: for (var i=0; i<callingForm.srchdomain.length; i++) {
7618: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7619: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7620: }
7621: }
7622: }
7623: }
7624: ENDSCRIPT
1.558 albertel 7625:
1.556 raeburn 7626: }
7627:
1.555 raeburn 7628: my $output = <<"END_BLOCK";
1.556 raeburn 7629: <script type="text/javascript">
1.824 bisitz 7630: // <![CDATA[
1.570 raeburn 7631: function validateEntry(callingForm) {
1.558 albertel 7632:
1.556 raeburn 7633: var checkok = 1;
1.558 albertel 7634: var srchin;
1.570 raeburn 7635: for (var i=0; i<callingForm.srchin.length; i++) {
7636: if ( callingForm.srchin[i].checked ) {
7637: srchin = callingForm.srchin[i].value;
1.558 albertel 7638: }
7639: }
7640:
1.570 raeburn 7641: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7642: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7643: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7644: var srchterm = callingForm.srchterm.value;
7645: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7646: var msg = "";
7647:
7648: if (srchterm == "") {
7649: checkok = 0;
1.571 raeburn 7650: msg += "$lt{'youm'}\\n";
1.556 raeburn 7651: }
7652:
1.569 raeburn 7653: if (srchtype== 'begins') {
7654: if (srchterm.length < 2) {
7655: checkok = 0;
1.571 raeburn 7656: msg += "$lt{'thte'}\\n";
1.569 raeburn 7657: }
7658: }
7659:
1.556 raeburn 7660: if (srchtype== 'contains') {
7661: if (srchterm.length < 3) {
7662: checkok = 0;
1.571 raeburn 7663: msg += "$lt{'thet'}\\n";
1.556 raeburn 7664: }
7665: }
7666: if (srchin == 'instd') {
7667: if (srchdomain == '') {
7668: checkok = 0;
1.571 raeburn 7669: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7670: }
7671: }
7672: if (srchin == 'dom') {
7673: if (srchdomain == '') {
7674: checkok = 0;
1.571 raeburn 7675: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7676: }
7677: }
7678: if (srchby == 'lastfirst') {
7679: if (srchterm.indexOf(",") == -1) {
7680: checkok = 0;
1.571 raeburn 7681: msg += "$lt{'whus'}\\n";
1.556 raeburn 7682: }
7683: if (srchterm.indexOf(",") == srchterm.length -1) {
7684: checkok = 0;
1.571 raeburn 7685: msg += "$lt{'whse'}\\n";
1.556 raeburn 7686: }
7687: }
7688: if (checkok == 0) {
1.571 raeburn 7689: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7690: return;
7691: }
7692: if (checkok == 1) {
1.570 raeburn 7693: callingForm.submit();
1.556 raeburn 7694: }
7695: }
7696:
7697: $newuserscript
7698:
1.824 bisitz 7699: // ]]>
1.556 raeburn 7700: </script>
1.558 albertel 7701:
7702: $new_user_create
7703:
1.555 raeburn 7704: END_BLOCK
1.558 albertel 7705:
1.876 raeburn 7706: $output .= &Apache::lonhtmlcommon::start_pick_box().
7707: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7708: $domform.
7709: &Apache::lonhtmlcommon::row_closure().
7710: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7711: $srchbysel.
7712: $srchtypesel.
7713: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7714: $srchinsel.
7715: &Apache::lonhtmlcommon::row_closure(1).
7716: &Apache::lonhtmlcommon::end_pick_box().
7717: '<br />';
1.555 raeburn 7718: return $output;
7719: }
7720:
1.612 raeburn 7721: sub user_rule_check {
1.615 raeburn 7722: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7723: my $response;
7724: if (ref($usershash) eq 'HASH') {
7725: foreach my $user (keys(%{$usershash})) {
7726: my ($uname,$udom) = split(/:/,$user);
7727: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7728: my ($id,$newuser);
1.612 raeburn 7729: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7730: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7731: $id = $usershash->{$user}->{'id'};
7732: }
7733: my $inst_response;
7734: if (ref($checks) eq 'HASH') {
7735: if (defined($checks->{'username'})) {
1.615 raeburn 7736: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7737: &Apache::lonnet::get_instuser($udom,$uname);
7738: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7739: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7740: &Apache::lonnet::get_instuser($udom,undef,$id);
7741: }
1.615 raeburn 7742: } else {
7743: ($inst_response,%{$inst_results->{$user}}) =
7744: &Apache::lonnet::get_instuser($udom,$uname);
7745: return;
1.612 raeburn 7746: }
1.615 raeburn 7747: if (!$got_rules->{$udom}) {
1.612 raeburn 7748: my %domconfig = &Apache::lonnet::get_dom('configuration',
7749: ['usercreation'],$udom);
7750: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7751: foreach my $item ('username','id') {
1.612 raeburn 7752: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7753: $$curr_rules{$udom}{$item} =
7754: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7755: }
7756: }
7757: }
1.615 raeburn 7758: $got_rules->{$udom} = 1;
1.585 raeburn 7759: }
1.612 raeburn 7760: foreach my $item (keys(%{$checks})) {
7761: if (ref($$curr_rules{$udom}) eq 'HASH') {
7762: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7763: if (@{$$curr_rules{$udom}{$item}} > 0) {
7764: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7765: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7766: if ($rule_check{$rule}) {
7767: $$rulematch{$user}{$item} = $rule;
7768: if ($inst_response eq 'ok') {
1.615 raeburn 7769: if (ref($inst_results) eq 'HASH') {
7770: if (ref($inst_results->{$user}) eq 'HASH') {
7771: if (keys(%{$inst_results->{$user}}) == 0) {
7772: $$alerts{$item}{$udom}{$uname} = 1;
7773: }
1.612 raeburn 7774: }
7775: }
1.615 raeburn 7776: }
7777: last;
1.585 raeburn 7778: }
7779: }
7780: }
7781: }
7782: }
7783: }
7784: }
7785: }
1.612 raeburn 7786: return;
7787: }
7788:
7789: sub user_rule_formats {
7790: my ($domain,$domdesc,$curr_rules,$check) = @_;
7791: my %text = (
7792: 'username' => 'Usernames',
7793: 'id' => 'IDs',
7794: );
7795: my $output;
7796: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7797: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7798: if (@{$ruleorder} > 0) {
7799: $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>';
7800: foreach my $rule (@{$ruleorder}) {
7801: if (ref($curr_rules) eq 'ARRAY') {
7802: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7803: if (ref($rules->{$rule}) eq 'HASH') {
7804: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7805: $rules->{$rule}{'desc'}.'</li>';
7806: }
7807: }
7808: }
7809: }
7810: $output .= '</ul>';
7811: }
7812: }
7813: return $output;
7814: }
7815:
7816: sub instrule_disallow_msg {
1.615 raeburn 7817: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7818: my $response;
7819: my %text = (
7820: item => 'username',
7821: items => 'usernames',
7822: match => 'matches',
7823: do => 'does',
7824: action => 'a username',
7825: one => 'one',
7826: );
7827: if ($count > 1) {
7828: $text{'item'} = 'usernames';
7829: $text{'match'} ='match';
7830: $text{'do'} = 'do';
7831: $text{'action'} = 'usernames',
7832: $text{'one'} = 'ones';
7833: }
7834: if ($checkitem eq 'id') {
7835: $text{'items'} = 'IDs';
7836: $text{'item'} = 'ID';
7837: $text{'action'} = 'an ID';
1.615 raeburn 7838: if ($count > 1) {
7839: $text{'item'} = 'IDs';
7840: $text{'action'} = 'IDs';
7841: }
1.612 raeburn 7842: }
1.674 bisitz 7843: $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 7844: if ($mode eq 'upload') {
7845: if ($checkitem eq 'username') {
7846: $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'}.");
7847: } elsif ($checkitem eq 'id') {
1.674 bisitz 7848: $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 7849: }
1.669 raeburn 7850: } elsif ($mode eq 'selfcreate') {
7851: if ($checkitem eq 'id') {
7852: $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.");
7853: }
1.615 raeburn 7854: } else {
7855: if ($checkitem eq 'username') {
7856: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7857: } elsif ($checkitem eq 'id') {
7858: $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.");
7859: }
1.612 raeburn 7860: }
7861: return $response;
1.585 raeburn 7862: }
7863:
1.624 raeburn 7864: sub personal_data_fieldtitles {
7865: my %fieldtitles = &Apache::lonlocal::texthash (
7866: id => 'Student/Employee ID',
7867: permanentemail => 'E-mail address',
7868: lastname => 'Last Name',
7869: firstname => 'First Name',
7870: middlename => 'Middle Name',
7871: generation => 'Generation',
7872: gen => 'Generation',
1.765 raeburn 7873: inststatus => 'Affiliation',
1.624 raeburn 7874: );
7875: return %fieldtitles;
7876: }
7877:
1.642 raeburn 7878: sub sorted_inst_types {
7879: my ($dom) = @_;
7880: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7881: my $othertitle = &mt('All users');
7882: if ($env{'request.course.id'}) {
1.668 raeburn 7883: $othertitle = &mt('Any users');
1.642 raeburn 7884: }
7885: my @types;
7886: if (ref($order) eq 'ARRAY') {
7887: @types = @{$order};
7888: }
7889: if (@types == 0) {
7890: if (ref($usertypes) eq 'HASH') {
7891: @types = sort(keys(%{$usertypes}));
7892: }
7893: }
7894: if (keys(%{$usertypes}) > 0) {
7895: $othertitle = &mt('Other users');
7896: }
7897: return ($othertitle,$usertypes,\@types);
7898: }
7899:
1.645 raeburn 7900: sub get_institutional_codes {
7901: my ($settings,$allcourses,$LC_code) = @_;
7902: # Get complete list of course sections to update
7903: my @currsections = ();
7904: my @currxlists = ();
7905: my $coursecode = $$settings{'internal.coursecode'};
7906:
7907: if ($$settings{'internal.sectionnums'} ne '') {
7908: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7909: }
7910:
7911: if ($$settings{'internal.crosslistings'} ne '') {
7912: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7913: }
7914:
7915: if (@currxlists > 0) {
7916: foreach (@currxlists) {
7917: if (m/^([^:]+):(\w*)$/) {
7918: unless (grep/^$1$/,@{$allcourses}) {
7919: push @{$allcourses},$1;
7920: $$LC_code{$1} = $2;
7921: }
7922: }
7923: }
7924: }
7925:
7926: if (@currsections > 0) {
7927: foreach (@currsections) {
7928: if (m/^(\w+):(\w*)$/) {
7929: my $sec = $coursecode.$1;
7930: my $lc_sec = $2;
7931: unless (grep/^$sec$/,@{$allcourses}) {
7932: push @{$allcourses},$sec;
7933: $$LC_code{$sec} = $lc_sec;
7934: }
7935: }
7936: }
7937: }
7938: return;
7939: }
7940:
1.112 bowersj2 7941: =pod
7942:
1.780 raeburn 7943: =head1 Slot Helpers
7944:
7945: =over 4
7946:
7947: =item * sorted_slots()
7948:
7949: Sorts an array of slot names in order of slot start time (earliest first).
7950:
7951: Inputs:
7952:
7953: =over 4
7954:
7955: slotsarr - Reference to array of unsorted slot names.
7956:
7957: slots - Reference to hash of hash, where outer hash keys are slot names.
7958:
1.549 albertel 7959: =back
7960:
1.780 raeburn 7961: Returns:
7962:
7963: =over 4
7964:
7965: sorted - An array of slot names sorted by the start time of the slot.
7966:
7967: =back
7968:
7969: =back
7970:
7971: =cut
7972:
7973:
7974: sub sorted_slots {
7975: my ($slotsarr,$slots) = @_;
7976: my @sorted;
7977: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7978: @sorted =
7979: sort {
7980: if (ref($slots->{$a}) && ref($slots->{$b})) {
7981: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7982: }
7983: if (ref($slots->{$a})) { return -1;}
7984: if (ref($slots->{$b})) { return 1;}
7985: return 0;
7986: } @{$slotsarr};
7987: }
7988: return @sorted;
7989: }
7990:
7991:
7992: =pod
7993:
1.549 albertel 7994: =head1 HTTP Helpers
7995:
7996: =over 4
7997:
1.648 raeburn 7998: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7999:
1.258 albertel 8000: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8001: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8002: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8003:
8004: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8005: $possible_names is an ref to an array of form element names. As an example:
8006: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8007: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8008:
8009: =cut
1.1 albertel 8010:
1.6 albertel 8011: sub get_unprocessed_cgi {
1.25 albertel 8012: my ($query,$possible_names)= @_;
1.26 matthew 8013: # $Apache::lonxml::debug=1;
1.356 albertel 8014: foreach my $pair (split(/&/,$query)) {
8015: my ($name, $value) = split(/=/,$pair);
1.369 www 8016: $name = &unescape($name);
1.25 albertel 8017: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8018: $value =~ tr/+/ /;
8019: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8020: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8021: }
1.16 harris41 8022: }
1.6 albertel 8023: }
8024:
1.112 bowersj2 8025: =pod
8026:
1.648 raeburn 8027: =item * &cacheheader()
1.112 bowersj2 8028:
8029: returns cache-controlling header code
8030:
8031: =cut
8032:
1.7 albertel 8033: sub cacheheader {
1.258 albertel 8034: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8035: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8036: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8037: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8038: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8039: return $output;
1.7 albertel 8040: }
8041:
1.112 bowersj2 8042: =pod
8043:
1.648 raeburn 8044: =item * &no_cache($r)
1.112 bowersj2 8045:
8046: specifies header code to not have cache
8047:
8048: =cut
8049:
1.9 albertel 8050: sub no_cache {
1.216 albertel 8051: my ($r) = @_;
8052: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8053: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8054: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8055: $r->no_cache(1);
8056: $r->header_out("Expires" => $date);
8057: $r->header_out("Pragma" => "no-cache");
1.123 www 8058: }
8059:
8060: sub content_type {
1.181 albertel 8061: my ($r,$type,$charset) = @_;
1.299 foxr 8062: if ($r) {
8063: # Note that printout.pl calls this with undef for $r.
8064: &no_cache($r);
8065: }
1.258 albertel 8066: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8067: unless ($charset) {
8068: $charset=&Apache::lonlocal::current_encoding;
8069: }
8070: if ($charset) { $type.='; charset='.$charset; }
8071: if ($r) {
8072: $r->content_type($type);
8073: } else {
8074: print("Content-type: $type\n\n");
8075: }
1.9 albertel 8076: }
1.25 albertel 8077:
1.112 bowersj2 8078: =pod
8079:
1.648 raeburn 8080: =item * &add_to_env($name,$value)
1.112 bowersj2 8081:
1.258 albertel 8082: adds $name to the %env hash with value
1.112 bowersj2 8083: $value, if $name already exists, the entry is converted to an array
8084: reference and $value is added to the array.
8085:
8086: =cut
8087:
1.25 albertel 8088: sub add_to_env {
8089: my ($name,$value)=@_;
1.258 albertel 8090: if (defined($env{$name})) {
8091: if (ref($env{$name})) {
1.25 albertel 8092: #already have multiple values
1.258 albertel 8093: push(@{ $env{$name} },$value);
1.25 albertel 8094: } else {
8095: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8096: my $first=$env{$name};
8097: undef($env{$name});
8098: push(@{ $env{$name} },$first,$value);
1.25 albertel 8099: }
8100: } else {
1.258 albertel 8101: $env{$name}=$value;
1.25 albertel 8102: }
1.31 albertel 8103: }
1.149 albertel 8104:
8105: =pod
8106:
1.648 raeburn 8107: =item * &get_env_multiple($name)
1.149 albertel 8108:
1.258 albertel 8109: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8110: values may be defined and end up as an array ref.
8111:
8112: returns an array of values
8113:
8114: =cut
8115:
8116: sub get_env_multiple {
8117: my ($name) = @_;
8118: my @values;
1.258 albertel 8119: if (defined($env{$name})) {
1.149 albertel 8120: # exists is it an array
1.258 albertel 8121: if (ref($env{$name})) {
8122: @values=@{ $env{$name} };
1.149 albertel 8123: } else {
1.258 albertel 8124: $values[0]=$env{$name};
1.149 albertel 8125: }
8126: }
8127: return(@values);
8128: }
8129:
1.660 raeburn 8130: sub ask_for_embedded_content {
8131: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8132: my $upload_output = '
8133: <form name="upload_embedded" action="'.$actionurl.'"
8134: method="post" enctype="multipart/form-data">';
8135: $upload_output .= $state;
1.661 raeburn 8136: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8137:
8138: my $num = 0;
8139: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8140: $upload_output .= &start_data_table_row().
8141: '<td>'.$embed_file.'</td><td>';
8142: if ($args->{'ignore_remote_references'}
8143: && $embed_file =~ m{^\w+://}) {
8144: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8145: } elsif ($args->{'error_on_invalid_names'}
8146: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8147:
8148: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8149:
8150: } else {
8151: $upload_output .='
1.661 raeburn 8152: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8153: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8154: my $attrib = join(':',@{$$allfiles{$embed_file}});
8155: $upload_output .=
8156: "\n\t\t".
8157: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8158: $attrib.'" />';
8159: if (exists($$codebase{$embed_file})) {
8160: $upload_output .=
8161: "\n\t\t".
8162: '<input name="codebase_'.$num.'" type="hidden" value="'.
8163: &escape($$codebase{$embed_file}).'" />';
8164: }
8165: }
8166: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8167: $num++;
8168: }
8169: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8170: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8171: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8172: '.&mt('(only files for which a location has been provided will be uploaded)').'
8173: </form>';
8174: return $upload_output;
8175: }
8176:
1.661 raeburn 8177: sub upload_embedded {
8178: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8179: $current_disk_usage) = @_;
8180: my $output;
8181: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8182: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8183: my $orig_uploaded_filename =
8184: $env{'form.embedded_item_'.$i.'.filename'};
8185:
8186: $env{'form.embedded_orig_'.$i} =
8187: &unescape($env{'form.embedded_orig_'.$i});
8188: my ($path,$fname) =
8189: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8190: # no path, whole string is fname
8191: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8192:
8193: $path = $env{'form.currentpath'}.$path;
8194: $fname = &Apache::lonnet::clean_filename($fname);
8195: # See if there is anything left
8196: next if ($fname eq '');
8197:
8198: # Check if file already exists as a file or directory.
8199: my ($state,$msg);
8200: if ($context eq 'portfolio') {
8201: my $port_path = $dirpath;
8202: if ($group ne '') {
8203: $port_path = "groups/$group/$port_path";
8204: }
8205: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8206: $dir_root,$port_path,$disk_quota,
8207: $current_disk_usage,$uname,$udom);
8208: if ($state eq 'will_exceed_quota'
8209: || $state eq 'file_locked'
8210: || $state eq 'file_exists' ) {
8211: $output .= $msg;
8212: next;
8213: }
8214: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8215: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8216: if ($state eq 'exists') {
8217: $output .= $msg;
8218: next;
8219: }
8220: }
8221: # Check if extension is valid
8222: if (($fname =~ /\.(\w+)$/) &&
8223: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8224: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8225: next;
8226: } elsif (($fname =~ /\.(\w+)$/) &&
8227: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8228: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8229: next;
8230: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8231: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8232: next;
8233: }
8234:
8235: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8236: if ($context eq 'portfolio') {
8237: my $result=
8238: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8239: $dirpath.$path);
8240: if ($result !~ m|^/uploaded/|) {
8241: $output .= '<span class="LC_error">'
8242: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8243: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8244: .'</span><br />';
8245: next;
8246: } else {
8247: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8248: $path.$fname.'</span>').'</p>';
8249: }
8250: } else {
8251: # Save the file
8252: my $target = $env{'form.embedded_item_'.$i};
8253: my $fullpath = $dir_root.$dirpath.'/'.$path;
8254: my $dest = $fullpath.$fname;
8255: my $url = $url_root.$dirpath.'/'.$path.$fname;
8256: my @parts=split(/\//,$fullpath);
8257: my $count;
8258: my $filepath = $dir_root;
8259: for ($count=4;$count<=$#parts;$count++) {
8260: $filepath .= "/$parts[$count]";
8261: if ((-e $filepath)!=1) {
8262: mkdir($filepath,0770);
8263: }
8264: }
8265: my $fh;
8266: if (!open($fh,'>'.$dest)) {
8267: &Apache::lonnet::logthis('Failed to create '.$dest);
8268: $output .= '<span class="LC_error">'.
8269: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8270: '</span><br />';
8271: } else {
8272: if (!print $fh $env{'form.embedded_item_'.$i}) {
8273: &Apache::lonnet::logthis('Failed to write to '.$dest);
8274: $output .= '<span class="LC_error">'.
8275: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8276: '</span><br />';
8277: } else {
8278: if ($context eq 'testbank') {
8279: $output .= &mt('Embedded file uploaded successfully:').
8280: ' <a href="'.$url.'">'.
8281: $orig_uploaded_filename.'</a><br />';
8282: } else {
1.705 tempelho 8283: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8284: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8285: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8286: }
8287: }
8288: close($fh);
8289: }
8290: }
8291: }
8292: return $output;
8293: }
8294:
8295: sub check_for_existing {
8296: my ($path,$fname,$element) = @_;
8297: my ($state,$msg);
8298: if (-d $path.'/'.$fname) {
8299: $state = 'exists';
8300: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8301: } elsif (-e $path.'/'.$fname) {
8302: $state = 'exists';
8303: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8304: }
8305: if ($state eq 'exists') {
8306: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8307: }
8308: return ($state,$msg);
8309: }
8310:
8311: sub check_for_upload {
8312: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8313: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8314: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8315: my $getpropath = 1;
8316: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8317: $getpropath);
8318: my $found_file = 0;
8319: my $locked_file = 0;
8320: foreach my $line (@dir_list) {
8321: my ($file_name)=split(/\&/,$line,2);
8322: if ($file_name eq $fname){
8323: $file_name = $path.$file_name;
8324: if ($group ne '') {
8325: $file_name = $group.$file_name;
8326: }
8327: $found_file = 1;
8328: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8329: $locked_file = 1;
8330: }
8331: }
8332: }
8333: if (($current_disk_usage + $filesize) > $disk_quota){
8334: my $msg = '<span class="LC_error">'.
8335: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8336: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8337: return ('will_exceed_quota',$msg);
8338: } elsif ($found_file) {
8339: if ($locked_file) {
8340: my $msg = '<span class="LC_error">';
8341: $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>');
8342: $msg .= '</span><br />';
8343: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8344: return ('file_locked',$msg);
8345: } else {
8346: my $msg = '<span class="LC_error">';
8347: $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'});
8348: $msg .= '</span>';
8349: $msg .= '<br />';
8350: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8351: return ('file_exists',$msg);
8352: }
8353: }
8354: }
8355:
1.31 albertel 8356:
1.41 ng 8357: =pod
1.45 matthew 8358:
1.464 albertel 8359: =back
1.41 ng 8360:
1.112 bowersj2 8361: =head1 CSV Upload/Handling functions
1.38 albertel 8362:
1.41 ng 8363: =over 4
8364:
1.648 raeburn 8365: =item * &upfile_store($r)
1.41 ng 8366:
8367: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8368: needs $env{'form.upfile'}
1.41 ng 8369: returns $datatoken to be put into hidden field
8370:
8371: =cut
1.31 albertel 8372:
8373: sub upfile_store {
8374: my $r=shift;
1.258 albertel 8375: $env{'form.upfile'}=~s/\r/\n/gs;
8376: $env{'form.upfile'}=~s/\f/\n/gs;
8377: $env{'form.upfile'}=~s/\n+/\n/gs;
8378: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8379:
1.258 albertel 8380: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8381: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8382: {
1.158 raeburn 8383: my $datafile = $r->dir_config('lonDaemons').
8384: '/tmp/'.$datatoken.'.tmp';
8385: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8386: print $fh $env{'form.upfile'};
1.158 raeburn 8387: close($fh);
8388: }
1.31 albertel 8389: }
8390: return $datatoken;
8391: }
8392:
1.56 matthew 8393: =pod
8394:
1.648 raeburn 8395: =item * &load_tmp_file($r)
1.41 ng 8396:
8397: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8398: needs $env{'form.datatoken'},
8399: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8400:
8401: =cut
1.31 albertel 8402:
8403: sub load_tmp_file {
8404: my $r=shift;
8405: my @studentdata=();
8406: {
1.158 raeburn 8407: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8408: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8409: if ( open(my $fh,"<$studentfile") ) {
8410: @studentdata=<$fh>;
8411: close($fh);
8412: }
1.31 albertel 8413: }
1.258 albertel 8414: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8415: }
8416:
1.56 matthew 8417: =pod
8418:
1.648 raeburn 8419: =item * &upfile_record_sep()
1.41 ng 8420:
8421: Separate uploaded file into records
8422: returns array of records,
1.258 albertel 8423: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8424:
8425: =cut
1.31 albertel 8426:
8427: sub upfile_record_sep {
1.258 albertel 8428: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8429: } else {
1.248 albertel 8430: my @records;
1.258 albertel 8431: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8432: if ($line=~/^\s*$/) { next; }
8433: push(@records,$line);
8434: }
8435: return @records;
1.31 albertel 8436: }
8437: }
8438:
1.56 matthew 8439: =pod
8440:
1.648 raeburn 8441: =item * &record_sep($record)
1.41 ng 8442:
1.258 albertel 8443: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8444:
8445: =cut
8446:
1.263 www 8447: sub takeleft {
8448: my $index=shift;
8449: return substr('0000'.$index,-4,4);
8450: }
8451:
1.31 albertel 8452: sub record_sep {
8453: my $record=shift;
8454: my %components=();
1.258 albertel 8455: if ($env{'form.upfiletype'} eq 'xml') {
8456: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8457: my $i=0;
1.356 albertel 8458: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8459: $field=~s/^(\"|\')//;
8460: $field=~s/(\"|\')$//;
1.263 www 8461: $components{&takeleft($i)}=$field;
1.31 albertel 8462: $i++;
8463: }
1.258 albertel 8464: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8465: my $i=0;
1.356 albertel 8466: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8467: $field=~s/^(\"|\')//;
8468: $field=~s/(\"|\')$//;
1.263 www 8469: $components{&takeleft($i)}=$field;
1.31 albertel 8470: $i++;
8471: }
8472: } else {
1.561 www 8473: my $separator=',';
1.480 banghart 8474: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8475: $separator=';';
1.480 banghart 8476: }
1.31 albertel 8477: my $i=0;
1.561 www 8478: # the character we are looking for to indicate the end of a quote or a record
8479: my $looking_for=$separator;
8480: # do not add the characters to the fields
8481: my $ignore=0;
8482: # we just encountered a separator (or the beginning of the record)
8483: my $just_found_separator=1;
8484: # store the field we are working on here
8485: my $field='';
8486: # work our way through all characters in record
8487: foreach my $character ($record=~/(.)/g) {
8488: if ($character eq $looking_for) {
8489: if ($character ne $separator) {
8490: # Found the end of a quote, again looking for separator
8491: $looking_for=$separator;
8492: $ignore=1;
8493: } else {
8494: # Found a separator, store away what we got
8495: $components{&takeleft($i)}=$field;
8496: $i++;
8497: $just_found_separator=1;
8498: $ignore=0;
8499: $field='';
8500: }
8501: next;
8502: }
8503: # single or double quotation marks after a separator indicate beginning of a quote
8504: # we are now looking for the end of the quote and need to ignore separators
8505: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8506: $looking_for=$character;
8507: next;
8508: }
8509: # ignore would be true after we reached the end of a quote
8510: if ($ignore) { next; }
8511: if (($just_found_separator) && ($character=~/\s/)) { next; }
8512: $field.=$character;
8513: $just_found_separator=0;
1.31 albertel 8514: }
1.561 www 8515: # catch the very last entry, since we never encountered the separator
8516: $components{&takeleft($i)}=$field;
1.31 albertel 8517: }
8518: return %components;
8519: }
8520:
1.144 matthew 8521: ######################################################
8522: ######################################################
8523:
1.56 matthew 8524: =pod
8525:
1.648 raeburn 8526: =item * &upfile_select_html()
1.41 ng 8527:
1.144 matthew 8528: Return HTML code to select a file from the users machine and specify
8529: the file type.
1.41 ng 8530:
8531: =cut
8532:
1.144 matthew 8533: ######################################################
8534: ######################################################
1.31 albertel 8535: sub upfile_select_html {
1.144 matthew 8536: my %Types = (
8537: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8538: semisv => &mt('Semicolon separated values'),
1.144 matthew 8539: space => &mt('Space separated'),
8540: tab => &mt('Tabulator separated'),
8541: # xml => &mt('HTML/XML'),
8542: );
8543: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8544: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8545: foreach my $type (sort(keys(%Types))) {
8546: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8547: }
8548: $Str .= "</select>\n";
8549: return $Str;
1.31 albertel 8550: }
8551:
1.301 albertel 8552: sub get_samples {
8553: my ($records,$toget) = @_;
8554: my @samples=({});
8555: my $got=0;
8556: foreach my $rec (@$records) {
8557: my %temp = &record_sep($rec);
8558: if (! grep(/\S/, values(%temp))) { next; }
8559: if (%temp) {
8560: $samples[$got]=\%temp;
8561: $got++;
8562: if ($got == $toget) { last; }
8563: }
8564: }
8565: return \@samples;
8566: }
8567:
1.144 matthew 8568: ######################################################
8569: ######################################################
8570:
1.56 matthew 8571: =pod
8572:
1.648 raeburn 8573: =item * &csv_print_samples($r,$records)
1.41 ng 8574:
8575: Prints a table of sample values from each column uploaded $r is an
8576: Apache Request ref, $records is an arrayref from
8577: &Apache::loncommon::upfile_record_sep
8578:
8579: =cut
8580:
1.144 matthew 8581: ######################################################
8582: ######################################################
1.31 albertel 8583: sub csv_print_samples {
8584: my ($r,$records) = @_;
1.662 bisitz 8585: my $samples = &get_samples($records,5);
1.301 albertel 8586:
1.594 raeburn 8587: $r->print(&mt('Samples').'<br />'.&start_data_table().
8588: &start_data_table_header_row());
1.356 albertel 8589: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8590: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8591: $r->print(&end_data_table_header_row());
1.301 albertel 8592: foreach my $hash (@$samples) {
1.594 raeburn 8593: $r->print(&start_data_table_row());
1.356 albertel 8594: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8595: $r->print('<td>');
1.356 albertel 8596: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8597: $r->print('</td>');
8598: }
1.594 raeburn 8599: $r->print(&end_data_table_row());
1.31 albertel 8600: }
1.594 raeburn 8601: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8602: }
8603:
1.144 matthew 8604: ######################################################
8605: ######################################################
8606:
1.56 matthew 8607: =pod
8608:
1.648 raeburn 8609: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8610:
8611: Prints a table to create associations between values and table columns.
1.144 matthew 8612:
1.41 ng 8613: $r is an Apache Request ref,
8614: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8615: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8616:
8617: =cut
8618:
1.144 matthew 8619: ######################################################
8620: ######################################################
1.31 albertel 8621: sub csv_print_select_table {
8622: my ($r,$records,$d) = @_;
1.301 albertel 8623: my $i=0;
8624: my $samples = &get_samples($records,1);
1.144 matthew 8625: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8626: &start_data_table().&start_data_table_header_row().
1.144 matthew 8627: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8628: '<th>'.&mt('Column').'</th>'.
8629: &end_data_table_header_row()."\n");
1.356 albertel 8630: foreach my $array_ref (@$d) {
8631: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8632: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8633:
1.875 bisitz 8634: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8635: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8636: $r->print('<option value="none"></option>');
1.356 albertel 8637: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8638: $r->print('<option value="'.$sample.'"'.
8639: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8640: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8641: }
1.594 raeburn 8642: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8643: $i++;
8644: }
1.594 raeburn 8645: $r->print(&end_data_table());
1.31 albertel 8646: $i--;
8647: return $i;
8648: }
1.56 matthew 8649:
1.144 matthew 8650: ######################################################
8651: ######################################################
8652:
1.56 matthew 8653: =pod
1.31 albertel 8654:
1.648 raeburn 8655: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8656:
8657: Prints a table of sample values from the upload and can make associate samples to internal names.
8658:
8659: $r is an Apache Request ref,
8660: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8661: $d is an array of 2 element arrays (internal name, displayed name)
8662:
8663: =cut
8664:
1.144 matthew 8665: ######################################################
8666: ######################################################
1.31 albertel 8667: sub csv_samples_select_table {
8668: my ($r,$records,$d) = @_;
8669: my $i=0;
1.144 matthew 8670: #
1.662 bisitz 8671: my $max_samples = 5;
8672: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8673: $r->print(&start_data_table().
8674: &start_data_table_header_row().'<th>'.
8675: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8676: &end_data_table_header_row());
1.301 albertel 8677:
8678: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8679: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8680: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8681: foreach my $option (@$d) {
8682: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8683: $r->print('<option value="'.$value.'"'.
1.253 albertel 8684: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8685: $display.'</option>');
1.31 albertel 8686: }
8687: $r->print('</select></td><td>');
1.662 bisitz 8688: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8689: if (defined($samples->[$line]{$key})) {
8690: $r->print($samples->[$line]{$key}."<br />\n");
8691: }
8692: }
1.594 raeburn 8693: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8694: $i++;
8695: }
1.594 raeburn 8696: $r->print(&end_data_table());
1.31 albertel 8697: $i--;
8698: return($i);
1.115 matthew 8699: }
8700:
1.144 matthew 8701: ######################################################
8702: ######################################################
8703:
1.115 matthew 8704: =pod
8705:
1.648 raeburn 8706: =item * &clean_excel_name($name)
1.115 matthew 8707:
8708: Returns a replacement for $name which does not contain any illegal characters.
8709:
8710: =cut
8711:
1.144 matthew 8712: ######################################################
8713: ######################################################
1.115 matthew 8714: sub clean_excel_name {
8715: my ($name) = @_;
8716: $name =~ s/[:\*\?\/\\]//g;
8717: if (length($name) > 31) {
8718: $name = substr($name,0,31);
8719: }
8720: return $name;
1.25 albertel 8721: }
1.84 albertel 8722:
1.85 albertel 8723: =pod
8724:
1.648 raeburn 8725: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8726:
8727: Returns either 1 or undef
8728:
8729: 1 if the part is to be hidden, undef if it is to be shown
8730:
8731: Arguments are:
8732:
8733: $id the id of the part to be checked
8734: $symb, optional the symb of the resource to check
8735: $udom, optional the domain of the user to check for
8736: $uname, optional the username of the user to check for
8737:
8738: =cut
1.84 albertel 8739:
8740: sub check_if_partid_hidden {
8741: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8742: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8743: $symb,$udom,$uname);
1.141 albertel 8744: my $truth=1;
8745: #if the string starts with !, then the list is the list to show not hide
8746: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8747: my @hiddenlist=split(/,/,$hiddenparts);
8748: foreach my $checkid (@hiddenlist) {
1.141 albertel 8749: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8750: }
1.141 albertel 8751: return !$truth;
1.84 albertel 8752: }
1.127 matthew 8753:
1.138 matthew 8754:
8755: ############################################################
8756: ############################################################
8757:
8758: =pod
8759:
1.157 matthew 8760: =back
8761:
1.138 matthew 8762: =head1 cgi-bin script and graphing routines
8763:
1.157 matthew 8764: =over 4
8765:
1.648 raeburn 8766: =item * &get_cgi_id()
1.138 matthew 8767:
8768: Inputs: none
8769:
8770: Returns an id which can be used to pass environment variables
8771: to various cgi-bin scripts. These environment variables will
8772: be removed from the users environment after a given time by
8773: the routine &Apache::lonnet::transfer_profile_to_env.
8774:
8775: =cut
8776:
8777: ############################################################
8778: ############################################################
1.152 albertel 8779: my $uniq=0;
1.136 matthew 8780: sub get_cgi_id {
1.154 albertel 8781: $uniq=($uniq+1)%100000;
1.280 albertel 8782: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8783: }
8784:
1.127 matthew 8785: ############################################################
8786: ############################################################
8787:
8788: =pod
8789:
1.648 raeburn 8790: =item * &DrawBarGraph()
1.127 matthew 8791:
1.138 matthew 8792: Facilitates the plotting of data in a (stacked) bar graph.
8793: Puts plot definition data into the users environment in order for
8794: graph.png to plot it. Returns an <img> tag for the plot.
8795: The bars on the plot are labeled '1','2',...,'n'.
8796:
8797: Inputs:
8798:
8799: =over 4
8800:
8801: =item $Title: string, the title of the plot
8802:
8803: =item $xlabel: string, text describing the X-axis of the plot
8804:
8805: =item $ylabel: string, text describing the Y-axis of the plot
8806:
8807: =item $Max: scalar, the maximum Y value to use in the plot
8808: If $Max is < any data point, the graph will not be rendered.
8809:
1.140 matthew 8810: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8811: they are plotted. If undefined, default values will be used.
8812:
1.178 matthew 8813: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8814:
1.138 matthew 8815: =item @Values: An array of array references. Each array reference holds data
8816: to be plotted in a stacked bar chart.
8817:
1.239 matthew 8818: =item If the final element of @Values is a hash reference the key/value
8819: pairs will be added to the graph definition.
8820:
1.138 matthew 8821: =back
8822:
8823: Returns:
8824:
8825: An <img> tag which references graph.png and the appropriate identifying
8826: information for the plot.
8827:
1.127 matthew 8828: =cut
8829:
8830: ############################################################
8831: ############################################################
1.134 matthew 8832: sub DrawBarGraph {
1.178 matthew 8833: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8834: #
8835: if (! defined($colors)) {
8836: $colors = ['#33ff00',
8837: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8838: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8839: ];
8840: }
1.228 matthew 8841: my $extra_settings = {};
8842: if (ref($Values[-1]) eq 'HASH') {
8843: $extra_settings = pop(@Values);
8844: }
1.127 matthew 8845: #
1.136 matthew 8846: my $identifier = &get_cgi_id();
8847: my $id = 'cgi.'.$identifier;
1.129 matthew 8848: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8849: return '';
8850: }
1.225 matthew 8851: #
8852: my @Labels;
8853: if (defined($labels)) {
8854: @Labels = @$labels;
8855: } else {
8856: for (my $i=0;$i<@{$Values[0]};$i++) {
8857: push (@Labels,$i+1);
8858: }
8859: }
8860: #
1.129 matthew 8861: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8862: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8863: my %ValuesHash;
8864: my $NumSets=1;
8865: foreach my $array (@Values) {
8866: next if (! ref($array));
1.136 matthew 8867: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8868: join(',',@$array);
1.129 matthew 8869: }
1.127 matthew 8870: #
1.136 matthew 8871: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8872: if ($NumBars < 3) {
8873: $width = 120+$NumBars*32;
1.220 matthew 8874: $xskip = 1;
1.225 matthew 8875: $bar_width = 30;
8876: } elsif ($NumBars < 5) {
8877: $width = 120+$NumBars*20;
8878: $xskip = 1;
8879: $bar_width = 20;
1.220 matthew 8880: } elsif ($NumBars < 10) {
1.136 matthew 8881: $width = 120+$NumBars*15;
8882: $xskip = 1;
8883: $bar_width = 15;
8884: } elsif ($NumBars <= 25) {
8885: $width = 120+$NumBars*11;
8886: $xskip = 5;
8887: $bar_width = 8;
8888: } elsif ($NumBars <= 50) {
8889: $width = 120+$NumBars*8;
8890: $xskip = 5;
8891: $bar_width = 4;
8892: } else {
8893: $width = 120+$NumBars*8;
8894: $xskip = 5;
8895: $bar_width = 4;
8896: }
8897: #
1.137 matthew 8898: $Max = 1 if ($Max < 1);
8899: if ( int($Max) < $Max ) {
8900: $Max++;
8901: $Max = int($Max);
8902: }
1.127 matthew 8903: $Title = '' if (! defined($Title));
8904: $xlabel = '' if (! defined($xlabel));
8905: $ylabel = '' if (! defined($ylabel));
1.369 www 8906: $ValuesHash{$id.'.title'} = &escape($Title);
8907: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8908: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8909: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8910: $ValuesHash{$id.'.NumBars'} = $NumBars;
8911: $ValuesHash{$id.'.NumSets'} = $NumSets;
8912: $ValuesHash{$id.'.PlotType'} = 'bar';
8913: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8914: $ValuesHash{$id.'.height'} = $height;
8915: $ValuesHash{$id.'.width'} = $width;
8916: $ValuesHash{$id.'.xskip'} = $xskip;
8917: $ValuesHash{$id.'.bar_width'} = $bar_width;
8918: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8919: #
1.228 matthew 8920: # Deal with other parameters
8921: while (my ($key,$value) = each(%$extra_settings)) {
8922: $ValuesHash{$id.'.'.$key} = $value;
8923: }
8924: #
1.646 raeburn 8925: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8926: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8927: }
8928:
8929: ############################################################
8930: ############################################################
8931:
8932: =pod
8933:
1.648 raeburn 8934: =item * &DrawXYGraph()
1.137 matthew 8935:
1.138 matthew 8936: Facilitates the plotting of data in an XY graph.
8937: Puts plot definition data into the users environment in order for
8938: graph.png to plot it. Returns an <img> tag for the plot.
8939:
8940: Inputs:
8941:
8942: =over 4
8943:
8944: =item $Title: string, the title of the plot
8945:
8946: =item $xlabel: string, text describing the X-axis of the plot
8947:
8948: =item $ylabel: string, text describing the Y-axis of the plot
8949:
8950: =item $Max: scalar, the maximum Y value to use in the plot
8951: If $Max is < any data point, the graph will not be rendered.
8952:
8953: =item $colors: Array ref containing the hex color codes for the data to be
8954: plotted in. If undefined, default values will be used.
8955:
8956: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8957:
8958: =item $Ydata: Array ref containing Array refs.
1.185 www 8959: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8960:
8961: =item %Values: hash indicating or overriding any default values which are
8962: passed to graph.png.
8963: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8964:
8965: =back
8966:
8967: Returns:
8968:
8969: An <img> tag which references graph.png and the appropriate identifying
8970: information for the plot.
8971:
1.137 matthew 8972: =cut
8973:
8974: ############################################################
8975: ############################################################
8976: sub DrawXYGraph {
8977: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8978: #
8979: # Create the identifier for the graph
8980: my $identifier = &get_cgi_id();
8981: my $id = 'cgi.'.$identifier;
8982: #
8983: $Title = '' if (! defined($Title));
8984: $xlabel = '' if (! defined($xlabel));
8985: $ylabel = '' if (! defined($ylabel));
8986: my %ValuesHash =
8987: (
1.369 www 8988: $id.'.title' => &escape($Title),
8989: $id.'.xlabel' => &escape($xlabel),
8990: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8991: $id.'.y_max_value'=> $Max,
8992: $id.'.labels' => join(',',@$Xlabels),
8993: $id.'.PlotType' => 'XY',
8994: );
8995: #
8996: if (defined($colors) && ref($colors) eq 'ARRAY') {
8997: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8998: }
8999: #
9000: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9001: return '';
9002: }
9003: my $NumSets=1;
1.138 matthew 9004: foreach my $array (@{$Ydata}){
1.137 matthew 9005: next if (! ref($array));
9006: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9007: }
1.138 matthew 9008: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9009: #
9010: # Deal with other parameters
9011: while (my ($key,$value) = each(%Values)) {
9012: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9013: }
9014: #
1.646 raeburn 9015: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9016: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9017: }
9018:
9019: ############################################################
9020: ############################################################
9021:
9022: =pod
9023:
1.648 raeburn 9024: =item * &DrawXYYGraph()
1.138 matthew 9025:
9026: Facilitates the plotting of data in an XY graph with two Y axes.
9027: Puts plot definition data into the users environment in order for
9028: graph.png to plot it. Returns an <img> tag for the plot.
9029:
9030: Inputs:
9031:
9032: =over 4
9033:
9034: =item $Title: string, the title of the plot
9035:
9036: =item $xlabel: string, text describing the X-axis of the plot
9037:
9038: =item $ylabel: string, text describing the Y-axis of the plot
9039:
9040: =item $colors: Array ref containing the hex color codes for the data to be
9041: plotted in. If undefined, default values will be used.
9042:
9043: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9044:
9045: =item $Ydata1: The first data set
9046:
9047: =item $Min1: The minimum value of the left Y-axis
9048:
9049: =item $Max1: The maximum value of the left Y-axis
9050:
9051: =item $Ydata2: The second data set
9052:
9053: =item $Min2: The minimum value of the right Y-axis
9054:
9055: =item $Max2: The maximum value of the left Y-axis
9056:
9057: =item %Values: hash indicating or overriding any default values which are
9058: passed to graph.png.
9059: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9060:
9061: =back
9062:
9063: Returns:
9064:
9065: An <img> tag which references graph.png and the appropriate identifying
9066: information for the plot.
1.136 matthew 9067:
9068: =cut
9069:
9070: ############################################################
9071: ############################################################
1.137 matthew 9072: sub DrawXYYGraph {
9073: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9074: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9075: #
9076: # Create the identifier for the graph
9077: my $identifier = &get_cgi_id();
9078: my $id = 'cgi.'.$identifier;
9079: #
9080: $Title = '' if (! defined($Title));
9081: $xlabel = '' if (! defined($xlabel));
9082: $ylabel = '' if (! defined($ylabel));
9083: my %ValuesHash =
9084: (
1.369 www 9085: $id.'.title' => &escape($Title),
9086: $id.'.xlabel' => &escape($xlabel),
9087: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9088: $id.'.labels' => join(',',@$Xlabels),
9089: $id.'.PlotType' => 'XY',
9090: $id.'.NumSets' => 2,
1.137 matthew 9091: $id.'.two_axes' => 1,
9092: $id.'.y1_max_value' => $Max1,
9093: $id.'.y1_min_value' => $Min1,
9094: $id.'.y2_max_value' => $Max2,
9095: $id.'.y2_min_value' => $Min2,
1.136 matthew 9096: );
9097: #
1.137 matthew 9098: if (defined($colors) && ref($colors) eq 'ARRAY') {
9099: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9100: }
9101: #
9102: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9103: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9104: return '';
9105: }
9106: my $NumSets=1;
1.137 matthew 9107: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9108: next if (! ref($array));
9109: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9110: }
9111: #
9112: # Deal with other parameters
9113: while (my ($key,$value) = each(%Values)) {
9114: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9115: }
9116: #
1.646 raeburn 9117: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9118: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9119: }
9120:
9121: ############################################################
9122: ############################################################
9123:
9124: =pod
9125:
1.157 matthew 9126: =back
9127:
1.139 matthew 9128: =head1 Statistics helper routines?
9129:
9130: Bad place for them but what the hell.
9131:
1.157 matthew 9132: =over 4
9133:
1.648 raeburn 9134: =item * &chartlink()
1.139 matthew 9135:
9136: Returns a link to the chart for a specific student.
9137:
9138: Inputs:
9139:
9140: =over 4
9141:
9142: =item $linktext: The text of the link
9143:
9144: =item $sname: The students username
9145:
9146: =item $sdomain: The students domain
9147:
9148: =back
9149:
1.157 matthew 9150: =back
9151:
1.139 matthew 9152: =cut
9153:
9154: ############################################################
9155: ############################################################
9156: sub chartlink {
9157: my ($linktext, $sname, $sdomain) = @_;
9158: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9159: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9160: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9161: '">'.$linktext.'</a>';
1.153 matthew 9162: }
9163:
9164: #######################################################
9165: #######################################################
9166:
9167: =pod
9168:
9169: =head1 Course Environment Routines
1.157 matthew 9170:
9171: =over 4
1.153 matthew 9172:
1.648 raeburn 9173: =item * &restore_course_settings()
1.153 matthew 9174:
1.648 raeburn 9175: =item * &store_course_settings()
1.153 matthew 9176:
9177: Restores/Store indicated form parameters from the course environment.
9178: Will not overwrite existing values of the form parameters.
9179:
9180: Inputs:
9181: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9182:
9183: a hash ref describing the data to be stored. For example:
9184:
9185: %Save_Parameters = ('Status' => 'scalar',
9186: 'chartoutputmode' => 'scalar',
9187: 'chartoutputdata' => 'scalar',
9188: 'Section' => 'array',
1.373 raeburn 9189: 'Group' => 'array',
1.153 matthew 9190: 'StudentData' => 'array',
9191: 'Maps' => 'array');
9192:
9193: Returns: both routines return nothing
9194:
1.631 raeburn 9195: =back
9196:
1.153 matthew 9197: =cut
9198:
9199: #######################################################
9200: #######################################################
9201: sub store_course_settings {
1.496 albertel 9202: return &store_settings($env{'request.course.id'},@_);
9203: }
9204:
9205: sub store_settings {
1.153 matthew 9206: # save to the environment
9207: # appenv the same items, just to be safe
1.300 albertel 9208: my $udom = $env{'user.domain'};
9209: my $uname = $env{'user.name'};
1.496 albertel 9210: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9211: my %SaveHash;
9212: my %AppHash;
9213: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9214: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9215: my $envname = 'environment.'.$basename;
1.258 albertel 9216: if (exists($env{'form.'.$setting})) {
1.153 matthew 9217: # Save this value away
9218: if ($type eq 'scalar' &&
1.258 albertel 9219: (! exists($env{$envname}) ||
9220: $env{$envname} ne $env{'form.'.$setting})) {
9221: $SaveHash{$basename} = $env{'form.'.$setting};
9222: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9223: } elsif ($type eq 'array') {
9224: my $stored_form;
1.258 albertel 9225: if (ref($env{'form.'.$setting})) {
1.153 matthew 9226: $stored_form = join(',',
9227: map {
1.369 www 9228: &escape($_);
1.258 albertel 9229: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9230: } else {
9231: $stored_form =
1.369 www 9232: &escape($env{'form.'.$setting});
1.153 matthew 9233: }
9234: # Determine if the array contents are the same.
1.258 albertel 9235: if ($stored_form ne $env{$envname}) {
1.153 matthew 9236: $SaveHash{$basename} = $stored_form;
9237: $AppHash{$envname} = $stored_form;
9238: }
9239: }
9240: }
9241: }
9242: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9243: $udom,$uname);
1.153 matthew 9244: if ($put_result !~ /^(ok|delayed)/) {
9245: &Apache::lonnet::logthis('unable to save form parameters, '.
9246: 'got error:'.$put_result);
9247: }
9248: # Make sure these settings stick around in this session, too
1.646 raeburn 9249: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9250: return;
9251: }
9252:
9253: sub restore_course_settings {
1.499 albertel 9254: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9255: }
9256:
9257: sub restore_settings {
9258: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9259: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9260: next if (exists($env{'form.'.$setting}));
1.496 albertel 9261: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9262: '.'.$setting;
1.258 albertel 9263: if (exists($env{$envname})) {
1.153 matthew 9264: if ($type eq 'scalar') {
1.258 albertel 9265: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9266: } elsif ($type eq 'array') {
1.258 albertel 9267: $env{'form.'.$setting} = [
1.153 matthew 9268: map {
1.369 www 9269: &unescape($_);
1.258 albertel 9270: } split(',',$env{$envname})
1.153 matthew 9271: ];
9272: }
9273: }
9274: }
1.127 matthew 9275: }
9276:
1.618 raeburn 9277: #######################################################
9278: #######################################################
9279:
9280: =pod
9281:
9282: =head1 Domain E-mail Routines
9283:
9284: =over 4
9285:
1.648 raeburn 9286: =item * &build_recipient_list()
1.618 raeburn 9287:
1.884 raeburn 9288: Build recipient lists for five types of e-mail:
1.766 raeburn 9289: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9290: (d) Help requests, (e) Course requests needing approval, generated by
9291: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9292: loncoursequeueadmin.pm respectively.
1.618 raeburn 9293:
9294: Inputs:
1.619 raeburn 9295: defmail (scalar - email address of default recipient),
1.618 raeburn 9296: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9297: defdom (domain for which to retrieve configuration settings),
9298: origmail (scalar - email address of recipient from loncapa.conf,
9299: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9300:
1.655 raeburn 9301: Returns: comma separated list of addresses to which to send e-mail.
9302:
9303: =back
1.618 raeburn 9304:
9305: =cut
9306:
9307: ############################################################
9308: ############################################################
9309: sub build_recipient_list {
1.619 raeburn 9310: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9311: my @recipients;
9312: my $otheremails;
9313: my %domconfig =
9314: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9315: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9316: if (exists($domconfig{'contacts'}{$mailing})) {
9317: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9318: my @contacts = ('adminemail','supportemail');
9319: foreach my $item (@contacts) {
9320: if ($domconfig{'contacts'}{$mailing}{$item}) {
9321: my $addr = $domconfig{'contacts'}{$item};
9322: if (!grep(/^\Q$addr\E$/,@recipients)) {
9323: push(@recipients,$addr);
9324: }
1.619 raeburn 9325: }
1.766 raeburn 9326: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9327: }
9328: }
1.766 raeburn 9329: } elsif ($origmail ne '') {
9330: push(@recipients,$origmail);
1.618 raeburn 9331: }
1.619 raeburn 9332: } elsif ($origmail ne '') {
9333: push(@recipients,$origmail);
1.618 raeburn 9334: }
1.688 raeburn 9335: if (defined($defmail)) {
9336: if ($defmail ne '') {
9337: push(@recipients,$defmail);
9338: }
1.618 raeburn 9339: }
9340: if ($otheremails) {
1.619 raeburn 9341: my @others;
9342: if ($otheremails =~ /,/) {
9343: @others = split(/,/,$otheremails);
1.618 raeburn 9344: } else {
1.619 raeburn 9345: push(@others,$otheremails);
9346: }
9347: foreach my $addr (@others) {
9348: if (!grep(/^\Q$addr\E$/,@recipients)) {
9349: push(@recipients,$addr);
9350: }
1.618 raeburn 9351: }
9352: }
1.619 raeburn 9353: my $recipientlist = join(',',@recipients);
1.618 raeburn 9354: return $recipientlist;
9355: }
9356:
1.127 matthew 9357: ############################################################
9358: ############################################################
1.154 albertel 9359:
1.655 raeburn 9360: =pod
9361:
9362: =head1 Course Catalog Routines
9363:
9364: =over 4
9365:
9366: =item * &gather_categories()
9367:
9368: Converts category definitions - keys of categories hash stored in
9369: coursecategories in configuration.db on the primary library server in a
9370: domain - to an array. Also generates javascript and idx hash used to
9371: generate Domain Coordinator interface for editing Course Categories.
9372:
9373: Inputs:
1.663 raeburn 9374:
1.655 raeburn 9375: categories (reference to hash of category definitions).
1.663 raeburn 9376:
1.655 raeburn 9377: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9378: categories and subcategories).
1.663 raeburn 9379:
1.655 raeburn 9380: idx (reference to hash of counters used in Domain Coordinator interface for
9381: editing Course Categories).
1.663 raeburn 9382:
1.655 raeburn 9383: jsarray (reference to array of categories used to create Javascript arrays for
9384: Domain Coordinator interface for editing Course Categories).
9385:
9386: Returns: nothing
9387:
9388: Side effects: populates cats, idx and jsarray.
9389:
9390: =cut
9391:
9392: sub gather_categories {
9393: my ($categories,$cats,$idx,$jsarray) = @_;
9394: my %counters;
9395: my $num = 0;
9396: foreach my $item (keys(%{$categories})) {
9397: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9398: if ($container eq '' && $depth == 0) {
9399: $cats->[$depth][$categories->{$item}] = $cat;
9400: } else {
9401: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9402: }
9403: my ($escitem,$tail) = split(/:/,$item,2);
9404: if ($counters{$tail} eq '') {
9405: $counters{$tail} = $num;
9406: $num ++;
9407: }
9408: if (ref($idx) eq 'HASH') {
9409: $idx->{$item} = $counters{$tail};
9410: }
9411: if (ref($jsarray) eq 'ARRAY') {
9412: push(@{$jsarray->[$counters{$tail}]},$item);
9413: }
9414: }
9415: return;
9416: }
9417:
9418: =pod
9419:
9420: =item * &extract_categories()
9421:
9422: Used to generate breadcrumb trails for course categories.
9423:
9424: Inputs:
1.663 raeburn 9425:
1.655 raeburn 9426: categories (reference to hash of category definitions).
1.663 raeburn 9427:
1.655 raeburn 9428: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9429: categories and subcategories).
1.663 raeburn 9430:
1.655 raeburn 9431: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9432:
1.655 raeburn 9433: allitems (reference to hash - key is category key
9434: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9435:
1.655 raeburn 9436: idx (reference to hash of counters used in Domain Coordinator interface for
9437: editing Course Categories).
1.663 raeburn 9438:
1.655 raeburn 9439: jsarray (reference to array of categories used to create Javascript arrays for
9440: Domain Coordinator interface for editing Course Categories).
9441:
1.665 raeburn 9442: subcats (reference to hash of arrays containing all subcategories within each
9443: category, -recursive)
9444:
1.655 raeburn 9445: Returns: nothing
9446:
9447: Side effects: populates trails and allitems hash references.
9448:
9449: =cut
9450:
9451: sub extract_categories {
1.665 raeburn 9452: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9453: if (ref($categories) eq 'HASH') {
9454: &gather_categories($categories,$cats,$idx,$jsarray);
9455: if (ref($cats->[0]) eq 'ARRAY') {
9456: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9457: my $name = $cats->[0][$i];
9458: my $item = &escape($name).'::0';
9459: my $trailstr;
9460: if ($name eq 'instcode') {
9461: $trailstr = &mt('Official courses (with institutional codes)');
9462: } else {
9463: $trailstr = $name;
9464: }
9465: if ($allitems->{$item} eq '') {
9466: push(@{$trails},$trailstr);
9467: $allitems->{$item} = scalar(@{$trails})-1;
9468: }
9469: my @parents = ($name);
9470: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9471: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9472: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9473: if (ref($subcats) eq 'HASH') {
9474: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9475: }
9476: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9477: }
9478: } else {
9479: if (ref($subcats) eq 'HASH') {
9480: $subcats->{$item} = [];
1.655 raeburn 9481: }
9482: }
9483: }
9484: }
9485: }
9486: return;
9487: }
9488:
9489: =pod
9490:
9491: =item *&recurse_categories()
9492:
9493: Recursively used to generate breadcrumb trails for course categories.
9494:
9495: Inputs:
1.663 raeburn 9496:
1.655 raeburn 9497: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9498: categories and subcategories).
1.663 raeburn 9499:
1.655 raeburn 9500: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9501:
9502: category (current course category, for which breadcrumb trail is being generated).
9503:
9504: trails (reference to array of breadcrumb trails for each category).
9505:
1.655 raeburn 9506: allitems (reference to hash - key is category key
9507: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9508:
1.655 raeburn 9509: parents (array containing containers directories for current category,
9510: back to top level).
9511:
9512: Returns: nothing
9513:
9514: Side effects: populates trails and allitems hash references
9515:
9516: =cut
9517:
9518: sub recurse_categories {
1.665 raeburn 9519: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9520: my $shallower = $depth - 1;
9521: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9522: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9523: my $name = $cats->[$depth]{$category}[$k];
9524: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9525: my $trailstr = join(' -> ',(@{$parents},$category));
9526: if ($allitems->{$item} eq '') {
9527: push(@{$trails},$trailstr);
9528: $allitems->{$item} = scalar(@{$trails})-1;
9529: }
9530: my $deeper = $depth+1;
9531: push(@{$parents},$category);
1.665 raeburn 9532: if (ref($subcats) eq 'HASH') {
9533: my $subcat = &escape($name).':'.$category.':'.$depth;
9534: for (my $j=@{$parents}; $j>=0; $j--) {
9535: my $higher;
9536: if ($j > 0) {
9537: $higher = &escape($parents->[$j]).':'.
9538: &escape($parents->[$j-1]).':'.$j;
9539: } else {
9540: $higher = &escape($parents->[$j]).'::'.$j;
9541: }
9542: push(@{$subcats->{$higher}},$subcat);
9543: }
9544: }
9545: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9546: $subcats);
1.655 raeburn 9547: pop(@{$parents});
9548: }
9549: } else {
9550: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9551: my $trailstr = join(' -> ',(@{$parents},$category));
9552: if ($allitems->{$item} eq '') {
9553: push(@{$trails},$trailstr);
9554: $allitems->{$item} = scalar(@{$trails})-1;
9555: }
9556: }
9557: return;
9558: }
9559:
1.663 raeburn 9560: =pod
9561:
9562: =item *&assign_categories_table()
9563:
9564: Create a datatable for display of hierarchical categories in a domain,
9565: with checkboxes to allow a course to be categorized.
9566:
9567: Inputs:
9568:
9569: cathash - reference to hash of categories defined for the domain (from
9570: configuration.db)
9571:
9572: currcat - scalar with an & separated list of categories assigned to a course.
9573:
9574: Returns: $output (markup to be displayed)
9575:
9576: =cut
9577:
9578: sub assign_categories_table {
9579: my ($cathash,$currcat) = @_;
9580: my $output;
9581: if (ref($cathash) eq 'HASH') {
9582: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9583: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9584: $maxdepth = scalar(@cats);
9585: if (@cats > 0) {
9586: my $itemcount = 0;
9587: if (ref($cats[0]) eq 'ARRAY') {
9588: $output = &Apache::loncommon::start_data_table();
9589: my @currcategories;
9590: if ($currcat ne '') {
9591: @currcategories = split('&',$currcat);
9592: }
9593: for (my $i=0; $i<@{$cats[0]}; $i++) {
9594: my $parent = $cats[0][$i];
9595: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9596: next if ($parent eq 'instcode');
9597: my $item = &escape($parent).'::0';
9598: my $checked = '';
9599: if (@currcategories > 0) {
9600: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9601: $checked = ' checked="checked"';
1.663 raeburn 9602: }
9603: }
1.675 raeburn 9604: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9605: '<input type="checkbox" name="usecategory" value="'.
9606: $item.'"'.$checked.' />'.$parent.'</span>'.
9607: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9608: my $depth = 1;
9609: push(@path,$parent);
9610: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9611: pop(@path);
9612: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9613: $itemcount ++;
9614: }
9615: $output .= &Apache::loncommon::end_data_table();
9616: }
9617: }
9618: }
9619: return $output;
9620: }
9621:
9622: =pod
9623:
9624: =item *&assign_category_rows()
9625:
9626: Create a datatable row for display of nested categories in a domain,
9627: with checkboxes to allow a course to be categorized,called recursively.
9628:
9629: Inputs:
9630:
9631: itemcount - track row number for alternating colors
9632:
9633: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9634: categories and subcategories.
9635:
9636: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9637:
9638: parent - parent of current category item
9639:
9640: path - Array containing all categories back up through the hierarchy from the
9641: current category to the top level.
9642:
9643: currcategories - reference to array of current categories assigned to the course
9644:
9645: Returns: $output (markup to be displayed).
9646:
9647: =cut
9648:
9649: sub assign_category_rows {
9650: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9651: my ($text,$name,$item,$chgstr);
9652: if (ref($cats) eq 'ARRAY') {
9653: my $maxdepth = scalar(@{$cats});
9654: if (ref($cats->[$depth]) eq 'HASH') {
9655: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9656: my $numchildren = @{$cats->[$depth]{$parent}};
9657: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9658: $text .= '<td><table class="LC_datatable">';
9659: for (my $j=0; $j<$numchildren; $j++) {
9660: $name = $cats->[$depth]{$parent}[$j];
9661: $item = &escape($name).':'.&escape($parent).':'.$depth;
9662: my $deeper = $depth+1;
9663: my $checked = '';
9664: if (ref($currcategories) eq 'ARRAY') {
9665: if (@{$currcategories} > 0) {
9666: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9667: $checked = ' checked="checked"';
1.663 raeburn 9668: }
9669: }
9670: }
1.664 raeburn 9671: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9672: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9673: $item.'"'.$checked.' />'.$name.'</label></span>'.
9674: '<input type="hidden" name="catname" value="'.$name.'" />'.
9675: '</td><td>';
1.663 raeburn 9676: if (ref($path) eq 'ARRAY') {
9677: push(@{$path},$name);
9678: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9679: pop(@{$path});
9680: }
9681: $text .= '</td></tr>';
9682: }
9683: $text .= '</table></td>';
9684: }
9685: }
9686: }
9687: return $text;
9688: }
9689:
1.655 raeburn 9690: ############################################################
9691: ############################################################
9692:
9693:
1.443 albertel 9694: sub commit_customrole {
1.664 raeburn 9695: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9696: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9697: ($start?', '.&mt('starting').' '.localtime($start):'').
9698: ($end?', ending '.localtime($end):'').': <b>'.
9699: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9700: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9701: '</b><br />';
9702: return $output;
9703: }
9704:
9705: sub commit_standardrole {
1.541 raeburn 9706: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9707: my ($output,$logmsg,$linefeed);
9708: if ($context eq 'auto') {
9709: $linefeed = "\n";
9710: } else {
9711: $linefeed = "<br />\n";
9712: }
1.443 albertel 9713: if ($three eq 'st') {
1.541 raeburn 9714: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9715: $one,$two,$sec,$context);
9716: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9717: ($result eq 'unknown_course') || ($result eq 'refused')) {
9718: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9719: } else {
1.541 raeburn 9720: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9721: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9722: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9723: if ($context eq 'auto') {
9724: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9725: } else {
9726: $output .= '<b>'.$result.'</b>'.$linefeed.
9727: &mt('Add to classlist').': <b>ok</b>';
9728: }
9729: $output .= $linefeed;
1.443 albertel 9730: }
9731: } else {
9732: $output = &mt('Assigning').' '.$three.' in '.$url.
9733: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9734: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9735: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9736: if ($context eq 'auto') {
9737: $output .= $result.$linefeed;
9738: } else {
9739: $output .= '<b>'.$result.'</b>'.$linefeed;
9740: }
1.443 albertel 9741: }
9742: return $output;
9743: }
9744:
9745: sub commit_studentrole {
1.541 raeburn 9746: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9747: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9748: if ($context eq 'auto') {
9749: $linefeed = "\n";
9750: } else {
9751: $linefeed = '<br />'."\n";
9752: }
1.443 albertel 9753: if (defined($one) && defined($two)) {
9754: my $cid=$one.'_'.$two;
9755: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9756: my $secchange = 0;
9757: my $expire_role_result;
9758: my $modify_section_result;
1.628 raeburn 9759: if ($oldsec ne '-1') {
9760: if ($oldsec ne $sec) {
1.443 albertel 9761: $secchange = 1;
1.628 raeburn 9762: my $now = time;
1.443 albertel 9763: my $uurl='/'.$cid;
9764: $uurl=~s/\_/\//g;
9765: if ($oldsec) {
9766: $uurl.='/'.$oldsec;
9767: }
1.626 raeburn 9768: $oldsecurl = $uurl;
1.628 raeburn 9769: $expire_role_result =
1.652 raeburn 9770: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9771: if ($env{'request.course.sec'} ne '') {
9772: if ($expire_role_result eq 'refused') {
9773: my @roles = ('st');
9774: my @statuses = ('previous');
9775: my @roledoms = ($one);
9776: my $withsec = 1;
9777: my %roleshash =
9778: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9779: \@statuses,\@roles,\@roledoms,$withsec);
9780: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9781: my ($oldstart,$oldend) =
9782: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9783: if ($oldend > 0 && $oldend <= $now) {
9784: $expire_role_result = 'ok';
9785: }
9786: }
9787: }
9788: }
1.443 albertel 9789: $result = $expire_role_result;
9790: }
9791: }
9792: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9793: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9794: if ($modify_section_result =~ /^ok/) {
9795: if ($secchange == 1) {
1.628 raeburn 9796: if ($sec eq '') {
9797: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9798: } else {
9799: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9800: }
1.443 albertel 9801: } elsif ($oldsec eq '-1') {
1.628 raeburn 9802: if ($sec eq '') {
9803: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9804: } else {
9805: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9806: }
1.443 albertel 9807: } else {
1.628 raeburn 9808: if ($sec eq '') {
9809: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9810: } else {
9811: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9812: }
1.443 albertel 9813: }
9814: } else {
1.628 raeburn 9815: if ($secchange) {
9816: $$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;
9817: } else {
9818: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9819: }
1.443 albertel 9820: }
9821: $result = $modify_section_result;
9822: } elsif ($secchange == 1) {
1.628 raeburn 9823: if ($oldsec eq '') {
9824: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9825: } else {
9826: $$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;
9827: }
1.626 raeburn 9828: if ($expire_role_result eq 'refused') {
9829: my $newsecurl = '/'.$cid;
9830: $newsecurl =~ s/\_/\//g;
9831: if ($sec ne '') {
9832: $newsecurl.='/'.$sec;
9833: }
9834: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9835: if ($sec eq '') {
9836: $$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;
9837: } else {
9838: $$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;
9839: }
9840: }
9841: }
1.443 albertel 9842: }
9843: } else {
1.626 raeburn 9844: $$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 9845: $result = "error: incomplete course id\n";
9846: }
9847: return $result;
9848: }
9849:
9850: ############################################################
9851: ############################################################
9852:
1.566 albertel 9853: sub check_clone {
1.578 raeburn 9854: my ($args,$linefeed) = @_;
1.566 albertel 9855: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9856: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9857: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9858: my $clonemsg;
9859: my $can_clone = 0;
9860:
9861: if ($clonehome eq 'no_host') {
1.578 raeburn 9862: $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 9863: } else {
9864: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.882 raeburn 9865: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
9866: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 9867: $can_clone = 1;
9868: } else {
9869: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9870: $args->{'clonedomain'},$args->{'clonecourse'});
9871: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9872: if (grep(/^\*$/,@cloners)) {
9873: $can_clone = 1;
9874: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9875: $can_clone = 1;
9876: } else {
9877: my %roleshash =
9878: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9879: $args->{'ccdomain'},
9880: 'userroles',['active'],['cc'],
9881: [$args->{'clonedomain'}]);
9882: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9883: $can_clone = 1;
9884: } else {
9885: $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'});
9886: }
1.566 albertel 9887: }
1.578 raeburn 9888: }
1.566 albertel 9889: }
9890: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9891: }
9892:
1.444 albertel 9893: sub construct_course {
1.885 raeburn 9894: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 9895: my $outcome;
1.541 raeburn 9896: my $linefeed = '<br />'."\n";
9897: if ($context eq 'auto') {
9898: $linefeed = "\n";
9899: }
1.566 albertel 9900:
9901: #
9902: # Are we cloning?
9903: #
9904: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9905: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9906: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9907: if ($context ne 'auto') {
1.578 raeburn 9908: if ($clonemsg ne '') {
9909: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9910: }
1.566 albertel 9911: }
9912: $outcome .= $clonemsg.$linefeed;
9913:
9914: if (!$can_clone) {
9915: return (0,$outcome);
9916: }
9917: }
9918:
1.444 albertel 9919: #
9920: # Open course
9921: #
9922: my $crstype = lc($args->{'crstype'});
9923: my %cenv=();
9924: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9925: $args->{'cdescr'},
9926: $args->{'curl'},
9927: $args->{'course_home'},
9928: $args->{'nonstandard'},
9929: $args->{'crscode'},
9930: $args->{'ccuname'}.':'.
9931: $args->{'ccdomain'},
1.882 raeburn 9932: $args->{'crstype'},
1.885 raeburn 9933: $cnum,$context,$category);
1.444 albertel 9934:
9935: # Note: The testing routines depend on this being output; see
9936: # Utils::Course. This needs to at least be output as a comment
9937: # if anyone ever decides to not show this, and Utils::Course::new
9938: # will need to be suitably modified.
1.541 raeburn 9939: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9940: #
9941: # Check if created correctly
9942: #
1.479 albertel 9943: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9944: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9945: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9946:
1.444 albertel 9947: #
1.566 albertel 9948: # Do the cloning
9949: #
9950: if ($can_clone && $cloneid) {
9951: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9952: if ($context ne 'auto') {
9953: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9954: }
9955: $outcome .= $clonemsg.$linefeed;
9956: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9957: # Copy all files
1.637 www 9958: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9959: # Restore URL
1.566 albertel 9960: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9961: # Restore title
1.566 albertel 9962: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9963: # Mark as cloned
1.566 albertel 9964: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9965: # Need to clone grading mode
9966: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9967: $cenv{'grading'}=$newenv{'grading'};
9968: # Do not clone these environment entries
9969: &Apache::lonnet::del('environment',
9970: ['default_enrollment_start_date',
9971: 'default_enrollment_end_date',
9972: 'question.email',
9973: 'policy.email',
9974: 'comment.email',
9975: 'pch.users.denied',
1.725 raeburn 9976: 'plc.users.denied',
9977: 'hidefromcat',
9978: 'categories'],
1.638 www 9979: $$crsudom,$$crsunum);
1.444 albertel 9980: }
1.566 albertel 9981:
1.444 albertel 9982: #
9983: # Set environment (will override cloned, if existing)
9984: #
9985: my @sections = ();
9986: my @xlists = ();
9987: if ($args->{'crstype'}) {
9988: $cenv{'type'}=$args->{'crstype'};
9989: }
9990: if ($args->{'crsid'}) {
9991: $cenv{'courseid'}=$args->{'crsid'};
9992: }
9993: if ($args->{'crscode'}) {
9994: $cenv{'internal.coursecode'}=$args->{'crscode'};
9995: }
9996: if ($args->{'crsquota'} ne '') {
9997: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9998: } else {
9999: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10000: }
10001: if ($args->{'ccuname'}) {
10002: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10003: ':'.$args->{'ccdomain'};
10004: } else {
10005: $cenv{'internal.courseowner'} = $args->{'curruser'};
10006: }
10007: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10008: if ($args->{'crssections'}) {
10009: $cenv{'internal.sectionnums'} = '';
10010: if ($args->{'crssections'} =~ m/,/) {
10011: @sections = split/,/,$args->{'crssections'};
10012: } else {
10013: $sections[0] = $args->{'crssections'};
10014: }
10015: if (@sections > 0) {
10016: foreach my $item (@sections) {
10017: my ($sec,$gp) = split/:/,$item;
10018: my $class = $args->{'crscode'}.$sec;
10019: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10020: $cenv{'internal.sectionnums'} .= $item.',';
10021: unless ($addcheck eq 'ok') {
10022: push @badclasses, $class;
10023: }
10024: }
10025: $cenv{'internal.sectionnums'} =~ s/,$//;
10026: }
10027: }
10028: # do not hide course coordinator from staff listing,
10029: # even if privileged
10030: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10031: # add crosslistings
10032: if ($args->{'crsxlist'}) {
10033: $cenv{'internal.crosslistings'}='';
10034: if ($args->{'crsxlist'} =~ m/,/) {
10035: @xlists = split/,/,$args->{'crsxlist'};
10036: } else {
10037: $xlists[0] = $args->{'crsxlist'};
10038: }
10039: if (@xlists > 0) {
10040: foreach my $item (@xlists) {
10041: my ($xl,$gp) = split/:/,$item;
10042: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10043: $cenv{'internal.crosslistings'} .= $item.',';
10044: unless ($addcheck eq 'ok') {
10045: push @badclasses, $xl;
10046: }
10047: }
10048: $cenv{'internal.crosslistings'} =~ s/,$//;
10049: }
10050: }
10051: if ($args->{'autoadds'}) {
10052: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10053: }
10054: if ($args->{'autodrops'}) {
10055: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10056: }
10057: # check for notification of enrollment changes
10058: my @notified = ();
10059: if ($args->{'notify_owner'}) {
10060: if ($args->{'ccuname'} ne '') {
10061: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10062: }
10063: }
10064: if ($args->{'notify_dc'}) {
10065: if ($uname ne '') {
1.630 raeburn 10066: push(@notified,$uname.':'.$udom);
1.444 albertel 10067: }
10068: }
10069: if (@notified > 0) {
10070: my $notifylist;
10071: if (@notified > 1) {
10072: $notifylist = join(',',@notified);
10073: } else {
10074: $notifylist = $notified[0];
10075: }
10076: $cenv{'internal.notifylist'} = $notifylist;
10077: }
10078: if (@badclasses > 0) {
10079: my %lt=&Apache::lonlocal::texthash(
10080: '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',
10081: 'dnhr' => 'does not have rights to access enrollment in these classes',
10082: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10083: );
1.541 raeburn 10084: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10085: ' ('.$lt{'adby'}.')';
10086: if ($context eq 'auto') {
10087: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10088: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10089: foreach my $item (@badclasses) {
10090: if ($context eq 'auto') {
10091: $outcome .= " - $item\n";
10092: } else {
10093: $outcome .= "<li>$item</li>\n";
10094: }
10095: }
10096: if ($context eq 'auto') {
10097: $outcome .= $linefeed;
10098: } else {
1.566 albertel 10099: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10100: }
10101: }
1.444 albertel 10102: }
10103: if ($args->{'no_end_date'}) {
10104: $args->{'endaccess'} = 0;
10105: }
10106: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10107: $cenv{'internal.autoend'}=$args->{'enrollend'};
10108: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10109: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10110: if ($args->{'showphotos'}) {
10111: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10112: }
10113: $cenv{'internal.authtype'} = $args->{'authtype'};
10114: $cenv{'internal.autharg'} = $args->{'autharg'};
10115: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10116: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10117: 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');
10118: if ($context eq 'auto') {
10119: $outcome .= $krb_msg;
10120: } else {
1.566 albertel 10121: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10122: }
10123: $outcome .= $linefeed;
1.444 albertel 10124: }
10125: }
10126: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10127: if ($args->{'setpolicy'}) {
10128: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10129: }
10130: if ($args->{'setcontent'}) {
10131: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10132: }
10133: }
10134: if ($args->{'reshome'}) {
10135: $cenv{'reshome'}=$args->{'reshome'}.'/';
10136: $cenv{'reshome'}=~s/\/+$/\//;
10137: }
10138: #
10139: # course has keyed access
10140: #
10141: if ($args->{'setkeys'}) {
10142: $cenv{'keyaccess'}='yes';
10143: }
10144: # if specified, key authority is not course, but user
10145: # only active if keyaccess is yes
10146: if ($args->{'keyauth'}) {
1.487 albertel 10147: my ($user,$domain) = split(':',$args->{'keyauth'});
10148: $user = &LONCAPA::clean_username($user);
10149: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10150: if ($user ne '' && $domain ne '') {
1.487 albertel 10151: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10152: }
10153: }
10154:
10155: if ($args->{'disresdis'}) {
10156: $cenv{'pch.roles.denied'}='st';
10157: }
10158: if ($args->{'disablechat'}) {
10159: $cenv{'plc.roles.denied'}='st';
10160: }
10161:
10162: # Record we've not yet viewed the Course Initialization Helper for this
10163: # course
10164: $cenv{'course.helper.not.run'} = 1;
10165: #
10166: # Use new Randomseed
10167: #
10168: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10169: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10170: #
10171: # The encryption code and receipt prefix for this course
10172: #
10173: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10174: $cenv{'internal.encpref'}=100+int(9*rand(99));
10175: #
10176: # By default, use standard grading
10177: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10178:
1.541 raeburn 10179: $outcome .= $linefeed.&mt('Setting environment').': '.
10180: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10181: #
10182: # Open all assignments
10183: #
10184: if ($args->{'openall'}) {
10185: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10186: my %storecontent = ($storeunder => time,
10187: $storeunder.'.type' => 'date_start');
10188:
10189: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10190: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10191: }
10192: #
10193: # Set first page
10194: #
10195: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10196: || ($cloneid)) {
1.445 albertel 10197: use LONCAPA::map;
1.444 albertel 10198: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10199:
10200: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10201: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10202:
1.444 albertel 10203: $outcome .= ($fatal?$errtext:'read ok').' - ';
10204: my $title; my $url;
10205: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10206: $title=&mt('Syllabus');
1.444 albertel 10207: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10208: } else {
1.690 bisitz 10209: $title=&mt('Navigate Contents');
1.444 albertel 10210: $url='/adm/navmaps';
10211: }
1.445 albertel 10212:
10213: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10214: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10215:
10216: if ($errtext) { $fatal=2; }
1.541 raeburn 10217: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10218: }
1.566 albertel 10219:
10220: return (1,$outcome);
1.444 albertel 10221: }
10222:
10223: ############################################################
10224: ############################################################
10225:
1.378 raeburn 10226: sub course_type {
10227: my ($cid) = @_;
10228: if (!defined($cid)) {
10229: $cid = $env{'request.course.id'};
10230: }
1.404 albertel 10231: if (defined($env{'course.'.$cid.'.type'})) {
10232: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10233: } else {
10234: return 'Course';
1.377 raeburn 10235: }
10236: }
1.156 albertel 10237:
1.406 raeburn 10238: sub group_term {
10239: my $crstype = &course_type();
10240: my %names = (
10241: 'Course' => 'group',
1.865 raeburn 10242: 'Community' => 'group',
1.406 raeburn 10243: );
10244: return $names{$crstype};
10245: }
10246:
1.156 albertel 10247: sub icon {
10248: my ($file)=@_;
1.505 albertel 10249: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10250: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10251: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10252: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10253: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10254: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10255: $curfext.".gif") {
10256: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10257: $curfext.".gif";
10258: }
10259: }
1.249 albertel 10260: return &lonhttpdurl($iconname);
1.154 albertel 10261: }
1.84 albertel 10262:
1.575 albertel 10263: sub lonhttpdurl {
1.692 www 10264: #
10265: # Had been used for "small fry" static images on separate port 8080.
10266: # Modify here if lightweight http functionality desired again.
10267: # Currently eliminated due to increasing firewall issues.
10268: #
1.575 albertel 10269: my ($url)=@_;
1.692 www 10270: return $url;
1.215 albertel 10271: }
10272:
1.213 albertel 10273: sub connection_aborted {
10274: my ($r)=@_;
10275: $r->print(" ");$r->rflush();
10276: my $c = $r->connection;
10277: return $c->aborted();
10278: }
10279:
1.221 foxr 10280: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10281: # strings as 'strings'.
10282: sub escape_single {
1.221 foxr 10283: my ($input) = @_;
1.223 albertel 10284: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10285: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10286: return $input;
10287: }
1.223 albertel 10288:
1.222 foxr 10289: # Same as escape_single, but escape's "'s This
10290: # can be used for "strings"
10291: sub escape_double {
10292: my ($input) = @_;
10293: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10294: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10295: return $input;
10296: }
1.223 albertel 10297:
1.222 foxr 10298: # Escapes the last element of a full URL.
10299: sub escape_url {
10300: my ($url) = @_;
1.238 raeburn 10301: my @urlslices = split(/\//, $url,-1);
1.369 www 10302: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10303: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10304: }
1.462 albertel 10305:
1.820 raeburn 10306: sub compare_arrays {
10307: my ($arrayref1,$arrayref2) = @_;
10308: my (@difference,%count);
10309: @difference = ();
10310: %count = ();
10311: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10312: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10313: foreach my $element (keys(%count)) {
10314: if ($count{$element} == 1) {
10315: push(@difference,$element);
10316: }
10317: }
10318: }
10319: return @difference;
10320: }
10321:
1.817 bisitz 10322: # -------------------------------------------------------- Initialize user login
1.462 albertel 10323: sub init_user_environment {
1.463 albertel 10324: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10325: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10326:
10327: my $public=($username eq 'public' && $domain eq 'public');
10328:
10329: # See if old ID present, if so, remove
10330:
10331: my ($filename,$cookie,$userroles);
10332: my $now=time;
10333:
10334: if ($public) {
10335: my $max_public=100;
10336: my $oldest;
10337: my $oldest_time=0;
10338: for(my $next=1;$next<=$max_public;$next++) {
10339: if (-e $lonids."/publicuser_$next.id") {
10340: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10341: if ($mtime<$oldest_time || !$oldest_time) {
10342: $oldest_time=$mtime;
10343: $oldest=$next;
10344: }
10345: } else {
10346: $cookie="publicuser_$next";
10347: last;
10348: }
10349: }
10350: if (!$cookie) { $cookie="publicuser_$oldest"; }
10351: } else {
1.463 albertel 10352: # if this isn't a robot, kill any existing non-robot sessions
10353: if (!$args->{'robot'}) {
10354: opendir(DIR,$lonids);
10355: while ($filename=readdir(DIR)) {
10356: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10357: unlink($lonids.'/'.$filename);
10358: }
1.462 albertel 10359: }
1.463 albertel 10360: closedir(DIR);
1.462 albertel 10361: }
10362: # Give them a new cookie
1.463 albertel 10363: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10364: : $now.$$.int(rand(10000)));
1.463 albertel 10365: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10366:
10367: # Initialize roles
10368:
10369: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10370: }
10371: # ------------------------------------ Check browser type and MathML capability
10372:
10373: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10374: $clientunicode,$clientos) = &decode_user_agent($r);
10375:
10376: # ------------------------------------------------------------- Get environment
10377:
10378: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10379: my ($tmp) = keys(%userenv);
10380: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10381: # default remote control to off
10382: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10383: } else {
10384: undef(%userenv);
10385: }
10386: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10387: $form->{'interface'}=$userenv{'interface'};
10388: }
10389: $env{'environment.remote'}=$userenv{'remote'};
10390: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10391:
10392: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10393: foreach my $option ('interface','localpath','localres') {
10394: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10395: }
10396: # --------------------------------------------------------- Write first profile
10397:
10398: {
10399: my %initial_env =
10400: ("user.name" => $username,
10401: "user.domain" => $domain,
10402: "user.home" => $authhost,
10403: "browser.type" => $clientbrowser,
10404: "browser.version" => $clientversion,
10405: "browser.mathml" => $clientmathml,
10406: "browser.unicode" => $clientunicode,
10407: "browser.os" => $clientos,
10408: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10409: "request.course.fn" => '',
10410: "request.course.uri" => '',
10411: "request.course.sec" => '',
10412: "request.role" => 'cm',
10413: "request.role.adv" => $env{'user.adv'},
10414: "request.host" => $ENV{'REMOTE_ADDR'},);
10415:
10416: if ($form->{'localpath'}) {
10417: $initial_env{"browser.localpath"} = $form->{'localpath'};
10418: $initial_env{"browser.localres"} = $form->{'localres'};
10419: }
10420:
10421: if ($public) {
10422: $initial_env{"environment.remote"} = "off";
10423: }
10424: if ($form->{'interface'}) {
10425: $form->{'interface'}=~s/\W//gs;
10426: $initial_env{"browser.interface"} = $form->{'interface'};
10427: $env{'browser.interface'}=$form->{'interface'};
10428: }
10429:
1.724 raeburn 10430: foreach my $tool ('aboutme','blog','portfolio') {
10431: $userenv{'availabletools.'.$tool} =
10432: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10433: }
10434:
1.864 raeburn 10435: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10436: $userenv{'canrequest.'.$crstype} =
10437: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10438: 'reload','requestcourses');
10439: }
10440:
1.462 albertel 10441: $env{'user.environment'} = "$lonids/$cookie.id";
10442:
10443: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10444: &GDBM_WRCREAT(),0640)) {
10445: &_add_to_env(\%disk_env,\%initial_env);
10446: &_add_to_env(\%disk_env,\%userenv,'environment.');
10447: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10448: if (ref($args->{'extra_env'})) {
10449: &_add_to_env(\%disk_env,$args->{'extra_env'});
10450: }
1.462 albertel 10451: untie(%disk_env);
10452: } else {
1.705 tempelho 10453: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10454: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10455: return 'error: '.$!;
10456: }
10457: }
10458: $env{'request.role'}='cm';
10459: $env{'request.role.adv'}=$env{'user.adv'};
10460: $env{'browser.type'}=$clientbrowser;
10461:
10462: return $cookie;
10463:
10464: }
10465:
10466: sub _add_to_env {
10467: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10468: if (ref($env_data) eq 'HASH') {
10469: while (my ($key,$value) = each(%$env_data)) {
10470: $idf->{$prefix.$key} = $value;
10471: $env{$prefix.$key} = $value;
10472: }
1.462 albertel 10473: }
10474: }
10475:
1.685 tempelho 10476: # --- Get the symbolic name of a problem and the url
10477: sub get_symb {
10478: my ($request,$silent) = @_;
1.726 raeburn 10479: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10480: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10481: if ($symb eq '') {
10482: if (!$silent) {
10483: $request->print("Unable to handle ambiguous references:$url:.");
10484: return ();
10485: }
10486: }
10487: &Apache::lonenc::check_decrypt(\$symb);
10488: return ($symb);
10489: }
10490:
10491: # --------------------------------------------------------------Get annotation
10492:
10493: sub get_annotation {
10494: my ($symb,$enc) = @_;
10495:
10496: my $key = $symb;
10497: if (!$enc) {
10498: $key =
10499: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10500: }
10501: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10502: return $annotation{$key};
10503: }
10504:
10505: sub clean_symb {
1.731 raeburn 10506: my ($symb,$delete_enc) = @_;
1.685 tempelho 10507:
10508: &Apache::lonenc::check_decrypt(\$symb);
10509: my $enc = $env{'request.enc'};
1.731 raeburn 10510: if ($delete_enc) {
1.730 raeburn 10511: delete($env{'request.enc'});
10512: }
1.685 tempelho 10513:
10514: return ($symb,$enc);
10515: }
1.462 albertel 10516:
1.41 ng 10517: =pod
10518:
10519: =back
10520:
1.112 bowersj2 10521: =cut
1.41 ng 10522:
1.112 bowersj2 10523: 1;
10524: __END__;
1.41 ng 10525:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>