Annotation of loncom/interface/lontemplate.pm, revision 1.46

1.2       neumanie    1: # The LearningOnline Network
                      2: # "Template" Functions to generate html output
                      3: #
1.46    ! raeburn     4: # $Id: lontemplate.pm,v 1.45 2011/05/03 21:38:40 www Exp $
1.2       neumanie    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: #
                     28: 
1.1       amueller   29: package Apache::lontemplate;
                     30: 
                     31: 
                     32: use strict;
1.44      faziophi   33: use utf8;
1.1       amueller   34: use Apache::Constants qw(:common);
                     35: use Apache::loncommon;
                     36: use Apache::lonnet;
1.5       ehlerst    37: use Apache::lonxml;
                     38: use Apache::lonspeller;
1.1       amueller   39: use Apache::lontexconvert;
                     40: use Apache::lonfeedback;
                     41: use Apache::lonrss();
                     42: use Apache::lonlocal;
1.44      faziophi   43: use Apache::lonhtmlgateway;
1.1       amueller   44: use Apache::lonmsgdisplay();
                     45: use HTML::Entities();
                     46: 
1.42      faziophi   47: use constant {
                     48: 	RICH_TEXT_ALWAYS_ON => 'LC_richAlwaysOn',
                     49: 	RICH_TEXT_ALWAYS_OFF => 'LC_richAlwaysOff',
                     50: 	RICH_TEXT_DEFAULT_ON => 'LC_richDefaultOn',
                     51: 	RICH_TEXT_DETECT_HTML => 'LC_richDetectHtml',
                     52: 	RICH_TEXT_DEFAULT_OFF => 'LC_richDefaultOff'
                     53: };
1.7       ehlerst    54: 
1.33      bisitz     55: sub start_columnSection {
1.7       ehlerst    56: 	my ($r) = @_;
1.13      harmsja    57: 	 $r->print('<div class="LC_columnSection">');
1.7       ehlerst    58: }
                     59: 
1.33      bisitz     60: sub end_columnSection {
1.7       ehlerst    61: 	my ($r) = @_;
                     62: 	 $r->print('</div>');
                     63: }
                     64: 
1.33      bisitz     65: sub print_aboutme_content_template {
1.5       ehlerst    66: 	my ($r,$allowed,$target,$syllabusfields_ref,$syllabus_ref) = @_;
                     67: 	my %syllabusfields = %{$syllabusfields_ref};
                     68: 	my %syllabus = %{$syllabus_ref};
1.28      bisitz     69: 
1.5       ehlerst    70:        foreach my $field (sort(keys(%syllabusfields))) {
                     71:           if (($syllabus{$field}) || ($allowed)) {
                     72:               my $message=$syllabus{$field};
1.40      faziophi   73:               if (!&Apache::lonfeedback::contains_block_html($message)) {
                     74:               	&Apache::lonfeedback::newline_to_br(\$message);
                     75:               }
1.41      www        76:               $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
1.5       ehlerst    77:               if ($allowed) {
                     78:                   $message=&Apache::lonspeller::markeduptext($message);
                     79:               }
                     80:               $message=&Apache::lontexconvert::msgtexconverted($message);
                     81:               if ($target ne 'tex') {
1.15      neumanie   82: 		    if($field eq 'aaa_contactinfo') {
1.16      neumanie   83: 				$r->print('<div class="LC_Clear_AboutMe_Image" >&nbsp;</div>');
1.36      bisitz     84: 				&print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
1.33      bisitz     85: 		    } else {
1.36      bisitz     86: 			  &print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
1.15      neumanie   87: 		    }
1.38      amueller   88: 			if($allowed) {
                     89:                &print_editbox_template($r,$syllabus{$field},$field);
                     90: 			}
1.31      bisitz     91: 
1.5       ehlerst    92:               } else {
                     93:                      $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
                     94:                                &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
                     95:               }
                     96:           }
                     97:        }
1.28      bisitz     98: 
1.5       ehlerst    99: }
1.1       amueller  100: 
1.33      bisitz    101: sub send_message {
1.8       ehlerst   102: 	my ($r,$cnum,$cdom) = @_;
1.39      raeburn   103: 	my $linktext = &mt('Send message to [_1]',
                    104: 			   &Apache::loncommon::plainname($cnum,$cdom));
1.38      amueller  105: 	my $image = qq{<img name="Send_message" alt="Send message symbol" src="/res/adm/pages/mail-message-new.png" border="none" align="middle" />};
1.39      raeburn   106: 	return &Apache::loncommon::messagewrapper($image,$cnum,$cdom).' '.&Apache::loncommon::messagewrapper($linktext,$cnum,$cdom);
1.8       ehlerst   107: }
1.7       ehlerst   108: 
1.35      bisitz    109: sub print_template {
1.28      bisitz    110: 	my ($r,$topic,$content, $allowed,$boxclass) = @_;
                    111: 	$r->print('<div class="'.$boxclass.'">');
1.13      harmsja   112: 	$r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
1.35      bisitz    113: 	$r->print($content);
1.1       amueller  114: 	$r->print('</div>');
                    115: }
