File:  [LON-CAPA] / loncom / interface / lontemplate.pm
Revision 1.45.6.4: download - view: text, annotated - select for diffs
Fri May 10 23:48:12 2013 UTC (10 years, 11 months ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0
Diff to branchpoint 1.45: preferred, unified
- For 2.11
  - Backport 1.47, 1.48, 1.49, 1.50.

    1: # The LearningOnline Network
    2: # "Template" Functions to generate html output
    3: #
    4: # $Id: lontemplate.pm,v 1.45.6.4 2013/05/10 23:48:12 raeburn Exp $
    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: 
   29: package Apache::lontemplate;
   30: 
   31: 
   32: use strict;
   33: use utf8;
   34: use Apache::Constants qw(:common);
   35: use Apache::loncommon;
   36: use Apache::lonnet;
   37: use Apache::lonxml;
   38: use Apache::lonspeller;
   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: 
   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: };
   53: 
   54: sub start_columnSection {
   55: 	my ($r) = @_;
   56: 	 $r->print('<div class="LC_columnSection">');
   57: }
   58: 
   59: sub end_columnSection {
   60: 	my ($r) = @_;
   61: 	 $r->print('</div>');
   62: }
   63: 
   64: sub print_aboutme_content_template {
   65: 	my ($r,$allowed,$target,$syllabusfields_ref,$syllabus_ref) = @_;
   66: 	my %syllabusfields = %{$syllabusfields_ref};
   67: 	my %syllabus = %{$syllabus_ref};
   68: 
   69:        foreach my $field (sort(keys(%syllabusfields))) {
   70:           if (($syllabus{$field}) || ($allowed)) {
   71:               my $message=$syllabus{$field};
   72:               if (!&Apache::lonfeedback::contains_block_html($message)) {
   73:               	&Apache::lonfeedback::newline_to_br(\$message);
   74:               }
   75:               $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
   76:               if ($allowed) {
   77:                   $message=&Apache::lonspeller::markeduptext($message);
   78:               }
   79:               $message=&Apache::lontexconvert::msgtexconverted($message);
   80:               if ($target ne 'tex') {
   81: 		    if($field eq 'aaa_contactinfo') {
   82: 				$r->print('<div class="LC_Clear_AboutMe_Image" >&nbsp;</div>');
   83: 				&print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
   84: 		    } else {
   85: 			  &print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
   86: 		    }
   87: 			if($allowed) {
   88:                &print_editbox_template($r,$syllabus{$field},$field);
   89: 			}
   90: 
   91:               } else {
   92:                      $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
   93:                                &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
   94:               }
   95:           }
   96:        }
   97: 
   98: }
   99: 
  100: sub send_message {
  101: 	my ($r,$cnum,$cdom) = @_;
  102: 	my $linktext = &mt('Send message to [_1]',
  103: 			   &Apache::loncommon::plainname($cnum,$cdom));
  104: 	my $image = qq{<img name="Send_message" alt="Send message symbol" src="/res/adm/pages/mail-message-new.png" border="none" align="middle" />};
  105: 	return &Apache::loncommon::messagewrapper($image,$cnum,$cdom).' '.&Apache::loncommon::messagewrapper($linktext,$cnum,$cdom);
  106: }
  107: 
  108: sub print_template {
  109: 	my ($r,$topic,$content, $allowed,$boxclass) = @_;
  110: 	$r->print('<div class="'.$boxclass.'">');
  111: 	$r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
  112: 	$r->print($content);
  113: 	$r->print('</div>');
  114: }
  115: 
  116: sub print_start_template {
  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.'>');
  123: 	$r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
  124: }
  125: 
  126: sub print_end_template {
  127: 	my ($r) = @_;
  128: 	$r->print('</div>');
  129: }
  130: 
  131: sub print_editbox_template {
  132: 	my ($r,$content,$field) = @_;
  133: 	$r->print('<textarea cols="81" rows="6" name="'.$field.'">'.
  134:                   &HTML::Entities::encode($content,'"&<>').
  135:                   '</textarea><br />'."\n");
  136: 	&print_saveall_template($r);
  137: }
  138: 
  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: 
  151: sub print_template_fields {
  152: 	my ($r, $data_ref, $fields_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group,
  153:             $displayref,$noshowref) = @_;
  154: 	my @html_ids = ();
  155: 	my %data = %{$data_ref};
  156: 	my %fields = %{$fields_ref};
  157: 	my %custom_handlers = %{$custom_handlers_ref};
  158:         my (%displays,%noshow);
  159:         if (ref($displayref) eq 'HASH') {
  160:             %displays = %{$displayref};
  161:         }
  162:         if (ref($noshowref) eq 'HASH') {
  163:             %noshow = %{$noshowref};
  164:         }
  165: 	foreach my $field (sort(keys(%fields))) {
  166: 		my $message = $data{$field} if (($data{$field}=~/\w/) || ($allowed));
  167:                 my $display = $displays{$field};
  168:                 unless ($allowed) {
  169:                     next if ($noshow{$field});
  170:                 }
  171:                 if ((%custom_handlers) && ($custom_handlers{$field})) {
  172: 			$custom_handlers{$field}->($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display);
  173: 		} else {
  174: 			if (($data{$field}=~/\w/) || ($allowed)) {
  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);
  185: 				if ($target ne 'tex') {
  186: 					#output of syllabusfields will be generated here. 
  187: 					&Apache::lontemplate::print_start_template($r,$fields{$field},'LC_Box','box_'.$field,$display);
  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);
  193: 						&print_saveall_template($r);
  194: 						$r->print("</div>");
  195: 					} 
  196: 					&Apache::lontemplate::print_end_template($r);
  197: 				} else {
  198: 				    my $safeinit;
  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));
  205: 				}
  206: 				push(@html_ids,$field);
  207: 			}
  208: 		}
  209: 	}
  210: 	
  211: 	return @html_ids;	
  212: }
  213: 
  214: 1;

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