Passed
Push — master ( f14fa1...c29029 )
by Greg
02:55
created

CustomField::getCDFData()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 35
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 35
rs 9.7
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
/**
3
 * /classes/DomainMOD/CustomField.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2019 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class CustomField
25
{
26
    public $deeb;
27
28
    public function __construct()
29
    {
30
        $this->deeb = Database::getInstance();
31
    }
32
33
    public function checkFieldFormat($input_field)
34
    {
35
        if (preg_match('/^[a-zA-Z_]+$/i', $input_field)) {
36
37
            return true;
38
39
        } else {
40
41
            return false;
42
43
        }
44
    }
45
46
    public function getCustomFields($table_name)
47
    {
48
        $result = $this->queryCustomFields($table_name);
49
50
        $columns_array = array();
51
        $count = 0;
52
53
        if ($result) {
54
55
            foreach ($result as $row) {
56
57
                $columns_array[$count++] = $row->field_name;
58
59
            }
60
61
        }
62
63
        return $columns_array;
64
    }
65
66
    public function queryCustomFields($table_name)
67
    {
68
        return $this->deeb->cnxx->query("
69
            SELECT field_name
70
            FROM " . $table_name . "
71
            ORDER BY `name` ASC")->fetchAll();
72
    }
73
74
    public function getCustomFieldsSql($table_name, $column_prefix)
75
    {
76
        $result = $this->queryCustomFields($table_name);
77
78
        $columns = '';
79
80
        if ($result) {
81
82
            foreach ($result as $row) {
83
84
                $columns .= ", " . $column_prefix . "." . $row->field_name;
85
86
            }
87
88
        }
89
90
        return $columns;
91
    }
92
93
    public function getCDFData()
94
    {
95
        $custom_domain_field_data = array();
96
97
        $result = $this->deeb->cnxx->query("
98
            SELECT name, field_name, type_id
99
            FROM domain_fields
100
            ORDER BY name")->fetchAll(\PDO::FETCH_ASSOC);
101
102
        if ($result) {
103
104
            $count = 0;
105
106
            foreach ($result as $field_values) {
107
108
                $custom_domain_field_data[$count]['name'] = $field_values['name'];
109
                $custom_domain_field_data[$count]['field'] = $field_values['field_name'];
110
                $custom_domain_field_data[$count]['type_id'] = $field_values['type_id'];
111
                $custom_domain_field_data[$count]['display_field'] = 'dispcdf_' . $field_values['field_name'];
112
113
                $stmt = $this->deeb->cnxx->prepare("
114
                    SELECT  dispcdf_" . $field_values['field_name'] . "
115
                    FROM user_settings
116
                    WHERE user_id = :user_id");
117
                $stmt->bindValue('user_id', $_SESSION['s_user_id'], \PDO::PARAM_INT);
118
                $stmt->execute();
119
                $custom_domain_field_data[$count]['value'] = $stmt->fetchColumn();
120
121
                $count++;
122
123
            }
124
125
        }
126
127
        return $custom_domain_field_data;
128
129
    }
130
131
    public function getCSFData()
132
    {
133
        $custom_ssl_field_data = array();
134
135
        $result = $this->deeb->cnxx->query("
136
            SELECT name, field_name, type_id
137
            FROM ssl_cert_fields
138
            ORDER BY name")->fetchAll(\PDO::FETCH_ASSOC);
139
140
        if ($result) {
141
142
            $count = 0;
143
144
            foreach ($result as $field_values) {
145
146
                $custom_ssl_field_data[$count]['name'] = $field_values['name'];
147
                $custom_ssl_field_data[$count]['field'] = $field_values['field_name'];
148
                $custom_ssl_field_data[$count]['type_id'] = $field_values['type_id'];
149
                $custom_ssl_field_data[$count]['display_field'] = 'dispcsf_' . $field_values['field_name'];
150
151
                $stmt = $this->deeb->cnxx->prepare("
152
                    SELECT  dispcsf_" . $field_values['field_name'] . "
153
                    FROM user_settings
154
                    WHERE user_id = :user_id");
155
                $stmt->bindValue('user_id', $_SESSION['s_user_id'], \PDO::PARAM_INT);
156
                $stmt->execute();
157
                $custom_ssl_field_data[$count]['value'] = $stmt->fetchColumn();
158
159
                $count++;
160
161
            }
162
163
        }
164
165
        return $custom_ssl_field_data;
166
167
    }
168
169
} //@formatter:on
170