Annotation of loncom/interface/loncommon.pm, revision 1.904
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.904 ! droeschl 4: # $Id: loncommon.pm,v 1.903 2009/10/26 18:59:16 droeschl Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.468 raeburn 485: my ($domainfilter,$sec_element,$formname)=@_;
1.886 raeburn 486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role.');
1.876 raeburn 487: my $id_functions = &javascript_index_functions();
488: my $output = '
1.776 bisitz 489: <script type="text/javascript" language="JavaScript">
1.824 bisitz 490: // <![CDATA[
1.468 raeburn 491: var stdeditbrowser;'."\n";
1.876 raeburn 492:
493: $output .= <<"ENDSTDBRW";
1.377 raeburn 494: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 495: var url = '/adm/pickcourse?';
1.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
551: if ($sec_element ne '') {
552: $output .= &setsec_javascript($sec_element,$formname);
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 {
664: my ($sec_element,$formname) = @_;
665: my $setsections = qq|
666: function setSect(sectionlist) {
1.629 raeburn 667: var sectionsArray = new Array();
668: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
669: sectionsArray = sectionlist.split(",");
670: }
1.468 raeburn 671: var numSections = sectionsArray.length;
672: document.$formname.$sec_element.length = 0;
673: if (numSections == 0) {
674: document.$formname.$sec_element.multiple=false;
675: document.$formname.$sec_element.size=1;
676: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
677: } else {
678: if (numSections == 1) {
679: document.$formname.$sec_element.multiple=false;
680: document.$formname.$sec_element.size=1;
681: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
682: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
683: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
684: } else {
685: for (var i=0; i<numSections; i++) {
686: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
687: }
688: document.$formname.$sec_element.multiple=true
689: if (numSections < 3) {
690: document.$formname.$sec_element.size=numSections;
691: } else {
692: document.$formname.$sec_element.size=3;
693: }
694: document.$formname.$sec_element.options[0].selected = false
695: }
696: }
1.91 www 697: }
1.468 raeburn 698: |;
699: return $setsections;
700: }
701:
1.91 www 702:
703: sub selectcourse_link {
1.377 raeburn 704: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.871 raeburn 705: my $linktext = &mt('Select Course');
706: if ($selecttype eq 'Community') {
707: $linktext = &mt('Select Community');
708: }
1.787 bisitz 709: return '<span class="LC_nobreak">'
710: ."<a href='"
711: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
712: .'","'.$udomele.'","'.$desc.'","'.$extra_element
713: .'","'.$multflag.'","'.$selecttype.'");'
1.871 raeburn 714: ."'>".$linktext.'</a>'
1.787 bisitz 715: .'</span>';
1.74 www 716: }
1.42 matthew 717:
1.653 raeburn 718: sub selectauthor_link {
719: my ($form,$udom)=@_;
720: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
721: &mt('Select Author').'</a>';
722: }
723:
1.876 raeburn 724: sub selectuser_link {
1.881 raeburn 725: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 726: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 727: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 728: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 729: ');">'.$linktext.'</a>';
1.876 raeburn 730: }
731:
1.273 raeburn 732: sub check_uncheck_jscript {
733: my $jscript = <<"ENDSCRT";
734: function checkAll(field) {
735: if (field.length > 0) {
736: for (i = 0; i < field.length; i++) {
737: field[i].checked = true ;
738: }
739: } else {
740: field.checked = true
741: }
742: }
743:
744: function uncheckAll(field) {
745: if (field.length > 0) {
746: for (i = 0; i < field.length; i++) {
747: field[i].checked = false ;
1.543 albertel 748: }
749: } else {
1.273 raeburn 750: field.checked = false ;
751: }
752: }
753: ENDSCRT
754: return $jscript;
755: }
756:
1.656 www 757: sub select_timezone {
1.659 raeburn 758: my ($name,$selected,$onchange,$includeempty)=@_;
759: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
760: if ($includeempty) {
761: $output .= '<option value=""';
762: if (($selected eq '') || ($selected eq 'local')) {
763: $output .= ' selected="selected" ';
764: }
765: $output .= '> </option>';
766: }
1.657 raeburn 767: my @timezones = DateTime::TimeZone->all_names;
768: foreach my $tzone (@timezones) {
769: $output.= '<option value="'.$tzone.'"';
770: if ($tzone eq $selected) {
771: $output.=' selected="selected"';
772: }
773: $output.=">$tzone</option>\n";
1.656 www 774: }
775: $output.="</select>";
776: return $output;
777: }
1.273 raeburn 778:
1.687 raeburn 779: sub select_datelocale {
780: my ($name,$selected,$onchange,$includeempty)=@_;
781: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
782: if ($includeempty) {
783: $output .= '<option value=""';
784: if ($selected eq '') {
785: $output .= ' selected="selected" ';
786: }
787: $output .= '> </option>';
788: }
789: my (@possibles,%locale_names);
790: my @locales = DateTime::Locale::Catalog::Locales;
791: foreach my $locale (@locales) {
792: if (ref($locale) eq 'HASH') {
793: my $id = $locale->{'id'};
794: if ($id ne '') {
795: my $en_terr = $locale->{'en_territory'};
796: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 797: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 798: if (grep(/^en$/,@languages) || !@languages) {
799: if ($en_terr ne '') {
800: $locale_names{$id} = '('.$en_terr.')';
801: } elsif ($native_terr ne '') {
802: $locale_names{$id} = $native_terr;
803: }
804: } else {
805: if ($native_terr ne '') {
806: $locale_names{$id} = $native_terr.' ';
807: } elsif ($en_terr ne '') {
808: $locale_names{$id} = '('.$en_terr.')';
809: }
810: }
811: push (@possibles,$id);
812: }
813: }
814: }
815: foreach my $item (sort(@possibles)) {
816: $output.= '<option value="'.$item.'"';
817: if ($item eq $selected) {
818: $output.=' selected="selected"';
819: }
820: $output.=">$item";
821: if ($locale_names{$item} ne '') {
822: $output.=" $locale_names{$item}</option>\n";
823: }
824: $output.="</option>\n";
825: }
826: $output.="</select>";
827: return $output;
828: }
829:
1.792 raeburn 830: sub select_language {
831: my ($name,$selected,$includeempty) = @_;
832: my %langchoices;
833: if ($includeempty) {
834: %langchoices = ('' => 'No language preference');
835: }
836: foreach my $id (&languageids()) {
837: my $code = &supportedlanguagecode($id);
838: if ($code) {
839: $langchoices{$code} = &plainlanguagedescription($id);
840: }
841: }
842: return &select_form($selected,$name,%langchoices);
843: }
844:
1.42 matthew 845: =pod
1.36 matthew 846:
1.648 raeburn 847: =item * &linked_select_forms(...)
1.36 matthew 848:
849: linked_select_forms returns a string containing a <script></script> block
850: and html for two <select> menus. The select menus will be linked in that
851: changing the value of the first menu will result in new values being placed
852: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 853: order unless a defined order is provided.
1.36 matthew 854:
855: linked_select_forms takes the following ordered inputs:
856:
857: =over 4
858:
1.112 bowersj2 859: =item * $formname, the name of the <form> tag
1.36 matthew 860:
1.112 bowersj2 861: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 862:
1.112 bowersj2 863: =item * $firstdefault, the default value for the first menu
1.36 matthew 864:
1.112 bowersj2 865: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 866:
1.112 bowersj2 867: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 868:
1.112 bowersj2 869: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 870:
1.609 raeburn 871: =item * $menuorder, the order of values in the first menu
872:
1.41 ng 873: =back
874:
1.36 matthew 875: Below is an example of such a hash. Only the 'text', 'default', and
876: 'select2' keys must appear as stated. keys(%menu) are the possible
877: values for the first select menu. The text that coincides with the
1.41 ng 878: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 879: and text for the second menu are given in the hash pointed to by
880: $menu{$choice1}->{'select2'}.
881:
1.112 bowersj2 882: my %menu = ( A1 => { text =>"Choice A1" ,
883: default => "B3",
884: select2 => {
885: B1 => "Choice B1",
886: B2 => "Choice B2",
887: B3 => "Choice B3",
888: B4 => "Choice B4"
1.609 raeburn 889: },
890: order => ['B4','B3','B1','B2'],
1.112 bowersj2 891: },
892: A2 => { text =>"Choice A2" ,
893: default => "C2",
894: select2 => {
895: C1 => "Choice C1",
896: C2 => "Choice C2",
897: C3 => "Choice C3"
1.609 raeburn 898: },
899: order => ['C2','C1','C3'],
1.112 bowersj2 900: },
901: A3 => { text =>"Choice A3" ,
902: default => "D6",
903: select2 => {
904: D1 => "Choice D1",
905: D2 => "Choice D2",
906: D3 => "Choice D3",
907: D4 => "Choice D4",
908: D5 => "Choice D5",
909: D6 => "Choice D6",
910: D7 => "Choice D7"
1.609 raeburn 911: },
912: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 913: }
914: );
1.36 matthew 915:
916: =cut
917:
918: sub linked_select_forms {
919: my ($formname,
920: $middletext,
921: $firstdefault,
922: $firstselectname,
923: $secondselectname,
1.609 raeburn 924: $hashref,
925: $menuorder,
1.36 matthew 926: ) = @_;
927: my $second = "document.$formname.$secondselectname";
928: my $first = "document.$formname.$firstselectname";
929: # output the javascript to do the changing
930: my $result = '';
1.776 bisitz 931: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 932: $result.="// <![CDATA[\n";
1.36 matthew 933: $result.="var select2data = new Object();\n";
934: $" = '","';
935: my $debug = '';
936: foreach my $s1 (sort(keys(%$hashref))) {
937: $result.="select2data.d_$s1 = new Object();\n";
938: $result.="select2data.d_$s1.def = new String('".
939: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 940: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 941: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 942: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
943: @s2values = @{$hashref->{$s1}->{'order'}};
944: }
1.36 matthew 945: $result.="\"@s2values\");\n";
946: $result.="select2data.d_$s1.texts = new Array(";
947: my @s2texts;
948: foreach my $value (@s2values) {
949: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
950: }
951: $result.="\"@s2texts\");\n";
952: }
953: $"=' ';
954: $result.= <<"END";
955:
956: function select1_changed() {
957: // Determine new choice
958: var newvalue = "d_" + $first.value;
959: // update select2
960: var values = select2data[newvalue].values;
961: var texts = select2data[newvalue].texts;
962: var select2def = select2data[newvalue].def;
963: var i;
964: // out with the old
965: for (i = 0; i < $second.options.length; i++) {
966: $second.options[i] = null;
967: }
968: // in with the nuclear
969: for (i=0;i<values.length; i++) {
970: $second.options[i] = new Option(values[i]);
1.143 matthew 971: $second.options[i].value = values[i];
1.36 matthew 972: $second.options[i].text = texts[i];
973: if (values[i] == select2def) {
974: $second.options[i].selected = true;
975: }
976: }
977: }
1.824 bisitz 978: // ]]>
1.36 matthew 979: </script>
980: END
981: # output the initial values for the selection lists
982: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 983: my @order = sort(keys(%{$hashref}));
984: if (ref($menuorder) eq 'ARRAY') {
985: @order = @{$menuorder};
986: }
987: foreach my $value (@order) {
1.36 matthew 988: $result.=" <option value=\"$value\" ";
1.253 albertel 989: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 990: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 991: }
992: $result .= "</select>\n";
993: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
994: $result .= $middletext;
995: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
996: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 997:
998: my @secondorder = sort(keys(%select2));
999: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1000: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1001: }
1002: foreach my $value (@secondorder) {
1.36 matthew 1003: $result.=" <option value=\"$value\" ";
1.253 albertel 1004: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1005: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1006: }
1007: $result .= "</select>\n";
1008: # return $debug;
1009: return $result;
1010: } # end of sub linked_select_forms {
1011:
1.45 matthew 1012: =pod
1.44 bowersj2 1013:
1.648 raeburn 1014: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 1015:
1.112 bowersj2 1016: Returns a string corresponding to an HTML link to the given help
1017: $topic, where $topic corresponds to the name of a .tex file in
1018: /home/httpd/html/adm/help/tex, with underscores replaced by
1019: spaces.
1020:
1021: $text will optionally be linked to the same topic, allowing you to
1022: link text in addition to the graphic. If you do not want to link
1023: text, but wish to specify one of the later parameters, pass an
1024: empty string.
1025:
1026: $stayOnPage is a value that will be interpreted as a boolean. If true,
1027: the link will not open a new window. If false, the link will open
1028: a new window using Javascript. (Default is false.)
1029:
1030: $width and $height are optional numerical parameters that will
1031: override the width and height of the popped up window, which may
1032: be useful for certain help topics with big pictures included.
1.44 bowersj2 1033:
1034: =cut
1035:
1036: sub help_open_topic {
1.48 bowersj2 1037: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1038: $text = "" if (not defined $text);
1.44 bowersj2 1039: $stayOnPage = 0 if (not defined $stayOnPage);
1040: $width = 350 if (not defined $width);
1041: $height = 400 if (not defined $height);
1042: my $filename = $topic;
1043: $filename =~ s/ /_/g;
1044:
1.48 bowersj2 1045: my $template = "";
1046: my $link;
1.572 banghart 1047:
1.159 www 1048: $topic=~s/\W/\_/g;
1.44 bowersj2 1049:
1.572 banghart 1050: if (!$stayOnPage) {
1.72 bowersj2 1051: $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 1052: } else {
1.48 bowersj2 1053: $link = "/adm/help/${filename}.hlp";
1054: }
1055:
1056: # Add the text
1.755 neumanie 1057: if ($text ne "") {
1.763 bisitz 1058: $template.='<span class="LC_help_open_topic">'
1059: .'<a target="_top" href="'.$link.'">'
1060: .$text.'</a>';
1.48 bowersj2 1061: }
1062:
1.763 bisitz 1063: # (Always) Add the graphic
1.179 matthew 1064: my $title = &mt('Online Help');
1.667 raeburn 1065: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 1066: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1067: .'<img src="'.$helpicon.'" border="0"'
1068: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 1069: .' title="'.$title.'"'
1.763 bisitz 1070: .' /></a>';
1071: if ($text ne "") {
1072: $template.='</span>';
1073: }
1.44 bowersj2 1074: return $template;
1075:
1.106 bowersj2 1076: }
1077:
1078: # This is a quicky function for Latex cheatsheet editing, since it
1079: # appears in at least four places
1080: sub helpLatexCheatsheet {
1.732 raeburn 1081: my ($topic,$text,$not_author) = @_;
1082: my $out;
1.106 bowersj2 1083: my $addOther = '';
1.732 raeburn 1084: if ($topic) {
1.763 bisitz 1085: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1086: undef, undef, 600).
1087: '</span> ';
1088: }
1089: $out = '<span>' # Start cheatsheet
1090: .$addOther
1091: .'<span>'
1092: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1093: undef,undef,600)
1094: .'</span> <span>'
1095: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1096: undef,undef,600)
1097: .'</span>';
1.732 raeburn 1098: unless ($not_author) {
1.763 bisitz 1099: $out .= ' <span>'
1100: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1101: undef,undef,600)
1102: .'</span>';
1.732 raeburn 1103: }
1.763 bisitz 1104: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1105: return $out;
1.172 www 1106: }
1107:
1.430 albertel 1108: sub general_help {
1109: my $helptopic='Student_Intro';
1110: if ($env{'request.role'}=~/^(ca|au)/) {
1111: $helptopic='Authoring_Intro';
1112: } elsif ($env{'request.role'}=~/^cc/) {
1113: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1114: } elsif ($env{'request.role'}=~/^dc/) {
1115: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1116: }
1117: return $helptopic;
1118: }
1119:
1120: sub update_help_link {
1121: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1122: my $origurl = $ENV{'REQUEST_URI'};
1123: $origurl=~s|^/~|/priv/|;
1124: my $timestamp = time;
1125: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1126: $$datum = &escape($$datum);
1127: }
1128:
1129: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1130: my $output .= <<"ENDOUTPUT";
1131: <script type="text/javascript">
1.824 bisitz 1132: // <![CDATA[
1.430 albertel 1133: banner_link = '$banner_link';
1.824 bisitz 1134: // ]]>
1.430 albertel 1135: </script>
1136: ENDOUTPUT
1137: return $output;
1138: }
1139:
1140: # now just updates the help link and generates a blue icon
1.193 raeburn 1141: sub help_open_menu {
1.430 albertel 1142: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1143: = @_;
1.430 albertel 1144: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1145: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1146: # if environment.remote is on (using remote control UI)
1.798 tempelho 1147: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1148: $stayOnPage=1;
1.430 albertel 1149: }
1150: my $output;
1151: if ($component_help) {
1152: if (!$text) {
1153: $output=&help_open_topic($component_help,undef,$stayOnPage,
1154: $width,$height);
1155: } else {
1156: my $help_text;
1157: $help_text=&unescape($topic);
1158: $output='<table><tr><td>'.
1159: &help_open_topic($component_help,$help_text,$stayOnPage,
1160: $width,$height).'</td></tr></table>';
1161: }
1162: }
1163: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1164: return $output.$banner_link;
1165: }
1166:
1167: sub top_nav_help {
1168: my ($text) = @_;
1.436 albertel 1169: $text = &mt($text);
1.572 banghart 1170: my $stay_on_page =
1.798 tempelho 1171: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1172: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1173: : "javascript:helpMenu('open')";
1.572 banghart 1174: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1175:
1.201 raeburn 1176: my $title = &mt('Get help');
1.436 albertel 1177:
1178: return <<"END";
1179: $banner_link
1180: <a href="$link" title="$title">$text</a>
1181: END
1182: }
1183:
1184: sub help_menu_js {
1185: my ($text) = @_;
1186:
1187: my $stayOnPage =
1.798 tempelho 1188: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1189:
1190: my $width = 620;
1191: my $height = 600;
1.430 albertel 1192: my $helptopic=&general_help();
1193: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1194: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1195: my $start_page =
1196: &Apache::loncommon::start_page('Help Menu', undef,
1197: {'frameset' => 1,
1198: 'js_ready' => 1,
1199: 'add_entries' => {
1200: 'border' => '0',
1.579 raeburn 1201: 'rows' => "110,*",},});
1.331 albertel 1202: my $end_page =
1203: &Apache::loncommon::end_page({'frameset' => 1,
1204: 'js_ready' => 1,});
1205:
1.436 albertel 1206: my $template .= <<"ENDTEMPLATE";
1207: <script type="text/javascript">
1.877 bisitz 1208: // <![CDATA[
1.253 albertel 1209: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1210: var banner_link = '';
1.243 raeburn 1211: function helpMenu(target) {
1212: var caller = this;
1213: if (target == 'open') {
1214: var newWindow = null;
1215: try {
1.262 albertel 1216: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1217: }
1218: catch(error) {
1219: writeHelp(caller);
1220: return;
1221: }
1222: if (newWindow) {
1223: caller = newWindow;
1224: }
1.193 raeburn 1225: }
1.243 raeburn 1226: writeHelp(caller);
1227: return;
1228: }
1229: function writeHelp(caller) {
1.430 albertel 1230: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1231: caller.document.close()
1232: caller.focus()
1.193 raeburn 1233: }
1.877 bisitz 1234: // END LON-CAPA Internal -->
1.253 albertel 1235: // ]]>
1.436 albertel 1236: </script>
1.193 raeburn 1237: ENDTEMPLATE
1238: return $template;
1239: }
1240:
1.172 www 1241: sub help_open_bug {
1242: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1243: unless ($env{'user.adv'}) { return ''; }
1.172 www 1244: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1245: $text = "" if (not defined $text);
1246: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1247: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1248: $stayOnPage=1;
1249: }
1.184 albertel 1250: $width = 600 if (not defined $width);
1251: $height = 600 if (not defined $height);
1.172 www 1252:
1253: $topic=~s/\W+/\+/g;
1254: my $link='';
1255: my $template='';
1.379 albertel 1256: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1257: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1258: if (!$stayOnPage)
1259: {
1260: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1261: }
1262: else
1263: {
1264: $link = $url;
1265: }
1266: # Add the text
1267: if ($text ne "")
1268: {
1269: $template .=
1270: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1271: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1272: }
1273:
1274: # Add the graphic
1.179 matthew 1275: my $title = &mt('Report a Bug');
1.215 albertel 1276: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1277: $template .= <<"ENDTEMPLATE";
1.436 albertel 1278: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1279: ENDTEMPLATE
1280: if ($text ne '') { $template.='</td></tr></table>' };
1281: return $template;
1282:
1283: }
1284:
1285: sub help_open_faq {
1286: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1287: unless ($env{'user.adv'}) { return ''; }
1.172 www 1288: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1289: $text = "" if (not defined $text);
1290: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1291: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1292: $stayOnPage=1;
1293: }
1294: $width = 350 if (not defined $width);
1295: $height = 400 if (not defined $height);
1296:
1297: $topic=~s/\W+/\+/g;
1298: my $link='';
1299: my $template='';
1300: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1301: if (!$stayOnPage)
1302: {
1303: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1304: }
1305: else
1306: {
1307: $link = $url;
1308: }
1309:
1310: # Add the text
1311: if ($text ne "")
1312: {
1313: $template .=
1.173 www 1314: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1315: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1316: }
1317:
1318: # Add the graphic
1.179 matthew 1319: my $title = &mt('View the FAQ');
1.215 albertel 1320: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1321: $template .= <<"ENDTEMPLATE";
1.436 albertel 1322: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1323: ENDTEMPLATE
1324: if ($text ne '') { $template.='</td></tr></table>' };
1325: return $template;
1326:
1.44 bowersj2 1327: }
1.37 matthew 1328:
1.180 matthew 1329: ###############################################################
1330: ###############################################################
1331:
1.45 matthew 1332: =pod
1333:
1.648 raeburn 1334: =item * &change_content_javascript():
1.256 matthew 1335:
1336: This and the next function allow you to create small sections of an
1337: otherwise static HTML page that you can update on the fly with
1338: Javascript, even in Netscape 4.
1339:
1340: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1341: must be written to the HTML page once. It will prove the Javascript
1342: function "change(name, content)". Calling the change function with the
1343: name of the section
1344: you want to update, matching the name passed to C<changable_area>, and
1345: the new content you want to put in there, will put the content into
1346: that area.
1347:
1348: B<Note>: Netscape 4 only reserves enough space for the changable area
1349: to contain room for the original contents. You need to "make space"
1350: for whatever changes you wish to make, and be B<sure> to check your
1351: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1352: it's adequate for updating a one-line status display, but little more.
1353: This script will set the space to 100% width, so you only need to
1354: worry about height in Netscape 4.
1355:
1356: Modern browsers are much less limiting, and if you can commit to the
1357: user not using Netscape 4, this feature may be used freely with
1358: pretty much any HTML.
1359:
1360: =cut
1361:
1362: sub change_content_javascript {
1363: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1364: if ($env{'browser.type'} eq 'netscape' &&
1365: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1366: return (<<NETSCAPE4);
1367: function change(name, content) {
1368: doc = document.layers[name+"___escape"].layers[0].document;
1369: doc.open();
1370: doc.write(content);
1371: doc.close();
1372: }
1373: NETSCAPE4
1374: } else {
1375: # Otherwise, we need to use semi-standards-compliant code
1376: # (technically, "innerHTML" isn't standard but the equivalent
1377: # is really scary, and every useful browser supports it
1378: return (<<DOMBASED);
1379: function change(name, content) {
1380: element = document.getElementById(name);
1381: element.innerHTML = content;
1382: }
1383: DOMBASED
1384: }
1385: }
1386:
1387: =pod
1388:
1.648 raeburn 1389: =item * &changable_area($name,$origContent):
1.256 matthew 1390:
1391: This provides a "changable area" that can be modified on the fly via
1392: the Javascript code provided in C<change_content_javascript>. $name is
1393: the name you will use to reference the area later; do not repeat the
1394: same name on a given HTML page more then once. $origContent is what
1395: the area will originally contain, which can be left blank.
1396:
1397: =cut
1398:
1399: sub changable_area {
1400: my ($name, $origContent) = @_;
1401:
1.258 albertel 1402: if ($env{'browser.type'} eq 'netscape' &&
1403: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1404: # If this is netscape 4, we need to use the Layer tag
1405: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1406: } else {
1407: return "<span id='$name'>$origContent</span>";
1408: }
1409: }
1410:
1411: =pod
1412:
1.648 raeburn 1413: =item * &viewport_geometry_js
1.590 raeburn 1414:
1415: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1416:
1417: =cut
1418:
1419:
1420: sub viewport_geometry_js {
1421: return <<"GEOMETRY";
1422: var Geometry = {};
1423: function init_geometry() {
1424: if (Geometry.init) { return };
1425: Geometry.init=1;
1426: if (window.innerHeight) {
1427: Geometry.getViewportHeight = function() { return window.innerHeight; };
1428: Geometry.getViewportWidth = function() { return window.innerWidth; };
1429: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1430: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1431: }
1432: else if (document.documentElement && document.documentElement.clientHeight) {
1433: Geometry.getViewportHeight =
1434: function() { return document.documentElement.clientHeight; };
1435: Geometry.getViewportWidth =
1436: function() { return document.documentElement.clientWidth; };
1437:
1438: Geometry.getHorizontalScroll =
1439: function() { return document.documentElement.scrollLeft; };
1440: Geometry.getVerticalScroll =
1441: function() { return document.documentElement.scrollTop; };
1442: }
1443: else if (document.body.clientHeight) {
1444: Geometry.getViewportHeight =
1445: function() { return document.body.clientHeight; };
1446: Geometry.getViewportWidth =
1447: function() { return document.body.clientWidth; };
1448: Geometry.getHorizontalScroll =
1449: function() { return document.body.scrollLeft; };
1450: Geometry.getVerticalScroll =
1451: function() { return document.body.scrollTop; };
1452: }
1453: }
1454:
1455: GEOMETRY
1456: }
1457:
1458: =pod
1459:
1.648 raeburn 1460: =item * &viewport_size_js()
1.590 raeburn 1461:
1462: 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.
1463:
1464: =cut
1465:
1466: sub viewport_size_js {
1467: my $geometry = &viewport_geometry_js();
1468: return <<"DIMS";
1469:
1470: $geometry
1471:
1472: function getViewportDims(width,height) {
1473: init_geometry();
1474: width.value = Geometry.getViewportWidth();
1475: height.value = Geometry.getViewportHeight();
1476: return;
1477: }
1478:
1479: DIMS
1480: }
1481:
1482: =pod
1483:
1.648 raeburn 1484: =item * &resize_textarea_js()
1.565 albertel 1485:
1486: emits the needed javascript to resize a textarea to be as big as possible
1487:
1488: creates a function resize_textrea that takes two IDs first should be
1489: the id of the element to resize, second should be the id of a div that
1490: surrounds everything that comes after the textarea, this routine needs
1491: to be attached to the <body> for the onload and onresize events.
1492:
1.648 raeburn 1493: =back
1.565 albertel 1494:
1495: =cut
1496:
1497: sub resize_textarea_js {
1.590 raeburn 1498: my $geometry = &viewport_geometry_js();
1.565 albertel 1499: return <<"RESIZE";
1500: <script type="text/javascript">
1.824 bisitz 1501: // <![CDATA[
1.590 raeburn 1502: $geometry
1.565 albertel 1503:
1.588 albertel 1504: function getX(element) {
1505: var x = 0;
1506: while (element) {
1507: x += element.offsetLeft;
1508: element = element.offsetParent;
1509: }
1510: return x;
1511: }
1512: function getY(element) {
1513: var y = 0;
1514: while (element) {
1515: y += element.offsetTop;
1516: element = element.offsetParent;
1517: }
1518: return y;
1519: }
1520:
1521:
1.565 albertel 1522: function resize_textarea(textarea_id,bottom_id) {
1523: init_geometry();
1524: var textarea = document.getElementById(textarea_id);
1525: //alert(textarea);
1526:
1.588 albertel 1527: var textarea_top = getY(textarea);
1.565 albertel 1528: var textarea_height = textarea.offsetHeight;
1529: var bottom = document.getElementById(bottom_id);
1.588 albertel 1530: var bottom_top = getY(bottom);
1.565 albertel 1531: var bottom_height = bottom.offsetHeight;
1532: var window_height = Geometry.getViewportHeight();
1.588 albertel 1533: var fudge = 23;
1.565 albertel 1534: var new_height = window_height-fudge-textarea_top-bottom_height;
1535: if (new_height < 300) {
1536: new_height = 300;
1537: }
1538: textarea.style.height=new_height+'px';
1539: }
1.824 bisitz 1540: // ]]>
1.565 albertel 1541: </script>
1542: RESIZE
1543:
1544: }
1545:
1546: =pod
1547:
1.256 matthew 1548: =head1 Excel and CSV file utility routines
1549:
1550: =over 4
1551:
1552: =cut
1553:
1554: ###############################################################
1555: ###############################################################
1556:
1557: =pod
1558:
1.648 raeburn 1559: =item * &csv_translate($text)
1.37 matthew 1560:
1.185 www 1561: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1562: format.
1563:
1564: =cut
1565:
1.180 matthew 1566: ###############################################################
1567: ###############################################################
1.37 matthew 1568: sub csv_translate {
1569: my $text = shift;
1570: $text =~ s/\"/\"\"/g;
1.209 albertel 1571: $text =~ s/\n/ /g;
1.37 matthew 1572: return $text;
1573: }
1.180 matthew 1574:
1575: ###############################################################
1576: ###############################################################
1577:
1578: =pod
1579:
1.648 raeburn 1580: =item * &define_excel_formats()
1.180 matthew 1581:
1582: Define some commonly used Excel cell formats.
1583:
1584: Currently supported formats:
1585:
1586: =over 4
1587:
1588: =item header
1589:
1590: =item bold
1591:
1592: =item h1
1593:
1594: =item h2
1595:
1596: =item h3
1597:
1.256 matthew 1598: =item h4
1599:
1600: =item i
1601:
1.180 matthew 1602: =item date
1603:
1604: =back
1605:
1606: Inputs: $workbook
1607:
1608: Returns: $format, a hash reference.
1609:
1610: =cut
1611:
1612: ###############################################################
1613: ###############################################################
1614: sub define_excel_formats {
1615: my ($workbook) = @_;
1616: my $format;
1617: $format->{'header'} = $workbook->add_format(bold => 1,
1618: bottom => 1,
1619: align => 'center');
1620: $format->{'bold'} = $workbook->add_format(bold=>1);
1621: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1622: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1623: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1624: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1625: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1626: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1627: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1628: return $format;
1629: }
1630:
1631: ###############################################################
1632: ###############################################################
1.113 bowersj2 1633:
1634: =pod
1635:
1.648 raeburn 1636: =item * &create_workbook()
1.255 matthew 1637:
1638: Create an Excel worksheet. If it fails, output message on the
1639: request object and return undefs.
1640:
1641: Inputs: Apache request object
1642:
1643: Returns (undef) on failure,
1644: Excel worksheet object, scalar with filename, and formats
1645: from &Apache::loncommon::define_excel_formats on success
1646:
1647: =cut
1648:
1649: ###############################################################
1650: ###############################################################
1651: sub create_workbook {
1652: my ($r) = @_;
1653: #
1654: # Create the excel spreadsheet
1655: my $filename = '/prtspool/'.
1.258 albertel 1656: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1657: time.'_'.rand(1000000000).'.xls';
1658: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1659: if (! defined($workbook)) {
1660: $r->log_error("Error creating excel spreadsheet $filename: $!");
1661: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1662: "This error has been logged. ".
1663: "Please alert your LON-CAPA administrator").
1664: '</p>');
1665: return (undef);
1666: }
1667: #
1668: $workbook->set_tempdir('/home/httpd/perl/tmp');
1669: #
1670: my $format = &Apache::loncommon::define_excel_formats($workbook);
1671: return ($workbook,$filename,$format);
1672: }
1673:
1674: ###############################################################
1675: ###############################################################
1676:
1677: =pod
1678:
1.648 raeburn 1679: =item * &create_text_file()
1.113 bowersj2 1680:
1.542 raeburn 1681: Create a file to write to and eventually make available to the user.
1.256 matthew 1682: If file creation fails, outputs an error message on the request object and
1683: return undefs.
1.113 bowersj2 1684:
1.256 matthew 1685: Inputs: Apache request object, and file suffix
1.113 bowersj2 1686:
1.256 matthew 1687: Returns (undef) on failure,
1688: Filehandle and filename on success.
1.113 bowersj2 1689:
1690: =cut
1691:
1.256 matthew 1692: ###############################################################
1693: ###############################################################
1694: sub create_text_file {
1695: my ($r,$suffix) = @_;
1696: if (! defined($suffix)) { $suffix = 'txt'; };
1697: my $fh;
1698: my $filename = '/prtspool/'.
1.258 albertel 1699: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1700: time.'_'.rand(1000000000).'.'.$suffix;
1701: $fh = Apache::File->new('>/home/httpd'.$filename);
1702: if (! defined($fh)) {
1703: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1704: $r->print(&mt('Problems occurred in creating the output file. '
1705: .'This error has been logged. '
1706: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1707: }
1.256 matthew 1708: return ($fh,$filename)
1.113 bowersj2 1709: }
1710:
1711:
1.256 matthew 1712: =pod
1.113 bowersj2 1713:
1714: =back
1715:
1716: =cut
1.37 matthew 1717:
1718: ###############################################################
1.33 matthew 1719: ## Home server <option> list generating code ##
1720: ###############################################################
1.35 matthew 1721:
1.169 www 1722: # ------------------------------------------
1723:
1724: sub domain_select {
1725: my ($name,$value,$multiple)=@_;
1726: my %domains=map {
1.514 albertel 1727: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1728: } &Apache::lonnet::all_domains();
1.169 www 1729: if ($multiple) {
1730: $domains{''}=&mt('Any domain');
1.550 albertel 1731: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1732: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1733: } else {
1.550 albertel 1734: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1735: return &select_form($name,$value,%domains);
1736: }
1737: }
1738:
1.282 albertel 1739: #-------------------------------------------
1740:
1741: =pod
1742:
1.519 raeburn 1743: =head1 Routines for form select boxes
1744:
1745: =over 4
1746:
1.648 raeburn 1747: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1748:
1749: Returns a string containing a <select> element int multiple mode
1750:
1751:
1752: Args:
1753: $name - name of the <select> element
1.506 raeburn 1754: $value - scalar or array ref of values that should already be selected
1.282 albertel 1755: $size - number of rows long the select element is
1.283 albertel 1756: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1757: (shown text should already have been &mt())
1.506 raeburn 1758: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1759:
1.282 albertel 1760: =cut
1761:
1762: #-------------------------------------------
1.169 www 1763: sub multiple_select_form {
1.284 albertel 1764: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1765: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1766: my $output='';
1.191 matthew 1767: if (! defined($size)) {
1768: $size = 4;
1.283 albertel 1769: if (scalar(keys(%$hash))<4) {
1770: $size = scalar(keys(%$hash));
1.191 matthew 1771: }
1772: }
1.734 bisitz 1773: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1774: my @order;
1.506 raeburn 1775: if (ref($order) eq 'ARRAY') {
1776: @order = @{$order};
1777: } else {
1778: @order = sort(keys(%$hash));
1.501 banghart 1779: }
1780: if (exists($$hash{'select_form_order'})) {
1781: @order = @{$$hash{'select_form_order'}};
1782: }
1783:
1.284 albertel 1784: foreach my $key (@order) {
1.356 albertel 1785: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1786: $output.='selected="selected" ' if ($selected{$key});
1787: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1788: }
1789: $output.="</select>\n";
1790: return $output;
1791: }
1792:
1.88 www 1793: #-------------------------------------------
1794:
1795: =pod
1796:
1.648 raeburn 1797: =item * &select_form($defdom,$name,%hash)
1.88 www 1798:
1799: Returns a string containing a <select name='$name' size='1'> form to
1800: allow a user to select options from a hash option_name => displayed text.
1801: See lonrights.pm for an example invocation and use.
1802:
1803: =cut
1804:
1805: #-------------------------------------------
1806: sub select_form {
1807: my ($def,$name,%hash) = @_;
1808: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1809: my @keys;
1810: if (exists($hash{'select_form_order'})) {
1811: @keys=@{$hash{'select_form_order'}};
1812: } else {
1813: @keys=sort(keys(%hash));
1814: }
1.356 albertel 1815: foreach my $key (@keys) {
1816: $selectform.=
1817: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1818: ($key eq $def ? 'selected="selected" ' : '').
1819: ">".&mt($hash{$key})."</option>\n";
1.88 www 1820: }
1821: $selectform.="</select>";
1822: return $selectform;
1823: }
1824:
1.475 www 1825: # For display filters
1826:
1827: sub display_filter {
1828: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1829: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1830: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1831: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1832: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1833: '</label></span> <span class="LC_nobreak">'.
1.475 www 1834: &mt('Filter [_1]',
1.477 www 1835: &select_form($env{'form.displayfilter'},
1836: 'displayfilter',
1837: ('currentfolder' => 'Current folder/page',
1838: 'containing' => 'Containing phrase',
1839: 'none' => 'None'))).
1.714 bisitz 1840: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1841: }
1842:
1.167 www 1843: sub gradeleveldescription {
1844: my $gradelevel=shift;
1845: my %gradelevels=(0 => 'Not specified',
1846: 1 => 'Grade 1',
1847: 2 => 'Grade 2',
1848: 3 => 'Grade 3',
1849: 4 => 'Grade 4',
1850: 5 => 'Grade 5',
1851: 6 => 'Grade 6',
1852: 7 => 'Grade 7',
1853: 8 => 'Grade 8',
1854: 9 => 'Grade 9',
1855: 10 => 'Grade 10',
1856: 11 => 'Grade 11',
1857: 12 => 'Grade 12',
1858: 13 => 'Grade 13',
1859: 14 => '100 Level',
1860: 15 => '200 Level',
1861: 16 => '300 Level',
1862: 17 => '400 Level',
1863: 18 => 'Graduate Level');
1864: return &mt($gradelevels{$gradelevel});
1865: }
1866:
1.163 www 1867: sub select_level_form {
1868: my ($deflevel,$name)=@_;
1869: unless ($deflevel) { $deflevel=0; }
1.167 www 1870: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1871: for (my $i=0; $i<=18; $i++) {
1872: $selectform.="<option value=\"$i\" ".
1.253 albertel 1873: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1874: ">".&gradeleveldescription($i)."</option>\n";
1875: }
1876: $selectform.="</select>";
1877: return $selectform;
1.163 www 1878: }
1.167 www 1879:
1.35 matthew 1880: #-------------------------------------------
1881:
1.45 matthew 1882: =pod
1883:
1.873 raeburn 1884: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35 matthew 1885:
1886: Returns a string containing a <select name='$name' size='1'> form to
1887: allow a user to select the domain to preform an operation in.
1888: See loncreateuser.pm for an example invocation and use.
1889:
1.90 www 1890: If the $includeempty flag is set, it also includes an empty choice ("no domain
1891: selected");
1892:
1.743 raeburn 1893: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1894:
1.872 raeburn 1895: 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 1896:
1.35 matthew 1897: =cut
1898:
1899: #-------------------------------------------
1.34 matthew 1900: sub select_dom_form {
1.872 raeburn 1901: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
1902: if ($onchange) {
1.874 raeburn 1903: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1904: }
1.550 albertel 1905: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1906: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1907: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1908: foreach my $dom (@domains) {
1909: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1910: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1911: if ($showdomdesc) {
1912: if ($dom ne '') {
1913: my $domdesc = &Apache::lonnet::domain($dom,'description');
1914: if ($domdesc ne '') {
1915: $selectdomain .= ' ('.$domdesc.')';
1916: }
1917: }
1918: }
1919: $selectdomain .= "</option>\n";
1.34 matthew 1920: }
1921: $selectdomain.="</select>";
1922: return $selectdomain;
1923: }
1924:
1.35 matthew 1925: #-------------------------------------------
1926:
1.45 matthew 1927: =pod
1928:
1.648 raeburn 1929: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1930:
1.586 raeburn 1931: input: 4 arguments (two required, two optional) -
1932: $domain - domain of new user
1933: $name - name of form element
1934: $default - Value of 'default' causes a default item to be first
1935: option, and selected by default.
1936: $hide - Value of 'hide' causes hiding of the name of the server,
1937: if 1 server found, or default, if 0 found.
1.594 raeburn 1938: output: returns 2 items:
1.586 raeburn 1939: (a) form element which contains either:
1940: (i) <select name="$name">
1941: <option value="$hostid1">$hostid $servers{$hostid}</option>
1942: <option value="$hostid2">$hostid $servers{$hostid}</option>
1943: </select>
1944: form item if there are multiple library servers in $domain, or
1945: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1946: if there is only one library server in $domain.
1947:
1948: (b) number of library servers found.
1949:
1950: See loncreateuser.pm for example of use.
1.35 matthew 1951:
1952: =cut
1953:
1954: #-------------------------------------------
1.586 raeburn 1955: sub home_server_form_item {
1956: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1957: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1958: my $result;
1959: my $numlib = keys(%servers);
1960: if ($numlib > 1) {
1961: $result .= '<select name="'.$name.'" />'."\n";
1962: if ($default) {
1.804 bisitz 1963: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1964: '</option>'."\n";
1965: }
1966: foreach my $hostid (sort(keys(%servers))) {
1967: $result.= '<option value="'.$hostid.'">'.
1968: $hostid.' '.$servers{$hostid}."</option>\n";
1969: }
1970: $result .= '</select>'."\n";
1971: } elsif ($numlib == 1) {
1972: my $hostid;
1973: foreach my $item (keys(%servers)) {
1974: $hostid = $item;
1975: }
1976: $result .= '<input type="hidden" name="'.$name.'" value="'.
1977: $hostid.'" />';
1978: if (!$hide) {
1979: $result .= $hostid.' '.$servers{$hostid};
1980: }
1981: $result .= "\n";
1982: } elsif ($default) {
1983: $result .= '<input type="hidden" name="'.$name.
1984: '" value="default" />';
1985: if (!$hide) {
1986: $result .= &mt('default');
1987: }
1988: $result .= "\n";
1.33 matthew 1989: }
1.586 raeburn 1990: return ($result,$numlib);
1.33 matthew 1991: }
1.112 bowersj2 1992:
1993: =pod
1994:
1.534 albertel 1995: =back
1996:
1.112 bowersj2 1997: =cut
1.87 matthew 1998:
1999: ###############################################################
1.112 bowersj2 2000: ## Decoding User Agent ##
1.87 matthew 2001: ###############################################################
2002:
2003: =pod
2004:
1.112 bowersj2 2005: =head1 Decoding the User Agent
2006:
2007: =over 4
2008:
2009: =item * &decode_user_agent()
1.87 matthew 2010:
2011: Inputs: $r
2012:
2013: Outputs:
2014:
2015: =over 4
2016:
1.112 bowersj2 2017: =item * $httpbrowser
1.87 matthew 2018:
1.112 bowersj2 2019: =item * $clientbrowser
1.87 matthew 2020:
1.112 bowersj2 2021: =item * $clientversion
1.87 matthew 2022:
1.112 bowersj2 2023: =item * $clientmathml
1.87 matthew 2024:
1.112 bowersj2 2025: =item * $clientunicode
1.87 matthew 2026:
1.112 bowersj2 2027: =item * $clientos
1.87 matthew 2028:
2029: =back
2030:
1.157 matthew 2031: =back
2032:
1.87 matthew 2033: =cut
2034:
2035: ###############################################################
2036: ###############################################################
2037: sub decode_user_agent {
1.247 albertel 2038: my ($r)=@_;
1.87 matthew 2039: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2040: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2041: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2042: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2043: my $clientbrowser='unknown';
2044: my $clientversion='0';
2045: my $clientmathml='';
2046: my $clientunicode='0';
2047: for (my $i=0;$i<=$#browsertype;$i++) {
2048: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2049: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2050: $clientbrowser=$bname;
2051: $httpbrowser=~/$vreg/i;
2052: $clientversion=$1;
2053: $clientmathml=($clientversion>=$minv);
2054: $clientunicode=($clientversion>=$univ);
2055: }
2056: }
2057: my $clientos='unknown';
2058: if (($httpbrowser=~/linux/i) ||
2059: ($httpbrowser=~/unix/i) ||
2060: ($httpbrowser=~/ux/i) ||
2061: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2062: if (($httpbrowser=~/vax/i) ||
2063: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2064: if ($httpbrowser=~/next/i) { $clientos='next'; }
2065: if (($httpbrowser=~/mac/i) ||
2066: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2067: if ($httpbrowser=~/win/i) { $clientos='win'; }
2068: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2069: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2070: $clientunicode,$clientos,);
2071: }
2072:
1.32 matthew 2073: ###############################################################
2074: ## Authentication changing form generation subroutines ##
2075: ###############################################################
2076: ##
2077: ## All of the authform_xxxxxxx subroutines take their inputs in a
2078: ## hash, and have reasonable default values.
2079: ##
2080: ## formname = the name given in the <form> tag.
1.35 matthew 2081: #-------------------------------------------
2082:
1.45 matthew 2083: =pod
2084:
1.112 bowersj2 2085: =head1 Authentication Routines
2086:
2087: =over 4
2088:
1.648 raeburn 2089: =item * &authform_xxxxxx()
1.35 matthew 2090:
2091: The authform_xxxxxx subroutines provide javascript and html forms which
2092: handle some of the conveniences required for authentication forms.
2093: This is not an optimal method, but it works.
2094:
2095: =over 4
2096:
1.112 bowersj2 2097: =item * authform_header
1.35 matthew 2098:
1.112 bowersj2 2099: =item * authform_authorwarning
1.35 matthew 2100:
1.112 bowersj2 2101: =item * authform_nochange
1.35 matthew 2102:
1.112 bowersj2 2103: =item * authform_kerberos
1.35 matthew 2104:
1.112 bowersj2 2105: =item * authform_internal
1.35 matthew 2106:
1.112 bowersj2 2107: =item * authform_filesystem
1.35 matthew 2108:
2109: =back
2110:
1.648 raeburn 2111: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2112:
1.35 matthew 2113: =cut
2114:
2115: #-------------------------------------------
1.32 matthew 2116: sub authform_header{
2117: my %in = (
2118: formname => 'cu',
1.80 albertel 2119: kerb_def_dom => '',
1.32 matthew 2120: @_,
2121: );
2122: $in{'formname'} = 'document.' . $in{'formname'};
2123: my $result='';
1.80 albertel 2124:
2125: #---------------------------------------------- Code for upper case translation
2126: my $Javascript_toUpperCase;
2127: unless ($in{kerb_def_dom}) {
2128: $Javascript_toUpperCase =<<"END";
2129: switch (choice) {
2130: case 'krb': currentform.elements[choicearg].value =
2131: currentform.elements[choicearg].value.toUpperCase();
2132: break;
2133: default:
2134: }
2135: END
2136: } else {
2137: $Javascript_toUpperCase = "";
2138: }
2139:
1.165 raeburn 2140: my $radioval = "'nochange'";
1.591 raeburn 2141: if (defined($in{'curr_authtype'})) {
2142: if ($in{'curr_authtype'} ne '') {
2143: $radioval = "'".$in{'curr_authtype'}."arg'";
2144: }
1.174 matthew 2145: }
1.165 raeburn 2146: my $argfield = 'null';
1.591 raeburn 2147: if (defined($in{'mode'})) {
1.165 raeburn 2148: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2149: if (defined($in{'curr_autharg'})) {
2150: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2151: $argfield = "'$in{'curr_autharg'}'";
2152: }
2153: }
2154: }
2155: }
2156:
1.32 matthew 2157: $result.=<<"END";
2158: var current = new Object();
1.165 raeburn 2159: current.radiovalue = $radioval;
2160: current.argfield = $argfield;
1.32 matthew 2161:
2162: function changed_radio(choice,currentform) {
2163: var choicearg = choice + 'arg';
2164: // If a radio button in changed, we need to change the argfield
2165: if (current.radiovalue != choice) {
2166: current.radiovalue = choice;
2167: if (current.argfield != null) {
2168: currentform.elements[current.argfield].value = '';
2169: }
2170: if (choice == 'nochange') {
2171: current.argfield = null;
2172: } else {
2173: current.argfield = choicearg;
2174: switch(choice) {
2175: case 'krb':
2176: currentform.elements[current.argfield].value =
2177: "$in{'kerb_def_dom'}";
2178: break;
2179: default:
2180: break;
2181: }
2182: }
2183: }
2184: return;
2185: }
1.22 www 2186:
1.32 matthew 2187: function changed_text(choice,currentform) {
2188: var choicearg = choice + 'arg';
2189: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2190: $Javascript_toUpperCase
1.32 matthew 2191: // clear old field
2192: if ((current.argfield != choicearg) && (current.argfield != null)) {
2193: currentform.elements[current.argfield].value = '';
2194: }
2195: current.argfield = choicearg;
2196: }
2197: set_auth_radio_buttons(choice,currentform);
2198: return;
1.20 www 2199: }
1.32 matthew 2200:
2201: function set_auth_radio_buttons(newvalue,currentform) {
2202: var i=0;
2203: while (i < currentform.login.length) {
2204: if (currentform.login[i].value == newvalue) { break; }
2205: i++;
2206: }
2207: if (i == currentform.login.length) {
2208: return;
2209: }
2210: current.radiovalue = newvalue;
2211: currentform.login[i].checked = true;
2212: return;
2213: }
2214: END
2215: return $result;
2216: }
2217:
2218: sub authform_authorwarning{
2219: my $result='';
1.144 matthew 2220: $result='<i>'.
2221: &mt('As a general rule, only authors or co-authors should be '.
2222: 'filesystem authenticated '.
2223: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2224: return $result;
2225: }
2226:
2227: sub authform_nochange{
2228: my %in = (
2229: formname => 'document.cu',
2230: kerb_def_dom => 'MSU.EDU',
2231: @_,
2232: );
1.586 raeburn 2233: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2234: my $result;
2235: if (keys(%can_assign) == 0) {
2236: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2237: } else {
2238: $result = '<label>'.&mt('[_1] Do not change login data',
2239: '<input type="radio" name="login" value="nochange" '.
2240: 'checked="checked" onclick="'.
1.281 albertel 2241: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2242: '</label>';
1.586 raeburn 2243: }
1.32 matthew 2244: return $result;
2245: }
2246:
1.591 raeburn 2247: sub authform_kerberos {
1.32 matthew 2248: my %in = (
2249: formname => 'document.cu',
2250: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2251: kerb_def_auth => 'krb4',
1.32 matthew 2252: @_,
2253: );
1.586 raeburn 2254: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2255: $autharg,$jscall);
2256: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2257: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2258: $check5 = ' checked="checked"';
1.80 albertel 2259: } else {
1.772 bisitz 2260: $check4 = ' checked="checked"';
1.80 albertel 2261: }
1.165 raeburn 2262: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2263: if (defined($in{'curr_authtype'})) {
2264: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2265: $krbcheck = ' checked="checked"';
1.623 raeburn 2266: if (defined($in{'mode'})) {
2267: if ($in{'mode'} eq 'modifyuser') {
2268: $krbcheck = '';
2269: }
2270: }
1.591 raeburn 2271: if (defined($in{'curr_kerb_ver'})) {
2272: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2273: $check5 = ' checked="checked"';
1.591 raeburn 2274: $check4 = '';
2275: } else {
1.772 bisitz 2276: $check4 = ' checked="checked"';
1.591 raeburn 2277: $check5 = '';
2278: }
1.586 raeburn 2279: }
1.591 raeburn 2280: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2281: $krbarg = $in{'curr_autharg'};
2282: }
1.586 raeburn 2283: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2284: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2285: $result =
2286: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2287: $in{'curr_autharg'},$krbver);
2288: } else {
2289: $result =
2290: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2291: }
2292: return $result;
2293: }
2294: }
2295: } else {
2296: if ($authnum == 1) {
1.784 bisitz 2297: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2298: }
2299: }
1.586 raeburn 2300: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2301: return;
1.587 raeburn 2302: } elsif ($authtype eq '') {
1.591 raeburn 2303: if (defined($in{'mode'})) {
1.587 raeburn 2304: if ($in{'mode'} eq 'modifycourse') {
2305: if ($authnum == 1) {
1.784 bisitz 2306: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2307: }
2308: }
2309: }
1.586 raeburn 2310: }
2311: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2312: if ($authtype eq '') {
2313: $authtype = '<input type="radio" name="login" value="krb" '.
2314: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2315: $krbcheck.' />';
2316: }
2317: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2318: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2319: $in{'curr_authtype'} eq 'krb5') ||
2320: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2321: $in{'curr_authtype'} eq 'krb4')) {
2322: $result .= &mt
1.144 matthew 2323: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2324: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2325: '<label>'.$authtype,
1.281 albertel 2326: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2327: 'value="'.$krbarg.'" '.
1.144 matthew 2328: 'onchange="'.$jscall.'" />',
1.281 albertel 2329: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2330: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2331: '</label>');
1.586 raeburn 2332: } elsif ($can_assign{'krb4'}) {
2333: $result .= &mt
2334: ('[_1] Kerberos authenticated with domain [_2] '.
2335: '[_3] Version 4 [_4]',
2336: '<label>'.$authtype,
2337: '</label><input type="text" size="10" name="krbarg" '.
2338: 'value="'.$krbarg.'" '.
2339: 'onchange="'.$jscall.'" />',
2340: '<label><input type="hidden" name="krbver" value="4" />',
2341: '</label>');
2342: } elsif ($can_assign{'krb5'}) {
2343: $result .= &mt
2344: ('[_1] Kerberos authenticated with domain [_2] '.
2345: '[_3] Version 5 [_4]',
2346: '<label>'.$authtype,
2347: '</label><input type="text" size="10" name="krbarg" '.
2348: 'value="'.$krbarg.'" '.
2349: 'onchange="'.$jscall.'" />',
2350: '<label><input type="hidden" name="krbver" value="5" />',
2351: '</label>');
2352: }
1.32 matthew 2353: return $result;
2354: }
2355:
2356: sub authform_internal{
1.586 raeburn 2357: my %in = (
1.32 matthew 2358: formname => 'document.cu',
2359: kerb_def_dom => 'MSU.EDU',
2360: @_,
2361: );
1.586 raeburn 2362: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2363: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2364: if (defined($in{'curr_authtype'})) {
2365: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2366: if ($can_assign{'int'}) {
1.772 bisitz 2367: $intcheck = 'checked="checked" ';
1.623 raeburn 2368: if (defined($in{'mode'})) {
2369: if ($in{'mode'} eq 'modifyuser') {
2370: $intcheck = '';
2371: }
2372: }
1.591 raeburn 2373: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2374: $intarg = $in{'curr_autharg'};
2375: }
2376: } else {
2377: $result = &mt('Currently internally authenticated.');
2378: return $result;
1.165 raeburn 2379: }
2380: }
1.586 raeburn 2381: } else {
2382: if ($authnum == 1) {
1.784 bisitz 2383: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2384: }
2385: }
2386: if (!$can_assign{'int'}) {
2387: return;
1.587 raeburn 2388: } elsif ($authtype eq '') {
1.591 raeburn 2389: if (defined($in{'mode'})) {
1.587 raeburn 2390: if ($in{'mode'} eq 'modifycourse') {
2391: if ($authnum == 1) {
1.784 bisitz 2392: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2393: }
2394: }
2395: }
1.165 raeburn 2396: }
1.586 raeburn 2397: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2398: if ($authtype eq '') {
2399: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2400: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2401: }
1.605 bisitz 2402: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2403: $intarg.'" onchange="'.$jscall.'" />';
2404: $result = &mt
1.144 matthew 2405: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2406: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2407: $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 2408: return $result;
2409: }
2410:
2411: sub authform_local{
2412: my %in = (
2413: formname => 'document.cu',
2414: kerb_def_dom => 'MSU.EDU',
2415: @_,
2416: );
1.586 raeburn 2417: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2418: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2419: if (defined($in{'curr_authtype'})) {
2420: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2421: if ($can_assign{'loc'}) {
1.772 bisitz 2422: $loccheck = 'checked="checked" ';
1.623 raeburn 2423: if (defined($in{'mode'})) {
2424: if ($in{'mode'} eq 'modifyuser') {
2425: $loccheck = '';
2426: }
2427: }
1.591 raeburn 2428: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2429: $locarg = $in{'curr_autharg'};
2430: }
2431: } else {
2432: $result = &mt('Currently using local (institutional) authentication.');
2433: return $result;
1.165 raeburn 2434: }
2435: }
1.586 raeburn 2436: } else {
2437: if ($authnum == 1) {
1.784 bisitz 2438: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2439: }
2440: }
2441: if (!$can_assign{'loc'}) {
2442: return;
1.587 raeburn 2443: } elsif ($authtype eq '') {
1.591 raeburn 2444: if (defined($in{'mode'})) {
1.587 raeburn 2445: if ($in{'mode'} eq 'modifycourse') {
2446: if ($authnum == 1) {
1.784 bisitz 2447: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2448: }
2449: }
2450: }
1.165 raeburn 2451: }
1.586 raeburn 2452: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2453: if ($authtype eq '') {
2454: $authtype = '<input type="radio" name="login" value="loc" '.
2455: $loccheck.' onchange="'.$jscall.'" onclick="'.
2456: $jscall.'" />';
2457: }
2458: $autharg = '<input type="text" size="10" name="locarg" value="'.
2459: $locarg.'" onchange="'.$jscall.'" />';
2460: $result = &mt('[_1] Local Authentication with argument [_2]',
2461: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2462: return $result;
2463: }
2464:
2465: sub authform_filesystem{
2466: my %in = (
2467: formname => 'document.cu',
2468: kerb_def_dom => 'MSU.EDU',
2469: @_,
2470: );
1.586 raeburn 2471: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2472: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2473: if (defined($in{'curr_authtype'})) {
2474: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2475: if ($can_assign{'fsys'}) {
1.772 bisitz 2476: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2477: if (defined($in{'mode'})) {
2478: if ($in{'mode'} eq 'modifyuser') {
2479: $fsyscheck = '';
2480: }
2481: }
1.586 raeburn 2482: } else {
2483: $result = &mt('Currently Filesystem Authenticated.');
2484: return $result;
2485: }
2486: }
2487: } else {
2488: if ($authnum == 1) {
1.784 bisitz 2489: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2490: }
2491: }
2492: if (!$can_assign{'fsys'}) {
2493: return;
1.587 raeburn 2494: } elsif ($authtype eq '') {
1.591 raeburn 2495: if (defined($in{'mode'})) {
1.587 raeburn 2496: if ($in{'mode'} eq 'modifycourse') {
2497: if ($authnum == 1) {
1.784 bisitz 2498: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2499: }
2500: }
2501: }
1.586 raeburn 2502: }
2503: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2504: if ($authtype eq '') {
2505: $authtype = '<input type="radio" name="login" value="fsys" '.
2506: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2507: $jscall.'" />';
2508: }
2509: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2510: ' onchange="'.$jscall.'" />';
2511: $result = &mt
1.144 matthew 2512: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2513: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2514: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2515: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2516: 'onchange="'.$jscall.'" />');
1.32 matthew 2517: return $result;
2518: }
2519:
1.586 raeburn 2520: sub get_assignable_auth {
2521: my ($dom) = @_;
2522: if ($dom eq '') {
2523: $dom = $env{'request.role.domain'};
2524: }
2525: my %can_assign = (
2526: krb4 => 1,
2527: krb5 => 1,
2528: int => 1,
2529: loc => 1,
2530: );
2531: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2532: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2533: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2534: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2535: my $context;
2536: if ($env{'request.role'} =~ /^au/) {
2537: $context = 'author';
2538: } elsif ($env{'request.role'} =~ /^dc/) {
2539: $context = 'domain';
2540: } elsif ($env{'request.course.id'}) {
2541: $context = 'course';
2542: }
2543: if ($context) {
2544: if (ref($authhash->{$context}) eq 'HASH') {
2545: %can_assign = %{$authhash->{$context}};
2546: }
2547: }
2548: }
2549: }
2550: my $authnum = 0;
2551: foreach my $key (keys(%can_assign)) {
2552: if ($can_assign{$key}) {
2553: $authnum ++;
2554: }
2555: }
2556: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2557: $authnum --;
2558: }
2559: return ($authnum,%can_assign);
2560: }
2561:
1.80 albertel 2562: ###############################################################
2563: ## Get Kerberos Defaults for Domain ##
2564: ###############################################################
2565: ##
2566: ## Returns default kerberos version and an associated argument
2567: ## as listed in file domain.tab. If not listed, provides
2568: ## appropriate default domain and kerberos version.
2569: ##
2570: #-------------------------------------------
2571:
2572: =pod
2573:
1.648 raeburn 2574: =item * &get_kerberos_defaults()
1.80 albertel 2575:
2576: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2577: version and domain. If not found, it defaults to version 4 and the
2578: domain of the server.
1.80 albertel 2579:
1.648 raeburn 2580: =over 4
2581:
1.80 albertel 2582: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2583:
1.648 raeburn 2584: =back
2585:
2586: =back
2587:
1.80 albertel 2588: =cut
2589:
2590: #-------------------------------------------
2591: sub get_kerberos_defaults {
2592: my $domain=shift;
1.641 raeburn 2593: my ($krbdef,$krbdefdom);
2594: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2595: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2596: $krbdef = $domdefaults{'auth_def'};
2597: $krbdefdom = $domdefaults{'auth_arg_def'};
2598: } else {
1.80 albertel 2599: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2600: my $krbdefdom=$1;
2601: $krbdefdom=~tr/a-z/A-Z/;
2602: $krbdef = "krb4";
2603: }
2604: return ($krbdef,$krbdefdom);
2605: }
1.112 bowersj2 2606:
1.32 matthew 2607:
1.46 matthew 2608: ###############################################################
2609: ## Thesaurus Functions ##
2610: ###############################################################
1.20 www 2611:
1.46 matthew 2612: =pod
1.20 www 2613:
1.112 bowersj2 2614: =head1 Thesaurus Functions
2615:
2616: =over 4
2617:
1.648 raeburn 2618: =item * &initialize_keywords()
1.46 matthew 2619:
2620: Initializes the package variable %Keywords if it is empty. Uses the
2621: package variable $thesaurus_db_file.
2622:
2623: =cut
2624:
2625: ###################################################
2626:
2627: sub initialize_keywords {
2628: return 1 if (scalar keys(%Keywords));
2629: # If we are here, %Keywords is empty, so fill it up
2630: # Make sure the file we need exists...
2631: if (! -e $thesaurus_db_file) {
2632: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2633: " failed because it does not exist");
2634: return 0;
2635: }
2636: # Set up the hash as a database
2637: my %thesaurus_db;
2638: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2639: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2640: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2641: $thesaurus_db_file);
2642: return 0;
2643: }
2644: # Get the average number of appearances of a word.
2645: my $avecount = $thesaurus_db{'average.count'};
2646: # Put keywords (those that appear > average) into %Keywords
2647: while (my ($word,$data)=each (%thesaurus_db)) {
2648: my ($count,undef) = split /:/,$data;
2649: $Keywords{$word}++ if ($count > $avecount);
2650: }
2651: untie %thesaurus_db;
2652: # Remove special values from %Keywords.
1.356 albertel 2653: foreach my $value ('total.count','average.count') {
2654: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2655: }
1.46 matthew 2656: return 1;
2657: }
2658:
2659: ###################################################
2660:
2661: =pod
2662:
1.648 raeburn 2663: =item * &keyword($word)
1.46 matthew 2664:
2665: Returns true if $word is a keyword. A keyword is a word that appears more
2666: than the average number of times in the thesaurus database. Calls
2667: &initialize_keywords
2668:
2669: =cut
2670:
2671: ###################################################
1.20 www 2672:
2673: sub keyword {
1.46 matthew 2674: return if (!&initialize_keywords());
2675: my $word=lc(shift());
2676: $word=~s/\W//g;
2677: return exists($Keywords{$word});
1.20 www 2678: }
1.46 matthew 2679:
2680: ###############################################################
2681:
2682: =pod
1.20 www 2683:
1.648 raeburn 2684: =item * &get_related_words()
1.46 matthew 2685:
1.160 matthew 2686: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2687: an array of words. If the keyword is not in the thesaurus, an empty array
2688: will be returned. The order of the words returned is determined by the
2689: database which holds them.
2690:
2691: Uses global $thesaurus_db_file.
2692:
2693: =cut
2694:
2695: ###############################################################
2696: sub get_related_words {
2697: my $keyword = shift;
2698: my %thesaurus_db;
2699: if (! -e $thesaurus_db_file) {
2700: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2701: "failed because the file does not exist");
2702: return ();
2703: }
2704: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2705: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2706: return ();
2707: }
2708: my @Words=();
1.429 www 2709: my $count=0;
1.46 matthew 2710: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2711: # The first element is the number of times
2712: # the word appears. We do not need it now.
1.429 www 2713: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2714: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2715: my $threshold=$mostfrequentcount/10;
2716: foreach my $possibleword (@RelatedWords) {
2717: my ($word,$wordcount)=split(/\,/,$possibleword);
2718: if ($wordcount>$threshold) {
2719: push(@Words,$word);
2720: $count++;
2721: if ($count>10) { last; }
2722: }
1.20 www 2723: }
2724: }
1.46 matthew 2725: untie %thesaurus_db;
2726: return @Words;
1.14 harris41 2727: }
1.46 matthew 2728:
1.112 bowersj2 2729: =pod
2730:
2731: =back
2732:
2733: =cut
1.61 www 2734:
2735: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2736: =pod
2737:
1.112 bowersj2 2738: =head1 User Name Functions
2739:
2740: =over 4
2741:
1.648 raeburn 2742: =item * &plainname($uname,$udom,$first)
1.81 albertel 2743:
1.112 bowersj2 2744: Takes a users logon name and returns it as a string in
1.226 albertel 2745: "first middle last generation" form
2746: if $first is set to 'lastname' then it returns it as
2747: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2748:
2749: =cut
1.61 www 2750:
1.295 www 2751:
1.81 albertel 2752: ###############################################################
1.61 www 2753: sub plainname {
1.226 albertel 2754: my ($uname,$udom,$first)=@_;
1.537 albertel 2755: return if (!defined($uname) || !defined($udom));
1.295 www 2756: my %names=&getnames($uname,$udom);
1.226 albertel 2757: my $name=&Apache::lonnet::format_name($names{'firstname'},
2758: $names{'middlename'},
2759: $names{'lastname'},
2760: $names{'generation'},$first);
2761: $name=~s/^\s+//;
1.62 www 2762: $name=~s/\s+$//;
2763: $name=~s/\s+/ /g;
1.353 albertel 2764: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2765: return $name;
1.61 www 2766: }
1.66 www 2767:
2768: # -------------------------------------------------------------------- Nickname
1.81 albertel 2769: =pod
2770:
1.648 raeburn 2771: =item * &nickname($uname,$udom)
1.81 albertel 2772:
2773: Gets a users name and returns it as a string as
2774:
2775: ""nickname""
1.66 www 2776:
1.81 albertel 2777: if the user has a nickname or
2778:
2779: "first middle last generation"
2780:
2781: if the user does not
2782:
2783: =cut
1.66 www 2784:
2785: sub nickname {
2786: my ($uname,$udom)=@_;
1.537 albertel 2787: return if (!defined($uname) || !defined($udom));
1.295 www 2788: my %names=&getnames($uname,$udom);
1.68 albertel 2789: my $name=$names{'nickname'};
1.66 www 2790: if ($name) {
2791: $name='"'.$name.'"';
2792: } else {
2793: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2794: $names{'lastname'}.' '.$names{'generation'};
2795: $name=~s/\s+$//;
2796: $name=~s/\s+/ /g;
2797: }
2798: return $name;
2799: }
2800:
1.295 www 2801: sub getnames {
2802: my ($uname,$udom)=@_;
1.537 albertel 2803: return if (!defined($uname) || !defined($udom));
1.433 albertel 2804: if ($udom eq 'public' && $uname eq 'public') {
2805: return ('lastname' => &mt('Public'));
2806: }
1.295 www 2807: my $id=$uname.':'.$udom;
2808: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2809: if ($cached) {
2810: return %{$names};
2811: } else {
2812: my %loadnames=&Apache::lonnet::get('environment',
2813: ['firstname','middlename','lastname','generation','nickname'],
2814: $udom,$uname);
2815: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2816: return %loadnames;
2817: }
2818: }
1.61 www 2819:
1.542 raeburn 2820: # -------------------------------------------------------------------- getemails
1.648 raeburn 2821:
1.542 raeburn 2822: =pod
2823:
1.648 raeburn 2824: =item * &getemails($uname,$udom)
1.542 raeburn 2825:
2826: Gets a user's email information and returns it as a hash with keys:
2827: notification, critnotification, permanentemail
2828:
2829: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2830: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2831:
1.648 raeburn 2832:
1.542 raeburn 2833: =cut
2834:
1.648 raeburn 2835:
1.466 albertel 2836: sub getemails {
2837: my ($uname,$udom)=@_;
2838: if ($udom eq 'public' && $uname eq 'public') {
2839: return;
2840: }
1.467 www 2841: if (!$udom) { $udom=$env{'user.domain'}; }
2842: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2843: my $id=$uname.':'.$udom;
2844: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2845: if ($cached) {
2846: return %{$names};
2847: } else {
2848: my %loadnames=&Apache::lonnet::get('environment',
2849: ['notification','critnotification',
2850: 'permanentemail'],
2851: $udom,$uname);
2852: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2853: return %loadnames;
2854: }
2855: }
2856:
1.551 albertel 2857: sub flush_email_cache {
2858: my ($uname,$udom)=@_;
2859: if (!$udom) { $udom =$env{'user.domain'}; }
2860: if (!$uname) { $uname=$env{'user.name'}; }
2861: return if ($udom eq 'public' && $uname eq 'public');
2862: my $id=$uname.':'.$udom;
2863: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2864: }
2865:
1.728 raeburn 2866: # -------------------------------------------------------------------- getlangs
2867:
2868: =pod
2869:
2870: =item * &getlangs($uname,$udom)
2871:
2872: Gets a user's language preference and returns it as a hash with key:
2873: language.
2874:
2875: =cut
2876:
2877:
2878: sub getlangs {
2879: my ($uname,$udom) = @_;
2880: if (!$udom) { $udom =$env{'user.domain'}; }
2881: if (!$uname) { $uname=$env{'user.name'}; }
2882: my $id=$uname.':'.$udom;
2883: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2884: if ($cached) {
2885: return %{$langs};
2886: } else {
2887: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2888: $udom,$uname);
2889: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2890: return %loadlangs;
2891: }
2892: }
2893:
2894: sub flush_langs_cache {
2895: my ($uname,$udom)=@_;
2896: if (!$udom) { $udom =$env{'user.domain'}; }
2897: if (!$uname) { $uname=$env{'user.name'}; }
2898: return if ($udom eq 'public' && $uname eq 'public');
2899: my $id=$uname.':'.$udom;
2900: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2901: }
2902:
1.61 www 2903: # ------------------------------------------------------------------ Screenname
1.81 albertel 2904:
2905: =pod
2906:
1.648 raeburn 2907: =item * &screenname($uname,$udom)
1.81 albertel 2908:
2909: Gets a users screenname and returns it as a string
2910:
2911: =cut
1.61 www 2912:
2913: sub screenname {
2914: my ($uname,$udom)=@_;
1.258 albertel 2915: if ($uname eq $env{'user.name'} &&
2916: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2917: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2918: return $names{'screenname'};
1.62 www 2919: }
2920:
1.212 albertel 2921:
1.802 bisitz 2922: # ------------------------------------------------------------- Confirm Wrapper
2923: =pod
2924:
2925: =item confirmwrapper
2926:
2927: Wrap messages about completion of operation in box
2928:
2929: =cut
2930:
2931: sub confirmwrapper {
2932: my ($message)=@_;
2933: if ($message) {
2934: return "\n".'<div class="LC_confirm_box">'."\n"
2935: .$message."\n"
2936: .'</div>'."\n";
2937: } else {
2938: return $message;
2939: }
2940: }
2941:
1.62 www 2942: # ------------------------------------------------------------- Message Wrapper
2943:
2944: sub messagewrapper {
1.369 www 2945: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2946: return
1.441 albertel 2947: '<a href="/adm/email?compose=individual&'.
2948: 'recname='.$username.'&recdom='.$domain.
2949: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2950: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2951: }
1.802 bisitz 2952:
1.74 www 2953: # --------------------------------------------------------------- Notes Wrapper
2954:
2955: sub noteswrapper {
2956: my ($link,$un,$do)=@_;
2957: return
1.896 amueller 2958: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2959: }
1.802 bisitz 2960:
1.62 www 2961: # ------------------------------------------------------------- Aboutme Wrapper
2962:
2963: sub aboutmewrapper {
1.166 www 2964: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2965: if (!defined($username) && !defined($domain)) {
2966: return;
2967: }
1.892 amueller 2968: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 2969: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2970: }
2971:
2972: # ------------------------------------------------------------ Syllabus Wrapper
2973:
2974: sub syllabuswrapper {
1.707 bisitz 2975: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2976: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2977: }
1.14 harris41 2978:
1.802 bisitz 2979: # -----------------------------------------------------------------------------
2980:
1.208 matthew 2981: sub track_student_link {
1.887 raeburn 2982: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 2983: my $link ="/adm/trackstudent?";
1.208 matthew 2984: my $title = 'View recent activity';
2985: if (defined($sname) && $sname !~ /^\s*$/ &&
2986: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2987: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2988: $title .= ' of this student';
1.268 albertel 2989: }
1.208 matthew 2990: if (defined($target) && $target !~ /^\s*$/) {
2991: $target = qq{target="$target"};
2992: } else {
2993: $target = '';
2994: }
1.268 albertel 2995: if ($start) { $link.='&start='.$start; }
1.887 raeburn 2996: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 2997: $title = &mt($title);
2998: $linktext = &mt($linktext);
1.448 albertel 2999: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3000: &help_open_topic('View_recent_activity');
1.208 matthew 3001: }
3002:
1.781 raeburn 3003: sub slot_reservations_link {
3004: my ($linktext,$sname,$sdom,$target) = @_;
3005: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3006: my $title = 'View slot reservation history';
3007: if (defined($sname) && $sname !~ /^\s*$/ &&
3008: defined($sdom) && $sdom !~ /^\s*$/) {
3009: $link .= "&uname=$sname&udom=$sdom";
3010: $title .= ' of this student';
3011: }
3012: if (defined($target) && $target !~ /^\s*$/) {
3013: $target = qq{target="$target"};
3014: } else {
3015: $target = '';
3016: }
3017: $title = &mt($title);
3018: $linktext = &mt($linktext);
3019: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3020: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3021:
3022: }
3023:
1.508 www 3024: # ===================================================== Display a student photo
3025:
3026:
1.509 albertel 3027: sub student_image_tag {
1.508 www 3028: my ($domain,$user)=@_;
3029: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3030: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3031: return '<img src="'.$imgsrc.'" align="right" />';
3032: } else {
3033: return '';
3034: }
3035: }
3036:
1.112 bowersj2 3037: =pod
3038:
3039: =back
3040:
3041: =head1 Access .tab File Data
3042:
3043: =over 4
3044:
1.648 raeburn 3045: =item * &languageids()
1.112 bowersj2 3046:
3047: returns list of all language ids
3048:
3049: =cut
3050:
1.14 harris41 3051: sub languageids {
1.16 harris41 3052: return sort(keys(%language));
1.14 harris41 3053: }
3054:
1.112 bowersj2 3055: =pod
3056:
1.648 raeburn 3057: =item * &languagedescription()
1.112 bowersj2 3058:
3059: returns description of a specified language id
3060:
3061: =cut
3062:
1.14 harris41 3063: sub languagedescription {
1.125 www 3064: my $code=shift;
3065: return ($supported_language{$code}?'* ':'').
3066: $language{$code}.
1.126 www 3067: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3068: }
3069:
3070: sub plainlanguagedescription {
3071: my $code=shift;
3072: return $language{$code};
3073: }
3074:
3075: sub supportedlanguagecode {
3076: my $code=shift;
3077: return $supported_language{$code};
1.97 www 3078: }
3079:
1.112 bowersj2 3080: =pod
3081:
1.648 raeburn 3082: =item * ©rightids()
1.112 bowersj2 3083:
3084: returns list of all copyrights
3085:
3086: =cut
3087:
3088: sub copyrightids {
3089: return sort(keys(%cprtag));
3090: }
3091:
3092: =pod
3093:
1.648 raeburn 3094: =item * ©rightdescription()
1.112 bowersj2 3095:
3096: returns description of a specified copyright id
3097:
3098: =cut
3099:
3100: sub copyrightdescription {
1.166 www 3101: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3102: }
1.197 matthew 3103:
3104: =pod
3105:
1.648 raeburn 3106: =item * &source_copyrightids()
1.192 taceyjo1 3107:
3108: returns list of all source copyrights
3109:
3110: =cut
3111:
3112: sub source_copyrightids {
3113: return sort(keys(%scprtag));
3114: }
3115:
3116: =pod
3117:
1.648 raeburn 3118: =item * &source_copyrightdescription()
1.192 taceyjo1 3119:
3120: returns description of a specified source copyright id
3121:
3122: =cut
3123:
3124: sub source_copyrightdescription {
3125: return &mt($scprtag{shift(@_)});
3126: }
1.112 bowersj2 3127:
3128: =pod
3129:
1.648 raeburn 3130: =item * &filecategories()
1.112 bowersj2 3131:
3132: returns list of all file categories
3133:
3134: =cut
3135:
3136: sub filecategories {
3137: return sort(keys(%category_extensions));
3138: }
3139:
3140: =pod
3141:
1.648 raeburn 3142: =item * &filecategorytypes()
1.112 bowersj2 3143:
3144: returns list of file types belonging to a given file
3145: category
3146:
3147: =cut
3148:
3149: sub filecategorytypes {
1.356 albertel 3150: my ($cat) = @_;
3151: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3152: }
3153:
3154: =pod
3155:
1.648 raeburn 3156: =item * &fileembstyle()
1.112 bowersj2 3157:
3158: returns embedding style for a specified file type
3159:
3160: =cut
3161:
3162: sub fileembstyle {
3163: return $fe{lc(shift(@_))};
1.169 www 3164: }
3165:
1.351 www 3166: sub filemimetype {
3167: return $fm{lc(shift(@_))};
3168: }
3169:
1.169 www 3170:
3171: sub filecategoryselect {
3172: my ($name,$value)=@_;
1.189 matthew 3173: return &select_form($value,$name,
1.169 www 3174: '' => &mt('Any category'),
3175: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3176: }
3177:
3178: =pod
3179:
1.648 raeburn 3180: =item * &filedescription()
1.112 bowersj2 3181:
3182: returns description for a specified file type
3183:
3184: =cut
3185:
3186: sub filedescription {
1.188 matthew 3187: my $file_description = $fd{lc(shift())};
3188: $file_description =~ s:([\[\]]):~$1:g;
3189: return &mt($file_description);
1.112 bowersj2 3190: }
3191:
3192: =pod
3193:
1.648 raeburn 3194: =item * &filedescriptionex()
1.112 bowersj2 3195:
3196: returns description for a specified file type with
3197: extra formatting
3198:
3199: =cut
3200:
3201: sub filedescriptionex {
3202: my $ex=shift;
1.188 matthew 3203: my $file_description = $fd{lc($ex)};
3204: $file_description =~ s:([\[\]]):~$1:g;
3205: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3206: }
3207:
3208: # End of .tab access
3209: =pod
3210:
3211: =back
3212:
3213: =cut
3214:
3215: # ------------------------------------------------------------------ File Types
3216: sub fileextensions {
3217: return sort(keys(%fe));
3218: }
3219:
1.97 www 3220: # ----------------------------------------------------------- Display Languages
3221: # returns a hash with all desired display languages
3222: #
3223:
3224: sub display_languages {
3225: my %languages=();
1.695 raeburn 3226: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3227: $languages{$lang}=1;
1.97 www 3228: }
3229: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3230: if ($env{'form.displaylanguage'}) {
1.356 albertel 3231: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3232: $languages{$lang}=1;
1.97 www 3233: }
3234: }
3235: return %languages;
1.14 harris41 3236: }
3237:
1.582 albertel 3238: sub languages {
3239: my ($possible_langs) = @_;
1.695 raeburn 3240: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3241: if (!ref($possible_langs)) {
3242: if( wantarray ) {
3243: return @preferred_langs;
3244: } else {
3245: return $preferred_langs[0];
3246: }
3247: }
3248: my %possibilities = map { $_ => 1 } (@$possible_langs);
3249: my @preferred_possibilities;
3250: foreach my $preferred_lang (@preferred_langs) {
3251: if (exists($possibilities{$preferred_lang})) {
3252: push(@preferred_possibilities, $preferred_lang);
3253: }
3254: }
3255: if( wantarray ) {
3256: return @preferred_possibilities;
3257: }
3258: return $preferred_possibilities[0];
3259: }
3260:
1.742 raeburn 3261: sub user_lang {
3262: my ($touname,$toudom,$fromcid) = @_;
3263: my @userlangs;
3264: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3265: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3266: $env{'course.'.$fromcid.'.languages'}));
3267: } else {
3268: my %langhash = &getlangs($touname,$toudom);
3269: if ($langhash{'languages'} ne '') {
3270: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3271: } else {
3272: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3273: if ($domdefs{'lang_def'} ne '') {
3274: @userlangs = ($domdefs{'lang_def'});
3275: }
3276: }
3277: }
3278: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3279: my $user_lh = Apache::localize->get_handle(@languages);
3280: return $user_lh;
3281: }
3282:
3283:
1.112 bowersj2 3284: ###############################################################
3285: ## Student Answer Attempts ##
3286: ###############################################################
3287:
3288: =pod
3289:
3290: =head1 Alternate Problem Views
3291:
3292: =over 4
3293:
1.648 raeburn 3294: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3295: $getattempt, $regexp, $gradesub)
3296:
3297: Return string with previous attempt on problem. Arguments:
3298:
3299: =over 4
3300:
3301: =item * $symb: Problem, including path
3302:
3303: =item * $username: username of the desired student
3304:
3305: =item * $domain: domain of the desired student
1.14 harris41 3306:
1.112 bowersj2 3307: =item * $course: Course ID
1.14 harris41 3308:
1.112 bowersj2 3309: =item * $getattempt: Leave blank for all attempts, otherwise put
3310: something
1.14 harris41 3311:
1.112 bowersj2 3312: =item * $regexp: if string matches this regexp, the string will be
3313: sent to $gradesub
1.14 harris41 3314:
1.112 bowersj2 3315: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3316:
1.112 bowersj2 3317: =back
1.14 harris41 3318:
1.112 bowersj2 3319: The output string is a table containing all desired attempts, if any.
1.16 harris41 3320:
1.112 bowersj2 3321: =cut
1.1 albertel 3322:
3323: sub get_previous_attempt {
1.43 ng 3324: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3325: my $prevattempts='';
1.43 ng 3326: no strict 'refs';
1.1 albertel 3327: if ($symb) {
1.3 albertel 3328: my (%returnhash)=
3329: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3330: if ($returnhash{'version'}) {
3331: my %lasthash=();
3332: my $version;
3333: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3334: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3335: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3336: }
1.1 albertel 3337: }
1.596 albertel 3338: $prevattempts=&start_data_table().&start_data_table_header_row();
3339: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3340: foreach my $key (sort(keys(%lasthash))) {
3341: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3342: if ($#parts > 0) {
1.31 albertel 3343: my $data=$parts[-1];
3344: pop(@parts);
1.596 albertel 3345: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3346: } else {
1.41 ng 3347: if ($#parts == 0) {
3348: $prevattempts.='<th>'.$parts[0].'</th>';
3349: } else {
3350: $prevattempts.='<th>'.$ign.'</th>';
3351: }
1.31 albertel 3352: }
1.16 harris41 3353: }
1.596 albertel 3354: $prevattempts.=&end_data_table_header_row();
1.40 ng 3355: if ($getattempt eq '') {
3356: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3357: $prevattempts.=&start_data_table_row().
3358: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3359: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3360: my $value = &format_previous_attempt_value($key,
3361: $returnhash{$version.':'.$key});
3362: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3363: }
1.596 albertel 3364: $prevattempts.=&end_data_table_row();
1.40 ng 3365: }
1.1 albertel 3366: }
1.596 albertel 3367: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3368: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3369: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3370: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3371: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3372: }
1.596 albertel 3373: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3374: } else {
1.596 albertel 3375: $prevattempts=
3376: &start_data_table().&start_data_table_row().
3377: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3378: &end_data_table_row().&end_data_table();
1.1 albertel 3379: }
3380: } else {
1.596 albertel 3381: $prevattempts=
3382: &start_data_table().&start_data_table_row().
3383: '<td>'.&mt('No data.').'</td>'.
3384: &end_data_table_row().&end_data_table();
1.1 albertel 3385: }
1.10 albertel 3386: }
3387:
1.581 albertel 3388: sub format_previous_attempt_value {
3389: my ($key,$value) = @_;
3390: if ($key =~ /timestamp/) {
3391: $value = &Apache::lonlocal::locallocaltime($value);
3392: } elsif (ref($value) eq 'ARRAY') {
3393: $value = '('.join(', ', @{ $value }).')';
3394: } else {
3395: $value = &unescape($value);
3396: }
3397: return $value;
3398: }
3399:
3400:
1.107 albertel 3401: sub relative_to_absolute {
3402: my ($url,$output)=@_;
3403: my $parser=HTML::TokeParser->new(\$output);
3404: my $token;
3405: my $thisdir=$url;
3406: my @rlinks=();
3407: while ($token=$parser->get_token) {
3408: if ($token->[0] eq 'S') {
3409: if ($token->[1] eq 'a') {
3410: if ($token->[2]->{'href'}) {
3411: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3412: }
3413: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3414: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3415: } elsif ($token->[1] eq 'base') {
3416: $thisdir=$token->[2]->{'href'};
3417: }
3418: }
3419: }
3420: $thisdir=~s-/[^/]*$--;
1.356 albertel 3421: foreach my $link (@rlinks) {
1.726 raeburn 3422: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3423: ($link=~/^\//) ||
3424: ($link=~/^javascript:/i) ||
3425: ($link=~/^mailto:/i) ||
3426: ($link=~/^\#/)) {
3427: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3428: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3429: }
3430: }
3431: # -------------------------------------------------- Deal with Applet codebases
3432: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3433: return $output;
3434: }
3435:
1.112 bowersj2 3436: =pod
3437:
1.648 raeburn 3438: =item * &get_student_view()
1.112 bowersj2 3439:
3440: show a snapshot of what student was looking at
3441:
3442: =cut
3443:
1.10 albertel 3444: sub get_student_view {
1.186 albertel 3445: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3446: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3447: my (%form);
1.10 albertel 3448: my @elements=('symb','courseid','domain','username');
3449: foreach my $element (@elements) {
1.186 albertel 3450: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3451: }
1.186 albertel 3452: if (defined($moreenv)) {
3453: %form=(%form,%{$moreenv});
3454: }
1.236 albertel 3455: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3456: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3457: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3458: $userview=~s/\<body[^\>]*\>//gi;
3459: $userview=~s/\<\/body\>//gi;
3460: $userview=~s/\<html\>//gi;
3461: $userview=~s/\<\/html\>//gi;
3462: $userview=~s/\<head\>//gi;
3463: $userview=~s/\<\/head\>//gi;
3464: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3465: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3466: if (wantarray) {
3467: return ($userview,$response);
3468: } else {
3469: return $userview;
3470: }
3471: }
3472:
3473: sub get_student_view_with_retries {
3474: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3475:
3476: my $ok = 0; # True if we got a good response.
3477: my $content;
3478: my $response;
3479:
3480: # Try to get the student_view done. within the retries count:
3481:
3482: do {
3483: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3484: $ok = $response->is_success;
3485: if (!$ok) {
3486: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3487: }
3488: $retries--;
3489: } while (!$ok && ($retries > 0));
3490:
3491: if (!$ok) {
3492: $content = ''; # On error return an empty content.
3493: }
1.651 www 3494: if (wantarray) {
3495: return ($content, $response);
3496: } else {
3497: return $content;
3498: }
1.11 albertel 3499: }
3500:
1.112 bowersj2 3501: =pod
3502:
1.648 raeburn 3503: =item * &get_student_answers()
1.112 bowersj2 3504:
3505: show a snapshot of how student was answering problem
3506:
3507: =cut
3508:
1.11 albertel 3509: sub get_student_answers {
1.100 sakharuk 3510: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3511: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3512: my (%moreenv);
1.11 albertel 3513: my @elements=('symb','courseid','domain','username');
3514: foreach my $element (@elements) {
1.186 albertel 3515: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3516: }
1.186 albertel 3517: $moreenv{'grade_target'}='answer';
3518: %moreenv=(%form,%moreenv);
1.497 raeburn 3519: $feedurl = &Apache::lonnet::clutter($feedurl);
3520: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3521: return $userview;
1.1 albertel 3522: }
1.116 albertel 3523:
3524: =pod
3525:
3526: =item * &submlink()
3527:
1.242 albertel 3528: Inputs: $text $uname $udom $symb $target
1.116 albertel 3529:
3530: Returns: A link to grades.pm such as to see the SUBM view of a student
3531:
3532: =cut
3533:
3534: ###############################################
3535: sub submlink {
1.242 albertel 3536: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3537: if (!($uname && $udom)) {
3538: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3539: &Apache::lonnet::whichuser($symb);
1.116 albertel 3540: if (!$symb) { $symb=$cursymb; }
3541: }
1.254 matthew 3542: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3543: $symb=&escape($symb);
1.242 albertel 3544: if ($target) { $target="target=\"$target\""; }
3545: return '<a href="/adm/grades?&command=submission&'.
3546: 'symb='.$symb.'&student='.$uname.
3547: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3548: }
3549: ##############################################
3550:
3551: =pod
3552:
3553: =item * &pgrdlink()
3554:
3555: Inputs: $text $uname $udom $symb $target
3556:
3557: Returns: A link to grades.pm such as to see the PGRD view of a student
3558:
3559: =cut
3560:
3561: ###############################################
3562: sub pgrdlink {
3563: my $link=&submlink(@_);
3564: $link=~s/(&command=submission)/$1&showgrading=yes/;
3565: return $link;
3566: }
3567: ##############################################
3568:
3569: =pod
3570:
3571: =item * &pprmlink()
3572:
3573: Inputs: $text $uname $udom $symb $target
3574:
3575: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3576: student and a specific resource
1.242 albertel 3577:
3578: =cut
3579:
3580: ###############################################
3581: sub pprmlink {
3582: my ($text,$uname,$udom,$symb,$target)=@_;
3583: if (!($uname && $udom)) {
3584: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3585: &Apache::lonnet::whichuser($symb);
1.242 albertel 3586: if (!$symb) { $symb=$cursymb; }
3587: }
1.254 matthew 3588: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3589: $symb=&escape($symb);
1.242 albertel 3590: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3591: return '<a href="/adm/parmset?command=set&'.
3592: 'symb='.$symb.'&uname='.$uname.
3593: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3594: }
3595: ##############################################
1.37 matthew 3596:
1.112 bowersj2 3597: =pod
3598:
3599: =back
3600:
3601: =cut
3602:
1.37 matthew 3603: ###############################################
1.51 www 3604:
3605:
3606: sub timehash {
1.687 raeburn 3607: my ($thistime) = @_;
3608: my $timezone = &Apache::lonlocal::gettimezone();
3609: my $dt = DateTime->from_epoch(epoch => $thistime)
3610: ->set_time_zone($timezone);
3611: my $wday = $dt->day_of_week();
3612: if ($wday == 7) { $wday = 0; }
3613: return ( 'second' => $dt->second(),
3614: 'minute' => $dt->minute(),
3615: 'hour' => $dt->hour(),
3616: 'day' => $dt->day_of_month(),
3617: 'month' => $dt->month(),
3618: 'year' => $dt->year(),
3619: 'weekday' => $wday,
3620: 'dayyear' => $dt->day_of_year(),
3621: 'dlsav' => $dt->is_dst() );
1.51 www 3622: }
3623:
1.370 www 3624: sub utc_string {
3625: my ($date)=@_;
1.371 www 3626: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3627: }
3628:
1.51 www 3629: sub maketime {
3630: my %th=@_;
1.687 raeburn 3631: my ($epoch_time,$timezone,$dt);
3632: $timezone = &Apache::lonlocal::gettimezone();
3633: eval {
3634: $dt = DateTime->new( year => $th{'year'},
3635: month => $th{'month'},
3636: day => $th{'day'},
3637: hour => $th{'hour'},
3638: minute => $th{'minute'},
3639: second => $th{'second'},
3640: time_zone => $timezone,
3641: );
3642: };
3643: if (!$@) {
3644: $epoch_time = $dt->epoch;
3645: if ($epoch_time) {
3646: return $epoch_time;
3647: }
3648: }
1.51 www 3649: return POSIX::mktime(
3650: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3651: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3652: }
3653:
3654: #########################################
1.51 www 3655:
3656: sub findallcourses {
1.482 raeburn 3657: my ($roles,$uname,$udom) = @_;
1.355 albertel 3658: my %roles;
3659: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3660: my %courses;
1.51 www 3661: my $now=time;
1.482 raeburn 3662: if (!defined($uname)) {
3663: $uname = $env{'user.name'};
3664: }
3665: if (!defined($udom)) {
3666: $udom = $env{'user.domain'};
3667: }
3668: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3669: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3670: if (!%roles) {
3671: %roles = (
3672: cc => 1,
3673: in => 1,
3674: ep => 1,
3675: ta => 1,
3676: cr => 1,
3677: st => 1,
3678: );
3679: }
3680: foreach my $entry (keys(%roleshash)) {
3681: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3682: if ($trole =~ /^cr/) {
3683: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3684: } else {
3685: next if (!exists($roles{$trole}));
3686: }
3687: if ($tend) {
3688: next if ($tend < $now);
3689: }
3690: if ($tstart) {
3691: next if ($tstart > $now);
3692: }
3693: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3694: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3695: if ($secpart eq '') {
3696: ($cnum,$role) = split(/_/,$cnumpart);
3697: $sec = 'none';
3698: $realsec = '';
3699: } else {
3700: $cnum = $cnumpart;
3701: ($sec,$role) = split(/_/,$secpart);
3702: $realsec = $sec;
1.490 raeburn 3703: }
1.482 raeburn 3704: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3705: }
3706: } else {
3707: foreach my $key (keys(%env)) {
1.483 albertel 3708: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3709: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3710: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3711: next if ($role eq 'ca' || $role eq 'aa');
3712: next if (%roles && !exists($roles{$role}));
3713: my ($starttime,$endtime)=split(/\./,$env{$key});
3714: my $active=1;
3715: if ($starttime) {
3716: if ($now<$starttime) { $active=0; }
3717: }
3718: if ($endtime) {
3719: if ($now>$endtime) { $active=0; }
3720: }
3721: if ($active) {
3722: if ($sec eq '') {
3723: $sec = 'none';
3724: }
3725: $courses{$cdom.'_'.$cnum}{$sec} =
3726: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3727: }
3728: }
1.51 www 3729: }
3730: }
1.474 raeburn 3731: return %courses;
1.51 www 3732: }
1.37 matthew 3733:
1.54 www 3734: ###############################################
1.474 raeburn 3735:
3736: sub blockcheck {
1.482 raeburn 3737: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3738:
3739: if (!defined($udom)) {
3740: $udom = $env{'user.domain'};
3741: }
3742: if (!defined($uname)) {
3743: $uname = $env{'user.name'};
3744: }
3745:
3746: # If uname and udom are for a course, check for blocks in the course.
3747:
3748: if (&Apache::lonnet::is_course($udom,$uname)) {
3749: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3750: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3751: return ($startblock,$endblock);
3752: }
1.474 raeburn 3753:
1.502 raeburn 3754: my $startblock = 0;
3755: my $endblock = 0;
1.482 raeburn 3756: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3757:
1.490 raeburn 3758: # If uname is for a user, and activity is course-specific, i.e.,
3759: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3760:
1.490 raeburn 3761: if (($activity eq 'boards' || $activity eq 'chat' ||
3762: $activity eq 'groups') && ($env{'request.course.id'})) {
3763: foreach my $key (keys(%live_courses)) {
3764: if ($key ne $env{'request.course.id'}) {
3765: delete($live_courses{$key});
3766: }
3767: }
3768: }
3769:
3770: my $otheruser = 0;
3771: my %own_courses;
3772: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3773: # Resource belongs to user other than current user.
3774: $otheruser = 1;
3775: # Gather courses for current user
3776: %own_courses =
3777: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3778: }
3779:
3780: # Gather active course roles - course coordinator, instructor,
3781: # exam proctor, ta, student, or custom role.
1.474 raeburn 3782:
3783: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3784: my ($cdom,$cnum);
3785: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3786: $cdom = $env{'course.'.$course.'.domain'};
3787: $cnum = $env{'course.'.$course.'.num'};
3788: } else {
1.490 raeburn 3789: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3790: }
3791: my $no_ownblock = 0;
3792: my $no_userblock = 0;
1.533 raeburn 3793: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3794: # Check if current user has 'evb' priv for this
3795: if (defined($own_courses{$course})) {
3796: foreach my $sec (keys(%{$own_courses{$course}})) {
3797: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3798: if ($sec ne 'none') {
3799: $checkrole .= '/'.$sec;
3800: }
3801: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3802: $no_ownblock = 1;
3803: last;
3804: }
3805: }
3806: }
3807: # if they have 'evb' priv and are currently not playing student
3808: next if (($no_ownblock) &&
3809: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3810: }
1.474 raeburn 3811: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3812: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3813: if ($sec ne 'none') {
1.482 raeburn 3814: $checkrole .= '/'.$sec;
1.474 raeburn 3815: }
1.490 raeburn 3816: if ($otheruser) {
3817: # Resource belongs to user other than current user.
3818: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3819: my ($trole,$tdom,$tnum,$tsec);
3820: my $entry = $live_courses{$course}{$sec};
3821: if ($entry =~ /^cr/) {
3822: ($trole,$tdom,$tnum,$tsec) =
3823: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3824: } else {
3825: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3826: }
3827: my ($spec,$area,$trest,%allroles,%userroles);
3828: $area = '/'.$tdom.'/'.$tnum;
3829: $trest = $tnum;
3830: if ($tsec ne '') {
3831: $area .= '/'.$tsec;
3832: $trest .= '/'.$tsec;
3833: }
3834: $spec = $trole.'.'.$area;
3835: if ($trole =~ /^cr/) {
3836: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3837: $tdom,$spec,$trest,$area);
3838: } else {
3839: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3840: $tdom,$spec,$trest,$area);
3841: }
3842: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3843: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3844: if ($1) {
3845: $no_userblock = 1;
3846: last;
3847: }
3848: }
1.490 raeburn 3849: } else {
3850: # Resource belongs to current user
3851: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3852: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3853: $no_ownblock = 1;
3854: last;
3855: }
1.474 raeburn 3856: }
3857: }
3858: # if they have the evb priv and are currently not playing student
1.482 raeburn 3859: next if (($no_ownblock) &&
1.491 albertel 3860: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3861: next if ($no_userblock);
1.474 raeburn 3862:
1.866 kalberla 3863: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3864: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3865:
3866: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3867: if (($start != 0) &&
3868: (($startblock == 0) || ($startblock > $start))) {
3869: $startblock = $start;
3870: }
3871: if (($end != 0) &&
3872: (($endblock == 0) || ($endblock < $end))) {
3873: $endblock = $end;
3874: }
1.490 raeburn 3875: }
3876: return ($startblock,$endblock);
3877: }
3878:
3879: sub get_blocks {
3880: my ($setters,$activity,$cdom,$cnum) = @_;
3881: my $startblock = 0;
3882: my $endblock = 0;
3883: my $course = $cdom.'_'.$cnum;
3884: $setters->{$course} = {};
3885: $setters->{$course}{'staff'} = [];
3886: $setters->{$course}{'times'} = [];
3887: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3888: foreach my $record (keys(%records)) {
3889: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3890: if ($start <= time && $end >= time) {
3891: my ($staff_name,$staff_dom,$title,$blocks) =
3892: &parse_block_record($records{$record});
3893: if ($blocks->{$activity} eq 'on') {
3894: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3895: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3896: if ( ($startblock == 0) || ($startblock > $start) ) {
3897: $startblock = $start;
1.490 raeburn 3898: }
1.491 albertel 3899: if ( ($endblock == 0) || ($endblock < $end) ) {
3900: $endblock = $end;
1.474 raeburn 3901: }
3902: }
3903: }
3904: }
3905: return ($startblock,$endblock);
3906: }
3907:
3908: sub parse_block_record {
3909: my ($record) = @_;
3910: my ($setuname,$setudom,$title,$blocks);
3911: if (ref($record) eq 'HASH') {
3912: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3913: $title = &unescape($record->{'event'});
3914: $blocks = $record->{'blocks'};
3915: } else {
3916: my @data = split(/:/,$record,3);
3917: if (scalar(@data) eq 2) {
3918: $title = $data[1];
3919: ($setuname,$setudom) = split(/@/,$data[0]);
3920: } else {
3921: ($setuname,$setudom,$title) = @data;
3922: }
3923: $blocks = { 'com' => 'on' };
3924: }
3925: return ($setuname,$setudom,$title,$blocks);
3926: }
3927:
1.854 kalberla 3928: sub blocking_status {
3929: my ($activity,$uname,$udom) = @_;
1.867 kalberla 3930: my %setters;
1.890 droeschl 3931:
3932: # check for active blocking
1.867 kalberla 3933: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 3934:
1.890 droeschl 3935: my $blocked = $startblock && $endblock ? 1 : 0;
3936:
3937: # caller just wants to know whether a block is active
3938: if (!wantarray) { return $blocked; }
3939:
3940: # build a link to a popup window containing the details
3941: my $querystring = "?activity=$activity";
3942: # $uname and $udom decide whose portfolio the user is trying to look at
3943: $querystring .= "&udom=$udom" if $udom;
3944: $querystring .= "&uname=$uname" if $uname;
3945:
3946: my $output .= <<'END_MYBLOCK';
1.854 kalberla 3947: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3948: var options = "width=" + w + ",height=" + h + ",";
3949: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3950: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3951: var newWin = window.open(url, wdwName, options);
3952: newWin.focus();
3953: }
1.890 droeschl 3954: END_MYBLOCK
1.854 kalberla 3955:
1.890 droeschl 3956: $output = Apache::lonhtmlcommon::scripttag($output);
3957:
1.854 kalberla 3958: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 3959: my $text = mt('Communication Blocked');
3960:
1.867 kalberla 3961: $output .= <<"END_BLOCK";
3962: <div class='LC_comblock'>
1.869 kalberla 3963: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 3964: title='$text'>
3965: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 3966: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 3967: title='$text'>$text</a>
1.867 kalberla 3968: </div>
3969:
3970: END_BLOCK
1.474 raeburn 3971:
1.854 kalberla 3972: return ($blocked, $output);
3973: }
1.490 raeburn 3974:
1.60 matthew 3975: ###############################################
3976:
1.682 raeburn 3977: sub check_ip_acc {
3978: my ($acc)=@_;
3979: &Apache::lonxml::debug("acc is $acc");
3980: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3981: return 1;
3982: }
3983: my $allowed=0;
3984: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3985:
3986: my $name;
3987: foreach my $pattern (split(',',$acc)) {
3988: $pattern =~ s/^\s*//;
3989: $pattern =~ s/\s*$//;
3990: if ($pattern =~ /\*$/) {
3991: #35.8.*
3992: $pattern=~s/\*//;
3993: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3994: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3995: #35.8.3.[34-56]
3996: my $low=$2;
3997: my $high=$3;
3998: $pattern=$1;
3999: if ($ip =~ /^\Q$pattern\E/) {
4000: my $last=(split(/\./,$ip))[3];
4001: if ($last <=$high && $last >=$low) { $allowed=1; }
4002: }
4003: } elsif ($pattern =~ /^\*/) {
4004: #*.msu.edu
4005: $pattern=~s/\*//;
4006: if (!defined($name)) {
4007: use Socket;
4008: my $netaddr=inet_aton($ip);
4009: ($name)=gethostbyaddr($netaddr,AF_INET);
4010: }
4011: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4012: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4013: #127.0.0.1
4014: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4015: } else {
4016: #some.name.com
4017: if (!defined($name)) {
4018: use Socket;
4019: my $netaddr=inet_aton($ip);
4020: ($name)=gethostbyaddr($netaddr,AF_INET);
4021: }
4022: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4023: }
4024: if ($allowed) { last; }
4025: }
4026: return $allowed;
4027: }
4028:
4029: ###############################################
4030:
1.60 matthew 4031: =pod
4032:
1.112 bowersj2 4033: =head1 Domain Template Functions
4034:
4035: =over 4
4036:
4037: =item * &determinedomain()
1.60 matthew 4038:
4039: Inputs: $domain (usually will be undef)
4040:
1.63 www 4041: Returns: Determines which domain should be used for designs
1.60 matthew 4042:
4043: =cut
1.54 www 4044:
1.60 matthew 4045: ###############################################
1.63 www 4046: sub determinedomain {
4047: my $domain=shift;
1.531 albertel 4048: if (! $domain) {
1.60 matthew 4049: # Determine domain if we have not been given one
1.893 raeburn 4050: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4051: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4052: if ($env{'request.role.domain'}) {
4053: $domain=$env{'request.role.domain'};
1.60 matthew 4054: }
4055: }
1.63 www 4056: return $domain;
4057: }
4058: ###############################################
1.517 raeburn 4059:
1.518 albertel 4060: sub devalidate_domconfig_cache {
4061: my ($udom)=@_;
4062: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4063: }
4064:
4065: # ---------------------- Get domain configuration for a domain
4066: sub get_domainconf {
4067: my ($udom) = @_;
4068: my $cachetime=1800;
4069: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4070: if (defined($cached)) { return %{$result}; }
4071:
4072: my %domconfig = &Apache::lonnet::get_dom('configuration',
4073: ['login','rolecolors'],$udom);
1.632 raeburn 4074: my (%designhash,%legacy);
1.518 albertel 4075: if (keys(%domconfig) > 0) {
4076: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4077: if (keys(%{$domconfig{'login'}})) {
4078: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4079: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4080: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4081: $designhash{$udom.'.login.'.$key.'_'.$img} =
4082: $domconfig{'login'}{$key}{$img};
4083: }
4084: } else {
4085: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4086: }
1.632 raeburn 4087: }
4088: } else {
4089: $legacy{'login'} = 1;
1.518 albertel 4090: }
1.632 raeburn 4091: } else {
4092: $legacy{'login'} = 1;
1.518 albertel 4093: }
4094: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4095: if (keys(%{$domconfig{'rolecolors'}})) {
4096: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4097: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4098: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4099: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4100: }
1.518 albertel 4101: }
4102: }
1.632 raeburn 4103: } else {
4104: $legacy{'rolecolors'} = 1;
1.518 albertel 4105: }
1.632 raeburn 4106: } else {
4107: $legacy{'rolecolors'} = 1;
1.518 albertel 4108: }
1.632 raeburn 4109: if (keys(%legacy) > 0) {
4110: my %legacyhash = &get_legacy_domconf($udom);
4111: foreach my $item (keys(%legacyhash)) {
4112: if ($item =~ /^\Q$udom\E\.login/) {
4113: if ($legacy{'login'}) {
4114: $designhash{$item} = $legacyhash{$item};
4115: }
4116: } else {
4117: if ($legacy{'rolecolors'}) {
4118: $designhash{$item} = $legacyhash{$item};
4119: }
1.518 albertel 4120: }
4121: }
4122: }
1.632 raeburn 4123: } else {
4124: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4125: }
4126: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4127: $cachetime);
4128: return %designhash;
4129: }
4130:
1.632 raeburn 4131: sub get_legacy_domconf {
4132: my ($udom) = @_;
4133: my %legacyhash;
4134: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4135: my $designfile = $designdir.'/'.$udom.'.tab';
4136: if (-e $designfile) {
4137: if ( open (my $fh,"<$designfile") ) {
4138: while (my $line = <$fh>) {
4139: next if ($line =~ /^\#/);
4140: chomp($line);
4141: my ($key,$val)=(split(/\=/,$line));
4142: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4143: }
4144: close($fh);
4145: }
4146: }
4147: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4148: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4149: }
4150: return %legacyhash;
4151: }
4152:
1.63 www 4153: =pod
4154:
1.112 bowersj2 4155: =item * &domainlogo()
1.63 www 4156:
4157: Inputs: $domain (usually will be undef)
4158:
4159: Returns: A link to a domain logo, if the domain logo exists.
4160: If the domain logo does not exist, a description of the domain.
4161:
4162: =cut
1.112 bowersj2 4163:
1.63 www 4164: ###############################################
4165: sub domainlogo {
1.517 raeburn 4166: my $domain = &determinedomain(shift);
1.518 albertel 4167: my %designhash = &get_domainconf($domain);
1.517 raeburn 4168: # See if there is a logo
4169: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4170: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4171: if ($imgsrc =~ m{^/(adm|res)/}) {
4172: if ($imgsrc =~ m{^/res/}) {
4173: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4174: &Apache::lonnet::repcopy($local_name);
4175: }
4176: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4177: }
4178: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4179: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4180: return &Apache::lonnet::domain($domain,'description');
1.59 www 4181: } else {
1.60 matthew 4182: return '';
1.59 www 4183: }
4184: }
1.63 www 4185: ##############################################
4186:
4187: =pod
4188:
1.112 bowersj2 4189: =item * &designparm()
1.63 www 4190:
4191: Inputs: $which parameter; $domain (usually will be undef)
4192:
4193: Returns: value of designparamter $which
4194:
4195: =cut
1.112 bowersj2 4196:
1.397 albertel 4197:
1.400 albertel 4198: ##############################################
1.397 albertel 4199: sub designparm {
4200: my ($which,$domain)=@_;
4201: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4202: return $env{'environment.color.'.$which};
1.96 www 4203: }
1.63 www 4204: $domain=&determinedomain($domain);
1.518 albertel 4205: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4206: my $output;
1.517 raeburn 4207: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4208: $output = $domdesign{$domain.'.'.$which};
1.63 www 4209: } else {
1.520 raeburn 4210: $output = $defaultdesign{$which};
4211: }
4212: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4213: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4214: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4215: if ($output =~ m{^/res/}) {
4216: my $local_name = &Apache::lonnet::filelocation('',$output);
4217: &Apache::lonnet::repcopy($local_name);
4218: }
1.520 raeburn 4219: $output = &lonhttpdurl($output);
4220: }
1.63 www 4221: }
1.520 raeburn 4222: return $output;
1.63 www 4223: }
1.59 www 4224:
1.822 bisitz 4225: ##############################################
4226: =pod
4227:
1.832 bisitz 4228: =item * &authorspace()
4229:
4230: Inputs: ./.
4231:
4232: Returns: Path to the Construction Space of the current user's
4233: accessed author space
4234: The author space will be that of the current user
4235: when accessing the own author space
4236: and that of the co-author/assistent co-author
4237: when accessing the co-author's/assistent co-author's
4238: space
4239:
4240: =cut
4241:
4242: sub authorspace {
4243: my $caname = '';
4244: if ($env{'request.role'} =~ /^ca|^aa/) {
4245: (undef,$caname) =
4246: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4247: } else {
4248: $caname = $env{'user.name'};
4249: }
4250: return '/priv/'.$caname.'/';
4251: }
4252:
4253: ##############################################
4254: =pod
4255:
1.822 bisitz 4256: =item * &head_subbox()
4257:
4258: Inputs: $content (contains HTML code with page functions, etc.)
4259:
4260: Returns: HTML div with $content
4261: To be included in page header
4262:
4263: =cut
4264:
4265: sub head_subbox {
4266: my ($content)=@_;
4267: my $output =
1.844 bisitz 4268: '<div id="LC_head_subbox">'
1.822 bisitz 4269: .$content
4270: .'</div>'
4271: }
4272:
4273: ##############################################
4274: =pod
4275:
4276: =item * &CSTR_pageheader()
4277:
4278: Inputs: ./.
4279:
4280: Returns: HTML div with CSTR path and recent box
4281: To be included on Construction Space pages
4282:
4283: =cut
4284:
4285: sub CSTR_pageheader {
4286: # this is for resources; directories have customtitle, and crumbs
4287: # and select recent are created in lonpubdir.pm
4288: my ($uname,$thisdisfn)=
4289: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4290: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4291: $formaction=~s/\/+/\//g;
4292:
4293: my $parentpath = '';
4294: my $lastitem = '';
4295: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4296: $parentpath = $1;
4297: $lastitem = $2;
4298: } else {
4299: $lastitem = $thisdisfn;
4300: }
4301: return
4302: '<div>'
4303: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4304: .'<b>'.&mt('Construction Space:').'</b> '
4305: .'<form name="dirs" method="post" action="'.$formaction
4306: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4307: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4308: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4309: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4310: .'</form>'
4311: .&Apache::lonmenu::constspaceform()
4312: .'</div>';
4313: }
4314:
1.60 matthew 4315: ###############################################
4316: ###############################################
4317:
4318: =pod
4319:
1.112 bowersj2 4320: =back
4321:
1.549 albertel 4322: =head1 HTML Helpers
1.112 bowersj2 4323:
4324: =over 4
4325:
4326: =item * &bodytag()
1.60 matthew 4327:
4328: Returns a uniform header for LON-CAPA web pages.
4329:
4330: Inputs:
4331:
1.112 bowersj2 4332: =over 4
4333:
4334: =item * $title, A title to be displayed on the page.
4335:
4336: =item * $function, the current role (can be undef).
4337:
4338: =item * $addentries, extra parameters for the <body> tag.
4339:
4340: =item * $bodyonly, if defined, only return the <body> tag.
4341:
4342: =item * $domain, if defined, force a given domain.
4343:
4344: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4345: text interface only)
1.60 matthew 4346:
1.814 bisitz 4347: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4348: navigational links
1.317 albertel 4349:
1.338 albertel 4350: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4351:
1.361 albertel 4352: =item * $no_inline_link, if true and in remote mode, don't show the
4353: 'Switch To Inline Menu' link
4354:
1.460 albertel 4355: =item * $args, optional argument valid values are
4356: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4357: inherit_jsmath -> when creating popup window in a page,
4358: should it have jsmath forced on by the
4359: current page
1.460 albertel 4360:
1.112 bowersj2 4361: =back
4362:
1.60 matthew 4363: Returns: A uniform header for LON-CAPA web pages.
4364: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4365: If $bodyonly is undef or zero, an html string containing a <body> tag and
4366: other decorations will be returned.
4367:
4368: =cut
4369:
1.54 www 4370: sub bodytag {
1.831 bisitz 4371: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4372: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4373:
1.460 albertel 4374: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4375:
1.183 matthew 4376: $function = &get_users_function() if (!$function);
1.339 albertel 4377: my $img = &designparm($function.'.img',$domain);
4378: my $font = &designparm($function.'.font',$domain);
4379: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4380:
1.803 bisitz 4381: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4382: 'bgcolor' => $pgbg,
1.339 albertel 4383: 'text' => $font,
4384: 'alink' => &designparm($function.'.alink',$domain),
4385: 'vlink' => &designparm($function.'.vlink',$domain),
4386: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4387: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4388:
1.63 www 4389: # role and realm
1.378 raeburn 4390: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4391: if ($role eq 'ca') {
1.479 albertel 4392: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4393: $realm = &plainname($rname,$rdom);
1.378 raeburn 4394: }
1.55 www 4395: # realm
1.258 albertel 4396: if ($env{'request.course.id'}) {
1.378 raeburn 4397: if ($env{'request.role'} !~ /^cr/) {
4398: $role = &Apache::lonnet::plaintext($role,&course_type());
4399: }
1.898 raeburn 4400: if ($env{'request.course.sec'}) {
4401: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4402: }
1.359 albertel 4403: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4404: } else {
4405: $role = &Apache::lonnet::plaintext($role);
1.54 www 4406: }
1.433 albertel 4407:
1.359 albertel 4408: if (!$realm) { $realm=' '; }
1.55 www 4409: # Set messages
1.60 matthew 4410: my $messages=&domainlogo($domain);
1.330 albertel 4411:
1.438 albertel 4412: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4413:
1.101 www 4414: # construct main body tag
1.359 albertel 4415: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4416: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4417:
1.530 albertel 4418: if ($bodyonly) {
1.60 matthew 4419: return $bodytag;
1.798 tempelho 4420: }
1.359 albertel 4421:
1.410 albertel 4422: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4423: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4424: undef($role);
1.434 albertel 4425: } else {
4426: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4427: }
1.359 albertel 4428:
1.762 bisitz 4429: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4430: #
4431: # Extra info if you are the DC
4432: my $dc_info = '';
4433: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4434: $env{'course.'.$env{'request.course.id'}.
4435: '.domain'}.'/'})) {
4436: my $cid = $env{'request.course.id'};
4437: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4438: $dc_info =~ s/\s+$//;
1.359 albertel 4439: $dc_info = '('.$dc_info.')';
4440: }
4441:
1.898 raeburn 4442: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4443: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4444:
1.837 bisitz 4445: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4446: # No Remote
1.903 droeschl 4447: if ($no_nav_bar) { return $bodytag; }
4448:
4449: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4450:
4451: # if ($env{'request.state'} eq 'construct') {
4452: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4453: # }
4454:
4455: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4456: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
1.359 albertel 4457:
1.903 droeschl 4458: if ( $env{'form.inhibitmenu'} eq 'yes'
4459: || $ENV{'REQUEST_URI'} eq '/adm/logout'
4460: || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.359 albertel 4461:
1.903 droeschl 4462: return $bodytag;
4463: }
1.894 droeschl 4464:
1.903 droeschl 4465: $bodytag .= Apache::lonhtmlcommon::scripttag(
4466: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4467:
1.903 droeschl 4468: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4469:
1.903 droeschl 4470: #don't show menus for public users
4471: if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
4472: $bodytag .= Apache::lonmenu::secondary_menu();
4473: $bodytag .= Apache::lonmenu::serverform();
4474: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4475: $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
4476: }else{
4477: # this is to seperate menu from content when there's no secondary
4478: # menu. Especially needed for public accessible ressources.
4479: $bodytag .= '<hr style="clear:both" />';
4480: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4481: }
1.903 droeschl 4482:
4483: #SD testing
4484: #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
1.235 raeburn 4485: return $bodytag;
1.94 www 4486: }
1.95 www 4487:
1.93 www 4488: #
1.95 www 4489: # Top frame rendering, Remote is up
1.93 www 4490: #
1.359 albertel 4491:
1.517 raeburn 4492: my $imgsrc = $img;
4493: if ($img =~ /^\/adm/) {
1.575 albertel 4494: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4495: }
4496: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4497:
1.305 www 4498: # Explicit link to get inline menu
1.361 albertel 4499: my $menu= ($no_inline_link?''
1.883 droeschl 4500: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.853 droeschl 4501: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4502: <em>$realm</em> $dc_info </div>
1.897 wenzelju 4503: <ol class="LC_primary_menu LC_right">
1.853 droeschl 4504: <li>$menu</li>
4505: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4506: #
1.94 www 4507: return(<<ENDBODY);
1.60 matthew 4508: $bodytag
1.359 albertel 4509: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4510: <tr><td>$upperleft</td>
4511: <td>$messages </td>
1.54 www 4512: </tr>
1.359 albertel 4513: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4514: </tr>
1.356 albertel 4515: </table>
1.54 www 4516: ENDBODY
1.182 matthew 4517: }
4518:
1.330 albertel 4519: sub make_attr_string {
4520: my ($register,$attr_ref) = @_;
4521:
4522: if ($attr_ref && !ref($attr_ref)) {
4523: die("addentries Must be a hash ref ".
4524: join(':',caller(1))." ".
4525: join(':',caller(0))." ");
4526: }
4527:
4528: if ($register) {
1.339 albertel 4529: my ($on_load,$on_unload);
4530: foreach my $key (keys(%{$attr_ref})) {
4531: if (lc($key) eq 'onload') {
4532: $on_load.=$attr_ref->{$key}.';';
4533: delete($attr_ref->{$key});
4534:
4535: } elsif (lc($key) eq 'onunload') {
4536: $on_unload.=$attr_ref->{$key}.';';
4537: delete($attr_ref->{$key});
4538: }
4539: }
4540: $attr_ref->{'onload'} =
4541: &Apache::lonmenu::loadevents(). $on_load;
4542: $attr_ref->{'onunload'}=
4543: &Apache::lonmenu::unloadevents().$on_unload;
4544: }
4545:
4546: # Accessibility font enhance
4547: if ($env{'browser.fontenhance'} eq 'on') {
4548: my $style;
4549: foreach my $key (keys(%{$attr_ref})) {
4550: if (lc($key) eq 'style') {
4551: $style.=$attr_ref->{$key}.';';
4552: delete($attr_ref->{$key});
4553: }
4554: }
4555: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4556: }
1.339 albertel 4557:
1.330 albertel 4558: my $attr_string;
4559: foreach my $attr (keys(%$attr_ref)) {
4560: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4561: }
4562: return $attr_string;
4563: }
4564:
4565:
1.182 matthew 4566: ###############################################
1.251 albertel 4567: ###############################################
4568:
4569: =pod
4570:
4571: =item * &endbodytag()
4572:
4573: Returns a uniform footer for LON-CAPA web pages.
4574:
1.635 raeburn 4575: Inputs: 1 - optional reference to an args hash
4576: If in the hash, key for noredirectlink has a value which evaluates to true,
4577: a 'Continue' link is not displayed if the page contains an
4578: internal redirect in the <head></head> section,
4579: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4580:
4581: =cut
4582:
4583: sub endbodytag {
1.635 raeburn 4584: my ($args) = @_;
1.251 albertel 4585: my $endbodytag='</body>';
1.269 albertel 4586: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4587: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4588: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4589: $endbodytag=
4590: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4591: &mt('Continue').'</a>'.
4592: $endbodytag;
4593: }
1.315 albertel 4594: }
1.251 albertel 4595: return $endbodytag;
4596: }
4597:
1.352 albertel 4598: =pod
4599:
4600: =item * &standard_css()
4601:
4602: Returns a style sheet
4603:
4604: Inputs: (all optional)
4605: domain -> force to color decorate a page for a specific
4606: domain
4607: function -> force usage of a specific rolish color scheme
4608: bgcolor -> override the default page bgcolor
4609:
4610: =cut
4611:
1.343 albertel 4612: sub standard_css {
1.345 albertel 4613: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4614: $function = &get_users_function() if (!$function);
4615: my $img = &designparm($function.'.img', $domain);
4616: my $tabbg = &designparm($function.'.tabbg', $domain);
4617: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4618: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4619: #second colour for later usage
1.345 albertel 4620: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4621: my $pgbg_or_bgcolor =
4622: $bgcolor ||
1.352 albertel 4623: &designparm($function.'.pgbg', $domain);
1.382 albertel 4624: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4625: my $alink = &designparm($function.'.alink', $domain);
4626: my $vlink = &designparm($function.'.vlink', $domain);
4627: my $link = &designparm($function.'.link', $domain);
4628:
1.704 muellerd 4629: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4630: my $bgcol = &designparm('login.bgcol',$domain);
4631: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4632:
1.602 albertel 4633: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4634: my $mono = 'monospace';
1.850 bisitz 4635: my $data_table_head = $sidebg;
4636: my $data_table_light = '#FAFAFA';
4637: my $data_table_dark = '#F0F0F0';
1.470 banghart 4638: my $data_table_darker = '#CCCCCC';
1.349 albertel 4639: my $data_table_highlight = '#FFFF00';
1.352 albertel 4640: my $mail_new = '#FFBB77';
4641: my $mail_new_hover = '#DD9955';
4642: my $mail_read = '#BBBB77';
4643: my $mail_read_hover = '#999944';
4644: my $mail_replied = '#AAAA88';
4645: my $mail_replied_hover = '#888855';
4646: my $mail_other = '#99BBBB';
4647: my $mail_other_hover = '#669999';
1.391 albertel 4648: my $table_header = '#DDDDDD';
1.489 raeburn 4649: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4650: my $lg_border_color = '#C8C8C8';
1.392 albertel 4651:
1.608 albertel 4652: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4653: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4654: : '0 3px 0 4px';
1.448 albertel 4655:
1.523 albertel 4656:
1.343 albertel 4657: return <<END;
1.795 www 4658: body {
4659: font-family: $sans;
4660: line-height:130%;
4661: font-size:0.83em;
4662: color:$font;
4663: }
4664:
4665: a:link, a:visited {
4666: font-size:100%;
4667: }
4668:
4669: a:focus {
4670: color: red;
4671: background: yellow
4672: }
1.698 harmsja 4673:
1.795 www 4674: form, .inline {
4675: display: inline;
4676: }
1.721 harmsja 4677:
1.795 www 4678: .LC_right {
4679: text-align:right;
4680: }
4681:
4682: .LC_middle {
4683: vertical-align:middle;
4684: }
1.721 harmsja 4685:
4686: /* just for tests */
1.754 droeschl 4687: .LC_400Box {width:400px; }
1.721 harmsja 4688: /* end */
4689:
1.778 bisitz 4690: .LC_filename {
4691: font-family: $mono;
4692: white-space:pre;
4693: }
4694:
4695: .LC_fileicon {
4696: border: none;
4697: height: 1.3em;
4698: vertical-align: text-bottom;
4699: margin-right: 0.3em;
4700: text-decoration:none;
4701: }
4702:
1.350 albertel 4703: .LC_error {
4704: color: red;
4705: font-size: larger;
4706: }
1.795 www 4707:
1.457 albertel 4708: .LC_warning,
4709: .LC_diff_removed {
1.733 bisitz 4710: color: red;
1.394 albertel 4711: }
1.532 albertel 4712:
4713: .LC_info,
1.457 albertel 4714: .LC_success,
4715: .LC_diff_added {
1.350 albertel 4716: color: green;
4717: }
1.795 www 4718:
1.802 bisitz 4719: div.LC_confirm_box {
4720: background-color: #FAFAFA;
4721: border: 1px solid $lg_border_color;
4722: margin-right: 0;
4723: padding: 5px;
4724: }
4725:
4726: div.LC_confirm_box .LC_error img,
4727: div.LC_confirm_box .LC_success img {
4728: vertical-align: middle;
4729: }
4730:
1.440 albertel 4731: .LC_icon {
1.771 droeschl 4732: border: none;
1.790 droeschl 4733: vertical-align: middle;
1.771 droeschl 4734: }
4735:
1.543 albertel 4736: .LC_docs_spacer {
4737: width: 25px;
4738: height: 1px;
1.771 droeschl 4739: border: none;
1.543 albertel 4740: }
1.346 albertel 4741:
1.532 albertel 4742: .LC_internal_info {
1.735 bisitz 4743: color: #999999;
1.532 albertel 4744: }
4745:
1.794 www 4746: .LC_discussion {
4747: background: $tabbg;
4748: border: 1px solid black;
4749: margin: 2px;
4750: }
4751:
4752: .LC_disc_action_links_bar {
4753: background: $tabbg;
1.803 bisitz 4754: border: none;
1.795 www 4755: margin: 4px;
1.794 www 4756: }
4757:
4758: .LC_disc_action_left {
4759: text-align: left;
4760: }
4761:
4762: .LC_disc_action_right {
4763: text-align: right;
4764: }
4765:
4766: .LC_disc_new_item {
4767: background: white;
4768: border: 2px solid red;
4769: margin: 2px;
4770: }
4771:
4772: .LC_disc_old_item {
4773: background: white;
4774: border: 1px solid black;
4775: margin: 2px;
4776: }
4777:
1.458 albertel 4778: table.LC_pastsubmission {
4779: border: 1px solid black;
4780: margin: 2px;
4781: }
4782:
1.795 www 4783: table#LC_top_nav,
4784: table#LC_menubuttons,
4785: table#LC_nav_location {
1.345 albertel 4786: width: 100%;
4787: background: $pgbg;
1.392 albertel 4788: border: 2px;
1.402 albertel 4789: border-collapse: separate;
1.803 bisitz 4790: padding: 0;
1.345 albertel 4791: }
1.392 albertel 4792:
1.801 tempelho 4793: table#LC_title_bar a {
4794: color: $fontmenu;
4795: }
1.836 bisitz 4796:
1.807 droeschl 4797: table#LC_title_bar {
1.819 tempelho 4798: clear: both;
1.836 bisitz 4799: display: none;
1.807 droeschl 4800: }
4801:
1.795 www 4802: table#LC_title_bar,
4803: table.LC_breadcrumbs,
1.393 albertel 4804: table#LC_title_bar.LC_with_remote {
1.359 albertel 4805: width: 100%;
1.392 albertel 4806: border-color: $pgbg;
4807: border-style: solid;
4808: border-width: $border;
1.379 albertel 4809: background: $pgbg;
1.801 tempelho 4810: color: $fontmenu;
1.392 albertel 4811: border-collapse: collapse;
1.803 bisitz 4812: padding: 0;
1.819 tempelho 4813: margin: 0;
1.359 albertel 4814: }
1.795 www 4815:
1.359 albertel 4816: table#LC_title_bar td {
4817: background: $tabbg;
4818: }
1.795 www 4819:
1.706 harmsja 4820: table#LC_menubuttons img{
1.803 bisitz 4821: border: none;
1.346 albertel 4822: }
1.795 www 4823:
1.345 albertel 4824: table#LC_top_nav td {
4825: background: $tabbg;
1.803 bisitz 4826: border: none;
1.407 albertel 4827: font-size: small;
1.706 harmsja 4828: vertical-align:top;
4829: padding:2px 5px 2px 5px;
1.345 albertel 4830: }
1.795 www 4831:
4832: table#LC_top_nav td a,
4833: div#LC_top_nav a {
1.345 albertel 4834: color: $font;
4835: }
1.795 www 4836:
1.364 albertel 4837: table#LC_top_nav td.LC_top_nav_logo {
4838: background: $tabbg;
1.432 albertel 4839: text-align: left;
1.408 albertel 4840: white-space: nowrap;
1.432 albertel 4841: width: 31px;
1.408 albertel 4842: }
1.795 www 4843:
1.408 albertel 4844: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4845: border: none;
1.408 albertel 4846: vertical-align: bottom;
1.364 albertel 4847: }
1.795 www 4848:
1.777 tempelho 4849: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4850: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4851: width: 2.0em;
4852: }
1.795 www 4853:
1.442 albertel 4854: table#LC_top_nav td.LC_top_nav_login {
4855: width: 4.0em;
4856: text-align: center;
4857: }
1.795 www 4858:
1.842 droeschl 4859: .LC_breadcrumbs_component {
4860: float: right;
4861: margin: 0 1em;
1.357 albertel 4862: }
1.842 droeschl 4863: .LC_breadcrumbs_component img {
4864: vertical-align: middle;
1.777 tempelho 4865: }
1.795 www 4866:
1.383 albertel 4867: td.LC_table_cell_checkbox {
4868: text-align: center;
4869: }
1.795 www 4870:
1.779 bisitz 4871: table#LC_mainmenu td.LC_mainmenu_column {
4872: vertical-align: top;
1.777 tempelho 4873: }
1.522 albertel 4874:
1.795 www 4875: .LC_fontsize_small {
1.705 tempelho 4876: font-size: 70%;
4877: }
4878:
1.844 bisitz 4879: #LC_breadcrumbs {
1.819 tempelho 4880: clear:both;
4881: background: $sidebg;
1.822 bisitz 4882: border-bottom: 1px solid $lg_border_color;
1.904 ! droeschl 4883: line-height: 2.5em;
! 4884: /* SD working here
! 4885: height: 2.5em;
! 4886: overflow: hidden; */
1.822 bisitz 4887: margin: 0;
1.819 tempelho 4888: padding: 0;
4889: }
1.862 bisitz 4890:
1.839 droeschl 4891: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4892: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4893: display:none;
4894: }
1.819 tempelho 4895:
1.844 bisitz 4896: #LC_head_subbox {
1.822 bisitz 4897: clear:both;
4898: background: #F8F8F8; /* $sidebg; */
4899: border-bottom: 1px solid $lg_border_color;
4900: margin: 0 0 10px 0;
4901: padding: 5px;
4902: }
4903:
1.795 www 4904: .LC_fontsize_medium {
1.705 tempelho 4905: font-size: 85%;
4906: }
4907:
1.795 www 4908: .LC_fontsize_large {
1.705 tempelho 4909: font-size: 120%;
4910: }
4911:
1.346 albertel 4912: .LC_menubuttons_inline_text {
4913: color: $font;
1.698 harmsja 4914: font-size: 90%;
1.701 harmsja 4915: padding-left:3px;
1.346 albertel 4916: }
4917:
1.526 www 4918: .LC_menubuttons_link {
4919: text-decoration: none;
4920: }
1.795 www 4921:
1.522 albertel 4922: .LC_menubuttons_category {
1.521 www 4923: color: $font;
1.526 www 4924: background: $pgbg;
1.521 www 4925: font-size: larger;
4926: font-weight: bold;
4927: }
4928:
1.346 albertel 4929: td.LC_menubuttons_text {
1.779 bisitz 4930: color: $font;
1.346 albertel 4931: }
1.706 harmsja 4932:
1.346 albertel 4933: .LC_current_location {
4934: background: $tabbg;
4935: }
1.795 www 4936:
1.346 albertel 4937: .LC_new_mail {
1.634 www 4938: background: $tabbg;
1.346 albertel 4939: font-weight: bold;
4940: }
1.347 albertel 4941:
1.795 www 4942: table.LC_data_table,
4943: table.LC_mail_list {
1.347 albertel 4944: border: 1px solid #000000;
1.402 albertel 4945: border-collapse: separate;
1.426 albertel 4946: border-spacing: 1px;
1.610 albertel 4947: background: $pgbg;
1.347 albertel 4948: }
1.795 www 4949:
1.422 albertel 4950: .LC_data_table_dense {
4951: font-size: small;
4952: }
1.795 www 4953:
1.507 raeburn 4954: table.LC_nested_outer {
4955: border: 1px solid #000000;
1.589 raeburn 4956: border-collapse: collapse;
1.803 bisitz 4957: border-spacing: 0;
1.507 raeburn 4958: width: 100%;
4959: }
1.795 www 4960:
1.879 raeburn 4961: table.LC_innerpickbox,
1.507 raeburn 4962: table.LC_nested {
1.803 bisitz 4963: border: none;
1.589 raeburn 4964: border-collapse: collapse;
1.803 bisitz 4965: border-spacing: 0;
1.507 raeburn 4966: width: 100%;
4967: }
1.795 www 4968:
4969: table.LC_data_table tr th,
4970: table.LC_calendar tr th,
4971: table.LC_mail_list tr th,
1.879 raeburn 4972: table.LC_prior_tries tr th,
4973: table.LC_innerpickbox tr th {
1.349 albertel 4974: font-weight: bold;
4975: background-color: $data_table_head;
1.801 tempelho 4976: color:$fontmenu;
1.701 harmsja 4977: font-size:90%;
1.347 albertel 4978: }
1.795 www 4979:
1.879 raeburn 4980: table.LC_innerpickbox tr th,
4981: table.LC_innerpickbox tr td {
4982: vertical-align: top;
4983: }
4984:
1.711 raeburn 4985: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4986: background-color: #CCCCCC;
1.711 raeburn 4987: font-weight: bold;
4988: text-align: left;
4989: }
1.795 www 4990:
1.779 bisitz 4991: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 4992: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 4993: background-color: $data_table_light;
1.425 albertel 4994: padding: 2px;
1.900 bisitz 4995: vertical-align: top;
1.347 albertel 4996: }
1.795 www 4997:
1.610 albertel 4998: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 4999: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5000: background-color: $data_table_dark;
1.709 bisitz 5001: padding: 2px;
1.900 bisitz 5002: vertical-align: top;
1.347 albertel 5003: }
1.795 www 5004:
1.425 albertel 5005: table.LC_data_table tr.LC_data_table_highlight td {
5006: background-color: $data_table_darker;
5007: }
1.795 www 5008:
1.639 raeburn 5009: table.LC_data_table tr td.LC_leftcol_header {
5010: background-color: $data_table_head;
5011: font-weight: bold;
5012: }
1.795 www 5013:
1.451 albertel 5014: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5015: table.LC_nested tr.LC_empty_row td {
1.347 albertel 5016: background-color: #FFFFFF;
1.421 albertel 5017: font-weight: bold;
5018: font-style: italic;
5019: text-align: center;
5020: padding: 8px;
1.347 albertel 5021: }
1.795 www 5022:
1.890 droeschl 5023: table.LC_caption {
5024: }
5025:
1.507 raeburn 5026: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5027: padding: 4ex
5028: }
1.795 www 5029:
1.507 raeburn 5030: table.LC_nested_outer tr th {
5031: font-weight: bold;
1.801 tempelho 5032: color:$fontmenu;
1.507 raeburn 5033: background-color: $data_table_head;
1.701 harmsja 5034: font-size: small;
1.507 raeburn 5035: border-bottom: 1px solid #000000;
5036: }
1.795 www 5037:
1.507 raeburn 5038: table.LC_nested_outer tr td.LC_subheader {
5039: background-color: $data_table_head;
5040: font-weight: bold;
5041: font-size: small;
5042: border-bottom: 1px solid #000000;
5043: text-align: right;
1.451 albertel 5044: }
1.795 www 5045:
1.507 raeburn 5046: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5047: background-color: #CCCCCC;
1.451 albertel 5048: font-weight: bold;
5049: font-size: small;
1.507 raeburn 5050: text-align: center;
5051: }
1.795 www 5052:
1.589 raeburn 5053: table.LC_nested tr.LC_info_row td.LC_left_item,
5054: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5055: text-align: left;
1.451 albertel 5056: }
1.795 www 5057:
1.507 raeburn 5058: table.LC_nested td {
1.735 bisitz 5059: background-color: #FFFFFF;
1.451 albertel 5060: font-size: small;
1.507 raeburn 5061: }
1.795 www 5062:
1.507 raeburn 5063: table.LC_nested_outer tr th.LC_right_item,
5064: table.LC_nested tr.LC_info_row td.LC_right_item,
5065: table.LC_nested tr.LC_odd_row td.LC_right_item,
5066: table.LC_nested tr td.LC_right_item {
1.451 albertel 5067: text-align: right;
5068: }
5069:
1.507 raeburn 5070: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5071: background-color: #EEEEEE;
1.451 albertel 5072: }
5073:
1.473 raeburn 5074: table.LC_createuser {
5075: }
5076:
5077: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5078: font-size: small;
1.473 raeburn 5079: }
5080:
5081: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5082: background-color: #CCCCCC;
1.473 raeburn 5083: font-weight: bold;
5084: text-align: center;
5085: }
5086:
1.349 albertel 5087: table.LC_calendar {
5088: border: 1px solid #000000;
5089: border-collapse: collapse;
5090: }
1.795 www 5091:
1.349 albertel 5092: table.LC_calendar_pickdate {
5093: font-size: xx-small;
5094: }
1.795 www 5095:
1.349 albertel 5096: table.LC_calendar tr td {
5097: border: 1px solid #000000;
5098: vertical-align: top;
5099: }
1.795 www 5100:
1.349 albertel 5101: table.LC_calendar tr td.LC_calendar_day_empty {
5102: background-color: $data_table_dark;
5103: }
1.795 www 5104:
1.779 bisitz 5105: table.LC_calendar tr td.LC_calendar_day_current {
5106: background-color: $data_table_highlight;
1.777 tempelho 5107: }
1.795 www 5108:
1.349 albertel 5109: table.LC_mail_list tr.LC_mail_new {
5110: background-color: $mail_new;
5111: }
1.795 www 5112:
1.349 albertel 5113: table.LC_mail_list tr.LC_mail_new:hover {
5114: background-color: $mail_new_hover;
5115: }
1.795 www 5116:
5117: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5118: }
1.795 www 5119:
5120: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5121: }
1.795 www 5122:
1.349 albertel 5123: table.LC_mail_list tr.LC_mail_read {
5124: background-color: $mail_read;
5125: }
1.795 www 5126:
1.349 albertel 5127: table.LC_mail_list tr.LC_mail_read:hover {
5128: background-color: $mail_read_hover;
5129: }
1.795 www 5130:
1.349 albertel 5131: table.LC_mail_list tr.LC_mail_replied {
5132: background-color: $mail_replied;
5133: }
1.795 www 5134:
1.349 albertel 5135: table.LC_mail_list tr.LC_mail_replied:hover {
5136: background-color: $mail_replied_hover;
5137: }
1.795 www 5138:
1.349 albertel 5139: table.LC_mail_list tr.LC_mail_other {
5140: background-color: $mail_other;
5141: }
1.795 www 5142:
1.349 albertel 5143: table.LC_mail_list tr.LC_mail_other:hover {
5144: background-color: $mail_other_hover;
5145: }
1.494 raeburn 5146:
1.777 tempelho 5147: table.LC_data_table tr > td.LC_browser_file,
5148: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5149: background: #AAEE77;
1.389 albertel 5150: }
1.795 www 5151:
1.777 tempelho 5152: table.LC_data_table tr > td.LC_browser_file_locked,
5153: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5154: background: #FFAA99;
1.387 albertel 5155: }
1.795 www 5156:
1.777 tempelho 5157: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5158: background: #888888;
1.779 bisitz 5159: }
1.795 www 5160:
1.777 tempelho 5161: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5162: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5163: background: #F8F866;
1.777 tempelho 5164: }
1.795 www 5165:
1.696 bisitz 5166: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5167: background: #E0E8FF;
1.387 albertel 5168: }
1.696 bisitz 5169:
1.707 bisitz 5170: table.LC_data_table tr > td.LC_roles_is {
5171: /* background: #77FF77; */
5172: }
1.795 www 5173:
1.707 bisitz 5174: table.LC_data_table tr > td.LC_roles_future {
5175: background: #FFFF77;
5176: }
1.795 www 5177:
1.707 bisitz 5178: table.LC_data_table tr > td.LC_roles_will {
5179: background: #FFAA77;
5180: }
1.795 www 5181:
1.707 bisitz 5182: table.LC_data_table tr > td.LC_roles_expired {
5183: background: #FF7777;
5184: }
1.795 www 5185:
1.707 bisitz 5186: table.LC_data_table tr > td.LC_roles_will_not {
5187: background: #AAFF77;
5188: }
1.795 www 5189:
1.707 bisitz 5190: table.LC_data_table tr > td.LC_roles_selected {
5191: background: #11CC55;
5192: }
5193:
1.388 albertel 5194: span.LC_current_location {
1.701 harmsja 5195: font-size:larger;
1.388 albertel 5196: background: $pgbg;
5197: }
1.387 albertel 5198:
1.395 albertel 5199: span.LC_parm_menu_item {
5200: font-size: larger;
5201: }
1.795 www 5202:
1.395 albertel 5203: span.LC_parm_scope_all {
5204: color: red;
5205: }
1.795 www 5206:
1.395 albertel 5207: span.LC_parm_scope_folder {
5208: color: green;
5209: }
1.795 www 5210:
1.395 albertel 5211: span.LC_parm_scope_resource {
5212: color: orange;
5213: }
1.795 www 5214:
1.395 albertel 5215: span.LC_parm_part {
5216: color: blue;
5217: }
1.795 www 5218:
1.395 albertel 5219: span.LC_parm_folder, span.LC_parm_symb {
5220: font-size: x-small;
5221: font-family: $mono;
5222: color: #AAAAAA;
5223: }
5224:
1.795 www 5225: td.LC_parm_overview_level_menu,
5226: td.LC_parm_overview_map_menu,
5227: td.LC_parm_overview_parm_selectors,
5228: td.LC_parm_overview_restrictions {
1.396 albertel 5229: border: 1px solid black;
5230: border-collapse: collapse;
5231: }
1.795 www 5232:
1.396 albertel 5233: table.LC_parm_overview_restrictions td {
5234: border-width: 1px 4px 1px 4px;
5235: border-style: solid;
5236: border-color: $pgbg;
5237: text-align: center;
5238: }
1.795 www 5239:
1.396 albertel 5240: table.LC_parm_overview_restrictions th {
5241: background: $tabbg;
5242: border-width: 1px 4px 1px 4px;
5243: border-style: solid;
5244: border-color: $pgbg;
5245: }
1.795 www 5246:
1.398 albertel 5247: table#LC_helpmenu {
1.803 bisitz 5248: border: none;
1.398 albertel 5249: height: 55px;
1.803 bisitz 5250: border-spacing: 0;
1.398 albertel 5251: }
5252:
5253: table#LC_helpmenu fieldset legend {
5254: font-size: larger;
5255: }
1.795 www 5256:
1.397 albertel 5257: table#LC_helpmenu_links {
5258: width: 100%;
5259: border: 1px solid black;
5260: background: $pgbg;
1.803 bisitz 5261: padding: 0;
1.397 albertel 5262: border-spacing: 1px;
5263: }
1.795 www 5264:
1.397 albertel 5265: table#LC_helpmenu_links tr td {
5266: padding: 1px;
5267: background: $tabbg;
1.399 albertel 5268: text-align: center;
5269: font-weight: bold;
1.397 albertel 5270: }
1.396 albertel 5271:
1.795 www 5272: table#LC_helpmenu_links a:link,
5273: table#LC_helpmenu_links a:visited,
1.397 albertel 5274: table#LC_helpmenu_links a:active {
5275: text-decoration: none;
5276: color: $font;
5277: }
1.795 www 5278:
1.397 albertel 5279: table#LC_helpmenu_links a:hover {
5280: text-decoration: underline;
5281: color: $vlink;
5282: }
1.396 albertel 5283:
1.417 albertel 5284: .LC_chrt_popup_exists {
5285: border: 1px solid #339933;
5286: margin: -1px;
5287: }
1.795 www 5288:
1.417 albertel 5289: .LC_chrt_popup_up {
5290: border: 1px solid yellow;
5291: margin: -1px;
5292: }
1.795 www 5293:
1.417 albertel 5294: .LC_chrt_popup {
5295: border: 1px solid #8888FF;
5296: background: #CCCCFF;
5297: }
1.795 www 5298:
1.421 albertel 5299: table.LC_pick_box {
5300: border-collapse: separate;
5301: background: white;
5302: border: 1px solid black;
5303: border-spacing: 1px;
5304: }
1.795 www 5305:
1.421 albertel 5306: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5307: background: $sidebg;
1.421 albertel 5308: font-weight: bold;
1.900 bisitz 5309: text-align: left;
1.740 bisitz 5310: vertical-align: top;
1.421 albertel 5311: width: 184px;
5312: padding: 8px;
5313: }
1.795 www 5314:
1.579 raeburn 5315: table.LC_pick_box td.LC_pick_box_value {
5316: text-align: left;
5317: padding: 8px;
5318: }
1.795 www 5319:
1.579 raeburn 5320: table.LC_pick_box td.LC_pick_box_select {
5321: text-align: left;
5322: padding: 8px;
5323: }
1.795 www 5324:
1.424 albertel 5325: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5326: padding: 0;
1.421 albertel 5327: height: 1px;
5328: background: black;
5329: }
1.795 www 5330:
1.421 albertel 5331: table.LC_pick_box td.LC_pick_box_submit {
5332: text-align: right;
5333: }
1.795 www 5334:
1.579 raeburn 5335: table.LC_pick_box td.LC_evenrow_value {
5336: text-align: left;
5337: padding: 8px;
5338: background-color: $data_table_light;
5339: }
1.795 www 5340:
1.579 raeburn 5341: table.LC_pick_box td.LC_oddrow_value {
5342: text-align: left;
5343: padding: 8px;
5344: background-color: $data_table_light;
5345: }
1.795 www 5346:
1.579 raeburn 5347: span.LC_helpform_receipt_cat {
5348: font-weight: bold;
5349: }
1.795 www 5350:
1.424 albertel 5351: table.LC_group_priv_box {
5352: background: white;
5353: border: 1px solid black;
5354: border-spacing: 1px;
5355: }
1.795 www 5356:
1.424 albertel 5357: table.LC_group_priv_box td.LC_pick_box_title {
5358: background: $tabbg;
5359: font-weight: bold;
5360: text-align: right;
5361: width: 184px;
5362: }
1.795 www 5363:
1.424 albertel 5364: table.LC_group_priv_box td.LC_groups_fixed {
5365: background: $data_table_light;
5366: text-align: center;
5367: }
1.795 www 5368:
1.424 albertel 5369: table.LC_group_priv_box td.LC_groups_optional {
5370: background: $data_table_dark;
5371: text-align: center;
5372: }
1.795 www 5373:
1.424 albertel 5374: table.LC_group_priv_box td.LC_groups_functionality {
5375: background: $data_table_darker;
5376: text-align: center;
5377: font-weight: bold;
5378: }
1.795 www 5379:
1.424 albertel 5380: table.LC_group_priv td {
5381: text-align: left;
1.803 bisitz 5382: padding: 0;
1.424 albertel 5383: }
5384:
1.421 albertel 5385: table.LC_notify_front_page {
5386: background: white;
5387: border: 1px solid black;
5388: padding: 8px;
5389: }
1.795 www 5390:
1.421 albertel 5391: table.LC_notify_front_page td {
5392: padding: 8px;
5393: }
1.795 www 5394:
1.424 albertel 5395: .LC_navbuttons {
5396: margin: 2ex 0ex 2ex 0ex;
5397: }
1.795 www 5398:
1.423 albertel 5399: .LC_topic_bar {
5400: font-weight: bold;
5401: width: 100%;
5402: background: $tabbg;
5403: vertical-align: middle;
5404: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5405: padding: 3px;
1.423 albertel 5406: }
1.795 www 5407:
1.423 albertel 5408: .LC_topic_bar span {
5409: vertical-align: middle;
5410: }
1.795 www 5411:
1.423 albertel 5412: .LC_topic_bar img {
5413: vertical-align: bottom;
5414: }
1.795 www 5415:
1.423 albertel 5416: table.LC_course_group_status {
5417: margin: 20px;
5418: }
1.795 www 5419:
1.423 albertel 5420: table.LC_status_selector td {
5421: vertical-align: top;
5422: text-align: center;
1.424 albertel 5423: padding: 4px;
5424: }
1.795 www 5425:
1.599 albertel 5426: div.LC_feedback_link {
1.616 albertel 5427: clear: both;
1.829 kalberla 5428: background: $sidebg;
1.779 bisitz 5429: width: 100%;
1.829 kalberla 5430: padding-bottom: 10px;
5431: border: 1px $tabbg solid;
1.833 kalberla 5432: height: 22px;
5433: line-height: 22px;
5434: padding-top: 5px;
5435: }
5436:
5437: div.LC_feedback_link img {
5438: height: 22px;
1.867 kalberla 5439: vertical-align:middle;
1.829 kalberla 5440: }
5441:
5442: div.LC_feedback_link a{
5443: text-decoration: none;
1.489 raeburn 5444: }
1.795 www 5445:
1.867 kalberla 5446: div.LC_comblock {
5447: display:inline;
5448: color:$font;
5449: font-size:90%;
5450: }
5451:
5452: div.LC_feedback_link div.LC_comblock {
5453: padding-left:5px;
5454: }
5455:
5456: div.LC_feedback_link div.LC_comblock a {
5457: color:$font;
5458: }
5459:
1.489 raeburn 5460: span.LC_feedback_link {
1.858 bisitz 5461: /* background: $feedback_link_bg; */
1.599 albertel 5462: font-size: larger;
5463: }
1.795 www 5464:
1.599 albertel 5465: span.LC_message_link {
1.858 bisitz 5466: /* background: $feedback_link_bg; */
1.599 albertel 5467: font-size: larger;
5468: position: absolute;
5469: right: 1em;
1.489 raeburn 5470: }
1.421 albertel 5471:
1.515 albertel 5472: table.LC_prior_tries {
1.524 albertel 5473: border: 1px solid #000000;
5474: border-collapse: separate;
5475: border-spacing: 1px;
1.515 albertel 5476: }
1.523 albertel 5477:
1.515 albertel 5478: table.LC_prior_tries td {
1.524 albertel 5479: padding: 2px;
1.515 albertel 5480: }
1.523 albertel 5481:
5482: .LC_answer_correct {
1.795 www 5483: background: lightgreen;
5484: color: darkgreen;
5485: padding: 6px;
1.523 albertel 5486: }
1.795 www 5487:
1.523 albertel 5488: .LC_answer_charged_try {
1.797 www 5489: background: #FFAAAA;
1.795 www 5490: color: darkred;
5491: padding: 6px;
1.523 albertel 5492: }
1.795 www 5493:
1.779 bisitz 5494: .LC_answer_not_charged_try,
1.523 albertel 5495: .LC_answer_no_grade,
5496: .LC_answer_late {
1.795 www 5497: background: lightyellow;
1.523 albertel 5498: color: black;
1.795 www 5499: padding: 6px;
1.523 albertel 5500: }
1.795 www 5501:
1.523 albertel 5502: .LC_answer_previous {
1.795 www 5503: background: lightblue;
5504: color: darkblue;
5505: padding: 6px;
1.523 albertel 5506: }
1.795 www 5507:
1.779 bisitz 5508: .LC_answer_no_message {
1.777 tempelho 5509: background: #FFFFFF;
5510: color: black;
1.795 www 5511: padding: 6px;
1.779 bisitz 5512: }
1.795 www 5513:
1.779 bisitz 5514: .LC_answer_unknown {
5515: background: orange;
5516: color: black;
1.795 www 5517: padding: 6px;
1.777 tempelho 5518: }
1.795 www 5519:
1.529 albertel 5520: span.LC_prior_numerical,
5521: span.LC_prior_string,
5522: span.LC_prior_custom,
5523: span.LC_prior_reaction,
5524: span.LC_prior_math {
1.523 albertel 5525: font-family: monospace;
5526: white-space: pre;
5527: }
5528:
1.525 albertel 5529: span.LC_prior_string {
5530: font-family: monospace;
5531: white-space: pre;
5532: }
5533:
1.523 albertel 5534: table.LC_prior_option {
5535: width: 100%;
5536: border-collapse: collapse;
5537: }
1.795 www 5538:
5539: table.LC_prior_rank,
5540: table.LC_prior_match {
1.528 albertel 5541: border-collapse: collapse;
5542: }
1.795 www 5543:
1.528 albertel 5544: table.LC_prior_option tr td,
5545: table.LC_prior_rank tr td,
5546: table.LC_prior_match tr td {
1.524 albertel 5547: border: 1px solid #000000;
1.515 albertel 5548: }
5549:
1.855 bisitz 5550: .LC_nobreak {
1.544 albertel 5551: white-space: nowrap;
1.519 raeburn 5552: }
5553:
1.576 raeburn 5554: span.LC_cusr_emph {
5555: font-style: italic;
5556: }
5557:
1.633 raeburn 5558: span.LC_cusr_subheading {
5559: font-weight: normal;
5560: font-size: 85%;
5561: }
5562:
1.545 albertel 5563: table.LC_docs_documents {
5564: background: #BBBBBB;
1.803 bisitz 5565: border-width: 0;
1.545 albertel 5566: border-collapse: collapse;
5567: }
1.795 www 5568:
1.777 tempelho 5569: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5570: border: 2px solid black;
5571: padding: 4px;
1.777 tempelho 5572: }
1.795 www 5573:
1.861 bisitz 5574: div.LC_docs_entry_move {
1.859 bisitz 5575: border: 1px solid #BBBBBB;
1.545 albertel 5576: background: #DDDDDD;
1.861 bisitz 5577: width: 22px;
1.859 bisitz 5578: padding: 1px;
5579: margin: 0;
1.545 albertel 5580: }
5581:
1.861 bisitz 5582: table.LC_data_table tr > td.LC_docs_entry_commands,
5583: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5584: background: #DDDDDD;
5585: font-size: x-small;
5586: }
1.795 www 5587:
1.861 bisitz 5588: .LC_docs_entry_parameter {
5589: white-space: nowrap;
5590: }
5591:
1.544 albertel 5592: .LC_docs_copy {
1.545 albertel 5593: color: #000099;
1.544 albertel 5594: }
1.795 www 5595:
1.544 albertel 5596: .LC_docs_cut {
1.545 albertel 5597: color: #550044;
1.544 albertel 5598: }
1.795 www 5599:
1.544 albertel 5600: .LC_docs_rename {
1.545 albertel 5601: color: #009900;
1.544 albertel 5602: }
1.795 www 5603:
1.544 albertel 5604: .LC_docs_remove {
1.545 albertel 5605: color: #990000;
5606: }
5607:
1.547 albertel 5608: .LC_docs_reinit_warn,
5609: .LC_docs_ext_edit {
5610: font-size: x-small;
5611: }
5612:
1.545 albertel 5613: table.LC_docs_adddocs td,
5614: table.LC_docs_adddocs th {
5615: border: 1px solid #BBBBBB;
5616: padding: 4px;
5617: background: #DDDDDD;
1.543 albertel 5618: }
5619:
1.584 albertel 5620: table.LC_sty_begin {
5621: background: #BBFFBB;
5622: }
1.795 www 5623:
1.584 albertel 5624: table.LC_sty_end {
5625: background: #FFBBBB;
5626: }
5627:
1.589 raeburn 5628: table.LC_double_column {
1.803 bisitz 5629: border-width: 0;
1.589 raeburn 5630: border-collapse: collapse;
5631: width: 100%;
5632: padding: 2px;
5633: }
5634:
5635: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5636: top: 2px;
1.589 raeburn 5637: left: 2px;
5638: width: 47%;
5639: vertical-align: top;
5640: }
5641:
5642: table.LC_double_column tr td.LC_right_col {
5643: top: 2px;
1.779 bisitz 5644: right: 2px;
1.589 raeburn 5645: width: 47%;
5646: vertical-align: top;
5647: }
5648:
1.591 raeburn 5649: div.LC_left_float {
5650: float: left;
5651: padding-right: 5%;
1.597 albertel 5652: padding-bottom: 4px;
1.591 raeburn 5653: }
5654:
5655: div.LC_clear_float_header {
1.597 albertel 5656: padding-bottom: 2px;
1.591 raeburn 5657: }
5658:
5659: div.LC_clear_float_footer {
1.597 albertel 5660: padding-top: 10px;
1.591 raeburn 5661: clear: both;
5662: }
5663:
1.597 albertel 5664: div.LC_grade_show_user {
5665: margin-top: 20px;
5666: border: 1px solid black;
5667: }
1.795 www 5668:
1.597 albertel 5669: div.LC_grade_user_name {
5670: background: #DDDDEE;
5671: border-bottom: 1px solid black;
1.705 tempelho 5672: font-weight: bold;
5673: font-size: large;
1.597 albertel 5674: }
1.795 www 5675:
1.597 albertel 5676: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5677: background: #DDEEDD;
5678: }
5679:
5680: div.LC_grade_show_problem,
5681: div.LC_grade_submissions,
5682: div.LC_grade_message_center,
5683: div.LC_grade_info_links,
5684: div.LC_grade_assign {
5685: margin: 5px;
5686: width: 99%;
5687: background: #FFFFFF;
5688: }
1.795 www 5689:
1.597 albertel 5690: div.LC_grade_show_problem_header,
5691: div.LC_grade_submissions_header,
5692: div.LC_grade_message_center_header,
5693: div.LC_grade_assign_header {
1.705 tempelho 5694: font-weight: bold;
5695: font-size: large;
1.597 albertel 5696: }
1.795 www 5697:
1.597 albertel 5698: div.LC_grade_show_problem_problem,
5699: div.LC_grade_submissions_body,
5700: div.LC_grade_message_center_body,
5701: div.LC_grade_assign_body {
5702: border: 1px solid black;
5703: width: 99%;
5704: background: #FFFFFF;
5705: }
1.795 www 5706:
1.598 albertel 5707: span.LC_grade_check_note {
1.705 tempelho 5708: font-weight: normal;
5709: font-size: medium;
1.598 albertel 5710: display: inline;
5711: position: absolute;
5712: right: 1em;
5713: }
1.597 albertel 5714:
1.613 albertel 5715: table.LC_scantron_action {
5716: width: 100%;
5717: }
1.795 www 5718:
1.613 albertel 5719: table.LC_scantron_action tr th {
1.698 harmsja 5720: font-weight:bold;
5721: font-style:normal;
1.613 albertel 5722: }
1.795 www 5723:
1.779 bisitz 5724: .LC_edit_problem_header,
1.614 albertel 5725: div.LC_edit_problem_footer {
1.705 tempelho 5726: font-weight: normal;
5727: font-size: medium;
1.602 albertel 5728: margin: 2px;
1.600 albertel 5729: }
1.795 www 5730:
1.600 albertel 5731: div.LC_edit_problem_header,
1.602 albertel 5732: div.LC_edit_problem_header div,
1.614 albertel 5733: div.LC_edit_problem_footer,
5734: div.LC_edit_problem_footer div,
1.602 albertel 5735: div.LC_edit_problem_editxml_header,
5736: div.LC_edit_problem_editxml_header div {
1.600 albertel 5737: margin-top: 5px;
5738: }
1.795 www 5739:
1.600 albertel 5740: div.LC_edit_problem_header_title {
1.705 tempelho 5741: font-weight: bold;
5742: font-size: larger;
1.602 albertel 5743: background: $tabbg;
5744: padding: 3px;
5745: }
1.795 www 5746:
1.602 albertel 5747: table.LC_edit_problem_header_title {
1.705 tempelho 5748: font-size: larger;
5749: font-weight: bold;
1.602 albertel 5750: width: 100%;
5751: border-color: $pgbg;
5752: border-style: solid;
5753: border-width: $border;
1.600 albertel 5754: background: $tabbg;
1.602 albertel 5755: border-collapse: collapse;
1.803 bisitz 5756: padding: 0;
1.602 albertel 5757: }
5758:
5759: div.LC_edit_problem_discards {
5760: float: left;
5761: padding-bottom: 5px;
5762: }
1.795 www 5763:
1.602 albertel 5764: div.LC_edit_problem_saves {
5765: float: right;
5766: padding-bottom: 5px;
1.600 albertel 5767: }
1.795 www 5768:
1.679 riegler 5769: img.stift{
1.803 bisitz 5770: border-width: 0;
5771: vertical-align: middle;
1.677 riegler 5772: }
1.680 riegler 5773:
1.681 riegler 5774: table#LC_mainmenu{
5775: margin-top:10px;
5776: width:80%;
5777: }
5778:
1.680 riegler 5779: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5780: vertical-align: top;
5781: width: 45%;
5782: }
1.795 www 5783:
1.779 bisitz 5784: .LC_mainmenu_fieldset_category {
5785: color: $font;
5786: background: $pgbg;
5787: font-size: small;
5788: font-weight: bold;
1.777 tempelho 5789: }
1.795 www 5790:
1.716 raeburn 5791: div.LC_createcourse {
5792: margin: 10px 10px 10px 10px;
5793: }
5794:
1.693 droeschl 5795: /* ---- Remove when done ----
5796: # The following styles is part of the redesign of LON-CAPA and are
5797: # subject to change during this project.
5798: # Don't rely on their current functionality as they might be
5799: # changed or removed.
5800: # --------------------------*/
5801:
1.698 harmsja 5802: a:hover,
1.897 wenzelju 5803: ol.LC_primary_menu a:hover,
1.721 harmsja 5804: ol#LC_MenuBreadcrumbs a:hover,
5805: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5806: ul#LC_secondary_menu a:hover,
1.721 harmsja 5807: .LC_FormSectionClearButton input:hover
1.795 www 5808: ul.LC_TabContent li:hover a {
1.698 harmsja 5809: color:#BF2317;
1.904 ! droeschl 5810: text-decoration:none;
1.693 droeschl 5811: }
5812:
1.779 bisitz 5813: h1 {
1.813 bisitz 5814: padding: 0;
1.693 droeschl 5815: line-height:130%;
5816: }
1.698 harmsja 5817:
1.795 www 5818: h2,h3,h4,h5,h6 {
1.803 bisitz 5819: margin: 5px 0 5px 0;
5820: padding: 0;
1.721 harmsja 5821: line-height:130%;
1.693 droeschl 5822: }
1.795 www 5823:
5824: .LC_hcell {
1.698 harmsja 5825: padding:3px 15px 3px 15px;
1.803 bisitz 5826: margin: 0;
1.703 harmsja 5827: background-color:$tabbg;
1.801 tempelho 5828: color:$fontmenu;
1.779 bisitz 5829: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5830: }
1.795 www 5831:
1.840 bisitz 5832: .LC_Box > .LC_hcell {
1.847 tempelho 5833: margin: 0 -10px 10px -10px;
1.835 bisitz 5834: }
5835:
1.721 harmsja 5836: .LC_noBorder {
1.803 bisitz 5837: border: 0;
1.698 harmsja 5838: }
1.693 droeschl 5839:
1.761 tempelho 5840: .LC_Right {
5841: float: right;
1.803 bisitz 5842: margin: 0;
5843: padding: 0;
1.761 tempelho 5844: }
5845:
1.721 harmsja 5846: .LC_FormSectionClearButton input {
1.779 bisitz 5847: background-color:transparent;
1.803 bisitz 5848: border: none;
1.698 harmsja 5849: cursor:pointer;
5850: text-decoration:underline;
1.693 droeschl 5851: }
1.763 bisitz 5852:
5853: .LC_help_open_topic {
5854: color: #FFFFFF;
5855: background-color: #EEEEFF;
5856: margin: 1px;
5857: padding: 4px;
5858: border: 1px solid #000033;
5859: white-space: nowrap;
1.783 amueller 5860: /* vertical-align: middle; */
1.759 neumanie 5861: }
1.693 droeschl 5862:
1.698 harmsja 5863: dl,ul,div,fieldset {
1.803 bisitz 5864: margin: 10px 10px 10px 0;
1.806 bisitz 5865: /* overflow: hidden; */
1.693 droeschl 5866: }
1.795 www 5867:
1.838 bisitz 5868: fieldset > legend {
5869: font-weight: bold;
5870: padding: 0 5px 0 5px;
5871: }
5872:
1.813 bisitz 5873: #LC_nav_bar {
1.807 droeschl 5874: float: left;
1.852 droeschl 5875: margin: 0.2em 0 0 0;
1.807 droeschl 5876: }
5877:
1.813 bisitz 5878: #LC_nav_bar em{
1.807 droeschl 5879: font-weight: bold;
5880: font-style: normal;
5881: }
5882:
1.897 wenzelju 5883: ol.LC_primary_menu {
1.807 droeschl 5884: float: right;
1.852 droeschl 5885: margin: 0.2em 0 0 0;
1.807 droeschl 5886: }
5887:
1.852 droeschl 5888: ol#LC_PathBreadcrumbs {
1.803 bisitz 5889: margin: 0;
1.693 droeschl 5890: }
5891:
1.897 wenzelju 5892: ol.LC_primary_menu li {
1.693 droeschl 5893: display: inline;
1.803 bisitz 5894: padding: 5px 5px 0 10px;
1.693 droeschl 5895: vertical-align: top;
5896: }
5897:
1.897 wenzelju 5898: ol.LC_primary_menu li img {
1.693 droeschl 5899: vertical-align: bottom;
5900: }
5901:
1.897 wenzelju 5902: ol.LC_primary_menu a {
1.693 droeschl 5903: font-size: 90%;
5904: color: RGB(80, 80, 80);
5905: text-decoration: none;
5906: }
1.795 www 5907:
1.897 wenzelju 5908: ul#LC_secondary_menu {
1.807 droeschl 5909: clear: both;
1.808 droeschl 5910: color: $fontmenu;
5911: background: $tabbg;
5912: list-style: none;
5913: padding: 0;
5914: margin: 0;
5915: width: 100%;
5916: }
5917:
1.897 wenzelju 5918: ul#LC_secondary_menu li {
1.808 droeschl 5919: font-weight: bold;
5920: line-height: 1.8em;
5921: padding: 0 0.8em;
5922: border-right: 1px solid black;
5923: display: inline;
5924: vertical-align: middle;
1.807 droeschl 5925: }
5926:
1.847 tempelho 5927: ul.LC_TabContent {
1.721 harmsja 5928: display:block;
1.847 tempelho 5929: background: $sidebg;
1.858 bisitz 5930: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5931: list-style:none;
1.870 tempelho 5932: margin: 0 -10px;
1.803 bisitz 5933: padding: 0;
1.693 droeschl 5934: }
5935:
1.795 www 5936: ul.LC_TabContent li,
5937: ul.LC_TabContentBigger li {
1.741 harmsja 5938: float:left;
5939: }
1.795 www 5940:
1.897 wenzelju 5941: ul#LC_secondary_menu li a {
1.808 droeschl 5942: color: $fontmenu;
1.693 droeschl 5943: text-decoration: none;
5944: }
1.795 www 5945:
1.721 harmsja 5946: ul.LC_TabContent {
1.847 tempelho 5947: min-height:1.5em;
1.721 harmsja 5948: }
1.795 www 5949:
5950: ul.LC_TabContent li {
1.741 harmsja 5951: vertical-align:middle;
1.803 bisitz 5952: padding: 0 10px 0 10px;
1.745 ehlerst 5953: background-color:$tabbg;
5954: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5955: }
1.795 www 5956:
1.847 tempelho 5957: ul.LC_TabContent .right {
5958: float:right;
5959: }
5960:
1.795 www 5961: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5962: color:rgb(47,47,47);
5963: text-decoration:none;
5964: font-size:95%;
5965: font-weight:bold;
1.761 tempelho 5966: padding-right: 16px;
1.721 harmsja 5967: }
1.795 www 5968:
5969: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5970: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 5971: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 5972: padding-right: 16px;
1.744 ehlerst 5973: }
1.795 www 5974:
1.870 tempelho 5975: #maincoursedoc {
5976: clear:both;
5977: }
5978:
5979: ul.LC_TabContentBigger {
5980: display:block;
5981: list-style:none;
5982: padding: 0;
5983: }
5984:
1.795 www 5985: ul.LC_TabContentBigger li {
1.870 tempelho 5986: vertical-align:bottom;
5987: height: 30px;
5988: font-size:110%;
5989: font-weight:bold;
5990: color: #737373;
1.841 tempelho 5991: }
5992:
1.870 tempelho 5993:
5994: ul.LC_TabContentBigger li a {
5995: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
5996: height: 30px;
5997: line-height: 30px;
5998: text-align: center;
5999: display: block;
6000: text-decoration: none;
1.741 harmsja 6001: }
1.795 www 6002:
1.870 tempelho 6003: ul.LC_TabContentBigger li:hover a,
6004: ul.LC_TabContentBigger li.active a {
6005: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857 tempelho 6006: color:$font;
1.870 tempelho 6007: text-decoration: underline;
1.744 ehlerst 6008: }
1.795 www 6009:
1.870 tempelho 6010:
6011: ul.LC_TabContentBigger li b {
6012: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6013: display: block;
6014: float: left;
6015: padding: 0 30px;
6016: }
6017:
6018: ul.LC_TabContentBigger li:hover b,
6019: ul.LC_TabContentBigger li.active b {
6020: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6021: color:$font;
6022: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6023: }
1.693 droeschl 6024:
1.870 tempelho 6025:
1.862 bisitz 6026: ul.LC_CourseBreadcrumbs {
6027: background: $sidebg;
6028: line-height: 32px;
6029: padding-left: 10px;
6030: margin: 0 0 10px 0;
6031: list-style-position: inside;
6032:
6033: }
6034:
1.795 www 6035: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6036: ol#LC_PathBreadcrumbs {
1.693 droeschl 6037: padding-left: 10px;
1.819 tempelho 6038: margin: 0;
1.693 droeschl 6039: list-style-position: inside;
1.904 ! droeschl 6040: /* SD working here
! 6041: white-space: nowrap; */
1.693 droeschl 6042: }
6043:
1.795 www 6044: ol#LC_MenuBreadcrumbs li,
6045: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6046: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 6047: display: inline;
6048: white-space: nowrap;
1.904 ! droeschl 6049: /* SD working here
! 6050: white-space: normal; */
1.693 droeschl 6051: }
6052:
1.823 bisitz 6053: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6054: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 6055: text-decoration: none;
6056: font-size:90%;
6057: }
1.795 www 6058:
6059: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6060: text-decoration:none;
6061: font-size:100%;
6062: font-weight:bold;
1.693 droeschl 6063: }
1.795 www 6064:
1.840 bisitz 6065: .LC_Box {
1.835 bisitz 6066: border: solid 1px $lg_border_color;
6067: padding: 0 10px 10px 10px;
1.746 neumanie 6068: }
1.795 www 6069:
6070: .LC_AboutMe_Image {
1.747 neumanie 6071: float:left;
6072: margin-right:10px;
6073: }
1.795 www 6074:
6075: .LC_Clear_AboutMe_Image {
1.747 neumanie 6076: clear:left;
6077: }
1.795 www 6078:
1.721 harmsja 6079: dl.LC_ListStyleClean dt {
1.693 droeschl 6080: padding-right: 5px;
6081: display: table-header-group;
6082: }
6083:
1.721 harmsja 6084: dl.LC_ListStyleClean dd {
1.693 droeschl 6085: display: table-row;
6086: }
6087:
1.721 harmsja 6088: .LC_ListStyleClean,
6089: .LC_ListStyleSimple,
6090: .LC_ListStyleNormal,
1.777 tempelho 6091: .LC_ListStyle_Border,
1.795 www 6092: .LC_ListStyleSpecial {
1.693 droeschl 6093: /*display:block; */
6094: list-style-position: inside;
6095: list-style-type: none;
6096: overflow: hidden;
1.803 bisitz 6097: padding: 0;
1.693 droeschl 6098: }
6099:
1.721 harmsja 6100: .LC_ListStyleSimple li,
6101: .LC_ListStyleSimple dd,
6102: .LC_ListStyleNormal li,
6103: .LC_ListStyleNormal dd,
6104: .LC_ListStyleSpecial li,
1.795 www 6105: .LC_ListStyleSpecial dd {
1.803 bisitz 6106: margin: 0;
1.693 droeschl 6107: padding: 5px 5px 5px 10px;
6108: clear: both;
6109: }
6110:
1.721 harmsja 6111: .LC_ListStyleClean li,
6112: .LC_ListStyleClean dd {
1.803 bisitz 6113: padding-top: 0;
6114: padding-bottom: 0;
1.693 droeschl 6115: }
6116:
1.721 harmsja 6117: .LC_ListStyleSimple dd,
1.795 www 6118: .LC_ListStyleSimple li {
1.698 harmsja 6119: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6120: }
6121:
1.721 harmsja 6122: .LC_ListStyleSpecial li,
6123: .LC_ListStyleSpecial dd {
1.693 droeschl 6124: list-style-type: none;
6125: background-color: RGB(220, 220, 220);
6126: margin-bottom: 4px;
6127: }
6128:
1.721 harmsja 6129: table.LC_SimpleTable {
1.698 harmsja 6130: margin:5px;
6131: border:solid 1px $lg_border_color;
1.795 www 6132: }
1.693 droeschl 6133:
1.721 harmsja 6134: table.LC_SimpleTable tr {
1.803 bisitz 6135: padding: 0;
1.698 harmsja 6136: border:solid 1px $lg_border_color;
1.693 droeschl 6137: }
1.795 www 6138:
6139: table.LC_SimpleTable thead {
1.698 harmsja 6140: background:rgb(220,220,220);
1.693 droeschl 6141: }
6142:
1.721 harmsja 6143: div.LC_columnSection {
1.693 droeschl 6144: display: block;
6145: clear: both;
6146: overflow: hidden;
1.803 bisitz 6147: margin: 0;
1.693 droeschl 6148: }
6149:
1.721 harmsja 6150: div.LC_columnSection>* {
1.693 droeschl 6151: float: left;
1.803 bisitz 6152: margin: 10px 20px 10px 0;
1.747 neumanie 6153: overflow:hidden;
1.693 droeschl 6154: }
1.721 harmsja 6155:
1.694 tempelho 6156: .LC_loginpage_container {
6157: text-align:left;
6158: margin : 0 auto;
1.785 tempelho 6159: width:90%;
1.694 tempelho 6160: padding: 10px;
6161: height: auto;
1.712 muellerd 6162: background-color:#FFFFFF;
1.694 tempelho 6163: border:1px solid #CCCCCC;
6164: }
6165:
6166:
6167: .LC_loginpage_loginContainer {
6168: float:left;
1.712 muellerd 6169: width: 182px;
1.785 tempelho 6170: padding: 2px;
1.712 muellerd 6171: border:1px solid #CCCCCC;
6172: background-color:$loginbg;
1.694 tempelho 6173: }
6174:
1.795 www 6175: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6176: margin-top: 0;
1.712 muellerd 6177: display:block;
6178: background:$bgcol;
6179: color:$textcol;
6180: padding-left:5px;
6181: }
1.785 tempelho 6182:
1.694 tempelho 6183: .LC_loginpage_loginInfo {
6184: float:left;
1.785 tempelho 6185: width:182px;
1.694 tempelho 6186: border:1px solid #CCCCCC;
1.785 tempelho 6187: padding:2px;
1.712 muellerd 6188: }
6189:
1.694 tempelho 6190: .LC_loginpage_space {
1.754 droeschl 6191: clear: both;
6192: margin-bottom: 20px;
1.694 tempelho 6193: border-bottom: 1px solid #CCCCCC;
6194: }
6195:
1.785 tempelho 6196: .LC_loginpage_floatLeft {
6197: float: left;
6198: width: 200px;
6199: margin: 0;
6200: }
6201:
1.795 www 6202: table em {
1.754 droeschl 6203: font-weight: bold;
6204: font-style: normal;
1.748 schulted 6205: }
1.795 www 6206:
1.779 bisitz 6207: table.LC_tableBrowseRes,
1.795 www 6208: table.LC_tableOfContent {
1.769 schulted 6209: border:none;
1.858 bisitz 6210: border-spacing: 1px;
1.754 droeschl 6211: padding: 3px;
6212: background-color: #FFFFFF;
6213: font-size: 90%;
1.753 droeschl 6214: }
1.789 droeschl 6215:
6216: table.LC_tableOfContent{
6217: border-collapse: collapse;
6218: }
6219:
1.771 droeschl 6220: table.LC_tableBrowseRes a,
1.768 schulted 6221: table.LC_tableOfContent a {
1.771 droeschl 6222: background-color: transparent;
1.753 droeschl 6223: text-decoration: none;
6224: }
6225:
1.771 droeschl 6226: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6227: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6228: background-color: #EEEEEE;
1.753 droeschl 6229: }
6230:
1.795 www 6231: table.LC_tableOfContent img {
1.753 droeschl 6232: border: none;
6233: height: 1.3em;
6234: vertical-align: text-bottom;
6235: margin-right: 0.3em;
6236: }
1.757 schulted 6237:
1.795 www 6238: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6239: background-image:url(/res/adm/pages/open-first-problem.gif);
6240: }
6241:
1.795 www 6242: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6243: background-image:url(/res/adm/pages/start-navigation.gif);
6244: }
6245:
1.795 www 6246: a#LC_content_toolbar_closenav {
1.774 ehlerst 6247: background-image:url(/res/adm/pages/close-navigation.gif);
6248: }
6249:
1.795 www 6250: a#LC_content_toolbar_everything {
1.774 ehlerst 6251: background-image:url(/res/adm/pages/show-all.gif);
6252: }
6253:
1.795 www 6254: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6255: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6256: }
6257:
1.795 www 6258: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6259: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6260: }
6261:
1.795 www 6262: a#LC_content_toolbar_changefolder {
1.757 schulted 6263: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6264: }
6265:
1.795 www 6266: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6267: background-image:url(/res/adm/pages/open-all-folders.gif);
6268: }
6269:
1.795 www 6270: ul#LC_toolbar li a:hover {
1.757 schulted 6271: background-position: bottom center;
6272: }
6273:
1.795 www 6274: ul#LC_toolbar {
1.803 bisitz 6275: padding: 0;
1.757 schulted 6276: margin: 2px;
6277: list-style:none;
6278: position:relative;
6279: background-color:white;
6280: }
6281:
1.795 www 6282: ul#LC_toolbar li {
1.757 schulted 6283: border:1px solid white;
1.803 bisitz 6284: padding: 0;
1.757 schulted 6285: margin: 0;
1.795 www 6286: float: left;
1.767 droeschl 6287: display:inline;
1.757 schulted 6288: vertical-align:middle;
1.795 www 6289: }
1.757 schulted 6290:
1.783 amueller 6291:
1.795 www 6292: a.LC_toolbarItem {
1.767 droeschl 6293: display:block;
1.803 bisitz 6294: padding: 0;
6295: margin: 0;
1.757 schulted 6296: height: 32px;
6297: width: 32px;
1.779 bisitz 6298: color:white;
1.803 bisitz 6299: border: none;
1.757 schulted 6300: background-repeat:no-repeat;
6301: background-color:transparent;
6302: }
6303:
1.843 bisitz 6304: ul.LC_funclist li {
1.782 bisitz 6305: float: left;
6306: white-space: nowrap;
6307: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6308: margin: 0 15px 15px 10px;
1.782 bisitz 6309: }
6310:
1.757 schulted 6311:
1.343 albertel 6312: END
6313: }
6314:
1.306 albertel 6315: =pod
6316:
6317: =item * &headtag()
6318:
6319: Returns a uniform footer for LON-CAPA web pages.
6320:
1.307 albertel 6321: Inputs: $title - optional title for the head
6322: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6323: $args - optional arguments
1.319 albertel 6324: force_register - if is true call registerurl so the remote is
6325: informed
1.415 albertel 6326: redirect -> array ref of
6327: 1- seconds before redirect occurs
6328: 2- url to redirect to
6329: 3- whether the side effect should occur
1.315 albertel 6330: (side effect of setting
6331: $env{'internal.head.redirect'} to the url
6332: redirected too)
1.352 albertel 6333: domain -> force to color decorate a page for a specific
6334: domain
6335: function -> force usage of a specific rolish color scheme
6336: bgcolor -> override the default page bgcolor
1.460 albertel 6337: no_auto_mt_title
6338: -> prevent &mt()ing the title arg
1.464 albertel 6339:
1.306 albertel 6340: =cut
6341:
6342: sub headtag {
1.313 albertel 6343: my ($title,$head_extra,$args) = @_;
1.306 albertel 6344:
1.363 albertel 6345: my $function = $args->{'function'} || &get_users_function();
6346: my $domain = $args->{'domain'} || &determinedomain();
6347: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6348: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6349: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6350: #time(),
1.418 albertel 6351: $env{'environment.color.timestamp'},
1.363 albertel 6352: $function,$domain,$bgcolor);
6353:
1.369 www 6354: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6355:
1.308 albertel 6356: my $result =
6357: '<head>'.
1.461 albertel 6358: &font_settings();
1.319 albertel 6359:
1.461 albertel 6360: if (!$args->{'frameset'}) {
6361: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6362: }
1.319 albertel 6363: if ($args->{'force_register'}) {
6364: $result .= &Apache::lonmenu::registerurl(1);
6365: }
1.436 albertel 6366: if (!$args->{'no_nav_bar'}
6367: && !$args->{'only_body'}
6368: && !$args->{'frameset'}) {
6369: $result .= &help_menu_js();
6370: }
1.319 albertel 6371:
1.314 albertel 6372: if (ref($args->{'redirect'})) {
1.414 albertel 6373: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6374: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6375: if (!$inhibit_continue) {
6376: $env{'internal.head.redirect'} = $url;
6377: }
1.313 albertel 6378: $result.=<<ADDMETA
6379: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6380: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6381: ADDMETA
6382: }
1.306 albertel 6383: if (!defined($title)) {
6384: $title = 'The LearningOnline Network with CAPA';
6385: }
1.460 albertel 6386: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6387: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6388: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6389: .$head_extra;
1.306 albertel 6390: return $result;
6391: }
6392:
6393: =pod
6394:
1.340 albertel 6395: =item * &font_settings()
6396:
6397: Returns neccessary <meta> to set the proper encoding
6398:
6399: Inputs: none
6400:
6401: =cut
6402:
6403: sub font_settings {
6404: my $headerstring='';
1.647 www 6405: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6406: $headerstring.=
6407: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6408: }
6409: return $headerstring;
6410: }
6411:
1.341 albertel 6412: =pod
6413:
6414: =item * &xml_begin()
6415:
6416: Returns the needed doctype and <html>
6417:
6418: Inputs: none
6419:
6420: =cut
6421:
6422: sub xml_begin {
6423: my $output='';
6424:
1.592 albertel 6425: if ($env{'internal.start_page'}==1) {
6426: &Apache::lonhtmlcommon::init_htmlareafields();
6427: }
1.342 albertel 6428:
1.341 albertel 6429: if ($env{'browser.mathml'}) {
6430: $output='<?xml version="1.0"?>'
6431: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6432: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6433:
6434: # .'<!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">] >'
6435: .'<!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">'
6436: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6437: .'xmlns="http://www.w3.org/1999/xhtml">';
6438: } else {
1.849 bisitz 6439: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6440: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6441: }
6442: return $output;
6443: }
1.340 albertel 6444:
6445: =pod
6446:
1.306 albertel 6447: =item * &endheadtag()
6448:
6449: Returns a uniform </head> for LON-CAPA web pages.
6450:
6451: Inputs: none
6452:
6453: =cut
6454:
6455: sub endheadtag {
6456: return '</head>';
6457: }
6458:
6459: =pod
6460:
6461: =item * &head()
6462:
6463: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6464:
1.648 raeburn 6465: Inputs:
6466:
6467: =over 4
6468:
6469: $title - optional title for the page
6470:
6471: $head_extra - optional extra HTML to put inside the <head>
6472:
6473: =back
1.405 albertel 6474:
1.306 albertel 6475: =cut
6476:
6477: sub head {
1.325 albertel 6478: my ($title,$head_extra,$args) = @_;
6479: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6480: }
6481:
6482: =pod
6483:
6484: =item * &start_page()
6485:
6486: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6487:
1.648 raeburn 6488: Inputs:
6489:
6490: =over 4
6491:
6492: $title - optional title for the page
6493:
6494: $head_extra - optional extra HTML to incude inside the <head>
6495:
6496: $args - additional optional args supported are:
6497:
6498: =over 8
6499:
6500: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6501: arg on
1.814 bisitz 6502: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6503: add_entries -> additional attributes to add to the <body>
6504: domain -> force to color decorate a page for a
1.317 albertel 6505: specific domain
1.648 raeburn 6506: function -> force usage of a specific rolish color
1.317 albertel 6507: scheme
1.648 raeburn 6508: redirect -> see &headtag()
6509: bgcolor -> override the default page bg color
6510: js_ready -> return a string ready for being used in
1.317 albertel 6511: a javascript writeln
1.648 raeburn 6512: html_encode -> return a string ready for being used in
1.320 albertel 6513: a html attribute
1.648 raeburn 6514: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6515: $forcereg arg
1.648 raeburn 6516: frameset -> if true will start with a <frameset>
1.330 albertel 6517: rather than <body>
1.648 raeburn 6518: skip_phases -> hash ref of
1.338 albertel 6519: head -> skip the <html><head> generation
6520: body -> skip all <body> generation
1.648 raeburn 6521: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6522: 'Switch To Inline Menu' link
1.648 raeburn 6523: no_auto_mt_title -> prevent &mt()ing the title arg
6524: inherit_jsmath -> when creating popup window in a page,
6525: should it have jsmath forced on by the
6526: current page
1.867 kalberla 6527: bread_crumbs -> Array containing breadcrumbs
6528: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6529:
1.648 raeburn 6530: =back
1.460 albertel 6531:
1.648 raeburn 6532: =back
1.562 albertel 6533:
1.306 albertel 6534: =cut
6535:
6536: sub start_page {
1.309 albertel 6537: my ($title,$head_extra,$args) = @_;
1.318 albertel 6538: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6539: my %head_args;
1.352 albertel 6540: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6541: 'bgcolor','frameset','no_nav_bar','only_body',
6542: 'no_auto_mt_title') {
1.319 albertel 6543: if (defined($args->{$arg})) {
1.324 raeburn 6544: $head_args{$arg} = $args->{$arg};
1.319 albertel 6545: }
1.313 albertel 6546: }
1.319 albertel 6547:
1.315 albertel 6548: $env{'internal.start_page'}++;
1.338 albertel 6549: my $result;
6550: if (! exists($args->{'skip_phases'}{'head'}) ) {
6551: $result.=
1.341 albertel 6552: &xml_begin().
1.338 albertel 6553: &headtag($title,$head_extra,\%head_args).&endheadtag();
6554: }
6555:
6556: if (! exists($args->{'skip_phases'}{'body'}) ) {
6557: if ($args->{'frameset'}) {
6558: my $attr_string = &make_attr_string($args->{'force_register'},
6559: $args->{'add_entries'});
6560: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6561: } else {
6562: $result .=
6563: &bodytag($title,
6564: $args->{'function'}, $args->{'add_entries'},
6565: $args->{'only_body'}, $args->{'domain'},
6566: $args->{'force_register'}, $args->{'no_nav_bar'},
6567: $args->{'bgcolor'}, $args->{'no_inline_link'},
6568: $args);
6569: }
1.330 albertel 6570: }
1.338 albertel 6571:
1.315 albertel 6572: if ($args->{'js_ready'}) {
1.713 kaisler 6573: $result = &js_ready($result);
1.315 albertel 6574: }
1.320 albertel 6575: if ($args->{'html_encode'}) {
1.713 kaisler 6576: $result = &html_encode($result);
6577: }
6578:
1.813 bisitz 6579: # Preparation for new and consistent functionlist at top of screen
6580: # if ($args->{'functionlist'}) {
6581: # $result .= &build_functionlist();
6582: #}
6583:
6584: # Don't add anything more if only_body wanted
6585: return $result if $args->{'only_body'};
6586:
6587: #Breadcrumbs
1.758 kaisler 6588: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6589: &Apache::lonhtmlcommon::clear_breadcrumbs();
6590: #if any br links exists, add them to the breadcrumbs
6591: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6592: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6593: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6594: }
6595: }
6596:
6597: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6598: if(exists($args->{'bread_crumbs_component'})){
6599: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6600: }else{
6601: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6602: }
1.320 albertel 6603: }
1.315 albertel 6604: return $result;
1.306 albertel 6605: }
6606:
1.330 albertel 6607:
1.306 albertel 6608: =pod
6609:
6610: =item * &head()
6611:
6612: Returns a complete </body></html> section for LON-CAPA web pages.
6613:
1.315 albertel 6614: Inputs: $args - additional optional args supported are:
6615: js_ready -> return a string ready for being used in
6616: a javascript writeln
1.320 albertel 6617: html_encode -> return a string ready for being used in
6618: a html attribute
1.330 albertel 6619: frameset -> if true will start with a <frameset>
6620: rather than <body>
1.493 albertel 6621: dicsussion -> if true will get discussion from
6622: lonxml::xmlend
6623: (you can pass the target and parser arguments
6624: through optional 'target' and 'parser' args
6625: to this routine)
1.306 albertel 6626:
6627: =cut
6628:
6629: sub end_page {
1.315 albertel 6630: my ($args) = @_;
6631: $env{'internal.end_page'}++;
1.330 albertel 6632: my $result;
1.335 albertel 6633: if ($args->{'discussion'}) {
6634: my ($target,$parser);
6635: if (ref($args->{'discussion'})) {
6636: ($target,$parser) =($args->{'discussion'}{'target'},
6637: $args->{'discussion'}{'parser'});
6638: }
6639: $result .= &Apache::lonxml::xmlend($target,$parser);
6640: }
6641:
1.330 albertel 6642: if ($args->{'frameset'}) {
6643: $result .= '</frameset>';
6644: } else {
1.635 raeburn 6645: $result .= &endbodytag($args);
1.330 albertel 6646: }
6647: $result .= "\n</html>";
6648:
1.315 albertel 6649: if ($args->{'js_ready'}) {
1.317 albertel 6650: $result = &js_ready($result);
1.315 albertel 6651: }
1.335 albertel 6652:
1.320 albertel 6653: if ($args->{'html_encode'}) {
6654: $result = &html_encode($result);
6655: }
1.335 albertel 6656:
1.315 albertel 6657: return $result;
6658: }
6659:
1.320 albertel 6660: sub html_encode {
6661: my ($result) = @_;
6662:
1.322 albertel 6663: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6664:
6665: return $result;
6666: }
1.317 albertel 6667: sub js_ready {
6668: my ($result) = @_;
6669:
1.323 albertel 6670: $result =~ s/[\n\r]/ /xmsg;
6671: $result =~ s/\\/\\\\/xmsg;
6672: $result =~ s/'/\\'/xmsg;
1.372 albertel 6673: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6674:
6675: return $result;
6676: }
6677:
1.315 albertel 6678: sub validate_page {
6679: if ( exists($env{'internal.start_page'})
1.316 albertel 6680: && $env{'internal.start_page'} > 1) {
6681: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6682: $env{'internal.start_page'}.' '.
1.316 albertel 6683: $ENV{'request.filename'});
1.315 albertel 6684: }
6685: if ( exists($env{'internal.end_page'})
1.316 albertel 6686: && $env{'internal.end_page'} > 1) {
6687: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6688: $env{'internal.end_page'}.' '.
1.316 albertel 6689: $env{'request.filename'});
1.315 albertel 6690: }
6691: if ( exists($env{'internal.start_page'})
6692: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6693: &Apache::lonnet::logthis('start_page called without end_page '.
6694: $env{'request.filename'});
1.315 albertel 6695: }
6696: if ( ! exists($env{'internal.start_page'})
6697: && exists($env{'internal.end_page'})) {
1.316 albertel 6698: &Apache::lonnet::logthis('end_page called without start_page'.
6699: $env{'request.filename'});
1.315 albertel 6700: }
1.306 albertel 6701: }
1.315 albertel 6702:
1.318 albertel 6703: sub simple_error_page {
6704: my ($r,$title,$msg) = @_;
6705: my $page =
6706: &Apache::loncommon::start_page($title).
6707: &mt($msg).
6708: &Apache::loncommon::end_page();
6709: if (ref($r)) {
6710: $r->print($page);
1.327 albertel 6711: return;
1.318 albertel 6712: }
6713: return $page;
6714: }
1.347 albertel 6715:
6716: {
1.610 albertel 6717: my @row_count;
1.347 albertel 6718: sub start_data_table {
1.422 albertel 6719: my ($add_class) = @_;
6720: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6721: unshift(@row_count,0);
1.422 albertel 6722: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6723: }
6724:
6725: sub end_data_table {
1.610 albertel 6726: shift(@row_count);
1.389 albertel 6727: return '</table>'."\n";;
1.347 albertel 6728: }
6729:
6730: sub start_data_table_row {
1.422 albertel 6731: my ($add_class) = @_;
1.610 albertel 6732: $row_count[0]++;
6733: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6734: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 6735: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6736: }
1.471 banghart 6737:
6738: sub continue_data_table_row {
6739: my ($add_class) = @_;
1.610 albertel 6740: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6741: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 6742: return '<tr class="'.$css_class.'">'."\n";;
6743: }
1.347 albertel 6744:
6745: sub end_data_table_row {
1.389 albertel 6746: return '</tr>'."\n";;
1.347 albertel 6747: }
1.367 www 6748:
1.421 albertel 6749: sub start_data_table_empty_row {
1.707 bisitz 6750: # $row_count[0]++;
1.421 albertel 6751: return '<tr class="LC_empty_row" >'."\n";;
6752: }
6753:
6754: sub end_data_table_empty_row {
6755: return '</tr>'."\n";;
6756: }
6757:
1.367 www 6758: sub start_data_table_header_row {
1.389 albertel 6759: return '<tr class="LC_header_row">'."\n";;
1.367 www 6760: }
6761:
6762: sub end_data_table_header_row {
1.389 albertel 6763: return '</tr>'."\n";;
1.367 www 6764: }
1.890 droeschl 6765:
6766: sub data_table_caption {
6767: my $caption = shift;
6768: return "<caption class=\"LC_caption\">$caption</caption>";
6769: }
1.347 albertel 6770: }
6771:
1.548 albertel 6772: =pod
6773:
6774: =item * &inhibit_menu_check($arg)
6775:
6776: Checks for a inhibitmenu state and generates output to preserve it
6777:
6778: Inputs: $arg - can be any of
6779: - undef - in which case the return value is a string
6780: to add into arguments list of a uri
6781: - 'input' - in which case the return value is a HTML
6782: <form> <input> field of type hidden to
6783: preserve the value
6784: - a url - in which case the return value is the url with
6785: the neccesary cgi args added to preserve the
6786: inhibitmenu state
6787: - a ref to a url - no return value, but the string is
6788: updated to include the neccessary cgi
6789: args to preserve the inhibitmenu state
6790:
6791: =cut
6792:
6793: sub inhibit_menu_check {
6794: my ($arg) = @_;
6795: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6796: if ($arg eq 'input') {
6797: if ($env{'form.inhibitmenu'}) {
6798: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6799: } else {
6800: return
6801: }
6802: }
6803: if ($env{'form.inhibitmenu'}) {
6804: if (ref($arg)) {
6805: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6806: } elsif ($arg eq '') {
6807: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6808: } else {
6809: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6810: }
6811: }
6812: if (!ref($arg)) {
6813: return $arg;
6814: }
6815: }
6816:
1.251 albertel 6817: ###############################################
1.182 matthew 6818:
6819: =pod
6820:
1.549 albertel 6821: =back
6822:
6823: =head1 User Information Routines
6824:
6825: =over 4
6826:
1.405 albertel 6827: =item * &get_users_function()
1.182 matthew 6828:
6829: Used by &bodytag to determine the current users primary role.
6830: Returns either 'student','coordinator','admin', or 'author'.
6831:
6832: =cut
6833:
6834: ###############################################
6835: sub get_users_function {
1.815 tempelho 6836: my $function = 'norole';
1.818 tempelho 6837: if ($env{'request.role'}=~/^(st)/) {
6838: $function='student';
6839: }
1.258 albertel 6840: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6841: $function='coordinator';
6842: }
1.258 albertel 6843: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6844: $function='admin';
6845: }
1.826 bisitz 6846: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6847: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6848: $function='author';
6849: }
6850: return $function;
1.54 www 6851: }
1.99 www 6852:
6853: ###############################################
6854:
1.233 raeburn 6855: =pod
6856:
1.821 raeburn 6857: =item * &show_course()
6858:
6859: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6860: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6861:
6862: Inputs:
6863: None
6864:
6865: Outputs:
6866: Scalar: 1 if 'Course' to be used, 0 otherwise.
6867:
6868: =cut
6869:
6870: ###############################################
6871: sub show_course {
6872: my $course = !$env{'user.adv'};
6873: if (!$env{'user.adv'}) {
6874: foreach my $env (keys(%env)) {
6875: next if ($env !~ m/^user\.priv\./);
6876: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6877: $course = 0;
6878: last;
6879: }
6880: }
6881: }
6882: return $course;
6883: }
6884:
6885: ###############################################
6886:
6887: =pod
6888:
1.542 raeburn 6889: =item * &check_user_status()
1.274 raeburn 6890:
6891: Determines current status of supplied role for a
6892: specific user. Roles can be active, previous or future.
6893:
6894: Inputs:
6895: user's domain, user's username, course's domain,
1.375 raeburn 6896: course's number, optional section ID.
1.274 raeburn 6897:
6898: Outputs:
6899: role status: active, previous or future.
6900:
6901: =cut
6902:
6903: sub check_user_status {
1.412 raeburn 6904: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6905: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6906: my @uroles = keys %userinfo;
6907: my $srchstr;
6908: my $active_chk = 'none';
1.412 raeburn 6909: my $now = time;
1.274 raeburn 6910: if (@uroles > 0) {
1.412 raeburn 6911: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6912: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6913: } else {
1.412 raeburn 6914: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6915: }
6916: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6917: my $role_end = 0;
6918: my $role_start = 0;
6919: $active_chk = 'active';
1.412 raeburn 6920: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6921: $role_end = $1;
6922: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6923: $role_start = $1;
1.274 raeburn 6924: }
6925: }
6926: if ($role_start > 0) {
1.412 raeburn 6927: if ($now < $role_start) {
1.274 raeburn 6928: $active_chk = 'future';
6929: }
6930: }
6931: if ($role_end > 0) {
1.412 raeburn 6932: if ($now > $role_end) {
1.274 raeburn 6933: $active_chk = 'previous';
6934: }
6935: }
6936: }
6937: }
6938: return $active_chk;
6939: }
6940:
6941: ###############################################
6942:
6943: =pod
6944:
1.405 albertel 6945: =item * &get_sections()
1.233 raeburn 6946:
6947: Determines all the sections for a course including
6948: sections with students and sections containing other roles.
1.419 raeburn 6949: Incoming parameters:
6950:
6951: 1. domain
6952: 2. course number
6953: 3. reference to array containing roles for which sections should
6954: be gathered (optional).
6955: 4. reference to array containing status types for which sections
6956: should be gathered (optional).
6957:
6958: If the third argument is undefined, sections are gathered for any role.
6959: If the fourth argument is undefined, sections are gathered for any status.
6960: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6961:
1.374 raeburn 6962: Returns section hash (keys are section IDs, values are
6963: number of users in each section), subject to the
1.419 raeburn 6964: optional roles filter, optional status filter
1.233 raeburn 6965:
6966: =cut
6967:
6968: ###############################################
6969: sub get_sections {
1.419 raeburn 6970: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6971: if (!defined($cdom) || !defined($cnum)) {
6972: my $cid = $env{'request.course.id'};
6973:
6974: return if (!defined($cid));
6975:
6976: $cdom = $env{'course.'.$cid.'.domain'};
6977: $cnum = $env{'course.'.$cid.'.num'};
6978: }
6979:
6980: my %sectioncount;
1.419 raeburn 6981: my $now = time;
1.240 albertel 6982:
1.366 albertel 6983: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6984: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6985: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6986: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6987: my $start_index = &Apache::loncoursedata::CL_START();
6988: my $end_index = &Apache::loncoursedata::CL_END();
6989: my $status;
1.366 albertel 6990: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6991: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6992: $data->[$status_index],
6993: $data->[$start_index],
6994: $data->[$end_index]);
6995: if ($stu_status eq 'Active') {
6996: $status = 'active';
6997: } elsif ($end < $now) {
6998: $status = 'previous';
6999: } elsif ($start > $now) {
7000: $status = 'future';
7001: }
7002: if ($section ne '-1' && $section !~ /^\s*$/) {
7003: if ((!defined($possible_status)) || (($status ne '') &&
7004: (grep/^\Q$status\E$/,@{$possible_status}))) {
7005: $sectioncount{$section}++;
7006: }
1.240 albertel 7007: }
7008: }
7009: }
7010: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7011: foreach my $user (sort(keys(%courseroles))) {
7012: if ($user !~ /^(\w{2})/) { next; }
7013: my ($role) = ($user =~ /^(\w{2})/);
7014: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7015: my ($section,$status);
1.240 albertel 7016: if ($role eq 'cr' &&
7017: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7018: $section=$1;
7019: }
7020: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7021: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7022: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7023: if ($end == -1 && $start == -1) {
7024: next; #deleted role
7025: }
7026: if (!defined($possible_status)) {
7027: $sectioncount{$section}++;
7028: } else {
7029: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7030: $status = 'active';
7031: } elsif ($end < $now) {
7032: $status = 'future';
7033: } elsif ($start > $now) {
7034: $status = 'previous';
7035: }
7036: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7037: $sectioncount{$section}++;
7038: }
7039: }
1.233 raeburn 7040: }
1.366 albertel 7041: return %sectioncount;
1.233 raeburn 7042: }
7043:
1.274 raeburn 7044: ###############################################
1.294 raeburn 7045:
7046: =pod
1.405 albertel 7047:
7048: =item * &get_course_users()
7049:
1.275 raeburn 7050: Retrieves usernames:domains for users in the specified course
7051: with specific role(s), and access status.
7052:
7053: Incoming parameters:
1.277 albertel 7054: 1. course domain
7055: 2. course number
7056: 3. access status: users must have - either active,
1.275 raeburn 7057: previous, future, or all.
1.277 albertel 7058: 4. reference to array of permissible roles
1.288 raeburn 7059: 5. reference to array of section restrictions (optional)
7060: 6. reference to results object (hash of hashes).
7061: 7. reference to optional userdata hash
1.609 raeburn 7062: 8. reference to optional statushash
1.630 raeburn 7063: 9. flag if privileged users (except those set to unhide in
7064: course settings) should be excluded
1.609 raeburn 7065: Keys of top level results hash are roles.
1.275 raeburn 7066: Keys of inner hashes are username:domain, with
7067: values set to access type.
1.288 raeburn 7068: Optional userdata hash returns an array with arguments in the
7069: same order as loncoursedata::get_classlist() for student data.
7070:
1.609 raeburn 7071: Optional statushash returns
7072:
1.288 raeburn 7073: Entries for end, start, section and status are blank because
7074: of the possibility of multiple values for non-student roles.
7075:
1.275 raeburn 7076: =cut
1.405 albertel 7077:
1.275 raeburn 7078: ###############################################
1.405 albertel 7079:
1.275 raeburn 7080: sub get_course_users {
1.630 raeburn 7081: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7082: my %idx = ();
1.419 raeburn 7083: my %seclists;
1.288 raeburn 7084:
7085: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7086: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7087: $idx{end} = &Apache::loncoursedata::CL_END();
7088: $idx{start} = &Apache::loncoursedata::CL_START();
7089: $idx{id} = &Apache::loncoursedata::CL_ID();
7090: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7091: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7092: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7093:
1.290 albertel 7094: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7095: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7096: my $now = time;
1.277 albertel 7097: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7098: my $match = 0;
1.412 raeburn 7099: my $secmatch = 0;
1.419 raeburn 7100: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7101: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7102: if ($section eq '') {
7103: $section = 'none';
7104: }
1.291 albertel 7105: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7106: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7107: $secmatch = 1;
7108: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7109: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7110: $secmatch = 1;
7111: }
7112: } else {
1.419 raeburn 7113: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7114: $secmatch = 1;
7115: }
1.290 albertel 7116: }
1.412 raeburn 7117: if (!$secmatch) {
7118: next;
7119: }
1.419 raeburn 7120: }
1.275 raeburn 7121: if (defined($$types{'active'})) {
1.288 raeburn 7122: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7123: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7124: $match = 1;
1.275 raeburn 7125: }
7126: }
7127: if (defined($$types{'previous'})) {
1.609 raeburn 7128: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7129: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7130: $match = 1;
1.275 raeburn 7131: }
7132: }
7133: if (defined($$types{'future'})) {
1.609 raeburn 7134: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7135: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7136: $match = 1;
1.275 raeburn 7137: }
7138: }
1.609 raeburn 7139: if ($match) {
7140: push(@{$seclists{$student}},$section);
7141: if (ref($userdata) eq 'HASH') {
7142: $$userdata{$student} = $$classlist{$student};
7143: }
7144: if (ref($statushash) eq 'HASH') {
7145: $statushash->{$student}{'st'}{$section} = $status;
7146: }
1.288 raeburn 7147: }
1.275 raeburn 7148: }
7149: }
1.412 raeburn 7150: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7151: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7152: my $now = time;
1.609 raeburn 7153: my %displaystatus = ( previous => 'Expired',
7154: active => 'Active',
7155: future => 'Future',
7156: );
1.630 raeburn 7157: my %nothide;
7158: if ($hidepriv) {
7159: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7160: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7161: if ($user !~ /:/) {
7162: $nothide{join(':',split(/[\@]/,$user))}=1;
7163: } else {
7164: $nothide{$user} = 1;
7165: }
7166: }
7167: }
1.439 raeburn 7168: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7169: my $match = 0;
1.412 raeburn 7170: my $secmatch = 0;
1.439 raeburn 7171: my $status;
1.412 raeburn 7172: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7173: $user =~ s/:$//;
1.439 raeburn 7174: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7175: if ($end == -1 || $start == -1) {
7176: next;
7177: }
7178: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7179: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7180: my ($uname,$udom) = split(/:/,$user);
7181: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7182: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7183: $secmatch = 1;
7184: } elsif ($usec eq '') {
1.420 albertel 7185: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7186: $secmatch = 1;
7187: }
7188: } else {
7189: if (grep(/^\Q$usec\E$/,@{$sections})) {
7190: $secmatch = 1;
7191: }
7192: }
7193: if (!$secmatch) {
7194: next;
7195: }
1.288 raeburn 7196: }
1.419 raeburn 7197: if ($usec eq '') {
7198: $usec = 'none';
7199: }
1.275 raeburn 7200: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7201: if ($hidepriv) {
7202: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7203: (!$nothide{$uname.':'.$udom})) {
7204: next;
7205: }
7206: }
1.503 raeburn 7207: if ($end > 0 && $end < $now) {
1.439 raeburn 7208: $status = 'previous';
7209: } elsif ($start > $now) {
7210: $status = 'future';
7211: } else {
7212: $status = 'active';
7213: }
1.277 albertel 7214: foreach my $type (keys(%{$types})) {
1.275 raeburn 7215: if ($status eq $type) {
1.420 albertel 7216: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7217: push(@{$$users{$role}{$user}},$type);
7218: }
1.288 raeburn 7219: $match = 1;
7220: }
7221: }
1.419 raeburn 7222: if (($match) && (ref($userdata) eq 'HASH')) {
7223: if (!exists($$userdata{$uname.':'.$udom})) {
7224: &get_user_info($udom,$uname,\%idx,$userdata);
7225: }
1.420 albertel 7226: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7227: push(@{$seclists{$uname.':'.$udom}},$usec);
7228: }
1.609 raeburn 7229: if (ref($statushash) eq 'HASH') {
7230: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7231: }
1.275 raeburn 7232: }
7233: }
7234: }
7235: }
1.290 albertel 7236: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7237: if ((defined($cdom)) && (defined($cnum))) {
7238: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7239: if ( defined($csettings{'internal.courseowner'}) ) {
7240: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7241: next if ($owner eq '');
7242: my ($ownername,$ownerdom);
7243: if ($owner =~ /^([^:]+):([^:]+)$/) {
7244: $ownername = $1;
7245: $ownerdom = $2;
7246: } else {
7247: $ownername = $owner;
7248: $ownerdom = $cdom;
7249: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7250: }
7251: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7252: if (defined($userdata) &&
1.609 raeburn 7253: !exists($$userdata{$owner})) {
7254: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7255: if (!grep(/^none$/,@{$seclists{$owner}})) {
7256: push(@{$seclists{$owner}},'none');
7257: }
7258: if (ref($statushash) eq 'HASH') {
7259: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7260: }
1.290 albertel 7261: }
1.279 raeburn 7262: }
7263: }
7264: }
1.419 raeburn 7265: foreach my $user (keys(%seclists)) {
7266: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7267: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7268: }
1.275 raeburn 7269: }
7270: return;
7271: }
7272:
1.288 raeburn 7273: sub get_user_info {
7274: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7275: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7276: &plainname($uname,$udom,'lastname');
1.291 albertel 7277: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7278: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7279: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7280: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7281: return;
7282: }
1.275 raeburn 7283:
1.472 raeburn 7284: ###############################################
7285:
7286: =pod
7287:
7288: =item * &get_user_quota()
7289:
7290: Retrieves quota assigned for storage of portfolio files for a user
7291:
7292: Incoming parameters:
7293: 1. user's username
7294: 2. user's domain
7295:
7296: Returns:
1.536 raeburn 7297: 1. Disk quota (in Mb) assigned to student.
7298: 2. (Optional) Type of setting: custom or default
7299: (individually assigned or default for user's
7300: institutional status).
7301: 3. (Optional) - User's institutional status (e.g., faculty, staff
7302: or student - types as defined in localenroll::inst_usertypes
7303: for user's domain, which determines default quota for user.
7304: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7305:
7306: If a value has been stored in the user's environment,
1.536 raeburn 7307: it will return that, otherwise it returns the maximal default
7308: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7309:
7310: =cut
7311:
7312: ###############################################
7313:
7314:
7315: sub get_user_quota {
7316: my ($uname,$udom) = @_;
1.536 raeburn 7317: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7318: if (!defined($udom)) {
7319: $udom = $env{'user.domain'};
7320: }
7321: if (!defined($uname)) {
7322: $uname = $env{'user.name'};
7323: }
7324: if (($udom eq '' || $uname eq '') ||
7325: ($udom eq 'public') && ($uname eq 'public')) {
7326: $quota = 0;
1.536 raeburn 7327: $quotatype = 'default';
7328: $defquota = 0;
1.472 raeburn 7329: } else {
1.536 raeburn 7330: my $inststatus;
1.472 raeburn 7331: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7332: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7333: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7334: } else {
1.536 raeburn 7335: my %userenv =
7336: &Apache::lonnet::get('environment',['portfolioquota',
7337: 'inststatus'],$udom,$uname);
1.472 raeburn 7338: my ($tmp) = keys(%userenv);
7339: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7340: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7341: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7342: } else {
7343: undef(%userenv);
7344: }
7345: }
1.536 raeburn 7346: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7347: if ($quota eq '') {
1.536 raeburn 7348: $quota = $defquota;
7349: $quotatype = 'default';
7350: } else {
7351: $quotatype = 'custom';
1.472 raeburn 7352: }
7353: }
1.536 raeburn 7354: if (wantarray) {
7355: return ($quota,$quotatype,$settingstatus,$defquota);
7356: } else {
7357: return $quota;
7358: }
1.472 raeburn 7359: }
7360:
7361: ###############################################
7362:
7363: =pod
7364:
7365: =item * &default_quota()
7366:
1.536 raeburn 7367: Retrieves default quota assigned for storage of user portfolio files,
7368: given an (optional) user's institutional status.
1.472 raeburn 7369:
7370: Incoming parameters:
7371: 1. domain
1.536 raeburn 7372: 2. (Optional) institutional status(es). This is a : separated list of
7373: status types (e.g., faculty, staff, student etc.)
7374: which apply to the user for whom the default is being retrieved.
7375: If the institutional status string in undefined, the domain
7376: default quota will be returned.
1.472 raeburn 7377:
7378: Returns:
7379: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7380: 2. (Optional) institutional type which determined the value of the
7381: default quota.
1.472 raeburn 7382:
7383: If a value has been stored in the domain's configuration db,
7384: it will return that, otherwise it returns 20 (for backwards
7385: compatibility with domains which have not set up a configuration
7386: db file; the original statically defined portfolio quota was 20 Mb).
7387:
1.536 raeburn 7388: If the user's status includes multiple types (e.g., staff and student),
7389: the largest default quota which applies to the user determines the
7390: default quota returned.
7391:
1.780 raeburn 7392: =back
7393:
1.472 raeburn 7394: =cut
7395:
7396: ###############################################
7397:
7398:
7399: sub default_quota {
1.536 raeburn 7400: my ($udom,$inststatus) = @_;
7401: my ($defquota,$settingstatus);
7402: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7403: ['quotas'],$udom);
7404: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7405: if ($inststatus ne '') {
1.765 raeburn 7406: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7407: foreach my $item (@statuses) {
1.711 raeburn 7408: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7409: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7410: if ($defquota eq '') {
7411: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7412: $settingstatus = $item;
7413: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7414: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7415: $settingstatus = $item;
7416: }
7417: }
7418: } else {
7419: if ($quotahash{'quotas'}{$item} ne '') {
7420: if ($defquota eq '') {
7421: $defquota = $quotahash{'quotas'}{$item};
7422: $settingstatus = $item;
7423: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7424: $defquota = $quotahash{'quotas'}{$item};
7425: $settingstatus = $item;
7426: }
1.536 raeburn 7427: }
7428: }
7429: }
7430: }
7431: if ($defquota eq '') {
1.711 raeburn 7432: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7433: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7434: } else {
7435: $defquota = $quotahash{'quotas'}{'default'};
7436: }
1.536 raeburn 7437: $settingstatus = 'default';
7438: }
7439: } else {
7440: $settingstatus = 'default';
7441: $defquota = 20;
7442: }
7443: if (wantarray) {
7444: return ($defquota,$settingstatus);
1.472 raeburn 7445: } else {
1.536 raeburn 7446: return $defquota;
1.472 raeburn 7447: }
7448: }
7449:
1.384 raeburn 7450: sub get_secgrprole_info {
7451: my ($cdom,$cnum,$needroles,$type) = @_;
7452: my %sections_count = &get_sections($cdom,$cnum);
7453: my @sections = (sort {$a <=> $b} keys(%sections_count));
7454: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7455: my @groups = sort(keys(%curr_groups));
7456: my $allroles = [];
7457: my $rolehash;
7458: my $accesshash = {
7459: active => 'Currently has access',
7460: future => 'Will have future access',
7461: previous => 'Previously had access',
7462: };
7463: if ($needroles) {
7464: $rolehash = {'all' => 'all'};
1.385 albertel 7465: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7466: if (&Apache::lonnet::error(%user_roles)) {
7467: undef(%user_roles);
7468: }
7469: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7470: my ($role)=split(/\:/,$item,2);
7471: if ($role eq 'cr') { next; }
7472: if ($role =~ /^cr/) {
7473: $$rolehash{$role} = (split('/',$role))[3];
7474: } else {
7475: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7476: }
7477: }
7478: foreach my $key (sort(keys(%{$rolehash}))) {
7479: push(@{$allroles},$key);
7480: }
7481: push (@{$allroles},'st');
7482: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7483: }
7484: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7485: }
7486:
1.555 raeburn 7487: sub user_picker {
1.627 raeburn 7488: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7489: my $currdom = $dom;
7490: my %curr_selected = (
7491: srchin => 'dom',
1.580 raeburn 7492: srchby => 'lastname',
1.555 raeburn 7493: );
7494: my $srchterm;
1.625 raeburn 7495: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7496: if ($srch->{'srchby'} ne '') {
7497: $curr_selected{'srchby'} = $srch->{'srchby'};
7498: }
7499: if ($srch->{'srchin'} ne '') {
7500: $curr_selected{'srchin'} = $srch->{'srchin'};
7501: }
7502: if ($srch->{'srchtype'} ne '') {
7503: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7504: }
7505: if ($srch->{'srchdomain'} ne '') {
7506: $currdom = $srch->{'srchdomain'};
7507: }
7508: $srchterm = $srch->{'srchterm'};
7509: }
7510: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7511: 'usr' => 'Search criteria',
1.563 raeburn 7512: 'doma' => 'Domain/institution to search',
1.558 albertel 7513: 'uname' => 'username',
7514: 'lastname' => 'last name',
1.555 raeburn 7515: 'lastfirst' => 'last name, first name',
1.558 albertel 7516: 'crs' => 'in this course',
1.576 raeburn 7517: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7518: 'alc' => 'all LON-CAPA',
1.573 raeburn 7519: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7520: 'exact' => 'is',
7521: 'contains' => 'contains',
1.569 raeburn 7522: 'begins' => 'begins with',
1.571 raeburn 7523: 'youm' => "You must include some text to search for.",
7524: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7525: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7526: 'yomc' => "You must choose a domain when using an institutional directory search.",
7527: 'ymcd' => "You must choose a domain when using a domain search.",
7528: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7529: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7530: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7531: );
1.563 raeburn 7532: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7533: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7534:
7535: my @srchins = ('crs','dom','alc','instd');
7536:
7537: foreach my $option (@srchins) {
7538: # FIXME 'alc' option unavailable until
7539: # loncreateuser::print_user_query_page()
7540: # has been completed.
7541: next if ($option eq 'alc');
1.880 raeburn 7542: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7543: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7544: if ($curr_selected{'srchin'} eq $option) {
7545: $srchinsel .= '
7546: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7547: } else {
7548: $srchinsel .= '
7549: <option value="'.$option.'">'.$lt{$option}.'</option>';
7550: }
1.555 raeburn 7551: }
1.563 raeburn 7552: $srchinsel .= "\n </select>\n";
1.555 raeburn 7553:
7554: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7555: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7556: if ($curr_selected{'srchby'} eq $option) {
7557: $srchbysel .= '
7558: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7559: } else {
7560: $srchbysel .= '
7561: <option value="'.$option.'">'.$lt{$option}.'</option>';
7562: }
7563: }
7564: $srchbysel .= "\n </select>\n";
7565:
7566: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7567: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7568: if ($curr_selected{'srchtype'} eq $option) {
7569: $srchtypesel .= '
7570: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7571: } else {
7572: $srchtypesel .= '
7573: <option value="'.$option.'">'.$lt{$option}.'</option>';
7574: }
7575: }
7576: $srchtypesel .= "\n </select>\n";
7577:
1.558 albertel 7578: my ($newuserscript,$new_user_create);
1.556 raeburn 7579:
7580: if ($forcenewuser) {
1.576 raeburn 7581: if (ref($srch) eq 'HASH') {
7582: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7583: if ($cancreate) {
7584: $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>';
7585: } else {
1.799 bisitz 7586: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7587: my %usertypetext = (
7588: official => 'institutional',
7589: unofficial => 'non-institutional',
7590: );
1.799 bisitz 7591: $new_user_create = '<p class="LC_warning">'
7592: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7593: .' '
7594: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7595: ,'<a href="'.$helplink.'">','</a>')
7596: .'</p><br />';
1.627 raeburn 7597: }
1.576 raeburn 7598: }
7599: }
7600:
1.556 raeburn 7601: $newuserscript = <<"ENDSCRIPT";
7602:
1.570 raeburn 7603: function setSearch(createnew,callingForm) {
1.556 raeburn 7604: if (createnew == 1) {
1.570 raeburn 7605: for (var i=0; i<callingForm.srchby.length; i++) {
7606: if (callingForm.srchby.options[i].value == 'uname') {
7607: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7608: }
7609: }
1.570 raeburn 7610: for (var i=0; i<callingForm.srchin.length; i++) {
7611: if ( callingForm.srchin.options[i].value == 'dom') {
7612: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7613: }
7614: }
1.570 raeburn 7615: for (var i=0; i<callingForm.srchtype.length; i++) {
7616: if (callingForm.srchtype.options[i].value == 'exact') {
7617: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7618: }
7619: }
1.570 raeburn 7620: for (var i=0; i<callingForm.srchdomain.length; i++) {
7621: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7622: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7623: }
7624: }
7625: }
7626: }
7627: ENDSCRIPT
1.558 albertel 7628:
1.556 raeburn 7629: }
7630:
1.555 raeburn 7631: my $output = <<"END_BLOCK";
1.556 raeburn 7632: <script type="text/javascript">
1.824 bisitz 7633: // <![CDATA[
1.570 raeburn 7634: function validateEntry(callingForm) {
1.558 albertel 7635:
1.556 raeburn 7636: var checkok = 1;
1.558 albertel 7637: var srchin;
1.570 raeburn 7638: for (var i=0; i<callingForm.srchin.length; i++) {
7639: if ( callingForm.srchin[i].checked ) {
7640: srchin = callingForm.srchin[i].value;
1.558 albertel 7641: }
7642: }
7643:
1.570 raeburn 7644: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7645: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7646: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7647: var srchterm = callingForm.srchterm.value;
7648: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7649: var msg = "";
7650:
7651: if (srchterm == "") {
7652: checkok = 0;
1.571 raeburn 7653: msg += "$lt{'youm'}\\n";
1.556 raeburn 7654: }
7655:
1.569 raeburn 7656: if (srchtype== 'begins') {
7657: if (srchterm.length < 2) {
7658: checkok = 0;
1.571 raeburn 7659: msg += "$lt{'thte'}\\n";
1.569 raeburn 7660: }
7661: }
7662:
1.556 raeburn 7663: if (srchtype== 'contains') {
7664: if (srchterm.length < 3) {
7665: checkok = 0;
1.571 raeburn 7666: msg += "$lt{'thet'}\\n";
1.556 raeburn 7667: }
7668: }
7669: if (srchin == 'instd') {
7670: if (srchdomain == '') {
7671: checkok = 0;
1.571 raeburn 7672: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7673: }
7674: }
7675: if (srchin == 'dom') {
7676: if (srchdomain == '') {
7677: checkok = 0;
1.571 raeburn 7678: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7679: }
7680: }
7681: if (srchby == 'lastfirst') {
7682: if (srchterm.indexOf(",") == -1) {
7683: checkok = 0;
1.571 raeburn 7684: msg += "$lt{'whus'}\\n";
1.556 raeburn 7685: }
7686: if (srchterm.indexOf(",") == srchterm.length -1) {
7687: checkok = 0;
1.571 raeburn 7688: msg += "$lt{'whse'}\\n";
1.556 raeburn 7689: }
7690: }
7691: if (checkok == 0) {
1.571 raeburn 7692: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7693: return;
7694: }
7695: if (checkok == 1) {
1.570 raeburn 7696: callingForm.submit();
1.556 raeburn 7697: }
7698: }
7699:
7700: $newuserscript
7701:
1.824 bisitz 7702: // ]]>
1.556 raeburn 7703: </script>
1.558 albertel 7704:
7705: $new_user_create
7706:
1.555 raeburn 7707: END_BLOCK
1.558 albertel 7708:
1.876 raeburn 7709: $output .= &Apache::lonhtmlcommon::start_pick_box().
7710: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7711: $domform.
7712: &Apache::lonhtmlcommon::row_closure().
7713: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7714: $srchbysel.
7715: $srchtypesel.
7716: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7717: $srchinsel.
7718: &Apache::lonhtmlcommon::row_closure(1).
7719: &Apache::lonhtmlcommon::end_pick_box().
7720: '<br />';
1.555 raeburn 7721: return $output;
7722: }
7723:
1.612 raeburn 7724: sub user_rule_check {
1.615 raeburn 7725: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7726: my $response;
7727: if (ref($usershash) eq 'HASH') {
7728: foreach my $user (keys(%{$usershash})) {
7729: my ($uname,$udom) = split(/:/,$user);
7730: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7731: my ($id,$newuser);
1.612 raeburn 7732: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7733: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7734: $id = $usershash->{$user}->{'id'};
7735: }
7736: my $inst_response;
7737: if (ref($checks) eq 'HASH') {
7738: if (defined($checks->{'username'})) {
1.615 raeburn 7739: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7740: &Apache::lonnet::get_instuser($udom,$uname);
7741: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7742: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7743: &Apache::lonnet::get_instuser($udom,undef,$id);
7744: }
1.615 raeburn 7745: } else {
7746: ($inst_response,%{$inst_results->{$user}}) =
7747: &Apache::lonnet::get_instuser($udom,$uname);
7748: return;
1.612 raeburn 7749: }
1.615 raeburn 7750: if (!$got_rules->{$udom}) {
1.612 raeburn 7751: my %domconfig = &Apache::lonnet::get_dom('configuration',
7752: ['usercreation'],$udom);
7753: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7754: foreach my $item ('username','id') {
1.612 raeburn 7755: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7756: $$curr_rules{$udom}{$item} =
7757: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7758: }
7759: }
7760: }
1.615 raeburn 7761: $got_rules->{$udom} = 1;
1.585 raeburn 7762: }
1.612 raeburn 7763: foreach my $item (keys(%{$checks})) {
7764: if (ref($$curr_rules{$udom}) eq 'HASH') {
7765: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7766: if (@{$$curr_rules{$udom}{$item}} > 0) {
7767: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7768: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7769: if ($rule_check{$rule}) {
7770: $$rulematch{$user}{$item} = $rule;
7771: if ($inst_response eq 'ok') {
1.615 raeburn 7772: if (ref($inst_results) eq 'HASH') {
7773: if (ref($inst_results->{$user}) eq 'HASH') {
7774: if (keys(%{$inst_results->{$user}}) == 0) {
7775: $$alerts{$item}{$udom}{$uname} = 1;
7776: }
1.612 raeburn 7777: }
7778: }
1.615 raeburn 7779: }
7780: last;
1.585 raeburn 7781: }
7782: }
7783: }
7784: }
7785: }
7786: }
7787: }
7788: }
1.612 raeburn 7789: return;
7790: }
7791:
7792: sub user_rule_formats {
7793: my ($domain,$domdesc,$curr_rules,$check) = @_;
7794: my %text = (
7795: 'username' => 'Usernames',
7796: 'id' => 'IDs',
7797: );
7798: my $output;
7799: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7800: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7801: if (@{$ruleorder} > 0) {
7802: $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>';
7803: foreach my $rule (@{$ruleorder}) {
7804: if (ref($curr_rules) eq 'ARRAY') {
7805: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7806: if (ref($rules->{$rule}) eq 'HASH') {
7807: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7808: $rules->{$rule}{'desc'}.'</li>';
7809: }
7810: }
7811: }
7812: }
7813: $output .= '</ul>';
7814: }
7815: }
7816: return $output;
7817: }
7818:
7819: sub instrule_disallow_msg {
1.615 raeburn 7820: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7821: my $response;
7822: my %text = (
7823: item => 'username',
7824: items => 'usernames',
7825: match => 'matches',
7826: do => 'does',
7827: action => 'a username',
7828: one => 'one',
7829: );
7830: if ($count > 1) {
7831: $text{'item'} = 'usernames';
7832: $text{'match'} ='match';
7833: $text{'do'} = 'do';
7834: $text{'action'} = 'usernames',
7835: $text{'one'} = 'ones';
7836: }
7837: if ($checkitem eq 'id') {
7838: $text{'items'} = 'IDs';
7839: $text{'item'} = 'ID';
7840: $text{'action'} = 'an ID';
1.615 raeburn 7841: if ($count > 1) {
7842: $text{'item'} = 'IDs';
7843: $text{'action'} = 'IDs';
7844: }
1.612 raeburn 7845: }
1.674 bisitz 7846: $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 7847: if ($mode eq 'upload') {
7848: if ($checkitem eq 'username') {
7849: $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'}.");
7850: } elsif ($checkitem eq 'id') {
1.674 bisitz 7851: $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 7852: }
1.669 raeburn 7853: } elsif ($mode eq 'selfcreate') {
7854: if ($checkitem eq 'id') {
7855: $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.");
7856: }
1.615 raeburn 7857: } else {
7858: if ($checkitem eq 'username') {
7859: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7860: } elsif ($checkitem eq 'id') {
7861: $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.");
7862: }
1.612 raeburn 7863: }
7864: return $response;
1.585 raeburn 7865: }
7866:
1.624 raeburn 7867: sub personal_data_fieldtitles {
7868: my %fieldtitles = &Apache::lonlocal::texthash (
7869: id => 'Student/Employee ID',
7870: permanentemail => 'E-mail address',
7871: lastname => 'Last Name',
7872: firstname => 'First Name',
7873: middlename => 'Middle Name',
7874: generation => 'Generation',
7875: gen => 'Generation',
1.765 raeburn 7876: inststatus => 'Affiliation',
1.624 raeburn 7877: );
7878: return %fieldtitles;
7879: }
7880:
1.642 raeburn 7881: sub sorted_inst_types {
7882: my ($dom) = @_;
7883: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7884: my $othertitle = &mt('All users');
7885: if ($env{'request.course.id'}) {
1.668 raeburn 7886: $othertitle = &mt('Any users');
1.642 raeburn 7887: }
7888: my @types;
7889: if (ref($order) eq 'ARRAY') {
7890: @types = @{$order};
7891: }
7892: if (@types == 0) {
7893: if (ref($usertypes) eq 'HASH') {
7894: @types = sort(keys(%{$usertypes}));
7895: }
7896: }
7897: if (keys(%{$usertypes}) > 0) {
7898: $othertitle = &mt('Other users');
7899: }
7900: return ($othertitle,$usertypes,\@types);
7901: }
7902:
1.645 raeburn 7903: sub get_institutional_codes {
7904: my ($settings,$allcourses,$LC_code) = @_;
7905: # Get complete list of course sections to update
7906: my @currsections = ();
7907: my @currxlists = ();
7908: my $coursecode = $$settings{'internal.coursecode'};
7909:
7910: if ($$settings{'internal.sectionnums'} ne '') {
7911: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7912: }
7913:
7914: if ($$settings{'internal.crosslistings'} ne '') {
7915: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7916: }
7917:
7918: if (@currxlists > 0) {
7919: foreach (@currxlists) {
7920: if (m/^([^:]+):(\w*)$/) {
7921: unless (grep/^$1$/,@{$allcourses}) {
7922: push @{$allcourses},$1;
7923: $$LC_code{$1} = $2;
7924: }
7925: }
7926: }
7927: }
7928:
7929: if (@currsections > 0) {
7930: foreach (@currsections) {
7931: if (m/^(\w+):(\w*)$/) {
7932: my $sec = $coursecode.$1;
7933: my $lc_sec = $2;
7934: unless (grep/^$sec$/,@{$allcourses}) {
7935: push @{$allcourses},$sec;
7936: $$LC_code{$sec} = $lc_sec;
7937: }
7938: }
7939: }
7940: }
7941: return;
7942: }
7943:
1.112 bowersj2 7944: =pod
7945:
1.780 raeburn 7946: =head1 Slot Helpers
7947:
7948: =over 4
7949:
7950: =item * sorted_slots()
7951:
7952: Sorts an array of slot names in order of slot start time (earliest first).
7953:
7954: Inputs:
7955:
7956: =over 4
7957:
7958: slotsarr - Reference to array of unsorted slot names.
7959:
7960: slots - Reference to hash of hash, where outer hash keys are slot names.
7961:
1.549 albertel 7962: =back
7963:
1.780 raeburn 7964: Returns:
7965:
7966: =over 4
7967:
7968: sorted - An array of slot names sorted by the start time of the slot.
7969:
7970: =back
7971:
7972: =back
7973:
7974: =cut
7975:
7976:
7977: sub sorted_slots {
7978: my ($slotsarr,$slots) = @_;
7979: my @sorted;
7980: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7981: @sorted =
7982: sort {
7983: if (ref($slots->{$a}) && ref($slots->{$b})) {
7984: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7985: }
7986: if (ref($slots->{$a})) { return -1;}
7987: if (ref($slots->{$b})) { return 1;}
7988: return 0;
7989: } @{$slotsarr};
7990: }
7991: return @sorted;
7992: }
7993:
7994:
7995: =pod
7996:
1.549 albertel 7997: =head1 HTTP Helpers
7998:
7999: =over 4
8000:
1.648 raeburn 8001: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8002:
1.258 albertel 8003: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8004: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8005: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8006:
8007: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8008: $possible_names is an ref to an array of form element names. As an example:
8009: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8010: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8011:
8012: =cut
1.1 albertel 8013:
1.6 albertel 8014: sub get_unprocessed_cgi {
1.25 albertel 8015: my ($query,$possible_names)= @_;
1.26 matthew 8016: # $Apache::lonxml::debug=1;
1.356 albertel 8017: foreach my $pair (split(/&/,$query)) {
8018: my ($name, $value) = split(/=/,$pair);
1.369 www 8019: $name = &unescape($name);
1.25 albertel 8020: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8021: $value =~ tr/+/ /;
8022: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8023: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8024: }
1.16 harris41 8025: }
1.6 albertel 8026: }
8027:
1.112 bowersj2 8028: =pod
8029:
1.648 raeburn 8030: =item * &cacheheader()
1.112 bowersj2 8031:
8032: returns cache-controlling header code
8033:
8034: =cut
8035:
1.7 albertel 8036: sub cacheheader {
1.258 albertel 8037: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8038: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8039: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8040: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8041: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8042: return $output;
1.7 albertel 8043: }
8044:
1.112 bowersj2 8045: =pod
8046:
1.648 raeburn 8047: =item * &no_cache($r)
1.112 bowersj2 8048:
8049: specifies header code to not have cache
8050:
8051: =cut
8052:
1.9 albertel 8053: sub no_cache {
1.216 albertel 8054: my ($r) = @_;
8055: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8056: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8057: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8058: $r->no_cache(1);
8059: $r->header_out("Expires" => $date);
8060: $r->header_out("Pragma" => "no-cache");
1.123 www 8061: }
8062:
8063: sub content_type {
1.181 albertel 8064: my ($r,$type,$charset) = @_;
1.299 foxr 8065: if ($r) {
8066: # Note that printout.pl calls this with undef for $r.
8067: &no_cache($r);
8068: }
1.258 albertel 8069: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8070: unless ($charset) {
8071: $charset=&Apache::lonlocal::current_encoding;
8072: }
8073: if ($charset) { $type.='; charset='.$charset; }
8074: if ($r) {
8075: $r->content_type($type);
8076: } else {
8077: print("Content-type: $type\n\n");
8078: }
1.9 albertel 8079: }
1.25 albertel 8080:
1.112 bowersj2 8081: =pod
8082:
1.648 raeburn 8083: =item * &add_to_env($name,$value)
1.112 bowersj2 8084:
1.258 albertel 8085: adds $name to the %env hash with value
1.112 bowersj2 8086: $value, if $name already exists, the entry is converted to an array
8087: reference and $value is added to the array.
8088:
8089: =cut
8090:
1.25 albertel 8091: sub add_to_env {
8092: my ($name,$value)=@_;
1.258 albertel 8093: if (defined($env{$name})) {
8094: if (ref($env{$name})) {
1.25 albertel 8095: #already have multiple values
1.258 albertel 8096: push(@{ $env{$name} },$value);
1.25 albertel 8097: } else {
8098: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8099: my $first=$env{$name};
8100: undef($env{$name});
8101: push(@{ $env{$name} },$first,$value);
1.25 albertel 8102: }
8103: } else {
1.258 albertel 8104: $env{$name}=$value;
1.25 albertel 8105: }
1.31 albertel 8106: }
1.149 albertel 8107:
8108: =pod
8109:
1.648 raeburn 8110: =item * &get_env_multiple($name)
1.149 albertel 8111:
1.258 albertel 8112: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8113: values may be defined and end up as an array ref.
8114:
8115: returns an array of values
8116:
8117: =cut
8118:
8119: sub get_env_multiple {
8120: my ($name) = @_;
8121: my @values;
1.258 albertel 8122: if (defined($env{$name})) {
1.149 albertel 8123: # exists is it an array
1.258 albertel 8124: if (ref($env{$name})) {
8125: @values=@{ $env{$name} };
1.149 albertel 8126: } else {
1.258 albertel 8127: $values[0]=$env{$name};
1.149 albertel 8128: }
8129: }
8130: return(@values);
8131: }
8132:
1.660 raeburn 8133: sub ask_for_embedded_content {
8134: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8135: my $upload_output = '
8136: <form name="upload_embedded" action="'.$actionurl.'"
8137: method="post" enctype="multipart/form-data">';
8138: $upload_output .= $state;
1.661 raeburn 8139: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8140:
8141: my $num = 0;
8142: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8143: $upload_output .= &start_data_table_row().
8144: '<td>'.$embed_file.'</td><td>';
8145: if ($args->{'ignore_remote_references'}
8146: && $embed_file =~ m{^\w+://}) {
8147: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8148: } elsif ($args->{'error_on_invalid_names'}
8149: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8150:
8151: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8152:
8153: } else {
8154: $upload_output .='
1.661 raeburn 8155: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8156: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8157: my $attrib = join(':',@{$$allfiles{$embed_file}});
8158: $upload_output .=
8159: "\n\t\t".
8160: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8161: $attrib.'" />';
8162: if (exists($$codebase{$embed_file})) {
8163: $upload_output .=
8164: "\n\t\t".
8165: '<input name="codebase_'.$num.'" type="hidden" value="'.
8166: &escape($$codebase{$embed_file}).'" />';
8167: }
8168: }
8169: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8170: $num++;
8171: }
8172: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8173: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8174: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8175: '.&mt('(only files for which a location has been provided will be uploaded)').'
8176: </form>';
8177: return $upload_output;
8178: }
8179:
1.661 raeburn 8180: sub upload_embedded {
8181: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8182: $current_disk_usage) = @_;
8183: my $output;
8184: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8185: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8186: my $orig_uploaded_filename =
8187: $env{'form.embedded_item_'.$i.'.filename'};
8188:
8189: $env{'form.embedded_orig_'.$i} =
8190: &unescape($env{'form.embedded_orig_'.$i});
8191: my ($path,$fname) =
8192: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8193: # no path, whole string is fname
8194: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8195:
8196: $path = $env{'form.currentpath'}.$path;
8197: $fname = &Apache::lonnet::clean_filename($fname);
8198: # See if there is anything left
8199: next if ($fname eq '');
8200:
8201: # Check if file already exists as a file or directory.
8202: my ($state,$msg);
8203: if ($context eq 'portfolio') {
8204: my $port_path = $dirpath;
8205: if ($group ne '') {
8206: $port_path = "groups/$group/$port_path";
8207: }
8208: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8209: $dir_root,$port_path,$disk_quota,
8210: $current_disk_usage,$uname,$udom);
8211: if ($state eq 'will_exceed_quota'
8212: || $state eq 'file_locked'
8213: || $state eq 'file_exists' ) {
8214: $output .= $msg;
8215: next;
8216: }
8217: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8218: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8219: if ($state eq 'exists') {
8220: $output .= $msg;
8221: next;
8222: }
8223: }
8224: # Check if extension is valid
8225: if (($fname =~ /\.(\w+)$/) &&
8226: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8227: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8228: next;
8229: } elsif (($fname =~ /\.(\w+)$/) &&
8230: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8231: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8232: next;
8233: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8234: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8235: next;
8236: }
8237:
8238: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8239: if ($context eq 'portfolio') {
8240: my $result=
8241: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8242: $dirpath.$path);
8243: if ($result !~ m|^/uploaded/|) {
8244: $output .= '<span class="LC_error">'
8245: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8246: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8247: .'</span><br />';
8248: next;
8249: } else {
8250: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8251: $path.$fname.'</span>').'</p>';
8252: }
8253: } else {
8254: # Save the file
8255: my $target = $env{'form.embedded_item_'.$i};
8256: my $fullpath = $dir_root.$dirpath.'/'.$path;
8257: my $dest = $fullpath.$fname;
8258: my $url = $url_root.$dirpath.'/'.$path.$fname;
8259: my @parts=split(/\//,$fullpath);
8260: my $count;
8261: my $filepath = $dir_root;
8262: for ($count=4;$count<=$#parts;$count++) {
8263: $filepath .= "/$parts[$count]";
8264: if ((-e $filepath)!=1) {
8265: mkdir($filepath,0770);
8266: }
8267: }
8268: my $fh;
8269: if (!open($fh,'>'.$dest)) {
8270: &Apache::lonnet::logthis('Failed to create '.$dest);
8271: $output .= '<span class="LC_error">'.
8272: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8273: '</span><br />';
8274: } else {
8275: if (!print $fh $env{'form.embedded_item_'.$i}) {
8276: &Apache::lonnet::logthis('Failed to write to '.$dest);
8277: $output .= '<span class="LC_error">'.
8278: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8279: '</span><br />';
8280: } else {
8281: if ($context eq 'testbank') {
8282: $output .= &mt('Embedded file uploaded successfully:').
8283: ' <a href="'.$url.'">'.
8284: $orig_uploaded_filename.'</a><br />';
8285: } else {
1.705 tempelho 8286: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8287: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8288: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8289: }
8290: }
8291: close($fh);
8292: }
8293: }
8294: }
8295: return $output;
8296: }
8297:
8298: sub check_for_existing {
8299: my ($path,$fname,$element) = @_;
8300: my ($state,$msg);
8301: if (-d $path.'/'.$fname) {
8302: $state = 'exists';
8303: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8304: } elsif (-e $path.'/'.$fname) {
8305: $state = 'exists';
8306: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8307: }
8308: if ($state eq 'exists') {
8309: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8310: }
8311: return ($state,$msg);
8312: }
8313:
8314: sub check_for_upload {
8315: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8316: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8317: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8318: my $getpropath = 1;
8319: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8320: $getpropath);
8321: my $found_file = 0;
8322: my $locked_file = 0;
8323: foreach my $line (@dir_list) {
8324: my ($file_name)=split(/\&/,$line,2);
8325: if ($file_name eq $fname){
8326: $file_name = $path.$file_name;
8327: if ($group ne '') {
8328: $file_name = $group.$file_name;
8329: }
8330: $found_file = 1;
8331: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8332: $locked_file = 1;
8333: }
8334: }
8335: }
8336: if (($current_disk_usage + $filesize) > $disk_quota){
8337: my $msg = '<span class="LC_error">'.
8338: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8339: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8340: return ('will_exceed_quota',$msg);
8341: } elsif ($found_file) {
8342: if ($locked_file) {
8343: my $msg = '<span class="LC_error">';
8344: $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>');
8345: $msg .= '</span><br />';
8346: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8347: return ('file_locked',$msg);
8348: } else {
8349: my $msg = '<span class="LC_error">';
8350: $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'});
8351: $msg .= '</span>';
8352: $msg .= '<br />';
8353: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8354: return ('file_exists',$msg);
8355: }
8356: }
8357: }
8358:
1.31 albertel 8359:
1.41 ng 8360: =pod
1.45 matthew 8361:
1.464 albertel 8362: =back
1.41 ng 8363:
1.112 bowersj2 8364: =head1 CSV Upload/Handling functions
1.38 albertel 8365:
1.41 ng 8366: =over 4
8367:
1.648 raeburn 8368: =item * &upfile_store($r)
1.41 ng 8369:
8370: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8371: needs $env{'form.upfile'}
1.41 ng 8372: returns $datatoken to be put into hidden field
8373:
8374: =cut
1.31 albertel 8375:
8376: sub upfile_store {
8377: my $r=shift;
1.258 albertel 8378: $env{'form.upfile'}=~s/\r/\n/gs;
8379: $env{'form.upfile'}=~s/\f/\n/gs;
8380: $env{'form.upfile'}=~s/\n+/\n/gs;
8381: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8382:
1.258 albertel 8383: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8384: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8385: {
1.158 raeburn 8386: my $datafile = $r->dir_config('lonDaemons').
8387: '/tmp/'.$datatoken.'.tmp';
8388: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8389: print $fh $env{'form.upfile'};
1.158 raeburn 8390: close($fh);
8391: }
1.31 albertel 8392: }
8393: return $datatoken;
8394: }
8395:
1.56 matthew 8396: =pod
8397:
1.648 raeburn 8398: =item * &load_tmp_file($r)
1.41 ng 8399:
8400: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8401: needs $env{'form.datatoken'},
8402: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8403:
8404: =cut
1.31 albertel 8405:
8406: sub load_tmp_file {
8407: my $r=shift;
8408: my @studentdata=();
8409: {
1.158 raeburn 8410: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8411: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8412: if ( open(my $fh,"<$studentfile") ) {
8413: @studentdata=<$fh>;
8414: close($fh);
8415: }
1.31 albertel 8416: }
1.258 albertel 8417: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8418: }
8419:
1.56 matthew 8420: =pod
8421:
1.648 raeburn 8422: =item * &upfile_record_sep()
1.41 ng 8423:
8424: Separate uploaded file into records
8425: returns array of records,
1.258 albertel 8426: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8427:
8428: =cut
1.31 albertel 8429:
8430: sub upfile_record_sep {
1.258 albertel 8431: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8432: } else {
1.248 albertel 8433: my @records;
1.258 albertel 8434: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8435: if ($line=~/^\s*$/) { next; }
8436: push(@records,$line);
8437: }
8438: return @records;
1.31 albertel 8439: }
8440: }
8441:
1.56 matthew 8442: =pod
8443:
1.648 raeburn 8444: =item * &record_sep($record)
1.41 ng 8445:
1.258 albertel 8446: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8447:
8448: =cut
8449:
1.263 www 8450: sub takeleft {
8451: my $index=shift;
8452: return substr('0000'.$index,-4,4);
8453: }
8454:
1.31 albertel 8455: sub record_sep {
8456: my $record=shift;
8457: my %components=();
1.258 albertel 8458: if ($env{'form.upfiletype'} eq 'xml') {
8459: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8460: my $i=0;
1.356 albertel 8461: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8462: $field=~s/^(\"|\')//;
8463: $field=~s/(\"|\')$//;
1.263 www 8464: $components{&takeleft($i)}=$field;
1.31 albertel 8465: $i++;
8466: }
1.258 albertel 8467: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8468: my $i=0;
1.356 albertel 8469: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8470: $field=~s/^(\"|\')//;
8471: $field=~s/(\"|\')$//;
1.263 www 8472: $components{&takeleft($i)}=$field;
1.31 albertel 8473: $i++;
8474: }
8475: } else {
1.561 www 8476: my $separator=',';
1.480 banghart 8477: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8478: $separator=';';
1.480 banghart 8479: }
1.31 albertel 8480: my $i=0;
1.561 www 8481: # the character we are looking for to indicate the end of a quote or a record
8482: my $looking_for=$separator;
8483: # do not add the characters to the fields
8484: my $ignore=0;
8485: # we just encountered a separator (or the beginning of the record)
8486: my $just_found_separator=1;
8487: # store the field we are working on here
8488: my $field='';
8489: # work our way through all characters in record
8490: foreach my $character ($record=~/(.)/g) {
8491: if ($character eq $looking_for) {
8492: if ($character ne $separator) {
8493: # Found the end of a quote, again looking for separator
8494: $looking_for=$separator;
8495: $ignore=1;
8496: } else {
8497: # Found a separator, store away what we got
8498: $components{&takeleft($i)}=$field;
8499: $i++;
8500: $just_found_separator=1;
8501: $ignore=0;
8502: $field='';
8503: }
8504: next;
8505: }
8506: # single or double quotation marks after a separator indicate beginning of a quote
8507: # we are now looking for the end of the quote and need to ignore separators
8508: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8509: $looking_for=$character;
8510: next;
8511: }
8512: # ignore would be true after we reached the end of a quote
8513: if ($ignore) { next; }
8514: if (($just_found_separator) && ($character=~/\s/)) { next; }
8515: $field.=$character;
8516: $just_found_separator=0;
1.31 albertel 8517: }
1.561 www 8518: # catch the very last entry, since we never encountered the separator
8519: $components{&takeleft($i)}=$field;
1.31 albertel 8520: }
8521: return %components;
8522: }
8523:
1.144 matthew 8524: ######################################################
8525: ######################################################
8526:
1.56 matthew 8527: =pod
8528:
1.648 raeburn 8529: =item * &upfile_select_html()
1.41 ng 8530:
1.144 matthew 8531: Return HTML code to select a file from the users machine and specify
8532: the file type.
1.41 ng 8533:
8534: =cut
8535:
1.144 matthew 8536: ######################################################
8537: ######################################################
1.31 albertel 8538: sub upfile_select_html {
1.144 matthew 8539: my %Types = (
8540: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8541: semisv => &mt('Semicolon separated values'),
1.144 matthew 8542: space => &mt('Space separated'),
8543: tab => &mt('Tabulator separated'),
8544: # xml => &mt('HTML/XML'),
8545: );
8546: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8547: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8548: foreach my $type (sort(keys(%Types))) {
8549: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8550: }
8551: $Str .= "</select>\n";
8552: return $Str;
1.31 albertel 8553: }
8554:
1.301 albertel 8555: sub get_samples {
8556: my ($records,$toget) = @_;
8557: my @samples=({});
8558: my $got=0;
8559: foreach my $rec (@$records) {
8560: my %temp = &record_sep($rec);
8561: if (! grep(/\S/, values(%temp))) { next; }
8562: if (%temp) {
8563: $samples[$got]=\%temp;
8564: $got++;
8565: if ($got == $toget) { last; }
8566: }
8567: }
8568: return \@samples;
8569: }
8570:
1.144 matthew 8571: ######################################################
8572: ######################################################
8573:
1.56 matthew 8574: =pod
8575:
1.648 raeburn 8576: =item * &csv_print_samples($r,$records)
1.41 ng 8577:
8578: Prints a table of sample values from each column uploaded $r is an
8579: Apache Request ref, $records is an arrayref from
8580: &Apache::loncommon::upfile_record_sep
8581:
8582: =cut
8583:
1.144 matthew 8584: ######################################################
8585: ######################################################
1.31 albertel 8586: sub csv_print_samples {
8587: my ($r,$records) = @_;
1.662 bisitz 8588: my $samples = &get_samples($records,5);
1.301 albertel 8589:
1.594 raeburn 8590: $r->print(&mt('Samples').'<br />'.&start_data_table().
8591: &start_data_table_header_row());
1.356 albertel 8592: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8593: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8594: $r->print(&end_data_table_header_row());
1.301 albertel 8595: foreach my $hash (@$samples) {
1.594 raeburn 8596: $r->print(&start_data_table_row());
1.356 albertel 8597: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8598: $r->print('<td>');
1.356 albertel 8599: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8600: $r->print('</td>');
8601: }
1.594 raeburn 8602: $r->print(&end_data_table_row());
1.31 albertel 8603: }
1.594 raeburn 8604: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8605: }
8606:
1.144 matthew 8607: ######################################################
8608: ######################################################
8609:
1.56 matthew 8610: =pod
8611:
1.648 raeburn 8612: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8613:
8614: Prints a table to create associations between values and table columns.
1.144 matthew 8615:
1.41 ng 8616: $r is an Apache Request ref,
8617: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8618: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8619:
8620: =cut
8621:
1.144 matthew 8622: ######################################################
8623: ######################################################
1.31 albertel 8624: sub csv_print_select_table {
8625: my ($r,$records,$d) = @_;
1.301 albertel 8626: my $i=0;
8627: my $samples = &get_samples($records,1);
1.144 matthew 8628: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8629: &start_data_table().&start_data_table_header_row().
1.144 matthew 8630: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8631: '<th>'.&mt('Column').'</th>'.
8632: &end_data_table_header_row()."\n");
1.356 albertel 8633: foreach my $array_ref (@$d) {
8634: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8635: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8636:
1.875 bisitz 8637: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8638: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8639: $r->print('<option value="none"></option>');
1.356 albertel 8640: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8641: $r->print('<option value="'.$sample.'"'.
8642: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8643: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8644: }
1.594 raeburn 8645: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8646: $i++;
8647: }
1.594 raeburn 8648: $r->print(&end_data_table());
1.31 albertel 8649: $i--;
8650: return $i;
8651: }
1.56 matthew 8652:
1.144 matthew 8653: ######################################################
8654: ######################################################
8655:
1.56 matthew 8656: =pod
1.31 albertel 8657:
1.648 raeburn 8658: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8659:
8660: Prints a table of sample values from the upload and can make associate samples to internal names.
8661:
8662: $r is an Apache Request ref,
8663: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8664: $d is an array of 2 element arrays (internal name, displayed name)
8665:
8666: =cut
8667:
1.144 matthew 8668: ######################################################
8669: ######################################################
1.31 albertel 8670: sub csv_samples_select_table {
8671: my ($r,$records,$d) = @_;
8672: my $i=0;
1.144 matthew 8673: #
1.662 bisitz 8674: my $max_samples = 5;
8675: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8676: $r->print(&start_data_table().
8677: &start_data_table_header_row().'<th>'.
8678: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8679: &end_data_table_header_row());
1.301 albertel 8680:
8681: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8682: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8683: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8684: foreach my $option (@$d) {
8685: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8686: $r->print('<option value="'.$value.'"'.
1.253 albertel 8687: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8688: $display.'</option>');
1.31 albertel 8689: }
8690: $r->print('</select></td><td>');
1.662 bisitz 8691: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8692: if (defined($samples->[$line]{$key})) {
8693: $r->print($samples->[$line]{$key}."<br />\n");
8694: }
8695: }
1.594 raeburn 8696: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8697: $i++;
8698: }
1.594 raeburn 8699: $r->print(&end_data_table());
1.31 albertel 8700: $i--;
8701: return($i);
1.115 matthew 8702: }
8703:
1.144 matthew 8704: ######################################################
8705: ######################################################
8706:
1.115 matthew 8707: =pod
8708:
1.648 raeburn 8709: =item * &clean_excel_name($name)
1.115 matthew 8710:
8711: Returns a replacement for $name which does not contain any illegal characters.
8712:
8713: =cut
8714:
1.144 matthew 8715: ######################################################
8716: ######################################################
1.115 matthew 8717: sub clean_excel_name {
8718: my ($name) = @_;
8719: $name =~ s/[:\*\?\/\\]//g;
8720: if (length($name) > 31) {
8721: $name = substr($name,0,31);
8722: }
8723: return $name;
1.25 albertel 8724: }
1.84 albertel 8725:
1.85 albertel 8726: =pod
8727:
1.648 raeburn 8728: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8729:
8730: Returns either 1 or undef
8731:
8732: 1 if the part is to be hidden, undef if it is to be shown
8733:
8734: Arguments are:
8735:
8736: $id the id of the part to be checked
8737: $symb, optional the symb of the resource to check
8738: $udom, optional the domain of the user to check for
8739: $uname, optional the username of the user to check for
8740:
8741: =cut
1.84 albertel 8742:
8743: sub check_if_partid_hidden {
8744: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8745: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8746: $symb,$udom,$uname);
1.141 albertel 8747: my $truth=1;
8748: #if the string starts with !, then the list is the list to show not hide
8749: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8750: my @hiddenlist=split(/,/,$hiddenparts);
8751: foreach my $checkid (@hiddenlist) {
1.141 albertel 8752: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8753: }
1.141 albertel 8754: return !$truth;
1.84 albertel 8755: }
1.127 matthew 8756:
1.138 matthew 8757:
8758: ############################################################
8759: ############################################################
8760:
8761: =pod
8762:
1.157 matthew 8763: =back
8764:
1.138 matthew 8765: =head1 cgi-bin script and graphing routines
8766:
1.157 matthew 8767: =over 4
8768:
1.648 raeburn 8769: =item * &get_cgi_id()
1.138 matthew 8770:
8771: Inputs: none
8772:
8773: Returns an id which can be used to pass environment variables
8774: to various cgi-bin scripts. These environment variables will
8775: be removed from the users environment after a given time by
8776: the routine &Apache::lonnet::transfer_profile_to_env.
8777:
8778: =cut
8779:
8780: ############################################################
8781: ############################################################
1.152 albertel 8782: my $uniq=0;
1.136 matthew 8783: sub get_cgi_id {
1.154 albertel 8784: $uniq=($uniq+1)%100000;
1.280 albertel 8785: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8786: }
8787:
1.127 matthew 8788: ############################################################
8789: ############################################################
8790:
8791: =pod
8792:
1.648 raeburn 8793: =item * &DrawBarGraph()
1.127 matthew 8794:
1.138 matthew 8795: Facilitates the plotting of data in a (stacked) bar graph.
8796: Puts plot definition data into the users environment in order for
8797: graph.png to plot it. Returns an <img> tag for the plot.
8798: The bars on the plot are labeled '1','2',...,'n'.
8799:
8800: Inputs:
8801:
8802: =over 4
8803:
8804: =item $Title: string, the title of the plot
8805:
8806: =item $xlabel: string, text describing the X-axis of the plot
8807:
8808: =item $ylabel: string, text describing the Y-axis of the plot
8809:
8810: =item $Max: scalar, the maximum Y value to use in the plot
8811: If $Max is < any data point, the graph will not be rendered.
8812:
1.140 matthew 8813: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8814: they are plotted. If undefined, default values will be used.
8815:
1.178 matthew 8816: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8817:
1.138 matthew 8818: =item @Values: An array of array references. Each array reference holds data
8819: to be plotted in a stacked bar chart.
8820:
1.239 matthew 8821: =item If the final element of @Values is a hash reference the key/value
8822: pairs will be added to the graph definition.
8823:
1.138 matthew 8824: =back
8825:
8826: Returns:
8827:
8828: An <img> tag which references graph.png and the appropriate identifying
8829: information for the plot.
8830:
1.127 matthew 8831: =cut
8832:
8833: ############################################################
8834: ############################################################
1.134 matthew 8835: sub DrawBarGraph {
1.178 matthew 8836: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8837: #
8838: if (! defined($colors)) {
8839: $colors = ['#33ff00',
8840: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8841: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8842: ];
8843: }
1.228 matthew 8844: my $extra_settings = {};
8845: if (ref($Values[-1]) eq 'HASH') {
8846: $extra_settings = pop(@Values);
8847: }
1.127 matthew 8848: #
1.136 matthew 8849: my $identifier = &get_cgi_id();
8850: my $id = 'cgi.'.$identifier;
1.129 matthew 8851: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8852: return '';
8853: }
1.225 matthew 8854: #
8855: my @Labels;
8856: if (defined($labels)) {
8857: @Labels = @$labels;
8858: } else {
8859: for (my $i=0;$i<@{$Values[0]};$i++) {
8860: push (@Labels,$i+1);
8861: }
8862: }
8863: #
1.129 matthew 8864: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8865: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8866: my %ValuesHash;
8867: my $NumSets=1;
8868: foreach my $array (@Values) {
8869: next if (! ref($array));
1.136 matthew 8870: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8871: join(',',@$array);
1.129 matthew 8872: }
1.127 matthew 8873: #
1.136 matthew 8874: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8875: if ($NumBars < 3) {
8876: $width = 120+$NumBars*32;
1.220 matthew 8877: $xskip = 1;
1.225 matthew 8878: $bar_width = 30;
8879: } elsif ($NumBars < 5) {
8880: $width = 120+$NumBars*20;
8881: $xskip = 1;
8882: $bar_width = 20;
1.220 matthew 8883: } elsif ($NumBars < 10) {
1.136 matthew 8884: $width = 120+$NumBars*15;
8885: $xskip = 1;
8886: $bar_width = 15;
8887: } elsif ($NumBars <= 25) {
8888: $width = 120+$NumBars*11;
8889: $xskip = 5;
8890: $bar_width = 8;
8891: } elsif ($NumBars <= 50) {
8892: $width = 120+$NumBars*8;
8893: $xskip = 5;
8894: $bar_width = 4;
8895: } else {
8896: $width = 120+$NumBars*8;
8897: $xskip = 5;
8898: $bar_width = 4;
8899: }
8900: #
1.137 matthew 8901: $Max = 1 if ($Max < 1);
8902: if ( int($Max) < $Max ) {
8903: $Max++;
8904: $Max = int($Max);
8905: }
1.127 matthew 8906: $Title = '' if (! defined($Title));
8907: $xlabel = '' if (! defined($xlabel));
8908: $ylabel = '' if (! defined($ylabel));
1.369 www 8909: $ValuesHash{$id.'.title'} = &escape($Title);
8910: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8911: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8912: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8913: $ValuesHash{$id.'.NumBars'} = $NumBars;
8914: $ValuesHash{$id.'.NumSets'} = $NumSets;
8915: $ValuesHash{$id.'.PlotType'} = 'bar';
8916: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8917: $ValuesHash{$id.'.height'} = $height;
8918: $ValuesHash{$id.'.width'} = $width;
8919: $ValuesHash{$id.'.xskip'} = $xskip;
8920: $ValuesHash{$id.'.bar_width'} = $bar_width;
8921: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8922: #
1.228 matthew 8923: # Deal with other parameters
8924: while (my ($key,$value) = each(%$extra_settings)) {
8925: $ValuesHash{$id.'.'.$key} = $value;
8926: }
8927: #
1.646 raeburn 8928: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8929: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8930: }
8931:
8932: ############################################################
8933: ############################################################
8934:
8935: =pod
8936:
1.648 raeburn 8937: =item * &DrawXYGraph()
1.137 matthew 8938:
1.138 matthew 8939: Facilitates the plotting of data in an XY graph.
8940: Puts plot definition data into the users environment in order for
8941: graph.png to plot it. Returns an <img> tag for the plot.
8942:
8943: Inputs:
8944:
8945: =over 4
8946:
8947: =item $Title: string, the title of the plot
8948:
8949: =item $xlabel: string, text describing the X-axis of the plot
8950:
8951: =item $ylabel: string, text describing the Y-axis of the plot
8952:
8953: =item $Max: scalar, the maximum Y value to use in the plot
8954: If $Max is < any data point, the graph will not be rendered.
8955:
8956: =item $colors: Array ref containing the hex color codes for the data to be
8957: plotted in. If undefined, default values will be used.
8958:
8959: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8960:
8961: =item $Ydata: Array ref containing Array refs.
1.185 www 8962: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8963:
8964: =item %Values: hash indicating or overriding any default values which are
8965: passed to graph.png.
8966: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8967:
8968: =back
8969:
8970: Returns:
8971:
8972: An <img> tag which references graph.png and the appropriate identifying
8973: information for the plot.
8974:
1.137 matthew 8975: =cut
8976:
8977: ############################################################
8978: ############################################################
8979: sub DrawXYGraph {
8980: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8981: #
8982: # Create the identifier for the graph
8983: my $identifier = &get_cgi_id();
8984: my $id = 'cgi.'.$identifier;
8985: #
8986: $Title = '' if (! defined($Title));
8987: $xlabel = '' if (! defined($xlabel));
8988: $ylabel = '' if (! defined($ylabel));
8989: my %ValuesHash =
8990: (
1.369 www 8991: $id.'.title' => &escape($Title),
8992: $id.'.xlabel' => &escape($xlabel),
8993: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8994: $id.'.y_max_value'=> $Max,
8995: $id.'.labels' => join(',',@$Xlabels),
8996: $id.'.PlotType' => 'XY',
8997: );
8998: #
8999: if (defined($colors) && ref($colors) eq 'ARRAY') {
9000: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9001: }
9002: #
9003: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9004: return '';
9005: }
9006: my $NumSets=1;
1.138 matthew 9007: foreach my $array (@{$Ydata}){
1.137 matthew 9008: next if (! ref($array));
9009: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9010: }
1.138 matthew 9011: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9012: #
9013: # Deal with other parameters
9014: while (my ($key,$value) = each(%Values)) {
9015: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9016: }
9017: #
1.646 raeburn 9018: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9019: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9020: }
9021:
9022: ############################################################
9023: ############################################################
9024:
9025: =pod
9026:
1.648 raeburn 9027: =item * &DrawXYYGraph()
1.138 matthew 9028:
9029: Facilitates the plotting of data in an XY graph with two Y axes.
9030: Puts plot definition data into the users environment in order for
9031: graph.png to plot it. Returns an <img> tag for the plot.
9032:
9033: Inputs:
9034:
9035: =over 4
9036:
9037: =item $Title: string, the title of the plot
9038:
9039: =item $xlabel: string, text describing the X-axis of the plot
9040:
9041: =item $ylabel: string, text describing the Y-axis of the plot
9042:
9043: =item $colors: Array ref containing the hex color codes for the data to be
9044: plotted in. If undefined, default values will be used.
9045:
9046: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9047:
9048: =item $Ydata1: The first data set
9049:
9050: =item $Min1: The minimum value of the left Y-axis
9051:
9052: =item $Max1: The maximum value of the left Y-axis
9053:
9054: =item $Ydata2: The second data set
9055:
9056: =item $Min2: The minimum value of the right Y-axis
9057:
9058: =item $Max2: The maximum value of the left Y-axis
9059:
9060: =item %Values: hash indicating or overriding any default values which are
9061: passed to graph.png.
9062: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9063:
9064: =back
9065:
9066: Returns:
9067:
9068: An <img> tag which references graph.png and the appropriate identifying
9069: information for the plot.
1.136 matthew 9070:
9071: =cut
9072:
9073: ############################################################
9074: ############################################################
1.137 matthew 9075: sub DrawXYYGraph {
9076: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9077: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9078: #
9079: # Create the identifier for the graph
9080: my $identifier = &get_cgi_id();
9081: my $id = 'cgi.'.$identifier;
9082: #
9083: $Title = '' if (! defined($Title));
9084: $xlabel = '' if (! defined($xlabel));
9085: $ylabel = '' if (! defined($ylabel));
9086: my %ValuesHash =
9087: (
1.369 www 9088: $id.'.title' => &escape($Title),
9089: $id.'.xlabel' => &escape($xlabel),
9090: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9091: $id.'.labels' => join(',',@$Xlabels),
9092: $id.'.PlotType' => 'XY',
9093: $id.'.NumSets' => 2,
1.137 matthew 9094: $id.'.two_axes' => 1,
9095: $id.'.y1_max_value' => $Max1,
9096: $id.'.y1_min_value' => $Min1,
9097: $id.'.y2_max_value' => $Max2,
9098: $id.'.y2_min_value' => $Min2,
1.136 matthew 9099: );
9100: #
1.137 matthew 9101: if (defined($colors) && ref($colors) eq 'ARRAY') {
9102: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9103: }
9104: #
9105: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9106: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9107: return '';
9108: }
9109: my $NumSets=1;
1.137 matthew 9110: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9111: next if (! ref($array));
9112: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9113: }
9114: #
9115: # Deal with other parameters
9116: while (my ($key,$value) = each(%Values)) {
9117: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9118: }
9119: #
1.646 raeburn 9120: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9121: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9122: }
9123:
9124: ############################################################
9125: ############################################################
9126:
9127: =pod
9128:
1.157 matthew 9129: =back
9130:
1.139 matthew 9131: =head1 Statistics helper routines?
9132:
9133: Bad place for them but what the hell.
9134:
1.157 matthew 9135: =over 4
9136:
1.648 raeburn 9137: =item * &chartlink()
1.139 matthew 9138:
9139: Returns a link to the chart for a specific student.
9140:
9141: Inputs:
9142:
9143: =over 4
9144:
9145: =item $linktext: The text of the link
9146:
9147: =item $sname: The students username
9148:
9149: =item $sdomain: The students domain
9150:
9151: =back
9152:
1.157 matthew 9153: =back
9154:
1.139 matthew 9155: =cut
9156:
9157: ############################################################
9158: ############################################################
9159: sub chartlink {
9160: my ($linktext, $sname, $sdomain) = @_;
9161: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9162: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9163: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9164: '">'.$linktext.'</a>';
1.153 matthew 9165: }
9166:
9167: #######################################################
9168: #######################################################
9169:
9170: =pod
9171:
9172: =head1 Course Environment Routines
1.157 matthew 9173:
9174: =over 4
1.153 matthew 9175:
1.648 raeburn 9176: =item * &restore_course_settings()
1.153 matthew 9177:
1.648 raeburn 9178: =item * &store_course_settings()
1.153 matthew 9179:
9180: Restores/Store indicated form parameters from the course environment.
9181: Will not overwrite existing values of the form parameters.
9182:
9183: Inputs:
9184: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9185:
9186: a hash ref describing the data to be stored. For example:
9187:
9188: %Save_Parameters = ('Status' => 'scalar',
9189: 'chartoutputmode' => 'scalar',
9190: 'chartoutputdata' => 'scalar',
9191: 'Section' => 'array',
1.373 raeburn 9192: 'Group' => 'array',
1.153 matthew 9193: 'StudentData' => 'array',
9194: 'Maps' => 'array');
9195:
9196: Returns: both routines return nothing
9197:
1.631 raeburn 9198: =back
9199:
1.153 matthew 9200: =cut
9201:
9202: #######################################################
9203: #######################################################
9204: sub store_course_settings {
1.496 albertel 9205: return &store_settings($env{'request.course.id'},@_);
9206: }
9207:
9208: sub store_settings {
1.153 matthew 9209: # save to the environment
9210: # appenv the same items, just to be safe
1.300 albertel 9211: my $udom = $env{'user.domain'};
9212: my $uname = $env{'user.name'};
1.496 albertel 9213: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9214: my %SaveHash;
9215: my %AppHash;
9216: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9217: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9218: my $envname = 'environment.'.$basename;
1.258 albertel 9219: if (exists($env{'form.'.$setting})) {
1.153 matthew 9220: # Save this value away
9221: if ($type eq 'scalar' &&
1.258 albertel 9222: (! exists($env{$envname}) ||
9223: $env{$envname} ne $env{'form.'.$setting})) {
9224: $SaveHash{$basename} = $env{'form.'.$setting};
9225: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9226: } elsif ($type eq 'array') {
9227: my $stored_form;
1.258 albertel 9228: if (ref($env{'form.'.$setting})) {
1.153 matthew 9229: $stored_form = join(',',
9230: map {
1.369 www 9231: &escape($_);
1.258 albertel 9232: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9233: } else {
9234: $stored_form =
1.369 www 9235: &escape($env{'form.'.$setting});
1.153 matthew 9236: }
9237: # Determine if the array contents are the same.
1.258 albertel 9238: if ($stored_form ne $env{$envname}) {
1.153 matthew 9239: $SaveHash{$basename} = $stored_form;
9240: $AppHash{$envname} = $stored_form;
9241: }
9242: }
9243: }
9244: }
9245: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9246: $udom,$uname);
1.153 matthew 9247: if ($put_result !~ /^(ok|delayed)/) {
9248: &Apache::lonnet::logthis('unable to save form parameters, '.
9249: 'got error:'.$put_result);
9250: }
9251: # Make sure these settings stick around in this session, too
1.646 raeburn 9252: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9253: return;
9254: }
9255:
9256: sub restore_course_settings {
1.499 albertel 9257: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9258: }
9259:
9260: sub restore_settings {
9261: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9262: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9263: next if (exists($env{'form.'.$setting}));
1.496 albertel 9264: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9265: '.'.$setting;
1.258 albertel 9266: if (exists($env{$envname})) {
1.153 matthew 9267: if ($type eq 'scalar') {
1.258 albertel 9268: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9269: } elsif ($type eq 'array') {
1.258 albertel 9270: $env{'form.'.$setting} = [
1.153 matthew 9271: map {
1.369 www 9272: &unescape($_);
1.258 albertel 9273: } split(',',$env{$envname})
1.153 matthew 9274: ];
9275: }
9276: }
9277: }
1.127 matthew 9278: }
9279:
1.618 raeburn 9280: #######################################################
9281: #######################################################
9282:
9283: =pod
9284:
9285: =head1 Domain E-mail Routines
9286:
9287: =over 4
9288:
1.648 raeburn 9289: =item * &build_recipient_list()
1.618 raeburn 9290:
1.884 raeburn 9291: Build recipient lists for five types of e-mail:
1.766 raeburn 9292: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9293: (d) Help requests, (e) Course requests needing approval, generated by
9294: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9295: loncoursequeueadmin.pm respectively.
1.618 raeburn 9296:
9297: Inputs:
1.619 raeburn 9298: defmail (scalar - email address of default recipient),
1.618 raeburn 9299: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9300: defdom (domain for which to retrieve configuration settings),
9301: origmail (scalar - email address of recipient from loncapa.conf,
9302: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9303:
1.655 raeburn 9304: Returns: comma separated list of addresses to which to send e-mail.
9305:
9306: =back
1.618 raeburn 9307:
9308: =cut
9309:
9310: ############################################################
9311: ############################################################
9312: sub build_recipient_list {
1.619 raeburn 9313: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9314: my @recipients;
9315: my $otheremails;
9316: my %domconfig =
9317: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9318: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9319: if (exists($domconfig{'contacts'}{$mailing})) {
9320: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9321: my @contacts = ('adminemail','supportemail');
9322: foreach my $item (@contacts) {
9323: if ($domconfig{'contacts'}{$mailing}{$item}) {
9324: my $addr = $domconfig{'contacts'}{$item};
9325: if (!grep(/^\Q$addr\E$/,@recipients)) {
9326: push(@recipients,$addr);
9327: }
1.619 raeburn 9328: }
1.766 raeburn 9329: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9330: }
9331: }
1.766 raeburn 9332: } elsif ($origmail ne '') {
9333: push(@recipients,$origmail);
1.618 raeburn 9334: }
1.619 raeburn 9335: } elsif ($origmail ne '') {
9336: push(@recipients,$origmail);
1.618 raeburn 9337: }
1.688 raeburn 9338: if (defined($defmail)) {
9339: if ($defmail ne '') {
9340: push(@recipients,$defmail);
9341: }
1.618 raeburn 9342: }
9343: if ($otheremails) {
1.619 raeburn 9344: my @others;
9345: if ($otheremails =~ /,/) {
9346: @others = split(/,/,$otheremails);
1.618 raeburn 9347: } else {
1.619 raeburn 9348: push(@others,$otheremails);
9349: }
9350: foreach my $addr (@others) {
9351: if (!grep(/^\Q$addr\E$/,@recipients)) {
9352: push(@recipients,$addr);
9353: }
1.618 raeburn 9354: }
9355: }
1.619 raeburn 9356: my $recipientlist = join(',',@recipients);
1.618 raeburn 9357: return $recipientlist;
9358: }
9359:
1.127 matthew 9360: ############################################################
9361: ############################################################
1.154 albertel 9362:
1.655 raeburn 9363: =pod
9364:
9365: =head1 Course Catalog Routines
9366:
9367: =over 4
9368:
9369: =item * &gather_categories()
9370:
9371: Converts category definitions - keys of categories hash stored in
9372: coursecategories in configuration.db on the primary library server in a
9373: domain - to an array. Also generates javascript and idx hash used to
9374: generate Domain Coordinator interface for editing Course Categories.
9375:
9376: Inputs:
1.663 raeburn 9377:
1.655 raeburn 9378: categories (reference to hash of category definitions).
1.663 raeburn 9379:
1.655 raeburn 9380: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9381: categories and subcategories).
1.663 raeburn 9382:
1.655 raeburn 9383: idx (reference to hash of counters used in Domain Coordinator interface for
9384: editing Course Categories).
1.663 raeburn 9385:
1.655 raeburn 9386: jsarray (reference to array of categories used to create Javascript arrays for
9387: Domain Coordinator interface for editing Course Categories).
9388:
9389: Returns: nothing
9390:
9391: Side effects: populates cats, idx and jsarray.
9392:
9393: =cut
9394:
9395: sub gather_categories {
9396: my ($categories,$cats,$idx,$jsarray) = @_;
9397: my %counters;
9398: my $num = 0;
9399: foreach my $item (keys(%{$categories})) {
9400: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9401: if ($container eq '' && $depth == 0) {
9402: $cats->[$depth][$categories->{$item}] = $cat;
9403: } else {
9404: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9405: }
9406: my ($escitem,$tail) = split(/:/,$item,2);
9407: if ($counters{$tail} eq '') {
9408: $counters{$tail} = $num;
9409: $num ++;
9410: }
9411: if (ref($idx) eq 'HASH') {
9412: $idx->{$item} = $counters{$tail};
9413: }
9414: if (ref($jsarray) eq 'ARRAY') {
9415: push(@{$jsarray->[$counters{$tail}]},$item);
9416: }
9417: }
9418: return;
9419: }
9420:
9421: =pod
9422:
9423: =item * &extract_categories()
9424:
9425: Used to generate breadcrumb trails for course categories.
9426:
9427: Inputs:
1.663 raeburn 9428:
1.655 raeburn 9429: categories (reference to hash of category definitions).
1.663 raeburn 9430:
1.655 raeburn 9431: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9432: categories and subcategories).
1.663 raeburn 9433:
1.655 raeburn 9434: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9435:
1.655 raeburn 9436: allitems (reference to hash - key is category key
9437: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9438:
1.655 raeburn 9439: idx (reference to hash of counters used in Domain Coordinator interface for
9440: editing Course Categories).
1.663 raeburn 9441:
1.655 raeburn 9442: jsarray (reference to array of categories used to create Javascript arrays for
9443: Domain Coordinator interface for editing Course Categories).
9444:
1.665 raeburn 9445: subcats (reference to hash of arrays containing all subcategories within each
9446: category, -recursive)
9447:
1.655 raeburn 9448: Returns: nothing
9449:
9450: Side effects: populates trails and allitems hash references.
9451:
9452: =cut
9453:
9454: sub extract_categories {
1.665 raeburn 9455: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9456: if (ref($categories) eq 'HASH') {
9457: &gather_categories($categories,$cats,$idx,$jsarray);
9458: if (ref($cats->[0]) eq 'ARRAY') {
9459: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9460: my $name = $cats->[0][$i];
9461: my $item = &escape($name).'::0';
9462: my $trailstr;
9463: if ($name eq 'instcode') {
9464: $trailstr = &mt('Official courses (with institutional codes)');
9465: } else {
9466: $trailstr = $name;
9467: }
9468: if ($allitems->{$item} eq '') {
9469: push(@{$trails},$trailstr);
9470: $allitems->{$item} = scalar(@{$trails})-1;
9471: }
9472: my @parents = ($name);
9473: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9474: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9475: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9476: if (ref($subcats) eq 'HASH') {
9477: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9478: }
9479: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9480: }
9481: } else {
9482: if (ref($subcats) eq 'HASH') {
9483: $subcats->{$item} = [];
1.655 raeburn 9484: }
9485: }
9486: }
9487: }
9488: }
9489: return;
9490: }
9491:
9492: =pod
9493:
9494: =item *&recurse_categories()
9495:
9496: Recursively used to generate breadcrumb trails for course categories.
9497:
9498: Inputs:
1.663 raeburn 9499:
1.655 raeburn 9500: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9501: categories and subcategories).
1.663 raeburn 9502:
1.655 raeburn 9503: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9504:
9505: category (current course category, for which breadcrumb trail is being generated).
9506:
9507: trails (reference to array of breadcrumb trails for each category).
9508:
1.655 raeburn 9509: allitems (reference to hash - key is category key
9510: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9511:
1.655 raeburn 9512: parents (array containing containers directories for current category,
9513: back to top level).
9514:
9515: Returns: nothing
9516:
9517: Side effects: populates trails and allitems hash references
9518:
9519: =cut
9520:
9521: sub recurse_categories {
1.665 raeburn 9522: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9523: my $shallower = $depth - 1;
9524: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9525: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9526: my $name = $cats->[$depth]{$category}[$k];
9527: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9528: my $trailstr = join(' -> ',(@{$parents},$category));
9529: if ($allitems->{$item} eq '') {
9530: push(@{$trails},$trailstr);
9531: $allitems->{$item} = scalar(@{$trails})-1;
9532: }
9533: my $deeper = $depth+1;
9534: push(@{$parents},$category);
1.665 raeburn 9535: if (ref($subcats) eq 'HASH') {
9536: my $subcat = &escape($name).':'.$category.':'.$depth;
9537: for (my $j=@{$parents}; $j>=0; $j--) {
9538: my $higher;
9539: if ($j > 0) {
9540: $higher = &escape($parents->[$j]).':'.
9541: &escape($parents->[$j-1]).':'.$j;
9542: } else {
9543: $higher = &escape($parents->[$j]).'::'.$j;
9544: }
9545: push(@{$subcats->{$higher}},$subcat);
9546: }
9547: }
9548: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9549: $subcats);
1.655 raeburn 9550: pop(@{$parents});
9551: }
9552: } else {
9553: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9554: my $trailstr = join(' -> ',(@{$parents},$category));
9555: if ($allitems->{$item} eq '') {
9556: push(@{$trails},$trailstr);
9557: $allitems->{$item} = scalar(@{$trails})-1;
9558: }
9559: }
9560: return;
9561: }
9562:
1.663 raeburn 9563: =pod
9564:
9565: =item *&assign_categories_table()
9566:
9567: Create a datatable for display of hierarchical categories in a domain,
9568: with checkboxes to allow a course to be categorized.
9569:
9570: Inputs:
9571:
9572: cathash - reference to hash of categories defined for the domain (from
9573: configuration.db)
9574:
9575: currcat - scalar with an & separated list of categories assigned to a course.
9576:
9577: Returns: $output (markup to be displayed)
9578:
9579: =cut
9580:
9581: sub assign_categories_table {
9582: my ($cathash,$currcat) = @_;
9583: my $output;
9584: if (ref($cathash) eq 'HASH') {
9585: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9586: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9587: $maxdepth = scalar(@cats);
9588: if (@cats > 0) {
9589: my $itemcount = 0;
9590: if (ref($cats[0]) eq 'ARRAY') {
9591: $output = &Apache::loncommon::start_data_table();
9592: my @currcategories;
9593: if ($currcat ne '') {
9594: @currcategories = split('&',$currcat);
9595: }
9596: for (my $i=0; $i<@{$cats[0]}; $i++) {
9597: my $parent = $cats[0][$i];
9598: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9599: next if ($parent eq 'instcode');
9600: my $item = &escape($parent).'::0';
9601: my $checked = '';
9602: if (@currcategories > 0) {
9603: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9604: $checked = ' checked="checked"';
1.663 raeburn 9605: }
9606: }
1.675 raeburn 9607: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9608: '<input type="checkbox" name="usecategory" value="'.
9609: $item.'"'.$checked.' />'.$parent.'</span>'.
9610: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9611: my $depth = 1;
9612: push(@path,$parent);
9613: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9614: pop(@path);
9615: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9616: $itemcount ++;
9617: }
9618: $output .= &Apache::loncommon::end_data_table();
9619: }
9620: }
9621: }
9622: return $output;
9623: }
9624:
9625: =pod
9626:
9627: =item *&assign_category_rows()
9628:
9629: Create a datatable row for display of nested categories in a domain,
9630: with checkboxes to allow a course to be categorized,called recursively.
9631:
9632: Inputs:
9633:
9634: itemcount - track row number for alternating colors
9635:
9636: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9637: categories and subcategories.
9638:
9639: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9640:
9641: parent - parent of current category item
9642:
9643: path - Array containing all categories back up through the hierarchy from the
9644: current category to the top level.
9645:
9646: currcategories - reference to array of current categories assigned to the course
9647:
9648: Returns: $output (markup to be displayed).
9649:
9650: =cut
9651:
9652: sub assign_category_rows {
9653: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9654: my ($text,$name,$item,$chgstr);
9655: if (ref($cats) eq 'ARRAY') {
9656: my $maxdepth = scalar(@{$cats});
9657: if (ref($cats->[$depth]) eq 'HASH') {
9658: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9659: my $numchildren = @{$cats->[$depth]{$parent}};
9660: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9661: $text .= '<td><table class="LC_datatable">';
9662: for (my $j=0; $j<$numchildren; $j++) {
9663: $name = $cats->[$depth]{$parent}[$j];
9664: $item = &escape($name).':'.&escape($parent).':'.$depth;
9665: my $deeper = $depth+1;
9666: my $checked = '';
9667: if (ref($currcategories) eq 'ARRAY') {
9668: if (@{$currcategories} > 0) {
9669: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9670: $checked = ' checked="checked"';
1.663 raeburn 9671: }
9672: }
9673: }
1.664 raeburn 9674: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9675: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9676: $item.'"'.$checked.' />'.$name.'</label></span>'.
9677: '<input type="hidden" name="catname" value="'.$name.'" />'.
9678: '</td><td>';
1.663 raeburn 9679: if (ref($path) eq 'ARRAY') {
9680: push(@{$path},$name);
9681: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9682: pop(@{$path});
9683: }
9684: $text .= '</td></tr>';
9685: }
9686: $text .= '</table></td>';
9687: }
9688: }
9689: }
9690: return $text;
9691: }
9692:
1.655 raeburn 9693: ############################################################
9694: ############################################################
9695:
9696:
1.443 albertel 9697: sub commit_customrole {
1.664 raeburn 9698: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9699: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9700: ($start?', '.&mt('starting').' '.localtime($start):'').
9701: ($end?', ending '.localtime($end):'').': <b>'.
9702: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9703: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9704: '</b><br />';
9705: return $output;
9706: }
9707:
9708: sub commit_standardrole {
1.541 raeburn 9709: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9710: my ($output,$logmsg,$linefeed);
9711: if ($context eq 'auto') {
9712: $linefeed = "\n";
9713: } else {
9714: $linefeed = "<br />\n";
9715: }
1.443 albertel 9716: if ($three eq 'st') {
1.541 raeburn 9717: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9718: $one,$two,$sec,$context);
9719: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9720: ($result eq 'unknown_course') || ($result eq 'refused')) {
9721: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9722: } else {
1.541 raeburn 9723: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9724: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9725: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9726: if ($context eq 'auto') {
9727: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9728: } else {
9729: $output .= '<b>'.$result.'</b>'.$linefeed.
9730: &mt('Add to classlist').': <b>ok</b>';
9731: }
9732: $output .= $linefeed;
1.443 albertel 9733: }
9734: } else {
9735: $output = &mt('Assigning').' '.$three.' in '.$url.
9736: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9737: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9738: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9739: if ($context eq 'auto') {
9740: $output .= $result.$linefeed;
9741: } else {
9742: $output .= '<b>'.$result.'</b>'.$linefeed;
9743: }
1.443 albertel 9744: }
9745: return $output;
9746: }
9747:
9748: sub commit_studentrole {
1.541 raeburn 9749: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9750: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9751: if ($context eq 'auto') {
9752: $linefeed = "\n";
9753: } else {
9754: $linefeed = '<br />'."\n";
9755: }
1.443 albertel 9756: if (defined($one) && defined($two)) {
9757: my $cid=$one.'_'.$two;
9758: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9759: my $secchange = 0;
9760: my $expire_role_result;
9761: my $modify_section_result;
1.628 raeburn 9762: if ($oldsec ne '-1') {
9763: if ($oldsec ne $sec) {
1.443 albertel 9764: $secchange = 1;
1.628 raeburn 9765: my $now = time;
1.443 albertel 9766: my $uurl='/'.$cid;
9767: $uurl=~s/\_/\//g;
9768: if ($oldsec) {
9769: $uurl.='/'.$oldsec;
9770: }
1.626 raeburn 9771: $oldsecurl = $uurl;
1.628 raeburn 9772: $expire_role_result =
1.652 raeburn 9773: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9774: if ($env{'request.course.sec'} ne '') {
9775: if ($expire_role_result eq 'refused') {
9776: my @roles = ('st');
9777: my @statuses = ('previous');
9778: my @roledoms = ($one);
9779: my $withsec = 1;
9780: my %roleshash =
9781: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9782: \@statuses,\@roles,\@roledoms,$withsec);
9783: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9784: my ($oldstart,$oldend) =
9785: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9786: if ($oldend > 0 && $oldend <= $now) {
9787: $expire_role_result = 'ok';
9788: }
9789: }
9790: }
9791: }
1.443 albertel 9792: $result = $expire_role_result;
9793: }
9794: }
9795: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9796: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9797: if ($modify_section_result =~ /^ok/) {
9798: if ($secchange == 1) {
1.628 raeburn 9799: if ($sec eq '') {
9800: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9801: } else {
9802: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9803: }
1.443 albertel 9804: } elsif ($oldsec eq '-1') {
1.628 raeburn 9805: if ($sec eq '') {
9806: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9807: } else {
9808: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9809: }
1.443 albertel 9810: } else {
1.628 raeburn 9811: if ($sec eq '') {
9812: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9813: } else {
9814: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9815: }
1.443 albertel 9816: }
9817: } else {
1.628 raeburn 9818: if ($secchange) {
9819: $$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;
9820: } else {
9821: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9822: }
1.443 albertel 9823: }
9824: $result = $modify_section_result;
9825: } elsif ($secchange == 1) {
1.628 raeburn 9826: if ($oldsec eq '') {
9827: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9828: } else {
9829: $$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;
9830: }
1.626 raeburn 9831: if ($expire_role_result eq 'refused') {
9832: my $newsecurl = '/'.$cid;
9833: $newsecurl =~ s/\_/\//g;
9834: if ($sec ne '') {
9835: $newsecurl.='/'.$sec;
9836: }
9837: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9838: if ($sec eq '') {
9839: $$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;
9840: } else {
9841: $$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;
9842: }
9843: }
9844: }
1.443 albertel 9845: }
9846: } else {
1.626 raeburn 9847: $$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 9848: $result = "error: incomplete course id\n";
9849: }
9850: return $result;
9851: }
9852:
9853: ############################################################
9854: ############################################################
9855:
1.566 albertel 9856: sub check_clone {
1.578 raeburn 9857: my ($args,$linefeed) = @_;
1.566 albertel 9858: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9859: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9860: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9861: my $clonemsg;
9862: my $can_clone = 0;
9863:
9864: if ($clonehome eq 'no_host') {
1.578 raeburn 9865: $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 9866: } else {
9867: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.882 raeburn 9868: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
9869: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 9870: $can_clone = 1;
9871: } else {
9872: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9873: $args->{'clonedomain'},$args->{'clonecourse'});
9874: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9875: if (grep(/^\*$/,@cloners)) {
9876: $can_clone = 1;
9877: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9878: $can_clone = 1;
9879: } else {
9880: my %roleshash =
9881: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9882: $args->{'ccdomain'},
9883: 'userroles',['active'],['cc'],
9884: [$args->{'clonedomain'}]);
9885: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9886: $can_clone = 1;
9887: } else {
9888: $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'});
9889: }
1.566 albertel 9890: }
1.578 raeburn 9891: }
1.566 albertel 9892: }
9893: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9894: }
9895:
1.444 albertel 9896: sub construct_course {
1.885 raeburn 9897: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 9898: my $outcome;
1.541 raeburn 9899: my $linefeed = '<br />'."\n";
9900: if ($context eq 'auto') {
9901: $linefeed = "\n";
9902: }
1.566 albertel 9903:
9904: #
9905: # Are we cloning?
9906: #
9907: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9908: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9909: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9910: if ($context ne 'auto') {
1.578 raeburn 9911: if ($clonemsg ne '') {
9912: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9913: }
1.566 albertel 9914: }
9915: $outcome .= $clonemsg.$linefeed;
9916:
9917: if (!$can_clone) {
9918: return (0,$outcome);
9919: }
9920: }
9921:
1.444 albertel 9922: #
9923: # Open course
9924: #
9925: my $crstype = lc($args->{'crstype'});
9926: my %cenv=();
9927: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9928: $args->{'cdescr'},
9929: $args->{'curl'},
9930: $args->{'course_home'},
9931: $args->{'nonstandard'},
9932: $args->{'crscode'},
9933: $args->{'ccuname'}.':'.
9934: $args->{'ccdomain'},
1.882 raeburn 9935: $args->{'crstype'},
1.885 raeburn 9936: $cnum,$context,$category);
1.444 albertel 9937:
9938: # Note: The testing routines depend on this being output; see
9939: # Utils::Course. This needs to at least be output as a comment
9940: # if anyone ever decides to not show this, and Utils::Course::new
9941: # will need to be suitably modified.
1.541 raeburn 9942: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9943: #
9944: # Check if created correctly
9945: #
1.479 albertel 9946: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9947: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9948: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9949:
1.444 albertel 9950: #
1.566 albertel 9951: # Do the cloning
9952: #
9953: if ($can_clone && $cloneid) {
9954: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9955: if ($context ne 'auto') {
9956: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9957: }
9958: $outcome .= $clonemsg.$linefeed;
9959: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9960: # Copy all files
1.637 www 9961: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9962: # Restore URL
1.566 albertel 9963: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9964: # Restore title
1.566 albertel 9965: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9966: # Mark as cloned
1.566 albertel 9967: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9968: # Need to clone grading mode
9969: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9970: $cenv{'grading'}=$newenv{'grading'};
9971: # Do not clone these environment entries
9972: &Apache::lonnet::del('environment',
9973: ['default_enrollment_start_date',
9974: 'default_enrollment_end_date',
9975: 'question.email',
9976: 'policy.email',
9977: 'comment.email',
9978: 'pch.users.denied',
1.725 raeburn 9979: 'plc.users.denied',
9980: 'hidefromcat',
9981: 'categories'],
1.638 www 9982: $$crsudom,$$crsunum);
1.444 albertel 9983: }
1.566 albertel 9984:
1.444 albertel 9985: #
9986: # Set environment (will override cloned, if existing)
9987: #
9988: my @sections = ();
9989: my @xlists = ();
9990: if ($args->{'crstype'}) {
9991: $cenv{'type'}=$args->{'crstype'};
9992: }
9993: if ($args->{'crsid'}) {
9994: $cenv{'courseid'}=$args->{'crsid'};
9995: }
9996: if ($args->{'crscode'}) {
9997: $cenv{'internal.coursecode'}=$args->{'crscode'};
9998: }
9999: if ($args->{'crsquota'} ne '') {
10000: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10001: } else {
10002: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10003: }
10004: if ($args->{'ccuname'}) {
10005: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10006: ':'.$args->{'ccdomain'};
10007: } else {
10008: $cenv{'internal.courseowner'} = $args->{'curruser'};
10009: }
10010: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10011: if ($args->{'crssections'}) {
10012: $cenv{'internal.sectionnums'} = '';
10013: if ($args->{'crssections'} =~ m/,/) {
10014: @sections = split/,/,$args->{'crssections'};
10015: } else {
10016: $sections[0] = $args->{'crssections'};
10017: }
10018: if (@sections > 0) {
10019: foreach my $item (@sections) {
10020: my ($sec,$gp) = split/:/,$item;
10021: my $class = $args->{'crscode'}.$sec;
10022: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10023: $cenv{'internal.sectionnums'} .= $item.',';
10024: unless ($addcheck eq 'ok') {
10025: push @badclasses, $class;
10026: }
10027: }
10028: $cenv{'internal.sectionnums'} =~ s/,$//;
10029: }
10030: }
10031: # do not hide course coordinator from staff listing,
10032: # even if privileged
10033: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10034: # add crosslistings
10035: if ($args->{'crsxlist'}) {
10036: $cenv{'internal.crosslistings'}='';
10037: if ($args->{'crsxlist'} =~ m/,/) {
10038: @xlists = split/,/,$args->{'crsxlist'};
10039: } else {
10040: $xlists[0] = $args->{'crsxlist'};
10041: }
10042: if (@xlists > 0) {
10043: foreach my $item (@xlists) {
10044: my ($xl,$gp) = split/:/,$item;
10045: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10046: $cenv{'internal.crosslistings'} .= $item.',';
10047: unless ($addcheck eq 'ok') {
10048: push @badclasses, $xl;
10049: }
10050: }
10051: $cenv{'internal.crosslistings'} =~ s/,$//;
10052: }
10053: }
10054: if ($args->{'autoadds'}) {
10055: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10056: }
10057: if ($args->{'autodrops'}) {
10058: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10059: }
10060: # check for notification of enrollment changes
10061: my @notified = ();
10062: if ($args->{'notify_owner'}) {
10063: if ($args->{'ccuname'} ne '') {
10064: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10065: }
10066: }
10067: if ($args->{'notify_dc'}) {
10068: if ($uname ne '') {
1.630 raeburn 10069: push(@notified,$uname.':'.$udom);
1.444 albertel 10070: }
10071: }
10072: if (@notified > 0) {
10073: my $notifylist;
10074: if (@notified > 1) {
10075: $notifylist = join(',',@notified);
10076: } else {
10077: $notifylist = $notified[0];
10078: }
10079: $cenv{'internal.notifylist'} = $notifylist;
10080: }
10081: if (@badclasses > 0) {
10082: my %lt=&Apache::lonlocal::texthash(
10083: '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',
10084: 'dnhr' => 'does not have rights to access enrollment in these classes',
10085: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10086: );
1.541 raeburn 10087: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10088: ' ('.$lt{'adby'}.')';
10089: if ($context eq 'auto') {
10090: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10091: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10092: foreach my $item (@badclasses) {
10093: if ($context eq 'auto') {
10094: $outcome .= " - $item\n";
10095: } else {
10096: $outcome .= "<li>$item</li>\n";
10097: }
10098: }
10099: if ($context eq 'auto') {
10100: $outcome .= $linefeed;
10101: } else {
1.566 albertel 10102: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10103: }
10104: }
1.444 albertel 10105: }
10106: if ($args->{'no_end_date'}) {
10107: $args->{'endaccess'} = 0;
10108: }
10109: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10110: $cenv{'internal.autoend'}=$args->{'enrollend'};
10111: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10112: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10113: if ($args->{'showphotos'}) {
10114: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10115: }
10116: $cenv{'internal.authtype'} = $args->{'authtype'};
10117: $cenv{'internal.autharg'} = $args->{'autharg'};
10118: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10119: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10120: 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');
10121: if ($context eq 'auto') {
10122: $outcome .= $krb_msg;
10123: } else {
1.566 albertel 10124: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10125: }
10126: $outcome .= $linefeed;
1.444 albertel 10127: }
10128: }
10129: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10130: if ($args->{'setpolicy'}) {
10131: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10132: }
10133: if ($args->{'setcontent'}) {
10134: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10135: }
10136: }
10137: if ($args->{'reshome'}) {
10138: $cenv{'reshome'}=$args->{'reshome'}.'/';
10139: $cenv{'reshome'}=~s/\/+$/\//;
10140: }
10141: #
10142: # course has keyed access
10143: #
10144: if ($args->{'setkeys'}) {
10145: $cenv{'keyaccess'}='yes';
10146: }
10147: # if specified, key authority is not course, but user
10148: # only active if keyaccess is yes
10149: if ($args->{'keyauth'}) {
1.487 albertel 10150: my ($user,$domain) = split(':',$args->{'keyauth'});
10151: $user = &LONCAPA::clean_username($user);
10152: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10153: if ($user ne '' && $domain ne '') {
1.487 albertel 10154: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10155: }
10156: }
10157:
10158: if ($args->{'disresdis'}) {
10159: $cenv{'pch.roles.denied'}='st';
10160: }
10161: if ($args->{'disablechat'}) {
10162: $cenv{'plc.roles.denied'}='st';
10163: }
10164:
10165: # Record we've not yet viewed the Course Initialization Helper for this
10166: # course
10167: $cenv{'course.helper.not.run'} = 1;
10168: #
10169: # Use new Randomseed
10170: #
10171: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10172: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10173: #
10174: # The encryption code and receipt prefix for this course
10175: #
10176: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10177: $cenv{'internal.encpref'}=100+int(9*rand(99));
10178: #
10179: # By default, use standard grading
10180: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10181:
1.541 raeburn 10182: $outcome .= $linefeed.&mt('Setting environment').': '.
10183: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10184: #
10185: # Open all assignments
10186: #
10187: if ($args->{'openall'}) {
10188: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10189: my %storecontent = ($storeunder => time,
10190: $storeunder.'.type' => 'date_start');
10191:
10192: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10193: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10194: }
10195: #
10196: # Set first page
10197: #
10198: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10199: || ($cloneid)) {
1.445 albertel 10200: use LONCAPA::map;
1.444 albertel 10201: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10202:
10203: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10204: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10205:
1.444 albertel 10206: $outcome .= ($fatal?$errtext:'read ok').' - ';
10207: my $title; my $url;
10208: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10209: $title=&mt('Syllabus');
1.444 albertel 10210: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10211: } else {
1.690 bisitz 10212: $title=&mt('Navigate Contents');
1.444 albertel 10213: $url='/adm/navmaps';
10214: }
1.445 albertel 10215:
10216: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10217: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10218:
10219: if ($errtext) { $fatal=2; }
1.541 raeburn 10220: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10221: }
1.566 albertel 10222:
10223: return (1,$outcome);
1.444 albertel 10224: }
10225:
10226: ############################################################
10227: ############################################################
10228:
1.378 raeburn 10229: sub course_type {
10230: my ($cid) = @_;
10231: if (!defined($cid)) {
10232: $cid = $env{'request.course.id'};
10233: }
1.404 albertel 10234: if (defined($env{'course.'.$cid.'.type'})) {
10235: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10236: } else {
10237: return 'Course';
1.377 raeburn 10238: }
10239: }
1.156 albertel 10240:
1.406 raeburn 10241: sub group_term {
10242: my $crstype = &course_type();
10243: my %names = (
10244: 'Course' => 'group',
1.865 raeburn 10245: 'Community' => 'group',
1.406 raeburn 10246: );
10247: return $names{$crstype};
10248: }
10249:
1.902 raeburn 10250: sub course_types {
10251: my @types = ('official','unofficial','community');
10252: my %typename = (
10253: official => 'Official course',
10254: unofficial => 'Unofficial course',
10255: community => 'Community',
10256: );
10257: return (\@types,\%typename);
10258: }
10259:
1.156 albertel 10260: sub icon {
10261: my ($file)=@_;
1.505 albertel 10262: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10263: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10264: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10265: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10266: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10267: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10268: $curfext.".gif") {
10269: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10270: $curfext.".gif";
10271: }
10272: }
1.249 albertel 10273: return &lonhttpdurl($iconname);
1.154 albertel 10274: }
1.84 albertel 10275:
1.575 albertel 10276: sub lonhttpdurl {
1.692 www 10277: #
10278: # Had been used for "small fry" static images on separate port 8080.
10279: # Modify here if lightweight http functionality desired again.
10280: # Currently eliminated due to increasing firewall issues.
10281: #
1.575 albertel 10282: my ($url)=@_;
1.692 www 10283: return $url;
1.215 albertel 10284: }
10285:
1.213 albertel 10286: sub connection_aborted {
10287: my ($r)=@_;
10288: $r->print(" ");$r->rflush();
10289: my $c = $r->connection;
10290: return $c->aborted();
10291: }
10292:
1.221 foxr 10293: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10294: # strings as 'strings'.
10295: sub escape_single {
1.221 foxr 10296: my ($input) = @_;
1.223 albertel 10297: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10298: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10299: return $input;
10300: }
1.223 albertel 10301:
1.222 foxr 10302: # Same as escape_single, but escape's "'s This
10303: # can be used for "strings"
10304: sub escape_double {
10305: my ($input) = @_;
10306: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10307: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10308: return $input;
10309: }
1.223 albertel 10310:
1.222 foxr 10311: # Escapes the last element of a full URL.
10312: sub escape_url {
10313: my ($url) = @_;
1.238 raeburn 10314: my @urlslices = split(/\//, $url,-1);
1.369 www 10315: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10316: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10317: }
1.462 albertel 10318:
1.820 raeburn 10319: sub compare_arrays {
10320: my ($arrayref1,$arrayref2) = @_;
10321: my (@difference,%count);
10322: @difference = ();
10323: %count = ();
10324: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10325: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10326: foreach my $element (keys(%count)) {
10327: if ($count{$element} == 1) {
10328: push(@difference,$element);
10329: }
10330: }
10331: }
10332: return @difference;
10333: }
10334:
1.817 bisitz 10335: # -------------------------------------------------------- Initialize user login
1.462 albertel 10336: sub init_user_environment {
1.463 albertel 10337: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10338: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10339:
10340: my $public=($username eq 'public' && $domain eq 'public');
10341:
10342: # See if old ID present, if so, remove
10343:
10344: my ($filename,$cookie,$userroles);
10345: my $now=time;
10346:
10347: if ($public) {
10348: my $max_public=100;
10349: my $oldest;
10350: my $oldest_time=0;
10351: for(my $next=1;$next<=$max_public;$next++) {
10352: if (-e $lonids."/publicuser_$next.id") {
10353: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10354: if ($mtime<$oldest_time || !$oldest_time) {
10355: $oldest_time=$mtime;
10356: $oldest=$next;
10357: }
10358: } else {
10359: $cookie="publicuser_$next";
10360: last;
10361: }
10362: }
10363: if (!$cookie) { $cookie="publicuser_$oldest"; }
10364: } else {
1.463 albertel 10365: # if this isn't a robot, kill any existing non-robot sessions
10366: if (!$args->{'robot'}) {
10367: opendir(DIR,$lonids);
10368: while ($filename=readdir(DIR)) {
10369: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10370: unlink($lonids.'/'.$filename);
10371: }
1.462 albertel 10372: }
1.463 albertel 10373: closedir(DIR);
1.462 albertel 10374: }
10375: # Give them a new cookie
1.463 albertel 10376: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10377: : $now.$$.int(rand(10000)));
1.463 albertel 10378: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10379:
10380: # Initialize roles
10381:
10382: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10383: }
10384: # ------------------------------------ Check browser type and MathML capability
10385:
10386: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10387: $clientunicode,$clientos) = &decode_user_agent($r);
10388:
10389: # ------------------------------------------------------------- Get environment
10390:
10391: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10392: my ($tmp) = keys(%userenv);
10393: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10394: # default remote control to off
10395: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10396: } else {
10397: undef(%userenv);
10398: }
10399: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10400: $form->{'interface'}=$userenv{'interface'};
10401: }
10402: $env{'environment.remote'}=$userenv{'remote'};
10403: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10404:
10405: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10406: foreach my $option ('interface','localpath','localres') {
10407: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10408: }
10409: # --------------------------------------------------------- Write first profile
10410:
10411: {
10412: my %initial_env =
10413: ("user.name" => $username,
10414: "user.domain" => $domain,
10415: "user.home" => $authhost,
10416: "browser.type" => $clientbrowser,
10417: "browser.version" => $clientversion,
10418: "browser.mathml" => $clientmathml,
10419: "browser.unicode" => $clientunicode,
10420: "browser.os" => $clientos,
10421: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10422: "request.course.fn" => '',
10423: "request.course.uri" => '',
10424: "request.course.sec" => '',
10425: "request.role" => 'cm',
10426: "request.role.adv" => $env{'user.adv'},
10427: "request.host" => $ENV{'REMOTE_ADDR'},);
10428:
10429: if ($form->{'localpath'}) {
10430: $initial_env{"browser.localpath"} = $form->{'localpath'};
10431: $initial_env{"browser.localres"} = $form->{'localres'};
10432: }
10433:
10434: if ($public) {
10435: $initial_env{"environment.remote"} = "off";
10436: }
10437: if ($form->{'interface'}) {
10438: $form->{'interface'}=~s/\W//gs;
10439: $initial_env{"browser.interface"} = $form->{'interface'};
10440: $env{'browser.interface'}=$form->{'interface'};
10441: }
10442:
1.724 raeburn 10443: foreach my $tool ('aboutme','blog','portfolio') {
10444: $userenv{'availabletools.'.$tool} =
10445: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10446: }
10447:
1.864 raeburn 10448: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10449: $userenv{'canrequest.'.$crstype} =
10450: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10451: 'reload','requestcourses');
10452: }
10453:
1.462 albertel 10454: $env{'user.environment'} = "$lonids/$cookie.id";
10455:
10456: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10457: &GDBM_WRCREAT(),0640)) {
10458: &_add_to_env(\%disk_env,\%initial_env);
10459: &_add_to_env(\%disk_env,\%userenv,'environment.');
10460: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10461: if (ref($args->{'extra_env'})) {
10462: &_add_to_env(\%disk_env,$args->{'extra_env'});
10463: }
1.462 albertel 10464: untie(%disk_env);
10465: } else {
1.705 tempelho 10466: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10467: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10468: return 'error: '.$!;
10469: }
10470: }
10471: $env{'request.role'}='cm';
10472: $env{'request.role.adv'}=$env{'user.adv'};
10473: $env{'browser.type'}=$clientbrowser;
10474:
10475: return $cookie;
10476:
10477: }
10478:
10479: sub _add_to_env {
10480: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10481: if (ref($env_data) eq 'HASH') {
10482: while (my ($key,$value) = each(%$env_data)) {
10483: $idf->{$prefix.$key} = $value;
10484: $env{$prefix.$key} = $value;
10485: }
1.462 albertel 10486: }
10487: }
10488:
1.685 tempelho 10489: # --- Get the symbolic name of a problem and the url
10490: sub get_symb {
10491: my ($request,$silent) = @_;
1.726 raeburn 10492: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10493: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10494: if ($symb eq '') {
10495: if (!$silent) {
10496: $request->print("Unable to handle ambiguous references:$url:.");
10497: return ();
10498: }
10499: }
10500: &Apache::lonenc::check_decrypt(\$symb);
10501: return ($symb);
10502: }
10503:
10504: # --------------------------------------------------------------Get annotation
10505:
10506: sub get_annotation {
10507: my ($symb,$enc) = @_;
10508:
10509: my $key = $symb;
10510: if (!$enc) {
10511: $key =
10512: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10513: }
10514: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10515: return $annotation{$key};
10516: }
10517:
10518: sub clean_symb {
1.731 raeburn 10519: my ($symb,$delete_enc) = @_;
1.685 tempelho 10520:
10521: &Apache::lonenc::check_decrypt(\$symb);
10522: my $enc = $env{'request.enc'};
1.731 raeburn 10523: if ($delete_enc) {
1.730 raeburn 10524: delete($env{'request.enc'});
10525: }
1.685 tempelho 10526:
10527: return ($symb,$enc);
10528: }
1.462 albertel 10529:
1.41 ng 10530: =pod
10531:
10532: =back
10533:
1.112 bowersj2 10534: =cut
1.41 ng 10535:
1.112 bowersj2 10536: 1;
10537: __END__;
1.41 ng 10538:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>