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

1.2       neumanie    1: # The LearningOnline Network
                      2: # "Template" Functions to generate html output
                      3: #
1.45.6.4! raeburn     4: # $Id: lontemplate.pm,v 1.45.6.3 2012/12/18 15:53:07 raeburn 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;
                     43: use Apache::lonmsgdisplay();
                     44: use HTML::Entities();
                     45: 
1.42      faziophi   46: use constant {
                     47: 	RICH_TEXT_ALWAYS_ON => 'LC_richAlwaysOn',
                     48: 	RICH_TEXT_ALWAYS_OFF => 'LC_richAlwaysOff',
                     49: 	RICH_TEXT_DEFAULT_ON => 'LC_richDefaultOn',
                     50: 	RICH_TEXT_DETECT_HTML => 'LC_richDetectHtml',
                     51: 	RICH_TEXT_DEFAULT_OFF => 'LC_richDefaultOff'
                     52: };
1.7       ehlerst    53: 
1.33      bisitz     54: sub start_columnSection {
1.7       ehlerst    55: 	my ($r) = @_;
1.13      harmsja    56: 	 $r->print('<div class="LC_columnSection">');
1.7       ehlerst    57: }
                     58: 
1.33      bisitz     59: sub end_columnSection {
1.7       ehlerst    60: 	my ($r) = @_;
                     61: 	 $r->print('</div>');
                     62: }
                     63: 
1.33      bisitz     64: sub print_aboutme_content_template {
1.5       ehlerst    65: 	my ($r,$allowed,$target,$syllabusfields_ref,$syllabus_ref) = @_;
                     66: 	my %syllabusfields = %{$syllabusfields_ref};
                     67: 	my %syllabus = %{$syllabus_ref};
1.28      bisitz     68: 
1.5       ehlerst    69:        foreach my $field (sort(keys(%syllabusfields))) {
                     70:           if (($syllabus{$field}) || ($allowed)) {
                     71:               my $message=$syllabus{$field};
1.40      faziophi   72:               if (!&Apache::lonfeedback::contains_block_html($message)) {
                     73:               	&Apache::lonfeedback::newline_to_br(\$message);
                     74:               }
1.41      www        75:               $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
1.5       ehlerst    76:               if ($allowed) {
                     77:                   $message=&Apache::lonspeller::markeduptext($message);
                     78:               }
                     79:               $message=&Apache::lontexconvert::msgtexconverted($message);
                     80:               if ($target ne 'tex') {
1.15      neumanie   81: 		    if($field eq 'aaa_contactinfo') {
1.16      neumanie   82: 				$r->print('<div class="LC_Clear_AboutMe_Image" >&nbsp;</div>');
1.36      bisitz     83: 				&print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
1.33      bisitz     84: 		    } else {
1.36      bisitz     85: 			  &print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
1.15      neumanie   86: 		    }
1.38      amueller   87: 			if($allowed) {
                     88:                &print_editbox_template($r,$syllabus{$field},$field);
                     89: 			}
1.31      bisitz     90: 
1.5       ehlerst    91:               } else {
                     92:                      $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
                     93:                                &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
                     94:               }
                     95:           }
                     96:        }
1.28      bisitz     97: 
1.5       ehlerst    98: }
1.1       amueller   99: 
1.33      bisitz    100: sub send_message {
1.8       ehlerst   101: 	my ($r,$cnum,$cdom) = @_;
1.39      raeburn   102: 	my $linktext = &mt('Send message to [_1]',
                    103: 			   &Apache::loncommon::plainname($cnum,$cdom));
1.38      amueller  104: 	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   105: 	return &Apache::loncommon::messagewrapper($image,$cnum,$cdom).' '.&Apache::loncommon::messagewrapper($linktext,$cnum,$cdom);
1.8       ehlerst   106: }
1.7       ehlerst   107: 
1.35      bisitz    108: sub print_template {
1.28      bisitz    109: 	my ($r,$topic,$content, $allowed,$boxclass) = @_;
                    110: 	$r->print('<div class="'.$boxclass.'">');
1.13      harmsja   111: 	$r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
1.35      bisitz    112: 	$r->print($content);
1.1       amueller  113: 	$r->print('</div>');
                    114: }
1.33      bisitz    115: 
1.35      bisitz    116: sub print_start_template {
1.45.6.4! raeburn   117: 	my ($r,$topic,$boxclass,$id,$display) = @_;
        !           118:         my $idattrib;
        !           119:         if ($id ne '') {
        !           120:             $idattrib = ' id="'.$id.'"';
        !           121:         }
        !           122: 	$r->print('<div class="'.$boxclass.'"'.$idattrib.$display.'>');
1.20      neumanie  123: 	$r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
                    124: }
