bug 5783: Authorities edit logging
[koha_fer] / C4 / SQLHelper.pm
index 0b0c520..060b78f 100644 (file)
@@ -13,9 +13,9 @@ package C4::SQLHelper;
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 
 use strict;
@@ -24,7 +24,6 @@ use List::MoreUtils qw(first_value any);
 use C4::Context;
 use C4::Dates qw(format_date_in_iso);
 use C4::Debug;
-use YAML;
 require Exporter;
 use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
 
@@ -61,18 +60,11 @@ This module contains routines for adding, modifying and Searching Data in MysqlD
 
 =head1 FUNCTIONS
 
-=over 2
-
-=back
-
-
 =head2 SearchInTable
 
-=over 4
+  $hashref = &SearchInTable($tablename,$data, $orderby, $limit, 
+                      $columns_out, $filtercolumns, $searchtype);
 
-  $hashref = &SearchInTable($tablename,$data, $orderby, $limit, $columns_out, $filtercolumns, $searchtype);
-
-=back
 
 $tablename Name of the table (string)
 
@@ -138,20 +130,16 @@ sub SearchInTable{
 
 =head2 InsertInTable
 
-=over 4
-
-  $data_id_in_table = &InsertInTable($tablename,$data_hashref);
+  $data_id_in_table = &InsertInTable($tablename,$data_hashref,$withprimarykeys);
 
-=back
+Insert Data in table and returns the id of the row inserted
 
-  Insert Data in table
-  and returns the id of the row inserted
 =cut
 
 sub InsertInTable{
-    my ($tablename,$data) = @_;
+    my ($tablename,$data,$withprimarykeys) = @_;
     my $dbh      = C4::Context->dbh;
-    my ($keys,$values)=_filter_hash($tablename,$data,0);
+    my ($keys,$values)=_filter_hash($tablename,$data,($withprimarykeys?"exact":0));
     my $query = qq{ INSERT INTO $tablename SET  }.join(", ",@$keys);
 
        $debug && warn $query, join(",",@$values);
@@ -164,14 +152,10 @@ sub InsertInTable{
 
 =head2 UpdateInTable
 
-=over 4
-
   $status = &UpdateInTable($tablename,$data_hashref);
 
-=back
+Update Data in table and returns the status of the operation
 
-  Update Data in table
-  and returns the status of the operation
 =cut
 
 sub UpdateInTable{
@@ -195,14 +179,10 @@ sub UpdateInTable{
 
 =head2 DeleteInTable
 
-=over 4
-
   $status = &DeleteInTable($tablename,$data_hashref);
 
-=back
+Delete Data in table and returns the status of the operation
 
-  Delete Data in table
-  and returns the status of the operation
 =cut
 
 sub DeleteInTable{
@@ -224,13 +204,10 @@ sub DeleteInTable{
 
 =head2 GetPrimaryKeys
 
-=over 4
-
   @primarykeys = &GetPrimaryKeys($tablename)
 
-=back
+Get the Primary Key field names of the table
 
-       Get the Primary Key field names of the table
 =cut
 
 sub GetPrimaryKeys($) {
@@ -241,11 +218,7 @@ sub GetPrimaryKeys($) {
 
 =head2 _get_columns
 
-=over 4
-
-_get_columns($tablename)
-
-=back
+    _get_columns($tablename)
 
 Given a tablename 
 Returns a hashref of all the fieldnames of the table
@@ -266,11 +239,7 @@ sub _get_columns($) {
 
 =head2 _filter_columns
 
-=over 4
-
-_filter_columns($tablename,$research, $filtercolumns)
-
-=back
+    _filter_columns($tablename,$research, $filtercolumns)
 
 Given 
        - a tablename 
@@ -299,11 +268,7 @@ sub _filter_columns ($$;$) {
 }
 =head2 _filter_fields
 
-=over 4
-
-_filter_fields
-
-=back
+  _filter_fields
 
 Given 
        - a tablename
@@ -418,7 +383,7 @@ sub _Process_Operands{
        push @tmpkeys, " $field = ? ";
        push @values, $operand;
        #By default, exact search
-       unless ($searchtype){
+       if (!$searchtype ||$searchtype eq "exact"){
                return \@tmpkeys,\@values;
        }
        my $col_field=(index($field,".")>0?substr($field, index($field,".")+1):$field);
@@ -431,9 +396,13 @@ sub _Process_Operands{
                        push @tmpkeys,(" $field LIKE ? ");
                        push @localvaluesextended,("\%$operand\%") ;
                }
+               if ($searchtype eq "field_start_with"){
+                       push @tmpkeys,("$field LIKE ?");
+                       push @localvaluesextended, ("$operand\%") ;
+               }
                if ($searchtype eq "start_with"){
-                       push @tmpkeys,(" $field LIKE ? ","$field LIKE ?");
-                       push @localvaluesextended, ("\% $operand\%","$operand\%") ;
+                       push @tmpkeys,("$field LIKE ?","$field LIKE ?");
+                       push @localvaluesextended, ("$operand\%", " $operand\%") ;
                }
                push @values,@localvaluesextended;
        }