Lines 7-23
Link Here
|
7 |
# ALGO : |
7 |
# ALGO : |
8 |
# this script use an $op to know what to do. |
8 |
# this script use an $op to know what to do. |
9 |
# if $op is empty or none of the above values, |
9 |
# if $op is empty or none of the above values, |
10 |
# - the default screen is build (with all records, or filtered datas). |
10 |
# - the default screen is build (with all records, or filtered datas). |
11 |
# - the user can clic on add, modify or delete record. |
11 |
# - the user can clic on add, modify or delete record. |
12 |
# if $op=add_form |
12 |
# if $op=add_form |
13 |
# - if primkey exists, this is a modification,so we read the $primkey record |
13 |
# - if primkey exists, this is a modification,so we read the $primkey record |
14 |
# - builds the add/modify form |
14 |
# - builds the add/modify form |
15 |
# if $op=add_validate |
15 |
# if $op=add_validate |
16 |
# - the user has just send datas, so we create/modify the record |
16 |
# - the user has just send datas, so we create/modify the record |
17 |
# if $op=delete_form |
17 |
# if $op=delete_form |
18 |
# - we show the record having primkey=$primkey and ask for deletion validation form |
18 |
# - we show the record having primkey=$primkey and ask for deletion validation form |
19 |
# if $op=delete_confirm |
19 |
# if $op=delete_confirm |
20 |
# - we delete the record having primkey=$primkey |
20 |
# - we delete the record having primkey=$primkey |
21 |
|
21 |
|
22 |
|
22 |
|
23 |
# Copyright 2000-2002 Katipo Communications |
23 |
# Copyright 2000-2002 Katipo Communications |
Lines 43-61
use CGI qw ( -utf8 );
Link Here
|
43 |
use C4::Context; |
43 |
use C4::Context; |
44 |
use C4::Output; |
44 |
use C4::Output; |
45 |
use C4::Auth; |
45 |
use C4::Auth; |
46 |
|
46 |
use C4::Printer qw(GetPrinterDetails SearchPrinters AddPrinter UpdatePrinter DeletePrinter); |
47 |
sub StringSearch { |
|
|
48 |
my ($searchstring,$type)=@_; # why bother with $type if we don't use it?! |
49 |
$searchstring=~ s/\'/\\\'/g; |
50 |
my @data=split(' ',$searchstring); |
51 |
my $sth = C4::Context->dbh->prepare(" |
52 |
SELECT printername,printqueue,printtype from printers |
53 |
WHERE (printername like ?) order by printername |
54 |
"); |
55 |
$sth->execute("$data[0]%"); |
56 |
my $data=$sth->fetchall_arrayref({}); |
57 |
return (scalar(@$data),$data); |
58 |
} |
59 |
|
47 |
|
60 |
my $input = new CGI; |
48 |
my $input = new CGI; |
61 |
my $searchfield=$input->param('searchfield'); |
49 |
my $searchfield=$input->param('searchfield'); |
Lines 78-152
my ($template, $loggedinuser, $cookie) = get_template_and_user(
Link Here
|
78 |
} |
66 |
} |
79 |
); |
67 |
); |
80 |
|
68 |
|
81 |
$template->param(searchfield => $searchfield, |
|
|
82 |
script_name => $script_name); |
83 |
|
84 |
#start the page and read in includes |
69 |
#start the page and read in includes |
85 |
|
70 |
|
86 |
my $dbh = C4::Context->dbh; |
71 |
my $dbh = C4::Context->dbh; |
|
|
72 |
my $list_printers = 1; |
87 |
################## ADD_FORM ################################## |
73 |
################## ADD_FORM ################################## |
88 |
# called by default. Used to create form to add or modify a record |
74 |
# called by default. Used to create form to add or modify a record |
89 |
if ($op eq 'add_form') { |
75 |
if ($op eq 'add_form') { |
90 |
$template->param(add_form => 1); |
76 |
$list_printers = 0; |
91 |
#---- if primkey exists, it's a modify action, so read values to modify... |
77 |
$template->param(add_form => 1); |
92 |
my $data; |
78 |
#---- if primkey exists, it's a modify action, so read values to modify... |
93 |
if ($searchfield) { |
79 |
my $data; |
94 |
my $sth=$dbh->prepare("SELECT printername,printqueue,printtype from printers where printername=?"); |
80 |
if ($searchfield) { |
95 |
$sth->execute($searchfield); |
81 |
$data=GetPrinterDetails($searchfield); |
96 |
$data=$sth->fetchrow_hashref; |
82 |
} |
97 |
} |
83 |
|
98 |
|
84 |
$template->param( |
99 |
$template->param(printqueue => $data->{'printqueue'}, |
85 |
printqueue => $data->{'printqueue'}, |
100 |
printtype => $data->{'printtype'}); |
86 |
printername => $data->{'printername'}, |
101 |
# END $OP eq ADD_FORM |
87 |
printtype => $data->{'printtype'} |
|
|
88 |
); |
89 |
# END $OP eq ADD_FORM |
102 |
################## ADD_VALIDATE ################################## |
90 |
################## ADD_VALIDATE ################################## |
103 |
# called by add_form, used to insert/modify data in DB |
91 |
# called by add_form, used to insert/modify data in DB |
104 |
} elsif ($op eq 'add_validate') { |
92 |
} elsif ($op eq 'add_validate') { |
105 |
$template->param(add_validate => 1); |
93 |
my $params = $input->Vars; |
106 |
if ($input->param('add')){ |
94 |
if ($input->param('add')){ |
107 |
my $sth=$dbh->prepare("INSERT INTO printers (printername,printqueue,printtype) VALUES (?,?,?)"); |
95 |
AddPrinter($params); |
108 |
$sth->execute($input->param('printername'),$input->param('printqueue'),$input->param('printtype')); |
96 |
} else { |
109 |
} else { |
97 |
UpdatePrinter($searchfield, $params); |
110 |
my $sth=$dbh->prepare("UPDATE printers SET printqueue=?,printtype=? WHERE printername=?"); |
98 |
} |
111 |
$sth->execute($input->param('printqueue'),$input->param('printtype'),$input->param('printername')); |
99 |
$template->param(add_validate => 1); |
112 |
} |
100 |
$searchfield = ''; |
113 |
# END $OP eq ADD_VALIDATE |
101 |
# END $OP eq ADD_VALIDATE |
114 |
################## DELETE_CONFIRM ################################## |
102 |
################## DELETE_CONFIRM ################################## |
115 |
# called by default form, used to confirm deletion of data in DB |
103 |
# called by default form, used to confirm deletion of data in DB |
116 |
} elsif ($op eq 'delete_confirm') { |
104 |
} elsif ($op eq 'delete_confirm') { |
117 |
$template->param(delete_confirm => 1); |
105 |
$list_printers = 0; |
118 |
my $sth=$dbh->prepare("select printername,printqueue,printtype from printers where printername=?"); |
106 |
my $data=GetPrinterDetails($searchfield); |
119 |
$sth->execute($searchfield); |
107 |
my $branches = $data->{branches}; |
120 |
my $data=$sth->fetchrow_hashref; |
108 |
if ($branches && $branches > 0) { |
121 |
$template->param(printqueue => $data->{'printqueue'}, |
109 |
$template->param(cannot_delete_branches => $branches); |
122 |
printtype => $data->{'printtype'}); |
110 |
$template->param(add_form => 1); |
123 |
# END $OP eq DELETE_CONFIRM |
111 |
} else { |
|
|
112 |
$template->param(delete_confirm => 1); |
113 |
} |
114 |
$template->param( |
115 |
printqueue => $data->{'printqueue'}, |
116 |
printtype => $data->{'printtype'}, |
117 |
); |
118 |
# END $OP eq DELETE_CONFIRM |
124 |
################## DELETE_CONFIRMED ################################## |
119 |
################## DELETE_CONFIRMED ################################## |
125 |
# called by delete_confirm, used to effectively confirm deletion of data in DB |
120 |
# called by delete_confirm, used to effectively confirm deletion of data in DB |
126 |
} elsif ($op eq 'delete_confirmed') { |
121 |
} elsif ($op eq 'delete_confirmed') { |
127 |
$template->param(delete_confirmed => 1); |
122 |
# XXX Delete can fail |
128 |
my $sth=$dbh->prepare("delete from printers where printername=?"); |
123 |
DeletePrinter($searchfield); |
129 |
$sth->execute($searchfield); |
124 |
$template->param(delete_confirmed => 1); |
130 |
# END $OP eq DELETE_CONFIRMED |
125 |
$template->param(list_printers => 1); |
|
|
126 |
$searchfield = ''; |
127 |
# END $OP eq DELETE_CONFIRMED |
131 |
################## DEFAULT ########################################### |
128 |
################## DEFAULT ########################################### |
132 |
} else { # DEFAULT |
129 |
} else { # DEFAULT |
133 |
$template->param(else => 1); |
130 |
$searchfield ||= $input->param('description') || ""; |
134 |
my ($count,$results)=StringSearch($searchfield,'web'); |
|
|
135 |
my $max = ($offset+$pagesize < $count) ? $offset+$pagesize : $count; |
136 |
my @loop = (@$results)[$offset..$max]; |
137 |
|
138 |
$template->param(loop => \@loop); |
139 |
|
140 |
if ($offset>0) { |
141 |
$template->param(offsetgtzero => 1, |
142 |
prevpage => $offset-$pagesize); |
143 |
} |
144 |
if ($offset+$pagesize<$count) { |
145 |
$template->param(ltcount => 1, |
146 |
nextpage => $offset+$pagesize); |
147 |
} |
148 |
|
149 |
} #---- END $OP eq DEFAULT |
131 |
} #---- END $OP eq DEFAULT |
150 |
|
132 |
|
|
|
133 |
if ($list_printers) { |
134 |
$template->param(list_printers => 1); |
135 |
my $results=SearchPrinters($searchfield); |
136 |
my $count = $results ? scalar(@$results) : 0; |
137 |
my $max = ($offset+$pagesize < $count) ? $offset+$pagesize : $count; |
138 |
my @loop = (@$results)[$offset..$max-1]; |
139 |
|
140 |
$template->param(loop => \@loop); |
141 |
|
142 |
if ($offset>0) { |
143 |
$template->param(offsetgtzero => 1, |
144 |
prevpage => $offset-$pagesize); |
145 |
} |
146 |
if ($offset+$pagesize<$count) { |
147 |
$template->param(ltcount => 1, |
148 |
nextpage => $offset+$pagesize); |
149 |
} |
150 |
} |
151 |
|
152 |
$template->param( |
153 |
searchfield => $searchfield, |
154 |
script_name => $script_name |
155 |
); |
156 |
|
151 |
output_html_with_http_headers $input, $cookie, $template->output; |
157 |
output_html_with_http_headers $input, $cookie, $template->output; |
152 |
|
158 |
|