3 #script to administer the systempref 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 variable,value,explanation from systempreferences where (variable like \"$data[0]%\") order by variable";
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="variable";
52 my $reqsel="select variable,value,explanation from systempreferences where $pkfield='$searchfield'";
53 my $reqdel="delete from systempreferences where $pkfield='$searchfield'";
54 my $offset=$input->param('offset');
55 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
58 my $op = $input->param('op');
59 $searchfield=~ s/\,//g;
62 #start the page and read in includes
64 print startmenu('admin');
66 ################## ADD_FORM ##################################
67 # called by default. Used to create form to add or modify a record
68 if ($op eq 'add_form') {
69 #---- if primkey exists, it's a modify action, so read values to modify...
73 my $sth=$dbh->prepare("select variable,value,explanation from systempreferences where variable='$searchfield'");
75 $data=$sth->fetchrow_hashref;
80 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 function isNotNull(f,noalert) {
82 if (f.value.length ==0) {
87 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89 var x=f.value.toUpperCase();
93 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 function isNum(v,maybenull) {
95 var n = new Number(v.value);
99 if (maybenull==0 && v.value=='') {
104 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106 var t = Date.parse(f.value);
111 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116 if (f.variable.value.length==0) {
117 _alertString += "- variable missing\\n";
119 if (f.value.value.length==0) {
120 _alertString += "- value missing\\n";
122 if (_alertString.length==0) {
123 document.Aform.submit();
125 alertString2 = "Form not submitted because of the following problem(s)\\n";
126 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
127 alertString2 += _alertString;
135 print "<h1>Modify pref</h1>";
137 print "<h1>Add pref</h1>";
139 print "<form action='$script_name' name=Aform method=post>";
140 print "<input type=hidden name=op value='add_validate'>";
141 print "<input type=hidden name=explanation value='".$data->{'explanation'}."'>";
144 print "<tr><td>Variable</td><td><input type=hidden name=variable value='$searchfield'>$searchfield</td></tr>";
146 print "<tr><td>Variable</td><td><input type=text name=variable size=255 maxlength=255></td></tr>";
148 print "<tr><td>Value</td><td><input type=text name=value value='$data->{'value'}'></td></tr>";
149 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
153 # END $OP eq ADD_FORM
154 ################## ADD_VALIDATE ##################################
155 # called by add_form, used to insert/modify data in DB
156 } elsif ($op eq 'add_validate') {
158 my $query = "replace systempreferences (variable,value,explanation) values (";
159 $query.= $dbh->quote($input->param('variable')).",";
160 $query.= $dbh->quote($input->param('value')).",";
161 $query.= $dbh->quote($input->param('explanation')).")";
162 my $sth=$dbh->prepare($query);
165 print "data recorded";
166 print "<form action='$script_name' method=post>";
167 print "<input type=submit value=OK>";
169 # END $OP eq ADD_VALIDATE
170 ################## DELETE_CONFIRM ##################################
171 # called by default form, used to confirm deletion of data in DB
172 } elsif ($op eq 'delete_confirm') {
173 my $dbh = &C4Connect;
174 my $sth=$dbh->prepare($reqsel);
176 my $data=$sth->fetchrow_hashref;
179 print mktablerow(2,'#99cc33',bold('Variable'),bold("$searchfield"),'/images/background-mem.gif');
180 print "<tr><td>Value</td><td>$data->{'value'}</td></tr>";
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 colspan=2 align=center>CONFIRM DELETION</td></tr>";
183 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>";
184 # END $OP eq DELETE_CONFIRM
185 ################## DELETE_CONFIRMED ##################################
186 # called by delete_confirm, used to effectively confirm deletion of data in DB
187 } elsif ($op eq 'delete_confirmed') {
189 # my $searchfield=$input->param('branchcode');
190 my $sth=$dbh->prepare($reqdel);
193 print "data deleted";
194 print "<form action='$script_name' method=post>";
195 print "<input type=submit value=OK>";
197 # END $OP eq DELETE_CONFIRMED
198 ################## DEFAULT ##################################
200 my @inputs=(["text","searchfield",$searchfield],
201 ["reset","reset","clr"]);
202 print mkheadr(2,'System preferences admin');
203 print mkformnotable("$script_name",@inputs);
207 if ($searchfield ne '') {
208 print "You Searched for <b>$searchfield<b><p>";
211 print mktablerow(5,'#99cc33',bold('Variable'),bold('Value'),bold('Explanation'),
212 ' ',' ','/images/background-mem.gif');
214 my ($count,$results)=StringSearch($env,$searchfield,'web');
216 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
217 if ($toggle eq 'white'){
222 print mktablerow(5,$toggle,$results->[$i]{'variable'},$results->[$i]{'value'},$results->[$i]{'explanation'},
223 mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'variable'},'Edit'),
224 mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'},'Delete'));
227 print "<form action='$script_name' method=post>";
228 print "<input type=hidden name=op value=add_form>";
230 my $prevpage = $offset-$pagesize;
231 print mklink("$script_name?offset=".$prevpage,'<< Prev');
233 print " ";
234 if ($offset+$pagesize<$count) {
235 my $nextpage =$offset+$pagesize;
236 print mklink("$script_name?offset=".$nextpage,'Next >>');
238 print "<br><input type=image src=\"/images/button-add-new.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
240 } #---- END $OP eq DEFAULT
241 print endmenu('admin');