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 branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing from branches where (branchcode like \"$data[0]%\") order by branchcode";
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="branchcode";
52 my $reqsel="select branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing from branches where branchcode='$searchfield'";
53 my $reqdel="delete from branches where branchcode='$searchfield'";
54 #my $branchcode=$input->param('branchcode');
55 my $offset=$input->param('offset');
56 my $script_name="/cgi-bin/koha/admin/branches.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 branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing from branches where branchcode='$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.searchfield.value.length==0) {
118 _alertString += "- branch code missing\\n";
120 if (f.branchname.value.length==0) {
121 _alertString += "- branch name 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 branch</h1>";
138 print "<h1>Add branch</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>Branch code</td><td><input type=hidden name=searchfield value=$searchfield>$searchfield</td></tr>";
146 print "<tr><td>Branch code</td><td><input type=text name=searchfield size=5 maxlength=5 onBlur=toUC(this)></td></tr>";
148 print "<tr><td>Name</td><td><input type=text name=branchname size=40 maxlength=80 value='$data->{'branchname'}'> </td></tr>";
149 print "<tr><td>Adress</td><td><input type=text name=branchaddress1 value='$data->{'branchaddress1'}'></td></tr>";
150 print "<tr><td> </td><td><input type=text name=branchaddress2 value='$data->{'branchaddress2'}'></td></tr>";
151 print "<tr><td> </td><td><input type=text name=branchaddress3 value='$data->{'branchaddress3'}'></td></tr>";
152 print "<tr><td>Phone</td><td><input type=text name=branchphone value='$data->{'branchphone'}'></td></tr>";
153 print "<tr><td>Fax</td><td><input type=text name=branchfax value='$data->{'branchfax'}'></td></tr>";
154 print "<tr><td>E-mail</td><td><input type=text name=branchemail value='$data->{'branchemail'}'></td></tr>";
155 print "<tr><td>Issuing</td><td><input type=text name=issuing value='$data->{'issuing'}'></td></tr>";
156 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
160 # END $OP eq ADD_FORM
161 ################## ADD_VALIDATE ##################################
162 # called by add_form, used to insert/modify data in DB
163 } elsif ($op eq 'add_validate') {
165 my $query = "replace branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing) values (";
166 $query.= $dbh->quote($input->param('branchcode')).",";
167 $query.= $dbh->quote($input->param('branchname')).",";
168 $query.= $dbh->quote($input->param('branchaddress1')).",";
169 $query.= $dbh->quote($input->param('branchaddress2')).",";
170 $query.= $dbh->quote($input->param('branchaddress3')).",";
171 $query.= $dbh->quote($input->param('branchphone')).",";
172 $query.= $dbh->quote($input->param('branchfax')).",";
173 $query.= $dbh->quote($input->param('branchemail')).",";
174 $query.= $dbh->quote($input->param('issuing')).")";
175 my $sth=$dbh->prepare($query);
178 print "data recorded";
179 print "<form action='$script_name' method=post>";
180 print "<input type=submit value=OK>";
182 # END $OP eq ADD_VALIDATE
183 ################## DELETE_CONFIRM ##################################
184 # called by default form, used to confirm deletion of data in DB
185 } elsif ($op eq 'delete_confirm') {
186 my $dbh = &C4Connect;
187 my $sth=$dbh->prepare("select count(*) as total from borrowers where branchcode='$searchfield'");
189 my $total = $sth->fetchrow_hashref;
192 my $sth=$dbh->prepare($reqsel);
194 my $data=$sth->fetchrow_hashref;
197 print mktablerow(2,'#99cc33',bold('Branch code'),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>Branch code</td><td>$data->{'branchcode'}</td></tr>";
200 print "<tr><td> name</td><td>$data->{'branchname'}</td></tr>";
201 print "<tr><td> adress</td><td>$data->{'branchaddress1'}</td></tr>";
202 print "<tr><td> </td><td>$data->{'branchaddress2'}</td></tr>";
203 print "<tr><td> </td><td>$data->{'branchaddress3'}</td></tr>";
204 print "<tr><td> phone</td><td>$data->{'branchphone'}</td></tr>";
205 print "<tr><td> fax</td><td>$data->{'branchfax'}</td></tr>";
206 print "<tr><td> e-mail</td><td>$data->{'branchemail'}</td></tr>";
207 print "<tr><td> issuing</td><td>$data->{'issuing'}</td></tr>";
208 if ($total->{'total'} >0) {
209 print "<tr><td colspan=2 align=center><b>This record is used $total->{'total'} times. Deletion not possible</b></td></tr>";
210 print "<tr><td colspan=2></form><form action='$script_name' method=post><input type=submit value=OK></form></td></tr>";
212 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
213 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>";
215 # END $OP eq DELETE_CONFIRM
216 ################## DELETE_CONFIRMED ##################################
217 # called by delete_confirm, used to effectively confirm deletion of data in DB
218 } elsif ($op eq 'delete_confirmed') {
220 # my $searchfield=$input->param('branchcode');
221 my $sth=$dbh->prepare($reqdel);
224 print "data deleted";
225 print "<form action='$script_name' method=post>";
226 print "<input type=submit value=OK>";
228 # END $OP eq DELETE_CONFIRMED
229 ################## DEFAULT ##################################
231 my @inputs=(["text","searchfield",$searchfield],
232 ["reset","reset","clr"]);
233 print mkheadr(2,'branches admin');
234 print mkformnotable("$script_name",@inputs);
239 if ($searchfield ne '') {
240 print "You Searched for <b>$searchfield<b><p>";
243 print mktablerow(9,'#99cc33',bold('Branch code'),bold('name'),bold('adress'),
244 bold('phone'),bold('fax'),bold('mail'),bold('issuing'),
245 ' ',' ','/images/background-mem.gif');
247 my ($count,$results)=StringSearch($env,$searchfield,'web');
249 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
251 # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
253 if ($toggle eq 'white'){
258 print mktablerow(9,$toggle,$results->[$i]{'branchcode'},$results->[$i]{'branchname'},
259 $results->[$i]{'branchaddress1'}.$results->[$i]{'branchaddress2'}.$results->[$i]{'branchaddress3'},
260 $results->[$i]{'branchphone'},,$results->[$i]{'branchfax'},,$results->[$i]{'branchmail'},,$results->[$i]{'issuing'},
261 mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'branchcode'},'Edit'),
262 mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'branchcode'},'Delete',''));
265 print "<form action='$script_name' method=post>";
266 print "<input type=hidden name=op value=add_form>";
268 my $prevpage = $offset-$pagesize;
269 print mklink("$script_name?offset=".$prevpage,'<< Prev');
271 print " ";
272 if ($offset+$pagesize<$count) {
273 my $nextpage =$offset+$pagesize;
274 print mklink("$script_name?offset=".$nextpage,'Next >>');
276 print "<br><input type=image src=\"/images/button-add-member.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
278 } #---- END $OP eq DEFAULT
279 print endmenu('admin');