1.33      bisitz    125: 
1.35      bisitz    126: sub print_end_template {
1.20      neumanie  127: 	my ($r) = @_;
                    128: 	$r->print('</div>');
                    129: }
1.33      bisitz    130: 
1.35      bisitz    131: sub print_editbox_template {
1.1       amueller  132: 	my ($r,$content,$field) = @_;
1.10      ehlerst   133: 	$r->print('<textarea cols="81" rows="6" name="'.$field.'">'.
1.45.6.3  raeburn   134:                   &HTML::Entities::encode($content,'"&<>').
                    135:                   '</textarea><br />'."\n");
                    136: 	&print_saveall_template($r);
1.1       amueller  137: }
1.27      bisitz    138: 
1.42      faziophi  139: sub print_textarea_template {
                    140: 	my ($r, $content, $field, $wysiwyg) = @_;
                    141: 	$r->print('<textarea cols="81" rows="6" class="'.$wysiwyg.'" id="'.$field.'" name="'.$field.'">'.
                    142: 						  &HTML::Entities::encode($content, '"&<>').
                    143: 			'</textarea><br />');
                    144: }
                    145: 
                    146: sub print_saveall_template {
                    147: 	my ($r) = @_;
                    148: 	$r->print('<input type="submit" name="storesyl" value="'.&mt('Save All').'" />');
                    149: }
                    150: 
1.43      faziophi  151: sub print_template_fields {
1.45.6.4! raeburn   152: 	my ($r, $data_ref, $fields_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group,
        !           153:             $displayref,$noshowref) = @_;
1.43      faziophi  154: 	my @html_ids = ();
                    155: 	my %data = %{$data_ref};
                    156: 	my %fields = %{$fields_ref};
                    157: 	my %custom_handlers = %{$custom_handlers_ref};
1.45.6.4! raeburn   158:         my (%displays,%noshow);
        !           159:         if (ref($displayref) eq 'HASH') {
        !           160:             %displays = %{$displayref};
        !           161:         }
        !           162:         if (ref($noshowref) eq 'HASH') {
        !           163:             %noshow = %{$noshowref};
        !           164:         }
1.43      faziophi  165: 	foreach my $field (sort(keys(%fields))) {
                    166: 		my $message = $data{$field} if (($data{$field}=~/\w/) || ($allowed));
1.45.6.4! raeburn   167:                 my $display = $displays{$field};
        !           168:                 unless ($allowed) {
        !           169:                     next if ($noshow{$field});
        !           170:                 }
1.45.6.1  raeburn   171:                 if ((%custom_handlers) && ($custom_handlers{$field})) {
1.45.6.4! raeburn   172: 			$custom_handlers{$field}->($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display);
1.43      faziophi  173: 		} else {
                    174: 			if (($data{$field}=~/\w/) || ($allowed)) {
1.45.6.1  raeburn   175:                                 if (!&Apache::lonfeedback::contains_block_html($message)) {
                    176:                                         &Apache::lonfeedback::newline_to_br(\$message);
                    177:                                 } else {
                    178:                                         $message = &Apache::lonfeedback::tidy_html($message);
                    179:                                 }
                    180:                                 $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
                    181:                                 if ($allowed) {
                    182:                                         $message=&Apache::lonspeller::markeduptext($message);
                    183:                                 }
                    184:                                 $message=&Apache::lontexconvert::msgtexconverted($message);
1.43      faziophi  185: 				if ($target ne 'tex') {
                    186: 					#output of syllabusfields will be generated here. 
1.45.6.4! raeburn   187: 					&Apache::lontemplate::print_start_template($r,$fields{$field},'LC_Box','box_'.$field,$display);
1.43      faziophi  188: 					$r->print($message);
                    189: 					if ($allowed) {
                    190: 						$r->print("<br /><div>");
                    191: 						&Apache::lontemplate::print_textarea_template($r, $data{$field},
                    192: 							$field, $default_rich_text);
1.45.6.3  raeburn   193: 						&print_saveall_template($r);
1.43      faziophi  194: 						$r->print("</div>");
                    195: 					} 
                    196: 					&Apache::lontemplate::print_end_template($r);
                    197: 				} else {
                    198: 				    my $safeinit;
1.45      www       199:                                     if ($fields{$field}=~/\w/) {
                    200:                                        $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$fields{$field}.'</h3>'));
                    201:                                     } else {
                    202:                                        $r->print(&Apache::lonxml::xmlparse($r,'tex','<br />'));
                    203:                                     }
                    204:                                     $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
1.43      faziophi  205: 				}
                    206: 				push(@html_ids,$field);
                    207: 			}
                    208: 		}
                    209: 	}
                    210: 	
                    211: 	return @html_ids;	
                    212: }
                    213: 
1.1       amueller  214: 1;

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