Account   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 209
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 135
c 0
b 0
f 0
dl 0
loc 209
rs 10
wmc 24

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A getNewInsertedId() 0 3 1
F getForm() 0 143 20
A getValuesAccount() 0 15 2
1
<?php
2
3
namespace XoopsModules\Wgevents;
4
5
/**
6
 * ****************************************************************************
7
 *  - A Project by Developers TEAM For Xoops - ( https://xoops.org )
8
 * ****************************************************************************
9
 *  WGEVENTS - MODULE FOR XOOPS
10
 *  Copyright (c) 2007 - 2012
11
 *  Goffy ( wedega.com )
12
 *
13
 *  You may not change or alter any portion of this comment or credits
14
 *  of supporting developers from this source code or any supporting
15
 *  source code which is considered copyrighted (c) material of the
16
 *  original comment or credit authors.
17
 *
18
 *  This program is distributed in the hope that it will be useful,
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 *  GNU General Public License for more details.
22
 *  ---------------------------------------------------------------------------
23
 * @copyright  Goffy ( wedega.com )
24
 * @license    GPL 2.0
25
 * @package    wgevents
26
 * @author     Goffy ( [email protected] )
27
 *
28
 * ****************************************************************************
29
 */
30
31
//use XoopsModules\Wgevents;
32
33
require_once dirname(__DIR__) . '/include/common.php';
34
35
/**
36
 * Class Account
37
 */
38
class Account extends \XoopsObject
39
{
40
    public $helper;
41
    public $db;
42
43
    //Constructor
44
45
    public function __construct()
46
    {
47
        $this->initVar('id', XOBJ_DTYPE_INT);
48
        $this->initVar('type', XOBJ_DTYPE_INT, Constants::ACCOUNT_TYPE_VAL_PHP_MAIL);
49
        $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 100);
50
        $this->initVar('yourname', XOBJ_DTYPE_TXTBOX, null, false, 100);
51
        $this->initVar('yourmail', XOBJ_DTYPE_TXTBOX, null, false, 100);
52
        $this->initVar('username', XOBJ_DTYPE_TXTBOX, null, false, 100);
53
        $this->initVar('password', XOBJ_DTYPE_TXTBOX, null, false, 100);
54
        $this->initVar('server_in', XOBJ_DTYPE_TXTBOX, null, false, 100);
55
        $this->initVar('port_in', XOBJ_DTYPE_INT, null, false, 100);
56
        $this->initVar('securetype_in', XOBJ_DTYPE_TXTBOX, null, false, 20);
57
        $this->initVar('server_out', XOBJ_DTYPE_TXTBOX, null, false, 100);
58
        $this->initVar('port_out', XOBJ_DTYPE_INT, null, false, 100);
59
        $this->initVar('securetype_out', XOBJ_DTYPE_TXTBOX);
60
        $this->initVar('limit_hour', XOBJ_DTYPE_INT);
61
        $this->initVar('primary', XOBJ_DTYPE_INT); // boolean
62
        $this->initVar('submitter', XOBJ_DTYPE_INT);
63
        $this->initVar('datecreated', XOBJ_DTYPE_INT, time());
64
    }
65
66
    /**
67
     * @param bool $action
68
     *
69
     * @return \XoopsThemeForm
70
     */
71
    public function getForm($action = false)
72
    {
73
        global $xoopsDB;
74
75
        if (false === $action) {
76
            $action = $_SERVER['REQUEST_URI'];
77
        }
78
79
        $title = $this->isNew() ? \_AM_WGEVENTS_ACCOUNT_ADD : \_AM_WGEVENTS_ACCOUNT_EDIT;
80
81
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
82
        $form = new \XoopsThemeForm($title, 'accounts_form', $action, 'post', true);
83
        $form->setExtra('enctype="multipart/form-data"');
84
85
        $default = $this->getVar('type');
86
87
        switch ($default) {
88
            case Constants::ACCOUNT_TYPE_VAL_PHP_MAIL:
89
            default:
90
                $dis_acc_userpass     = true;
91
                $dis_acc_server_in    = true;
92
                $dis_acc_server_out   = true;
93
                $dis_acc_button_check = true;
0 ignored issues
show
Unused Code introduced by
The assignment to $dis_acc_button_check is dead and can be removed.
Loading history...
94
                break;
95
            case Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL:
96
                $dis_acc_userpass     = false;
97
                $dis_acc_server_in    = true;
98
                $dis_acc_server_out   = false;
99
                $dis_acc_button_check = true;
100
                break;
101
            case Constants::ACCOUNT_TYPE_VAL_POP3:
102
            case Constants::ACCOUNT_TYPE_VAL_SMTP:
103
            case Constants::ACCOUNT_TYPE_VAL_GMAIL:
104
                $dis_acc_userpass     = false;
105
                $dis_acc_server_in    = false;
106
                $dis_acc_server_out   = false;
107
                $dis_acc_button_check = false;
108
                break;
109
        }
110
        // Form Select $type
111
        $type = $this->isNew() ? 1 : $this->getVar('type');
112
        $accstd_select = new \XoopsFormSelect(\_AM_WGEVENTS_ACCOUNT_TYPE, 'type', $type);
113
        $accstd_select->setExtra(" onchange='preselectAccFields()' ");
114
        $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_PHP_MAIL, \_AM_WGEVENTS_ACCOUNT_TYPE_PHPMAIL);
