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;
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 68-150
my $op = $input->param('op');
Link Here
|
68 |
$searchfield=~ s/\,//g; |
56 |
$searchfield=~ s/\,//g; |
69 |
|
57 |
|
70 |
my ($template, $loggedinuser, $cookie) = get_template_and_user({ |
58 |
my ($template, $loggedinuser, $cookie) = get_template_and_user({ |
71 |
template_name => "admin/printers.tmpl", |
59 |
template_name => "admin/printers.tmpl", |
72 |
query => $input, |
60 |
query => $input, |
73 |
type => "intranet", |
61 |
type => "intranet", |
74 |
authnotrequired => 0, |
62 |
authnotrequired => 0, |
75 |
flagsrequired => {parameters => 'parameters_remaining_permissions'}, |
63 |
flagsrequired => {parameters => 'parameters_remaining_permissions'}, |
76 |
debug => 1, |
64 |
debug => 1, |
77 |
}); |
65 |
}); |
78 |
|
66 |
|
79 |
$template->param(searchfield => $searchfield, |
|
|
80 |
script_name => $script_name); |
81 |
|
82 |
#start the page and read in includes |
67 |
#start the page and read in includes |
83 |
|
68 |
|
84 |
my $dbh = C4::Context->dbh; |
69 |
my $dbh = C4::Context->dbh; |
|
|
70 |
my $list_printers = 1; |
85 |
################## ADD_FORM ################################## |
71 |
################## ADD_FORM ################################## |
86 |
# called by default. Used to create form to add or modify a record |
72 |
# called by default. Used to create form to add or modify a record |
87 |
if ($op eq 'add_form') { |
73 |
if ($op eq 'add_form') { |
88 |
$template->param(add_form => 1); |
74 |
$list_printers = 0; |
89 |
#---- if primkey exists, it's a modify action, so read values to modify... |
75 |
$template->param(add_form => 1); |
90 |
my $data; |
76 |
#---- if primkey exists, it's a modify action, so read values to modify... |
91 |
if ($searchfield) { |
77 |
my $data; |
92 |
my $sth=$dbh->prepare("SELECT printername,printqueue,printtype from printers where printername=?"); |
78 |
if ($searchfield) { |
93 |
$sth->execute($searchfield); |
79 |
$data=GetPrinterDetails($searchfield); |
94 |
$data=$sth->fetchrow_hashref; |
80 |
} |
95 |
} |
81 |
|
96 |
|
82 |
$template->param( |
97 |
$template->param(printqueue => $data->{'printqueue'}, |
83 |
printqueue => $data->{'printqueue'}, |
98 |
printtype => $data->{'printtype'}); |
84 |
printername => $data->{'printername'}, |
99 |
# END $OP eq ADD_FORM |
85 |
printtype => $data->{'printtype'} |
|
|
86 |
); |
87 |
# END $OP eq ADD_FORM |
100 |
################## ADD_VALIDATE ################################## |
88 |
################## ADD_VALIDATE ################################## |
101 |
# called by add_form, used to insert/modify data in DB |
89 |
# called by add_form, used to insert/modify data in DB |
102 |
} elsif ($op eq 'add_validate') { |
90 |
} elsif ($op eq 'add_validate') { |
103 |
$template->param(add_validate => 1); |
91 |
my $params = $input->Vars; |
104 |
if ($input->param('add')){ |
92 |
if ($input->param('add')){ |
105 |
my $sth=$dbh->prepare("INSERT INTO printers (printername,printqueue,printtype) VALUES (?,?,?)"); |
93 |
AddPrinter($params); |
106 |
$sth->execute($input->param('printername'),$input->param('printqueue'),$input->param('printtype')); |
94 |
} else { |
107 |
} else { |
95 |
UpdatePrinter($searchfield, $params); |
108 |
my $sth=$dbh->prepare("UPDATE printers SET printqueue=?,printtype=? WHERE printername=?"); |
96 |
} |
109 |
$sth->execute($input->param('printqueue'),$input->param('printtype'),$input->param('printername')); |
97 |
$template->param(add_validate => 1); |
110 |
} |
98 |
$searchfield = ''; |
111 |
# END $OP eq ADD_VALIDATE |
99 |
# END $OP eq ADD_VALIDATE |
112 |
################## DELETE_CONFIRM ################################## |
100 |
################## DELETE_CONFIRM ################################## |
113 |
# called by default form, used to confirm deletion of data in DB |
101 |
# called by default form, used to confirm deletion of data in DB |
114 |
} elsif ($op eq 'delete_confirm') { |
102 |
} elsif ($op eq 'delete_confirm') { |
115 |
$template->param(delete_confirm => 1); |
103 |
$list_printers = 0; |
116 |
my $sth=$dbh->prepare("select printername,printqueue,printtype from printers where printername=?"); |
104 |
$template->param(delete_confirm => 1); |
117 |
$sth->execute($searchfield); |
105 |
my $data=GetPrinterDetails($searchfield); |
118 |
my $data=$sth->fetchrow_hashref; |
106 |
$template->param( |
119 |
$template->param(printqueue => $data->{'printqueue'}, |
107 |
printqueue => $data->{'printqueue'}, |
120 |
printtype => $data->{'printtype'}); |
108 |
printtype => $data->{'printtype'}, |
121 |
# END $OP eq DELETE_CONFIRM |
109 |
); |
|
|
110 |
# END $OP eq DELETE_CONFIRM |
122 |
################## DELETE_CONFIRMED ################################## |
111 |
################## DELETE_CONFIRMED ################################## |
123 |
# called by delete_confirm, used to effectively confirm deletion of data in DB |
112 |
# called by delete_confirm, used to effectively confirm deletion of data in DB |
124 |
} elsif ($op eq 'delete_confirmed') { |
113 |
} elsif ($op eq 'delete_confirmed') { |
125 |
$template->param(delete_confirmed => 1); |
114 |
# XXX Delete can fail |
126 |
my $sth=$dbh->prepare("delete from printers where printername=?"); |
115 |
DeletePrinter($searchfield); |
127 |
$sth->execute($searchfield); |
116 |
$template->param(delete_confirmed => 1); |
128 |
# END $OP eq DELETE_CONFIRMED |
117 |
$template->param(list_printers => 1); |
|
|
118 |
$searchfield = ''; |
119 |
# END $OP eq DELETE_CONFIRMED |
129 |
################## DEFAULT ########################################### |
120 |
################## DEFAULT ########################################### |
130 |
} else { # DEFAULT |
121 |
} else { # DEFAULT |
131 |
$template->param(else => 1); |
122 |
$searchfield ||= $input->param('description') || ""; |
132 |
my ($count,$results)=StringSearch($searchfield,'web'); |
|
|
133 |
my $max = ($offset+$pagesize < $count) ? $offset+$pagesize : $count; |
134 |
my @loop = (@$results)[$offset..$max]; |
135 |
|
136 |
$template->param(loop => \@loop); |
137 |
|
138 |
if ($offset>0) { |
139 |
$template->param(offsetgtzero => 1, |
140 |
prevpage => $offset-$pagesize); |
141 |
} |
142 |
if ($offset+$pagesize<$count) { |
143 |
$template->param(ltcount => 1, |
144 |
nextpage => $offset+$pagesize); |
145 |
} |
146 |
|
147 |
} #---- END $OP eq DEFAULT |
123 |
} #---- END $OP eq DEFAULT |
148 |
|
124 |
|
|
|
125 |
if ($list_printers) { |
126 |
$template->param(list_printers => 1); |
127 |
my $results=SearchPrinters($searchfield); |
128 |
my $count = $results ? scalar(@$results) : 0; |
129 |
my $max = ($offset+$pagesize < $count) ? $offset+$pagesize : $count; |
130 |
my @loop = (@$results)[$offset..$max-1]; |
131 |
|
132 |
$template->param(loop => \@loop); |
133 |
|
134 |
if ($offset>0) { |
135 |
$template->param(offsetgtzero => 1, |
136 |
prevpage => $offset-$pagesize); |
137 |
} |
138 |
if ($offset+$pagesize<$count) { |
139 |
$template->param(ltcount => 1, |
140 |
nextpage => $offset+$pagesize); |
141 |
} |
142 |
} |
143 |
|
144 |
$template->param( |
145 |
searchfield => $searchfield, |
146 |
script_name => $script_name |
147 |
); |
148 |
|
149 |
output_html_with_http_headers $input, $cookie, $template->output; |
149 |
output_html_with_http_headers $input, $cookie, $template->output; |
150 |
|
150 |
|