Annotation of loncom/interface/loncommon.pm, revision 1.907
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.907 ! raeburn 4: # $Id: loncommon.pm,v 1.906 2009/10/31 05:47:10 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.905 raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element)=@_;
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.895 raeburn 496: var formid = getFormIdByName(formname);
1.876 raeburn 497: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 498: if (domainfilter != null) {
499: if (domainfilter != '') {
500: url += 'domainfilter='+domainfilter+'&';
501: }
502: }
1.91 www 503: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 504: '&cdomelement='+udom+
505: '&cnameelement='+desc;
1.468 raeburn 506: if (extra_element !=null && extra_element != '') {
1.594 raeburn 507: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 508: url += '&roleelement='+extra_element;
509: if (domainfilter == null || domainfilter == '') {
510: url += '&domainfilter='+extra_element;
511: }
1.234 raeburn 512: }
1.468 raeburn 513: else {
514: if (formname == 'portform') {
515: url += '&setroles='+extra_element;
1.800 raeburn 516: } else {
517: if (formname == 'rules') {
518: url += '&fixeddom='+extra_element;
519: }
1.468 raeburn 520: }
521: }
1.230 raeburn 522: }
1.872 raeburn 523: if (formname == 'ccrs') {
524: var ownername = document.forms[formid].ccuname.value;
525: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
526: url += '&cloner='+ownername+':'+ownerdom;
527: }
1.293 raeburn 528: if (multflag !=null && multflag != '') {
529: url += '&multiple='+multflag;
530: }
1.865 raeburn 531: if (crstype == 'Course/Community') {
1.377 raeburn 532: if (formname == 'cu') {
533: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
534: if (crstype == "") {
535: alert("$crs_or_grp_alert");
536: return;
537: }
538: }
539: }
540: if (crstype !=null && crstype != '') {
541: url += '&type='+crstype;
542: }
1.102 www 543: var title = 'Course_Browser';
1.91 www 544: var options = 'scrollbars=1,resizable=1,menubar=0';
545: options += ',width=700,height=600';
546: stdeditbrowser = open(url,title,options,'1');
547: stdeditbrowser.focus();
548: }
1.876 raeburn 549: $id_functions
550: ENDSTDBRW
1.905 raeburn 551: if (($sec_element ne '') || ($role_element ne '')) {
552: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 553: }
554: $output .= '
555: // ]]>
556: </script>';
557: return $output;
558: }
559:
560: sub javascript_index_functions {
561: return <<"ENDJS";
562:
563: function getFormIdByName(formname) {
564: for (var i=0;i<document.forms.length;i++) {
565: if (document.forms[i].name == formname) {
566: return i;
567: }
568: }
569: return -1;
570: }
571:
572: function getIndexByName(formid,item) {
573: for (var i=0;i<document.forms[formid].elements.length;i++) {
574: if (document.forms[formid].elements[i].name == item) {
575: return i;
576: }
577: }
578: return -1;
579: }
1.468 raeburn 580:
1.876 raeburn 581: function getDomainFromSelectbox(formname,udom) {
582: var userdom;
583: var formid = getFormIdByName(formname);
584: if (formid > -1) {
585: var domid = getIndexByName(formid,udom);
586: if (domid > -1) {
587: if (document.forms[formid].elements[domid].type == 'select-one') {
588: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
589: }
590: if (document.forms[formid].elements[domid].type == 'hidden') {
591: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 592: }
593: }
594: }
1.876 raeburn 595: return userdom;
596: }
597:
598: ENDJS
1.468 raeburn 599:
1.876 raeburn 600: }
601:
602: sub userbrowser_javascript {
603: my $id_functions = &javascript_index_functions();
604: return <<"ENDUSERBRW";
605:
1.888 raeburn 606: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 607: var url = '/adm/pickuser?';
608: var userdom = getDomainFromSelectbox(formname,udom);
609: if (userdom != null) {
610: if (userdom != '') {
611: url += 'srchdom='+userdom+'&';
612: }
613: }
614: url += 'form=' + formname + '&unameelement='+uname+
615: '&udomelement='+udom+
616: '&ulastelement='+ulast+
617: '&ufirstelement='+ufirst+
618: '&uemailelement='+uemail+
1.881 raeburn 619: '&hideudomelement='+hideudom+
620: '&coursedom='+crsdom;
1.888 raeburn 621: if ((caller != null) && (caller != undefined)) {
622: url += '&caller='+caller;
623: }
1.876 raeburn 624: var title = 'User_Browser';
625: var options = 'scrollbars=1,resizable=1,menubar=0';
626: options += ',width=700,height=600';
627: var stdeditbrowser = open(url,title,options,'1');
628: stdeditbrowser.focus();
629: }
630:
1.888 raeburn 631: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 632: var formid = getFormIdByName(formname);
633: if (formid > -1) {
1.888 raeburn 634: var unameid = getIndexByName(formid,uname);
1.876 raeburn 635: var domid = getIndexByName(formid,udom);
636: var hidedomid = getIndexByName(formid,origdom);
637: if (hidedomid > -1) {
638: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 639: var unameval = document.forms[formid].elements[unameid].value;
640: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
641: if (domid > -1) {
642: var slct = document.forms[formid].elements[domid];
643: if (slct.type == 'select-one') {
644: var i;
645: for (i=0;i<slct.length;i++) {
646: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
647: }
648: }
649: if (slct.type == 'hidden') {
650: slct.value = fixeddom;
1.876 raeburn 651: }
652: }
1.468 raeburn 653: }
654: }
655: }
1.876 raeburn 656: return;
657: }
658:
659: $id_functions
660: ENDUSERBRW
1.468 raeburn 661: }
662:
663: sub setsec_javascript {
1.905 raeburn 664: my ($sec_element,$formname,$role_element) = @_;
665: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
666: $communityrolestr);
667: if ($role_element ne '') {
668: my @allroles = ('st','ta','ep','in','ad');
669: foreach my $crstype ('Course','Community') {
670: if ($crstype eq 'Community') {
671: foreach my $role (@allroles) {
672: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
673: }
674: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
675: } else {
676: foreach my $role (@allroles) {
677: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
678: }
679: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
680: }
681: }
682: $rolestr = '"'.join('","',@allroles).'"';
683: $courserolestr = '"'.join('","',@courserolenames).'"';
684: $communityrolestr = '"'.join('","',@communityrolenames).'"';
685: }
1.468 raeburn 686: my $setsections = qq|
687: function setSect(sectionlist) {
1.629 raeburn 688: var sectionsArray = new Array();
689: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
690: sectionsArray = sectionlist.split(",");
691: }
1.468 raeburn 692: var numSections = sectionsArray.length;
693: document.$formname.$sec_element.length = 0;
694: if (numSections == 0) {
695: document.$formname.$sec_element.multiple=false;
696: document.$formname.$sec_element.size=1;
697: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
698: } else {
699: if (numSections == 1) {
700: document.$formname.$sec_element.multiple=false;
701: document.$formname.$sec_element.size=1;
702: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
703: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
704: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
705: } else {
706: for (var i=0; i<numSections; i++) {
707: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
708: }
709: document.$formname.$sec_element.multiple=true
710: if (numSections < 3) {
711: document.$formname.$sec_element.size=numSections;
712: } else {
713: document.$formname.$sec_element.size=3;
714: }
715: document.$formname.$sec_element.options[0].selected = false
716: }
717: }
1.91 www 718: }
1.905 raeburn 719:
720: function setRole(crstype) {
1.468 raeburn 721: |;
1.905 raeburn 722: if ($role_element eq '') {
723: $setsections .= ' return;
724: }
725: ';
726: } else {
727: $setsections .= qq|
728: var elementLength = document.$formname.$role_element.length;
729: var allroles = Array($rolestr);
730: var courserolenames = Array($courserolestr);
731: var communityrolenames = Array($communityrolestr);
732: if (elementLength != undefined) {
733: if (document.$formname.$role_element.options[5].value == 'cc') {
734: if (crstype == 'Course') {
735: return;
736: } else {
737: allroles[5] = 'co';
738: for (var i=0; i<6; i++) {
739: document.$formname.$role_element.options[i].value = allroles[i];
740: document.$formname.$role_element.options[i].text = communityrolenames[i];
741: }
742: }
743: } else {
744: if (crstype == 'Community') {
745: return;
746: } else {
747: allroles[5] = 'cc';
748: for (var i=0; i<6; i++) {
749: document.$formname.$role_element.options[i].value = allroles[i];
750: document.$formname.$role_element.options[i].text = courserolenames[i];
751: }
752: }
753: }
754: }
755: return;
756: }
757: |;
758: }
1.468 raeburn 759: return $setsections;
760: }
761:
1.91 www 762: sub selectcourse_link {
1.377 raeburn 763: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.871 raeburn 764: my $linktext = &mt('Select Course');
765: if ($selecttype eq 'Community') {
766: $linktext = &mt('Select Community');
1.906 raeburn 767: } elsif ($selecttype eq 'Course/Community') {
768: $linktext = &mt('Select Course/Community');
769: $selecttype = 'Course';
1.871 raeburn 770: }
1.787 bisitz 771: return '<span class="LC_nobreak">'
772: ."<a href='"
773: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
774: .'","'.$udomele.'","'.$desc.'","'.$extra_element
775: .'","'.$multflag.'","'.$selecttype.'");'
1.871 raeburn 776: ."'>".$linktext.'</a>'
1.787 bisitz 777: .'</span>';
1.74 www 778: }
1.42 matthew 779:
1.653 raeburn 780: sub selectauthor_link {
781: my ($form,$udom)=@_;
782: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
783: &mt('Select Author').'</a>';
784: }
785:
1.876 raeburn 786: sub selectuser_link {
1.881 raeburn 787: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 788: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 789: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 790: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 791: ');">'.$linktext.'</a>';
1.876 raeburn 792: }
793:
1.273 raeburn 794: sub check_uncheck_jscript {
795: my $jscript = <<"ENDSCRT";
796: function checkAll(field) {
797: if (field.length > 0) {
798: for (i = 0; i < field.length; i++) {
799: field[i].checked = true ;
800: }
801: } else {
802: field.checked = true
803: }
804: }
805:
806: function uncheckAll(field) {
807: if (field.length > 0) {
808: for (i = 0; i < field.length; i++) {
809: field[i].checked = false ;
1.543 albertel 810: }
811: } else {
1.273 raeburn 812: field.checked = false ;
813: }
814: }
815: ENDSCRT
816: return $jscript;
817: }
818:
1.656 www 819: sub select_timezone {
1.659 raeburn 820: my ($name,$selected,$onchange,$includeempty)=@_;
821: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
822: if ($includeempty) {
823: $output .= '<option value=""';
824: if (($selected eq '') || ($selected eq 'local')) {
825: $output .= ' selected="selected" ';
826: }
827: $output .= '> </option>';
828: }
1.657 raeburn 829: my @timezones = DateTime::TimeZone->all_names;
830: foreach my $tzone (@timezones) {
831: $output.= '<option value="'.$tzone.'"';
832: if ($tzone eq $selected) {
833: $output.=' selected="selected"';
834: }
835: $output.=">$tzone</option>\n";
1.656 www 836: }
837: $output.="</select>";
838: return $output;
839: }
1.273 raeburn 840:
1.687 raeburn 841: sub select_datelocale {
842: my ($name,$selected,$onchange,$includeempty)=@_;
843: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
844: if ($includeempty) {
845: $output .= '<option value=""';
846: if ($selected eq '') {
847: $output .= ' selected="selected" ';
848: }
849: $output .= '> </option>';
850: }
851: my (@possibles,%locale_names);
852: my @locales = DateTime::Locale::Catalog::Locales;
853: foreach my $locale (@locales) {
854: if (ref($locale) eq 'HASH') {
855: my $id = $locale->{'id'};
856: if ($id ne '') {
857: my $en_terr = $locale->{'en_territory'};
858: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 859: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 860: if (grep(/^en$/,@languages) || !@languages) {
861: if ($en_terr ne '') {
862: $locale_names{$id} = '('.$en_terr.')';
863: } elsif ($native_terr ne '') {
864: $locale_names{$id} = $native_terr;
865: }
866: } else {
867: if ($native_terr ne '') {
868: $locale_names{$id} = $native_terr.' ';
869: } elsif ($en_terr ne '') {
870: $locale_names{$id} = '('.$en_terr.')';
871: }
872: }
873: push (@possibles,$id);
874: }
875: }
876: }
877: foreach my $item (sort(@possibles)) {
878: $output.= '<option value="'.$item.'"';
879: if ($item eq $selected) {
880: $output.=' selected="selected"';
881: }
882: $output.=">$item";
883: if ($locale_names{$item} ne '') {
884: $output.=" $locale_names{$item}</option>\n";
885: }
886: $output.="</option>\n";
887: }
888: $output.="</select>";
889: return $output;
890: }
891:
1.792 raeburn 892: sub select_language {
893: my ($name,$selected,$includeempty) = @_;
894: my %langchoices;
895: if ($includeempty) {
896: %langchoices = ('' => 'No language preference');
897: }
898: foreach my $id (&languageids()) {
899: my $code = &supportedlanguagecode($id);
900: if ($code) {
901: $langchoices{$code} = &plainlanguagedescription($id);
902: }
903: }
904: return &select_form($selected,$name,%langchoices);
905: }
906:
1.42 matthew 907: =pod
1.36 matthew 908:
1.648 raeburn 909: =item * &linked_select_forms(...)
1.36 matthew 910:
911: linked_select_forms returns a string containing a <script></script> block
912: and html for two <select> menus. The select menus will be linked in that
913: changing the value of the first menu will result in new values being placed
914: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 915: order unless a defined order is provided.
1.36 matthew 916:
917: linked_select_forms takes the following ordered inputs:
918:
919: =over 4
920:
1.112 bowersj2 921: =item * $formname, the name of the <form> tag
1.36 matthew 922:
1.112 bowersj2 923: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 924:
1.112 bowersj2 925: =item * $firstdefault, the default value for the first menu
1.36 matthew 926:
1.112 bowersj2 927: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 928:
1.112 bowersj2 929: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 930:
1.112 bowersj2 931: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 932:
1.609 raeburn 933: =item * $menuorder, the order of values in the first menu
934:
1.41 ng 935: =back
936:
1.36 matthew 937: Below is an example of such a hash. Only the 'text', 'default', and
938: 'select2' keys must appear as stated. keys(%menu) are the possible
939: values for the first select menu. The text that coincides with the
1.41 ng 940: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 941: and text for the second menu are given in the hash pointed to by
942: $menu{$choice1}->{'select2'}.
943:
1.112 bowersj2 944: my %menu = ( A1 => { text =>"Choice A1" ,
945: default => "B3",
946: select2 => {
947: B1 => "Choice B1",
948: B2 => "Choice B2",
949: B3 => "Choice B3",
950: B4 => "Choice B4"
1.609 raeburn 951: },
952: order => ['B4','B3','B1','B2'],
1.112 bowersj2 953: },
954: A2 => { text =>"Choice A2" ,
955: default => "C2",
956: select2 => {
957: C1 => "Choice C1",
958: C2 => "Choice C2",
959: C3 => "Choice C3"
1.609 raeburn 960: },
961: order => ['C2','C1','C3'],
1.112 bowersj2 962: },
963: A3 => { text =>"Choice A3" ,
964: default => "D6",
965: select2 => {
966: D1 => "Choice D1",
967: D2 => "Choice D2",
968: D3 => "Choice D3",
969: D4 => "Choice D4",
970: D5 => "Choice D5",
971: D6 => "Choice D6",
972: D7 => "Choice D7"
1.609 raeburn 973: },
974: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 975: }
976: );
1.36 matthew 977:
978: =cut
979:
980: sub linked_select_forms {
981: my ($formname,
982: $middletext,
983: $firstdefault,
984: $firstselectname,
985: $secondselectname,
1.609 raeburn 986: $hashref,
987: $menuorder,
1.36 matthew 988: ) = @_;
989: my $second = "document.$formname.$secondselectname";
990: my $first = "document.$formname.$firstselectname";
991: # output the javascript to do the changing
992: my $result = '';
1.776 bisitz 993: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 994: $result.="// <![CDATA[\n";
1.36 matthew 995: $result.="var select2data = new Object();\n";
996: $" = '","';
997: my $debug = '';
998: foreach my $s1 (sort(keys(%$hashref))) {
999: $result.="select2data.d_$s1 = new Object();\n";
1000: $result.="select2data.d_$s1.def = new String('".
1001: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1002: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1003: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1004: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1005: @s2values = @{$hashref->{$s1}->{'order'}};
1006: }
1.36 matthew 1007: $result.="\"@s2values\");\n";
1008: $result.="select2data.d_$s1.texts = new Array(";
1009: my @s2texts;
1010: foreach my $value (@s2values) {
1011: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1012: }
1013: $result.="\"@s2texts\");\n";
1014: }
1015: $"=' ';
1016: $result.= <<"END";
1017:
1018: function select1_changed() {
1019: // Determine new choice
1020: var newvalue = "d_" + $first.value;
1021: // update select2
1022: var values = select2data[newvalue].values;
1023: var texts = select2data[newvalue].texts;
1024: var select2def = select2data[newvalue].def;
1025: var i;
1026: // out with the old
1027: for (i = 0; i < $second.options.length; i++) {
1028: $second.options[i] = null;
1029: }
1030: // in with the nuclear
1031: for (i=0;i<values.length; i++) {
1032: $second.options[i] = new Option(values[i]);
1.143 matthew 1033: $second.options[i].value = values[i];
1.36 matthew 1034: $second.options[i].text = texts[i];
1035: if (values[i] == select2def) {
1036: $second.options[i].selected = true;
1037: }
1038: }
1039: }
1.824 bisitz 1040: // ]]>
1.36 matthew 1041: </script>
1042: END
1043: # output the initial values for the selection lists
1044: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1045: my @order = sort(keys(%{$hashref}));
1046: if (ref($menuorder) eq 'ARRAY') {
1047: @order = @{$menuorder};
1048: }
1049: foreach my $value (@order) {
1.36 matthew 1050: $result.=" <option value=\"$value\" ";
1.253 albertel 1051: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1052: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1053: }
1054: $result .= "</select>\n";
1055: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1056: $result .= $middletext;
1057: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1058: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1059:
1060: my @secondorder = sort(keys(%select2));
1061: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1062: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1063: }
1064: foreach my $value (@secondorder) {
1.36 matthew 1065: $result.=" <option value=\"$value\" ";
1.253 albertel 1066: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1067: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1068: }
1069: $result .= "</select>\n";
1070: # return $debug;
1071: return $result;
1072: } # end of sub linked_select_forms {
1073:
1.45 matthew 1074: =pod
1.44 bowersj2 1075:
1.648 raeburn 1076: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 1077:
1.112 bowersj2 1078: Returns a string corresponding to an HTML link to the given help
1079: $topic, where $topic corresponds to the name of a .tex file in
1080: /home/httpd/html/adm/help/tex, with underscores replaced by
1081: spaces.
1082:
1083: $text will optionally be linked to the same topic, allowing you to
1084: link text in addition to the graphic. If you do not want to link
1085: text, but wish to specify one of the later parameters, pass an
1086: empty string.
1087:
1088: $stayOnPage is a value that will be interpreted as a boolean. If true,
1089: the link will not open a new window. If false, the link will open
1090: a new window using Javascript. (Default is false.)
1091:
1092: $width and $height are optional numerical parameters that will
1093: override the width and height of the popped up window, which may
1094: be useful for certain help topics with big pictures included.
1.44 bowersj2 1095:
1096: =cut
1097:
1098: sub help_open_topic {
1.48 bowersj2 1099: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1100: $text = "" if (not defined $text);
1.44 bowersj2 1101: $stayOnPage = 0 if (not defined $stayOnPage);
1102: $width = 350 if (not defined $width);
1103: $height = 400 if (not defined $height);
1104: my $filename = $topic;
1105: $filename =~ s/ /_/g;
1106:
1.48 bowersj2 1107: my $template = "";
1108: my $link;
1.572 banghart 1109:
1.159 www 1110: $topic=~s/\W/\_/g;
1.44 bowersj2 1111:
1.572 banghart 1112: if (!$stayOnPage) {
1.72 bowersj2 1113: $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 1114: } else {
1.48 bowersj2 1115: $link = "/adm/help/${filename}.hlp";
1116: }
1117:
1118: # Add the text
1.755 neumanie 1119: if ($text ne "") {
1.763 bisitz 1120: $template.='<span class="LC_help_open_topic">'
1121: .'<a target="_top" href="'.$link.'">'
1122: .$text.'</a>';
1.48 bowersj2 1123: }
1124:
1.763 bisitz 1125: # (Always) Add the graphic
1.179 matthew 1126: my $title = &mt('Online Help');
1.667 raeburn 1127: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 1128: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1129: .'<img src="'.$helpicon.'" border="0"'
1130: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 1131: .' title="'.$title.'"'
1.763 bisitz 1132: .' /></a>';
1133: if ($text ne "") {
1134: $template.='</span>';
1135: }
1.44 bowersj2 1136: return $template;
1137:
1.106 bowersj2 1138: }
1139:
1140: # This is a quicky function for Latex cheatsheet editing, since it
1141: # appears in at least four places
1142: sub helpLatexCheatsheet {
1.732 raeburn 1143: my ($topic,$text,$not_author) = @_;
1144: my $out;
1.106 bowersj2 1145: my $addOther = '';
1.732 raeburn 1146: if ($topic) {
1.763 bisitz 1147: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1148: undef, undef, 600).
1149: '</span> ';
1150: }
1151: $out = '<span>' # Start cheatsheet
1152: .$addOther
1153: .'<span>'
1154: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1155: undef,undef,600)
1156: .'</span> <span>'
1157: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1158: undef,undef,600)
1159: .'</span>';
1.732 raeburn 1160: unless ($not_author) {
1.763 bisitz 1161: $out .= ' <span>'
1162: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1163: undef,undef,600)
1164: .'</span>';
1.732 raeburn 1165: }
1.763 bisitz 1166: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1167: return $out;
1.172 www 1168: }
1169:
1.430 albertel 1170: sub general_help {
1171: my $helptopic='Student_Intro';
1172: if ($env{'request.role'}=~/^(ca|au)/) {
1173: $helptopic='Authoring_Intro';
1.907 ! raeburn 1174: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1175: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1176: } elsif ($env{'request.role'}=~/^dc/) {
1177: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1178: }
1179: return $helptopic;
1180: }
1181:
1182: sub update_help_link {
1183: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1184: my $origurl = $ENV{'REQUEST_URI'};
1185: $origurl=~s|^/~|/priv/|;
1186: my $timestamp = time;
1187: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1188: $$datum = &escape($$datum);
1189: }
1190:
1191: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1192: my $output .= <<"ENDOUTPUT";
1193: <script type="text/javascript">
1.824 bisitz 1194: // <![CDATA[
1.430 albertel 1195: banner_link = '$banner_link';
1.824 bisitz 1196: // ]]>
1.430 albertel 1197: </script>
1198: ENDOUTPUT
1199: return $output;
1200: }
1201:
1202: # now just updates the help link and generates a blue icon
1.193 raeburn 1203: sub help_open_menu {
1.430 albertel 1204: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1205: = @_;
1.430 albertel 1206: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1207: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1208: # if environment.remote is on (using remote control UI)
1.798 tempelho 1209: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1210: $stayOnPage=1;
1.430 albertel 1211: }
1212: my $output;
1213: if ($component_help) {
1214: if (!$text) {
1215: $output=&help_open_topic($component_help,undef,$stayOnPage,
1216: $width,$height);
1217: } else {
1218: my $help_text;
1219: $help_text=&unescape($topic);
1220: $output='<table><tr><td>'.
1221: &help_open_topic($component_help,$help_text,$stayOnPage,
1222: $width,$height).'</td></tr></table>';
1223: }
1224: }
1225: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1226: return $output.$banner_link;
1227: }
1228:
1229: sub top_nav_help {
1230: my ($text) = @_;
1.436 albertel 1231: $text = &mt($text);
1.572 banghart 1232: my $stay_on_page =
1.798 tempelho 1233: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1234: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1235: : "javascript:helpMenu('open')";
1.572 banghart 1236: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1237:
1.201 raeburn 1238: my $title = &mt('Get help');
1.436 albertel 1239:
1240: return <<"END";
1241: $banner_link
1242: <a href="$link" title="$title">$text</a>
1243: END
1244: }
1245:
1246: sub help_menu_js {
1247: my ($text) = @_;
1248:
1249: my $stayOnPage =
1.798 tempelho 1250: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1251:
1252: my $width = 620;
1253: my $height = 600;
1.430 albertel 1254: my $helptopic=&general_help();
1255: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1256: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1257: my $start_page =
1258: &Apache::loncommon::start_page('Help Menu', undef,
1259: {'frameset' => 1,
1260: 'js_ready' => 1,
1261: 'add_entries' => {
1262: 'border' => '0',
1.579 raeburn 1263: 'rows' => "110,*",},});
1.331 albertel 1264: my $end_page =
1265: &Apache::loncommon::end_page({'frameset' => 1,
1266: 'js_ready' => 1,});
1267:
1.436 albertel 1268: my $template .= <<"ENDTEMPLATE";
1269: <script type="text/javascript">
1.877 bisitz 1270: // <![CDATA[
1.253 albertel 1271: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1272: var banner_link = '';
1.243 raeburn 1273: function helpMenu(target) {
1274: var caller = this;
1275: if (target == 'open') {
1276: var newWindow = null;
1277: try {
1.262 albertel 1278: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1279: }
1280: catch(error) {
1281: writeHelp(caller);
1282: return;
1283: }
1284: if (newWindow) {
1285: caller = newWindow;
1286: }
1.193 raeburn 1287: }
1.243 raeburn 1288: writeHelp(caller);
1289: return;
1290: }
1291: function writeHelp(caller) {
1.430 albertel 1292: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1293: caller.document.close()
1294: caller.focus()
1.193 raeburn 1295: }
1.877 bisitz 1296: // END LON-CAPA Internal -->
1.253 albertel 1297: // ]]>
1.436 albertel 1298: </script>
1.193 raeburn 1299: ENDTEMPLATE
1300: return $template;
1301: }
1302:
1.172 www 1303: sub help_open_bug {
1304: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1305: unless ($env{'user.adv'}) { return ''; }
1.172 www 1306: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1307: $text = "" if (not defined $text);
1308: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1309: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1310: $stayOnPage=1;
1311: }
1.184 albertel 1312: $width = 600 if (not defined $width);
1313: $height = 600 if (not defined $height);
1.172 www 1314:
1315: $topic=~s/\W+/\+/g;
1316: my $link='';
1317: my $template='';
1.379 albertel 1318: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1319: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1320: if (!$stayOnPage)
1321: {
1322: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1323: }
1324: else
1325: {
1326: $link = $url;
1327: }
1328: # Add the text
1329: if ($text ne "")
1330: {
1331: $template .=
1332: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1333: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1334: }
1335:
1336: # Add the graphic
1.179 matthew 1337: my $title = &mt('Report a Bug');
1.215 albertel 1338: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1339: $template .= <<"ENDTEMPLATE";
1.436 albertel 1340: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1341: ENDTEMPLATE
1342: if ($text ne '') { $template.='</td></tr></table>' };
1343: return $template;
1344:
1345: }
1346:
1347: sub help_open_faq {
1348: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1349: unless ($env{'user.adv'}) { return ''; }
1.172 www 1350: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1351: $text = "" if (not defined $text);
1352: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1353: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1354: $stayOnPage=1;
1355: }
1356: $width = 350 if (not defined $width);
1357: $height = 400 if (not defined $height);
1358:
1359: $topic=~s/\W+/\+/g;
1360: my $link='';
1361: my $template='';
1362: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1363: if (!$stayOnPage)
1364: {
1365: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1366: }
1367: else
1368: {
1369: $link = $url;
1370: }
1371:
1372: # Add the text
1373: if ($text ne "")
1374: {
1375: $template .=
1.173 www 1376: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1377: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1378: }
1379:
1380: # Add the graphic
1.179 matthew 1381: my $title = &mt('View the FAQ');
1.215 albertel 1382: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1383: $template .= <<"ENDTEMPLATE";
1.436 albertel 1384: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1385: ENDTEMPLATE
1386: if ($text ne '') { $template.='</td></tr></table>' };
1387: return $template;
1388:
1.44 bowersj2 1389: }
1.37 matthew 1390:
1.180 matthew 1391: ###############################################################
1392: ###############################################################
1393:
1.45 matthew 1394: =pod
1395:
1.648 raeburn 1396: =item * &change_content_javascript():
1.256 matthew 1397:
1398: This and the next function allow you to create small sections of an
1399: otherwise static HTML page that you can update on the fly with
1400: Javascript, even in Netscape 4.
1401:
1402: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1403: must be written to the HTML page once. It will prove the Javascript
1404: function "change(name, content)". Calling the change function with the
1405: name of the section
1406: you want to update, matching the name passed to C<changable_area>, and
1407: the new content you want to put in there, will put the content into
1408: that area.
1409:
1410: B<Note>: Netscape 4 only reserves enough space for the changable area
1411: to contain room for the original contents. You need to "make space"
1412: for whatever changes you wish to make, and be B<sure> to check your
1413: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1414: it's adequate for updating a one-line status display, but little more.
1415: This script will set the space to 100% width, so you only need to
1416: worry about height in Netscape 4.
1417:
1418: Modern browsers are much less limiting, and if you can commit to the
1419: user not using Netscape 4, this feature may be used freely with
1420: pretty much any HTML.
1421:
1422: =cut
1423:
1424: sub change_content_javascript {
1425: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1426: if ($env{'browser.type'} eq 'netscape' &&
1427: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1428: return (<<NETSCAPE4);
1429: function change(name, content) {
1430: doc = document.layers[name+"___escape"].layers[0].document;
1431: doc.open();
1432: doc.write(content);
1433: doc.close();
1434: }
1435: NETSCAPE4
1436: } else {
1437: # Otherwise, we need to use semi-standards-compliant code
1438: # (technically, "innerHTML" isn't standard but the equivalent
1439: # is really scary, and every useful browser supports it
1440: return (<<DOMBASED);
1441: function change(name, content) {
1442: element = document.getElementById(name);
1443: element.innerHTML = content;
1444: }
1445: DOMBASED
1446: }
1447: }
1448:
1449: =pod
1450:
1.648 raeburn 1451: =item * &changable_area($name,$origContent):
1.256 matthew 1452:
1453: This provides a "changable area" that can be modified on the fly via
1454: the Javascript code provided in C<change_content_javascript>. $name is
1455: the name you will use to reference the area later; do not repeat the
1456: same name on a given HTML page more then once. $origContent is what
1457: the area will originally contain, which can be left blank.
1458:
1459: =cut
1460:
1461: sub changable_area {
1462: my ($name, $origContent) = @_;
1463:
1.258 albertel 1464: if ($env{'browser.type'} eq 'netscape' &&
1465: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1466: # If this is netscape 4, we need to use the Layer tag
1467: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1468: } else {
1469: return "<span id='$name'>$origContent</span>";
1470: }
1471: }
1472:
1473: =pod
1474:
1.648 raeburn 1475: =item * &viewport_geometry_js
1.590 raeburn 1476:
1477: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1478:
1479: =cut
1480:
1481:
1482: sub viewport_geometry_js {
1483: return <<"GEOMETRY";
1484: var Geometry = {};
1485: function init_geometry() {
1486: if (Geometry.init) { return };
1487: Geometry.init=1;
1488: if (window.innerHeight) {
1489: Geometry.getViewportHeight = function() { return window.innerHeight; };
1490: Geometry.getViewportWidth = function() { return window.innerWidth; };
1491: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1492: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1493: }
1494: else if (document.documentElement && document.documentElement.clientHeight) {
1495: Geometry.getViewportHeight =
1496: function() { return document.documentElement.clientHeight; };
1497: Geometry.getViewportWidth =
1498: function() { return document.documentElement.clientWidth; };
1499:
1500: Geometry.getHorizontalScroll =
1501: function() { return document.documentElement.scrollLeft; };
1502: Geometry.getVerticalScroll =
1503: function() { return document.documentElement.scrollTop; };
1504: }
1505: else if (document.body.clientHeight) {
1506: Geometry.getViewportHeight =
1507: function() { return document.body.clientHeight; };
1508: Geometry.getViewportWidth =
1509: function() { return document.body.clientWidth; };
1510: Geometry.getHorizontalScroll =
1511: function() { return document.body.scrollLeft; };
1512: Geometry.getVerticalScroll =
1513: function() { return document.body.scrollTop; };
1514: }
1515: }
1516:
1517: GEOMETRY
1518: }
1519:
1520: =pod
1521:
1.648 raeburn 1522: =item * &viewport_size_js()
1.590 raeburn 1523:
1524: 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.
1525:
1526: =cut
1527:
1528: sub viewport_size_js {
1529: my $geometry = &viewport_geometry_js();
1530: return <<"DIMS";
1531:
1532: $geometry
1533:
1534: function getViewportDims(width,height) {
1535: init_geometry();
1536: width.value = Geometry.getViewportWidth();
1537: height.value = Geometry.getViewportHeight();
1538: return;
1539: }
1540:
1541: DIMS
1542: }
1543:
1544: =pod
1545:
1.648 raeburn 1546: =item * &resize_textarea_js()
1.565 albertel 1547:
1548: emits the needed javascript to resize a textarea to be as big as possible
1549:
1550: creates a function resize_textrea that takes two IDs first should be
1551: the id of the element to resize, second should be the id of a div that
1552: surrounds everything that comes after the textarea, this routine needs
1553: to be attached to the <body> for the onload and onresize events.
1554:
1.648 raeburn 1555: =back
1.565 albertel 1556:
1557: =cut
1558:
1559: sub resize_textarea_js {
1.590 raeburn 1560: my $geometry = &viewport_geometry_js();
1.565 albertel 1561: return <<"RESIZE";
1562: <script type="text/javascript">
1.824 bisitz 1563: // <![CDATA[
1.590 raeburn 1564: $geometry
1.565 albertel 1565:
1.588 albertel 1566: function getX(element) {
1567: var x = 0;
1568: while (element) {
1569: x += element.offsetLeft;
1570: element = element.offsetParent;
1571: }
1572: return x;
1573: }
1574: function getY(element) {
1575: var y = 0;
1576: while (element) {
1577: y += element.offsetTop;
1578: element = element.offsetParent;
1579: }
1580: return y;
1581: }
1582:
1583:
1.565 albertel 1584: function resize_textarea(textarea_id,bottom_id) {
1585: init_geometry();
1586: var textarea = document.getElementById(textarea_id);
1587: //alert(textarea);
1588:
1.588 albertel 1589: var textarea_top = getY(textarea);
1.565 albertel 1590: var textarea_height = textarea.offsetHeight;
1591: var bottom = document.getElementById(bottom_id);
1.588 albertel 1592: var bottom_top = getY(bottom);
1.565 albertel 1593: var bottom_height = bottom.offsetHeight;
1594: var window_height = Geometry.getViewportHeight();
1.588 albertel 1595: var fudge = 23;
1.565 albertel 1596: var new_height = window_height-fudge-textarea_top-bottom_height;
1597: if (new_height < 300) {
1598: new_height = 300;
1599: }
1600: textarea.style.height=new_height+'px';
1601: }
1.824 bisitz 1602: // ]]>
1.565 albertel 1603: </script>
1604: RESIZE
1605:
1606: }
1607:
1608: =pod
1609:
1.256 matthew 1610: =head1 Excel and CSV file utility routines
1611:
1612: =over 4
1613:
1614: =cut
1615:
1616: ###############################################################
1617: ###############################################################
1618:
1619: =pod
1620:
1.648 raeburn 1621: =item * &csv_translate($text)
1.37 matthew 1622:
1.185 www 1623: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1624: format.
1625:
1626: =cut
1627:
1.180 matthew 1628: ###############################################################
1629: ###############################################################
1.37 matthew 1630: sub csv_translate {
1631: my $text = shift;
1632: $text =~ s/\"/\"\"/g;
1.209 albertel 1633: $text =~ s/\n/ /g;
1.37 matthew 1634: return $text;
1635: }
1.180 matthew 1636:
1637: ###############################################################
1638: ###############################################################
1639:
1640: =pod
1641:
1.648 raeburn 1642: =item * &define_excel_formats()
1.180 matthew 1643:
1644: Define some commonly used Excel cell formats.
1645:
1646: Currently supported formats:
1647:
1648: =over 4
1649:
1650: =item header
1651:
1652: =item bold
1653:
1654: =item h1
1655:
1656: =item h2
1657:
1658: =item h3
1659:
1.256 matthew 1660: =item h4
1661:
1662: =item i
1663:
1.180 matthew 1664: =item date
1665:
1666: =back
1667:
1668: Inputs: $workbook
1669:
1670: Returns: $format, a hash reference.
1671:
1672: =cut
1673:
1674: ###############################################################
1675: ###############################################################
1676: sub define_excel_formats {
1677: my ($workbook) = @_;
1678: my $format;
1679: $format->{'header'} = $workbook->add_format(bold => 1,
1680: bottom => 1,
1681: align => 'center');
1682: $format->{'bold'} = $workbook->add_format(bold=>1);
1683: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1684: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1685: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1686: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1687: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1688: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1689: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1690: return $format;
1691: }
1692:
1693: ###############################################################
1694: ###############################################################
1.113 bowersj2 1695:
1696: =pod
1697:
1.648 raeburn 1698: =item * &create_workbook()
1.255 matthew 1699:
1700: Create an Excel worksheet. If it fails, output message on the
1701: request object and return undefs.
1702:
1703: Inputs: Apache request object
1704:
1705: Returns (undef) on failure,
1706: Excel worksheet object, scalar with filename, and formats
1707: from &Apache::loncommon::define_excel_formats on success
1708:
1709: =cut
1710:
1711: ###############################################################
1712: ###############################################################
1713: sub create_workbook {
1714: my ($r) = @_;
1715: #
1716: # Create the excel spreadsheet
1717: my $filename = '/prtspool/'.
1.258 albertel 1718: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1719: time.'_'.rand(1000000000).'.xls';
1720: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1721: if (! defined($workbook)) {
1722: $r->log_error("Error creating excel spreadsheet $filename: $!");
1723: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1724: "This error has been logged. ".
1725: "Please alert your LON-CAPA administrator").
1726: '</p>');
1727: return (undef);
1728: }
1729: #
1730: $workbook->set_tempdir('/home/httpd/perl/tmp');
1731: #
1732: my $format = &Apache::loncommon::define_excel_formats($workbook);
1733: return ($workbook,$filename,$format);
1734: }
1735:
1736: ###############################################################
1737: ###############################################################
1738:
1739: =pod
1740:
1.648 raeburn 1741: =item * &create_text_file()
1.113 bowersj2 1742:
1.542 raeburn 1743: Create a file to write to and eventually make available to the user.
1.256 matthew 1744: If file creation fails, outputs an error message on the request object and
1745: return undefs.
1.113 bowersj2 1746:
1.256 matthew 1747: Inputs: Apache request object, and file suffix
1.113 bowersj2 1748:
1.256 matthew 1749: Returns (undef) on failure,
1750: Filehandle and filename on success.
1.113 bowersj2 1751:
1752: =cut
1753:
1.256 matthew 1754: ###############################################################
1755: ###############################################################
1756: sub create_text_file {
1757: my ($r,$suffix) = @_;
1758: if (! defined($suffix)) { $suffix = 'txt'; };
1759: my $fh;
1760: my $filename = '/prtspool/'.
1.258 albertel 1761: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1762: time.'_'.rand(1000000000).'.'.$suffix;
1763: $fh = Apache::File->new('>/home/httpd'.$filename);
1764: if (! defined($fh)) {
1765: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1766: $r->print(&mt('Problems occurred in creating the output file. '
1767: .'This error has been logged. '
1768: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1769: }
1.256 matthew 1770: return ($fh,$filename)
1.113 bowersj2 1771: }
1772:
1773:
1.256 matthew 1774: =pod
1.113 bowersj2 1775:
1776: =back
1777:
1778: =cut
1.37 matthew 1779:
1780: ###############################################################
1.33 matthew 1781: ## Home server <option> list generating code ##
1782: ###############################################################
1.35 matthew 1783:
1.169 www 1784: # ------------------------------------------
1785:
1786: sub domain_select {
1787: my ($name,$value,$multiple)=@_;
1788: my %domains=map {
1.514 albertel 1789: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1790: } &Apache::lonnet::all_domains();
1.169 www 1791: if ($multiple) {
1792: $domains{''}=&mt('Any domain');
1.550 albertel 1793: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1794: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1795: } else {
1.550 albertel 1796: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1797: return &select_form($name,$value,%domains);
1798: }
1799: }
1800:
1.282 albertel 1801: #-------------------------------------------
1802:
1803: =pod
1804:
1.519 raeburn 1805: =head1 Routines for form select boxes
1806:
1807: =over 4
1808:
1.648 raeburn 1809: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1810:
1811: Returns a string containing a <select> element int multiple mode
1812:
1813:
1814: Args:
1815: $name - name of the <select> element
1.506 raeburn 1816: $value - scalar or array ref of values that should already be selected
1.282 albertel 1817: $size - number of rows long the select element is
1.283 albertel 1818: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1819: (shown text should already have been &mt())
1.506 raeburn 1820: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1821:
1.282 albertel 1822: =cut
1823:
1824: #-------------------------------------------
1.169 www 1825: sub multiple_select_form {
1.284 albertel 1826: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1827: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1828: my $output='';
1.191 matthew 1829: if (! defined($size)) {
1830: $size = 4;
1.283 albertel 1831: if (scalar(keys(%$hash))<4) {
1832: $size = scalar(keys(%$hash));
1.191 matthew 1833: }
1834: }
1.734 bisitz 1835: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1836: my @order;
1.506 raeburn 1837: if (ref($order) eq 'ARRAY') {
1838: @order = @{$order};
1839: } else {
1840: @order = sort(keys(%$hash));
1.501 banghart 1841: }
1842: if (exists($$hash{'select_form_order'})) {
1843: @order = @{$$hash{'select_form_order'}};
1844: }
1845:
1.284 albertel 1846: foreach my $key (@order) {
1.356 albertel 1847: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1848: $output.='selected="selected" ' if ($selected{$key});
1849: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1850: }
1851: $output.="</select>\n";
1852: return $output;
1853: }
1854:
1.88 www 1855: #-------------------------------------------
1856:
1857: =pod
1858:
1.648 raeburn 1859: =item * &select_form($defdom,$name,%hash)
1.88 www 1860:
1861: Returns a string containing a <select name='$name' size='1'> form to
1862: allow a user to select options from a hash option_name => displayed text.
1863: See lonrights.pm for an example invocation and use.
1864:
1865: =cut
1866:
1867: #-------------------------------------------
1868: sub select_form {
1869: my ($def,$name,%hash) = @_;
1870: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1871: my @keys;
1872: if (exists($hash{'select_form_order'})) {
1873: @keys=@{$hash{'select_form_order'}};
1874: } else {
1875: @keys=sort(keys(%hash));
1876: }
1.356 albertel 1877: foreach my $key (@keys) {
1878: $selectform.=
1879: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1880: ($key eq $def ? 'selected="selected" ' : '').
1881: ">".&mt($hash{$key})."</option>\n";
1.88 www 1882: }
1883: $selectform.="</select>";
1884: return $selectform;
1885: }
1886:
1.475 www 1887: # For display filters
1888:
1889: sub display_filter {
1890: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1891: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1892: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1893: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1894: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1895: '</label></span> <span class="LC_nobreak">'.
1.475 www 1896: &mt('Filter [_1]',
1.477 www 1897: &select_form($env{'form.displayfilter'},
1898: 'displayfilter',
1899: ('currentfolder' => 'Current folder/page',
1900: 'containing' => 'Containing phrase',
1901: 'none' => 'None'))).
1.714 bisitz 1902: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1903: }
1904:
1.167 www 1905: sub gradeleveldescription {
1906: my $gradelevel=shift;
1907: my %gradelevels=(0 => 'Not specified',
1908: 1 => 'Grade 1',
1909: 2 => 'Grade 2',
1910: 3 => 'Grade 3',
1911: 4 => 'Grade 4',
1912: 5 => 'Grade 5',
1913: 6 => 'Grade 6',
1914: 7 => 'Grade 7',
1915: 8 => 'Grade 8',
1916: 9 => 'Grade 9',
1917: 10 => 'Grade 10',
1918: 11 => 'Grade 11',
1919: 12 => 'Grade 12',
1920: 13 => 'Grade 13',
1921: 14 => '100 Level',
1922: 15 => '200 Level',
1923: 16 => '300 Level',
1924: 17 => '400 Level',
1925: 18 => 'Graduate Level');
1926: return &mt($gradelevels{$gradelevel});
1927: }
1928:
1.163 www 1929: sub select_level_form {
1930: my ($deflevel,$name)=@_;
1931: unless ($deflevel) { $deflevel=0; }
1.167 www 1932: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1933: for (my $i=0; $i<=18; $i++) {
1934: $selectform.="<option value=\"$i\" ".
1.253 albertel 1935: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1936: ">".&gradeleveldescription($i)."</option>\n";
1937: }
1938: $selectform.="</select>";
1939: return $selectform;
1.163 www 1940: }
1.167 www 1941:
1.35 matthew 1942: #-------------------------------------------
1943:
1.45 matthew 1944: =pod
1945:
1.873 raeburn 1946: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35 matthew 1947:
1948: Returns a string containing a <select name='$name' size='1'> form to
1949: allow a user to select the domain to preform an operation in.
1950: See loncreateuser.pm for an example invocation and use.
1951:
1.90 www 1952: If the $includeempty flag is set, it also includes an empty choice ("no domain
1953: selected");
1954:
1.743 raeburn 1955: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1956:
1.872 raeburn 1957: 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 1958:
1.35 matthew 1959: =cut
1960:
1961: #-------------------------------------------
1.34 matthew 1962: sub select_dom_form {
1.872 raeburn 1963: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
1964: if ($onchange) {
1.874 raeburn 1965: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1966: }
1.550 albertel 1967: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1968: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1969: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1970: foreach my $dom (@domains) {
1971: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1972: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1973: if ($showdomdesc) {
1974: if ($dom ne '') {
1975: my $domdesc = &Apache::lonnet::domain($dom,'description');
1976: if ($domdesc ne '') {
1977: $selectdomain .= ' ('.$domdesc.')';
1978: }
1979: }
1980: }
1981: $selectdomain .= "</option>\n";
1.34 matthew 1982: }
1983: $selectdomain.="</select>";
1984: return $selectdomain;
1985: }
1986:
1.35 matthew 1987: #-------------------------------------------
1988:
1.45 matthew 1989: =pod
1990:
1.648 raeburn 1991: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1992:
1.586 raeburn 1993: input: 4 arguments (two required, two optional) -
1994: $domain - domain of new user
1995: $name - name of form element
1996: $default - Value of 'default' causes a default item to be first
1997: option, and selected by default.
1998: $hide - Value of 'hide' causes hiding of the name of the server,
1999: if 1 server found, or default, if 0 found.
1.594 raeburn 2000: output: returns 2 items:
1.586 raeburn 2001: (a) form element which contains either:
2002: (i) <select name="$name">
2003: <option value="$hostid1">$hostid $servers{$hostid}</option>
2004: <option value="$hostid2">$hostid $servers{$hostid}</option>
2005: </select>
2006: form item if there are multiple library servers in $domain, or
2007: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2008: if there is only one library server in $domain.
2009:
2010: (b) number of library servers found.
2011:
2012: See loncreateuser.pm for example of use.
1.35 matthew 2013:
2014: =cut
2015:
2016: #-------------------------------------------
1.586 raeburn 2017: sub home_server_form_item {
2018: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2019: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2020: my $result;
2021: my $numlib = keys(%servers);
2022: if ($numlib > 1) {
2023: $result .= '<select name="'.$name.'" />'."\n";
2024: if ($default) {
1.804 bisitz 2025: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2026: '</option>'."\n";
2027: }
2028: foreach my $hostid (sort(keys(%servers))) {
2029: $result.= '<option value="'.$hostid.'">'.
2030: $hostid.' '.$servers{$hostid}."</option>\n";
2031: }
2032: $result .= '</select>'."\n";
2033: } elsif ($numlib == 1) {
2034: my $hostid;
2035: foreach my $item (keys(%servers)) {
2036: $hostid = $item;
2037: }
2038: $result .= '<input type="hidden" name="'.$name.'" value="'.
2039: $hostid.'" />';
2040: if (!$hide) {
2041: $result .= $hostid.' '.$servers{$hostid};
2042: }
2043: $result .= "\n";
2044: } elsif ($default) {
2045: $result .= '<input type="hidden" name="'.$name.
2046: '" value="default" />';
2047: if (!$hide) {
2048: $result .= &mt('default');
2049: }
2050: $result .= "\n";
1.33 matthew 2051: }
1.586 raeburn 2052: return ($result,$numlib);
1.33 matthew 2053: }
1.112 bowersj2 2054:
2055: =pod
2056:
1.534 albertel 2057: =back
2058:
1.112 bowersj2 2059: =cut
1.87 matthew 2060:
2061: ###############################################################
1.112 bowersj2 2062: ## Decoding User Agent ##
1.87 matthew 2063: ###############################################################
2064:
2065: =pod
2066:
1.112 bowersj2 2067: =head1 Decoding the User Agent
2068:
2069: =over 4
2070:
2071: =item * &decode_user_agent()
1.87 matthew 2072:
2073: Inputs: $r
2074:
2075: Outputs:
2076:
2077: =over 4
2078:
1.112 bowersj2 2079: =item * $httpbrowser
1.87 matthew 2080:
1.112 bowersj2 2081: =item * $clientbrowser
1.87 matthew 2082:
1.112 bowersj2 2083: =item * $clientversion
1.87 matthew 2084:
1.112 bowersj2 2085: =item * $clientmathml
1.87 matthew 2086:
1.112 bowersj2 2087: =item * $clientunicode
1.87 matthew 2088:
1.112 bowersj2 2089: =item * $clientos
1.87 matthew 2090:
2091: =back
2092:
1.157 matthew 2093: =back
2094:
1.87 matthew 2095: =cut
2096:
2097: ###############################################################
2098: ###############################################################
2099: sub decode_user_agent {
1.247 albertel 2100: my ($r)=@_;
1.87 matthew 2101: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2102: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2103: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2104: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2105: my $clientbrowser='unknown';
2106: my $clientversion='0';
2107: my $clientmathml='';
2108: my $clientunicode='0';
2109: for (my $i=0;$i<=$#browsertype;$i++) {
2110: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2111: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2112: $clientbrowser=$bname;
2113: $httpbrowser=~/$vreg/i;
2114: $clientversion=$1;
2115: $clientmathml=($clientversion>=$minv);
2116: $clientunicode=($clientversion>=$univ);
2117: }
2118: }
2119: my $clientos='unknown';
2120: if (($httpbrowser=~/linux/i) ||
2121: ($httpbrowser=~/unix/i) ||
2122: ($httpbrowser=~/ux/i) ||
2123: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2124: if (($httpbrowser=~/vax/i) ||
2125: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2126: if ($httpbrowser=~/next/i) { $clientos='next'; }
2127: if (($httpbrowser=~/mac/i) ||
2128: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2129: if ($httpbrowser=~/win/i) { $clientos='win'; }
2130: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2131: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2132: $clientunicode,$clientos,);
2133: }
2134:
1.32 matthew 2135: ###############################################################
2136: ## Authentication changing form generation subroutines ##
2137: ###############################################################
2138: ##
2139: ## All of the authform_xxxxxxx subroutines take their inputs in a
2140: ## hash, and have reasonable default values.
2141: ##
2142: ## formname = the name given in the <form> tag.
1.35 matthew 2143: #-------------------------------------------
2144:
1.45 matthew 2145: =pod
2146:
1.112 bowersj2 2147: =head1 Authentication Routines
2148:
2149: =over 4
2150:
1.648 raeburn 2151: =item * &authform_xxxxxx()
1.35 matthew 2152:
2153: The authform_xxxxxx subroutines provide javascript and html forms which
2154: handle some of the conveniences required for authentication forms.
2155: This is not an optimal method, but it works.
2156:
2157: =over 4
2158:
1.112 bowersj2 2159: =item * authform_header
1.35 matthew 2160:
1.112 bowersj2 2161: =item * authform_authorwarning
1.35 matthew 2162:
1.112 bowersj2 2163: =item * authform_nochange
1.35 matthew 2164:
1.112 bowersj2 2165: =item * authform_kerberos
1.35 matthew 2166:
1.112 bowersj2 2167: =item * authform_internal
1.35 matthew 2168:
1.112 bowersj2 2169: =item * authform_filesystem
1.35 matthew 2170:
2171: =back
2172:
1.648 raeburn 2173: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2174:
1.35 matthew 2175: =cut
2176:
2177: #-------------------------------------------
1.32 matthew 2178: sub authform_header{
2179: my %in = (
2180: formname => 'cu',
1.80 albertel 2181: kerb_def_dom => '',
1.32 matthew 2182: @_,
2183: );
2184: $in{'formname'} = 'document.' . $in{'formname'};
2185: my $result='';
1.80 albertel 2186:
2187: #---------------------------------------------- Code for upper case translation
2188: my $Javascript_toUpperCase;
2189: unless ($in{kerb_def_dom}) {
2190: $Javascript_toUpperCase =<<"END";
2191: switch (choice) {
2192: case 'krb': currentform.elements[choicearg].value =
2193: currentform.elements[choicearg].value.toUpperCase();
2194: break;
2195: default:
2196: }
2197: END
2198: } else {
2199: $Javascript_toUpperCase = "";
2200: }
2201:
1.165 raeburn 2202: my $radioval = "'nochange'";
1.591 raeburn 2203: if (defined($in{'curr_authtype'})) {
2204: if ($in{'curr_authtype'} ne '') {
2205: $radioval = "'".$in{'curr_authtype'}."arg'";
2206: }
1.174 matthew 2207: }
1.165 raeburn 2208: my $argfield = 'null';
1.591 raeburn 2209: if (defined($in{'mode'})) {
1.165 raeburn 2210: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2211: if (defined($in{'curr_autharg'})) {
2212: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2213: $argfield = "'$in{'curr_autharg'}'";
2214: }
2215: }
2216: }
2217: }
2218:
1.32 matthew 2219: $result.=<<"END";
2220: var current = new Object();
1.165 raeburn 2221: current.radiovalue = $radioval;
2222: current.argfield = $argfield;
1.32 matthew 2223:
2224: function changed_radio(choice,currentform) {
2225: var choicearg = choice + 'arg';
2226: // If a radio button in changed, we need to change the argfield
2227: if (current.radiovalue != choice) {
2228: current.radiovalue = choice;
2229: if (current.argfield != null) {
2230: currentform.elements[current.argfield].value = '';
2231: }
2232: if (choice == 'nochange') {
2233: current.argfield = null;
2234: } else {
2235: current.argfield = choicearg;
2236: switch(choice) {
2237: case 'krb':
2238: currentform.elements[current.argfield].value =
2239: "$in{'kerb_def_dom'}";
2240: break;
2241: default:
2242: break;
2243: }
2244: }
2245: }
2246: return;
2247: }
1.22 www 2248:
1.32 matthew 2249: function changed_text(choice,currentform) {
2250: var choicearg = choice + 'arg';
2251: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2252: $Javascript_toUpperCase
1.32 matthew 2253: // clear old field
2254: if ((current.argfield != choicearg) && (current.argfield != null)) {
2255: currentform.elements[current.argfield].value = '';
2256: }
2257: current.argfield = choicearg;
2258: }
2259: set_auth_radio_buttons(choice,currentform);
2260: return;
1.20 www 2261: }
1.32 matthew 2262:
2263: function set_auth_radio_buttons(newvalue,currentform) {
2264: var i=0;
2265: while (i < currentform.login.length) {
2266: if (currentform.login[i].value == newvalue) { break; }
2267: i++;
2268: }
2269: if (i == currentform.login.length) {
2270: return;
2271: }
2272: current.radiovalue = newvalue;
2273: currentform.login[i].checked = true;
2274: return;
2275: }
2276: END
2277: return $result;
2278: }
2279:
2280: sub authform_authorwarning{
2281: my $result='';
1.144 matthew 2282: $result='<i>'.
2283: &mt('As a general rule, only authors or co-authors should be '.
2284: 'filesystem authenticated '.
2285: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2286: return $result;
2287: }
2288:
2289: sub authform_nochange{
2290: my %in = (
2291: formname => 'document.cu',
2292: kerb_def_dom => 'MSU.EDU',
2293: @_,
2294: );
1.586 raeburn 2295: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2296: my $result;
2297: if (keys(%can_assign) == 0) {
2298: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2299: } else {
2300: $result = '<label>'.&mt('[_1] Do not change login data',
2301: '<input type="radio" name="login" value="nochange" '.
2302: 'checked="checked" onclick="'.
1.281 albertel 2303: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2304: '</label>';
1.586 raeburn 2305: }
1.32 matthew 2306: return $result;
2307: }
2308:
1.591 raeburn 2309: sub authform_kerberos {
1.32 matthew 2310: my %in = (
2311: formname => 'document.cu',
2312: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2313: kerb_def_auth => 'krb4',
1.32 matthew 2314: @_,
2315: );
1.586 raeburn 2316: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2317: $autharg,$jscall);
2318: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2319: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2320: $check5 = ' checked="checked"';
1.80 albertel 2321: } else {
1.772 bisitz 2322: $check4 = ' checked="checked"';
1.80 albertel 2323: }
1.165 raeburn 2324: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2325: if (defined($in{'curr_authtype'})) {
2326: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2327: $krbcheck = ' checked="checked"';
1.623 raeburn 2328: if (defined($in{'mode'})) {
2329: if ($in{'mode'} eq 'modifyuser') {
2330: $krbcheck = '';
2331: }
2332: }
1.591 raeburn 2333: if (defined($in{'curr_kerb_ver'})) {
2334: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2335: $check5 = ' checked="checked"';
1.591 raeburn 2336: $check4 = '';
2337: } else {
1.772 bisitz 2338: $check4 = ' checked="checked"';
1.591 raeburn 2339: $check5 = '';
2340: }
1.586 raeburn 2341: }
1.591 raeburn 2342: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2343: $krbarg = $in{'curr_autharg'};
2344: }
1.586 raeburn 2345: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2346: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2347: $result =
2348: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2349: $in{'curr_autharg'},$krbver);
2350: } else {
2351: $result =
2352: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2353: }
2354: return $result;
2355: }
2356: }
2357: } else {
2358: if ($authnum == 1) {
1.784 bisitz 2359: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2360: }
2361: }
1.586 raeburn 2362: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2363: return;
1.587 raeburn 2364: } elsif ($authtype eq '') {
1.591 raeburn 2365: if (defined($in{'mode'})) {
1.587 raeburn 2366: if ($in{'mode'} eq 'modifycourse') {
2367: if ($authnum == 1) {
1.784 bisitz 2368: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2369: }
2370: }
2371: }
1.586 raeburn 2372: }
2373: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2374: if ($authtype eq '') {
2375: $authtype = '<input type="radio" name="login" value="krb" '.
2376: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2377: $krbcheck.' />';
2378: }
2379: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2380: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2381: $in{'curr_authtype'} eq 'krb5') ||
2382: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2383: $in{'curr_authtype'} eq 'krb4')) {
2384: $result .= &mt
1.144 matthew 2385: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2386: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2387: '<label>'.$authtype,
1.281 albertel 2388: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2389: 'value="'.$krbarg.'" '.
1.144 matthew 2390: 'onchange="'.$jscall.'" />',
1.281 albertel 2391: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2392: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2393: '</label>');
1.586 raeburn 2394: } elsif ($can_assign{'krb4'}) {
2395: $result .= &mt
2396: ('[_1] Kerberos authenticated with domain [_2] '.
2397: '[_3] Version 4 [_4]',
2398: '<label>'.$authtype,
2399: '</label><input type="text" size="10" name="krbarg" '.
2400: 'value="'.$krbarg.'" '.
2401: 'onchange="'.$jscall.'" />',
2402: '<label><input type="hidden" name="krbver" value="4" />',
2403: '</label>');
2404: } elsif ($can_assign{'krb5'}) {
2405: $result .= &mt
2406: ('[_1] Kerberos authenticated with domain [_2] '.
2407: '[_3] Version 5 [_4]',
2408: '<label>'.$authtype,
2409: '</label><input type="text" size="10" name="krbarg" '.
2410: 'value="'.$krbarg.'" '.
2411: 'onchange="'.$jscall.'" />',
2412: '<label><input type="hidden" name="krbver" value="5" />',
2413: '</label>');
2414: }
1.32 matthew 2415: return $result;
2416: }
2417:
2418: sub authform_internal{
1.586 raeburn 2419: my %in = (
1.32 matthew 2420: formname => 'document.cu',
2421: kerb_def_dom => 'MSU.EDU',
2422: @_,
2423: );
1.586 raeburn 2424: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2425: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2426: if (defined($in{'curr_authtype'})) {
2427: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2428: if ($can_assign{'int'}) {
1.772 bisitz 2429: $intcheck = 'checked="checked" ';
1.623 raeburn 2430: if (defined($in{'mode'})) {
2431: if ($in{'mode'} eq 'modifyuser') {
2432: $intcheck = '';
2433: }
2434: }
1.591 raeburn 2435: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2436: $intarg = $in{'curr_autharg'};
2437: }
2438: } else {
2439: $result = &mt('Currently internally authenticated.');
2440: return $result;
1.165 raeburn 2441: }
2442: }
1.586 raeburn 2443: } else {
2444: if ($authnum == 1) {
1.784 bisitz 2445: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2446: }
2447: }
2448: if (!$can_assign{'int'}) {
2449: return;
1.587 raeburn 2450: } elsif ($authtype eq '') {
1.591 raeburn 2451: if (defined($in{'mode'})) {
1.587 raeburn 2452: if ($in{'mode'} eq 'modifycourse') {
2453: if ($authnum == 1) {
1.784 bisitz 2454: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2455: }
2456: }
2457: }
1.165 raeburn 2458: }
1.586 raeburn 2459: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2460: if ($authtype eq '') {
2461: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2462: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2463: }
1.605 bisitz 2464: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2465: $intarg.'" onchange="'.$jscall.'" />';
2466: $result = &mt
1.144 matthew 2467: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2468: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2469: $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 2470: return $result;
2471: }
2472:
2473: sub authform_local{
2474: my %in = (
2475: formname => 'document.cu',
2476: kerb_def_dom => 'MSU.EDU',
2477: @_,
2478: );
1.586 raeburn 2479: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2480: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2481: if (defined($in{'curr_authtype'})) {
2482: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2483: if ($can_assign{'loc'}) {
1.772 bisitz 2484: $loccheck = 'checked="checked" ';
1.623 raeburn 2485: if (defined($in{'mode'})) {
2486: if ($in{'mode'} eq 'modifyuser') {
2487: $loccheck = '';
2488: }
2489: }
1.591 raeburn 2490: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2491: $locarg = $in{'curr_autharg'};
2492: }
2493: } else {
2494: $result = &mt('Currently using local (institutional) authentication.');
2495: return $result;
1.165 raeburn 2496: }
2497: }
1.586 raeburn 2498: } else {
2499: if ($authnum == 1) {
1.784 bisitz 2500: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2501: }
2502: }
2503: if (!$can_assign{'loc'}) {
2504: return;
1.587 raeburn 2505: } elsif ($authtype eq '') {
1.591 raeburn 2506: if (defined($in{'mode'})) {
1.587 raeburn 2507: if ($in{'mode'} eq 'modifycourse') {
2508: if ($authnum == 1) {
1.784 bisitz 2509: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2510: }
2511: }
2512: }
1.165 raeburn 2513: }
1.586 raeburn 2514: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2515: if ($authtype eq '') {
2516: $authtype = '<input type="radio" name="login" value="loc" '.
2517: $loccheck.' onchange="'.$jscall.'" onclick="'.
2518: $jscall.'" />';
2519: }
2520: $autharg = '<input type="text" size="10" name="locarg" value="'.
2521: $locarg.'" onchange="'.$jscall.'" />';
2522: $result = &mt('[_1] Local Authentication with argument [_2]',
2523: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2524: return $result;
2525: }
2526:
2527: sub authform_filesystem{
2528: my %in = (
2529: formname => 'document.cu',
2530: kerb_def_dom => 'MSU.EDU',
2531: @_,
2532: );
1.586 raeburn 2533: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2534: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2535: if (defined($in{'curr_authtype'})) {
2536: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2537: if ($can_assign{'fsys'}) {
1.772 bisitz 2538: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2539: if (defined($in{'mode'})) {
2540: if ($in{'mode'} eq 'modifyuser') {
2541: $fsyscheck = '';
2542: }
2543: }
1.586 raeburn 2544: } else {
2545: $result = &mt('Currently Filesystem Authenticated.');
2546: return $result;
2547: }
2548: }
2549: } else {
2550: if ($authnum == 1) {
1.784 bisitz 2551: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2552: }
2553: }
2554: if (!$can_assign{'fsys'}) {
2555: return;
1.587 raeburn 2556: } elsif ($authtype eq '') {
1.591 raeburn 2557: if (defined($in{'mode'})) {
1.587 raeburn 2558: if ($in{'mode'} eq 'modifycourse') {
2559: if ($authnum == 1) {
1.784 bisitz 2560: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2561: }
2562: }
2563: }
1.586 raeburn 2564: }
2565: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2566: if ($authtype eq '') {
2567: $authtype = '<input type="radio" name="login" value="fsys" '.
2568: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2569: $jscall.'" />';
2570: }
2571: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2572: ' onchange="'.$jscall.'" />';
2573: $result = &mt
1.144 matthew 2574: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2575: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2576: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2577: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2578: 'onchange="'.$jscall.'" />');
1.32 matthew 2579: return $result;
2580: }
2581:
1.586 raeburn 2582: sub get_assignable_auth {
2583: my ($dom) = @_;
2584: if ($dom eq '') {
2585: $dom = $env{'request.role.domain'};
2586: }
2587: my %can_assign = (
2588: krb4 => 1,
2589: krb5 => 1,
2590: int => 1,
2591: loc => 1,
2592: );
2593: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2594: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2595: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2596: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2597: my $context;
2598: if ($env{'request.role'} =~ /^au/) {
2599: $context = 'author';
2600: } elsif ($env{'request.role'} =~ /^dc/) {
2601: $context = 'domain';
2602: } elsif ($env{'request.course.id'}) {
2603: $context = 'course';
2604: }
2605: if ($context) {
2606: if (ref($authhash->{$context}) eq 'HASH') {
2607: %can_assign = %{$authhash->{$context}};
2608: }
2609: }
2610: }
2611: }
2612: my $authnum = 0;
2613: foreach my $key (keys(%can_assign)) {
2614: if ($can_assign{$key}) {
2615: $authnum ++;
2616: }
2617: }
2618: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2619: $authnum --;
2620: }
2621: return ($authnum,%can_assign);
2622: }
2623:
1.80 albertel 2624: ###############################################################
2625: ## Get Kerberos Defaults for Domain ##
2626: ###############################################################
2627: ##
2628: ## Returns default kerberos version and an associated argument
2629: ## as listed in file domain.tab. If not listed, provides
2630: ## appropriate default domain and kerberos version.
2631: ##
2632: #-------------------------------------------
2633:
2634: =pod
2635:
1.648 raeburn 2636: =item * &get_kerberos_defaults()
1.80 albertel 2637:
2638: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2639: version and domain. If not found, it defaults to version 4 and the
2640: domain of the server.
1.80 albertel 2641:
1.648 raeburn 2642: =over 4
2643:
1.80 albertel 2644: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2645:
1.648 raeburn 2646: =back
2647:
2648: =back
2649:
1.80 albertel 2650: =cut
2651:
2652: #-------------------------------------------
2653: sub get_kerberos_defaults {
2654: my $domain=shift;
1.641 raeburn 2655: my ($krbdef,$krbdefdom);
2656: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2657: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2658: $krbdef = $domdefaults{'auth_def'};
2659: $krbdefdom = $domdefaults{'auth_arg_def'};
2660: } else {
1.80 albertel 2661: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2662: my $krbdefdom=$1;
2663: $krbdefdom=~tr/a-z/A-Z/;
2664: $krbdef = "krb4";
2665: }
2666: return ($krbdef,$krbdefdom);
2667: }
1.112 bowersj2 2668:
1.32 matthew 2669:
1.46 matthew 2670: ###############################################################
2671: ## Thesaurus Functions ##
2672: ###############################################################
1.20 www 2673:
1.46 matthew 2674: =pod
1.20 www 2675:
1.112 bowersj2 2676: =head1 Thesaurus Functions
2677:
2678: =over 4
2679:
1.648 raeburn 2680: =item * &initialize_keywords()
1.46 matthew 2681:
2682: Initializes the package variable %Keywords if it is empty. Uses the
2683: package variable $thesaurus_db_file.
2684:
2685: =cut
2686:
2687: ###################################################
2688:
2689: sub initialize_keywords {
2690: return 1 if (scalar keys(%Keywords));
2691: # If we are here, %Keywords is empty, so fill it up
2692: # Make sure the file we need exists...
2693: if (! -e $thesaurus_db_file) {
2694: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2695: " failed because it does not exist");
2696: return 0;
2697: }
2698: # Set up the hash as a database
2699: my %thesaurus_db;
2700: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2701: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2702: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2703: $thesaurus_db_file);
2704: return 0;
2705: }
2706: # Get the average number of appearances of a word.
2707: my $avecount = $thesaurus_db{'average.count'};
2708: # Put keywords (those that appear > average) into %Keywords
2709: while (my ($word,$data)=each (%thesaurus_db)) {
2710: my ($count,undef) = split /:/,$data;
2711: $Keywords{$word}++ if ($count > $avecount);
2712: }
2713: untie %thesaurus_db;
2714: # Remove special values from %Keywords.
1.356 albertel 2715: foreach my $value ('total.count','average.count') {
2716: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2717: }
1.46 matthew 2718: return 1;
2719: }
2720:
2721: ###################################################
2722:
2723: =pod
2724:
1.648 raeburn 2725: =item * &keyword($word)
1.46 matthew 2726:
2727: Returns true if $word is a keyword. A keyword is a word that appears more
2728: than the average number of times in the thesaurus database. Calls
2729: &initialize_keywords
2730:
2731: =cut
2732:
2733: ###################################################
1.20 www 2734:
2735: sub keyword {
1.46 matthew 2736: return if (!&initialize_keywords());
2737: my $word=lc(shift());
2738: $word=~s/\W//g;
2739: return exists($Keywords{$word});
1.20 www 2740: }
1.46 matthew 2741:
2742: ###############################################################
2743:
2744: =pod
1.20 www 2745:
1.648 raeburn 2746: =item * &get_related_words()
1.46 matthew 2747:
1.160 matthew 2748: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2749: an array of words. If the keyword is not in the thesaurus, an empty array
2750: will be returned. The order of the words returned is determined by the
2751: database which holds them.
2752:
2753: Uses global $thesaurus_db_file.
2754:
2755: =cut
2756:
2757: ###############################################################
2758: sub get_related_words {
2759: my $keyword = shift;
2760: my %thesaurus_db;
2761: if (! -e $thesaurus_db_file) {
2762: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2763: "failed because the file does not exist");
2764: return ();
2765: }
2766: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2767: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2768: return ();
2769: }
2770: my @Words=();
1.429 www 2771: my $count=0;
1.46 matthew 2772: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2773: # The first element is the number of times
2774: # the word appears. We do not need it now.
1.429 www 2775: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2776: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2777: my $threshold=$mostfrequentcount/10;
2778: foreach my $possibleword (@RelatedWords) {
2779: my ($word,$wordcount)=split(/\,/,$possibleword);
2780: if ($wordcount>$threshold) {
2781: push(@Words,$word);
2782: $count++;
2783: if ($count>10) { last; }
2784: }
1.20 www 2785: }
2786: }
1.46 matthew 2787: untie %thesaurus_db;
2788: return @Words;
1.14 harris41 2789: }
1.46 matthew 2790:
1.112 bowersj2 2791: =pod
2792:
2793: =back
2794:
2795: =cut
1.61 www 2796:
2797: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2798: =pod
2799:
1.112 bowersj2 2800: =head1 User Name Functions
2801:
2802: =over 4
2803:
1.648 raeburn 2804: =item * &plainname($uname,$udom,$first)
1.81 albertel 2805:
1.112 bowersj2 2806: Takes a users logon name and returns it as a string in
1.226 albertel 2807: "first middle last generation" form
2808: if $first is set to 'lastname' then it returns it as
2809: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2810:
2811: =cut
1.61 www 2812:
1.295 www 2813:
1.81 albertel 2814: ###############################################################
1.61 www 2815: sub plainname {
1.226 albertel 2816: my ($uname,$udom,$first)=@_;
1.537 albertel 2817: return if (!defined($uname) || !defined($udom));
1.295 www 2818: my %names=&getnames($uname,$udom);
1.226 albertel 2819: my $name=&Apache::lonnet::format_name($names{'firstname'},
2820: $names{'middlename'},
2821: $names{'lastname'},
2822: $names{'generation'},$first);
2823: $name=~s/^\s+//;
1.62 www 2824: $name=~s/\s+$//;
2825: $name=~s/\s+/ /g;
1.353 albertel 2826: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2827: return $name;
1.61 www 2828: }
1.66 www 2829:
2830: # -------------------------------------------------------------------- Nickname
1.81 albertel 2831: =pod
2832:
1.648 raeburn 2833: =item * &nickname($uname,$udom)
1.81 albertel 2834:
2835: Gets a users name and returns it as a string as
2836:
2837: ""nickname""
1.66 www 2838:
1.81 albertel 2839: if the user has a nickname or
2840:
2841: "first middle last generation"
2842:
2843: if the user does not
2844:
2845: =cut
1.66 www 2846:
2847: sub nickname {
2848: my ($uname,$udom)=@_;
1.537 albertel 2849: return if (!defined($uname) || !defined($udom));
1.295 www 2850: my %names=&getnames($uname,$udom);
1.68 albertel 2851: my $name=$names{'nickname'};
1.66 www 2852: if ($name) {
2853: $name='"'.$name.'"';
2854: } else {
2855: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2856: $names{'lastname'}.' '.$names{'generation'};
2857: $name=~s/\s+$//;
2858: $name=~s/\s+/ /g;
2859: }
2860: return $name;
2861: }
2862:
1.295 www 2863: sub getnames {
2864: my ($uname,$udom)=@_;
1.537 albertel 2865: return if (!defined($uname) || !defined($udom));
1.433 albertel 2866: if ($udom eq 'public' && $uname eq 'public') {
2867: return ('lastname' => &mt('Public'));
2868: }
1.295 www 2869: my $id=$uname.':'.$udom;
2870: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2871: if ($cached) {
2872: return %{$names};
2873: } else {
2874: my %loadnames=&Apache::lonnet::get('environment',
2875: ['firstname','middlename','lastname','generation','nickname'],
2876: $udom,$uname);
2877: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2878: return %loadnames;
2879: }
2880: }
1.61 www 2881:
1.542 raeburn 2882: # -------------------------------------------------------------------- getemails
1.648 raeburn 2883:
1.542 raeburn 2884: =pod
2885:
1.648 raeburn 2886: =item * &getemails($uname,$udom)
1.542 raeburn 2887:
2888: Gets a user's email information and returns it as a hash with keys:
2889: notification, critnotification, permanentemail
2890:
2891: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2892: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2893:
1.648 raeburn 2894:
1.542 raeburn 2895: =cut
2896:
1.648 raeburn 2897:
1.466 albertel 2898: sub getemails {
2899: my ($uname,$udom)=@_;
2900: if ($udom eq 'public' && $uname eq 'public') {
2901: return;
2902: }
1.467 www 2903: if (!$udom) { $udom=$env{'user.domain'}; }
2904: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2905: my $id=$uname.':'.$udom;
2906: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2907: if ($cached) {
2908: return %{$names};
2909: } else {
2910: my %loadnames=&Apache::lonnet::get('environment',
2911: ['notification','critnotification',
2912: 'permanentemail'],
2913: $udom,$uname);
2914: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2915: return %loadnames;
2916: }
2917: }
2918:
1.551 albertel 2919: sub flush_email_cache {
2920: my ($uname,$udom)=@_;
2921: if (!$udom) { $udom =$env{'user.domain'}; }
2922: if (!$uname) { $uname=$env{'user.name'}; }
2923: return if ($udom eq 'public' && $uname eq 'public');
2924: my $id=$uname.':'.$udom;
2925: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2926: }
2927:
1.728 raeburn 2928: # -------------------------------------------------------------------- getlangs
2929:
2930: =pod
2931:
2932: =item * &getlangs($uname,$udom)
2933:
2934: Gets a user's language preference and returns it as a hash with key:
2935: language.
2936:
2937: =cut
2938:
2939:
2940: sub getlangs {
2941: my ($uname,$udom) = @_;
2942: if (!$udom) { $udom =$env{'user.domain'}; }
2943: if (!$uname) { $uname=$env{'user.name'}; }
2944: my $id=$uname.':'.$udom;
2945: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2946: if ($cached) {
2947: return %{$langs};
2948: } else {
2949: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2950: $udom,$uname);
2951: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2952: return %loadlangs;
2953: }
2954: }
2955:
2956: sub flush_langs_cache {
2957: my ($uname,$udom)=@_;
2958: if (!$udom) { $udom =$env{'user.domain'}; }
2959: if (!$uname) { $uname=$env{'user.name'}; }
2960: return if ($udom eq 'public' && $uname eq 'public');
2961: my $id=$uname.':'.$udom;
2962: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2963: }
2964:
1.61 www 2965: # ------------------------------------------------------------------ Screenname
1.81 albertel 2966:
2967: =pod
2968:
1.648 raeburn 2969: =item * &screenname($uname,$udom)
1.81 albertel 2970:
2971: Gets a users screenname and returns it as a string
2972:
2973: =cut
1.61 www 2974:
2975: sub screenname {
2976: my ($uname,$udom)=@_;
1.258 albertel 2977: if ($uname eq $env{'user.name'} &&
2978: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2979: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2980: return $names{'screenname'};
1.62 www 2981: }
2982:
1.212 albertel 2983:
1.802 bisitz 2984: # ------------------------------------------------------------- Confirm Wrapper
2985: =pod
2986:
2987: =item confirmwrapper
2988:
2989: Wrap messages about completion of operation in box
2990:
2991: =cut
2992:
2993: sub confirmwrapper {
2994: my ($message)=@_;
2995: if ($message) {
2996: return "\n".'<div class="LC_confirm_box">'."\n"
2997: .$message."\n"
2998: .'</div>'."\n";
2999: } else {
3000: return $message;
3001: }
3002: }
3003:
1.62 www 3004: # ------------------------------------------------------------- Message Wrapper
3005:
3006: sub messagewrapper {
1.369 www 3007: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3008: return
1.441 albertel 3009: '<a href="/adm/email?compose=individual&'.
3010: 'recname='.$username.'&recdom='.$domain.
3011: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3012: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3013: }
1.802 bisitz 3014:
1.74 www 3015: # --------------------------------------------------------------- Notes Wrapper
3016:
3017: sub noteswrapper {
3018: my ($link,$un,$do)=@_;
3019: return
1.896 amueller 3020: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3021: }
1.802 bisitz 3022:
1.62 www 3023: # ------------------------------------------------------------- Aboutme Wrapper
3024:
3025: sub aboutmewrapper {
1.166 www 3026: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3027: if (!defined($username) && !defined($domain)) {
3028: return;
3029: }
1.892 amueller 3030: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3031: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3032: }
3033:
3034: # ------------------------------------------------------------ Syllabus Wrapper
3035:
3036: sub syllabuswrapper {
1.707 bisitz 3037: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3038: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3039: }
1.14 harris41 3040:
1.802 bisitz 3041: # -----------------------------------------------------------------------------
3042:
1.208 matthew 3043: sub track_student_link {
1.887 raeburn 3044: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3045: my $link ="/adm/trackstudent?";
1.208 matthew 3046: my $title = 'View recent activity';
3047: if (defined($sname) && $sname !~ /^\s*$/ &&
3048: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3049: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3050: $title .= ' of this student';
1.268 albertel 3051: }
1.208 matthew 3052: if (defined($target) && $target !~ /^\s*$/) {
3053: $target = qq{target="$target"};
3054: } else {
3055: $target = '';
3056: }
1.268 albertel 3057: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3058: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3059: $title = &mt($title);
3060: $linktext = &mt($linktext);
1.448 albertel 3061: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3062: &help_open_topic('View_recent_activity');
1.208 matthew 3063: }
3064:
1.781 raeburn 3065: sub slot_reservations_link {
3066: my ($linktext,$sname,$sdom,$target) = @_;
3067: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3068: my $title = 'View slot reservation history';
3069: if (defined($sname) && $sname !~ /^\s*$/ &&
3070: defined($sdom) && $sdom !~ /^\s*$/) {
3071: $link .= "&uname=$sname&udom=$sdom";
3072: $title .= ' of this student';
3073: }
3074: if (defined($target) && $target !~ /^\s*$/) {
3075: $target = qq{target="$target"};
3076: } else {
3077: $target = '';
3078: }
3079: $title = &mt($title);
3080: $linktext = &mt($linktext);
3081: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3082: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3083:
3084: }
3085:
1.508 www 3086: # ===================================================== Display a student photo
3087:
3088:
1.509 albertel 3089: sub student_image_tag {
1.508 www 3090: my ($domain,$user)=@_;
3091: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3092: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3093: return '<img src="'.$imgsrc.'" align="right" />';
3094: } else {
3095: return '';
3096: }
3097: }
3098:
1.112 bowersj2 3099: =pod
3100:
3101: =back
3102:
3103: =head1 Access .tab File Data
3104:
3105: =over 4
3106:
1.648 raeburn 3107: =item * &languageids()
1.112 bowersj2 3108:
3109: returns list of all language ids
3110:
3111: =cut
3112:
1.14 harris41 3113: sub languageids {
1.16 harris41 3114: return sort(keys(%language));
1.14 harris41 3115: }
3116:
1.112 bowersj2 3117: =pod
3118:
1.648 raeburn 3119: =item * &languagedescription()
1.112 bowersj2 3120:
3121: returns description of a specified language id
3122:
3123: =cut
3124:
1.14 harris41 3125: sub languagedescription {
1.125 www 3126: my $code=shift;
3127: return ($supported_language{$code}?'* ':'').
3128: $language{$code}.
1.126 www 3129: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3130: }
3131:
3132: sub plainlanguagedescription {
3133: my $code=shift;
3134: return $language{$code};
3135: }
3136:
3137: sub supportedlanguagecode {
3138: my $code=shift;
3139: return $supported_language{$code};
1.97 www 3140: }
3141:
1.112 bowersj2 3142: =pod
3143:
1.648 raeburn 3144: =item * ©rightids()
1.112 bowersj2 3145:
3146: returns list of all copyrights
3147:
3148: =cut
3149:
3150: sub copyrightids {
3151: return sort(keys(%cprtag));
3152: }
3153:
3154: =pod
3155:
1.648 raeburn 3156: =item * ©rightdescription()
1.112 bowersj2 3157:
3158: returns description of a specified copyright id
3159:
3160: =cut
3161:
3162: sub copyrightdescription {
1.166 www 3163: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3164: }
1.197 matthew 3165:
3166: =pod
3167:
1.648 raeburn 3168: =item * &source_copyrightids()
1.192 taceyjo1 3169:
3170: returns list of all source copyrights
3171:
3172: =cut
3173:
3174: sub source_copyrightids {
3175: return sort(keys(%scprtag));
3176: }
3177:
3178: =pod
3179:
1.648 raeburn 3180: =item * &source_copyrightdescription()
1.192 taceyjo1 3181:
3182: returns description of a specified source copyright id
3183:
3184: =cut
3185:
3186: sub source_copyrightdescription {
3187: return &mt($scprtag{shift(@_)});
3188: }
1.112 bowersj2 3189:
3190: =pod
3191:
1.648 raeburn 3192: =item * &filecategories()
1.112 bowersj2 3193:
3194: returns list of all file categories
3195:
3196: =cut
3197:
3198: sub filecategories {
3199: return sort(keys(%category_extensions));
3200: }
3201:
3202: =pod
3203:
1.648 raeburn 3204: =item * &filecategorytypes()
1.112 bowersj2 3205:
3206: returns list of file types belonging to a given file
3207: category
3208:
3209: =cut
3210:
3211: sub filecategorytypes {
1.356 albertel 3212: my ($cat) = @_;
3213: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3214: }
3215:
3216: =pod
3217:
1.648 raeburn 3218: =item * &fileembstyle()
1.112 bowersj2 3219:
3220: returns embedding style for a specified file type
3221:
3222: =cut
3223:
3224: sub fileembstyle {
3225: return $fe{lc(shift(@_))};
1.169 www 3226: }
3227:
1.351 www 3228: sub filemimetype {
3229: return $fm{lc(shift(@_))};
3230: }
3231:
1.169 www 3232:
3233: sub filecategoryselect {
3234: my ($name,$value)=@_;
1.189 matthew 3235: return &select_form($value,$name,
1.169 www 3236: '' => &mt('Any category'),
3237: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3238: }
3239:
3240: =pod
3241:
1.648 raeburn 3242: =item * &filedescription()
1.112 bowersj2 3243:
3244: returns description for a specified file type
3245:
3246: =cut
3247:
3248: sub filedescription {
1.188 matthew 3249: my $file_description = $fd{lc(shift())};
3250: $file_description =~ s:([\[\]]):~$1:g;
3251: return &mt($file_description);
1.112 bowersj2 3252: }
3253:
3254: =pod
3255:
1.648 raeburn 3256: =item * &filedescriptionex()
1.112 bowersj2 3257:
3258: returns description for a specified file type with
3259: extra formatting
3260:
3261: =cut
3262:
3263: sub filedescriptionex {
3264: my $ex=shift;
1.188 matthew 3265: my $file_description = $fd{lc($ex)};
3266: $file_description =~ s:([\[\]]):~$1:g;
3267: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3268: }
3269:
3270: # End of .tab access
3271: =pod
3272:
3273: =back
3274:
3275: =cut
3276:
3277: # ------------------------------------------------------------------ File Types
3278: sub fileextensions {
3279: return sort(keys(%fe));
3280: }
3281:
1.97 www 3282: # ----------------------------------------------------------- Display Languages
3283: # returns a hash with all desired display languages
3284: #
3285:
3286: sub display_languages {
3287: my %languages=();
1.695 raeburn 3288: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3289: $languages{$lang}=1;
1.97 www 3290: }
3291: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3292: if ($env{'form.displaylanguage'}) {
1.356 albertel 3293: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3294: $languages{$lang}=1;
1.97 www 3295: }
3296: }
3297: return %languages;
1.14 harris41 3298: }
3299:
1.582 albertel 3300: sub languages {
3301: my ($possible_langs) = @_;
1.695 raeburn 3302: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3303: if (!ref($possible_langs)) {
3304: if( wantarray ) {
3305: return @preferred_langs;
3306: } else {
3307: return $preferred_langs[0];
3308: }
3309: }
3310: my %possibilities = map { $_ => 1 } (@$possible_langs);
3311: my @preferred_possibilities;
3312: foreach my $preferred_lang (@preferred_langs) {
3313: if (exists($possibilities{$preferred_lang})) {
3314: push(@preferred_possibilities, $preferred_lang);
3315: }
3316: }
3317: if( wantarray ) {
3318: return @preferred_possibilities;
3319: }
3320: return $preferred_possibilities[0];
3321: }
3322:
1.742 raeburn 3323: sub user_lang {
3324: my ($touname,$toudom,$fromcid) = @_;
3325: my @userlangs;
3326: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3327: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3328: $env{'course.'.$fromcid.'.languages'}));
3329: } else {
3330: my %langhash = &getlangs($touname,$toudom);
3331: if ($langhash{'languages'} ne '') {
3332: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3333: } else {
3334: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3335: if ($domdefs{'lang_def'} ne '') {
3336: @userlangs = ($domdefs{'lang_def'});
3337: }
3338: }
3339: }
3340: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3341: my $user_lh = Apache::localize->get_handle(@languages);
3342: return $user_lh;
3343: }
3344:
3345:
1.112 bowersj2 3346: ###############################################################
3347: ## Student Answer Attempts ##
3348: ###############################################################
3349:
3350: =pod
3351:
3352: =head1 Alternate Problem Views
3353:
3354: =over 4
3355:
1.648 raeburn 3356: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3357: $getattempt, $regexp, $gradesub)
3358:
3359: Return string with previous attempt on problem. Arguments:
3360:
3361: =over 4
3362:
3363: =item * $symb: Problem, including path
3364:
3365: =item * $username: username of the desired student
3366:
3367: =item * $domain: domain of the desired student
1.14 harris41 3368:
1.112 bowersj2 3369: =item * $course: Course ID
1.14 harris41 3370:
1.112 bowersj2 3371: =item * $getattempt: Leave blank for all attempts, otherwise put
3372: something
1.14 harris41 3373:
1.112 bowersj2 3374: =item * $regexp: if string matches this regexp, the string will be
3375: sent to $gradesub
1.14 harris41 3376:
1.112 bowersj2 3377: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3378:
1.112 bowersj2 3379: =back
1.14 harris41 3380:
1.112 bowersj2 3381: The output string is a table containing all desired attempts, if any.
1.16 harris41 3382:
1.112 bowersj2 3383: =cut
1.1 albertel 3384:
3385: sub get_previous_attempt {
1.43 ng 3386: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3387: my $prevattempts='';
1.43 ng 3388: no strict 'refs';
1.1 albertel 3389: if ($symb) {
1.3 albertel 3390: my (%returnhash)=
3391: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3392: if ($returnhash{'version'}) {
3393: my %lasthash=();
3394: my $version;
3395: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3396: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3397: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3398: }
1.1 albertel 3399: }
1.596 albertel 3400: $prevattempts=&start_data_table().&start_data_table_header_row();
3401: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3402: foreach my $key (sort(keys(%lasthash))) {
3403: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3404: if ($#parts > 0) {
1.31 albertel 3405: my $data=$parts[-1];
3406: pop(@parts);
1.596 albertel 3407: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3408: } else {
1.41 ng 3409: if ($#parts == 0) {
3410: $prevattempts.='<th>'.$parts[0].'</th>';
3411: } else {
3412: $prevattempts.='<th>'.$ign.'</th>';
3413: }
1.31 albertel 3414: }
1.16 harris41 3415: }
1.596 albertel 3416: $prevattempts.=&end_data_table_header_row();
1.40 ng 3417: if ($getattempt eq '') {
3418: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3419: $prevattempts.=&start_data_table_row().
3420: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3421: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3422: my $value = &format_previous_attempt_value($key,
3423: $returnhash{$version.':'.$key});
3424: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3425: }
1.596 albertel 3426: $prevattempts.=&end_data_table_row();
1.40 ng 3427: }
1.1 albertel 3428: }
1.596 albertel 3429: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3430: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3431: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3432: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3433: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3434: }
1.596 albertel 3435: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3436: } else {
1.596 albertel 3437: $prevattempts=
3438: &start_data_table().&start_data_table_row().
3439: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3440: &end_data_table_row().&end_data_table();
1.1 albertel 3441: }
3442: } else {
1.596 albertel 3443: $prevattempts=
3444: &start_data_table().&start_data_table_row().
3445: '<td>'.&mt('No data.').'</td>'.
3446: &end_data_table_row().&end_data_table();
1.1 albertel 3447: }
1.10 albertel 3448: }
3449:
1.581 albertel 3450: sub format_previous_attempt_value {
3451: my ($key,$value) = @_;
3452: if ($key =~ /timestamp/) {
3453: $value = &Apache::lonlocal::locallocaltime($value);
3454: } elsif (ref($value) eq 'ARRAY') {
3455: $value = '('.join(', ', @{ $value }).')';
3456: } else {
3457: $value = &unescape($value);
3458: }
3459: return $value;
3460: }
3461:
3462:
1.107 albertel 3463: sub relative_to_absolute {
3464: my ($url,$output)=@_;
3465: my $parser=HTML::TokeParser->new(\$output);
3466: my $token;
3467: my $thisdir=$url;
3468: my @rlinks=();
3469: while ($token=$parser->get_token) {
3470: if ($token->[0] eq 'S') {
3471: if ($token->[1] eq 'a') {
3472: if ($token->[2]->{'href'}) {
3473: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3474: }
3475: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3476: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3477: } elsif ($token->[1] eq 'base') {
3478: $thisdir=$token->[2]->{'href'};
3479: }
3480: }
3481: }
3482: $thisdir=~s-/[^/]*$--;
1.356 albertel 3483: foreach my $link (@rlinks) {
1.726 raeburn 3484: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3485: ($link=~/^\//) ||
3486: ($link=~/^javascript:/i) ||
3487: ($link=~/^mailto:/i) ||
3488: ($link=~/^\#/)) {
3489: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3490: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3491: }
3492: }
3493: # -------------------------------------------------- Deal with Applet codebases
3494: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3495: return $output;
3496: }
3497:
1.112 bowersj2 3498: =pod
3499:
1.648 raeburn 3500: =item * &get_student_view()
1.112 bowersj2 3501:
3502: show a snapshot of what student was looking at
3503:
3504: =cut
3505:
1.10 albertel 3506: sub get_student_view {
1.186 albertel 3507: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3508: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3509: my (%form);
1.10 albertel 3510: my @elements=('symb','courseid','domain','username');
3511: foreach my $element (@elements) {
1.186 albertel 3512: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3513: }
1.186 albertel 3514: if (defined($moreenv)) {
3515: %form=(%form,%{$moreenv});
3516: }
1.236 albertel 3517: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3518: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3519: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3520: $userview=~s/\<body[^\>]*\>//gi;
3521: $userview=~s/\<\/body\>//gi;
3522: $userview=~s/\<html\>//gi;
3523: $userview=~s/\<\/html\>//gi;
3524: $userview=~s/\<head\>//gi;
3525: $userview=~s/\<\/head\>//gi;
3526: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3527: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3528: if (wantarray) {
3529: return ($userview,$response);
3530: } else {
3531: return $userview;
3532: }
3533: }
3534:
3535: sub get_student_view_with_retries {
3536: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3537:
3538: my $ok = 0; # True if we got a good response.
3539: my $content;
3540: my $response;
3541:
3542: # Try to get the student_view done. within the retries count:
3543:
3544: do {
3545: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3546: $ok = $response->is_success;
3547: if (!$ok) {
3548: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3549: }
3550: $retries--;
3551: } while (!$ok && ($retries > 0));
3552:
3553: if (!$ok) {
3554: $content = ''; # On error return an empty content.
3555: }
1.651 www 3556: if (wantarray) {
3557: return ($content, $response);
3558: } else {
3559: return $content;
3560: }
1.11 albertel 3561: }
3562:
1.112 bowersj2 3563: =pod
3564:
1.648 raeburn 3565: =item * &get_student_answers()
1.112 bowersj2 3566:
3567: show a snapshot of how student was answering problem
3568:
3569: =cut
3570:
1.11 albertel 3571: sub get_student_answers {
1.100 sakharuk 3572: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3573: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3574: my (%moreenv);
1.11 albertel 3575: my @elements=('symb','courseid','domain','username');
3576: foreach my $element (@elements) {
1.186 albertel 3577: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3578: }
1.186 albertel 3579: $moreenv{'grade_target'}='answer';
3580: %moreenv=(%form,%moreenv);
1.497 raeburn 3581: $feedurl = &Apache::lonnet::clutter($feedurl);
3582: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3583: return $userview;
1.1 albertel 3584: }
1.116 albertel 3585:
3586: =pod
3587:
3588: =item * &submlink()
3589:
1.242 albertel 3590: Inputs: $text $uname $udom $symb $target
1.116 albertel 3591:
3592: Returns: A link to grades.pm such as to see the SUBM view of a student
3593:
3594: =cut
3595:
3596: ###############################################
3597: sub submlink {
1.242 albertel 3598: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3599: if (!($uname && $udom)) {
3600: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3601: &Apache::lonnet::whichuser($symb);
1.116 albertel 3602: if (!$symb) { $symb=$cursymb; }
3603: }
1.254 matthew 3604: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3605: $symb=&escape($symb);
1.242 albertel 3606: if ($target) { $target="target=\"$target\""; }
3607: return '<a href="/adm/grades?&command=submission&'.
3608: 'symb='.$symb.'&student='.$uname.
3609: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3610: }
3611: ##############################################
3612:
3613: =pod
3614:
3615: =item * &pgrdlink()
3616:
3617: Inputs: $text $uname $udom $symb $target
3618:
3619: Returns: A link to grades.pm such as to see the PGRD view of a student
3620:
3621: =cut
3622:
3623: ###############################################
3624: sub pgrdlink {
3625: my $link=&submlink(@_);
3626: $link=~s/(&command=submission)/$1&showgrading=yes/;
3627: return $link;
3628: }
3629: ##############################################
3630:
3631: =pod
3632:
3633: =item * &pprmlink()
3634:
3635: Inputs: $text $uname $udom $symb $target
3636:
3637: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3638: student and a specific resource
1.242 albertel 3639:
3640: =cut
3641:
3642: ###############################################
3643: sub pprmlink {
3644: my ($text,$uname,$udom,$symb,$target)=@_;
3645: if (!($uname && $udom)) {
3646: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3647: &Apache::lonnet::whichuser($symb);
1.242 albertel 3648: if (!$symb) { $symb=$cursymb; }
3649: }
1.254 matthew 3650: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3651: $symb=&escape($symb);
1.242 albertel 3652: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3653: return '<a href="/adm/parmset?command=set&'.
3654: 'symb='.$symb.'&uname='.$uname.
3655: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3656: }
3657: ##############################################
1.37 matthew 3658:
1.112 bowersj2 3659: =pod
3660:
3661: =back
3662:
3663: =cut
3664:
1.37 matthew 3665: ###############################################
1.51 www 3666:
3667:
3668: sub timehash {
1.687 raeburn 3669: my ($thistime) = @_;
3670: my $timezone = &Apache::lonlocal::gettimezone();
3671: my $dt = DateTime->from_epoch(epoch => $thistime)
3672: ->set_time_zone($timezone);
3673: my $wday = $dt->day_of_week();
3674: if ($wday == 7) { $wday = 0; }
3675: return ( 'second' => $dt->second(),
3676: 'minute' => $dt->minute(),
3677: 'hour' => $dt->hour(),
3678: 'day' => $dt->day_of_month(),
3679: 'month' => $dt->month(),
3680: 'year' => $dt->year(),
3681: 'weekday' => $wday,
3682: 'dayyear' => $dt->day_of_year(),
3683: 'dlsav' => $dt->is_dst() );
1.51 www 3684: }
3685:
1.370 www 3686: sub utc_string {
3687: my ($date)=@_;
1.371 www 3688: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3689: }
3690:
1.51 www 3691: sub maketime {
3692: my %th=@_;
1.687 raeburn 3693: my ($epoch_time,$timezone,$dt);
3694: $timezone = &Apache::lonlocal::gettimezone();
3695: eval {
3696: $dt = DateTime->new( year => $th{'year'},
3697: month => $th{'month'},
3698: day => $th{'day'},
3699: hour => $th{'hour'},
3700: minute => $th{'minute'},
3701: second => $th{'second'},
3702: time_zone => $timezone,
3703: );
3704: };
3705: if (!$@) {
3706: $epoch_time = $dt->epoch;
3707: if ($epoch_time) {
3708: return $epoch_time;
3709: }
3710: }
1.51 www 3711: return POSIX::mktime(
3712: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3713: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3714: }
3715:
3716: #########################################
1.51 www 3717:
3718: sub findallcourses {
1.482 raeburn 3719: my ($roles,$uname,$udom) = @_;
1.355 albertel 3720: my %roles;
3721: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3722: my %courses;
1.51 www 3723: my $now=time;
1.482 raeburn 3724: if (!defined($uname)) {
3725: $uname = $env{'user.name'};
3726: }
3727: if (!defined($udom)) {
3728: $udom = $env{'user.domain'};
3729: }
3730: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3731: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3732: if (!%roles) {
3733: %roles = (
3734: cc => 1,
1.907 ! raeburn 3735: co => 1,
1.482 raeburn 3736: in => 1,
3737: ep => 1,
3738: ta => 1,
3739: cr => 1,
3740: st => 1,
3741: );
3742: }
3743: foreach my $entry (keys(%roleshash)) {
3744: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3745: if ($trole =~ /^cr/) {
3746: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3747: } else {
3748: next if (!exists($roles{$trole}));
3749: }
3750: if ($tend) {
3751: next if ($tend < $now);
3752: }
3753: if ($tstart) {
3754: next if ($tstart > $now);
3755: }
3756: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3757: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3758: if ($secpart eq '') {
3759: ($cnum,$role) = split(/_/,$cnumpart);
3760: $sec = 'none';
3761: $realsec = '';
3762: } else {
3763: $cnum = $cnumpart;
3764: ($sec,$role) = split(/_/,$secpart);
3765: $realsec = $sec;
1.490 raeburn 3766: }
1.482 raeburn 3767: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3768: }
3769: } else {
3770: foreach my $key (keys(%env)) {
1.483 albertel 3771: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3772: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3773: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3774: next if ($role eq 'ca' || $role eq 'aa');
3775: next if (%roles && !exists($roles{$role}));
3776: my ($starttime,$endtime)=split(/\./,$env{$key});
3777: my $active=1;
3778: if ($starttime) {
3779: if ($now<$starttime) { $active=0; }
3780: }
3781: if ($endtime) {
3782: if ($now>$endtime) { $active=0; }
3783: }
3784: if ($active) {
3785: if ($sec eq '') {
3786: $sec = 'none';
3787: }
3788: $courses{$cdom.'_'.$cnum}{$sec} =
3789: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3790: }
3791: }
1.51 www 3792: }
3793: }
1.474 raeburn 3794: return %courses;
1.51 www 3795: }
1.37 matthew 3796:
1.54 www 3797: ###############################################
1.474 raeburn 3798:
3799: sub blockcheck {
1.482 raeburn 3800: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3801:
3802: if (!defined($udom)) {
3803: $udom = $env{'user.domain'};
3804: }
3805: if (!defined($uname)) {
3806: $uname = $env{'user.name'};
3807: }
3808:
3809: # If uname and udom are for a course, check for blocks in the course.
3810:
3811: if (&Apache::lonnet::is_course($udom,$uname)) {
3812: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3813: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3814: return ($startblock,$endblock);
3815: }
1.474 raeburn 3816:
1.502 raeburn 3817: my $startblock = 0;
3818: my $endblock = 0;
1.482 raeburn 3819: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3820:
1.490 raeburn 3821: # If uname is for a user, and activity is course-specific, i.e.,
3822: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3823:
1.490 raeburn 3824: if (($activity eq 'boards' || $activity eq 'chat' ||
3825: $activity eq 'groups') && ($env{'request.course.id'})) {
3826: foreach my $key (keys(%live_courses)) {
3827: if ($key ne $env{'request.course.id'}) {
3828: delete($live_courses{$key});
3829: }
3830: }
3831: }
3832:
3833: my $otheruser = 0;
3834: my %own_courses;
3835: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3836: # Resource belongs to user other than current user.
3837: $otheruser = 1;
3838: # Gather courses for current user
3839: %own_courses =
3840: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3841: }
3842:
3843: # Gather active course roles - course coordinator, instructor,
3844: # exam proctor, ta, student, or custom role.
1.474 raeburn 3845:
3846: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3847: my ($cdom,$cnum);
3848: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3849: $cdom = $env{'course.'.$course.'.domain'};
3850: $cnum = $env{'course.'.$course.'.num'};
3851: } else {
1.490 raeburn 3852: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3853: }
3854: my $no_ownblock = 0;
3855: my $no_userblock = 0;
1.533 raeburn 3856: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3857: # Check if current user has 'evb' priv for this
3858: if (defined($own_courses{$course})) {
3859: foreach my $sec (keys(%{$own_courses{$course}})) {
3860: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3861: if ($sec ne 'none') {
3862: $checkrole .= '/'.$sec;
3863: }
3864: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3865: $no_ownblock = 1;
3866: last;
3867: }
3868: }
3869: }
3870: # if they have 'evb' priv and are currently not playing student
3871: next if (($no_ownblock) &&
3872: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3873: }
1.474 raeburn 3874: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3875: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3876: if ($sec ne 'none') {
1.482 raeburn 3877: $checkrole .= '/'.$sec;
1.474 raeburn 3878: }
1.490 raeburn 3879: if ($otheruser) {
3880: # Resource belongs to user other than current user.
3881: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3882: my ($trole,$tdom,$tnum,$tsec);
3883: my $entry = $live_courses{$course}{$sec};
3884: if ($entry =~ /^cr/) {
3885: ($trole,$tdom,$tnum,$tsec) =
3886: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3887: } else {
3888: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3889: }
3890: my ($spec,$area,$trest,%allroles,%userroles);
3891: $area = '/'.$tdom.'/'.$tnum;
3892: $trest = $tnum;
3893: if ($tsec ne '') {
3894: $area .= '/'.$tsec;
3895: $trest .= '/'.$tsec;
3896: }
3897: $spec = $trole.'.'.$area;
3898: if ($trole =~ /^cr/) {
3899: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3900: $tdom,$spec,$trest,$area);
3901: } else {
3902: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3903: $tdom,$spec,$trest,$area);
3904: }
3905: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3906: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3907: if ($1) {
3908: $no_userblock = 1;
3909: last;
3910: }
3911: }
1.490 raeburn 3912: } else {
3913: # Resource belongs to current user
3914: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3915: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3916: $no_ownblock = 1;
3917: last;
3918: }
1.474 raeburn 3919: }
3920: }
3921: # if they have the evb priv and are currently not playing student
1.482 raeburn 3922: next if (($no_ownblock) &&
1.491 albertel 3923: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3924: next if ($no_userblock);
1.474 raeburn 3925:
1.866 kalberla 3926: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3927: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3928:
3929: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3930: if (($start != 0) &&
3931: (($startblock == 0) || ($startblock > $start))) {
3932: $startblock = $start;
3933: }
3934: if (($end != 0) &&
3935: (($endblock == 0) || ($endblock < $end))) {
3936: $endblock = $end;
3937: }
1.490 raeburn 3938: }
3939: return ($startblock,$endblock);
3940: }
3941:
3942: sub get_blocks {
3943: my ($setters,$activity,$cdom,$cnum) = @_;
3944: my $startblock = 0;
3945: my $endblock = 0;
3946: my $course = $cdom.'_'.$cnum;
3947: $setters->{$course} = {};
3948: $setters->{$course}{'staff'} = [];
3949: $setters->{$course}{'times'} = [];
3950: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3951: foreach my $record (keys(%records)) {
3952: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3953: if ($start <= time && $end >= time) {
3954: my ($staff_name,$staff_dom,$title,$blocks) =
3955: &parse_block_record($records{$record});
3956: if ($blocks->{$activity} eq 'on') {
3957: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3958: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3959: if ( ($startblock == 0) || ($startblock > $start) ) {
3960: $startblock = $start;
1.490 raeburn 3961: }
1.491 albertel 3962: if ( ($endblock == 0) || ($endblock < $end) ) {
3963: $endblock = $end;
1.474 raeburn 3964: }
3965: }
3966: }
3967: }
3968: return ($startblock,$endblock);
3969: }
3970:
3971: sub parse_block_record {
3972: my ($record) = @_;
3973: my ($setuname,$setudom,$title,$blocks);
3974: if (ref($record) eq 'HASH') {
3975: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3976: $title = &unescape($record->{'event'});
3977: $blocks = $record->{'blocks'};
3978: } else {
3979: my @data = split(/:/,$record,3);
3980: if (scalar(@data) eq 2) {
3981: $title = $data[1];
3982: ($setuname,$setudom) = split(/@/,$data[0]);
3983: } else {
3984: ($setuname,$setudom,$title) = @data;
3985: }
3986: $blocks = { 'com' => 'on' };
3987: }
3988: return ($setuname,$setudom,$title,$blocks);
3989: }
3990:
1.854 kalberla 3991: sub blocking_status {
3992: my ($activity,$uname,$udom) = @_;
1.867 kalberla 3993: my %setters;
1.890 droeschl 3994:
3995: # check for active blocking
1.867 kalberla 3996: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 3997:
1.890 droeschl 3998: my $blocked = $startblock && $endblock ? 1 : 0;
3999:
4000: # caller just wants to know whether a block is active
4001: if (!wantarray) { return $blocked; }
4002:
4003: # build a link to a popup window containing the details
4004: my $querystring = "?activity=$activity";
4005: # $uname and $udom decide whose portfolio the user is trying to look at
4006: $querystring .= "&udom=$udom" if $udom;
4007: $querystring .= "&uname=$uname" if $uname;
4008:
4009: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4010: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4011: var options = "width=" + w + ",height=" + h + ",";
4012: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4013: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4014: var newWin = window.open(url, wdwName, options);
4015: newWin.focus();
4016: }
1.890 droeschl 4017: END_MYBLOCK
1.854 kalberla 4018:
1.890 droeschl 4019: $output = Apache::lonhtmlcommon::scripttag($output);
4020:
1.854 kalberla 4021: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4022: my $text = mt('Communication Blocked');
4023:
1.867 kalberla 4024: $output .= <<"END_BLOCK";
4025: <div class='LC_comblock'>
1.869 kalberla 4026: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4027: title='$text'>
4028: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4029: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4030: title='$text'>$text</a>
1.867 kalberla 4031: </div>
4032:
4033: END_BLOCK
1.474 raeburn 4034:
1.854 kalberla 4035: return ($blocked, $output);
4036: }
1.490 raeburn 4037:
1.60 matthew 4038: ###############################################
4039:
1.682 raeburn 4040: sub check_ip_acc {
4041: my ($acc)=@_;
4042: &Apache::lonxml::debug("acc is $acc");
4043: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4044: return 1;
4045: }
4046: my $allowed=0;
4047: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4048:
4049: my $name;
4050: foreach my $pattern (split(',',$acc)) {
4051: $pattern =~ s/^\s*//;
4052: $pattern =~ s/\s*$//;
4053: if ($pattern =~ /\*$/) {
4054: #35.8.*
4055: $pattern=~s/\*//;
4056: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4057: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4058: #35.8.3.[34-56]
4059: my $low=$2;
4060: my $high=$3;
4061: $pattern=$1;
4062: if ($ip =~ /^\Q$pattern\E/) {
4063: my $last=(split(/\./,$ip))[3];
4064: if ($last <=$high && $last >=$low) { $allowed=1; }
4065: }
4066: } elsif ($pattern =~ /^\*/) {
4067: #*.msu.edu
4068: $pattern=~s/\*//;
4069: if (!defined($name)) {
4070: use Socket;
4071: my $netaddr=inet_aton($ip);
4072: ($name)=gethostbyaddr($netaddr,AF_INET);
4073: }
4074: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4075: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4076: #127.0.0.1
4077: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4078: } else {
4079: #some.name.com
4080: if (!defined($name)) {
4081: use Socket;
4082: my $netaddr=inet_aton($ip);
4083: ($name)=gethostbyaddr($netaddr,AF_INET);
4084: }
4085: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4086: }
4087: if ($allowed) { last; }
4088: }
4089: return $allowed;
4090: }
4091:
4092: ###############################################
4093:
1.60 matthew 4094: =pod
4095:
1.112 bowersj2 4096: =head1 Domain Template Functions
4097:
4098: =over 4
4099:
4100: =item * &determinedomain()
1.60 matthew 4101:
4102: Inputs: $domain (usually will be undef)
4103:
1.63 www 4104: Returns: Determines which domain should be used for designs
1.60 matthew 4105:
4106: =cut
1.54 www 4107:
1.60 matthew 4108: ###############################################
1.63 www 4109: sub determinedomain {
4110: my $domain=shift;
1.531 albertel 4111: if (! $domain) {
1.60 matthew 4112: # Determine domain if we have not been given one
1.893 raeburn 4113: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4114: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4115: if ($env{'request.role.domain'}) {
4116: $domain=$env{'request.role.domain'};
1.60 matthew 4117: }
4118: }
1.63 www 4119: return $domain;
4120: }
4121: ###############################################
1.517 raeburn 4122:
1.518 albertel 4123: sub devalidate_domconfig_cache {
4124: my ($udom)=@_;
4125: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4126: }
4127:
4128: # ---------------------- Get domain configuration for a domain
4129: sub get_domainconf {
4130: my ($udom) = @_;
4131: my $cachetime=1800;
4132: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4133: if (defined($cached)) { return %{$result}; }
4134:
4135: my %domconfig = &Apache::lonnet::get_dom('configuration',
4136: ['login','rolecolors'],$udom);
1.632 raeburn 4137: my (%designhash,%legacy);
1.518 albertel 4138: if (keys(%domconfig) > 0) {
4139: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4140: if (keys(%{$domconfig{'login'}})) {
4141: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4142: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4143: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4144: $designhash{$udom.'.login.'.$key.'_'.$img} =
4145: $domconfig{'login'}{$key}{$img};
4146: }
4147: } else {
4148: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4149: }
1.632 raeburn 4150: }
4151: } else {
4152: $legacy{'login'} = 1;
1.518 albertel 4153: }
1.632 raeburn 4154: } else {
4155: $legacy{'login'} = 1;
1.518 albertel 4156: }
4157: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4158: if (keys(%{$domconfig{'rolecolors'}})) {
4159: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4160: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4161: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4162: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4163: }
1.518 albertel 4164: }
4165: }
1.632 raeburn 4166: } else {
4167: $legacy{'rolecolors'} = 1;
1.518 albertel 4168: }
1.632 raeburn 4169: } else {
4170: $legacy{'rolecolors'} = 1;
1.518 albertel 4171: }
1.632 raeburn 4172: if (keys(%legacy) > 0) {
4173: my %legacyhash = &get_legacy_domconf($udom);
4174: foreach my $item (keys(%legacyhash)) {
4175: if ($item =~ /^\Q$udom\E\.login/) {
4176: if ($legacy{'login'}) {
4177: $designhash{$item} = $legacyhash{$item};
4178: }
4179: } else {
4180: if ($legacy{'rolecolors'}) {
4181: $designhash{$item} = $legacyhash{$item};
4182: }
1.518 albertel 4183: }
4184: }
4185: }
1.632 raeburn 4186: } else {
4187: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4188: }
4189: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4190: $cachetime);
4191: return %designhash;
4192: }
4193:
1.632 raeburn 4194: sub get_legacy_domconf {
4195: my ($udom) = @_;
4196: my %legacyhash;
4197: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4198: my $designfile = $designdir.'/'.$udom.'.tab';
4199: if (-e $designfile) {
4200: if ( open (my $fh,"<$designfile") ) {
4201: while (my $line = <$fh>) {
4202: next if ($line =~ /^\#/);
4203: chomp($line);
4204: my ($key,$val)=(split(/\=/,$line));
4205: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4206: }
4207: close($fh);
4208: }
4209: }
4210: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4211: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4212: }
4213: return %legacyhash;
4214: }
4215:
1.63 www 4216: =pod
4217:
1.112 bowersj2 4218: =item * &domainlogo()
1.63 www 4219:
4220: Inputs: $domain (usually will be undef)
4221:
4222: Returns: A link to a domain logo, if the domain logo exists.
4223: If the domain logo does not exist, a description of the domain.
4224:
4225: =cut
1.112 bowersj2 4226:
1.63 www 4227: ###############################################
4228: sub domainlogo {
1.517 raeburn 4229: my $domain = &determinedomain(shift);
1.518 albertel 4230: my %designhash = &get_domainconf($domain);
1.517 raeburn 4231: # See if there is a logo
4232: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4233: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4234: if ($imgsrc =~ m{^/(adm|res)/}) {
4235: if ($imgsrc =~ m{^/res/}) {
4236: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4237: &Apache::lonnet::repcopy($local_name);
4238: }
4239: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4240: }
4241: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4242: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4243: return &Apache::lonnet::domain($domain,'description');
1.59 www 4244: } else {
1.60 matthew 4245: return '';
1.59 www 4246: }
4247: }
1.63 www 4248: ##############################################
4249:
4250: =pod
4251:
1.112 bowersj2 4252: =item * &designparm()
1.63 www 4253:
4254: Inputs: $which parameter; $domain (usually will be undef)
4255:
4256: Returns: value of designparamter $which
4257:
4258: =cut
1.112 bowersj2 4259:
1.397 albertel 4260:
1.400 albertel 4261: ##############################################
1.397 albertel 4262: sub designparm {
4263: my ($which,$domain)=@_;
4264: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4265: return $env{'environment.color.'.$which};
1.96 www 4266: }
1.63 www 4267: $domain=&determinedomain($domain);
1.518 albertel 4268: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4269: my $output;
1.517 raeburn 4270: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4271: $output = $domdesign{$domain.'.'.$which};
1.63 www 4272: } else {
1.520 raeburn 4273: $output = $defaultdesign{$which};
4274: }
4275: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4276: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4277: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4278: if ($output =~ m{^/res/}) {
4279: my $local_name = &Apache::lonnet::filelocation('',$output);
4280: &Apache::lonnet::repcopy($local_name);
4281: }
1.520 raeburn 4282: $output = &lonhttpdurl($output);
4283: }
1.63 www 4284: }
1.520 raeburn 4285: return $output;
1.63 www 4286: }
1.59 www 4287:
1.822 bisitz 4288: ##############################################
4289: =pod
4290:
1.832 bisitz 4291: =item * &authorspace()
4292:
4293: Inputs: ./.
4294:
4295: Returns: Path to the Construction Space of the current user's
4296: accessed author space
4297: The author space will be that of the current user
4298: when accessing the own author space
4299: and that of the co-author/assistent co-author
4300: when accessing the co-author's/assistent co-author's
4301: space
4302:
4303: =cut
4304:
4305: sub authorspace {
4306: my $caname = '';
4307: if ($env{'request.role'} =~ /^ca|^aa/) {
4308: (undef,$caname) =
4309: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4310: } else {
4311: $caname = $env{'user.name'};
4312: }
4313: return '/priv/'.$caname.'/';
4314: }
4315:
4316: ##############################################
4317: =pod
4318:
1.822 bisitz 4319: =item * &head_subbox()
4320:
4321: Inputs: $content (contains HTML code with page functions, etc.)
4322:
4323: Returns: HTML div with $content
4324: To be included in page header
4325:
4326: =cut
4327:
4328: sub head_subbox {
4329: my ($content)=@_;
4330: my $output =
1.844 bisitz 4331: '<div id="LC_head_subbox">'
1.822 bisitz 4332: .$content
4333: .'</div>'
4334: }
4335:
4336: ##############################################
4337: =pod
4338:
4339: =item * &CSTR_pageheader()
4340:
4341: Inputs: ./.
4342:
4343: Returns: HTML div with CSTR path and recent box
4344: To be included on Construction Space pages
4345:
4346: =cut
4347:
4348: sub CSTR_pageheader {
4349: # this is for resources; directories have customtitle, and crumbs
4350: # and select recent are created in lonpubdir.pm
4351: my ($uname,$thisdisfn)=
4352: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4353: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4354: $formaction=~s/\/+/\//g;
4355:
4356: my $parentpath = '';
4357: my $lastitem = '';
4358: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4359: $parentpath = $1;
4360: $lastitem = $2;
4361: } else {
4362: $lastitem = $thisdisfn;
4363: }
4364: return
4365: '<div>'
4366: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4367: .'<b>'.&mt('Construction Space:').'</b> '
4368: .'<form name="dirs" method="post" action="'.$formaction
4369: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4370: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4371: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4372: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4373: .'</form>'
4374: .&Apache::lonmenu::constspaceform()
4375: .'</div>';
4376: }
4377:
1.60 matthew 4378: ###############################################
4379: ###############################################
4380:
4381: =pod
4382:
1.112 bowersj2 4383: =back
4384:
1.549 albertel 4385: =head1 HTML Helpers
1.112 bowersj2 4386:
4387: =over 4
4388:
4389: =item * &bodytag()
1.60 matthew 4390:
4391: Returns a uniform header for LON-CAPA web pages.
4392:
4393: Inputs:
4394:
1.112 bowersj2 4395: =over 4
4396:
4397: =item * $title, A title to be displayed on the page.
4398:
4399: =item * $function, the current role (can be undef).
4400:
4401: =item * $addentries, extra parameters for the <body> tag.
4402:
4403: =item * $bodyonly, if defined, only return the <body> tag.
4404:
4405: =item * $domain, if defined, force a given domain.
4406:
4407: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4408: text interface only)
1.60 matthew 4409:
1.814 bisitz 4410: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4411: navigational links
1.317 albertel 4412:
1.338 albertel 4413: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4414:
1.361 albertel 4415: =item * $no_inline_link, if true and in remote mode, don't show the
4416: 'Switch To Inline Menu' link
4417:
1.460 albertel 4418: =item * $args, optional argument valid values are
4419: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4420: inherit_jsmath -> when creating popup window in a page,
4421: should it have jsmath forced on by the
4422: current page
1.460 albertel 4423:
1.112 bowersj2 4424: =back
4425:
1.60 matthew 4426: Returns: A uniform header for LON-CAPA web pages.
4427: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4428: If $bodyonly is undef or zero, an html string containing a <body> tag and
4429: other decorations will be returned.
4430:
4431: =cut
4432:
1.54 www 4433: sub bodytag {
1.831 bisitz 4434: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4435: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4436:
1.460 albertel 4437: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4438:
1.183 matthew 4439: $function = &get_users_function() if (!$function);
1.339 albertel 4440: my $img = &designparm($function.'.img',$domain);
4441: my $font = &designparm($function.'.font',$domain);
4442: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4443:
1.803 bisitz 4444: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4445: 'bgcolor' => $pgbg,
1.339 albertel 4446: 'text' => $font,
4447: 'alink' => &designparm($function.'.alink',$domain),
4448: 'vlink' => &designparm($function.'.vlink',$domain),
4449: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4450: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4451:
1.63 www 4452: # role and realm
1.378 raeburn 4453: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4454: if ($role eq 'ca') {
1.479 albertel 4455: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4456: $realm = &plainname($rname,$rdom);
1.378 raeburn 4457: }
1.55 www 4458: # realm
1.258 albertel 4459: if ($env{'request.course.id'}) {
1.378 raeburn 4460: if ($env{'request.role'} !~ /^cr/) {
4461: $role = &Apache::lonnet::plaintext($role,&course_type());
4462: }
1.898 raeburn 4463: if ($env{'request.course.sec'}) {
4464: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4465: }
1.359 albertel 4466: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4467: } else {
4468: $role = &Apache::lonnet::plaintext($role);
1.54 www 4469: }
1.433 albertel 4470:
1.359 albertel 4471: if (!$realm) { $realm=' '; }
1.55 www 4472: # Set messages
1.60 matthew 4473: my $messages=&domainlogo($domain);
1.330 albertel 4474:
1.438 albertel 4475: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4476:
1.101 www 4477: # construct main body tag
1.359 albertel 4478: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4479: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4480:
1.530 albertel 4481: if ($bodyonly) {
1.60 matthew 4482: return $bodytag;
1.798 tempelho 4483: }
1.359 albertel 4484:
1.410 albertel 4485: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4486: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4487: undef($role);
1.434 albertel 4488: } else {
4489: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4490: }
1.359 albertel 4491:
1.762 bisitz 4492: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4493: #
4494: # Extra info if you are the DC
4495: my $dc_info = '';
4496: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4497: $env{'course.'.$env{'request.course.id'}.
4498: '.domain'}.'/'})) {
4499: my $cid = $env{'request.course.id'};
4500: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4501: $dc_info =~ s/\s+$//;
1.359 albertel 4502: $dc_info = '('.$dc_info.')';
4503: }
4504:
1.898 raeburn 4505: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4506: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4507:
1.837 bisitz 4508: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4509: # No Remote
1.903 droeschl 4510: if ($no_nav_bar) { return $bodytag; }
4511:
4512: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4513:
4514: # if ($env{'request.state'} eq 'construct') {
4515: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4516: # }
4517:
4518: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4519: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
1.359 albertel 4520:
1.903 droeschl 4521: if ( $env{'form.inhibitmenu'} eq 'yes'
4522: || $ENV{'REQUEST_URI'} eq '/adm/logout'
4523: || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.359 albertel 4524:
1.903 droeschl 4525: return $bodytag;
4526: }
1.894 droeschl 4527:
1.903 droeschl 4528: $bodytag .= Apache::lonhtmlcommon::scripttag(
4529: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4530:
1.903 droeschl 4531: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4532:
1.903 droeschl 4533: #don't show menus for public users
4534: if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
4535: $bodytag .= Apache::lonmenu::secondary_menu();
4536: $bodytag .= Apache::lonmenu::serverform();
4537: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4538: $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
4539: }else{
4540: # this is to seperate menu from content when there's no secondary
4541: # menu. Especially needed for public accessible ressources.
4542: $bodytag .= '<hr style="clear:both" />';
4543: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4544: }
1.903 droeschl 4545:
4546: #SD testing
4547: #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
1.235 raeburn 4548: return $bodytag;
1.94 www 4549: }
1.95 www 4550:
1.93 www 4551: #
1.95 www 4552: # Top frame rendering, Remote is up
1.93 www 4553: #
1.359 albertel 4554:
1.517 raeburn 4555: my $imgsrc = $img;
4556: if ($img =~ /^\/adm/) {
1.575 albertel 4557: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4558: }
4559: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4560:
1.305 www 4561: # Explicit link to get inline menu
1.361 albertel 4562: my $menu= ($no_inline_link?''
1.883 droeschl 4563: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.853 droeschl 4564: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4565: <em>$realm</em> $dc_info </div>
1.897 wenzelju 4566: <ol class="LC_primary_menu LC_right">
1.853 droeschl 4567: <li>$menu</li>
4568: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4569: #
1.94 www 4570: return(<<ENDBODY);
1.60 matthew 4571: $bodytag
1.359 albertel 4572: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4573: <tr><td>$upperleft</td>
4574: <td>$messages </td>
1.54 www 4575: </tr>
1.359 albertel 4576: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4577: </tr>
1.356 albertel 4578: </table>
1.54 www 4579: ENDBODY
1.182 matthew 4580: }
4581:
1.330 albertel 4582: sub make_attr_string {
4583: my ($register,$attr_ref) = @_;
4584:
4585: if ($attr_ref && !ref($attr_ref)) {
4586: die("addentries Must be a hash ref ".
4587: join(':',caller(1))." ".
4588: join(':',caller(0))." ");
4589: }
4590:
4591: if ($register) {
1.339 albertel 4592: my ($on_load,$on_unload);
4593: foreach my $key (keys(%{$attr_ref})) {
4594: if (lc($key) eq 'onload') {
4595: $on_load.=$attr_ref->{$key}.';';
4596: delete($attr_ref->{$key});
4597:
4598: } elsif (lc($key) eq 'onunload') {
4599: $on_unload.=$attr_ref->{$key}.';';
4600: delete($attr_ref->{$key});
4601: }
4602: }
4603: $attr_ref->{'onload'} =
4604: &Apache::lonmenu::loadevents(). $on_load;
4605: $attr_ref->{'onunload'}=
4606: &Apache::lonmenu::unloadevents().$on_unload;
4607: }
4608:
4609: # Accessibility font enhance
4610: if ($env{'browser.fontenhance'} eq 'on') {
4611: my $style;
4612: foreach my $key (keys(%{$attr_ref})) {
4613: if (lc($key) eq 'style') {
4614: $style.=$attr_ref->{$key}.';';
4615: delete($attr_ref->{$key});
4616: }
4617: }
4618: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4619: }
1.339 albertel 4620:
1.330 albertel 4621: my $attr_string;
4622: foreach my $attr (keys(%$attr_ref)) {
4623: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4624: }
4625: return $attr_string;
4626: }
4627:
4628:
1.182 matthew 4629: ###############################################
1.251 albertel 4630: ###############################################
4631:
4632: =pod
4633:
4634: =item * &endbodytag()
4635:
4636: Returns a uniform footer for LON-CAPA web pages.
4637:
1.635 raeburn 4638: Inputs: 1 - optional reference to an args hash
4639: If in the hash, key for noredirectlink has a value which evaluates to true,
4640: a 'Continue' link is not displayed if the page contains an
4641: internal redirect in the <head></head> section,
4642: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4643:
4644: =cut
4645:
4646: sub endbodytag {
1.635 raeburn 4647: my ($args) = @_;
1.251 albertel 4648: my $endbodytag='</body>';
1.269 albertel 4649: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4650: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4651: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4652: $endbodytag=
4653: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4654: &mt('Continue').'</a>'.
4655: $endbodytag;
4656: }
1.315 albertel 4657: }
1.251 albertel 4658: return $endbodytag;
4659: }
4660:
1.352 albertel 4661: =pod
4662:
4663: =item * &standard_css()
4664:
4665: Returns a style sheet
4666:
4667: Inputs: (all optional)
4668: domain -> force to color decorate a page for a specific
4669: domain
4670: function -> force usage of a specific rolish color scheme
4671: bgcolor -> override the default page bgcolor
4672:
4673: =cut
4674:
1.343 albertel 4675: sub standard_css {
1.345 albertel 4676: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4677: $function = &get_users_function() if (!$function);
4678: my $img = &designparm($function.'.img', $domain);
4679: my $tabbg = &designparm($function.'.tabbg', $domain);
4680: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4681: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4682: #second colour for later usage
1.345 albertel 4683: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4684: my $pgbg_or_bgcolor =
4685: $bgcolor ||
1.352 albertel 4686: &designparm($function.'.pgbg', $domain);
1.382 albertel 4687: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4688: my $alink = &designparm($function.'.alink', $domain);
4689: my $vlink = &designparm($function.'.vlink', $domain);
4690: my $link = &designparm($function.'.link', $domain);
4691:
1.704 muellerd 4692: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4693: my $bgcol = &designparm('login.bgcol',$domain);
4694: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4695:
1.602 albertel 4696: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4697: my $mono = 'monospace';
1.850 bisitz 4698: my $data_table_head = $sidebg;
4699: my $data_table_light = '#FAFAFA';
4700: my $data_table_dark = '#F0F0F0';
1.470 banghart 4701: my $data_table_darker = '#CCCCCC';
1.349 albertel 4702: my $data_table_highlight = '#FFFF00';
1.352 albertel 4703: my $mail_new = '#FFBB77';
4704: my $mail_new_hover = '#DD9955';
4705: my $mail_read = '#BBBB77';
4706: my $mail_read_hover = '#999944';
4707: my $mail_replied = '#AAAA88';
4708: my $mail_replied_hover = '#888855';
4709: my $mail_other = '#99BBBB';
4710: my $mail_other_hover = '#669999';
1.391 albertel 4711: my $table_header = '#DDDDDD';
1.489 raeburn 4712: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4713: my $lg_border_color = '#C8C8C8';
1.392 albertel 4714:
1.608 albertel 4715: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4716: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4717: : '0 3px 0 4px';
1.448 albertel 4718:
1.523 albertel 4719:
1.343 albertel 4720: return <<END;
1.795 www 4721: body {
4722: font-family: $sans;
4723: line-height:130%;
4724: font-size:0.83em;
4725: color:$font;
4726: }
4727:
4728: a:link, a:visited {
4729: font-size:100%;
4730: }
4731:
4732: a:focus {
4733: color: red;
4734: background: yellow
4735: }
1.698 harmsja 4736:
1.795 www 4737: form, .inline {
4738: display: inline;
4739: }
1.721 harmsja 4740:
1.795 www 4741: .LC_right {
4742: text-align:right;
4743: }
4744:
4745: .LC_middle {
4746: vertical-align:middle;
4747: }
1.721 harmsja 4748:
4749: /* just for tests */
1.754 droeschl 4750: .LC_400Box {width:400px; }
1.721 harmsja 4751: /* end */
4752:
1.778 bisitz 4753: .LC_filename {
4754: font-family: $mono;
4755: white-space:pre;
4756: }
4757:
4758: .LC_fileicon {
4759: border: none;
4760: height: 1.3em;
4761: vertical-align: text-bottom;
4762: margin-right: 0.3em;
4763: text-decoration:none;
4764: }
4765:
1.350 albertel 4766: .LC_error {
4767: color: red;
4768: font-size: larger;
4769: }
1.795 www 4770:
1.457 albertel 4771: .LC_warning,
4772: .LC_diff_removed {
1.733 bisitz 4773: color: red;
1.394 albertel 4774: }
1.532 albertel 4775:
4776: .LC_info,
1.457 albertel 4777: .LC_success,
4778: .LC_diff_added {
1.350 albertel 4779: color: green;
4780: }
1.795 www 4781:
1.802 bisitz 4782: div.LC_confirm_box {
4783: background-color: #FAFAFA;
4784: border: 1px solid $lg_border_color;
4785: margin-right: 0;
4786: padding: 5px;
4787: }
4788:
4789: div.LC_confirm_box .LC_error img,
4790: div.LC_confirm_box .LC_success img {
4791: vertical-align: middle;
4792: }
4793:
1.440 albertel 4794: .LC_icon {
1.771 droeschl 4795: border: none;
1.790 droeschl 4796: vertical-align: middle;
1.771 droeschl 4797: }
4798:
1.543 albertel 4799: .LC_docs_spacer {
4800: width: 25px;
4801: height: 1px;
1.771 droeschl 4802: border: none;
1.543 albertel 4803: }
1.346 albertel 4804:
1.532 albertel 4805: .LC_internal_info {
1.735 bisitz 4806: color: #999999;
1.532 albertel 4807: }
4808:
1.794 www 4809: .LC_discussion {
4810: background: $tabbg;
4811: border: 1px solid black;
4812: margin: 2px;
4813: }
4814:
4815: .LC_disc_action_links_bar {
4816: background: $tabbg;
1.803 bisitz 4817: border: none;
1.795 www 4818: margin: 4px;
1.794 www 4819: }
4820:
4821: .LC_disc_action_left {
4822: text-align: left;
4823: }
4824:
4825: .LC_disc_action_right {
4826: text-align: right;
4827: }
4828:
4829: .LC_disc_new_item {
4830: background: white;
4831: border: 2px solid red;
4832: margin: 2px;
4833: }
4834:
4835: .LC_disc_old_item {
4836: background: white;
4837: border: 1px solid black;
4838: margin: 2px;
4839: }
4840:
1.458 albertel 4841: table.LC_pastsubmission {
4842: border: 1px solid black;
4843: margin: 2px;
4844: }
4845:
1.795 www 4846: table#LC_top_nav,
4847: table#LC_menubuttons,
4848: table#LC_nav_location {
1.345 albertel 4849: width: 100%;
4850: background: $pgbg;
1.392 albertel 4851: border: 2px;
1.402 albertel 4852: border-collapse: separate;
1.803 bisitz 4853: padding: 0;
1.345 albertel 4854: }
1.392 albertel 4855:
1.801 tempelho 4856: table#LC_title_bar a {
4857: color: $fontmenu;
4858: }
1.836 bisitz 4859:
1.807 droeschl 4860: table#LC_title_bar {
1.819 tempelho 4861: clear: both;
1.836 bisitz 4862: display: none;
1.807 droeschl 4863: }
4864:
1.795 www 4865: table#LC_title_bar,
4866: table.LC_breadcrumbs,
1.393 albertel 4867: table#LC_title_bar.LC_with_remote {
1.359 albertel 4868: width: 100%;
1.392 albertel 4869: border-color: $pgbg;
4870: border-style: solid;
4871: border-width: $border;
1.379 albertel 4872: background: $pgbg;
1.801 tempelho 4873: color: $fontmenu;
1.392 albertel 4874: border-collapse: collapse;
1.803 bisitz 4875: padding: 0;
1.819 tempelho 4876: margin: 0;
1.359 albertel 4877: }
1.795 www 4878:
1.359 albertel 4879: table#LC_title_bar td {
4880: background: $tabbg;
4881: }
1.795 www 4882:
1.706 harmsja 4883: table#LC_menubuttons img{
1.803 bisitz 4884: border: none;
1.346 albertel 4885: }
1.795 www 4886:
1.345 albertel 4887: table#LC_top_nav td {
4888: background: $tabbg;
1.803 bisitz 4889: border: none;
1.407 albertel 4890: font-size: small;
1.706 harmsja 4891: vertical-align:top;
4892: padding:2px 5px 2px 5px;
1.345 albertel 4893: }
1.795 www 4894:
4895: table#LC_top_nav td a,
4896: div#LC_top_nav a {
1.345 albertel 4897: color: $font;
4898: }
1.795 www 4899:
1.364 albertel 4900: table#LC_top_nav td.LC_top_nav_logo {
4901: background: $tabbg;
1.432 albertel 4902: text-align: left;
1.408 albertel 4903: white-space: nowrap;
1.432 albertel 4904: width: 31px;
1.408 albertel 4905: }
1.795 www 4906:
1.408 albertel 4907: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4908: border: none;
1.408 albertel 4909: vertical-align: bottom;
1.364 albertel 4910: }
1.795 www 4911:
1.777 tempelho 4912: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4913: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4914: width: 2.0em;
4915: }
1.795 www 4916:
1.442 albertel 4917: table#LC_top_nav td.LC_top_nav_login {
4918: width: 4.0em;
4919: text-align: center;
4920: }
1.795 www 4921:
1.842 droeschl 4922: .LC_breadcrumbs_component {
4923: float: right;
4924: margin: 0 1em;
1.357 albertel 4925: }
1.842 droeschl 4926: .LC_breadcrumbs_component img {
4927: vertical-align: middle;
1.777 tempelho 4928: }
1.795 www 4929:
1.383 albertel 4930: td.LC_table_cell_checkbox {
4931: text-align: center;
4932: }
1.795 www 4933:
1.779 bisitz 4934: table#LC_mainmenu td.LC_mainmenu_column {
4935: vertical-align: top;
1.777 tempelho 4936: }
1.522 albertel 4937:
1.795 www 4938: .LC_fontsize_small {
1.705 tempelho 4939: font-size: 70%;
4940: }
4941:
1.844 bisitz 4942: #LC_breadcrumbs {
1.819 tempelho 4943: clear:both;
4944: background: $sidebg;
1.822 bisitz 4945: border-bottom: 1px solid $lg_border_color;
1.904 droeschl 4946: line-height: 2.5em;
4947: /* SD working here
4948: height: 2.5em;
4949: overflow: hidden; */
1.822 bisitz 4950: margin: 0;
1.819 tempelho 4951: padding: 0;
4952: }
1.862 bisitz 4953:
1.839 droeschl 4954: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4955: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4956: display:none;
4957: }
1.819 tempelho 4958:
1.844 bisitz 4959: #LC_head_subbox {
1.822 bisitz 4960: clear:both;
4961: background: #F8F8F8; /* $sidebg; */
4962: border-bottom: 1px solid $lg_border_color;
4963: margin: 0 0 10px 0;
4964: padding: 5px;
4965: }
4966:
1.795 www 4967: .LC_fontsize_medium {
1.705 tempelho 4968: font-size: 85%;
4969: }
4970:
1.795 www 4971: .LC_fontsize_large {
1.705 tempelho 4972: font-size: 120%;
4973: }
4974:
1.346 albertel 4975: .LC_menubuttons_inline_text {
4976: color: $font;
1.698 harmsja 4977: font-size: 90%;
1.701 harmsja 4978: padding-left:3px;
1.346 albertel 4979: }
4980:
1.526 www 4981: .LC_menubuttons_link {
4982: text-decoration: none;
4983: }
1.795 www 4984:
1.522 albertel 4985: .LC_menubuttons_category {
1.521 www 4986: color: $font;
1.526 www 4987: background: $pgbg;
1.521 www 4988: font-size: larger;
4989: font-weight: bold;
4990: }
4991:
1.346 albertel 4992: td.LC_menubuttons_text {
1.779 bisitz 4993: color: $font;
1.346 albertel 4994: }
1.706 harmsja 4995:
1.346 albertel 4996: .LC_current_location {
4997: background: $tabbg;
4998: }
1.795 www 4999:
1.346 albertel 5000: .LC_new_mail {
1.634 www 5001: background: $tabbg;
1.346 albertel 5002: font-weight: bold;
5003: }
1.347 albertel 5004:
1.795 www 5005: table.LC_data_table,
5006: table.LC_mail_list {
1.347 albertel 5007: border: 1px solid #000000;
1.402 albertel 5008: border-collapse: separate;
1.426 albertel 5009: border-spacing: 1px;
1.610 albertel 5010: background: $pgbg;
1.347 albertel 5011: }
1.795 www 5012:
1.422 albertel 5013: .LC_data_table_dense {
5014: font-size: small;
5015: }
1.795 www 5016:
1.507 raeburn 5017: table.LC_nested_outer {
5018: border: 1px solid #000000;
1.589 raeburn 5019: border-collapse: collapse;
1.803 bisitz 5020: border-spacing: 0;
1.507 raeburn 5021: width: 100%;
5022: }
1.795 www 5023:
1.879 raeburn 5024: table.LC_innerpickbox,
1.507 raeburn 5025: table.LC_nested {
1.803 bisitz 5026: border: none;
1.589 raeburn 5027: border-collapse: collapse;
1.803 bisitz 5028: border-spacing: 0;
1.507 raeburn 5029: width: 100%;
5030: }
1.795 www 5031:
5032: table.LC_data_table tr th,
5033: table.LC_calendar tr th,
5034: table.LC_mail_list tr th,
1.879 raeburn 5035: table.LC_prior_tries tr th,
5036: table.LC_innerpickbox tr th {
1.349 albertel 5037: font-weight: bold;
5038: background-color: $data_table_head;
1.801 tempelho 5039: color:$fontmenu;
1.701 harmsja 5040: font-size:90%;
1.347 albertel 5041: }
1.795 www 5042:
1.879 raeburn 5043: table.LC_innerpickbox tr th,
5044: table.LC_innerpickbox tr td {
5045: vertical-align: top;
5046: }
5047:
1.711 raeburn 5048: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5049: background-color: #CCCCCC;
1.711 raeburn 5050: font-weight: bold;
5051: text-align: left;
5052: }
1.795 www 5053:
1.779 bisitz 5054: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 5055: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5056: background-color: $data_table_light;
1.425 albertel 5057: padding: 2px;
1.900 bisitz 5058: vertical-align: top;
1.347 albertel 5059: }
1.795 www 5060:
1.610 albertel 5061: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 5062: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5063: background-color: $data_table_dark;
1.709 bisitz 5064: padding: 2px;
1.900 bisitz 5065: vertical-align: top;
1.347 albertel 5066: }
1.795 www 5067:
1.425 albertel 5068: table.LC_data_table tr.LC_data_table_highlight td {
5069: background-color: $data_table_darker;
5070: }
1.795 www 5071:
1.639 raeburn 5072: table.LC_data_table tr td.LC_leftcol_header {
5073: background-color: $data_table_head;
5074: font-weight: bold;
5075: }
1.795 www 5076:
1.451 albertel 5077: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5078: table.LC_nested tr.LC_empty_row td {
1.347 albertel 5079: background-color: #FFFFFF;
1.421 albertel 5080: font-weight: bold;
5081: font-style: italic;
5082: text-align: center;
5083: padding: 8px;
1.347 albertel 5084: }
1.795 www 5085:
1.890 droeschl 5086: table.LC_caption {
5087: }
5088:
1.507 raeburn 5089: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5090: padding: 4ex
5091: }
1.795 www 5092:
1.507 raeburn 5093: table.LC_nested_outer tr th {
5094: font-weight: bold;
1.801 tempelho 5095: color:$fontmenu;
1.507 raeburn 5096: background-color: $data_table_head;
1.701 harmsja 5097: font-size: small;
1.507 raeburn 5098: border-bottom: 1px solid #000000;
5099: }
1.795 www 5100:
1.507 raeburn 5101: table.LC_nested_outer tr td.LC_subheader {
5102: background-color: $data_table_head;
5103: font-weight: bold;
5104: font-size: small;
5105: border-bottom: 1px solid #000000;
5106: text-align: right;
1.451 albertel 5107: }
1.795 www 5108:
1.507 raeburn 5109: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5110: background-color: #CCCCCC;
1.451 albertel 5111: font-weight: bold;
5112: font-size: small;
1.507 raeburn 5113: text-align: center;
5114: }
1.795 www 5115:
1.589 raeburn 5116: table.LC_nested tr.LC_info_row td.LC_left_item,
5117: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5118: text-align: left;
1.451 albertel 5119: }
1.795 www 5120:
1.507 raeburn 5121: table.LC_nested td {
1.735 bisitz 5122: background-color: #FFFFFF;
1.451 albertel 5123: font-size: small;
1.507 raeburn 5124: }
1.795 www 5125:
1.507 raeburn 5126: table.LC_nested_outer tr th.LC_right_item,
5127: table.LC_nested tr.LC_info_row td.LC_right_item,
5128: table.LC_nested tr.LC_odd_row td.LC_right_item,
5129: table.LC_nested tr td.LC_right_item {
1.451 albertel 5130: text-align: right;
5131: }
5132:
1.507 raeburn 5133: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5134: background-color: #EEEEEE;
1.451 albertel 5135: }
5136:
1.473 raeburn 5137: table.LC_createuser {
5138: }
5139:
5140: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5141: font-size: small;
1.473 raeburn 5142: }
5143:
5144: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5145: background-color: #CCCCCC;
1.473 raeburn 5146: font-weight: bold;
5147: text-align: center;
5148: }
5149:
1.349 albertel 5150: table.LC_calendar {
5151: border: 1px solid #000000;
5152: border-collapse: collapse;
5153: }
1.795 www 5154:
1.349 albertel 5155: table.LC_calendar_pickdate {
5156: font-size: xx-small;
5157: }
1.795 www 5158:
1.349 albertel 5159: table.LC_calendar tr td {
5160: border: 1px solid #000000;
5161: vertical-align: top;
5162: }
1.795 www 5163:
1.349 albertel 5164: table.LC_calendar tr td.LC_calendar_day_empty {
5165: background-color: $data_table_dark;
5166: }
1.795 www 5167:
1.779 bisitz 5168: table.LC_calendar tr td.LC_calendar_day_current {
5169: background-color: $data_table_highlight;
1.777 tempelho 5170: }
1.795 www 5171:
1.349 albertel 5172: table.LC_mail_list tr.LC_mail_new {
5173: background-color: $mail_new;
5174: }
1.795 www 5175:
1.349 albertel 5176: table.LC_mail_list tr.LC_mail_new:hover {
5177: background-color: $mail_new_hover;
5178: }
1.795 www 5179:
5180: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5181: }
1.795 www 5182:
5183: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5184: }
1.795 www 5185:
1.349 albertel 5186: table.LC_mail_list tr.LC_mail_read {
5187: background-color: $mail_read;
5188: }
1.795 www 5189:
1.349 albertel 5190: table.LC_mail_list tr.LC_mail_read:hover {
5191: background-color: $mail_read_hover;
5192: }
1.795 www 5193:
1.349 albertel 5194: table.LC_mail_list tr.LC_mail_replied {
5195: background-color: $mail_replied;
5196: }
1.795 www 5197:
1.349 albertel 5198: table.LC_mail_list tr.LC_mail_replied:hover {
5199: background-color: $mail_replied_hover;
5200: }
1.795 www 5201:
1.349 albertel 5202: table.LC_mail_list tr.LC_mail_other {
5203: background-color: $mail_other;
5204: }
1.795 www 5205:
1.349 albertel 5206: table.LC_mail_list tr.LC_mail_other:hover {
5207: background-color: $mail_other_hover;
5208: }
1.494 raeburn 5209:
1.777 tempelho 5210: table.LC_data_table tr > td.LC_browser_file,
5211: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5212: background: #AAEE77;
1.389 albertel 5213: }
1.795 www 5214:
1.777 tempelho 5215: table.LC_data_table tr > td.LC_browser_file_locked,
5216: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5217: background: #FFAA99;
1.387 albertel 5218: }
1.795 www 5219:
1.777 tempelho 5220: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5221: background: #888888;
1.779 bisitz 5222: }
1.795 www 5223:
1.777 tempelho 5224: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5225: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5226: background: #F8F866;
1.777 tempelho 5227: }
1.795 www 5228:
1.696 bisitz 5229: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5230: background: #E0E8FF;
1.387 albertel 5231: }
1.696 bisitz 5232:
1.707 bisitz 5233: table.LC_data_table tr > td.LC_roles_is {
5234: /* background: #77FF77; */
5235: }
1.795 www 5236:
1.707 bisitz 5237: table.LC_data_table tr > td.LC_roles_future {
5238: background: #FFFF77;
5239: }
1.795 www 5240:
1.707 bisitz 5241: table.LC_data_table tr > td.LC_roles_will {
5242: background: #FFAA77;
5243: }
1.795 www 5244:
1.707 bisitz 5245: table.LC_data_table tr > td.LC_roles_expired {
5246: background: #FF7777;
5247: }
1.795 www 5248:
1.707 bisitz 5249: table.LC_data_table tr > td.LC_roles_will_not {
5250: background: #AAFF77;
5251: }
1.795 www 5252:
1.707 bisitz 5253: table.LC_data_table tr > td.LC_roles_selected {
5254: background: #11CC55;
5255: }
5256:
1.388 albertel 5257: span.LC_current_location {
1.701 harmsja 5258: font-size:larger;
1.388 albertel 5259: background: $pgbg;
5260: }
1.387 albertel 5261:
1.395 albertel 5262: span.LC_parm_menu_item {
5263: font-size: larger;
5264: }
1.795 www 5265:
1.395 albertel 5266: span.LC_parm_scope_all {
5267: color: red;
5268: }
1.795 www 5269:
1.395 albertel 5270: span.LC_parm_scope_folder {
5271: color: green;
5272: }
1.795 www 5273:
1.395 albertel 5274: span.LC_parm_scope_resource {
5275: color: orange;
5276: }
1.795 www 5277:
1.395 albertel 5278: span.LC_parm_part {
5279: color: blue;
5280: }
1.795 www 5281:
1.395 albertel 5282: span.LC_parm_folder, span.LC_parm_symb {
5283: font-size: x-small;
5284: font-family: $mono;
5285: color: #AAAAAA;
5286: }
5287:
1.795 www 5288: td.LC_parm_overview_level_menu,
5289: td.LC_parm_overview_map_menu,
5290: td.LC_parm_overview_parm_selectors,
5291: td.LC_parm_overview_restrictions {
1.396 albertel 5292: border: 1px solid black;
5293: border-collapse: collapse;
5294: }
1.795 www 5295:
1.396 albertel 5296: table.LC_parm_overview_restrictions td {
5297: border-width: 1px 4px 1px 4px;
5298: border-style: solid;
5299: border-color: $pgbg;
5300: text-align: center;
5301: }
1.795 www 5302:
1.396 albertel 5303: table.LC_parm_overview_restrictions th {
5304: background: $tabbg;
5305: border-width: 1px 4px 1px 4px;
5306: border-style: solid;
5307: border-color: $pgbg;
5308: }
1.795 www 5309:
1.398 albertel 5310: table#LC_helpmenu {
1.803 bisitz 5311: border: none;
1.398 albertel 5312: height: 55px;
1.803 bisitz 5313: border-spacing: 0;
1.398 albertel 5314: }
5315:
5316: table#LC_helpmenu fieldset legend {
5317: font-size: larger;
5318: }
1.795 www 5319:
1.397 albertel 5320: table#LC_helpmenu_links {
5321: width: 100%;
5322: border: 1px solid black;
5323: background: $pgbg;
1.803 bisitz 5324: padding: 0;
1.397 albertel 5325: border-spacing: 1px;
5326: }
1.795 www 5327:
1.397 albertel 5328: table#LC_helpmenu_links tr td {
5329: padding: 1px;
5330: background: $tabbg;
1.399 albertel 5331: text-align: center;
5332: font-weight: bold;
1.397 albertel 5333: }
1.396 albertel 5334:
1.795 www 5335: table#LC_helpmenu_links a:link,
5336: table#LC_helpmenu_links a:visited,
1.397 albertel 5337: table#LC_helpmenu_links a:active {
5338: text-decoration: none;
5339: color: $font;
5340: }
1.795 www 5341:
1.397 albertel 5342: table#LC_helpmenu_links a:hover {
5343: text-decoration: underline;
5344: color: $vlink;
5345: }
1.396 albertel 5346:
1.417 albertel 5347: .LC_chrt_popup_exists {
5348: border: 1px solid #339933;
5349: margin: -1px;
5350: }
1.795 www 5351:
1.417 albertel 5352: .LC_chrt_popup_up {
5353: border: 1px solid yellow;
5354: margin: -1px;
5355: }
1.795 www 5356:
1.417 albertel 5357: .LC_chrt_popup {
5358: border: 1px solid #8888FF;
5359: background: #CCCCFF;
5360: }
1.795 www 5361:
1.421 albertel 5362: table.LC_pick_box {
5363: border-collapse: separate;
5364: background: white;
5365: border: 1px solid black;
5366: border-spacing: 1px;
5367: }
1.795 www 5368:
1.421 albertel 5369: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5370: background: $sidebg;
1.421 albertel 5371: font-weight: bold;
1.900 bisitz 5372: text-align: left;
1.740 bisitz 5373: vertical-align: top;
1.421 albertel 5374: width: 184px;
5375: padding: 8px;
5376: }
1.795 www 5377:
1.579 raeburn 5378: table.LC_pick_box td.LC_pick_box_value {
5379: text-align: left;
5380: padding: 8px;
5381: }
1.795 www 5382:
1.579 raeburn 5383: table.LC_pick_box td.LC_pick_box_select {
5384: text-align: left;
5385: padding: 8px;
5386: }
1.795 www 5387:
1.424 albertel 5388: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5389: padding: 0;
1.421 albertel 5390: height: 1px;
5391: background: black;
5392: }
1.795 www 5393:
1.421 albertel 5394: table.LC_pick_box td.LC_pick_box_submit {
5395: text-align: right;
5396: }
1.795 www 5397:
1.579 raeburn 5398: table.LC_pick_box td.LC_evenrow_value {
5399: text-align: left;
5400: padding: 8px;
5401: background-color: $data_table_light;
5402: }
1.795 www 5403:
1.579 raeburn 5404: table.LC_pick_box td.LC_oddrow_value {
5405: text-align: left;
5406: padding: 8px;
5407: background-color: $data_table_light;
5408: }
1.795 www 5409:
1.579 raeburn 5410: span.LC_helpform_receipt_cat {
5411: font-weight: bold;
5412: }
1.795 www 5413:
1.424 albertel 5414: table.LC_group_priv_box {
5415: background: white;
5416: border: 1px solid black;
5417: border-spacing: 1px;
5418: }
1.795 www 5419:
1.424 albertel 5420: table.LC_group_priv_box td.LC_pick_box_title {
5421: background: $tabbg;
5422: font-weight: bold;
5423: text-align: right;
5424: width: 184px;
5425: }
1.795 www 5426:
1.424 albertel 5427: table.LC_group_priv_box td.LC_groups_fixed {
5428: background: $data_table_light;
5429: text-align: center;
5430: }
1.795 www 5431:
1.424 albertel 5432: table.LC_group_priv_box td.LC_groups_optional {
5433: background: $data_table_dark;
5434: text-align: center;
5435: }
1.795 www 5436:
1.424 albertel 5437: table.LC_group_priv_box td.LC_groups_functionality {
5438: background: $data_table_darker;
5439: text-align: center;
5440: font-weight: bold;
5441: }
1.795 www 5442:
1.424 albertel 5443: table.LC_group_priv td {
5444: text-align: left;
1.803 bisitz 5445: padding: 0;
1.424 albertel 5446: }
5447:
1.421 albertel 5448: table.LC_notify_front_page {
5449: background: white;
5450: border: 1px solid black;
5451: padding: 8px;
5452: }
1.795 www 5453:
1.421 albertel 5454: table.LC_notify_front_page td {
5455: padding: 8px;
5456: }
1.795 www 5457:
1.424 albertel 5458: .LC_navbuttons {
5459: margin: 2ex 0ex 2ex 0ex;
5460: }
1.795 www 5461:
1.423 albertel 5462: .LC_topic_bar {
5463: font-weight: bold;
5464: width: 100%;
5465: background: $tabbg;
5466: vertical-align: middle;
5467: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5468: padding: 3px;
1.423 albertel 5469: }
1.795 www 5470:
1.423 albertel 5471: .LC_topic_bar span {
5472: vertical-align: middle;
5473: }
1.795 www 5474:
1.423 albertel 5475: .LC_topic_bar img {
5476: vertical-align: bottom;
5477: }
1.795 www 5478:
1.423 albertel 5479: table.LC_course_group_status {
5480: margin: 20px;
5481: }
1.795 www 5482:
1.423 albertel 5483: table.LC_status_selector td {
5484: vertical-align: top;
5485: text-align: center;
1.424 albertel 5486: padding: 4px;
5487: }
1.795 www 5488:
1.599 albertel 5489: div.LC_feedback_link {
1.616 albertel 5490: clear: both;
1.829 kalberla 5491: background: $sidebg;
1.779 bisitz 5492: width: 100%;
1.829 kalberla 5493: padding-bottom: 10px;
5494: border: 1px $tabbg solid;
1.833 kalberla 5495: height: 22px;
5496: line-height: 22px;
5497: padding-top: 5px;
5498: }
5499:
5500: div.LC_feedback_link img {
5501: height: 22px;
1.867 kalberla 5502: vertical-align:middle;
1.829 kalberla 5503: }
5504:
5505: div.LC_feedback_link a{
5506: text-decoration: none;
1.489 raeburn 5507: }
1.795 www 5508:
1.867 kalberla 5509: div.LC_comblock {
5510: display:inline;
5511: color:$font;
5512: font-size:90%;
5513: }
5514:
5515: div.LC_feedback_link div.LC_comblock {
5516: padding-left:5px;
5517: }
5518:
5519: div.LC_feedback_link div.LC_comblock a {
5520: color:$font;
5521: }
5522:
1.489 raeburn 5523: span.LC_feedback_link {
1.858 bisitz 5524: /* background: $feedback_link_bg; */
1.599 albertel 5525: font-size: larger;
5526: }
1.795 www 5527:
1.599 albertel 5528: span.LC_message_link {
1.858 bisitz 5529: /* background: $feedback_link_bg; */
1.599 albertel 5530: font-size: larger;
5531: position: absolute;
5532: right: 1em;
1.489 raeburn 5533: }
1.421 albertel 5534:
1.515 albertel 5535: table.LC_prior_tries {
1.524 albertel 5536: border: 1px solid #000000;
5537: border-collapse: separate;
5538: border-spacing: 1px;
1.515 albertel 5539: }
1.523 albertel 5540:
1.515 albertel 5541: table.LC_prior_tries td {
1.524 albertel 5542: padding: 2px;
1.515 albertel 5543: }
1.523 albertel 5544:
5545: .LC_answer_correct {
1.795 www 5546: background: lightgreen;
5547: color: darkgreen;
5548: padding: 6px;
1.523 albertel 5549: }
1.795 www 5550:
1.523 albertel 5551: .LC_answer_charged_try {
1.797 www 5552: background: #FFAAAA;
1.795 www 5553: color: darkred;
5554: padding: 6px;
1.523 albertel 5555: }
1.795 www 5556:
1.779 bisitz 5557: .LC_answer_not_charged_try,
1.523 albertel 5558: .LC_answer_no_grade,
5559: .LC_answer_late {
1.795 www 5560: background: lightyellow;
1.523 albertel 5561: color: black;
1.795 www 5562: padding: 6px;
1.523 albertel 5563: }
1.795 www 5564:
1.523 albertel 5565: .LC_answer_previous {
1.795 www 5566: background: lightblue;
5567: color: darkblue;
5568: padding: 6px;
1.523 albertel 5569: }
1.795 www 5570:
1.779 bisitz 5571: .LC_answer_no_message {
1.777 tempelho 5572: background: #FFFFFF;
5573: color: black;
1.795 www 5574: padding: 6px;
1.779 bisitz 5575: }
1.795 www 5576:
1.779 bisitz 5577: .LC_answer_unknown {
5578: background: orange;
5579: color: black;
1.795 www 5580: padding: 6px;
1.777 tempelho 5581: }
1.795 www 5582:
1.529 albertel 5583: span.LC_prior_numerical,
5584: span.LC_prior_string,
5585: span.LC_prior_custom,
5586: span.LC_prior_reaction,
5587: span.LC_prior_math {
1.523 albertel 5588: font-family: monospace;
5589: white-space: pre;
5590: }
5591:
1.525 albertel 5592: span.LC_prior_string {
5593: font-family: monospace;
5594: white-space: pre;
5595: }
5596:
1.523 albertel 5597: table.LC_prior_option {
5598: width: 100%;
5599: border-collapse: collapse;
5600: }
1.795 www 5601:
5602: table.LC_prior_rank,
5603: table.LC_prior_match {
1.528 albertel 5604: border-collapse: collapse;
5605: }
1.795 www 5606:
1.528 albertel 5607: table.LC_prior_option tr td,
5608: table.LC_prior_rank tr td,
5609: table.LC_prior_match tr td {
1.524 albertel 5610: border: 1px solid #000000;
1.515 albertel 5611: }
5612:
1.855 bisitz 5613: .LC_nobreak {
1.544 albertel 5614: white-space: nowrap;
1.519 raeburn 5615: }
5616:
1.576 raeburn 5617: span.LC_cusr_emph {
5618: font-style: italic;
5619: }
5620:
1.633 raeburn 5621: span.LC_cusr_subheading {
5622: font-weight: normal;
5623: font-size: 85%;
5624: }
5625:
1.545 albertel 5626: table.LC_docs_documents {
5627: background: #BBBBBB;
1.803 bisitz 5628: border-width: 0;
1.545 albertel 5629: border-collapse: collapse;
5630: }
1.795 www 5631:
1.777 tempelho 5632: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5633: border: 2px solid black;
5634: padding: 4px;
1.777 tempelho 5635: }
1.795 www 5636:
1.861 bisitz 5637: div.LC_docs_entry_move {
1.859 bisitz 5638: border: 1px solid #BBBBBB;
1.545 albertel 5639: background: #DDDDDD;
1.861 bisitz 5640: width: 22px;
1.859 bisitz 5641: padding: 1px;
5642: margin: 0;
1.545 albertel 5643: }
5644:
1.861 bisitz 5645: table.LC_data_table tr > td.LC_docs_entry_commands,
5646: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5647: background: #DDDDDD;
5648: font-size: x-small;
5649: }
1.795 www 5650:
1.861 bisitz 5651: .LC_docs_entry_parameter {
5652: white-space: nowrap;
5653: }
5654:
1.544 albertel 5655: .LC_docs_copy {
1.545 albertel 5656: color: #000099;
1.544 albertel 5657: }
1.795 www 5658:
1.544 albertel 5659: .LC_docs_cut {
1.545 albertel 5660: color: #550044;
1.544 albertel 5661: }
1.795 www 5662:
1.544 albertel 5663: .LC_docs_rename {
1.545 albertel 5664: color: #009900;
1.544 albertel 5665: }
1.795 www 5666:
1.544 albertel 5667: .LC_docs_remove {
1.545 albertel 5668: color: #990000;
5669: }
5670:
1.547 albertel 5671: .LC_docs_reinit_warn,
5672: .LC_docs_ext_edit {
5673: font-size: x-small;
5674: }
5675:
1.545 albertel 5676: table.LC_docs_adddocs td,
5677: table.LC_docs_adddocs th {
5678: border: 1px solid #BBBBBB;
5679: padding: 4px;
5680: background: #DDDDDD;
1.543 albertel 5681: }
5682:
1.584 albertel 5683: table.LC_sty_begin {
5684: background: #BBFFBB;
5685: }
1.795 www 5686:
1.584 albertel 5687: table.LC_sty_end {
5688: background: #FFBBBB;
5689: }
5690:
1.589 raeburn 5691: table.LC_double_column {
1.803 bisitz 5692: border-width: 0;
1.589 raeburn 5693: border-collapse: collapse;
5694: width: 100%;
5695: padding: 2px;
5696: }
5697:
5698: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5699: top: 2px;
1.589 raeburn 5700: left: 2px;
5701: width: 47%;
5702: vertical-align: top;
5703: }
5704:
5705: table.LC_double_column tr td.LC_right_col {
5706: top: 2px;
1.779 bisitz 5707: right: 2px;
1.589 raeburn 5708: width: 47%;
5709: vertical-align: top;
5710: }
5711:
1.591 raeburn 5712: div.LC_left_float {
5713: float: left;
5714: padding-right: 5%;
1.597 albertel 5715: padding-bottom: 4px;
1.591 raeburn 5716: }
5717:
5718: div.LC_clear_float_header {
1.597 albertel 5719: padding-bottom: 2px;
1.591 raeburn 5720: }
5721:
5722: div.LC_clear_float_footer {
1.597 albertel 5723: padding-top: 10px;
1.591 raeburn 5724: clear: both;
5725: }
5726:
1.597 albertel 5727: div.LC_grade_show_user {
5728: margin-top: 20px;
5729: border: 1px solid black;
5730: }
1.795 www 5731:
1.597 albertel 5732: div.LC_grade_user_name {
5733: background: #DDDDEE;
5734: border-bottom: 1px solid black;
1.705 tempelho 5735: font-weight: bold;
5736: font-size: large;
1.597 albertel 5737: }
1.795 www 5738:
1.597 albertel 5739: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5740: background: #DDEEDD;
5741: }
5742:
5743: div.LC_grade_show_problem,
5744: div.LC_grade_submissions,
5745: div.LC_grade_message_center,
5746: div.LC_grade_info_links,
5747: div.LC_grade_assign {
5748: margin: 5px;
5749: width: 99%;
5750: background: #FFFFFF;
5751: }
1.795 www 5752:
1.597 albertel 5753: div.LC_grade_show_problem_header,
5754: div.LC_grade_submissions_header,
5755: div.LC_grade_message_center_header,
5756: div.LC_grade_assign_header {
1.705 tempelho 5757: font-weight: bold;
5758: font-size: large;
1.597 albertel 5759: }
1.795 www 5760:
1.597 albertel 5761: div.LC_grade_show_problem_problem,
5762: div.LC_grade_submissions_body,
5763: div.LC_grade_message_center_body,
5764: div.LC_grade_assign_body {
5765: border: 1px solid black;
5766: width: 99%;
5767: background: #FFFFFF;
5768: }
1.795 www 5769:
1.598 albertel 5770: span.LC_grade_check_note {
1.705 tempelho 5771: font-weight: normal;
5772: font-size: medium;
1.598 albertel 5773: display: inline;
5774: position: absolute;
5775: right: 1em;
5776: }
1.597 albertel 5777:
1.613 albertel 5778: table.LC_scantron_action {
5779: width: 100%;
5780: }
1.795 www 5781:
1.613 albertel 5782: table.LC_scantron_action tr th {
1.698 harmsja 5783: font-weight:bold;
5784: font-style:normal;
1.613 albertel 5785: }
1.795 www 5786:
1.779 bisitz 5787: .LC_edit_problem_header,
1.614 albertel 5788: div.LC_edit_problem_footer {
1.705 tempelho 5789: font-weight: normal;
5790: font-size: medium;
1.602 albertel 5791: margin: 2px;
1.600 albertel 5792: }
1.795 www 5793:
1.600 albertel 5794: div.LC_edit_problem_header,
1.602 albertel 5795: div.LC_edit_problem_header div,
1.614 albertel 5796: div.LC_edit_problem_footer,
5797: div.LC_edit_problem_footer div,
1.602 albertel 5798: div.LC_edit_problem_editxml_header,
5799: div.LC_edit_problem_editxml_header div {
1.600 albertel 5800: margin-top: 5px;
5801: }
1.795 www 5802:
1.600 albertel 5803: div.LC_edit_problem_header_title {
1.705 tempelho 5804: font-weight: bold;
5805: font-size: larger;
1.602 albertel 5806: background: $tabbg;
5807: padding: 3px;
5808: }
1.795 www 5809:
1.602 albertel 5810: table.LC_edit_problem_header_title {
1.705 tempelho 5811: font-size: larger;
5812: font-weight: bold;
1.602 albertel 5813: width: 100%;
5814: border-color: $pgbg;
5815: border-style: solid;
5816: border-width: $border;
1.600 albertel 5817: background: $tabbg;
1.602 albertel 5818: border-collapse: collapse;
1.803 bisitz 5819: padding: 0;
1.602 albertel 5820: }
5821:
5822: div.LC_edit_problem_discards {
5823: float: left;
5824: padding-bottom: 5px;
5825: }
1.795 www 5826:
1.602 albertel 5827: div.LC_edit_problem_saves {
5828: float: right;
5829: padding-bottom: 5px;
1.600 albertel 5830: }
1.795 www 5831:
1.679 riegler 5832: img.stift{
1.803 bisitz 5833: border-width: 0;
5834: vertical-align: middle;
1.677 riegler 5835: }
1.680 riegler 5836:
1.681 riegler 5837: table#LC_mainmenu{
5838: margin-top:10px;
5839: width:80%;
5840: }
5841:
1.680 riegler 5842: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5843: vertical-align: top;
5844: width: 45%;
5845: }
1.795 www 5846:
1.779 bisitz 5847: .LC_mainmenu_fieldset_category {
5848: color: $font;
5849: background: $pgbg;
5850: font-size: small;
5851: font-weight: bold;
1.777 tempelho 5852: }
1.795 www 5853:
1.716 raeburn 5854: div.LC_createcourse {
5855: margin: 10px 10px 10px 10px;
5856: }
5857:
1.693 droeschl 5858: /* ---- Remove when done ----
5859: # The following styles is part of the redesign of LON-CAPA and are
5860: # subject to change during this project.
5861: # Don't rely on their current functionality as they might be
5862: # changed or removed.
5863: # --------------------------*/
5864:
1.698 harmsja 5865: a:hover,
1.897 wenzelju 5866: ol.LC_primary_menu a:hover,
1.721 harmsja 5867: ol#LC_MenuBreadcrumbs a:hover,
5868: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5869: ul#LC_secondary_menu a:hover,
1.721 harmsja 5870: .LC_FormSectionClearButton input:hover
1.795 www 5871: ul.LC_TabContent li:hover a {
1.698 harmsja 5872: color:#BF2317;
1.904 droeschl 5873: text-decoration:none;
1.693 droeschl 5874: }
5875:
1.779 bisitz 5876: h1 {
1.813 bisitz 5877: padding: 0;
1.693 droeschl 5878: line-height:130%;
5879: }
1.698 harmsja 5880:
1.795 www 5881: h2,h3,h4,h5,h6 {
1.803 bisitz 5882: margin: 5px 0 5px 0;
5883: padding: 0;
1.721 harmsja 5884: line-height:130%;
1.693 droeschl 5885: }
1.795 www 5886:
5887: .LC_hcell {
1.698 harmsja 5888: padding:3px 15px 3px 15px;
1.803 bisitz 5889: margin: 0;
1.703 harmsja 5890: background-color:$tabbg;
1.801 tempelho 5891: color:$fontmenu;
1.779 bisitz 5892: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5893: }
1.795 www 5894:
1.840 bisitz 5895: .LC_Box > .LC_hcell {
1.847 tempelho 5896: margin: 0 -10px 10px -10px;
1.835 bisitz 5897: }
5898:
1.721 harmsja 5899: .LC_noBorder {
1.803 bisitz 5900: border: 0;
1.698 harmsja 5901: }
1.693 droeschl 5902:
1.761 tempelho 5903: .LC_Right {
5904: float: right;
1.803 bisitz 5905: margin: 0;
5906: padding: 0;
1.761 tempelho 5907: }
5908:
1.721 harmsja 5909: .LC_FormSectionClearButton input {
1.779 bisitz 5910: background-color:transparent;
1.803 bisitz 5911: border: none;
1.698 harmsja 5912: cursor:pointer;
5913: text-decoration:underline;
1.693 droeschl 5914: }
1.763 bisitz 5915:
5916: .LC_help_open_topic {
5917: color: #FFFFFF;
5918: background-color: #EEEEFF;
5919: margin: 1px;
5920: padding: 4px;
5921: border: 1px solid #000033;
5922: white-space: nowrap;
1.783 amueller 5923: /* vertical-align: middle; */
1.759 neumanie 5924: }
1.693 droeschl 5925:
1.698 harmsja 5926: dl,ul,div,fieldset {
1.803 bisitz 5927: margin: 10px 10px 10px 0;
1.806 bisitz 5928: /* overflow: hidden; */
1.693 droeschl 5929: }
1.795 www 5930:
1.838 bisitz 5931: fieldset > legend {
5932: font-weight: bold;
5933: padding: 0 5px 0 5px;
5934: }
5935:
1.813 bisitz 5936: #LC_nav_bar {
1.807 droeschl 5937: float: left;
1.852 droeschl 5938: margin: 0.2em 0 0 0;
1.807 droeschl 5939: }
5940:
1.813 bisitz 5941: #LC_nav_bar em{
1.807 droeschl 5942: font-weight: bold;
5943: font-style: normal;
5944: }
5945:
1.897 wenzelju 5946: ol.LC_primary_menu {
1.807 droeschl 5947: float: right;
1.852 droeschl 5948: margin: 0.2em 0 0 0;
1.807 droeschl 5949: }
5950:
1.852 droeschl 5951: ol#LC_PathBreadcrumbs {
1.803 bisitz 5952: margin: 0;
1.693 droeschl 5953: }
5954:
1.897 wenzelju 5955: ol.LC_primary_menu li {
1.693 droeschl 5956: display: inline;
1.803 bisitz 5957: padding: 5px 5px 0 10px;
1.693 droeschl 5958: vertical-align: top;
5959: }
5960:
1.897 wenzelju 5961: ol.LC_primary_menu li img {
1.693 droeschl 5962: vertical-align: bottom;
5963: }
5964:
1.897 wenzelju 5965: ol.LC_primary_menu a {
1.693 droeschl 5966: font-size: 90%;
5967: color: RGB(80, 80, 80);
5968: text-decoration: none;
5969: }
1.795 www 5970:
1.897 wenzelju 5971: ul#LC_secondary_menu {
1.807 droeschl 5972: clear: both;
1.808 droeschl 5973: color: $fontmenu;
5974: background: $tabbg;
5975: list-style: none;
5976: padding: 0;
5977: margin: 0;
5978: width: 100%;
5979: }
5980:
1.897 wenzelju 5981: ul#LC_secondary_menu li {
1.808 droeschl 5982: font-weight: bold;
5983: line-height: 1.8em;
5984: padding: 0 0.8em;
5985: border-right: 1px solid black;
5986: display: inline;
5987: vertical-align: middle;
1.807 droeschl 5988: }
5989:
1.847 tempelho 5990: ul.LC_TabContent {
1.721 harmsja 5991: display:block;
1.847 tempelho 5992: background: $sidebg;
1.858 bisitz 5993: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5994: list-style:none;
1.870 tempelho 5995: margin: 0 -10px;
1.803 bisitz 5996: padding: 0;
1.693 droeschl 5997: }
5998:
1.795 www 5999: ul.LC_TabContent li,
6000: ul.LC_TabContentBigger li {
1.741 harmsja 6001: float:left;
6002: }
1.795 www 6003:
1.897 wenzelju 6004: ul#LC_secondary_menu li a {
1.808 droeschl 6005: color: $fontmenu;
1.693 droeschl 6006: text-decoration: none;
6007: }
1.795 www 6008:
1.721 harmsja 6009: ul.LC_TabContent {
1.847 tempelho 6010: min-height:1.5em;
1.721 harmsja 6011: }
1.795 www 6012:
6013: ul.LC_TabContent li {
1.741 harmsja 6014: vertical-align:middle;
1.803 bisitz 6015: padding: 0 10px 0 10px;
1.745 ehlerst 6016: background-color:$tabbg;
6017: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 6018: }
1.795 www 6019:
1.847 tempelho 6020: ul.LC_TabContent .right {
6021: float:right;
6022: }
6023:
1.795 www 6024: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 6025: color:rgb(47,47,47);
6026: text-decoration:none;
6027: font-size:95%;
6028: font-weight:bold;
1.761 tempelho 6029: padding-right: 16px;
1.721 harmsja 6030: }
1.795 www 6031:
6032: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 6033: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 6034: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 6035: padding-right: 16px;
1.744 ehlerst 6036: }
1.795 www 6037:
1.870 tempelho 6038: #maincoursedoc {
6039: clear:both;
6040: }
6041:
6042: ul.LC_TabContentBigger {
6043: display:block;
6044: list-style:none;
6045: padding: 0;
6046: }
6047:
1.795 www 6048: ul.LC_TabContentBigger li {
1.870 tempelho 6049: vertical-align:bottom;
6050: height: 30px;
6051: font-size:110%;
6052: font-weight:bold;
6053: color: #737373;
1.841 tempelho 6054: }
6055:
1.870 tempelho 6056:
6057: ul.LC_TabContentBigger li a {
6058: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6059: height: 30px;
6060: line-height: 30px;
6061: text-align: center;
6062: display: block;
6063: text-decoration: none;
1.741 harmsja 6064: }
1.795 www 6065:
1.870 tempelho 6066: ul.LC_TabContentBigger li:hover a,
6067: ul.LC_TabContentBigger li.active a {
6068: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857 tempelho 6069: color:$font;
1.870 tempelho 6070: text-decoration: underline;
1.744 ehlerst 6071: }
1.795 www 6072:
1.870 tempelho 6073:
6074: ul.LC_TabContentBigger li b {
6075: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6076: display: block;
6077: float: left;
6078: padding: 0 30px;
6079: }
6080:
6081: ul.LC_TabContentBigger li:hover b,
6082: ul.LC_TabContentBigger li.active b {
6083: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6084: color:$font;
6085: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6086: }
1.693 droeschl 6087:
1.870 tempelho 6088:
1.862 bisitz 6089: ul.LC_CourseBreadcrumbs {
6090: background: $sidebg;
6091: line-height: 32px;
6092: padding-left: 10px;
6093: margin: 0 0 10px 0;
6094: list-style-position: inside;
6095:
6096: }
6097:
1.795 www 6098: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6099: ol#LC_PathBreadcrumbs {
1.693 droeschl 6100: padding-left: 10px;
1.819 tempelho 6101: margin: 0;
1.693 droeschl 6102: list-style-position: inside;
1.904 droeschl 6103: /* SD working here
6104: white-space: nowrap; */
1.693 droeschl 6105: }
6106:
1.795 www 6107: ol#LC_MenuBreadcrumbs li,
6108: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6109: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 6110: display: inline;
6111: white-space: nowrap;
1.904 droeschl 6112: /* SD working here
6113: white-space: normal; */
1.693 droeschl 6114: }
6115:
1.823 bisitz 6116: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6117: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 6118: text-decoration: none;
6119: font-size:90%;
6120: }
1.795 www 6121:
6122: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6123: text-decoration:none;
6124: font-size:100%;
6125: font-weight:bold;
1.693 droeschl 6126: }
1.795 www 6127:
1.840 bisitz 6128: .LC_Box {
1.835 bisitz 6129: border: solid 1px $lg_border_color;
6130: padding: 0 10px 10px 10px;
1.746 neumanie 6131: }
1.795 www 6132:
6133: .LC_AboutMe_Image {
1.747 neumanie 6134: float:left;
6135: margin-right:10px;
6136: }
1.795 www 6137:
6138: .LC_Clear_AboutMe_Image {
1.747 neumanie 6139: clear:left;
6140: }
1.795 www 6141:
1.721 harmsja 6142: dl.LC_ListStyleClean dt {
1.693 droeschl 6143: padding-right: 5px;
6144: display: table-header-group;
6145: }
6146:
1.721 harmsja 6147: dl.LC_ListStyleClean dd {
1.693 droeschl 6148: display: table-row;
6149: }
6150:
1.721 harmsja 6151: .LC_ListStyleClean,
6152: .LC_ListStyleSimple,
6153: .LC_ListStyleNormal,
1.777 tempelho 6154: .LC_ListStyle_Border,
1.795 www 6155: .LC_ListStyleSpecial {
1.693 droeschl 6156: /*display:block; */
6157: list-style-position: inside;
6158: list-style-type: none;
6159: overflow: hidden;
1.803 bisitz 6160: padding: 0;
1.693 droeschl 6161: }
6162:
1.721 harmsja 6163: .LC_ListStyleSimple li,
6164: .LC_ListStyleSimple dd,
6165: .LC_ListStyleNormal li,
6166: .LC_ListStyleNormal dd,
6167: .LC_ListStyleSpecial li,
1.795 www 6168: .LC_ListStyleSpecial dd {
1.803 bisitz 6169: margin: 0;
1.693 droeschl 6170: padding: 5px 5px 5px 10px;
6171: clear: both;
6172: }
6173:
1.721 harmsja 6174: .LC_ListStyleClean li,
6175: .LC_ListStyleClean dd {
1.803 bisitz 6176: padding-top: 0;
6177: padding-bottom: 0;
1.693 droeschl 6178: }
6179:
1.721 harmsja 6180: .LC_ListStyleSimple dd,
1.795 www 6181: .LC_ListStyleSimple li {
1.698 harmsja 6182: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6183: }
6184:
1.721 harmsja 6185: .LC_ListStyleSpecial li,
6186: .LC_ListStyleSpecial dd {
1.693 droeschl 6187: list-style-type: none;
6188: background-color: RGB(220, 220, 220);
6189: margin-bottom: 4px;
6190: }
6191:
1.721 harmsja 6192: table.LC_SimpleTable {
1.698 harmsja 6193: margin:5px;
6194: border:solid 1px $lg_border_color;
1.795 www 6195: }
1.693 droeschl 6196:
1.721 harmsja 6197: table.LC_SimpleTable tr {
1.803 bisitz 6198: padding: 0;
1.698 harmsja 6199: border:solid 1px $lg_border_color;
1.693 droeschl 6200: }
1.795 www 6201:
6202: table.LC_SimpleTable thead {
1.698 harmsja 6203: background:rgb(220,220,220);
1.693 droeschl 6204: }
6205:
1.721 harmsja 6206: div.LC_columnSection {
1.693 droeschl 6207: display: block;
6208: clear: both;
6209: overflow: hidden;
1.803 bisitz 6210: margin: 0;
1.693 droeschl 6211: }
6212:
1.721 harmsja 6213: div.LC_columnSection>* {
1.693 droeschl 6214: float: left;
1.803 bisitz 6215: margin: 10px 20px 10px 0;
1.747 neumanie 6216: overflow:hidden;
1.693 droeschl 6217: }
1.721 harmsja 6218:
1.694 tempelho 6219: .LC_loginpage_container {
6220: text-align:left;
6221: margin : 0 auto;
1.785 tempelho 6222: width:90%;
1.694 tempelho 6223: padding: 10px;
6224: height: auto;
1.712 muellerd 6225: background-color:#FFFFFF;
1.694 tempelho 6226: border:1px solid #CCCCCC;
6227: }
6228:
6229:
6230: .LC_loginpage_loginContainer {
6231: float:left;
1.712 muellerd 6232: width: 182px;
1.785 tempelho 6233: padding: 2px;
1.712 muellerd 6234: border:1px solid #CCCCCC;
6235: background-color:$loginbg;
1.694 tempelho 6236: }
6237:
1.795 www 6238: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6239: margin-top: 0;
1.712 muellerd 6240: display:block;
6241: background:$bgcol;
6242: color:$textcol;
6243: padding-left:5px;
6244: }
1.785 tempelho 6245:
1.694 tempelho 6246: .LC_loginpage_loginInfo {
6247: float:left;
1.785 tempelho 6248: width:182px;
1.694 tempelho 6249: border:1px solid #CCCCCC;
1.785 tempelho 6250: padding:2px;
1.712 muellerd 6251: }
6252:
1.694 tempelho 6253: .LC_loginpage_space {
1.754 droeschl 6254: clear: both;
6255: margin-bottom: 20px;
1.694 tempelho 6256: border-bottom: 1px solid #CCCCCC;
6257: }
6258:
1.785 tempelho 6259: .LC_loginpage_floatLeft {
6260: float: left;
6261: width: 200px;
6262: margin: 0;
6263: }
6264:
1.795 www 6265: table em {
1.754 droeschl 6266: font-weight: bold;
6267: font-style: normal;
1.748 schulted 6268: }
1.795 www 6269:
1.779 bisitz 6270: table.LC_tableBrowseRes,
1.795 www 6271: table.LC_tableOfContent {
1.769 schulted 6272: border:none;
1.858 bisitz 6273: border-spacing: 1px;
1.754 droeschl 6274: padding: 3px;
6275: background-color: #FFFFFF;
6276: font-size: 90%;
1.753 droeschl 6277: }
1.789 droeschl 6278:
6279: table.LC_tableOfContent{
6280: border-collapse: collapse;
6281: }
6282:
1.771 droeschl 6283: table.LC_tableBrowseRes a,
1.768 schulted 6284: table.LC_tableOfContent a {
1.771 droeschl 6285: background-color: transparent;
1.753 droeschl 6286: text-decoration: none;
6287: }
6288:
1.771 droeschl 6289: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6290: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6291: background-color: #EEEEEE;
1.753 droeschl 6292: }
6293:
1.795 www 6294: table.LC_tableOfContent img {
1.753 droeschl 6295: border: none;
6296: height: 1.3em;
6297: vertical-align: text-bottom;
6298: margin-right: 0.3em;
6299: }
1.757 schulted 6300:
1.795 www 6301: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6302: background-image:url(/res/adm/pages/open-first-problem.gif);
6303: }
6304:
1.795 www 6305: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6306: background-image:url(/res/adm/pages/start-navigation.gif);
6307: }
6308:
1.795 www 6309: a#LC_content_toolbar_closenav {
1.774 ehlerst 6310: background-image:url(/res/adm/pages/close-navigation.gif);
6311: }
6312:
1.795 www 6313: a#LC_content_toolbar_everything {
1.774 ehlerst 6314: background-image:url(/res/adm/pages/show-all.gif);
6315: }
6316:
1.795 www 6317: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6318: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6319: }
6320:
1.795 www 6321: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6322: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6323: }
6324:
1.795 www 6325: a#LC_content_toolbar_changefolder {
1.757 schulted 6326: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6327: }
6328:
1.795 www 6329: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6330: background-image:url(/res/adm/pages/open-all-folders.gif);
6331: }
6332:
1.795 www 6333: ul#LC_toolbar li a:hover {
1.757 schulted 6334: background-position: bottom center;
6335: }
6336:
1.795 www 6337: ul#LC_toolbar {
1.803 bisitz 6338: padding: 0;
1.757 schulted 6339: margin: 2px;
6340: list-style:none;
6341: position:relative;
6342: background-color:white;
6343: }
6344:
1.795 www 6345: ul#LC_toolbar li {
1.757 schulted 6346: border:1px solid white;
1.803 bisitz 6347: padding: 0;
1.757 schulted 6348: margin: 0;
1.795 www 6349: float: left;
1.767 droeschl 6350: display:inline;
1.757 schulted 6351: vertical-align:middle;
1.795 www 6352: }
1.757 schulted 6353:
1.783 amueller 6354:
1.795 www 6355: a.LC_toolbarItem {
1.767 droeschl 6356: display:block;
1.803 bisitz 6357: padding: 0;
6358: margin: 0;
1.757 schulted 6359: height: 32px;
6360: width: 32px;
1.779 bisitz 6361: color:white;
1.803 bisitz 6362: border: none;
1.757 schulted 6363: background-repeat:no-repeat;
6364: background-color:transparent;
6365: }
6366:
1.843 bisitz 6367: ul.LC_funclist li {
1.782 bisitz 6368: float: left;
6369: white-space: nowrap;
6370: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6371: margin: 0 15px 15px 10px;
1.782 bisitz 6372: }
6373:
1.757 schulted 6374:
1.343 albertel 6375: END
6376: }
6377:
1.306 albertel 6378: =pod
6379:
6380: =item * &headtag()
6381:
6382: Returns a uniform footer for LON-CAPA web pages.
6383:
1.307 albertel 6384: Inputs: $title - optional title for the head
6385: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6386: $args - optional arguments
1.319 albertel 6387: force_register - if is true call registerurl so the remote is
6388: informed
1.415 albertel 6389: redirect -> array ref of
6390: 1- seconds before redirect occurs
6391: 2- url to redirect to
6392: 3- whether the side effect should occur
1.315 albertel 6393: (side effect of setting
6394: $env{'internal.head.redirect'} to the url
6395: redirected too)
1.352 albertel 6396: domain -> force to color decorate a page for a specific
6397: domain
6398: function -> force usage of a specific rolish color scheme
6399: bgcolor -> override the default page bgcolor
1.460 albertel 6400: no_auto_mt_title
6401: -> prevent &mt()ing the title arg
1.464 albertel 6402:
1.306 albertel 6403: =cut
6404:
6405: sub headtag {
1.313 albertel 6406: my ($title,$head_extra,$args) = @_;
1.306 albertel 6407:
1.363 albertel 6408: my $function = $args->{'function'} || &get_users_function();
6409: my $domain = $args->{'domain'} || &determinedomain();
6410: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6411: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6412: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6413: #time(),
1.418 albertel 6414: $env{'environment.color.timestamp'},
1.363 albertel 6415: $function,$domain,$bgcolor);
6416:
1.369 www 6417: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6418:
1.308 albertel 6419: my $result =
6420: '<head>'.
1.461 albertel 6421: &font_settings();
1.319 albertel 6422:
1.461 albertel 6423: if (!$args->{'frameset'}) {
6424: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6425: }
1.319 albertel 6426: if ($args->{'force_register'}) {
6427: $result .= &Apache::lonmenu::registerurl(1);
6428: }
1.436 albertel 6429: if (!$args->{'no_nav_bar'}
6430: && !$args->{'only_body'}
6431: && !$args->{'frameset'}) {
6432: $result .= &help_menu_js();
6433: }
1.319 albertel 6434:
1.314 albertel 6435: if (ref($args->{'redirect'})) {
1.414 albertel 6436: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6437: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6438: if (!$inhibit_continue) {
6439: $env{'internal.head.redirect'} = $url;
6440: }
1.313 albertel 6441: $result.=<<ADDMETA
6442: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6443: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6444: ADDMETA
6445: }
1.306 albertel 6446: if (!defined($title)) {
6447: $title = 'The LearningOnline Network with CAPA';
6448: }
1.460 albertel 6449: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6450: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6451: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6452: .$head_extra;
1.306 albertel 6453: return $result;
6454: }
6455:
6456: =pod
6457:
1.340 albertel 6458: =item * &font_settings()
6459:
6460: Returns neccessary <meta> to set the proper encoding
6461:
6462: Inputs: none
6463:
6464: =cut
6465:
6466: sub font_settings {
6467: my $headerstring='';
1.647 www 6468: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6469: $headerstring.=
6470: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6471: }
6472: return $headerstring;
6473: }
6474:
1.341 albertel 6475: =pod
6476:
6477: =item * &xml_begin()
6478:
6479: Returns the needed doctype and <html>
6480:
6481: Inputs: none
6482:
6483: =cut
6484:
6485: sub xml_begin {
6486: my $output='';
6487:
1.592 albertel 6488: if ($env{'internal.start_page'}==1) {
6489: &Apache::lonhtmlcommon::init_htmlareafields();
6490: }
1.342 albertel 6491:
1.341 albertel 6492: if ($env{'browser.mathml'}) {
6493: $output='<?xml version="1.0"?>'
6494: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6495: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6496:
6497: # .'<!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">] >'
6498: .'<!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">'
6499: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6500: .'xmlns="http://www.w3.org/1999/xhtml">';
6501: } else {
1.849 bisitz 6502: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6503: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6504: }
6505: return $output;
6506: }
1.340 albertel 6507:
6508: =pod
6509:
1.306 albertel 6510: =item * &endheadtag()
6511:
6512: Returns a uniform </head> for LON-CAPA web pages.
6513:
6514: Inputs: none
6515:
6516: =cut
6517:
6518: sub endheadtag {
6519: return '</head>';
6520: }
6521:
6522: =pod
6523:
6524: =item * &head()
6525:
6526: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6527:
1.648 raeburn 6528: Inputs:
6529:
6530: =over 4
6531:
6532: $title - optional title for the page
6533:
6534: $head_extra - optional extra HTML to put inside the <head>
6535:
6536: =back
1.405 albertel 6537:
1.306 albertel 6538: =cut
6539:
6540: sub head {
1.325 albertel 6541: my ($title,$head_extra,$args) = @_;
6542: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6543: }
6544:
6545: =pod
6546:
6547: =item * &start_page()
6548:
6549: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6550:
1.648 raeburn 6551: Inputs:
6552:
6553: =over 4
6554:
6555: $title - optional title for the page
6556:
6557: $head_extra - optional extra HTML to incude inside the <head>
6558:
6559: $args - additional optional args supported are:
6560:
6561: =over 8
6562:
6563: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6564: arg on
1.814 bisitz 6565: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6566: add_entries -> additional attributes to add to the <body>
6567: domain -> force to color decorate a page for a
1.317 albertel 6568: specific domain
1.648 raeburn 6569: function -> force usage of a specific rolish color
1.317 albertel 6570: scheme
1.648 raeburn 6571: redirect -> see &headtag()
6572: bgcolor -> override the default page bg color
6573: js_ready -> return a string ready for being used in
1.317 albertel 6574: a javascript writeln
1.648 raeburn 6575: html_encode -> return a string ready for being used in
1.320 albertel 6576: a html attribute
1.648 raeburn 6577: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6578: $forcereg arg
1.648 raeburn 6579: frameset -> if true will start with a <frameset>
1.330 albertel 6580: rather than <body>
1.648 raeburn 6581: skip_phases -> hash ref of
1.338 albertel 6582: head -> skip the <html><head> generation
6583: body -> skip all <body> generation
1.648 raeburn 6584: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6585: 'Switch To Inline Menu' link
1.648 raeburn 6586: no_auto_mt_title -> prevent &mt()ing the title arg
6587: inherit_jsmath -> when creating popup window in a page,
6588: should it have jsmath forced on by the
6589: current page
1.867 kalberla 6590: bread_crumbs -> Array containing breadcrumbs
6591: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6592:
1.648 raeburn 6593: =back
1.460 albertel 6594:
1.648 raeburn 6595: =back
1.562 albertel 6596:
1.306 albertel 6597: =cut
6598:
6599: sub start_page {
1.309 albertel 6600: my ($title,$head_extra,$args) = @_;
1.318 albertel 6601: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6602: my %head_args;
1.352 albertel 6603: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6604: 'bgcolor','frameset','no_nav_bar','only_body',
6605: 'no_auto_mt_title') {
1.319 albertel 6606: if (defined($args->{$arg})) {
1.324 raeburn 6607: $head_args{$arg} = $args->{$arg};
1.319 albertel 6608: }
1.313 albertel 6609: }
1.319 albertel 6610:
1.315 albertel 6611: $env{'internal.start_page'}++;
1.338 albertel 6612: my $result;
6613: if (! exists($args->{'skip_phases'}{'head'}) ) {
6614: $result.=
1.341 albertel 6615: &xml_begin().
1.338 albertel 6616: &headtag($title,$head_extra,\%head_args).&endheadtag();
6617: }
6618:
6619: if (! exists($args->{'skip_phases'}{'body'}) ) {
6620: if ($args->{'frameset'}) {
6621: my $attr_string = &make_attr_string($args->{'force_register'},
6622: $args->{'add_entries'});
6623: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6624: } else {
6625: $result .=
6626: &bodytag($title,
6627: $args->{'function'}, $args->{'add_entries'},
6628: $args->{'only_body'}, $args->{'domain'},
6629: $args->{'force_register'}, $args->{'no_nav_bar'},
6630: $args->{'bgcolor'}, $args->{'no_inline_link'},
6631: $args);
6632: }
1.330 albertel 6633: }
1.338 albertel 6634:
1.315 albertel 6635: if ($args->{'js_ready'}) {
1.713 kaisler 6636: $result = &js_ready($result);
1.315 albertel 6637: }
1.320 albertel 6638: if ($args->{'html_encode'}) {
1.713 kaisler 6639: $result = &html_encode($result);
6640: }
6641:
1.813 bisitz 6642: # Preparation for new and consistent functionlist at top of screen
6643: # if ($args->{'functionlist'}) {
6644: # $result .= &build_functionlist();
6645: #}
6646:
6647: # Don't add anything more if only_body wanted
6648: return $result if $args->{'only_body'};
6649:
6650: #Breadcrumbs
1.758 kaisler 6651: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6652: &Apache::lonhtmlcommon::clear_breadcrumbs();
6653: #if any br links exists, add them to the breadcrumbs
6654: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6655: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6656: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6657: }
6658: }
6659:
6660: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6661: if(exists($args->{'bread_crumbs_component'})){
6662: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6663: }else{
6664: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6665: }
1.320 albertel 6666: }
1.315 albertel 6667: return $result;
1.306 albertel 6668: }
6669:
1.330 albertel 6670:
1.306 albertel 6671: =pod
6672:
6673: =item * &head()
6674:
6675: Returns a complete </body></html> section for LON-CAPA web pages.
6676:
1.315 albertel 6677: Inputs: $args - additional optional args supported are:
6678: js_ready -> return a string ready for being used in
6679: a javascript writeln
1.320 albertel 6680: html_encode -> return a string ready for being used in
6681: a html attribute
1.330 albertel 6682: frameset -> if true will start with a <frameset>
6683: rather than <body>
1.493 albertel 6684: dicsussion -> if true will get discussion from
6685: lonxml::xmlend
6686: (you can pass the target and parser arguments
6687: through optional 'target' and 'parser' args
6688: to this routine)
1.306 albertel 6689:
6690: =cut
6691:
6692: sub end_page {
1.315 albertel 6693: my ($args) = @_;
6694: $env{'internal.end_page'}++;
1.330 albertel 6695: my $result;
1.335 albertel 6696: if ($args->{'discussion'}) {
6697: my ($target,$parser);
6698: if (ref($args->{'discussion'})) {
6699: ($target,$parser) =($args->{'discussion'}{'target'},
6700: $args->{'discussion'}{'parser'});
6701: }
6702: $result .= &Apache::lonxml::xmlend($target,$parser);
6703: }
6704:
1.330 albertel 6705: if ($args->{'frameset'}) {
6706: $result .= '</frameset>';
6707: } else {
1.635 raeburn 6708: $result .= &endbodytag($args);
1.330 albertel 6709: }
6710: $result .= "\n</html>";
6711:
1.315 albertel 6712: if ($args->{'js_ready'}) {
1.317 albertel 6713: $result = &js_ready($result);
1.315 albertel 6714: }
1.335 albertel 6715:
1.320 albertel 6716: if ($args->{'html_encode'}) {
6717: $result = &html_encode($result);
6718: }
1.335 albertel 6719:
1.315 albertel 6720: return $result;
6721: }
6722:
1.320 albertel 6723: sub html_encode {
6724: my ($result) = @_;
6725:
1.322 albertel 6726: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6727:
6728: return $result;
6729: }
1.317 albertel 6730: sub js_ready {
6731: my ($result) = @_;
6732:
1.323 albertel 6733: $result =~ s/[\n\r]/ /xmsg;
6734: $result =~ s/\\/\\\\/xmsg;
6735: $result =~ s/'/\\'/xmsg;
1.372 albertel 6736: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6737:
6738: return $result;
6739: }
6740:
1.315 albertel 6741: sub validate_page {
6742: if ( exists($env{'internal.start_page'})
1.316 albertel 6743: && $env{'internal.start_page'} > 1) {
6744: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6745: $env{'internal.start_page'}.' '.
1.316 albertel 6746: $ENV{'request.filename'});
1.315 albertel 6747: }
6748: if ( exists($env{'internal.end_page'})
1.316 albertel 6749: && $env{'internal.end_page'} > 1) {
6750: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6751: $env{'internal.end_page'}.' '.
1.316 albertel 6752: $env{'request.filename'});
1.315 albertel 6753: }
6754: if ( exists($env{'internal.start_page'})
6755: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6756: &Apache::lonnet::logthis('start_page called without end_page '.
6757: $env{'request.filename'});
1.315 albertel 6758: }
6759: if ( ! exists($env{'internal.start_page'})
6760: && exists($env{'internal.end_page'})) {
1.316 albertel 6761: &Apache::lonnet::logthis('end_page called without start_page'.
6762: $env{'request.filename'});
1.315 albertel 6763: }
1.306 albertel 6764: }
1.315 albertel 6765:
1.318 albertel 6766: sub simple_error_page {
6767: my ($r,$title,$msg) = @_;
6768: my $page =
6769: &Apache::loncommon::start_page($title).
6770: &mt($msg).
6771: &Apache::loncommon::end_page();
6772: if (ref($r)) {
6773: $r->print($page);
1.327 albertel 6774: return;
1.318 albertel 6775: }
6776: return $page;
6777: }
1.347 albertel 6778:
6779: {
1.610 albertel 6780: my @row_count;
1.347 albertel 6781: sub start_data_table {
1.422 albertel 6782: my ($add_class) = @_;
6783: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6784: unshift(@row_count,0);
1.422 albertel 6785: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6786: }
6787:
6788: sub end_data_table {
1.610 albertel 6789: shift(@row_count);
1.389 albertel 6790: return '</table>'."\n";;
1.347 albertel 6791: }
6792:
6793: sub start_data_table_row {
1.422 albertel 6794: my ($add_class) = @_;
1.610 albertel 6795: $row_count[0]++;
6796: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6797: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 6798: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6799: }
1.471 banghart 6800:
6801: sub continue_data_table_row {
6802: my ($add_class) = @_;
1.610 albertel 6803: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6804: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 6805: return '<tr class="'.$css_class.'">'."\n";;
6806: }
1.347 albertel 6807:
6808: sub end_data_table_row {
1.389 albertel 6809: return '</tr>'."\n";;
1.347 albertel 6810: }
1.367 www 6811:
1.421 albertel 6812: sub start_data_table_empty_row {
1.707 bisitz 6813: # $row_count[0]++;
1.421 albertel 6814: return '<tr class="LC_empty_row" >'."\n";;
6815: }
6816:
6817: sub end_data_table_empty_row {
6818: return '</tr>'."\n";;
6819: }
6820:
1.367 www 6821: sub start_data_table_header_row {
1.389 albertel 6822: return '<tr class="LC_header_row">'."\n";;
1.367 www 6823: }
6824:
6825: sub end_data_table_header_row {
1.389 albertel 6826: return '</tr>'."\n";;
1.367 www 6827: }
1.890 droeschl 6828:
6829: sub data_table_caption {
6830: my $caption = shift;
6831: return "<caption class=\"LC_caption\">$caption</caption>";
6832: }
1.347 albertel 6833: }
6834:
1.548 albertel 6835: =pod
6836:
6837: =item * &inhibit_menu_check($arg)
6838:
6839: Checks for a inhibitmenu state and generates output to preserve it
6840:
6841: Inputs: $arg - can be any of
6842: - undef - in which case the return value is a string
6843: to add into arguments list of a uri
6844: - 'input' - in which case the return value is a HTML
6845: <form> <input> field of type hidden to
6846: preserve the value
6847: - a url - in which case the return value is the url with
6848: the neccesary cgi args added to preserve the
6849: inhibitmenu state
6850: - a ref to a url - no return value, but the string is
6851: updated to include the neccessary cgi
6852: args to preserve the inhibitmenu state
6853:
6854: =cut
6855:
6856: sub inhibit_menu_check {
6857: my ($arg) = @_;
6858: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6859: if ($arg eq 'input') {
6860: if ($env{'form.inhibitmenu'}) {
6861: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6862: } else {
6863: return
6864: }
6865: }
6866: if ($env{'form.inhibitmenu'}) {
6867: if (ref($arg)) {
6868: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6869: } elsif ($arg eq '') {
6870: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6871: } else {
6872: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6873: }
6874: }
6875: if (!ref($arg)) {
6876: return $arg;
6877: }
6878: }
6879:
1.251 albertel 6880: ###############################################
1.182 matthew 6881:
6882: =pod
6883:
1.549 albertel 6884: =back
6885:
6886: =head1 User Information Routines
6887:
6888: =over 4
6889:
1.405 albertel 6890: =item * &get_users_function()
1.182 matthew 6891:
6892: Used by &bodytag to determine the current users primary role.
6893: Returns either 'student','coordinator','admin', or 'author'.
6894:
6895: =cut
6896:
6897: ###############################################
6898: sub get_users_function {
1.815 tempelho 6899: my $function = 'norole';
1.818 tempelho 6900: if ($env{'request.role'}=~/^(st)/) {
6901: $function='student';
6902: }
1.907 ! raeburn 6903: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 6904: $function='coordinator';
6905: }
1.258 albertel 6906: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6907: $function='admin';
6908: }
1.826 bisitz 6909: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6910: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6911: $function='author';
6912: }
6913: return $function;
1.54 www 6914: }
1.99 www 6915:
6916: ###############################################
6917:
1.233 raeburn 6918: =pod
6919:
1.821 raeburn 6920: =item * &show_course()
6921:
6922: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6923: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6924:
6925: Inputs:
6926: None
6927:
6928: Outputs:
6929: Scalar: 1 if 'Course' to be used, 0 otherwise.
6930:
6931: =cut
6932:
6933: ###############################################
6934: sub show_course {
6935: my $course = !$env{'user.adv'};
6936: if (!$env{'user.adv'}) {
6937: foreach my $env (keys(%env)) {
6938: next if ($env !~ m/^user\.priv\./);
6939: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6940: $course = 0;
6941: last;
6942: }
6943: }
6944: }
6945: return $course;
6946: }
6947:
6948: ###############################################
6949:
6950: =pod
6951:
1.542 raeburn 6952: =item * &check_user_status()
1.274 raeburn 6953:
6954: Determines current status of supplied role for a
6955: specific user. Roles can be active, previous or future.
6956:
6957: Inputs:
6958: user's domain, user's username, course's domain,
1.375 raeburn 6959: course's number, optional section ID.
1.274 raeburn 6960:
6961: Outputs:
6962: role status: active, previous or future.
6963:
6964: =cut
6965:
6966: sub check_user_status {
1.412 raeburn 6967: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6968: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6969: my @uroles = keys %userinfo;
6970: my $srchstr;
6971: my $active_chk = 'none';
1.412 raeburn 6972: my $now = time;
1.274 raeburn 6973: if (@uroles > 0) {
1.412 raeburn 6974: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6975: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6976: } else {
1.412 raeburn 6977: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6978: }
6979: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6980: my $role_end = 0;
6981: my $role_start = 0;
6982: $active_chk = 'active';
1.412 raeburn 6983: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6984: $role_end = $1;
6985: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6986: $role_start = $1;
1.274 raeburn 6987: }
6988: }
6989: if ($role_start > 0) {
1.412 raeburn 6990: if ($now < $role_start) {
1.274 raeburn 6991: $active_chk = 'future';
6992: }
6993: }
6994: if ($role_end > 0) {
1.412 raeburn 6995: if ($now > $role_end) {
1.274 raeburn 6996: $active_chk = 'previous';
6997: }
6998: }
6999: }
7000: }
7001: return $active_chk;
7002: }
7003:
7004: ###############################################
7005:
7006: =pod
7007:
1.405 albertel 7008: =item * &get_sections()
1.233 raeburn 7009:
7010: Determines all the sections for a course including
7011: sections with students and sections containing other roles.
1.419 raeburn 7012: Incoming parameters:
7013:
7014: 1. domain
7015: 2. course number
7016: 3. reference to array containing roles for which sections should
7017: be gathered (optional).
7018: 4. reference to array containing status types for which sections
7019: should be gathered (optional).
7020:
7021: If the third argument is undefined, sections are gathered for any role.
7022: If the fourth argument is undefined, sections are gathered for any status.
7023: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7024:
1.374 raeburn 7025: Returns section hash (keys are section IDs, values are
7026: number of users in each section), subject to the
1.419 raeburn 7027: optional roles filter, optional status filter
1.233 raeburn 7028:
7029: =cut
7030:
7031: ###############################################
7032: sub get_sections {
1.419 raeburn 7033: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7034: if (!defined($cdom) || !defined($cnum)) {
7035: my $cid = $env{'request.course.id'};
7036:
7037: return if (!defined($cid));
7038:
7039: $cdom = $env{'course.'.$cid.'.domain'};
7040: $cnum = $env{'course.'.$cid.'.num'};
7041: }
7042:
7043: my %sectioncount;
1.419 raeburn 7044: my $now = time;
1.240 albertel 7045:
1.366 albertel 7046: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7047: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7048: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7049: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7050: my $start_index = &Apache::loncoursedata::CL_START();
7051: my $end_index = &Apache::loncoursedata::CL_END();
7052: my $status;
1.366 albertel 7053: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7054: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7055: $data->[$status_index],
7056: $data->[$start_index],
7057: $data->[$end_index]);
7058: if ($stu_status eq 'Active') {
7059: $status = 'active';
7060: } elsif ($end < $now) {
7061: $status = 'previous';
7062: } elsif ($start > $now) {
7063: $status = 'future';
7064: }
7065: if ($section ne '-1' && $section !~ /^\s*$/) {
7066: if ((!defined($possible_status)) || (($status ne '') &&
7067: (grep/^\Q$status\E$/,@{$possible_status}))) {
7068: $sectioncount{$section}++;
7069: }
1.240 albertel 7070: }
7071: }
7072: }
7073: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7074: foreach my $user (sort(keys(%courseroles))) {
7075: if ($user !~ /^(\w{2})/) { next; }
7076: my ($role) = ($user =~ /^(\w{2})/);
7077: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7078: my ($section,$status);
1.240 albertel 7079: if ($role eq 'cr' &&
7080: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7081: $section=$1;
7082: }
7083: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7084: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7085: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7086: if ($end == -1 && $start == -1) {
7087: next; #deleted role
7088: }
7089: if (!defined($possible_status)) {
7090: $sectioncount{$section}++;
7091: } else {
7092: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7093: $status = 'active';
7094: } elsif ($end < $now) {
7095: $status = 'future';
7096: } elsif ($start > $now) {
7097: $status = 'previous';
7098: }
7099: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7100: $sectioncount{$section}++;
7101: }
7102: }
1.233 raeburn 7103: }
1.366 albertel 7104: return %sectioncount;
1.233 raeburn 7105: }
7106:
1.274 raeburn 7107: ###############################################
1.294 raeburn 7108:
7109: =pod
1.405 albertel 7110:
7111: =item * &get_course_users()
7112:
1.275 raeburn 7113: Retrieves usernames:domains for users in the specified course
7114: with specific role(s), and access status.
7115:
7116: Incoming parameters:
1.277 albertel 7117: 1. course domain
7118: 2. course number
7119: 3. access status: users must have - either active,
1.275 raeburn 7120: previous, future, or all.
1.277 albertel 7121: 4. reference to array of permissible roles
1.288 raeburn 7122: 5. reference to array of section restrictions (optional)
7123: 6. reference to results object (hash of hashes).
7124: 7. reference to optional userdata hash
1.609 raeburn 7125: 8. reference to optional statushash
1.630 raeburn 7126: 9. flag if privileged users (except those set to unhide in
7127: course settings) should be excluded
1.609 raeburn 7128: Keys of top level results hash are roles.
1.275 raeburn 7129: Keys of inner hashes are username:domain, with
7130: values set to access type.
1.288 raeburn 7131: Optional userdata hash returns an array with arguments in the
7132: same order as loncoursedata::get_classlist() for student data.
7133:
1.609 raeburn 7134: Optional statushash returns
7135:
1.288 raeburn 7136: Entries for end, start, section and status are blank because
7137: of the possibility of multiple values for non-student roles.
7138:
1.275 raeburn 7139: =cut
1.405 albertel 7140:
1.275 raeburn 7141: ###############################################
1.405 albertel 7142:
1.275 raeburn 7143: sub get_course_users {
1.630 raeburn 7144: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7145: my %idx = ();
1.419 raeburn 7146: my %seclists;
1.288 raeburn 7147:
7148: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7149: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7150: $idx{end} = &Apache::loncoursedata::CL_END();
7151: $idx{start} = &Apache::loncoursedata::CL_START();
7152: $idx{id} = &Apache::loncoursedata::CL_ID();
7153: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7154: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7155: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7156:
1.290 albertel 7157: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7158: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7159: my $now = time;
1.277 albertel 7160: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7161: my $match = 0;
1.412 raeburn 7162: my $secmatch = 0;
1.419 raeburn 7163: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7164: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7165: if ($section eq '') {
7166: $section = 'none';
7167: }
1.291 albertel 7168: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7169: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7170: $secmatch = 1;
7171: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7172: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7173: $secmatch = 1;
7174: }
7175: } else {
1.419 raeburn 7176: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7177: $secmatch = 1;
7178: }
1.290 albertel 7179: }
1.412 raeburn 7180: if (!$secmatch) {
7181: next;
7182: }
1.419 raeburn 7183: }
1.275 raeburn 7184: if (defined($$types{'active'})) {
1.288 raeburn 7185: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7186: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7187: $match = 1;
1.275 raeburn 7188: }
7189: }
7190: if (defined($$types{'previous'})) {
1.609 raeburn 7191: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7192: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7193: $match = 1;
1.275 raeburn 7194: }
7195: }
7196: if (defined($$types{'future'})) {
1.609 raeburn 7197: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7198: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7199: $match = 1;
1.275 raeburn 7200: }
7201: }
1.609 raeburn 7202: if ($match) {
7203: push(@{$seclists{$student}},$section);
7204: if (ref($userdata) eq 'HASH') {
7205: $$userdata{$student} = $$classlist{$student};
7206: }
7207: if (ref($statushash) eq 'HASH') {
7208: $statushash->{$student}{'st'}{$section} = $status;
7209: }
1.288 raeburn 7210: }
1.275 raeburn 7211: }
7212: }
1.412 raeburn 7213: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7214: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7215: my $now = time;
1.609 raeburn 7216: my %displaystatus = ( previous => 'Expired',
7217: active => 'Active',
7218: future => 'Future',
7219: );
1.630 raeburn 7220: my %nothide;
7221: if ($hidepriv) {
7222: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7223: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7224: if ($user !~ /:/) {
7225: $nothide{join(':',split(/[\@]/,$user))}=1;
7226: } else {
7227: $nothide{$user} = 1;
7228: }
7229: }
7230: }
1.439 raeburn 7231: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7232: my $match = 0;
1.412 raeburn 7233: my $secmatch = 0;
1.439 raeburn 7234: my $status;
1.412 raeburn 7235: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7236: $user =~ s/:$//;
1.439 raeburn 7237: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7238: if ($end == -1 || $start == -1) {
7239: next;
7240: }
7241: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7242: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7243: my ($uname,$udom) = split(/:/,$user);
7244: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7245: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7246: $secmatch = 1;
7247: } elsif ($usec eq '') {
1.420 albertel 7248: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7249: $secmatch = 1;
7250: }
7251: } else {
7252: if (grep(/^\Q$usec\E$/,@{$sections})) {
7253: $secmatch = 1;
7254: }
7255: }
7256: if (!$secmatch) {
7257: next;
7258: }
1.288 raeburn 7259: }
1.419 raeburn 7260: if ($usec eq '') {
7261: $usec = 'none';
7262: }
1.275 raeburn 7263: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7264: if ($hidepriv) {
7265: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7266: (!$nothide{$uname.':'.$udom})) {
7267: next;
7268: }
7269: }
1.503 raeburn 7270: if ($end > 0 && $end < $now) {
1.439 raeburn 7271: $status = 'previous';
7272: } elsif ($start > $now) {
7273: $status = 'future';
7274: } else {
7275: $status = 'active';
7276: }
1.277 albertel 7277: foreach my $type (keys(%{$types})) {
1.275 raeburn 7278: if ($status eq $type) {
1.420 albertel 7279: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7280: push(@{$$users{$role}{$user}},$type);
7281: }
1.288 raeburn 7282: $match = 1;
7283: }
7284: }
1.419 raeburn 7285: if (($match) && (ref($userdata) eq 'HASH')) {
7286: if (!exists($$userdata{$uname.':'.$udom})) {
7287: &get_user_info($udom,$uname,\%idx,$userdata);
7288: }
1.420 albertel 7289: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7290: push(@{$seclists{$uname.':'.$udom}},$usec);
7291: }
1.609 raeburn 7292: if (ref($statushash) eq 'HASH') {
7293: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7294: }
1.275 raeburn 7295: }
7296: }
7297: }
7298: }
1.290 albertel 7299: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7300: if ((defined($cdom)) && (defined($cnum))) {
7301: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7302: if ( defined($csettings{'internal.courseowner'}) ) {
7303: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7304: next if ($owner eq '');
7305: my ($ownername,$ownerdom);
7306: if ($owner =~ /^([^:]+):([^:]+)$/) {
7307: $ownername = $1;
7308: $ownerdom = $2;
7309: } else {
7310: $ownername = $owner;
7311: $ownerdom = $cdom;
7312: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7313: }
7314: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7315: if (defined($userdata) &&
1.609 raeburn 7316: !exists($$userdata{$owner})) {
7317: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7318: if (!grep(/^none$/,@{$seclists{$owner}})) {
7319: push(@{$seclists{$owner}},'none');
7320: }
7321: if (ref($statushash) eq 'HASH') {
7322: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7323: }
1.290 albertel 7324: }
1.279 raeburn 7325: }
7326: }
7327: }
1.419 raeburn 7328: foreach my $user (keys(%seclists)) {
7329: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7330: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7331: }
1.275 raeburn 7332: }
7333: return;
7334: }
7335:
1.288 raeburn 7336: sub get_user_info {
7337: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7338: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7339: &plainname($uname,$udom,'lastname');
1.291 albertel 7340: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7341: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7342: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7343: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7344: return;
7345: }
1.275 raeburn 7346:
1.472 raeburn 7347: ###############################################
7348:
7349: =pod
7350:
7351: =item * &get_user_quota()
7352:
7353: Retrieves quota assigned for storage of portfolio files for a user
7354:
7355: Incoming parameters:
7356: 1. user's username
7357: 2. user's domain
7358:
7359: Returns:
1.536 raeburn 7360: 1. Disk quota (in Mb) assigned to student.
7361: 2. (Optional) Type of setting: custom or default
7362: (individually assigned or default for user's
7363: institutional status).
7364: 3. (Optional) - User's institutional status (e.g., faculty, staff
7365: or student - types as defined in localenroll::inst_usertypes
7366: for user's domain, which determines default quota for user.
7367: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7368:
7369: If a value has been stored in the user's environment,
1.536 raeburn 7370: it will return that, otherwise it returns the maximal default
7371: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7372:
7373: =cut
7374:
7375: ###############################################
7376:
7377:
7378: sub get_user_quota {
7379: my ($uname,$udom) = @_;
1.536 raeburn 7380: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7381: if (!defined($udom)) {
7382: $udom = $env{'user.domain'};
7383: }
7384: if (!defined($uname)) {
7385: $uname = $env{'user.name'};
7386: }
7387: if (($udom eq '' || $uname eq '') ||
7388: ($udom eq 'public') && ($uname eq 'public')) {
7389: $quota = 0;
1.536 raeburn 7390: $quotatype = 'default';
7391: $defquota = 0;
1.472 raeburn 7392: } else {
1.536 raeburn 7393: my $inststatus;
1.472 raeburn 7394: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7395: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7396: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7397: } else {
1.536 raeburn 7398: my %userenv =
7399: &Apache::lonnet::get('environment',['portfolioquota',
7400: 'inststatus'],$udom,$uname);
1.472 raeburn 7401: my ($tmp) = keys(%userenv);
7402: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7403: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7404: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7405: } else {
7406: undef(%userenv);
7407: }
7408: }
1.536 raeburn 7409: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7410: if ($quota eq '') {
1.536 raeburn 7411: $quota = $defquota;
7412: $quotatype = 'default';
7413: } else {
7414: $quotatype = 'custom';
1.472 raeburn 7415: }
7416: }
1.536 raeburn 7417: if (wantarray) {
7418: return ($quota,$quotatype,$settingstatus,$defquota);
7419: } else {
7420: return $quota;
7421: }
1.472 raeburn 7422: }
7423:
7424: ###############################################
7425:
7426: =pod
7427:
7428: =item * &default_quota()
7429:
1.536 raeburn 7430: Retrieves default quota assigned for storage of user portfolio files,
7431: given an (optional) user's institutional status.
1.472 raeburn 7432:
7433: Incoming parameters:
7434: 1. domain
1.536 raeburn 7435: 2. (Optional) institutional status(es). This is a : separated list of
7436: status types (e.g., faculty, staff, student etc.)
7437: which apply to the user for whom the default is being retrieved.
7438: If the institutional status string in undefined, the domain
7439: default quota will be returned.
1.472 raeburn 7440:
7441: Returns:
7442: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7443: 2. (Optional) institutional type which determined the value of the
7444: default quota.
1.472 raeburn 7445:
7446: If a value has been stored in the domain's configuration db,
7447: it will return that, otherwise it returns 20 (for backwards
7448: compatibility with domains which have not set up a configuration
7449: db file; the original statically defined portfolio quota was 20 Mb).
7450:
1.536 raeburn 7451: If the user's status includes multiple types (e.g., staff and student),
7452: the largest default quota which applies to the user determines the
7453: default quota returned.
7454:
1.780 raeburn 7455: =back
7456:
1.472 raeburn 7457: =cut
7458:
7459: ###############################################
7460:
7461:
7462: sub default_quota {
1.536 raeburn 7463: my ($udom,$inststatus) = @_;
7464: my ($defquota,$settingstatus);
7465: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7466: ['quotas'],$udom);
7467: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7468: if ($inststatus ne '') {
1.765 raeburn 7469: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7470: foreach my $item (@statuses) {
1.711 raeburn 7471: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7472: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7473: if ($defquota eq '') {
7474: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7475: $settingstatus = $item;
7476: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7477: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7478: $settingstatus = $item;
7479: }
7480: }
7481: } else {
7482: if ($quotahash{'quotas'}{$item} ne '') {
7483: if ($defquota eq '') {
7484: $defquota = $quotahash{'quotas'}{$item};
7485: $settingstatus = $item;
7486: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7487: $defquota = $quotahash{'quotas'}{$item};
7488: $settingstatus = $item;
7489: }
1.536 raeburn 7490: }
7491: }
7492: }
7493: }
7494: if ($defquota eq '') {
1.711 raeburn 7495: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7496: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7497: } else {
7498: $defquota = $quotahash{'quotas'}{'default'};
7499: }
1.536 raeburn 7500: $settingstatus = 'default';
7501: }
7502: } else {
7503: $settingstatus = 'default';
7504: $defquota = 20;
7505: }
7506: if (wantarray) {
7507: return ($defquota,$settingstatus);
1.472 raeburn 7508: } else {
1.536 raeburn 7509: return $defquota;
1.472 raeburn 7510: }
7511: }
7512:
1.384 raeburn 7513: sub get_secgrprole_info {
7514: my ($cdom,$cnum,$needroles,$type) = @_;
7515: my %sections_count = &get_sections($cdom,$cnum);
7516: my @sections = (sort {$a <=> $b} keys(%sections_count));
7517: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7518: my @groups = sort(keys(%curr_groups));
7519: my $allroles = [];
7520: my $rolehash;
7521: my $accesshash = {
7522: active => 'Currently has access',
7523: future => 'Will have future access',
7524: previous => 'Previously had access',
7525: };
7526: if ($needroles) {
7527: $rolehash = {'all' => 'all'};
1.385 albertel 7528: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7529: if (&Apache::lonnet::error(%user_roles)) {
7530: undef(%user_roles);
7531: }
7532: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7533: my ($role)=split(/\:/,$item,2);
7534: if ($role eq 'cr') { next; }
7535: if ($role =~ /^cr/) {
7536: $$rolehash{$role} = (split('/',$role))[3];
7537: } else {
7538: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7539: }
7540: }
7541: foreach my $key (sort(keys(%{$rolehash}))) {
7542: push(@{$allroles},$key);
7543: }
7544: push (@{$allroles},'st');
7545: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7546: }
7547: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7548: }
7549:
1.555 raeburn 7550: sub user_picker {
1.627 raeburn 7551: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7552: my $currdom = $dom;
7553: my %curr_selected = (
7554: srchin => 'dom',
1.580 raeburn 7555: srchby => 'lastname',
1.555 raeburn 7556: );
7557: my $srchterm;
1.625 raeburn 7558: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7559: if ($srch->{'srchby'} ne '') {
7560: $curr_selected{'srchby'} = $srch->{'srchby'};
7561: }
7562: if ($srch->{'srchin'} ne '') {
7563: $curr_selected{'srchin'} = $srch->{'srchin'};
7564: }
7565: if ($srch->{'srchtype'} ne '') {
7566: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7567: }
7568: if ($srch->{'srchdomain'} ne '') {
7569: $currdom = $srch->{'srchdomain'};
7570: }
7571: $srchterm = $srch->{'srchterm'};
7572: }
7573: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7574: 'usr' => 'Search criteria',
1.563 raeburn 7575: 'doma' => 'Domain/institution to search',
1.558 albertel 7576: 'uname' => 'username',
7577: 'lastname' => 'last name',
1.555 raeburn 7578: 'lastfirst' => 'last name, first name',
1.558 albertel 7579: 'crs' => 'in this course',
1.576 raeburn 7580: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7581: 'alc' => 'all LON-CAPA',
1.573 raeburn 7582: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7583: 'exact' => 'is',
7584: 'contains' => 'contains',
1.569 raeburn 7585: 'begins' => 'begins with',
1.571 raeburn 7586: 'youm' => "You must include some text to search for.",
7587: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7588: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7589: 'yomc' => "You must choose a domain when using an institutional directory search.",
7590: 'ymcd' => "You must choose a domain when using a domain search.",
7591: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7592: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7593: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7594: );
1.563 raeburn 7595: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7596: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7597:
7598: my @srchins = ('crs','dom','alc','instd');
7599:
7600: foreach my $option (@srchins) {
7601: # FIXME 'alc' option unavailable until
7602: # loncreateuser::print_user_query_page()
7603: # has been completed.
7604: next if ($option eq 'alc');
1.880 raeburn 7605: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7606: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7607: if ($curr_selected{'srchin'} eq $option) {
7608: $srchinsel .= '
7609: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7610: } else {
7611: $srchinsel .= '
7612: <option value="'.$option.'">'.$lt{$option}.'</option>';
7613: }
1.555 raeburn 7614: }
1.563 raeburn 7615: $srchinsel .= "\n </select>\n";
1.555 raeburn 7616:
7617: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7618: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7619: if ($curr_selected{'srchby'} eq $option) {
7620: $srchbysel .= '
7621: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7622: } else {
7623: $srchbysel .= '
7624: <option value="'.$option.'">'.$lt{$option}.'</option>';
7625: }
7626: }
7627: $srchbysel .= "\n </select>\n";
7628:
7629: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7630: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7631: if ($curr_selected{'srchtype'} eq $option) {
7632: $srchtypesel .= '
7633: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7634: } else {
7635: $srchtypesel .= '
7636: <option value="'.$option.'">'.$lt{$option}.'</option>';
7637: }
7638: }
7639: $srchtypesel .= "\n </select>\n";
7640:
1.558 albertel 7641: my ($newuserscript,$new_user_create);
1.556 raeburn 7642:
7643: if ($forcenewuser) {
1.576 raeburn 7644: if (ref($srch) eq 'HASH') {
7645: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7646: if ($cancreate) {
7647: $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>';
7648: } else {
1.799 bisitz 7649: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7650: my %usertypetext = (
7651: official => 'institutional',
7652: unofficial => 'non-institutional',
7653: );
1.799 bisitz 7654: $new_user_create = '<p class="LC_warning">'
7655: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7656: .' '
7657: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7658: ,'<a href="'.$helplink.'">','</a>')
7659: .'</p><br />';
1.627 raeburn 7660: }
1.576 raeburn 7661: }
7662: }
7663:
1.556 raeburn 7664: $newuserscript = <<"ENDSCRIPT";
7665:
1.570 raeburn 7666: function setSearch(createnew,callingForm) {
1.556 raeburn 7667: if (createnew == 1) {
1.570 raeburn 7668: for (var i=0; i<callingForm.srchby.length; i++) {
7669: if (callingForm.srchby.options[i].value == 'uname') {
7670: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7671: }
7672: }
1.570 raeburn 7673: for (var i=0; i<callingForm.srchin.length; i++) {
7674: if ( callingForm.srchin.options[i].value == 'dom') {
7675: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7676: }
7677: }
1.570 raeburn 7678: for (var i=0; i<callingForm.srchtype.length; i++) {
7679: if (callingForm.srchtype.options[i].value == 'exact') {
7680: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7681: }
7682: }
1.570 raeburn 7683: for (var i=0; i<callingForm.srchdomain.length; i++) {
7684: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7685: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7686: }
7687: }
7688: }
7689: }
7690: ENDSCRIPT
1.558 albertel 7691:
1.556 raeburn 7692: }
7693:
1.555 raeburn 7694: my $output = <<"END_BLOCK";
1.556 raeburn 7695: <script type="text/javascript">
1.824 bisitz 7696: // <![CDATA[
1.570 raeburn 7697: function validateEntry(callingForm) {
1.558 albertel 7698:
1.556 raeburn 7699: var checkok = 1;
1.558 albertel 7700: var srchin;
1.570 raeburn 7701: for (var i=0; i<callingForm.srchin.length; i++) {
7702: if ( callingForm.srchin[i].checked ) {
7703: srchin = callingForm.srchin[i].value;
1.558 albertel 7704: }
7705: }
7706:
1.570 raeburn 7707: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7708: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7709: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7710: var srchterm = callingForm.srchterm.value;
7711: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7712: var msg = "";
7713:
7714: if (srchterm == "") {
7715: checkok = 0;
1.571 raeburn 7716: msg += "$lt{'youm'}\\n";
1.556 raeburn 7717: }
7718:
1.569 raeburn 7719: if (srchtype== 'begins') {
7720: if (srchterm.length < 2) {
7721: checkok = 0;
1.571 raeburn 7722: msg += "$lt{'thte'}\\n";
1.569 raeburn 7723: }
7724: }
7725:
1.556 raeburn 7726: if (srchtype== 'contains') {
7727: if (srchterm.length < 3) {
7728: checkok = 0;
1.571 raeburn 7729: msg += "$lt{'thet'}\\n";
1.556 raeburn 7730: }
7731: }
7732: if (srchin == 'instd') {
7733: if (srchdomain == '') {
7734: checkok = 0;
1.571 raeburn 7735: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7736: }
7737: }
7738: if (srchin == 'dom') {
7739: if (srchdomain == '') {
7740: checkok = 0;
1.571 raeburn 7741: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7742: }
7743: }
7744: if (srchby == 'lastfirst') {
7745: if (srchterm.indexOf(",") == -1) {
7746: checkok = 0;
1.571 raeburn 7747: msg += "$lt{'whus'}\\n";
1.556 raeburn 7748: }
7749: if (srchterm.indexOf(",") == srchterm.length -1) {
7750: checkok = 0;
1.571 raeburn 7751: msg += "$lt{'whse'}\\n";
1.556 raeburn 7752: }
7753: }
7754: if (checkok == 0) {
1.571 raeburn 7755: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7756: return;
7757: }
7758: if (checkok == 1) {
1.570 raeburn 7759: callingForm.submit();
1.556 raeburn 7760: }
7761: }
7762:
7763: $newuserscript
7764:
1.824 bisitz 7765: // ]]>
1.556 raeburn 7766: </script>
1.558 albertel 7767:
7768: $new_user_create
7769:
1.555 raeburn 7770: END_BLOCK
1.558 albertel 7771:
1.876 raeburn 7772: $output .= &Apache::lonhtmlcommon::start_pick_box().
7773: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7774: $domform.
7775: &Apache::lonhtmlcommon::row_closure().
7776: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7777: $srchbysel.
7778: $srchtypesel.
7779: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7780: $srchinsel.
7781: &Apache::lonhtmlcommon::row_closure(1).
7782: &Apache::lonhtmlcommon::end_pick_box().
7783: '<br />';
1.555 raeburn 7784: return $output;
7785: }
7786:
1.612 raeburn 7787: sub user_rule_check {
1.615 raeburn 7788: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7789: my $response;
7790: if (ref($usershash) eq 'HASH') {
7791: foreach my $user (keys(%{$usershash})) {
7792: my ($uname,$udom) = split(/:/,$user);
7793: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7794: my ($id,$newuser);
1.612 raeburn 7795: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7796: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7797: $id = $usershash->{$user}->{'id'};
7798: }
7799: my $inst_response;
7800: if (ref($checks) eq 'HASH') {
7801: if (defined($checks->{'username'})) {
1.615 raeburn 7802: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7803: &Apache::lonnet::get_instuser($udom,$uname);
7804: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7805: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7806: &Apache::lonnet::get_instuser($udom,undef,$id);
7807: }
1.615 raeburn 7808: } else {
7809: ($inst_response,%{$inst_results->{$user}}) =
7810: &Apache::lonnet::get_instuser($udom,$uname);
7811: return;
1.612 raeburn 7812: }
1.615 raeburn 7813: if (!$got_rules->{$udom}) {
1.612 raeburn 7814: my %domconfig = &Apache::lonnet::get_dom('configuration',
7815: ['usercreation'],$udom);
7816: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7817: foreach my $item ('username','id') {
1.612 raeburn 7818: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7819: $$curr_rules{$udom}{$item} =
7820: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7821: }
7822: }
7823: }
1.615 raeburn 7824: $got_rules->{$udom} = 1;
1.585 raeburn 7825: }
1.612 raeburn 7826: foreach my $item (keys(%{$checks})) {
7827: if (ref($$curr_rules{$udom}) eq 'HASH') {
7828: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7829: if (@{$$curr_rules{$udom}{$item}} > 0) {
7830: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7831: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7832: if ($rule_check{$rule}) {
7833: $$rulematch{$user}{$item} = $rule;
7834: if ($inst_response eq 'ok') {
1.615 raeburn 7835: if (ref($inst_results) eq 'HASH') {
7836: if (ref($inst_results->{$user}) eq 'HASH') {
7837: if (keys(%{$inst_results->{$user}}) == 0) {
7838: $$alerts{$item}{$udom}{$uname} = 1;
7839: }
1.612 raeburn 7840: }
7841: }
1.615 raeburn 7842: }
7843: last;
1.585 raeburn 7844: }
7845: }
7846: }
7847: }
7848: }
7849: }
7850: }
7851: }
1.612 raeburn 7852: return;
7853: }
7854:
7855: sub user_rule_formats {
7856: my ($domain,$domdesc,$curr_rules,$check) = @_;
7857: my %text = (
7858: 'username' => 'Usernames',
7859: 'id' => 'IDs',
7860: );
7861: my $output;
7862: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7863: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7864: if (@{$ruleorder} > 0) {
7865: $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>';
7866: foreach my $rule (@{$ruleorder}) {
7867: if (ref($curr_rules) eq 'ARRAY') {
7868: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7869: if (ref($rules->{$rule}) eq 'HASH') {
7870: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7871: $rules->{$rule}{'desc'}.'</li>';
7872: }
7873: }
7874: }
7875: }
7876: $output .= '</ul>';
7877: }
7878: }
7879: return $output;
7880: }
7881:
7882: sub instrule_disallow_msg {
1.615 raeburn 7883: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7884: my $response;
7885: my %text = (
7886: item => 'username',
7887: items => 'usernames',
7888: match => 'matches',
7889: do => 'does',
7890: action => 'a username',
7891: one => 'one',
7892: );
7893: if ($count > 1) {
7894: $text{'item'} = 'usernames';
7895: $text{'match'} ='match';
7896: $text{'do'} = 'do';
7897: $text{'action'} = 'usernames',
7898: $text{'one'} = 'ones';
7899: }
7900: if ($checkitem eq 'id') {
7901: $text{'items'} = 'IDs';
7902: $text{'item'} = 'ID';
7903: $text{'action'} = 'an ID';
1.615 raeburn 7904: if ($count > 1) {
7905: $text{'item'} = 'IDs';
7906: $text{'action'} = 'IDs';
7907: }
1.612 raeburn 7908: }
1.674 bisitz 7909: $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 7910: if ($mode eq 'upload') {
7911: if ($checkitem eq 'username') {
7912: $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'}.");
7913: } elsif ($checkitem eq 'id') {
1.674 bisitz 7914: $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 7915: }
1.669 raeburn 7916: } elsif ($mode eq 'selfcreate') {
7917: if ($checkitem eq 'id') {
7918: $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.");
7919: }
1.615 raeburn 7920: } else {
7921: if ($checkitem eq 'username') {
7922: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7923: } elsif ($checkitem eq 'id') {
7924: $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.");
7925: }
1.612 raeburn 7926: }
7927: return $response;
1.585 raeburn 7928: }
7929:
1.624 raeburn 7930: sub personal_data_fieldtitles {
7931: my %fieldtitles = &Apache::lonlocal::texthash (
7932: id => 'Student/Employee ID',
7933: permanentemail => 'E-mail address',
7934: lastname => 'Last Name',
7935: firstname => 'First Name',
7936: middlename => 'Middle Name',
7937: generation => 'Generation',
7938: gen => 'Generation',
1.765 raeburn 7939: inststatus => 'Affiliation',
1.624 raeburn 7940: );
7941: return %fieldtitles;
7942: }
7943:
1.642 raeburn 7944: sub sorted_inst_types {
7945: my ($dom) = @_;
7946: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7947: my $othertitle = &mt('All users');
7948: if ($env{'request.course.id'}) {
1.668 raeburn 7949: $othertitle = &mt('Any users');
1.642 raeburn 7950: }
7951: my @types;
7952: if (ref($order) eq 'ARRAY') {
7953: @types = @{$order};
7954: }
7955: if (@types == 0) {
7956: if (ref($usertypes) eq 'HASH') {
7957: @types = sort(keys(%{$usertypes}));
7958: }
7959: }
7960: if (keys(%{$usertypes}) > 0) {
7961: $othertitle = &mt('Other users');
7962: }
7963: return ($othertitle,$usertypes,\@types);
7964: }
7965:
1.645 raeburn 7966: sub get_institutional_codes {
7967: my ($settings,$allcourses,$LC_code) = @_;
7968: # Get complete list of course sections to update
7969: my @currsections = ();
7970: my @currxlists = ();
7971: my $coursecode = $$settings{'internal.coursecode'};
7972:
7973: if ($$settings{'internal.sectionnums'} ne '') {
7974: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7975: }
7976:
7977: if ($$settings{'internal.crosslistings'} ne '') {
7978: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7979: }
7980:
7981: if (@currxlists > 0) {
7982: foreach (@currxlists) {
7983: if (m/^([^:]+):(\w*)$/) {
7984: unless (grep/^$1$/,@{$allcourses}) {
7985: push @{$allcourses},$1;
7986: $$LC_code{$1} = $2;
7987: }
7988: }
7989: }
7990: }
7991:
7992: if (@currsections > 0) {
7993: foreach (@currsections) {
7994: if (m/^(\w+):(\w*)$/) {
7995: my $sec = $coursecode.$1;
7996: my $lc_sec = $2;
7997: unless (grep/^$sec$/,@{$allcourses}) {
7998: push @{$allcourses},$sec;
7999: $$LC_code{$sec} = $lc_sec;
8000: }
8001: }
8002: }
8003: }
8004: return;
8005: }
8006:
1.112 bowersj2 8007: =pod
8008:
1.780 raeburn 8009: =head1 Slot Helpers
8010:
8011: =over 4
8012:
8013: =item * sorted_slots()
8014:
8015: Sorts an array of slot names in order of slot start time (earliest first).
8016:
8017: Inputs:
8018:
8019: =over 4
8020:
8021: slotsarr - Reference to array of unsorted slot names.
8022:
8023: slots - Reference to hash of hash, where outer hash keys are slot names.
8024:
1.549 albertel 8025: =back
8026:
1.780 raeburn 8027: Returns:
8028:
8029: =over 4
8030:
8031: sorted - An array of slot names sorted by the start time of the slot.
8032:
8033: =back
8034:
8035: =back
8036:
8037: =cut
8038:
8039:
8040: sub sorted_slots {
8041: my ($slotsarr,$slots) = @_;
8042: my @sorted;
8043: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8044: @sorted =
8045: sort {
8046: if (ref($slots->{$a}) && ref($slots->{$b})) {
8047: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8048: }
8049: if (ref($slots->{$a})) { return -1;}
8050: if (ref($slots->{$b})) { return 1;}
8051: return 0;
8052: } @{$slotsarr};
8053: }
8054: return @sorted;
8055: }
8056:
8057:
8058: =pod
8059:
1.549 albertel 8060: =head1 HTTP Helpers
8061:
8062: =over 4
8063:
1.648 raeburn 8064: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8065:
1.258 albertel 8066: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8067: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8068: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8069:
8070: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8071: $possible_names is an ref to an array of form element names. As an example:
8072: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8073: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8074:
8075: =cut
1.1 albertel 8076:
1.6 albertel 8077: sub get_unprocessed_cgi {
1.25 albertel 8078: my ($query,$possible_names)= @_;
1.26 matthew 8079: # $Apache::lonxml::debug=1;
1.356 albertel 8080: foreach my $pair (split(/&/,$query)) {
8081: my ($name, $value) = split(/=/,$pair);
1.369 www 8082: $name = &unescape($name);
1.25 albertel 8083: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8084: $value =~ tr/+/ /;
8085: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8086: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8087: }
1.16 harris41 8088: }
1.6 albertel 8089: }
8090:
1.112 bowersj2 8091: =pod
8092:
1.648 raeburn 8093: =item * &cacheheader()
1.112 bowersj2 8094:
8095: returns cache-controlling header code
8096:
8097: =cut
8098:
1.7 albertel 8099: sub cacheheader {
1.258 albertel 8100: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8101: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8102: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8103: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8104: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8105: return $output;
1.7 albertel 8106: }
8107:
1.112 bowersj2 8108: =pod
8109:
1.648 raeburn 8110: =item * &no_cache($r)
1.112 bowersj2 8111:
8112: specifies header code to not have cache
8113:
8114: =cut
8115:
1.9 albertel 8116: sub no_cache {
1.216 albertel 8117: my ($r) = @_;
8118: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8119: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8120: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8121: $r->no_cache(1);
8122: $r->header_out("Expires" => $date);
8123: $r->header_out("Pragma" => "no-cache");
1.123 www 8124: }
8125:
8126: sub content_type {
1.181 albertel 8127: my ($r,$type,$charset) = @_;
1.299 foxr 8128: if ($r) {
8129: # Note that printout.pl calls this with undef for $r.
8130: &no_cache($r);
8131: }
1.258 albertel 8132: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8133: unless ($charset) {
8134: $charset=&Apache::lonlocal::current_encoding;
8135: }
8136: if ($charset) { $type.='; charset='.$charset; }
8137: if ($r) {
8138: $r->content_type($type);
8139: } else {
8140: print("Content-type: $type\n\n");
8141: }
1.9 albertel 8142: }
1.25 albertel 8143:
1.112 bowersj2 8144: =pod
8145:
1.648 raeburn 8146: =item * &add_to_env($name,$value)
1.112 bowersj2 8147:
1.258 albertel 8148: adds $name to the %env hash with value
1.112 bowersj2 8149: $value, if $name already exists, the entry is converted to an array
8150: reference and $value is added to the array.
8151:
8152: =cut
8153:
1.25 albertel 8154: sub add_to_env {
8155: my ($name,$value)=@_;
1.258 albertel 8156: if (defined($env{$name})) {
8157: if (ref($env{$name})) {
1.25 albertel 8158: #already have multiple values
1.258 albertel 8159: push(@{ $env{$name} },$value);
1.25 albertel 8160: } else {
8161: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8162: my $first=$env{$name};
8163: undef($env{$name});
8164: push(@{ $env{$name} },$first,$value);
1.25 albertel 8165: }
8166: } else {
1.258 albertel 8167: $env{$name}=$value;
1.25 albertel 8168: }
1.31 albertel 8169: }
1.149 albertel 8170:
8171: =pod
8172:
1.648 raeburn 8173: =item * &get_env_multiple($name)
1.149 albertel 8174:
1.258 albertel 8175: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8176: values may be defined and end up as an array ref.
8177:
8178: returns an array of values
8179:
8180: =cut
8181:
8182: sub get_env_multiple {
8183: my ($name) = @_;
8184: my @values;
1.258 albertel 8185: if (defined($env{$name})) {
1.149 albertel 8186: # exists is it an array
1.258 albertel 8187: if (ref($env{$name})) {
8188: @values=@{ $env{$name} };
1.149 albertel 8189: } else {
1.258 albertel 8190: $values[0]=$env{$name};
1.149 albertel 8191: }
8192: }
8193: return(@values);
8194: }
8195:
1.660 raeburn 8196: sub ask_for_embedded_content {
8197: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8198: my $upload_output = '
8199: <form name="upload_embedded" action="'.$actionurl.'"
8200: method="post" enctype="multipart/form-data">';
8201: $upload_output .= $state;
1.661 raeburn 8202: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8203:
8204: my $num = 0;
8205: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8206: $upload_output .= &start_data_table_row().
8207: '<td>'.$embed_file.'</td><td>';
8208: if ($args->{'ignore_remote_references'}
8209: && $embed_file =~ m{^\w+://}) {
8210: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8211: } elsif ($args->{'error_on_invalid_names'}
8212: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8213:
8214: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8215:
8216: } else {
8217: $upload_output .='
1.661 raeburn 8218: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8219: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8220: my $attrib = join(':',@{$$allfiles{$embed_file}});
8221: $upload_output .=
8222: "\n\t\t".
8223: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8224: $attrib.'" />';
8225: if (exists($$codebase{$embed_file})) {
8226: $upload_output .=
8227: "\n\t\t".
8228: '<input name="codebase_'.$num.'" type="hidden" value="'.
8229: &escape($$codebase{$embed_file}).'" />';
8230: }
8231: }
8232: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8233: $num++;
8234: }
8235: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8236: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8237: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8238: '.&mt('(only files for which a location has been provided will be uploaded)').'
8239: </form>';
8240: return $upload_output;
8241: }
8242:
1.661 raeburn 8243: sub upload_embedded {
8244: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8245: $current_disk_usage) = @_;
8246: my $output;
8247: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8248: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8249: my $orig_uploaded_filename =
8250: $env{'form.embedded_item_'.$i.'.filename'};
8251:
8252: $env{'form.embedded_orig_'.$i} =
8253: &unescape($env{'form.embedded_orig_'.$i});
8254: my ($path,$fname) =
8255: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8256: # no path, whole string is fname
8257: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8258:
8259: $path = $env{'form.currentpath'}.$path;
8260: $fname = &Apache::lonnet::clean_filename($fname);
8261: # See if there is anything left
8262: next if ($fname eq '');
8263:
8264: # Check if file already exists as a file or directory.
8265: my ($state,$msg);
8266: if ($context eq 'portfolio') {
8267: my $port_path = $dirpath;
8268: if ($group ne '') {
8269: $port_path = "groups/$group/$port_path";
8270: }
8271: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8272: $dir_root,$port_path,$disk_quota,
8273: $current_disk_usage,$uname,$udom);
8274: if ($state eq 'will_exceed_quota'
8275: || $state eq 'file_locked'
8276: || $state eq 'file_exists' ) {
8277: $output .= $msg;
8278: next;
8279: }
8280: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8281: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8282: if ($state eq 'exists') {
8283: $output .= $msg;
8284: next;
8285: }
8286: }
8287: # Check if extension is valid
8288: if (($fname =~ /\.(\w+)$/) &&
8289: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8290: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8291: next;
8292: } elsif (($fname =~ /\.(\w+)$/) &&
8293: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8294: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8295: next;
8296: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8297: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8298: next;
8299: }
8300:
8301: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8302: if ($context eq 'portfolio') {
8303: my $result=
8304: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8305: $dirpath.$path);
8306: if ($result !~ m|^/uploaded/|) {
8307: $output .= '<span class="LC_error">'
8308: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8309: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8310: .'</span><br />';
8311: next;
8312: } else {
8313: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8314: $path.$fname.'</span>').'</p>';
8315: }
8316: } else {
8317: # Save the file
8318: my $target = $env{'form.embedded_item_'.$i};
8319: my $fullpath = $dir_root.$dirpath.'/'.$path;
8320: my $dest = $fullpath.$fname;
8321: my $url = $url_root.$dirpath.'/'.$path.$fname;
8322: my @parts=split(/\//,$fullpath);
8323: my $count;
8324: my $filepath = $dir_root;
8325: for ($count=4;$count<=$#parts;$count++) {
8326: $filepath .= "/$parts[$count]";
8327: if ((-e $filepath)!=1) {
8328: mkdir($filepath,0770);
8329: }
8330: }
8331: my $fh;
8332: if (!open($fh,'>'.$dest)) {
8333: &Apache::lonnet::logthis('Failed to create '.$dest);
8334: $output .= '<span class="LC_error">'.
8335: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8336: '</span><br />';
8337: } else {
8338: if (!print $fh $env{'form.embedded_item_'.$i}) {
8339: &Apache::lonnet::logthis('Failed to write to '.$dest);
8340: $output .= '<span class="LC_error">'.
8341: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8342: '</span><br />';
8343: } else {
8344: if ($context eq 'testbank') {
8345: $output .= &mt('Embedded file uploaded successfully:').
8346: ' <a href="'.$url.'">'.
8347: $orig_uploaded_filename.'</a><br />';
8348: } else {
1.705 tempelho 8349: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8350: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8351: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8352: }
8353: }
8354: close($fh);
8355: }
8356: }
8357: }
8358: return $output;
8359: }
8360:
8361: sub check_for_existing {
8362: my ($path,$fname,$element) = @_;
8363: my ($state,$msg);
8364: if (-d $path.'/'.$fname) {
8365: $state = 'exists';
8366: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8367: } elsif (-e $path.'/'.$fname) {
8368: $state = 'exists';
8369: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8370: }
8371: if ($state eq 'exists') {
8372: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8373: }
8374: return ($state,$msg);
8375: }
8376:
8377: sub check_for_upload {
8378: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8379: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8380: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8381: my $getpropath = 1;
8382: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8383: $getpropath);
8384: my $found_file = 0;
8385: my $locked_file = 0;
8386: foreach my $line (@dir_list) {
8387: my ($file_name)=split(/\&/,$line,2);
8388: if ($file_name eq $fname){
8389: $file_name = $path.$file_name;
8390: if ($group ne '') {
8391: $file_name = $group.$file_name;
8392: }
8393: $found_file = 1;
8394: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8395: $locked_file = 1;
8396: }
8397: }
8398: }
8399: if (($current_disk_usage + $filesize) > $disk_quota){
8400: my $msg = '<span class="LC_error">'.
8401: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8402: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8403: return ('will_exceed_quota',$msg);
8404: } elsif ($found_file) {
8405: if ($locked_file) {
8406: my $msg = '<span class="LC_error">';
8407: $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>');
8408: $msg .= '</span><br />';
8409: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8410: return ('file_locked',$msg);
8411: } else {
8412: my $msg = '<span class="LC_error">';
8413: $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'});
8414: $msg .= '</span>';
8415: $msg .= '<br />';
8416: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8417: return ('file_exists',$msg);
8418: }
8419: }
8420: }
8421:
1.31 albertel 8422:
1.41 ng 8423: =pod
1.45 matthew 8424:
1.464 albertel 8425: =back
1.41 ng 8426:
1.112 bowersj2 8427: =head1 CSV Upload/Handling functions
1.38 albertel 8428:
1.41 ng 8429: =over 4
8430:
1.648 raeburn 8431: =item * &upfile_store($r)
1.41 ng 8432:
8433: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8434: needs $env{'form.upfile'}
1.41 ng 8435: returns $datatoken to be put into hidden field
8436:
8437: =cut
1.31 albertel 8438:
8439: sub upfile_store {
8440: my $r=shift;
1.258 albertel 8441: $env{'form.upfile'}=~s/\r/\n/gs;
8442: $env{'form.upfile'}=~s/\f/\n/gs;
8443: $env{'form.upfile'}=~s/\n+/\n/gs;
8444: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8445:
1.258 albertel 8446: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8447: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8448: {
1.158 raeburn 8449: my $datafile = $r->dir_config('lonDaemons').
8450: '/tmp/'.$datatoken.'.tmp';
8451: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8452: print $fh $env{'form.upfile'};
1.158 raeburn 8453: close($fh);
8454: }
1.31 albertel 8455: }
8456: return $datatoken;
8457: }
8458:
1.56 matthew 8459: =pod
8460:
1.648 raeburn 8461: =item * &load_tmp_file($r)
1.41 ng 8462:
8463: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8464: needs $env{'form.datatoken'},
8465: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8466:
8467: =cut
1.31 albertel 8468:
8469: sub load_tmp_file {
8470: my $r=shift;
8471: my @studentdata=();
8472: {
1.158 raeburn 8473: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8474: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8475: if ( open(my $fh,"<$studentfile") ) {
8476: @studentdata=<$fh>;
8477: close($fh);
8478: }
1.31 albertel 8479: }
1.258 albertel 8480: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8481: }
8482:
1.56 matthew 8483: =pod
8484:
1.648 raeburn 8485: =item * &upfile_record_sep()
1.41 ng 8486:
8487: Separate uploaded file into records
8488: returns array of records,
1.258 albertel 8489: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8490:
8491: =cut
1.31 albertel 8492:
8493: sub upfile_record_sep {
1.258 albertel 8494: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8495: } else {
1.248 albertel 8496: my @records;
1.258 albertel 8497: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8498: if ($line=~/^\s*$/) { next; }
8499: push(@records,$line);
8500: }
8501: return @records;
1.31 albertel 8502: }
8503: }
8504:
1.56 matthew 8505: =pod
8506:
1.648 raeburn 8507: =item * &record_sep($record)
1.41 ng 8508:
1.258 albertel 8509: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8510:
8511: =cut
8512:
1.263 www 8513: sub takeleft {
8514: my $index=shift;
8515: return substr('0000'.$index,-4,4);
8516: }
8517:
1.31 albertel 8518: sub record_sep {
8519: my $record=shift;
8520: my %components=();
1.258 albertel 8521: if ($env{'form.upfiletype'} eq 'xml') {
8522: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8523: my $i=0;
1.356 albertel 8524: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8525: $field=~s/^(\"|\')//;
8526: $field=~s/(\"|\')$//;
1.263 www 8527: $components{&takeleft($i)}=$field;
1.31 albertel 8528: $i++;
8529: }
1.258 albertel 8530: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8531: my $i=0;
1.356 albertel 8532: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8533: $field=~s/^(\"|\')//;
8534: $field=~s/(\"|\')$//;
1.263 www 8535: $components{&takeleft($i)}=$field;
1.31 albertel 8536: $i++;
8537: }
8538: } else {
1.561 www 8539: my $separator=',';
1.480 banghart 8540: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8541: $separator=';';
1.480 banghart 8542: }
1.31 albertel 8543: my $i=0;
1.561 www 8544: # the character we are looking for to indicate the end of a quote or a record
8545: my $looking_for=$separator;
8546: # do not add the characters to the fields
8547: my $ignore=0;
8548: # we just encountered a separator (or the beginning of the record)
8549: my $just_found_separator=1;
8550: # store the field we are working on here
8551: my $field='';
8552: # work our way through all characters in record
8553: foreach my $character ($record=~/(.)/g) {
8554: if ($character eq $looking_for) {
8555: if ($character ne $separator) {
8556: # Found the end of a quote, again looking for separator
8557: $looking_for=$separator;
8558: $ignore=1;
8559: } else {
8560: # Found a separator, store away what we got
8561: $components{&takeleft($i)}=$field;
8562: $i++;
8563: $just_found_separator=1;
8564: $ignore=0;
8565: $field='';
8566: }
8567: next;
8568: }
8569: # single or double quotation marks after a separator indicate beginning of a quote
8570: # we are now looking for the end of the quote and need to ignore separators
8571: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8572: $looking_for=$character;
8573: next;
8574: }
8575: # ignore would be true after we reached the end of a quote
8576: if ($ignore) { next; }
8577: if (($just_found_separator) && ($character=~/\s/)) { next; }
8578: $field.=$character;
8579: $just_found_separator=0;
1.31 albertel 8580: }
1.561 www 8581: # catch the very last entry, since we never encountered the separator
8582: $components{&takeleft($i)}=$field;
1.31 albertel 8583: }
8584: return %components;
8585: }
8586:
1.144 matthew 8587: ######################################################
8588: ######################################################
8589:
1.56 matthew 8590: =pod
8591:
1.648 raeburn 8592: =item * &upfile_select_html()
1.41 ng 8593:
1.144 matthew 8594: Return HTML code to select a file from the users machine and specify
8595: the file type.
1.41 ng 8596:
8597: =cut
8598:
1.144 matthew 8599: ######################################################
8600: ######################################################
1.31 albertel 8601: sub upfile_select_html {
1.144 matthew 8602: my %Types = (
8603: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8604: semisv => &mt('Semicolon separated values'),
1.144 matthew 8605: space => &mt('Space separated'),
8606: tab => &mt('Tabulator separated'),
8607: # xml => &mt('HTML/XML'),
8608: );
8609: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8610: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8611: foreach my $type (sort(keys(%Types))) {
8612: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8613: }
8614: $Str .= "</select>\n";
8615: return $Str;
1.31 albertel 8616: }
8617:
1.301 albertel 8618: sub get_samples {
8619: my ($records,$toget) = @_;
8620: my @samples=({});
8621: my $got=0;
8622: foreach my $rec (@$records) {
8623: my %temp = &record_sep($rec);
8624: if (! grep(/\S/, values(%temp))) { next; }
8625: if (%temp) {
8626: $samples[$got]=\%temp;
8627: $got++;
8628: if ($got == $toget) { last; }
8629: }
8630: }
8631: return \@samples;
8632: }
8633:
1.144 matthew 8634: ######################################################
8635: ######################################################
8636:
1.56 matthew 8637: =pod
8638:
1.648 raeburn 8639: =item * &csv_print_samples($r,$records)
1.41 ng 8640:
8641: Prints a table of sample values from each column uploaded $r is an
8642: Apache Request ref, $records is an arrayref from
8643: &Apache::loncommon::upfile_record_sep
8644:
8645: =cut
8646:
1.144 matthew 8647: ######################################################
8648: ######################################################
1.31 albertel 8649: sub csv_print_samples {
8650: my ($r,$records) = @_;
1.662 bisitz 8651: my $samples = &get_samples($records,5);
1.301 albertel 8652:
1.594 raeburn 8653: $r->print(&mt('Samples').'<br />'.&start_data_table().
8654: &start_data_table_header_row());
1.356 albertel 8655: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8656: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8657: $r->print(&end_data_table_header_row());
1.301 albertel 8658: foreach my $hash (@$samples) {
1.594 raeburn 8659: $r->print(&start_data_table_row());
1.356 albertel 8660: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8661: $r->print('<td>');
1.356 albertel 8662: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8663: $r->print('</td>');
8664: }
1.594 raeburn 8665: $r->print(&end_data_table_row());
1.31 albertel 8666: }
1.594 raeburn 8667: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8668: }
8669:
1.144 matthew 8670: ######################################################
8671: ######################################################
8672:
1.56 matthew 8673: =pod
8674:
1.648 raeburn 8675: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8676:
8677: Prints a table to create associations between values and table columns.
1.144 matthew 8678:
1.41 ng 8679: $r is an Apache Request ref,
8680: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8681: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8682:
8683: =cut
8684:
1.144 matthew 8685: ######################################################
8686: ######################################################
1.31 albertel 8687: sub csv_print_select_table {
8688: my ($r,$records,$d) = @_;
1.301 albertel 8689: my $i=0;
8690: my $samples = &get_samples($records,1);
1.144 matthew 8691: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8692: &start_data_table().&start_data_table_header_row().
1.144 matthew 8693: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8694: '<th>'.&mt('Column').'</th>'.
8695: &end_data_table_header_row()."\n");
1.356 albertel 8696: foreach my $array_ref (@$d) {
8697: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8698: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8699:
1.875 bisitz 8700: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8701: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8702: $r->print('<option value="none"></option>');
1.356 albertel 8703: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8704: $r->print('<option value="'.$sample.'"'.
8705: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8706: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8707: }
1.594 raeburn 8708: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8709: $i++;
8710: }
1.594 raeburn 8711: $r->print(&end_data_table());
1.31 albertel 8712: $i--;
8713: return $i;
8714: }
1.56 matthew 8715:
1.144 matthew 8716: ######################################################
8717: ######################################################
8718:
1.56 matthew 8719: =pod
1.31 albertel 8720:
1.648 raeburn 8721: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8722:
8723: Prints a table of sample values from the upload and can make associate samples to internal names.
8724:
8725: $r is an Apache Request ref,
8726: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8727: $d is an array of 2 element arrays (internal name, displayed name)
8728:
8729: =cut
8730:
1.144 matthew 8731: ######################################################
8732: ######################################################
1.31 albertel 8733: sub csv_samples_select_table {
8734: my ($r,$records,$d) = @_;
8735: my $i=0;
1.144 matthew 8736: #
1.662 bisitz 8737: my $max_samples = 5;
8738: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8739: $r->print(&start_data_table().
8740: &start_data_table_header_row().'<th>'.
8741: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8742: &end_data_table_header_row());
1.301 albertel 8743:
8744: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8745: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8746: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8747: foreach my $option (@$d) {
8748: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8749: $r->print('<option value="'.$value.'"'.
1.253 albertel 8750: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8751: $display.'</option>');
1.31 albertel 8752: }
8753: $r->print('</select></td><td>');
1.662 bisitz 8754: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8755: if (defined($samples->[$line]{$key})) {
8756: $r->print($samples->[$line]{$key}."<br />\n");
8757: }
8758: }
1.594 raeburn 8759: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8760: $i++;
8761: }
1.594 raeburn 8762: $r->print(&end_data_table());
1.31 albertel 8763: $i--;
8764: return($i);
1.115 matthew 8765: }
8766:
1.144 matthew 8767: ######################################################
8768: ######################################################
8769:
1.115 matthew 8770: =pod
8771:
1.648 raeburn 8772: =item * &clean_excel_name($name)
1.115 matthew 8773:
8774: Returns a replacement for $name which does not contain any illegal characters.
8775:
8776: =cut
8777:
1.144 matthew 8778: ######################################################
8779: ######################################################
1.115 matthew 8780: sub clean_excel_name {
8781: my ($name) = @_;
8782: $name =~ s/[:\*\?\/\\]//g;
8783: if (length($name) > 31) {
8784: $name = substr($name,0,31);
8785: }
8786: return $name;
1.25 albertel 8787: }
1.84 albertel 8788:
1.85 albertel 8789: =pod
8790:
1.648 raeburn 8791: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8792:
8793: Returns either 1 or undef
8794:
8795: 1 if the part is to be hidden, undef if it is to be shown
8796:
8797: Arguments are:
8798:
8799: $id the id of the part to be checked
8800: $symb, optional the symb of the resource to check
8801: $udom, optional the domain of the user to check for
8802: $uname, optional the username of the user to check for
8803:
8804: =cut
1.84 albertel 8805:
8806: sub check_if_partid_hidden {
8807: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8808: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8809: $symb,$udom,$uname);
1.141 albertel 8810: my $truth=1;
8811: #if the string starts with !, then the list is the list to show not hide
8812: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8813: my @hiddenlist=split(/,/,$hiddenparts);
8814: foreach my $checkid (@hiddenlist) {
1.141 albertel 8815: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8816: }
1.141 albertel 8817: return !$truth;
1.84 albertel 8818: }
1.127 matthew 8819:
1.138 matthew 8820:
8821: ############################################################
8822: ############################################################
8823:
8824: =pod
8825:
1.157 matthew 8826: =back
8827:
1.138 matthew 8828: =head1 cgi-bin script and graphing routines
8829:
1.157 matthew 8830: =over 4
8831:
1.648 raeburn 8832: =item * &get_cgi_id()
1.138 matthew 8833:
8834: Inputs: none
8835:
8836: Returns an id which can be used to pass environment variables
8837: to various cgi-bin scripts. These environment variables will
8838: be removed from the users environment after a given time by
8839: the routine &Apache::lonnet::transfer_profile_to_env.
8840:
8841: =cut
8842:
8843: ############################################################
8844: ############################################################
1.152 albertel 8845: my $uniq=0;
1.136 matthew 8846: sub get_cgi_id {
1.154 albertel 8847: $uniq=($uniq+1)%100000;
1.280 albertel 8848: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8849: }
8850:
1.127 matthew 8851: ############################################################
8852: ############################################################
8853:
8854: =pod
8855:
1.648 raeburn 8856: =item * &DrawBarGraph()
1.127 matthew 8857:
1.138 matthew 8858: Facilitates the plotting of data in a (stacked) bar graph.
8859: Puts plot definition data into the users environment in order for
8860: graph.png to plot it. Returns an <img> tag for the plot.
8861: The bars on the plot are labeled '1','2',...,'n'.
8862:
8863: Inputs:
8864:
8865: =over 4
8866:
8867: =item $Title: string, the title of the plot
8868:
8869: =item $xlabel: string, text describing the X-axis of the plot
8870:
8871: =item $ylabel: string, text describing the Y-axis of the plot
8872:
8873: =item $Max: scalar, the maximum Y value to use in the plot
8874: If $Max is < any data point, the graph will not be rendered.
8875:
1.140 matthew 8876: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8877: they are plotted. If undefined, default values will be used.
8878:
1.178 matthew 8879: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8880:
1.138 matthew 8881: =item @Values: An array of array references. Each array reference holds data
8882: to be plotted in a stacked bar chart.
8883:
1.239 matthew 8884: =item If the final element of @Values is a hash reference the key/value
8885: pairs will be added to the graph definition.
8886:
1.138 matthew 8887: =back
8888:
8889: Returns:
8890:
8891: An <img> tag which references graph.png and the appropriate identifying
8892: information for the plot.
8893:
1.127 matthew 8894: =cut
8895:
8896: ############################################################
8897: ############################################################
1.134 matthew 8898: sub DrawBarGraph {
1.178 matthew 8899: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8900: #
8901: if (! defined($colors)) {
8902: $colors = ['#33ff00',
8903: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8904: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8905: ];
8906: }
1.228 matthew 8907: my $extra_settings = {};
8908: if (ref($Values[-1]) eq 'HASH') {
8909: $extra_settings = pop(@Values);
8910: }
1.127 matthew 8911: #
1.136 matthew 8912: my $identifier = &get_cgi_id();
8913: my $id = 'cgi.'.$identifier;
1.129 matthew 8914: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8915: return '';
8916: }
1.225 matthew 8917: #
8918: my @Labels;
8919: if (defined($labels)) {
8920: @Labels = @$labels;
8921: } else {
8922: for (my $i=0;$i<@{$Values[0]};$i++) {
8923: push (@Labels,$i+1);
8924: }
8925: }
8926: #
1.129 matthew 8927: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8928: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8929: my %ValuesHash;
8930: my $NumSets=1;
8931: foreach my $array (@Values) {
8932: next if (! ref($array));
1.136 matthew 8933: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8934: join(',',@$array);
1.129 matthew 8935: }
1.127 matthew 8936: #
1.136 matthew 8937: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8938: if ($NumBars < 3) {
8939: $width = 120+$NumBars*32;
1.220 matthew 8940: $xskip = 1;
1.225 matthew 8941: $bar_width = 30;
8942: } elsif ($NumBars < 5) {
8943: $width = 120+$NumBars*20;
8944: $xskip = 1;
8945: $bar_width = 20;
1.220 matthew 8946: } elsif ($NumBars < 10) {
1.136 matthew 8947: $width = 120+$NumBars*15;
8948: $xskip = 1;
8949: $bar_width = 15;
8950: } elsif ($NumBars <= 25) {
8951: $width = 120+$NumBars*11;
8952: $xskip = 5;
8953: $bar_width = 8;
8954: } elsif ($NumBars <= 50) {
8955: $width = 120+$NumBars*8;
8956: $xskip = 5;
8957: $bar_width = 4;
8958: } else {
8959: $width = 120+$NumBars*8;
8960: $xskip = 5;
8961: $bar_width = 4;
8962: }
8963: #
1.137 matthew 8964: $Max = 1 if ($Max < 1);
8965: if ( int($Max) < $Max ) {
8966: $Max++;
8967: $Max = int($Max);
8968: }
1.127 matthew 8969: $Title = '' if (! defined($Title));
8970: $xlabel = '' if (! defined($xlabel));
8971: $ylabel = '' if (! defined($ylabel));
1.369 www 8972: $ValuesHash{$id.'.title'} = &escape($Title);
8973: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8974: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8975: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8976: $ValuesHash{$id.'.NumBars'} = $NumBars;
8977: $ValuesHash{$id.'.NumSets'} = $NumSets;
8978: $ValuesHash{$id.'.PlotType'} = 'bar';
8979: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8980: $ValuesHash{$id.'.height'} = $height;
8981: $ValuesHash{$id.'.width'} = $width;
8982: $ValuesHash{$id.'.xskip'} = $xskip;
8983: $ValuesHash{$id.'.bar_width'} = $bar_width;
8984: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8985: #
1.228 matthew 8986: # Deal with other parameters
8987: while (my ($key,$value) = each(%$extra_settings)) {
8988: $ValuesHash{$id.'.'.$key} = $value;
8989: }
8990: #
1.646 raeburn 8991: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8992: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8993: }
8994:
8995: ############################################################
8996: ############################################################
8997:
8998: =pod
8999:
1.648 raeburn 9000: =item * &DrawXYGraph()
1.137 matthew 9001:
1.138 matthew 9002: Facilitates the plotting of data in an XY graph.
9003: Puts plot definition data into the users environment in order for
9004: graph.png to plot it. Returns an <img> tag for the plot.
9005:
9006: Inputs:
9007:
9008: =over 4
9009:
9010: =item $Title: string, the title of the plot
9011:
9012: =item $xlabel: string, text describing the X-axis of the plot
9013:
9014: =item $ylabel: string, text describing the Y-axis of the plot
9015:
9016: =item $Max: scalar, the maximum Y value to use in the plot
9017: If $Max is < any data point, the graph will not be rendered.
9018:
9019: =item $colors: Array ref containing the hex color codes for the data to be
9020: plotted in. If undefined, default values will be used.
9021:
9022: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9023:
9024: =item $Ydata: Array ref containing Array refs.
1.185 www 9025: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9026:
9027: =item %Values: hash indicating or overriding any default values which are
9028: passed to graph.png.
9029: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9030:
9031: =back
9032:
9033: Returns:
9034:
9035: An <img> tag which references graph.png and the appropriate identifying
9036: information for the plot.
9037:
1.137 matthew 9038: =cut
9039:
9040: ############################################################
9041: ############################################################
9042: sub DrawXYGraph {
9043: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9044: #
9045: # Create the identifier for the graph
9046: my $identifier = &get_cgi_id();
9047: my $id = 'cgi.'.$identifier;
9048: #
9049: $Title = '' if (! defined($Title));
9050: $xlabel = '' if (! defined($xlabel));
9051: $ylabel = '' if (! defined($ylabel));
9052: my %ValuesHash =
9053: (
1.369 www 9054: $id.'.title' => &escape($Title),
9055: $id.'.xlabel' => &escape($xlabel),
9056: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9057: $id.'.y_max_value'=> $Max,
9058: $id.'.labels' => join(',',@$Xlabels),
9059: $id.'.PlotType' => 'XY',
9060: );
9061: #
9062: if (defined($colors) && ref($colors) eq 'ARRAY') {
9063: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9064: }
9065: #
9066: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9067: return '';
9068: }
9069: my $NumSets=1;
1.138 matthew 9070: foreach my $array (@{$Ydata}){
1.137 matthew 9071: next if (! ref($array));
9072: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9073: }
1.138 matthew 9074: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9075: #
9076: # Deal with other parameters
9077: while (my ($key,$value) = each(%Values)) {
9078: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9079: }
9080: #
1.646 raeburn 9081: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9082: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9083: }
9084:
9085: ############################################################
9086: ############################################################
9087:
9088: =pod
9089:
1.648 raeburn 9090: =item * &DrawXYYGraph()
1.138 matthew 9091:
9092: Facilitates the plotting of data in an XY graph with two Y axes.
9093: Puts plot definition data into the users environment in order for
9094: graph.png to plot it. Returns an <img> tag for the plot.
9095:
9096: Inputs:
9097:
9098: =over 4
9099:
9100: =item $Title: string, the title of the plot
9101:
9102: =item $xlabel: string, text describing the X-axis of the plot
9103:
9104: =item $ylabel: string, text describing the Y-axis of the plot
9105:
9106: =item $colors: Array ref containing the hex color codes for the data to be
9107: plotted in. If undefined, default values will be used.
9108:
9109: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9110:
9111: =item $Ydata1: The first data set
9112:
9113: =item $Min1: The minimum value of the left Y-axis
9114:
9115: =item $Max1: The maximum value of the left Y-axis
9116:
9117: =item $Ydata2: The second data set
9118:
9119: =item $Min2: The minimum value of the right Y-axis
9120:
9121: =item $Max2: The maximum value of the left Y-axis
9122:
9123: =item %Values: hash indicating or overriding any default values which are
9124: passed to graph.png.
9125: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9126:
9127: =back
9128:
9129: Returns:
9130:
9131: An <img> tag which references graph.png and the appropriate identifying
9132: information for the plot.
1.136 matthew 9133:
9134: =cut
9135:
9136: ############################################################
9137: ############################################################
1.137 matthew 9138: sub DrawXYYGraph {
9139: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9140: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9141: #
9142: # Create the identifier for the graph
9143: my $identifier = &get_cgi_id();
9144: my $id = 'cgi.'.$identifier;
9145: #
9146: $Title = '' if (! defined($Title));
9147: $xlabel = '' if (! defined($xlabel));
9148: $ylabel = '' if (! defined($ylabel));
9149: my %ValuesHash =
9150: (
1.369 www 9151: $id.'.title' => &escape($Title),
9152: $id.'.xlabel' => &escape($xlabel),
9153: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9154: $id.'.labels' => join(',',@$Xlabels),
9155: $id.'.PlotType' => 'XY',
9156: $id.'.NumSets' => 2,
1.137 matthew 9157: $id.'.two_axes' => 1,
9158: $id.'.y1_max_value' => $Max1,
9159: $id.'.y1_min_value' => $Min1,
9160: $id.'.y2_max_value' => $Max2,
9161: $id.'.y2_min_value' => $Min2,
1.136 matthew 9162: );
9163: #
1.137 matthew 9164: if (defined($colors) && ref($colors) eq 'ARRAY') {
9165: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9166: }
9167: #
9168: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9169: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9170: return '';
9171: }
9172: my $NumSets=1;
1.137 matthew 9173: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9174: next if (! ref($array));
9175: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9176: }
9177: #
9178: # Deal with other parameters
9179: while (my ($key,$value) = each(%Values)) {
9180: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9181: }
9182: #
1.646 raeburn 9183: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9184: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9185: }
9186:
9187: ############################################################
9188: ############################################################
9189:
9190: =pod
9191:
1.157 matthew 9192: =back
9193:
1.139 matthew 9194: =head1 Statistics helper routines?
9195:
9196: Bad place for them but what the hell.
9197:
1.157 matthew 9198: =over 4
9199:
1.648 raeburn 9200: =item * &chartlink()
1.139 matthew 9201:
9202: Returns a link to the chart for a specific student.
9203:
9204: Inputs:
9205:
9206: =over 4
9207:
9208: =item $linktext: The text of the link
9209:
9210: =item $sname: The students username
9211:
9212: =item $sdomain: The students domain
9213:
9214: =back
9215:
1.157 matthew 9216: =back
9217:
1.139 matthew 9218: =cut
9219:
9220: ############################################################
9221: ############################################################
9222: sub chartlink {
9223: my ($linktext, $sname, $sdomain) = @_;
9224: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9225: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9226: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9227: '">'.$linktext.'</a>';
1.153 matthew 9228: }
9229:
9230: #######################################################
9231: #######################################################
9232:
9233: =pod
9234:
9235: =head1 Course Environment Routines
1.157 matthew 9236:
9237: =over 4
1.153 matthew 9238:
1.648 raeburn 9239: =item * &restore_course_settings()
1.153 matthew 9240:
1.648 raeburn 9241: =item * &store_course_settings()
1.153 matthew 9242:
9243: Restores/Store indicated form parameters from the course environment.
9244: Will not overwrite existing values of the form parameters.
9245:
9246: Inputs:
9247: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9248:
9249: a hash ref describing the data to be stored. For example:
9250:
9251: %Save_Parameters = ('Status' => 'scalar',
9252: 'chartoutputmode' => 'scalar',
9253: 'chartoutputdata' => 'scalar',
9254: 'Section' => 'array',
1.373 raeburn 9255: 'Group' => 'array',
1.153 matthew 9256: 'StudentData' => 'array',
9257: 'Maps' => 'array');
9258:
9259: Returns: both routines return nothing
9260:
1.631 raeburn 9261: =back
9262:
1.153 matthew 9263: =cut
9264:
9265: #######################################################
9266: #######################################################
9267: sub store_course_settings {
1.496 albertel 9268: return &store_settings($env{'request.course.id'},@_);
9269: }
9270:
9271: sub store_settings {
1.153 matthew 9272: # save to the environment
9273: # appenv the same items, just to be safe
1.300 albertel 9274: my $udom = $env{'user.domain'};
9275: my $uname = $env{'user.name'};
1.496 albertel 9276: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9277: my %SaveHash;
9278: my %AppHash;
9279: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9280: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9281: my $envname = 'environment.'.$basename;
1.258 albertel 9282: if (exists($env{'form.'.$setting})) {
1.153 matthew 9283: # Save this value away
9284: if ($type eq 'scalar' &&
1.258 albertel 9285: (! exists($env{$envname}) ||
9286: $env{$envname} ne $env{'form.'.$setting})) {
9287: $SaveHash{$basename} = $env{'form.'.$setting};
9288: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9289: } elsif ($type eq 'array') {
9290: my $stored_form;
1.258 albertel 9291: if (ref($env{'form.'.$setting})) {
1.153 matthew 9292: $stored_form = join(',',
9293: map {
1.369 www 9294: &escape($_);
1.258 albertel 9295: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9296: } else {
9297: $stored_form =
1.369 www 9298: &escape($env{'form.'.$setting});
1.153 matthew 9299: }
9300: # Determine if the array contents are the same.
1.258 albertel 9301: if ($stored_form ne $env{$envname}) {
1.153 matthew 9302: $SaveHash{$basename} = $stored_form;
9303: $AppHash{$envname} = $stored_form;
9304: }
9305: }
9306: }
9307: }
9308: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9309: $udom,$uname);
1.153 matthew 9310: if ($put_result !~ /^(ok|delayed)/) {
9311: &Apache::lonnet::logthis('unable to save form parameters, '.
9312: 'got error:'.$put_result);
9313: }
9314: # Make sure these settings stick around in this session, too
1.646 raeburn 9315: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9316: return;
9317: }
9318:
9319: sub restore_course_settings {
1.499 albertel 9320: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9321: }
9322:
9323: sub restore_settings {
9324: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9325: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9326: next if (exists($env{'form.'.$setting}));
1.496 albertel 9327: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9328: '.'.$setting;
1.258 albertel 9329: if (exists($env{$envname})) {
1.153 matthew 9330: if ($type eq 'scalar') {
1.258 albertel 9331: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9332: } elsif ($type eq 'array') {
1.258 albertel 9333: $env{'form.'.$setting} = [
1.153 matthew 9334: map {
1.369 www 9335: &unescape($_);
1.258 albertel 9336: } split(',',$env{$envname})
1.153 matthew 9337: ];
9338: }
9339: }
9340: }
1.127 matthew 9341: }
9342:
1.618 raeburn 9343: #######################################################
9344: #######################################################
9345:
9346: =pod
9347:
9348: =head1 Domain E-mail Routines
9349:
9350: =over 4
9351:
1.648 raeburn 9352: =item * &build_recipient_list()
1.618 raeburn 9353:
1.884 raeburn 9354: Build recipient lists for five types of e-mail:
1.766 raeburn 9355: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9356: (d) Help requests, (e) Course requests needing approval, generated by
9357: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9358: loncoursequeueadmin.pm respectively.
1.618 raeburn 9359:
9360: Inputs:
1.619 raeburn 9361: defmail (scalar - email address of default recipient),
1.618 raeburn 9362: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9363: defdom (domain for which to retrieve configuration settings),
9364: origmail (scalar - email address of recipient from loncapa.conf,
9365: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9366:
1.655 raeburn 9367: Returns: comma separated list of addresses to which to send e-mail.
9368:
9369: =back
1.618 raeburn 9370:
9371: =cut
9372:
9373: ############################################################
9374: ############################################################
9375: sub build_recipient_list {
1.619 raeburn 9376: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9377: my @recipients;
9378: my $otheremails;
9379: my %domconfig =
9380: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9381: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9382: if (exists($domconfig{'contacts'}{$mailing})) {
9383: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9384: my @contacts = ('adminemail','supportemail');
9385: foreach my $item (@contacts) {
9386: if ($domconfig{'contacts'}{$mailing}{$item}) {
9387: my $addr = $domconfig{'contacts'}{$item};
9388: if (!grep(/^\Q$addr\E$/,@recipients)) {
9389: push(@recipients,$addr);
9390: }
1.619 raeburn 9391: }
1.766 raeburn 9392: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9393: }
9394: }
1.766 raeburn 9395: } elsif ($origmail ne '') {
9396: push(@recipients,$origmail);
1.618 raeburn 9397: }
1.619 raeburn 9398: } elsif ($origmail ne '') {
9399: push(@recipients,$origmail);
1.618 raeburn 9400: }
1.688 raeburn 9401: if (defined($defmail)) {
9402: if ($defmail ne '') {
9403: push(@recipients,$defmail);
9404: }
1.618 raeburn 9405: }
9406: if ($otheremails) {
1.619 raeburn 9407: my @others;
9408: if ($otheremails =~ /,/) {
9409: @others = split(/,/,$otheremails);
1.618 raeburn 9410: } else {
1.619 raeburn 9411: push(@others,$otheremails);
9412: }
9413: foreach my $addr (@others) {
9414: if (!grep(/^\Q$addr\E$/,@recipients)) {
9415: push(@recipients,$addr);
9416: }
1.618 raeburn 9417: }
9418: }
1.619 raeburn 9419: my $recipientlist = join(',',@recipients);
1.618 raeburn 9420: return $recipientlist;
9421: }
9422:
1.127 matthew 9423: ############################################################
9424: ############################################################
1.154 albertel 9425:
1.655 raeburn 9426: =pod
9427:
9428: =head1 Course Catalog Routines
9429:
9430: =over 4
9431:
9432: =item * &gather_categories()
9433:
9434: Converts category definitions - keys of categories hash stored in
9435: coursecategories in configuration.db on the primary library server in a
9436: domain - to an array. Also generates javascript and idx hash used to
9437: generate Domain Coordinator interface for editing Course Categories.
9438:
9439: Inputs:
1.663 raeburn 9440:
1.655 raeburn 9441: categories (reference to hash of category definitions).
1.663 raeburn 9442:
1.655 raeburn 9443: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9444: categories and subcategories).
1.663 raeburn 9445:
1.655 raeburn 9446: idx (reference to hash of counters used in Domain Coordinator interface for
9447: editing Course Categories).
1.663 raeburn 9448:
1.655 raeburn 9449: jsarray (reference to array of categories used to create Javascript arrays for
9450: Domain Coordinator interface for editing Course Categories).
9451:
9452: Returns: nothing
9453:
9454: Side effects: populates cats, idx and jsarray.
9455:
9456: =cut
9457:
9458: sub gather_categories {
9459: my ($categories,$cats,$idx,$jsarray) = @_;
9460: my %counters;
9461: my $num = 0;
9462: foreach my $item (keys(%{$categories})) {
9463: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9464: if ($container eq '' && $depth == 0) {
9465: $cats->[$depth][$categories->{$item}] = $cat;
9466: } else {
9467: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9468: }
9469: my ($escitem,$tail) = split(/:/,$item,2);
9470: if ($counters{$tail} eq '') {
9471: $counters{$tail} = $num;
9472: $num ++;
9473: }
9474: if (ref($idx) eq 'HASH') {
9475: $idx->{$item} = $counters{$tail};
9476: }
9477: if (ref($jsarray) eq 'ARRAY') {
9478: push(@{$jsarray->[$counters{$tail}]},$item);
9479: }
9480: }
9481: return;
9482: }
9483:
9484: =pod
9485:
9486: =item * &extract_categories()
9487:
9488: Used to generate breadcrumb trails for course categories.
9489:
9490: Inputs:
1.663 raeburn 9491:
1.655 raeburn 9492: categories (reference to hash of category definitions).
1.663 raeburn 9493:
1.655 raeburn 9494: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9495: categories and subcategories).
1.663 raeburn 9496:
1.655 raeburn 9497: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9498:
1.655 raeburn 9499: allitems (reference to hash - key is category key
9500: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9501:
1.655 raeburn 9502: idx (reference to hash of counters used in Domain Coordinator interface for
9503: editing Course Categories).
1.663 raeburn 9504:
1.655 raeburn 9505: jsarray (reference to array of categories used to create Javascript arrays for
9506: Domain Coordinator interface for editing Course Categories).
9507:
1.665 raeburn 9508: subcats (reference to hash of arrays containing all subcategories within each
9509: category, -recursive)
9510:
1.655 raeburn 9511: Returns: nothing
9512:
9513: Side effects: populates trails and allitems hash references.
9514:
9515: =cut
9516:
9517: sub extract_categories {
1.665 raeburn 9518: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9519: if (ref($categories) eq 'HASH') {
9520: &gather_categories($categories,$cats,$idx,$jsarray);
9521: if (ref($cats->[0]) eq 'ARRAY') {
9522: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9523: my $name = $cats->[0][$i];
9524: my $item = &escape($name).'::0';
9525: my $trailstr;
9526: if ($name eq 'instcode') {
9527: $trailstr = &mt('Official courses (with institutional codes)');
9528: } else {
9529: $trailstr = $name;
9530: }
9531: if ($allitems->{$item} eq '') {
9532: push(@{$trails},$trailstr);
9533: $allitems->{$item} = scalar(@{$trails})-1;
9534: }
9535: my @parents = ($name);
9536: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9537: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9538: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9539: if (ref($subcats) eq 'HASH') {
9540: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9541: }
9542: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9543: }
9544: } else {
9545: if (ref($subcats) eq 'HASH') {
9546: $subcats->{$item} = [];
1.655 raeburn 9547: }
9548: }
9549: }
9550: }
9551: }
9552: return;
9553: }
9554:
9555: =pod
9556:
9557: =item *&recurse_categories()
9558:
9559: Recursively used to generate breadcrumb trails for course categories.
9560:
9561: Inputs:
1.663 raeburn 9562:
1.655 raeburn 9563: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9564: categories and subcategories).
1.663 raeburn 9565:
1.655 raeburn 9566: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9567:
9568: category (current course category, for which breadcrumb trail is being generated).
9569:
9570: trails (reference to array of breadcrumb trails for each category).
9571:
1.655 raeburn 9572: allitems (reference to hash - key is category key
9573: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9574:
1.655 raeburn 9575: parents (array containing containers directories for current category,
9576: back to top level).
9577:
9578: Returns: nothing
9579:
9580: Side effects: populates trails and allitems hash references
9581:
9582: =cut
9583:
9584: sub recurse_categories {
1.665 raeburn 9585: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9586: my $shallower = $depth - 1;
9587: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9588: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9589: my $name = $cats->[$depth]{$category}[$k];
9590: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9591: my $trailstr = join(' -> ',(@{$parents},$category));
9592: if ($allitems->{$item} eq '') {
9593: push(@{$trails},$trailstr);
9594: $allitems->{$item} = scalar(@{$trails})-1;
9595: }
9596: my $deeper = $depth+1;
9597: push(@{$parents},$category);
1.665 raeburn 9598: if (ref($subcats) eq 'HASH') {
9599: my $subcat = &escape($name).':'.$category.':'.$depth;
9600: for (my $j=@{$parents}; $j>=0; $j--) {
9601: my $higher;
9602: if ($j > 0) {
9603: $higher = &escape($parents->[$j]).':'.
9604: &escape($parents->[$j-1]).':'.$j;
9605: } else {
9606: $higher = &escape($parents->[$j]).'::'.$j;
9607: }
9608: push(@{$subcats->{$higher}},$subcat);
9609: }
9610: }
9611: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9612: $subcats);
1.655 raeburn 9613: pop(@{$parents});
9614: }
9615: } else {
9616: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9617: my $trailstr = join(' -> ',(@{$parents},$category));
9618: if ($allitems->{$item} eq '') {
9619: push(@{$trails},$trailstr);
9620: $allitems->{$item} = scalar(@{$trails})-1;
9621: }
9622: }
9623: return;
9624: }
9625:
1.663 raeburn 9626: =pod
9627:
9628: =item *&assign_categories_table()
9629:
9630: Create a datatable for display of hierarchical categories in a domain,
9631: with checkboxes to allow a course to be categorized.
9632:
9633: Inputs:
9634:
9635: cathash - reference to hash of categories defined for the domain (from
9636: configuration.db)
9637:
9638: currcat - scalar with an & separated list of categories assigned to a course.
9639:
9640: Returns: $output (markup to be displayed)
9641:
9642: =cut
9643:
9644: sub assign_categories_table {
9645: my ($cathash,$currcat) = @_;
9646: my $output;
9647: if (ref($cathash) eq 'HASH') {
9648: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9649: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9650: $maxdepth = scalar(@cats);
9651: if (@cats > 0) {
9652: my $itemcount = 0;
9653: if (ref($cats[0]) eq 'ARRAY') {
9654: $output = &Apache::loncommon::start_data_table();
9655: my @currcategories;
9656: if ($currcat ne '') {
9657: @currcategories = split('&',$currcat);
9658: }
9659: for (my $i=0; $i<@{$cats[0]}; $i++) {
9660: my $parent = $cats[0][$i];
9661: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9662: next if ($parent eq 'instcode');
9663: my $item = &escape($parent).'::0';
9664: my $checked = '';
9665: if (@currcategories > 0) {
9666: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9667: $checked = ' checked="checked"';
1.663 raeburn 9668: }
9669: }
1.675 raeburn 9670: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9671: '<input type="checkbox" name="usecategory" value="'.
9672: $item.'"'.$checked.' />'.$parent.'</span>'.
9673: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9674: my $depth = 1;
9675: push(@path,$parent);
9676: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9677: pop(@path);
9678: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9679: $itemcount ++;
9680: }
9681: $output .= &Apache::loncommon::end_data_table();
9682: }
9683: }
9684: }
9685: return $output;
9686: }
9687:
9688: =pod
9689:
9690: =item *&assign_category_rows()
9691:
9692: Create a datatable row for display of nested categories in a domain,
9693: with checkboxes to allow a course to be categorized,called recursively.
9694:
9695: Inputs:
9696:
9697: itemcount - track row number for alternating colors
9698:
9699: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9700: categories and subcategories.
9701:
9702: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9703:
9704: parent - parent of current category item
9705:
9706: path - Array containing all categories back up through the hierarchy from the
9707: current category to the top level.
9708:
9709: currcategories - reference to array of current categories assigned to the course
9710:
9711: Returns: $output (markup to be displayed).
9712:
9713: =cut
9714:
9715: sub assign_category_rows {
9716: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9717: my ($text,$name,$item,$chgstr);
9718: if (ref($cats) eq 'ARRAY') {
9719: my $maxdepth = scalar(@{$cats});
9720: if (ref($cats->[$depth]) eq 'HASH') {
9721: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9722: my $numchildren = @{$cats->[$depth]{$parent}};
9723: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9724: $text .= '<td><table class="LC_datatable">';
9725: for (my $j=0; $j<$numchildren; $j++) {
9726: $name = $cats->[$depth]{$parent}[$j];
9727: $item = &escape($name).':'.&escape($parent).':'.$depth;
9728: my $deeper = $depth+1;
9729: my $checked = '';
9730: if (ref($currcategories) eq 'ARRAY') {
9731: if (@{$currcategories} > 0) {
9732: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9733: $checked = ' checked="checked"';
1.663 raeburn 9734: }
9735: }
9736: }
1.664 raeburn 9737: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9738: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9739: $item.'"'.$checked.' />'.$name.'</label></span>'.
9740: '<input type="hidden" name="catname" value="'.$name.'" />'.
9741: '</td><td>';
1.663 raeburn 9742: if (ref($path) eq 'ARRAY') {
9743: push(@{$path},$name);
9744: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9745: pop(@{$path});
9746: }
9747: $text .= '</td></tr>';
9748: }
9749: $text .= '</table></td>';
9750: }
9751: }
9752: }
9753: return $text;
9754: }
9755:
1.655 raeburn 9756: ############################################################
9757: ############################################################
9758:
9759:
1.443 albertel 9760: sub commit_customrole {
1.664 raeburn 9761: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9762: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9763: ($start?', '.&mt('starting').' '.localtime($start):'').
9764: ($end?', ending '.localtime($end):'').': <b>'.
9765: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9766: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9767: '</b><br />';
9768: return $output;
9769: }
9770:
9771: sub commit_standardrole {
1.541 raeburn 9772: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9773: my ($output,$logmsg,$linefeed);
9774: if ($context eq 'auto') {
9775: $linefeed = "\n";
9776: } else {
9777: $linefeed = "<br />\n";
9778: }
1.443 albertel 9779: if ($three eq 'st') {
1.541 raeburn 9780: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9781: $one,$two,$sec,$context);
9782: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9783: ($result eq 'unknown_course') || ($result eq 'refused')) {
9784: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9785: } else {
1.541 raeburn 9786: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9787: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9788: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9789: if ($context eq 'auto') {
9790: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9791: } else {
9792: $output .= '<b>'.$result.'</b>'.$linefeed.
9793: &mt('Add to classlist').': <b>ok</b>';
9794: }
9795: $output .= $linefeed;
1.443 albertel 9796: }
9797: } else {
9798: $output = &mt('Assigning').' '.$three.' in '.$url.
9799: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9800: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9801: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9802: if ($context eq 'auto') {
9803: $output .= $result.$linefeed;
9804: } else {
9805: $output .= '<b>'.$result.'</b>'.$linefeed;
9806: }
1.443 albertel 9807: }
9808: return $output;
9809: }
9810:
9811: sub commit_studentrole {
1.541 raeburn 9812: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9813: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9814: if ($context eq 'auto') {
9815: $linefeed = "\n";
9816: } else {
9817: $linefeed = '<br />'."\n";
9818: }
1.443 albertel 9819: if (defined($one) && defined($two)) {
9820: my $cid=$one.'_'.$two;
9821: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9822: my $secchange = 0;
9823: my $expire_role_result;
9824: my $modify_section_result;
1.628 raeburn 9825: if ($oldsec ne '-1') {
9826: if ($oldsec ne $sec) {
1.443 albertel 9827: $secchange = 1;
1.628 raeburn 9828: my $now = time;
1.443 albertel 9829: my $uurl='/'.$cid;
9830: $uurl=~s/\_/\//g;
9831: if ($oldsec) {
9832: $uurl.='/'.$oldsec;
9833: }
1.626 raeburn 9834: $oldsecurl = $uurl;
1.628 raeburn 9835: $expire_role_result =
1.652 raeburn 9836: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9837: if ($env{'request.course.sec'} ne '') {
9838: if ($expire_role_result eq 'refused') {
9839: my @roles = ('st');
9840: my @statuses = ('previous');
9841: my @roledoms = ($one);
9842: my $withsec = 1;
9843: my %roleshash =
9844: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9845: \@statuses,\@roles,\@roledoms,$withsec);
9846: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9847: my ($oldstart,$oldend) =
9848: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9849: if ($oldend > 0 && $oldend <= $now) {
9850: $expire_role_result = 'ok';
9851: }
9852: }
9853: }
9854: }
1.443 albertel 9855: $result = $expire_role_result;
9856: }
9857: }
9858: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9859: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9860: if ($modify_section_result =~ /^ok/) {
9861: if ($secchange == 1) {
1.628 raeburn 9862: if ($sec eq '') {
9863: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9864: } else {
9865: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9866: }
1.443 albertel 9867: } elsif ($oldsec eq '-1') {
1.628 raeburn 9868: if ($sec eq '') {
9869: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9870: } else {
9871: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9872: }
1.443 albertel 9873: } else {
1.628 raeburn 9874: if ($sec eq '') {
9875: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9876: } else {
9877: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9878: }
1.443 albertel 9879: }
9880: } else {
1.628 raeburn 9881: if ($secchange) {
9882: $$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;
9883: } else {
9884: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9885: }
1.443 albertel 9886: }
9887: $result = $modify_section_result;
9888: } elsif ($secchange == 1) {
1.628 raeburn 9889: if ($oldsec eq '') {
9890: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9891: } else {
9892: $$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;
9893: }
1.626 raeburn 9894: if ($expire_role_result eq 'refused') {
9895: my $newsecurl = '/'.$cid;
9896: $newsecurl =~ s/\_/\//g;
9897: if ($sec ne '') {
9898: $newsecurl.='/'.$sec;
9899: }
9900: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9901: if ($sec eq '') {
9902: $$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;
9903: } else {
9904: $$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;
9905: }
9906: }
9907: }
1.443 albertel 9908: }
9909: } else {
1.626 raeburn 9910: $$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 9911: $result = "error: incomplete course id\n";
9912: }
9913: return $result;
9914: }
9915:
9916: ############################################################
9917: ############################################################
9918:
1.566 albertel 9919: sub check_clone {
1.578 raeburn 9920: my ($args,$linefeed) = @_;
1.566 albertel 9921: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9922: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9923: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9924: my $clonemsg;
9925: my $can_clone = 0;
9926:
9927: if ($clonehome eq 'no_host') {
1.578 raeburn 9928: $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 9929: } else {
9930: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.882 raeburn 9931: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
9932: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 9933: $can_clone = 1;
9934: } else {
9935: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9936: $args->{'clonedomain'},$args->{'clonecourse'});
9937: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9938: if (grep(/^\*$/,@cloners)) {
9939: $can_clone = 1;
9940: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9941: $can_clone = 1;
9942: } else {
9943: my %roleshash =
9944: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9945: $args->{'ccdomain'},
9946: 'userroles',['active'],['cc'],
9947: [$args->{'clonedomain'}]);
9948: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9949: $can_clone = 1;
9950: } else {
9951: $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'});
9952: }
1.566 albertel 9953: }
1.578 raeburn 9954: }
1.566 albertel 9955: }
9956: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9957: }
9958:
1.444 albertel 9959: sub construct_course {
1.885 raeburn 9960: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 9961: my $outcome;
1.541 raeburn 9962: my $linefeed = '<br />'."\n";
9963: if ($context eq 'auto') {
9964: $linefeed = "\n";
9965: }
1.566 albertel 9966:
9967: #
9968: # Are we cloning?
9969: #
9970: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9971: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9972: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9973: if ($context ne 'auto') {
1.578 raeburn 9974: if ($clonemsg ne '') {
9975: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9976: }
1.566 albertel 9977: }
9978: $outcome .= $clonemsg.$linefeed;
9979:
9980: if (!$can_clone) {
9981: return (0,$outcome);
9982: }
9983: }
9984:
1.444 albertel 9985: #
9986: # Open course
9987: #
9988: my $crstype = lc($args->{'crstype'});
9989: my %cenv=();
9990: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9991: $args->{'cdescr'},
9992: $args->{'curl'},
9993: $args->{'course_home'},
9994: $args->{'nonstandard'},
9995: $args->{'crscode'},
9996: $args->{'ccuname'}.':'.
9997: $args->{'ccdomain'},
1.882 raeburn 9998: $args->{'crstype'},
1.885 raeburn 9999: $cnum,$context,$category);
1.444 albertel 10000:
10001: # Note: The testing routines depend on this being output; see
10002: # Utils::Course. This needs to at least be output as a comment
10003: # if anyone ever decides to not show this, and Utils::Course::new
10004: # will need to be suitably modified.
1.541 raeburn 10005: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 10006: #
10007: # Check if created correctly
10008: #
1.479 albertel 10009: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10010: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 10011: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10012:
1.444 albertel 10013: #
1.566 albertel 10014: # Do the cloning
10015: #
10016: if ($can_clone && $cloneid) {
10017: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10018: if ($context ne 'auto') {
10019: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10020: }
10021: $outcome .= $clonemsg.$linefeed;
10022: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10023: # Copy all files
1.637 www 10024: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10025: # Restore URL
1.566 albertel 10026: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10027: # Restore title
1.566 albertel 10028: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 10029: # Mark as cloned
1.566 albertel 10030: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10031: # Need to clone grading mode
10032: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10033: $cenv{'grading'}=$newenv{'grading'};
10034: # Do not clone these environment entries
10035: &Apache::lonnet::del('environment',
10036: ['default_enrollment_start_date',
10037: 'default_enrollment_end_date',
10038: 'question.email',
10039: 'policy.email',
10040: 'comment.email',
10041: 'pch.users.denied',
1.725 raeburn 10042: 'plc.users.denied',
10043: 'hidefromcat',
10044: 'categories'],
1.638 www 10045: $$crsudom,$$crsunum);
1.444 albertel 10046: }
1.566 albertel 10047:
1.444 albertel 10048: #
10049: # Set environment (will override cloned, if existing)
10050: #
10051: my @sections = ();
10052: my @xlists = ();
10053: if ($args->{'crstype'}) {
10054: $cenv{'type'}=$args->{'crstype'};
10055: }
10056: if ($args->{'crsid'}) {
10057: $cenv{'courseid'}=$args->{'crsid'};
10058: }
10059: if ($args->{'crscode'}) {
10060: $cenv{'internal.coursecode'}=$args->{'crscode'};
10061: }
10062: if ($args->{'crsquota'} ne '') {
10063: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10064: } else {
10065: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10066: }
10067: if ($args->{'ccuname'}) {
10068: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10069: ':'.$args->{'ccdomain'};
10070: } else {
10071: $cenv{'internal.courseowner'} = $args->{'curruser'};
10072: }
10073: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10074: if ($args->{'crssections'}) {
10075: $cenv{'internal.sectionnums'} = '';
10076: if ($args->{'crssections'} =~ m/,/) {
10077: @sections = split/,/,$args->{'crssections'};
10078: } else {
10079: $sections[0] = $args->{'crssections'};
10080: }
10081: if (@sections > 0) {
10082: foreach my $item (@sections) {
10083: my ($sec,$gp) = split/:/,$item;
10084: my $class = $args->{'crscode'}.$sec;
10085: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10086: $cenv{'internal.sectionnums'} .= $item.',';
10087: unless ($addcheck eq 'ok') {
10088: push @badclasses, $class;
10089: }
10090: }
10091: $cenv{'internal.sectionnums'} =~ s/,$//;
10092: }
10093: }
10094: # do not hide course coordinator from staff listing,
10095: # even if privileged
10096: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10097: # add crosslistings
10098: if ($args->{'crsxlist'}) {
10099: $cenv{'internal.crosslistings'}='';
10100: if ($args->{'crsxlist'} =~ m/,/) {
10101: @xlists = split/,/,$args->{'crsxlist'};
10102: } else {
10103: $xlists[0] = $args->{'crsxlist'};
10104: }
10105: if (@xlists > 0) {
10106: foreach my $item (@xlists) {
10107: my ($xl,$gp) = split/:/,$item;
10108: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10109: $cenv{'internal.crosslistings'} .= $item.',';
10110: unless ($addcheck eq 'ok') {
10111: push @badclasses, $xl;
10112: }
10113: }
10114: $cenv{'internal.crosslistings'} =~ s/,$//;
10115: }
10116: }
10117: if ($args->{'autoadds'}) {
10118: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10119: }
10120: if ($args->{'autodrops'}) {
10121: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10122: }
10123: # check for notification of enrollment changes
10124: my @notified = ();
10125: if ($args->{'notify_owner'}) {
10126: if ($args->{'ccuname'} ne '') {
10127: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10128: }
10129: }
10130: if ($args->{'notify_dc'}) {
10131: if ($uname ne '') {
1.630 raeburn 10132: push(@notified,$uname.':'.$udom);
1.444 albertel 10133: }
10134: }
10135: if (@notified > 0) {
10136: my $notifylist;
10137: if (@notified > 1) {
10138: $notifylist = join(',',@notified);
10139: } else {
10140: $notifylist = $notified[0];
10141: }
10142: $cenv{'internal.notifylist'} = $notifylist;
10143: }
10144: if (@badclasses > 0) {
10145: my %lt=&Apache::lonlocal::texthash(
10146: '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',
10147: 'dnhr' => 'does not have rights to access enrollment in these classes',
10148: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10149: );
1.541 raeburn 10150: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10151: ' ('.$lt{'adby'}.')';
10152: if ($context eq 'auto') {
10153: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10154: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10155: foreach my $item (@badclasses) {
10156: if ($context eq 'auto') {
10157: $outcome .= " - $item\n";
10158: } else {
10159: $outcome .= "<li>$item</li>\n";
10160: }
10161: }
10162: if ($context eq 'auto') {
10163: $outcome .= $linefeed;
10164: } else {
1.566 albertel 10165: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10166: }
10167: }
1.444 albertel 10168: }
10169: if ($args->{'no_end_date'}) {
10170: $args->{'endaccess'} = 0;
10171: }
10172: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10173: $cenv{'internal.autoend'}=$args->{'enrollend'};
10174: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10175: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10176: if ($args->{'showphotos'}) {
10177: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10178: }
10179: $cenv{'internal.authtype'} = $args->{'authtype'};
10180: $cenv{'internal.autharg'} = $args->{'autharg'};
10181: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10182: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10183: 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');
10184: if ($context eq 'auto') {
10185: $outcome .= $krb_msg;
10186: } else {
1.566 albertel 10187: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10188: }
10189: $outcome .= $linefeed;
1.444 albertel 10190: }
10191: }
10192: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10193: if ($args->{'setpolicy'}) {
10194: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10195: }
10196: if ($args->{'setcontent'}) {
10197: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10198: }
10199: }
10200: if ($args->{'reshome'}) {
10201: $cenv{'reshome'}=$args->{'reshome'}.'/';
10202: $cenv{'reshome'}=~s/\/+$/\//;
10203: }
10204: #
10205: # course has keyed access
10206: #
10207: if ($args->{'setkeys'}) {
10208: $cenv{'keyaccess'}='yes';
10209: }
10210: # if specified, key authority is not course, but user
10211: # only active if keyaccess is yes
10212: if ($args->{'keyauth'}) {
1.487 albertel 10213: my ($user,$domain) = split(':',$args->{'keyauth'});
10214: $user = &LONCAPA::clean_username($user);
10215: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10216: if ($user ne '' && $domain ne '') {
1.487 albertel 10217: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10218: }
10219: }
10220:
10221: if ($args->{'disresdis'}) {
10222: $cenv{'pch.roles.denied'}='st';
10223: }
10224: if ($args->{'disablechat'}) {
10225: $cenv{'plc.roles.denied'}='st';
10226: }
10227:
10228: # Record we've not yet viewed the Course Initialization Helper for this
10229: # course
10230: $cenv{'course.helper.not.run'} = 1;
10231: #
10232: # Use new Randomseed
10233: #
10234: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10235: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10236: #
10237: # The encryption code and receipt prefix for this course
10238: #
10239: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10240: $cenv{'internal.encpref'}=100+int(9*rand(99));
10241: #
10242: # By default, use standard grading
10243: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10244:
1.541 raeburn 10245: $outcome .= $linefeed.&mt('Setting environment').': '.
10246: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10247: #
10248: # Open all assignments
10249: #
10250: if ($args->{'openall'}) {
10251: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10252: my %storecontent = ($storeunder => time,
10253: $storeunder.'.type' => 'date_start');
10254:
10255: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10256: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10257: }
10258: #
10259: # Set first page
10260: #
10261: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10262: || ($cloneid)) {
1.445 albertel 10263: use LONCAPA::map;
1.444 albertel 10264: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10265:
10266: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10267: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10268:
1.444 albertel 10269: $outcome .= ($fatal?$errtext:'read ok').' - ';
10270: my $title; my $url;
10271: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10272: $title=&mt('Syllabus');
1.444 albertel 10273: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10274: } else {
1.690 bisitz 10275: $title=&mt('Navigate Contents');
1.444 albertel 10276: $url='/adm/navmaps';
10277: }
1.445 albertel 10278:
10279: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10280: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10281:
10282: if ($errtext) { $fatal=2; }
1.541 raeburn 10283: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10284: }
1.566 albertel 10285:
10286: return (1,$outcome);
1.444 albertel 10287: }
10288:
10289: ############################################################
10290: ############################################################
10291:
1.378 raeburn 10292: sub course_type {
10293: my ($cid) = @_;
10294: if (!defined($cid)) {
10295: $cid = $env{'request.course.id'};
10296: }
1.404 albertel 10297: if (defined($env{'course.'.$cid.'.type'})) {
10298: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10299: } else {
10300: return 'Course';
1.377 raeburn 10301: }
10302: }
1.156 albertel 10303:
1.406 raeburn 10304: sub group_term {
10305: my $crstype = &course_type();
10306: my %names = (
10307: 'Course' => 'group',
1.865 raeburn 10308: 'Community' => 'group',
1.406 raeburn 10309: );
10310: return $names{$crstype};
10311: }
10312:
1.902 raeburn 10313: sub course_types {
10314: my @types = ('official','unofficial','community');
10315: my %typename = (
10316: official => 'Official course',
10317: unofficial => 'Unofficial course',
10318: community => 'Community',
10319: );
10320: return (\@types,\%typename);
10321: }
10322:
1.156 albertel 10323: sub icon {
10324: my ($file)=@_;
1.505 albertel 10325: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10326: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10327: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10328: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10329: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10330: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10331: $curfext.".gif") {
10332: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10333: $curfext.".gif";
10334: }
10335: }
1.249 albertel 10336: return &lonhttpdurl($iconname);
1.154 albertel 10337: }
1.84 albertel 10338:
1.575 albertel 10339: sub lonhttpdurl {
1.692 www 10340: #
10341: # Had been used for "small fry" static images on separate port 8080.
10342: # Modify here if lightweight http functionality desired again.
10343: # Currently eliminated due to increasing firewall issues.
10344: #
1.575 albertel 10345: my ($url)=@_;
1.692 www 10346: return $url;
1.215 albertel 10347: }
10348:
1.213 albertel 10349: sub connection_aborted {
10350: my ($r)=@_;
10351: $r->print(" ");$r->rflush();
10352: my $c = $r->connection;
10353: return $c->aborted();
10354: }
10355:
1.221 foxr 10356: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10357: # strings as 'strings'.
10358: sub escape_single {
1.221 foxr 10359: my ($input) = @_;
1.223 albertel 10360: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10361: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10362: return $input;
10363: }
1.223 albertel 10364:
1.222 foxr 10365: # Same as escape_single, but escape's "'s This
10366: # can be used for "strings"
10367: sub escape_double {
10368: my ($input) = @_;
10369: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10370: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10371: return $input;
10372: }
1.223 albertel 10373:
1.222 foxr 10374: # Escapes the last element of a full URL.
10375: sub escape_url {
10376: my ($url) = @_;
1.238 raeburn 10377: my @urlslices = split(/\//, $url,-1);
1.369 www 10378: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10379: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10380: }
1.462 albertel 10381:
1.820 raeburn 10382: sub compare_arrays {
10383: my ($arrayref1,$arrayref2) = @_;
10384: my (@difference,%count);
10385: @difference = ();
10386: %count = ();
10387: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10388: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10389: foreach my $element (keys(%count)) {
10390: if ($count{$element} == 1) {
10391: push(@difference,$element);
10392: }
10393: }
10394: }
10395: return @difference;
10396: }
10397:
1.817 bisitz 10398: # -------------------------------------------------------- Initialize user login
1.462 albertel 10399: sub init_user_environment {
1.463 albertel 10400: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10401: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10402:
10403: my $public=($username eq 'public' && $domain eq 'public');
10404:
10405: # See if old ID present, if so, remove
10406:
10407: my ($filename,$cookie,$userroles);
10408: my $now=time;
10409:
10410: if ($public) {
10411: my $max_public=100;
10412: my $oldest;
10413: my $oldest_time=0;
10414: for(my $next=1;$next<=$max_public;$next++) {
10415: if (-e $lonids."/publicuser_$next.id") {
10416: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10417: if ($mtime<$oldest_time || !$oldest_time) {
10418: $oldest_time=$mtime;
10419: $oldest=$next;
10420: }
10421: } else {
10422: $cookie="publicuser_$next";
10423: last;
10424: }
10425: }
10426: if (!$cookie) { $cookie="publicuser_$oldest"; }
10427: } else {
1.463 albertel 10428: # if this isn't a robot, kill any existing non-robot sessions
10429: if (!$args->{'robot'}) {
10430: opendir(DIR,$lonids);
10431: while ($filename=readdir(DIR)) {
10432: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10433: unlink($lonids.'/'.$filename);
10434: }
1.462 albertel 10435: }
1.463 albertel 10436: closedir(DIR);
1.462 albertel 10437: }
10438: # Give them a new cookie
1.463 albertel 10439: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10440: : $now.$$.int(rand(10000)));
1.463 albertel 10441: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10442:
10443: # Initialize roles
10444:
10445: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10446: }
10447: # ------------------------------------ Check browser type and MathML capability
10448:
10449: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10450: $clientunicode,$clientos) = &decode_user_agent($r);
10451:
10452: # ------------------------------------------------------------- Get environment
10453:
10454: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10455: my ($tmp) = keys(%userenv);
10456: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10457: # default remote control to off
10458: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10459: } else {
10460: undef(%userenv);
10461: }
10462: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10463: $form->{'interface'}=$userenv{'interface'};
10464: }
10465: $env{'environment.remote'}=$userenv{'remote'};
10466: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10467:
10468: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10469: foreach my $option ('interface','localpath','localres') {
10470: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10471: }
10472: # --------------------------------------------------------- Write first profile
10473:
10474: {
10475: my %initial_env =
10476: ("user.name" => $username,
10477: "user.domain" => $domain,
10478: "user.home" => $authhost,
10479: "browser.type" => $clientbrowser,
10480: "browser.version" => $clientversion,
10481: "browser.mathml" => $clientmathml,
10482: "browser.unicode" => $clientunicode,
10483: "browser.os" => $clientos,
10484: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10485: "request.course.fn" => '',
10486: "request.course.uri" => '',
10487: "request.course.sec" => '',
10488: "request.role" => 'cm',
10489: "request.role.adv" => $env{'user.adv'},
10490: "request.host" => $ENV{'REMOTE_ADDR'},);
10491:
10492: if ($form->{'localpath'}) {
10493: $initial_env{"browser.localpath"} = $form->{'localpath'};
10494: $initial_env{"browser.localres"} = $form->{'localres'};
10495: }
10496:
10497: if ($public) {
10498: $initial_env{"environment.remote"} = "off";
10499: }
10500: if ($form->{'interface'}) {
10501: $form->{'interface'}=~s/\W//gs;
10502: $initial_env{"browser.interface"} = $form->{'interface'};
10503: $env{'browser.interface'}=$form->{'interface'};
10504: }
10505:
1.724 raeburn 10506: foreach my $tool ('aboutme','blog','portfolio') {
10507: $userenv{'availabletools.'.$tool} =
10508: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10509: }
10510:
1.864 raeburn 10511: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10512: $userenv{'canrequest.'.$crstype} =
10513: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10514: 'reload','requestcourses');
10515: }
10516:
1.462 albertel 10517: $env{'user.environment'} = "$lonids/$cookie.id";
10518:
10519: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10520: &GDBM_WRCREAT(),0640)) {
10521: &_add_to_env(\%disk_env,\%initial_env);
10522: &_add_to_env(\%disk_env,\%userenv,'environment.');
10523: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10524: if (ref($args->{'extra_env'})) {
10525: &_add_to_env(\%disk_env,$args->{'extra_env'});
10526: }
1.462 albertel 10527: untie(%disk_env);
10528: } else {
1.705 tempelho 10529: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10530: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10531: return 'error: '.$!;
10532: }
10533: }
10534: $env{'request.role'}='cm';
10535: $env{'request.role.adv'}=$env{'user.adv'};
10536: $env{'browser.type'}=$clientbrowser;
10537:
10538: return $cookie;
10539:
10540: }
10541:
10542: sub _add_to_env {
10543: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10544: if (ref($env_data) eq 'HASH') {
10545: while (my ($key,$value) = each(%$env_data)) {
10546: $idf->{$prefix.$key} = $value;
10547: $env{$prefix.$key} = $value;
10548: }
1.462 albertel 10549: }
10550: }
10551:
1.685 tempelho 10552: # --- Get the symbolic name of a problem and the url
10553: sub get_symb {
10554: my ($request,$silent) = @_;
1.726 raeburn 10555: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10556: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10557: if ($symb eq '') {
10558: if (!$silent) {
10559: $request->print("Unable to handle ambiguous references:$url:.");
10560: return ();
10561: }
10562: }
10563: &Apache::lonenc::check_decrypt(\$symb);
10564: return ($symb);
10565: }
10566:
10567: # --------------------------------------------------------------Get annotation
10568:
10569: sub get_annotation {
10570: my ($symb,$enc) = @_;
10571:
10572: my $key = $symb;
10573: if (!$enc) {
10574: $key =
10575: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10576: }
10577: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10578: return $annotation{$key};
10579: }
10580:
10581: sub clean_symb {
1.731 raeburn 10582: my ($symb,$delete_enc) = @_;
1.685 tempelho 10583:
10584: &Apache::lonenc::check_decrypt(\$symb);
10585: my $enc = $env{'request.enc'};
1.731 raeburn 10586: if ($delete_enc) {
1.730 raeburn 10587: delete($env{'request.enc'});
10588: }
1.685 tempelho 10589:
10590: return ($symb,$enc);
10591: }
1.462 albertel 10592:
1.41 ng 10593: =pod
10594:
10595: =back
10596:
1.112 bowersj2 10597: =cut
1.41 ng 10598:
1.112 bowersj2 10599: 1;
10600: __END__;
1.41 ng 10601:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>