This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
forked from akoeb/amacube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccountConfig.php
87 lines (79 loc) · 3.02 KB
/
AccountConfig.php
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
<?php
/**
* AccountConfig - class to load and store account settings in DB
*/
/*
This file is part of the amacube Roundcube plugin
Copyright (C) 2013, Alexander Köb <nerdkram@koeb.me>
Licensed under the GNU General Public License version 3.
See the COPYING file for a full license statement.
*/
include_once('AmacubeAbstract.php');
class AccountConfig extends AmacubeAbstract
{
// User config
public $initialized = false; // User record exists in database
public $catchall = null;
public $filter = null;
// Constructor
function __construct($db_config) {
// Call constructor of the super class to initialize db connection:
parent::__construct($db_config);
// Check config
$this->initialized = $this->get_account();
}
function get_account() {
$table_account = $this->rc->config->get('amacube_accounts_db_account_table');
$field_account = $this->rc->config->get('amacube_accounts_db_account_field');
$field_account_filter = $this->rc->config->get('amacube_accounts_db_account_filter_field');
$field_account_catchall = $this->rc->config->get('amacube_accounts_db_account_catchall_field');
// Account table required
if (isset($table_account) && is_string($table_account)) {
// Account field required
if (isset($field_account) && is_string($field_account)) {
// Account filter or catchall required
if ((isset($field_account_filter) && is_string($field_account_filter)) || (isset($field_account_catchall) && is_string($field_account_catchall))) {
// Connect to db
if (!is_resource($this->db_conn)) {
if (!$this->init_db()) { return false; }
}
$query = "SELECT $table_account.$field_account";
if ($field_account_filter) {
$query .= ", $table_account.$field_account_filter";
}
if ($field_account_catchall) {
$query .= ", $table_account.$field_account_catchall";
}
$query .= " FROM $table_account WHERE $table_account.$field_account = ? ";
$res = $this->db_conn->query($query, $this->user_email);
if ($error = $this->db_conn->is_error()) {
$this->rc->amacube->errors[] = 'db_query_error';
rcube::write_log('errors','AMACUBE: Database query error: '.$error);
return false;
}
if ($res && ($res_array = $this->db_conn->fetch_assoc($res))) {
// Check filter
if (isset($res_array[$field_account_filter])) {
if ($res_array[$field_account_filter] == 1 || $res_array[$field_account_filter] == 'Y' || $res_array[$field_account_filter]) {
$this->filter = true;
} else {
$this->filter = false;
}
}
// Check catchall
if (isset($res_array[$field_account_catchall])) {
if ($res_array[$field_account_catchall] == 1 || $res_array[$field_account_catchall] == 'Y' || $res_array[$field_account_catchall]) {
$this->catchall = true;
} else {
$this->catchall = false;
}
}
return true;
}
}
}
}
return false;
}
}
?>