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 aqbudget.bookfundid,startdate,enddate,budgetamount,bookfundname from aqbudget,aqbookfund where aqbudget.bookfundid=aqbookfund.bookfundid and (aqbudget.bookfundid like \"$data[0]%\") order by bookfundid";
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 $offset=$input->param('offset');
52 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
53 my $bookfundid=$input->param('bookfundid');
55 my $op = $input->param('op');
56 $searchfield=~ s/\,//g;
59 #start the page and read in includes
61 print startmenu('admin');
63 ################## ADD_FORM ##################################
64 # called by default. Used to create form to add or modify a record
65 if ($op eq 'add_form') {
66 #---- if primkey exists, it's a modify action, so read values to modify...
70 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
72 $data=$sth->fetchrow_hashref;
77 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78 function isNotNull(f,noalert) {
79 if (f.value.length ==0) {
84 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86 var x=f.value.toUpperCase();
90 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91 function isNum(v,maybenull) {
92 var n = new Number(v.value);
96 if (maybenull==0 && v.value=='') {
101 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103 var t = Date.parse(f.value);
108 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
113 if (f.bookfundid.value.length==0) {
114 _alertString += "- bookfundid missing\\n";
116 if (f.bookfundname.value.length==0) {
117 _alertString += "- bookfundname missing\\n";
119 if (_alertString.length==0) {
120 document.Aform.submit();
122 alertString2 = "Form not submitted because of the following problem(s)\\n";
123 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
124 alertString2 += _alertString;
132 print "<h1>Modify book fund</h1>";
134 print "<h1>Add book fund</h1>";
136 print "<form action='$script_name' name=Aform method=post>";
137 print "<input type=hidden name=op value='add_validate'>";
138 print "<input type=hidden name=checked value=0>";
141 print "<tr><td>Book fund</td><td><input type=hidden name=bookfundid value=$bookfundid>$bookfundid</td></tr>";
143 print "<tr><td>Book fund</td><td><input type=text name=bookfundid size=5 maxlength=5 onBlur=toUC(this)></td></tr>";
145 print "<tr><td>Name</td><td><input type=text name=bookfundname size=40 maxlength=80 value='$data->{'bookfundname'}'> </td></tr>";
146 print "<tr><td>Group</td><td><input type=text name=bookfundgroup value='$data->{'bookfundgroup'}'></td></tr>";
147 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
151 # END $OP eq ADD_FORM
152 ################## ADD_VALIDATE ##################################
153 # called by add_form, used to insert/modify data in DB
154 } elsif ($op eq 'add_validate') {
156 my $query = "replace aqbookfund (bookfundid,bookfundname,bookfundgroup) values (";
157 $query.= $dbh->quote($input->param('bookfundid')).",";
158 $query.= $dbh->quote($input->param('bookfundname')).",";
159 $query.= $dbh->quote($input->param('bookfundgroup')).")";
160 my $sth=$dbh->prepare($query);
163 print "data recorded";
164 print "<form action='$script_name' method=post>";
165 print "<input type=submit value=OK>";
167 # END $OP eq ADD_VALIDATE
168 ################## DELETE_CONFIRM ##################################
169 # called by default form, used to confirm deletion of data in DB
170 } elsif ($op eq 'delete_confirm') {
171 my $dbh = &C4Connect;
172 # my $sth=$dbh->prepare("select count(*) as total from categoryitem where itemtype='$itemtype'");
174 # my $total = $sth->fetchrow_hashref;
176 my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
178 my $data=$sth->fetchrow_hashref;
181 print mktablerow(2,'#99cc33',bold('Book fund'),bold("$bookfundid"),'/images/background-mem.gif');
182 print "<form action='$script_name' method=post><input type=hidden name=op value=delete_confirmed><input type=hidden name=bookfundid value='$bookfundid'>";
183 print "<tr><td>Name</td><td>$data->{'bookfundname'}</td></tr>";
184 print "<tr><td>Group</td><td>$data->{'bookfundgroup'}</td></tr>";
185 # if ($total->{'total'} >0) {
186 # print "<tr><td colspan=2 align=center><b>This record is used $total->{'total'} times. Deletion not possible</b></td></tr>";
187 # print "<tr><td colspan=2></form><form action='$script_name' method=post><input type=submit value=OK></form></td></tr>";
189 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
190 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>";
192 # END $OP eq DELETE_CONFIRM
193 ################## DELETE_CONFIRMED ##################################
194 # called by delete_confirm, used to effectively confirm deletion of data in DB
195 } elsif ($op eq 'delete_confirmed') {
197 my $bookfundid=uc($input->param('bookfundid'));
198 my $query = "delete from aqbookfund where bookfundid='$bookfundid'";
199 my $sth=$dbh->prepare($query);
202 print "data deleted";
203 print "<form action='$script_name' method=post>";
204 print "<input type=submit value=OK>";
206 # END $OP eq DELETE_CONFIRMED
207 ################## DEFAULT ##################################
209 my @inputs=(["text","searchfield",$searchfield],
210 ["reset","reset","clr"]);
211 print mkheadr(2,'bookfund admin');
212 print mkformnotable("$script_name",@inputs);
217 if ($searchfield ne '') {
218 print "You Searched for <b>$searchfield<b><p>";
221 print mktablerow(6,'#99cc33',bold('Book fund'),bold('Start date'),bold('End date'),bold('Budget amount'),
222 ' ',' ','/images/background-mem.gif');
224 my ($count,$results)=StringSearch($env,$searchfield,'web');
226 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
228 # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
230 if ($toggle eq 'white'){
235 print mktablerow(6,$toggle,$results->[$i]{'bookfundid'},
236 $results->[$i]{'bookfundname'},$results->[$i]{'bookfundgroup'},
237 mklink("$script_name?op=add_form&bookfundid=".$results->[$i]{'bookfundid'},'Edit'),
238 mklink("$script_name?op=delete_confirm&bookfundid=".$results->[$i]{'bookfundid'},'Delete',''));
241 print "<form action='$script_name' method=post>";
242 print "<input type=hidden name=op value=add_form>";
244 my $prevpage = $offset-$pagesize;
245 print mklink("$script_name?offset=".$prevpage,'<< Prev');
247 print " ";
248 if ($offset+$pagesize<$count) {
249 my $nextpage =$offset+$pagesize;
250 print mklink("$script_name?offset=".$nextpage,'Next >>');
252 print "<br><input type=image src=\"/images/button-add-member.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
254 } #---- END $OP eq DEFAULT
255 print endmenu('admin');