Lines 47-60
use C4::Auth;
Link Here
|
47 |
use C4::Context; |
47 |
use C4::Context; |
48 |
use C4::Output; |
48 |
use C4::Output; |
49 |
use C4::Branch; # GetBranches |
49 |
use C4::Branch; # GetBranches |
|
|
50 |
use C4::Letters; |
50 |
use C4::Members::Attributes; |
51 |
use C4::Members::Attributes; |
51 |
|
52 |
|
52 |
# _letter_from_where($branchcode,$module, $code) |
53 |
# _letter_from_where($branchcode,$module, $code, $mtt) |
53 |
# - return FROM WHERE clause and bind args for a letter |
54 |
# - return FROM WHERE clause and bind args for a letter |
54 |
sub _letter_from_where { |
55 |
sub _letter_from_where { |
55 |
my ($branchcode, $module, $code) = @_; |
56 |
my ($branchcode, $module, $code, $mtt) = @_; |
56 |
my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?}; |
57 |
my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?}; |
57 |
my @args = ($branchcode || '', $module, $code); |
58 |
$sql .= q{ AND message_transport_type = ?} if $mtt ne '*'; |
|
|
59 |
my @args = ( $branchcode || '', $module, $code, ($mtt ne '*' ? $mtt : ()) ); |
58 |
# Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that |
60 |
# Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that |
59 |
# work with foreign key constraint I wonder... |
61 |
# work with foreign key constraint I wonder... |
60 |
|
62 |
|
Lines 68-79
sub _letter_from_where {
Link Here
|
68 |
return ($sql, \@args); |
70 |
return ($sql, \@args); |
69 |
} |
71 |
} |
70 |
|
72 |
|
71 |
# letter_exists($branchcode,$module, $code) |
73 |
# get_letters($branchcode,$module, $code, $mtt) |
72 |
# - return true if a letter with the given $branchcode, $module and $code exists |
74 |
# - return letters with the given $branchcode, $module, $code and $mtt exists |
73 |
sub letter_exists { |
75 |
sub get_letters { |
74 |
my ($sql, $args) = _letter_from_where(@_); |
76 |
my ($sql, $args) = _letter_from_where(@_); |
75 |
my $dbh = C4::Context->dbh; |
77 |
my $dbh = C4::Context->dbh; |
76 |
my $letter = $dbh->selectrow_hashref("SELECT * $sql", undef, @$args); |
78 |
my $letter = $dbh->selectall_hashref("SELECT * $sql", 'message_transport_type', undef, @$args); |
77 |
return $letter; |
79 |
return $letter; |
78 |
} |
80 |
} |
79 |
|
81 |
|
Lines 90-96
my $searchfield = $input->param('searchfield');
Link Here
|
90 |
my $script_name = '/cgi-bin/koha/tools/letter.pl'; |
92 |
my $script_name = '/cgi-bin/koha/tools/letter.pl'; |
91 |
our $branchcode = $input->param('branchcode'); |
93 |
our $branchcode = $input->param('branchcode'); |
92 |
my $code = $input->param('code'); |
94 |
my $code = $input->param('code'); |
93 |
my $module = $input->param('module'); |
95 |
my $module = $input->param('module') || ''; |
94 |
my $content = $input->param('content'); |
96 |
my $content = $input->param('content'); |
95 |
my $op = $input->param('op') || ''; |
97 |
my $op = $input->param('op') || ''; |
96 |
my $dbh = C4::Context->dbh; |
98 |
my $dbh = C4::Context->dbh; |
Lines 135-141
elsif ( $op eq 'delete_confirm' ) {
Link Here
|
135 |
delete_confirm($branchcode, $module, $code); |
137 |
delete_confirm($branchcode, $module, $code); |
136 |
} |
138 |
} |
137 |
elsif ( $op eq 'delete_confirmed' ) { |
139 |
elsif ( $op eq 'delete_confirmed' ) { |
138 |
delete_confirmed($branchcode, $module, $code); |
140 |
my $mtt = $input->param('message_transport_type'); |
|
|
141 |
delete_confirmed($branchcode, $module, $code, $mtt); |
139 |
$op = q{}; # next operation is to return to default screen |
142 |
$op = q{}; # next operation is to return to default screen |
140 |
} |
143 |
} |
141 |
else { |
144 |
else { |
Lines 152-176
if ($op) {
Link Here
|
152 |
output_html_with_http_headers $input, $cookie, $template->output; |
155 |
output_html_with_http_headers $input, $cookie, $template->output; |
153 |
|
156 |
|
154 |
sub add_form { |
157 |
sub add_form { |
155 |
my ($branchcode,$module, $code ) = @_; |
158 |
my ( $branchcode,$module, $code ) = @_; |
156 |
|
159 |
|
157 |
my $letter; |
160 |
my $letters; |
158 |
# if code has been passed we can identify letter and its an update action |
161 |
# if code has been passed we can identify letter and its an update action |
159 |
if ($code) { |
162 |
if ($code) { |
160 |
$letter = letter_exists($branchcode,$module, $code); |
163 |
$letters = get_letters($branchcode,$module, $code, '*'); |
161 |
} |
164 |
} |
162 |
if ($letter) { |
165 |
|
163 |
$template->param( modify => 1 ); |
166 |
my $message_transport_types = GetMessageTransportTypes(); |
164 |
$template->param( code => $letter->{code} ); |
167 |
my @letter_loop; |
|
|
168 |
if ($letters) { |
169 |
my $first_flag = 1; |
170 |
for my $mtt ( @$message_transport_types ) { |
171 |
if ( $first_flag ) { |
172 |
$template->param( |
173 |
modify => 1, |
174 |
code => $code, |
175 |
branchcode => $branchcode, |
176 |
name => $letters->{$mtt}{name}, |
177 |
); |
178 |
$first_flag = 0; |
179 |
} |
180 |
|
181 |
push @letter_loop, { |
182 |
message_transport_type => $mtt, |
183 |
is_html => $letters->{$mtt}{is_html}, |
184 |
title => $letters->{$mtt}{title}, |
185 |
content => $letters->{$mtt}{content}, |
186 |
}; |
187 |
} |
165 |
} |
188 |
} |
166 |
else { # initialize the new fields |
189 |
else { # initialize the new fields |
167 |
$letter = { |
190 |
for my $mtt ( @$message_transport_types ) { |
|
|
191 |
$mtt = $mtt->{message_transport_type}; |
192 |
push @letter_loop, { |
193 |
message_transport_type => $mtt, |
194 |
} |
195 |
} |
196 |
$template->param( |
168 |
branchcode => $branchcode, |
197 |
branchcode => $branchcode, |
169 |
module => $module, |
198 |
module => $module, |
170 |
}; |
199 |
); |
171 |
$template->param( adding => 1 ); |
200 |
$template->param( adding => 1 ); |
172 |
} |
201 |
} |
173 |
|
202 |
|
|
|
203 |
$template->param( |
204 |
letters => \@letter_loop, |
205 |
); |
206 |
|
174 |
my $field_selection; |
207 |
my $field_selection; |
175 |
push @{$field_selection}, add_fields('branches'); |
208 |
push @{$field_selection}, add_fields('branches'); |
176 |
if ($module eq 'reserves') { |
209 |
if ($module eq 'reserves') { |
Lines 212-224
sub add_form {
Link Here
|
212 |
} |
245 |
} |
213 |
|
246 |
|
214 |
$template->param( |
247 |
$template->param( |
215 |
branchcode => $letter->{branchcode}, |
|
|
216 |
name => $letter->{name}, |
217 |
is_html => $letter->{is_html}, |
218 |
title => $letter->{title}, |
219 |
content => $letter->{content}, |
220 |
module => $module, |
248 |
module => $module, |
221 |
$module => 1, |
|
|
222 |
branchloop => _branchloop($branchcode), |
249 |
branchloop => _branchloop($branchcode), |
223 |
SQLfieldname => $field_selection, |
250 |
SQLfieldname => $field_selection, |
224 |
); |
251 |
); |
Lines 233-254
sub add_validate {
Link Here
|
233 |
my $oldmodule = $input->param('oldmodule'); |
260 |
my $oldmodule = $input->param('oldmodule'); |
234 |
my $code = $input->param('code'); |
261 |
my $code = $input->param('code'); |
235 |
my $name = $input->param('name'); |
262 |
my $name = $input->param('name'); |
236 |
my $is_html = $input->param('is_html'); |
263 |
my @mtt = $input->param('message_transport_type'); |
237 |
my $title = $input->param('title'); |
264 |
my @title = $input->param('title'); |
238 |
my $content = $input->param('content'); |
265 |
my @content = $input->param('content'); |
239 |
if (letter_exists($oldbranchcode,$oldmodule, $code)) { |
266 |
for my $mtt ( @mtt ) { |
240 |
$dbh->do( |
267 |
my $is_html = $input->param("is_html_$mtt"); |
241 |
q{UPDATE letter SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ? WHERE branchcode = ? AND module = ? AND code = ?}, |
268 |
my $title = shift @title; |
242 |
undef, |
269 |
my $content = shift @content; |
243 |
$branchcode, $module, $name, $is_html || 0, $title, $content, |
270 |
my $letter = get_letters($oldbranchcode,$oldmodule, $code, $mtt); |
244 |
$oldbranchcode, $oldmodule, $code |
271 |
unless ( $title and $content ) { |
245 |
); |
272 |
delete_confirmed( $oldbranchcode, $oldmodule, $code, $mtt ); |
246 |
} else { |
273 |
next; |
247 |
$dbh->do( |
274 |
} |
248 |
q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content) VALUES (?,?,?,?,?,?,?)}, |
275 |
if ( exists $letter->{$mtt} ) { |
249 |
undef, |
276 |
$dbh->do( |
250 |
$branchcode, $module, $code, $name, $is_html || 0, $title, $content |
277 |
q{ |
251 |
); |
278 |
UPDATE letter |
|
|
279 |
SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ? |
280 |
WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ? |
281 |
}, |
282 |
undef, |
283 |
$branchcode, $module, $name, $is_html || 0, $title, $content, |
284 |
$oldbranchcode, $oldmodule, $code, $mtt |
285 |
); |
286 |
} else { |
287 |
$dbh->do( |
288 |
q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)}, |
289 |
undef, |
290 |
$branchcode, $module, $code, $name, $is_html || 0, $title, $content, $mtt |
291 |
); |
292 |
} |
252 |
} |
293 |
} |
253 |
# set up default display |
294 |
# set up default display |
254 |
default_display($branchcode); |
295 |
default_display($branchcode); |
Lines 261-291
sub add_copy {
Link Here
|
261 |
my $module = $input->param('module'); |
302 |
my $module = $input->param('module'); |
262 |
my $code = $input->param('code'); |
303 |
my $code = $input->param('code'); |
263 |
|
304 |
|
264 |
return if letter_exists($branchcode,$module, $code); |
305 |
return if keys %{ get_letters($branchcode,$module, $code, '*') }; |
265 |
|
306 |
|
266 |
my $old_letter = letter_exists($oldbranchcode,$module, $code); |
307 |
my $old_letters = get_letters($oldbranchcode,$module, $code, '*'); |
267 |
|
308 |
|
268 |
$dbh->do( |
309 |
my $message_transport_types = GetMessageTransportTypes(); |
269 |
q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content) VALUES (?,?,?,?,?,?,?)}, |
310 |
for my $mtt ( @$message_transport_types ) { |
270 |
undef, |
311 |
next unless exists $old_letters->{$mtt}; |
271 |
$branchcode, $module, $code, $old_letter->{name}, $old_letter->{is_html}, $old_letter->{title}, $old_letter->{content} |
312 |
my $old_letter = $old_letters->{$mtt}; |
272 |
); |
313 |
|
|
|
314 |
$dbh->do( |
315 |
q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,?,?,?,?,?,?,?)}, |
316 |
undef, |
317 |
$branchcode, $module, $code, $old_letter->{name}, $old_letter->{is_html}, $old_letter->{title}, $old_letter->{content}, $mtt |
318 |
); |
319 |
} |
273 |
} |
320 |
} |
274 |
|
321 |
|
275 |
sub delete_confirm { |
322 |
sub delete_confirm { |
276 |
my ($branchcode, $module, $code) = @_; |
323 |
my ($branchcode, $module, $code) = @_; |
277 |
my $dbh = C4::Context->dbh; |
324 |
my $dbh = C4::Context->dbh; |
278 |
my $letter = letter_exists($branchcode, $module, $code); |
325 |
my $letter = get_letters($branchcode, $module, $code, '*'); |
279 |
$template->param( branchcode => $branchcode, branchname => GetBranchName($branchcode) ); |
326 |
my @values = values %$letter; |
280 |
$template->param( code => $code ); |
327 |
$template->param( |
281 |
$template->param( module => $module); |
328 |
branchcode => $branchcode, |
282 |
$template->param( name => $letter->{name}); |
329 |
branchname => GetBranchName($branchcode), |
|
|
330 |
code => $code, |
331 |
module => $module, |
332 |
name => $values[0]->{name}, |
333 |
); |
283 |
return; |
334 |
return; |
284 |
} |
335 |
} |
285 |
|
336 |
|
286 |
sub delete_confirmed { |
337 |
sub delete_confirmed { |
287 |
my ($branchcode, $module, $code) = @_; |
338 |
my ($branchcode, $module, $code, $mtt) = @_; |
288 |
my ($sql, $args) = _letter_from_where($branchcode, $module, $code); |
339 |
my ($sql, $args) = _letter_from_where($branchcode, $module, $code, $mtt); |
289 |
my $dbh = C4::Context->dbh; |
340 |
my $dbh = C4::Context->dbh; |
290 |
$dbh->do("DELETE $sql", undef, @$args); |
341 |
$dbh->do("DELETE $sql", undef, @$args); |
291 |
# setup default display for screen |
342 |
# setup default display for screen |
Lines 302-308
sub retrieve_letters {
Link Here
|
302 |
my ($sql, @where, @args); |
353 |
my ($sql, @where, @args); |
303 |
$sql = "SELECT branchcode, module, code, name, branchname |
354 |
$sql = "SELECT branchcode, module, code, name, branchname |
304 |
FROM letter |
355 |
FROM letter |
305 |
LEFT OUTER JOIN branches USING (branchcode)"; |
356 |
LEFT OUTER JOIN branches USING (branchcode) |
|
|
357 |
"; |
306 |
if ($searchstring && $searchstring=~m/(\S+)/) { |
358 |
if ($searchstring && $searchstring=~m/(\S+)/) { |
307 |
$searchstring = $1 . q{%}; |
359 |
$searchstring = $1 . q{%}; |
308 |
push @where, 'code LIKE ?'; |
360 |
push @where, 'code LIKE ?'; |
Lines 318-325
sub retrieve_letters {
Link Here
|
318 |
} |
370 |
} |
319 |
|
371 |
|
320 |
$sql .= " WHERE ".join(" AND ", @where) if @where; |
372 |
$sql .= " WHERE ".join(" AND ", @where) if @where; |
|
|
373 |
$sql .= " GROUP BY branchcode,module,code"; |
321 |
$sql .= " ORDER BY module, code, branchcode"; |
374 |
$sql .= " ORDER BY module, code, branchcode"; |
322 |
# use Data::Dumper; die Dumper($sql, \@args); |
375 |
|
323 |
return $dbh->selectall_arrayref($sql, { Slice => {} }, @args); |
376 |
return $dbh->selectall_arrayref($sql, { Slice => {} }, @args); |
324 |
} |
377 |
} |
325 |
|
378 |
|
326 |
- |
|
|