115
        $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL, \_AM_WGEVENTS_ACCOUNT_TYPE_PHPSENDMAIL);
116
        $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_POP3, \_AM_WGEVENTS_ACCOUNT_TYPE_POP3);
117
        $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_SMTP, \_AM_WGEVENTS_ACCOUNT_TYPE_SMTP);
118
        $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_GMAIL, \_AM_WGEVENTS_ACCOUNT_TYPE_GMAIL);
119
        $form->addElement($accstd_select);
120
        // Form Text $name
121
        $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_NAME, 'name', 50, 255, $this->getVar('name')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

121
        $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_NAME, 'name', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('name')));
Loading history...
122
        // Form Text $yourname
123
        $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_YOURNAME, 'yourname', 50, 255, $this->getVar('yourname')));
124
        // Form Text $yourmail
125
        $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_YOURMAIL, 'yourmail', 50, 255, $this->getVar('yourmail')));
126
        // Form RadioYN $primary
127
        $primary = $this->isNew() ? 0 : $this->getVar('primary');
128
        $form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_ACCOUNT_PRIMARY, 'primary', $primary, _YES, _NO));
0 ignored issues
show
Bug introduced by
It seems like $primary can also be of type array and array; however, parameter $value of XoopsFormRadioYN::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

128
        $form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_ACCOUNT_PRIMARY, 'primary', /** @scrutinizer ignore-type */ $primary, _YES, _NO));
Loading history...
129
        // Form Text $username
130
        $username = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_USERNAME, 'username', 50, 255, $this->getVar('username'));
131
        if ($dis_acc_userpass) {
132
            $username->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
133
        }
134
        $form->addElement($username);
135
        // Form Text $password
136
        $password = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_PASSWORD, 'password', 50, 255, $this->getVar('password'));
137
        if ($dis_acc_userpass) {
138
            $password->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
139
        }
140
        $form->addElement($password);
141
142
        // Form Tray Incoming
143
        $incomming_tray = new \XoopsFormElementTray(\_AM_WGEVENTS_ACCOUNT_INCOMING, '');
144
        // Form Tray Incoming - Server in
145
        $serverIn = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_SERVER_IN, 'server_in', 50, 255, $this->getVar('server_in'));
146
        if ($dis_acc_server_in) {
147
            $serverIn->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
148
        }
149
        $incomming_tray->addElement($serverIn);
150
        // Form Tray Incoming - Port in
151
        $portIn = new \XoopsFormText('<br>' . \_AM_WGEVENTS_ACCOUNT_PORT_IN, 'port_in', 50, 255, $this->getVar('port_in'));
152
        if ($dis_acc_server_in) {
153
            $portIn->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
154
        }
155
        $incomming_tray->addElement($portIn);
156
        // Form Tray Incoming - Secure type in
157
        $formfield_securetype_in = new \XoopsFormSelect('<br>' . \_AM_WGEVENTS_ACCOUNT_SECURETYPE_IN, 'securetype_in', $this->getVar('securetype_in'));
158
        $formfield_securetype_in->addOption('');
159
        $formfield_securetype_in->addOption('notls', 'NOTLS / STARTTLS');
160
        $formfield_securetype_in->addOption('ssl', 'SSL');
161
        $formfield_securetype_in->addOption('tls', 'TLS');
162
        if ($dis_acc_server_in) {
163
            $formfield_securetype_in->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
164
        }
165
        $incomming_tray->addElement($formfield_securetype_in);
166
        $form->addElement($incomming_tray);
167
168
        // Form Tray Outgoing
169
        $outcomming_tray = new \XoopsFormElementTray(\_AM_WGEVENTS_ACCOUNT_OUTGOING, '');
170
        // Form Tray Outgoing - Server out
171
        $serverOut = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_SERVER_OUT, 'server_out', 50, 255, $this->getVar('server_out'));
