3 #script to administer the aqbudget table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
8 # this script use an $op to know what to do.
9 # if $op is empty or none of the above values,
10 # - the default screen is build (with all records, or filtered datas).
11 # - the user can clic on add, modify or delete record.
13 # - if primkey exists, this is a modification,so we read the $primkey record
14 # - builds the add/modify form
16 # - the user has just send datas, so we create/modify the record
18 # - we show the record having primkey=$primkey and ask for deletion validation form
19 # if $op=delete_confirm
20 # - we delete the record having primkey=$primkey
23 # Copyright 2000-2002 Katipo Communications
25 # This file is part of Koha.
27 # Koha is free software; you can redistribute it and/or modify it under the
28 # terms of the GNU General Public License as published by the Free Software
29 # Foundation; either version 2 of the License, or (at your option) any later
32 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
33 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
34 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License along with
37 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
38 # Suite 330, Boston, MA 02111-1307 USA
47 my ($env,$searchstring,$type)=@_;
48 my $dbh = C4::Context->dbh;
49 $searchstring=~ s/\'/\\\'/g;
50 my @data=split(' ',$searchstring);
52 my $query="Select printername,printqueue,printtype from printers where (printername like \"$data[0]%\") order by printername";
53 my $sth=$dbh->prepare($query);
57 while (my $data=$sth->fetchrow_hashref){
63 return ($cnt,\@results);
67 my $searchfield=$input->param('searchfield');
68 my $pkfield="printername";
69 my $reqsel="select printername,printqueue,printtype from printers where $pkfield='$searchfield'";
70 my $reqdel="delete from printers where $pkfield='$searchfield'";
71 #my $branchcode=$input->param('branchcode');
72 my $offset=$input->param('offset');
73 my $script_name="/cgi-bin/koha/admin/printers.pl";
76 my $op = $input->param('op');
77 $searchfield=~ s/\,//g;
80 #start the page and read in includes
82 print startmenu('admin');
84 ################## ADD_FORM ##################################
85 # called by default. Used to create form to add or modify a record
86 if ($op eq 'add_form') {
87 #---- if primkey exists, it's a modify action, so read values to modify...
90 my $dbh = C4::Context->dbh;
91 my $sth=$dbh->prepare("select printername,printqueue,printtype from printers where printername='$searchfield'");
93 $data=$sth->fetchrow_hashref;
98 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99 function isNotNull(f,noalert) {
100 if (f.value.length ==0) {
105 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107 var x=f.value.toUpperCase();
111 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
112 function isNum(v,maybenull) {
113 var n = new Number(v.value);
117 if (maybenull==0 && v.value=='') {
122 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
124 var t = Date.parse(f.value);
129 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
134 if (f.printername.value.length==0) {
135 _alertString += "- printer name missing\\n";
137 if (f.printqueue.value.length==0) {
138 _alertString += "- Queue missing\\n";
140 if (_alertString.length==0) {
141 document.Aform.submit();
143 alertString2 = "Form not submitted because of the following problem(s)\\n";
144 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
145 alertString2 += _alertString;
153 print "<h1>Modify printer</h1>";
155 print "<h1>Add printer</h1>";
157 print "<form action='$script_name' name=Aform method=post>";
158 print "<input type=hidden name=op value='add_validate'>";
161 print "<tr><td>Printer</td><td><input type=hidden name=printername value='$searchfield'>$searchfield</td></tr>";
163 print "<tr><td>Printer</td><td><input type=text name=printername size=50 maxlength=50></td></tr>";
165 print "<tr><td>Queue</td><td><input type=text name=printqueue size=50 maxlength=50 value='$data->{'printqueue'}'> </td></tr>";
166 print "<tr><td>Type</td><td><input type=text name=printtype size=50 maxlength=50 value='$data->{'printtype'}'> </td></tr>";
167 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
171 # END $OP eq ADD_FORM
172 ################## ADD_VALIDATE ##################################
173 # called by add_form, used to insert/modify data in DB
174 } elsif ($op eq 'add_validate') {
175 my $dbh = C4::Context->dbh;
176 my $query = "replace printers (printername,printqueue,printtype) values (";
177 $query.= $dbh->quote($input->param('printername')).",";
178 $query.= $dbh->quote($input->param('printqueue')).",";
179 $query.= $dbh->quote($input->param('printtype')).")";
180 my $sth=$dbh->prepare($query);
183 print "data recorded";
184 print "<form action='$script_name' method=post>";
185 print "<input type=submit value=OK>";
187 # END $OP eq ADD_VALIDATE
188 ################## DELETE_CONFIRM ##################################
189 # called by default form, used to confirm deletion of data in DB
190 } elsif ($op eq 'delete_confirm') {
191 my $dbh = C4::Context->dbh;
192 my $sth=$dbh->prepare($reqsel);
194 my $data=$sth->fetchrow_hashref;
197 print mktablerow(2,'#99cc33',bold('Printer'),bold("$searchfield"),'/images/background-mem.gif');
198 print "<form action='$script_name' method=post><input type=hidden name=op value=delete_confirmed><input type=hidden name=searchfield value='$searchfield'>";
199 print "<tr><td>Queue</td><td>$data->{'printqueue'}</td></tr>";
200 print "<tr><td>Type</td><td>$data->{'printtype'}</td></tr>";
201 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
202 print "<tr><td><INPUT type=submit value='YES'></form></td><td><form action='$script_name' method=post><input type=submit value=NO></form></td></tr>";
203 # END $OP eq DELETE_CONFIRM
204 ################## DELETE_CONFIRMED ##################################
205 # called by delete_confirm, used to effectively confirm deletion of data in DB
206 } elsif ($op eq 'delete_confirmed') {
207 my $dbh = C4::Context->dbh;
208 # my $searchfield=$input->param('branchcode');
209 my $sth=$dbh->prepare($reqdel);
212 print "data deleted";
213 print "<form action='$script_name' method=post>";
214 print "<input type=submit value=OK>";
216 # END $OP eq DELETE_CONFIRMED
217 ################## DEFAULT ##################################
219 my @inputs=(["text","searchfield",$searchfield],
220 ["reset","reset","clr"]);
221 print mkheadr(2,'Printer admin');
222 print mkformnotable("$script_name",@inputs);
227 if ($searchfield ne '') {
228 print "You Searched for <b>$searchfield<b><p>";
231 print mktablerow(5,'#99cc33',bold('Name'),bold('Queue'),bold('Type'),
232 ' ',' ','/images/background-mem.gif');
234 my ($count,$results)=StringSearch($env,$searchfield,'web');
236 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
237 if ($toggle eq 'white'){
242 print mktablerow(5,$toggle,$results->[$i]{'printername'},$results->[$i]{'printqueue'},$results->[$i]{'printtype'},
243 mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'printername'},'Edit'),
244 mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'printername'},'Delete'));
247 print "<form action='$script_name' method=post>";
248 print "<input type=hidden name=op value=add_form>";
250 my $prevpage = $offset-$pagesize;
251 print mklink("$script_name?offset=".$prevpage,'<< Prev');
253 print " ";
254 if ($offset+$pagesize<$count) {
255 my $nextpage =$offset+$pagesize;
256 print mklink("$script_name?offset=".$nextpage,'Next >>');
258 print "<br><input type=image src=\"/images/button-add-new.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
260 } #---- END $OP eq DEFAULT
261 print endmenu('admin');