1.33      bisitz    116: 
1.35      bisitz    117: sub print_start_template {
1.20      neumanie  118: 	my ($r,$topic,$boxclass) = @_;
1.28      bisitz    119: 	$r->print('<div class="'.$boxclass.'">');
1.20      neumanie  120: 	$r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
                    121: }
1.33      bisitz    122: 
1.35      bisitz    123: sub print_end_template {
1.20      neumanie  124: 	my ($r) = @_;
                    125: 	$r->print('</div>');
                    126: }
1.33      bisitz    127: 
1.35      bisitz    128: sub print_editbox_template {
1.1       amueller  129: 	my ($r,$content,$field) = @_;
1.10      ehlerst   130: 	$r->print('<textarea cols="81" rows="6" name="'.$field.'">'.
1.46    ! raeburn   131:                   &HTML::Entities::encode($content,'"&<>').
        !           132:                   '</textarea><br />'."\n");
        !           133: 	&print_saveall_template($r);
1.1       amueller  134: }
1.27      bisitz    135: 
1.42      faziophi  136: sub print_textarea_template {
                    137: 	my ($r, $content, $field, $wysiwyg) = @_;
                    138: 	$r->print('<textarea cols="81" rows="6" class="'.$wysiwyg.'" id="'.$field.'" name="'.$field.'">'.
                    139: 						  &HTML::Entities::encode($content, '"&<>').
                    140: 			'</textarea><br />');
                    141: }
                    142: 
                    143: sub print_saveall_template {
                    144: 	my ($r) = @_;
                    145: 	$r->print('<input type="submit" name="storesyl" value="'.&mt('Save All').'" />');
                    146: }
                    147: 
1.43      faziophi  148: sub print_template_fields {
                    149: 	my ($r, $data_ref, $fields_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group) = @_;
                    150: 	my @html_ids = ();
                    151: 	my %data = %{$data_ref};
                    152: 	my %fields = %{$fields_ref};
                    153: 	my %custom_handlers = %{$custom_handlers_ref};
                    154: 
                    155: 	foreach my $field (sort(keys(%fields))) {
                    156: 		my $message = $data{$field} if (($data{$field}=~/\w/) || ($allowed));
1.44      faziophi  157: 		my $legacy = 1;
                    158: 		my $gateway = Apache::lonhtmlgateway->new($target);
                    159:         $message = &Encode::decode('utf8', $message);		
                    160:         $message = $gateway->process_outgoing_html($message, $legacy);
                    161:         if ((%custom_handlers) && ($custom_handlers{$field})) {
1.43      faziophi  162: 			$custom_handlers{$field}->($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed);
                    163: 		} else {
                    164: 			if (($data{$field}=~/\w/) || ($allowed)) {
                    165: 				if ($target ne 'tex') {
                    166: 					#output of syllabusfields will be generated here. 
                    167: 					&Apache::lontemplate::print_start_template($r,$fields{$field},'LC_Box');
                    168: 					$r->print($message);
                    169: 					if ($allowed) {
                    170: 						$r->print("<br /><div>");
                    171: 						&Apache::lontemplate::print_textarea_template($r, $data{$field},
                    172: 							$field, $default_rich_text);
1.46    ! raeburn   173: 						&print_saveall_template($r);
1.43      faziophi  174: 						$r->print("</div>");
                    175: 					} 
                    176: 					&Apache::lontemplate::print_end_template($r);
                    177: 				} else {
                    178: 				    my $safeinit;
1.45      www       179:                                     if ($fields{$field}=~/\w/) {
                    180:                                        $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$fields{$field}.'</h3>'));
                    181:                                     } else {
                    182:                                        $r->print(&Apache::lonxml::xmlparse($r,'tex','<br />'));
                    183:                                     }
                    184:                                     $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
1.43      faziophi  185: 				}
                    186: 				push(@html_ids,$field);
                    187: 			}
                    188: 		}
1.44      faziophi  189: 		undef $gateway;
1.43      faziophi  190: 	}
                    191: 	
                    192: 	return @html_ids;	
                    193: }
                    194: 
1.1       amueller  195: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>