1: # The LearningOnline Network
2: # "Template" Functions to generate html output
3: #
4: # $Id: lontemplate.pm,v 1.52 2025/01/28 19:49:20 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::lonhtmlgateway;
44: use Apache::lonmsgdisplay();
45: use HTML::Entities();
46:
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: };
54:
55: sub start_columnSection {
56: my ($r) = @_;
57: $r->print('<div class="LC_columnSection">');
58: }
59:
60: sub end_columnSection {
61: my ($r) = @_;
62: $r->print('</div>');
63: }
64:
65: sub print_aboutme_content_template {
66: my ($r,$allowed,$target,$syllabusfields_ref,$syllabus_ref) = @_;
67: my %syllabusfields = %{$syllabusfields_ref};
68: my %syllabus = %{$syllabus_ref};
69:
70: foreach my $field (sort(keys(%syllabusfields))) {
71: if (($syllabus{$field}) || ($allowed)) {
72: my $message=$syllabus{$field};
73: if (!&Apache::lonfeedback::contains_block_html($message)) {
74: &Apache::lonfeedback::newline_to_br(\$message);
75: }
76: $message=&Apache::lonhtmlcommon::raw_href_to_link($message);
77: if ($allowed) {
78: $message=&Apache::lonspeller::markeduptext($message);
79: }
80: $message=&Apache::lontexconvert::msgtexconverted($message);
81: if ($target ne 'tex') {
82: if($field eq 'aaa_contactinfo') {
83: $r->print('<div class="LC_Clear_AboutMe_Image" > </div>');
84: &print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
85: } else {
86: &print_template($r,$syllabusfields{$field},$message,$allowed,'LC_Box');
87: }
88: if($allowed) {
89: &print_editbox_template($r,$syllabus{$field},$field,$syllabusfields{$field});
90: }
91:
92: } else {
93: $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
94: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
95: }
96: }
97: }
98:
99: }
100:
101: sub send_message {
102: my ($r,$cnum,$cdom) = @_;
103: my $linktext = &mt('Send message to [_1]',
104: &Apache::loncommon::plainname($cnum,$cdom));
105: my $image = qq{<img name="Send_message" alt="Send message symbol" src="/res/adm/pages/mail-message-new.png" border="none" align="middle" />};
106: return &Apache::loncommon::messagewrapper($image,$cnum,$cdom).' '.&Apache::loncommon::messagewrapper($linktext,$cnum,$cdom);
107: }
108:
109: sub print_template {
110: my ($r,$topic,$content, $allowed,$boxclass) = @_;
111: $r->print('<div class="'.$boxclass.'">');
112: $r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
113: $r->print($content);
114: $r->print('</div>');
115: }
116:
117: sub print_start_template {
118: my ($r,$topic,$boxclass,$id,$display) = @_;
119: my $idattrib;
120: if ($id ne '') {
121: $idattrib = ' id="'.$id.'"';
122: }
123: $r->print('<div class="'.$boxclass.'"'.$idattrib.$display.'>');
124: $r->print('<h4 class="LC_hcell">'.$topic.'</h4>');
125: }
126:
127: sub print_end_template {
128: my ($r) = @_;
129: $r->print('</div>');
130: }
131:
132: sub print_editbox_template {
133: my ($r,$content,$field,$fieldname) = @_;
134: my $labeltext = &HTML::Entities::encode(&mt('Edit [_1]',$fieldname),'"&<>');
135: $r->print('<textarea cols="81" rows="6" name="'.$field.'" aria-label="'.$labeltext.'">'.
136: &HTML::Entities::encode($content,'"&<>').
137: '</textarea><br />'."\n");
138: &print_saveall_template($r);
139: }
140:
141: sub print_textarea_template {
142: my ($r, $content, $field, $fieldname, $wysiwyg) = @_;
143: my $labeltext = &HTML::Entities::encode(&mt('Edit [_1]',$fieldname),'"&<>');
144: $r->print('<textarea cols="81" rows="6" class="'.$wysiwyg.'" id="'.$field.'" name="'.$field.'" aria-label="'.$labeltext.'">'.
145: &HTML::Entities::encode($content, '"&<>').
146: '</textarea><br />');
147: }
148:
149: sub print_saveall_template {
150: my ($r) = @_;
151: $r->print('<input type="submit" name="storesyl" value="'.&mt('Save All').'" />');
152: }
153:
154: sub print_template_fields {
155: my ($r, $data_ref, $fields_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group,
156: $displayref,$noshowref) = @_;
157: my @html_ids = ();
158: my %data = %{$data_ref};
159: my %fields = %{$fields_ref};
160: my %custom_handlers = %{$custom_handlers_ref};
161: my (%displays,%noshow);
162: if (ref($displayref) eq 'HASH') {
163: %displays = %{$displayref};
164: }
165: if (ref($noshowref) eq 'HASH') {
166: %noshow = %{$noshowref};
167: }
168: foreach my $field (sort(keys(%fields))) {
169: my $message = $data{$field} if (($data{$field}=~/\w/) || ($allowed));
170: my $legacy = 1;
171: my $display = $displays{$field};
172: unless ($allowed) {
173: next if ($noshow{$field});
174: }
175: my $gateway = Apache::lonhtmlgateway->new($target);
176: $message = &Encode::decode('utf8', $message);
177: $message = $gateway->process_outgoing_html($message, $legacy);
178: if ((%custom_handlers) && ($custom_handlers{$field})) {
179: $custom_handlers{$field}->($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display);
180: } else {
181: if (($data{$field}=~/\w/) || ($allowed)) {
182: if ($target ne 'tex') {
183: #output of syllabusfields will be generated here.
184: &Apache::lontemplate::print_start_template($r,$fields{$field},'LC_Box','box_'.$field,$display);
185: $r->print($message);
186: if ($allowed) {
187: $r->print("<br /><div>");
188: &print_textarea_template($r, $data{$field},
189: $field, $fields{$field}, $default_rich_text);
190: &print_saveall_template($r);
191: $r->print("</div>");
192: }
193: &Apache::lontemplate::print_end_template($r);
194: } else {
195: my $safeinit;
196: if ($fields{$field}=~/\w/) {
197: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$fields{$field}.'</h3>'));
198: } else {
199: $r->print(&Apache::lonxml::xmlparse($r,'tex','<br />'));
200: }
201: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
202: }
203: push(@html_ids,$field);
204: }
205: }
206: undef $gateway;
207: }
208:
209: return @html_ids;
210: }
211:
212: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>