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
29 my ($env,$searchstring,$type)=@_;
31 $searchstring=~ s/\'/\\\'/g;
32 my @data=split(' ',$searchstring);
34 my $query="Select printername,printqueue,printtype from printers where (printername like \"$data[0]%\") order by printername";
35 my $sth=$dbh->prepare($query);
39 while (my $data=$sth->fetchrow_hashref){
46 return ($cnt,\
@results);
50 my $searchfield=$input->param('searchfield');
51 my $pkfield="printername";
52 my $reqsel="select printername,printqueue,printtype from printers where $pkfield='$searchfield'";
53 my $reqdel="delete from printers where $pkfield='$searchfield'";
54 #my $branchcode=$input->param('branchcode');
55 my $offset=$input->param('offset');
56 my $script_name="/cgi-bin/koha/admin/printers.pl";
59 my $op = $input->param('op');
60 $searchfield=~ s/\,//g;
63 #start the page and read in includes
65 print startmenu
('admin');
67 ################## ADD_FORM ##################################
68 # called by default. Used to create form to add or modify a record
69 if ($op eq 'add_form') {
70 #---- if primkey exists, it's a modify action, so read values to modify...
74 my $sth=$dbh->prepare("select printername,printqueue,printtype from printers where printername='$searchfield'");
76 $data=$sth->fetchrow_hashref;
81 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 function isNotNull(f,noalert) {
83 if (f.value.length ==0) {
88 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 var x=f.value.toUpperCase();
94 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95 function isNum(v,maybenull) {
96 var n = new Number(v.value);
100 if (maybenull==0 && v.value=='') {
105 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107 var t = Date.parse(f.value);
112 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117 if (f.printername.value.length==0) {
118 _alertString += "- printer name missing\\n";
120 if (f.printqueue.value.length==0) {
121 _alertString += "- Queue missing\\n";
123 if (_alertString.length==0) {
124 document.Aform.submit();
126 alertString2 = "Form not submitted because of the following problem(s)\\n";
127 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
128 alertString2 += _alertString;
136 print "<h1>Modify printer</h1>";
138 print "<h1>Add printer</h1>";
140 print "<form action='$script_name' name=Aform method=post>";
141 print "<input type=hidden name=op value='add_validate'>";
144 print "<tr><td>Printer</td><td><input type=hidden name=printername value='$searchfield'>$searchfield</td></tr>";
146 print "<tr><td>Printer</td><td><input type=text name=printername size=50 maxlength=50></td></tr>";
148 print "<tr><td>Queue</td><td><input type=text name=printqueue size=50 maxlength=50 value='$data->{'printqueue'}'> </td></tr>";
149 print "<tr><td>Type</td><td><input type=text name=printtype size=50 maxlength=50 value='$data->{'printtype'}'> </td></tr>";
150 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
154 # END $OP eq ADD_FORM
155 ################## ADD_VALIDATE ##################################
156 # called by add_form, used to insert/modify data in DB
157 } elsif ($op eq 'add_validate') {
159 my $query = "replace printers (printername,printqueue,printtype) values (";
160 $query.= $dbh->quote($input->param('printername')).",";
161 $query.= $dbh->quote($input->param('printqueue')).",";
162 $query.= $dbh->quote($input->param('printtype')).")";
163 my $sth=$dbh->prepare($query);
166 print "data recorded";
167 print "<form action='$script_name' method=post>";
168 print "<input type=submit value=OK>";
170 # END $OP eq ADD_VALIDATE
171 ################## DELETE_CONFIRM ##################################
172 # called by default form, used to confirm deletion of data in DB
173 } elsif ($op eq 'delete_confirm') {
174 my $dbh = &C4Connect
;
175 my $sth=$dbh->prepare($reqsel);
177 my $data=$sth->fetchrow_hashref;
180 print mktablerow
(2,'#99cc33',bold
('Printer'),bold
("$searchfield"),'/images/background-mem.gif');
181 print "<form action='$script_name' method=post><input type=hidden name=op value=delete_confirmed><input type=hidden name=searchfield value='$searchfield'>";
182 print "<tr><td>Queue</td><td>$data->{'printqueue'}</td></tr>";
183 print "<tr><td>Type</td><td>$data->{'printtype'}</td></tr>";
184 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
185 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>";
186 # END $OP eq DELETE_CONFIRM
187 ################## DELETE_CONFIRMED ##################################
188 # called by delete_confirm, used to effectively confirm deletion of data in DB
189 } elsif ($op eq 'delete_confirmed') {
191 # my $searchfield=$input->param('branchcode');
192 my $sth=$dbh->prepare($reqdel);
195 print "data deleted";
196 print "<form action='$script_name' method=post>";
197 print "<input type=submit value=OK>";
199 # END $OP eq DELETE_CONFIRMED
200 ################## DEFAULT ##################################
202 my @inputs=(["text","searchfield",$searchfield],
203 ["reset","reset","clr"]);
204 print mkheadr
(2,'Currencies admin');
205 print mkformnotable
("$script_name",@inputs);
210 if ($searchfield ne '') {
211 print "You Searched for <b>$searchfield<b><p>";
214 print mktablerow
(5,'#99cc33',bold
('Name'),bold
('Queue'),bold
('Type'),
215 ' ',' ','/images/background-mem.gif');
217 my ($count,$results)=StringSearch
($env,$searchfield,'web');
219 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
220 if ($toggle eq 'white'){
225 print mktablerow
(5,$toggle,$results->[$i]{'printername'},$results->[$i]{'printqueue'},$results->[$i]{'printtype'},
226 mklink
("$script_name?op=add_form&searchfield=".$results->[$i]{'printername'},'Edit'),
227 mklink
("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'printername'},'Delete',''));
230 print "<form action='$script_name' method=post>";
231 print "<input type=hidden name=op value=add_form>";
233 my $prevpage = $offset-$pagesize;
234 print mklink
("$script_name?offset=".$prevpage,'<< Prev');
236 print " ";
237 if ($offset+$pagesize<$count) {
238 my $nextpage =$offset+$pagesize;
239 print mklink
("$script_name?offset=".$nextpage,'Next >>');
241 print "<br><input type=image src=\"/images/button-add-member.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
243 } #---- END $OP eq DEFAULT
244 print endmenu
('admin');