172
        if ($dis_acc_server_out) {
173
            $serverOut->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
174
        }
175
        $outcomming_tray->addElement($serverOut);
176
        // Form Tray Outgoing - Port out
177
        $portOut = new \XoopsFormText('<br>' . \_AM_WGEVENTS_ACCOUNT_PORT_OUT, 'port_out', 50, 255, $this->getVar('port_out'));
178
        if ($dis_acc_server_out) {
179
            $portOut->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
180
        }
181
        $outcomming_tray->addElement($portOut);
182
        // Form Tray Outgoing - Secure type out
183
        $formfield_securetype_out = new \XoopsFormSelect('<br>' . \_AM_WGEVENTS_ACCOUNT_SECURETYPE_OUT, 'securetype_out', $this->getVar('securetype_out'));
184
        $formfield_securetype_out->addOption('');
185
        $formfield_securetype_out->addOption('notls', 'NOTLS / STARTTLS');
186
        $formfield_securetype_out->addOption('ssl', 'SSL');
187
        $formfield_securetype_out->addOption('tls', 'TLS');
188
        if ($dis_acc_server_out) {
189
            $formfield_securetype_out->setExtra(' disabled="disabled" style="background-color:#d4d5d6"');
190
        }
191
        $outcomming_tray->addElement($formfield_securetype_out);
192
        $form->addElement($outcomming_tray);
193
        // Form Text $limitHour
194
        $limitHour = $this->isNew() ? 0 : $this->getVar('limit_hour');
195
        $limitHourText = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_LIMIT_HOUR, 'limit_hour', 50, 255, $limitHour);
196
        $limitHourText->setDescription(\_AM_WGEVENTS_ACCOUNT_LIMIT_HOUR_DESC);
197
        $form->addElement($limitHourText);
198
        //
199
        $time = $this->isNew() ? time() : $this->getVar('datecreated');
200
        $form->addElement(new \XoopsFormHidden('submitter', $GLOBALS['xoopsUser']->uid()));
201
        $form->addElement(new \XoopsFormHidden('datecreated', time()));
202
        $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
203
        $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_DATECREATED, formatTimestamp($time, 's')));
204
205
        // Buttons
206
        $buttonTray = new \XoopsFormElementTray(' ', '&nbsp;&nbsp;');
207
        $buttonTray->addElement(new \XoopsFormHidden('op', 'save'));
208
        $buttonTray->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
209
        //$button_check = new \XoopsFormButton('', 'save_and_check', \_AM_WGEVENTS_SAVE_AND_CHECK, 'submit');
210
        //$buttonTray->addElement($button_check);
211
        $form->addElement($buttonTray);
212
213
        return $form;
214
    }
215
216
    /**
217
     * Get Values
218
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
219
     * @param string|null $format
220
     * @param int|null $maxDepth
221
     * @return array
222
     */
223
    public function getValuesAccount($keys = null, $format = null, $maxDepth = null)
224
    {
225
        $ret = $this->getValues($keys, $format, $maxDepth);
226
        $acc_types = [
227
            Constants::ACCOUNT_TYPE_VAL_PHP_MAIL     => \_AM_WGEVENTS_ACCOUNT_TYPE_PHPMAIL,
228
            Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL => \_AM_WGEVENTS_ACCOUNT_TYPE_PHPSENDMAIL,
229
            Constants::ACCOUNT_TYPE_VAL_POP3         => \_AM_WGEVENTS_ACCOUNT_TYPE_POP3,
230
            Constants::ACCOUNT_TYPE_VAL_SMTP         => \_AM_WGEVENTS_ACCOUNT_TYPE_SMTP,
231
            Constants::ACCOUNT_TYPE_VAL_GMAIL        => \_AM_WGEVENTS_ACCOUNT_TYPE_GMAIL,
232
        ];
233
        $ret['type_text']        = $acc_types[$this->getVar('type')];
234
        $ret['primary_text']     = $this->getVar('primary') == 1 ? _YES : _NO;
235
        $ret['datecreated_text'] = formatTimestamp($this->getVar('datecreated'), 's');
236
        $ret['submitter_text']   = \XoopsUser::getUnameFromId($this->getVar('submitter'));
237
        return $ret;
238
    }
239
240
    /**
241
     * The new inserted $Id
242
     * @return inserted id
0 ignored issues
show
Bug introduced by
The type XoopsModules\Wgevents\inserted was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
243
     */
244
    public function getNewInsertedId()
245
    {
246
        return $GLOBALS['xoopsDB']->getInsertId();
247
    }
248
}
249