1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
# --
# Kernel/System/CustomerUser/Preferences/DB.pm - some customer user functions
# Copyright (C) 2002-2003 Martin Edenhofer <martin+code@otrs.org>
# --
# $Id: DB.pm,v 1.7 2004/01/10 15:34:15 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
package Kernel::System::CustomerUser::Preferences::DB;
use strict;
use vars qw(@ISA $VERSION);
$VERSION = '$Revision: 1.7 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
# --
sub new {
my $Type = shift;
my %Param = @_;
# allocate new hash for object
my $Self = {};
bless ($Self, $Type);
# check needed objects
foreach (qw(DBObject ConfigObject LogObject)) {
$Self->{$_} = $Param{$_} || die "Got no $_!";
}
# preferences table data
$Self->{PreferencesTable} = $Self->{ConfigObject}->Get('CustomerPreferences')->{Params}->{Table}
|| 'customer_preferences';
$Self->{PreferencesTableKey} = $Self->{ConfigObject}->Get('CustomerPreferences')->{Params}->{TableKey}
|| 'preferences_key';
$Self->{PreferencesTableValue} = $Self->{ConfigObject}->Get('CustomerPreferences')->{Params}->{TableValue}
|| 'preferences_value';
$Self->{PreferencesTableUserID} = $Self->{ConfigObject}->Get('CustomerPreferences')->{Params}->{TableUserID}
|| 'user_id';
return $Self;
}
# --
sub SetPreferences {
my $Self = shift;
my %Param = @_;
my $UserID = $Param{UserID} || return;
my $Key = $Param{Key} || return;
my $Value = defined($Param{Value}) ? $Param{Value} : '';
# delete old data
if (!$Self->{DBObject}->Do(
SQL => "DELETE FROM $Self->{PreferencesTable} ".
" WHERE ".
" $Self->{PreferencesTableUserID} = '".$Self->{DBObject}->Quote($UserID)."'".
" AND ".
" $Self->{PreferencesTableKey} = '".$Self->{DBObject}->Quote($Key)."'",
)) {
return;
}
# insert new data
if (!$Self->{DBObject}->Do(
SQL => "INSERT INTO $Self->{PreferencesTable} ($Self->{PreferencesTableUserID}, ".
" $Self->{PreferencesTableKey}, $Self->{PreferencesTableValue}) " .
" VALUES ('".$Self->{DBObject}->Quote($UserID)."', ".
" '".$Self->{DBObject}->Quote($Key)."', ".
" '".$Self->{DBObject}->Quote($Value)."')",
)) {
return;
}
return 1;
}
# --
sub GetPreferences {
my $Self = shift;
my %Param = @_;
my $UserID = $Param{UserID} || return;
my %Data;
# --
# get preferences
# --
my $SQL = "SELECT $Self->{PreferencesTableKey}, $Self->{PreferencesTableValue} " .
" FROM " .
" $Self->{PreferencesTable} ".
" WHERE " .
" $Self->{PreferencesTableUserID} = '".$Self->{DBObject}->Quote($UserID)."'";
$Self->{DBObject}->Prepare(SQL => $SQL);
while (my @RowTmp = $Self->{DBObject}->FetchrowArray()) {
$Data{$RowTmp[0]} = $RowTmp[1];
}
# --
# return data
# --
return %Data;
}
# --
1;
|