![]() ![]() | ![]() |
- For 2.11 - lonhtmgateway.pm not in 2.11.0
1: # The LearningOnline Network 2: # "Template" Functions to generate html output 3: # 4: # $Id: lontemplate.pm,v 1.45.6.2 2012/05/15 22:52:56 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" > </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) = @_; 118: $r->print('<div class="'.$boxclass.'">'); 119: $r->print('<h4 class="LC_hcell">'.$topic.'</h4>'); 120: } 121: 122: sub print_end_template { 123: my ($r) = @_; 124: $r->print('</div>'); 125: } 126: 127: sub print_editbox_template { 128: my ($r,$content,$field) = @_; 129: $r->print('<textarea cols="81" rows="6" name="'.$field.'">'. 130: &HTML::Entities::encode($content,'"&<>'). 131: '</textarea><br /><input type="submit" name="storesyl" value="'. 132: &mt('Save All').'" />'); 133: } 134: 135: sub print_textarea_template { 136: my ($r, $content, $field, $wysiwyg) = @_; 137: $r->print('<textarea cols="81" rows="6" class="'.$wysiwyg.'" id="'.$field.'" name="'.$field.'">'. 138: &HTML::Entities::encode($content, '"&<>'). 139: '</textarea><br />'); 140: } 141: 142: sub print_saveall_template { 143: my ($r) = @_; 144: $r->print('<input type="submit" name="storesyl" value="'.&mt('Save All').'" />'); 145: } 146: 147: sub print_template_fields { 148: my ($r, $data_ref, $fields_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group) = @_; 149: my @html_ids = (); 150: my %data = %{$data_ref}; 151: my %fields = %{$fields_ref}; 152: my %custom_handlers = %{$custom_handlers_ref}; 153: 154: foreach my $field (sort(keys(%fields))) { 155: my $message = $data{$field} if (($data{$field}=~/\w/) || ($allowed)); 156: if ((%custom_handlers) && ($custom_handlers{$field})) { 157: $custom_handlers{$field}->($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed); 158: } else { 159: if (($data{$field}=~/\w/) || ($allowed)) { 160: if (!&Apache::lonfeedback::contains_block_html($message)) { 161: &Apache::lonfeedback::newline_to_br(\$message); 162: } else { 163: $message = &Apache::lonfeedback::tidy_html($message); 164: } 165: $message=&Apache::lonhtmlcommon::raw_href_to_link($message); 166: if ($allowed) { 167: $message=&Apache::lonspeller::markeduptext($message); 168: } 169: $message=&Apache::lontexconvert::msgtexconverted($message); 170: if ($target ne 'tex') { 171: #output of syllabusfields will be generated here. 172: &Apache::lontemplate::print_start_template($r,$fields{$field},'LC_Box'); 173: $r->print($message); 174: if ($allowed) { 175: $r->print("<br /><div>"); 176: &Apache::lontemplate::print_textarea_template($r, $data{$field}, 177: $field, $default_rich_text); 178: &Apache::lontemplate::print_saveall_template($r); 179: $r->print("</div>"); 180: } 181: &Apache::lontemplate::print_end_template($r); 182: } else { 183: my $safeinit; 184: if ($fields{$field}=~/\w/) { 185: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$fields{$field}.'</h3>')); 186: } else { 187: $r->print(&Apache::lonxml::xmlparse($r,'tex','<br />')); 188: } 189: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message)); 190: } 191: push(@html_ids,$field); 192: } 193: } 194: } 195: 196: return @html_ids; 197: } 198: 199: 1;