Completed
Pull Request — master (#29)
by Goffy
01:40
created

class/Accounts.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace XoopsModules\Xnewsletter;
4
5
/**
6
 * ****************************************************************************
7
 *  - A Project by Developers TEAM For Xoops - ( https://xoops.org )
8
 * ****************************************************************************
9
 *  XNEWSLETTER - 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    xnewsletter
26
 * @author     Goffy ( [email protected] )
27
 *
28
 * ****************************************************************************
29
 */
30
31
//use XoopsModules\Xnewsletter;
32
33
require_once dirname(__DIR__) . '/include/common.php';
34
35
/**
36
 * Class Accounts
37
 */
38
class Accounts extends \XoopsObject
39
{
40
    public $helper = null;
41
    public $db;
42
43
    //Constructor
44
45
    public function __construct()
46
    {
47
        $this->helper = Helper::getInstance();
48
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
49
        $this->initVar('accounts_id', XOBJ_DTYPE_INT, null, false);
50
        $this->initVar('accounts_type', XOBJ_DTYPE_INT, _XNEWSLETTER_ACCOUNTS_TYPE_VAL_PHP_MAIL, false);
51
        $this->initVar('accounts_name', XOBJ_DTYPE_TXTBOX, null, false, 100);
52
        $this->initVar('accounts_yourname', XOBJ_DTYPE_TXTBOX, null, false, 100);
53
        $this->initVar('accounts_yourmail', XOBJ_DTYPE_TXTBOX, null, false, 100);
54
        $this->initVar('accounts_username', XOBJ_DTYPE_TXTBOX, null, false, 100);
55
        $this->initVar('accounts_password', XOBJ_DTYPE_TXTBOX, null, false, 100);
56
        $this->initVar('accounts_server_in', XOBJ_DTYPE_TXTBOX, null, false, 100);
57
        $this->initVar('accounts_port_in', XOBJ_DTYPE_TXTBOX, null, false, 100);
58
        $this->initVar('accounts_securetype_in', XOBJ_DTYPE_TXTBOX, null, false, 20);
59
        $this->initVar('accounts_server_out', XOBJ_DTYPE_TXTBOX, null, false, 100);
60
        $this->initVar('accounts_port_out', XOBJ_DTYPE_TXTBOX, null, false, 100);
61
        $this->initVar('accounts_securetype_out', XOBJ_DTYPE_TXTAREA, null, false);
62
        $this->initVar('accounts_use_bmh', XOBJ_DTYPE_INT, null, false);
63
        $this->initVar('accounts_inbox', XOBJ_DTYPE_TXTBOX, null, false, 100);
64
        $this->initVar('accounts_hardbox', XOBJ_DTYPE_TXTBOX, null, false, 100);
65
        $this->initVar('accounts_movehard', XOBJ_DTYPE_INT, null, false);
66
        $this->initVar('accounts_softbox', XOBJ_DTYPE_TXTBOX, null, false, 100);
67
        $this->initVar('accounts_movesoft', XOBJ_DTYPE_INT, null, false);
68
        $this->initVar('accounts_default', XOBJ_DTYPE_INT, null, false); // boolean
69
        $this->initVar('accounts_submitter', XOBJ_DTYPE_INT, null, false);
70
        $this->initVar('accounts_created', XOBJ_DTYPE_INT, time(), false);
71
    }
72
73
    /**
74
     * @param bool $action
75
     *
76
     * @return \XoopsThemeForm
77
     */
78
    public function getForm($action = false)
79
    {
80
        global $xoopsDB;
81
82
        if (false === $action) {
83
            $action = $_SERVER['REQUEST_URI'];
84
        }
85
86
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_ACCOUNTS_ADD) : sprintf(_AM_XNEWSLETTER_ACCOUNTS_EDIT);
87
88
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
89
        $form = new \XoopsThemeForm($title, $this->helper->getModule()->getVar('dirname') . '_form', $action, 'post', true);
90
        $form->setExtra('enctype="multipart/form-data"');
91
92
        $default = $this->getVar('accounts_type');
93
94
        switch ($default) {
95
            case _XNEWSLETTER_ACCOUNTS_TYPE_VAL_PHP_MAIL:
96 View Code Duplication
            default:
97
                $dis_accounts_userpass     = true;
98
                $dis_accounts_server_in    = true;
99
                $dis_accounts_server_out   = true;
100
                $dis_accounts_use_bmh      = true;
101
                $dis_accounts_button_check = true;
102
                break;
103 View Code Duplication
            case _XNEWSLETTER_ACCOUNTS_TYPE_VAL_PHP_SENDMAIL:
104
                $dis_accounts_userpass     = false;
105
                $dis_accounts_server_in    = true;
106
                $dis_accounts_server_out   = false;
107
                $dis_accounts_use_bmh      = true;
108
                $dis_accounts_button_check = true;
109
                break;
110 View Code Duplication
            case _XNEWSLETTER_ACCOUNTS_TYPE_VAL_POP3:
111
                $dis_accounts_userpass     = false;
112
                $dis_accounts_server_in    = false;
113
                $dis_accounts_server_out   = false;
114
                $dis_accounts_use_bmh      = true;
115
                $dis_accounts_button_check = false;
116
                break;
117
            case _XNEWSLETTER_ACCOUNTS_TYPE_VAL_SMTP:
118 View Code Duplication
            case _XNEWSLETTER_ACCOUNTS_TYPE_VAL_GMAIL:
119
                $dis_accounts_userpass     = false;
120
                $dis_accounts_server_in    = false;
121
                $dis_accounts_server_out   = false;
122
                $dis_accounts_use_bmh      = false;
123
                $dis_accounts_button_check = false;
124
                break;
125
        }
126
127
        $accstd_select = new \XoopsFormSelect(_AM_XNEWSLETTER_ACCOUNTS_TYPE, 'accounts_type', $this->getVar('accounts_type'));
128
        $accstd_select->setExtra('onchange="document.forms.' . $this->helper->getModule()->getVar('dirname') . '_form.submit()"');
129
        $accstd_select->addOption(_XNEWSLETTER_ACCOUNTS_TYPE_VAL_PHP_MAIL, _AM_XNEWSLETTER_ACCOUNTS_TYPE_PHPMAIL);
130
        $accstd_select->addOption(_XNEWSLETTER_ACCOUNTS_TYPE_VAL_PHP_SENDMAIL, _AM_XNEWSLETTER_ACCOUNTS_TYPE_PHPSENDMAIL);
131
        $accstd_select->addOption(_XNEWSLETTER_ACCOUNTS_TYPE_VAL_POP3, _AM_XNEWSLETTER_ACCOUNTS_TYPE_POP3);
132
        $accstd_select->addOption(_XNEWSLETTER_ACCOUNTS_TYPE_VAL_SMTP, _AM_XNEWSLETTER_ACCOUNTS_TYPE_SMTP);
133
        $accstd_select->addOption(_XNEWSLETTER_ACCOUNTS_TYPE_VAL_GMAIL, _AM_XNEWSLETTER_ACCOUNTS_TYPE_GMAIL);
134
        $form->addElement($accstd_select, true);
135
136
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_NAME, 'accounts_name', 50, 255, $this->getVar('accounts_name')), true);
137
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_YOURNAME, 'accounts_yourname', 50, 255, $this->getVar('accounts_yourname')), true);
138
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_YOURMAIL, 'accounts_yourmail', 50, 255, $this->getVar('accounts_yourmail')), true);
139
140
        $form->addElement(new \XoopsFormRadioYN(_AM_XNEWSLETTER_ACCOUNTS_DEFAULT, 'accounts_default', $this->getVar('accounts_default'), _YES, _NO), false);
141
142 View Code Duplication
        if (false === $dis_accounts_userpass) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
            $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_USERNAME, 'accounts_username', 50, 255, $this->getVar('accounts_username')), true);
144
            $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_PASSWORD, 'accounts_password', 50, 255, $this->getVar('accounts_password')), true);
145
        }
146
147 View Code Duplication
        if (false === $dis_accounts_server_in) {
148
            $incomming_tray = new \XoopsFormElementTray(_AM_XNEWSLETTER_ACCOUNTS_INCOMING, '');
149
            $incomming_tray->addElement(new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_SERVER_IN, 'accounts_server_in', 50, 255, $this->getVar('accounts_server_in')));
150
            $incomming_tray->addElement(new \XoopsFormText('<br>' . _AM_XNEWSLETTER_ACCOUNTS_PORT_IN, 'accounts_port_in', 50, 255, $this->getVar('accounts_port_in')));
151
            $formfield_securetype_in = new \XoopsFormSelect('<br>' . _AM_XNEWSLETTER_ACCOUNTS_SECURETYPE_IN, 'accounts_securetype_in', $this->getVar('accounts_securetype_in'));
152
            $formfield_securetype_in->addOption('', '');
153
            $formfield_securetype_in->addOption('notls', 'NOTLS / STARTTLS');
154
            $formfield_securetype_in->addOption('ssl', 'SSL');
155
            $formfield_securetype_in->addOption('tls', 'TLS');
156
            $incomming_tray->addElement($formfield_securetype_in);
157
            $form->addElement($incomming_tray);
158
        }
159
160 View Code Duplication
        if (false === $dis_accounts_server_out) {
161
            $outcomming_tray = new \XoopsFormElementTray(_AM_XNEWSLETTER_ACCOUNTS_OUTGOING, '');
162
            $outcomming_tray->addElement(new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_SERVER_OUT, 'accounts_server_out', 50, 255, $this->getVar('accounts_server_out')));
163
            $outcomming_tray->addElement(new \XoopsFormText('<br>' . _AM_XNEWSLETTER_ACCOUNTS_PORT_OUT, 'accounts_port_out', 50, 255, $this->getVar('accounts_port_out')));
164
            $formfield_securetype_out = new \XoopsFormSelect('<br>' . _AM_XNEWSLETTER_ACCOUNTS_SECURETYPE_OUT, 'accounts_securetype_out', $this->getVar('accounts_securetype_out'));
165
            $formfield_securetype_out->addOption('', '');
166
            $formfield_securetype_out->addOption('notls', 'NOTLS / STARTTLS');
167
            $formfield_securetype_out->addOption('ssl', 'SSL');
168
            $formfield_securetype_out->addOption('tls', 'TLS');
169
            $outcomming_tray->addElement($formfield_securetype_out);
170
            $form->addElement($outcomming_tray);
171
        }
172
173
        if (false === $dis_accounts_use_bmh) {
174
            $form->addElement(new \XoopsFormLabel('', _AM_XNEWSLETTER_ACCOUNTS_BOUNCE_INFO));
175
176
            $formfield_use_bmh = new \XoopsFormRadioYN(_AM_XNEWSLETTER_ACCOUNTS_USE_BMH, 'accounts_use_bmh', $this->getVar('accounts_use_bmh'), _YES, _NO);
177
            $form->addElement($formfield_use_bmh, false);
178
179
            $formfield_inbox = new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_INBOX, 'accounts_inbox', 50, 255, $this->getVar('accounts_inbox'));
180
            $form->addElement($formfield_inbox, false);
181
182
            //Hardbox
183
            $hard_tray          = new \XoopsFormElementTray(_AM_XNEWSLETTER_BOUNCETYPE . ' ' . _XNEWSLETTER_BOUNCETYPE_HARD, '<br>');
184
            $formfield_movehard = new \XoopsFormRadioYN(_AM_XNEWSLETTER_ACCOUNTS_MOVEHARD, 'accounts_movehard', $this->getVar('accounts_movehard'), _YES, _NO);
185
            $hard_tray->addElement($formfield_movehard, false);
186
            $formfield_hardbox = new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_HARDBOX, 'accounts_hardbox', 50, 255, $this->getVar('accounts_hardbox'));
187
            $hard_tray->addElement($formfield_hardbox, false);
188
            $hard_tray->addElement(new \XoopsFormLabel('', _AM_XNEWSLETTER_ACCOUNTS_HARDBOX_DESC), false);
189
            $form->addElement($hard_tray, false);
190
191
            //Softbox
192
            $soft_tray          = new \XoopsFormElementTray(_AM_XNEWSLETTER_BOUNCETYPE . ' ' . _XNEWSLETTER_BOUNCETYPE_SOFT, '<br>');
193
            $formfield_movesoft = new \XoopsFormRadioYN(_AM_XNEWSLETTER_ACCOUNTS_MOVESOFT, 'accounts_movesoft', $this->getVar('accounts_movesoft'), _YES, _NO);
194
            $soft_tray->addElement($formfield_movesoft, false);
195
            $formfield_softbox = new \XoopsFormText(_AM_XNEWSLETTER_ACCOUNTS_SOFTBOX, 'accounts_softbox', 50, 255, $this->getVar('accounts_softbox'));
196
            $soft_tray->addElement($formfield_softbox, false);
197
            $soft_tray->addElement(new \XoopsFormLabel('', _AM_XNEWSLETTER_ACCOUNTS_HARDBOX_DESC), false);
198
            $form->addElement($soft_tray, false);
199
        }
200
        $time = $this->isNew() ? time() : $this->getVar('accounts_created');
201
        $form->addElement(new \XoopsFormHidden('accounts_submitter', $GLOBALS['xoopsUser']->uid()));
202
        $form->addElement(new \XoopsFormHidden('accounts_created', $time));
203
204
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
205
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_CREATED, formatTimestamp($time, 's')));
206
207
        $buttonTray = new \XoopsFormElementTray(' ', '&nbsp;&nbsp;');
208
        $buttonTray->addElement(new \XoopsFormHidden('op', 'save_accounts'));
209
        $buttonTray->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
210
        if (false === $dis_accounts_button_check) {
211
            $button_check = new \XoopsFormButton('', 'save_and_check', _AM_XNEWSLETTER_SAVE_AND_CHECK, 'submit');
212
            $buttonTray->addElement($button_check);
213
        }
214
        $form->addElement($buttonTray, false);
215
216
        return $form;
217
    }
218
219
    /**
220
     * Get Values
221
     * @param null $keys
222
     * @param string|null $format
223
     * @param int|null $maxDepth
224
     * @return array
225
     */
226
    public function getValuesAccount($keys = null, $format = null, $maxDepth = null)
227
    {
228
        $ret = $this->getValues($keys, $format, $maxDepth);
229
        $ret['id'] = $this->getVar('accounts_id');
230
        $accounts_types = [
231
            _XNEWSLETTER_ACCOUNTS_TYPE_VAL_PHP_MAIL     => _AM_XNEWSLETTER_ACCOUNTS_TYPE_PHPMAIL,
232
            _XNEWSLETTER_ACCOUNTS_TYPE_VAL_PHP_SENDMAIL => _AM_XNEWSLETTER_ACCOUNTS_TYPE_PHPSENDMAIL,
233
            _XNEWSLETTER_ACCOUNTS_TYPE_VAL_POP3         => _AM_XNEWSLETTER_ACCOUNTS_TYPE_POP3,
234
            _XNEWSLETTER_ACCOUNTS_TYPE_VAL_SMTP         => _AM_XNEWSLETTER_ACCOUNTS_TYPE_SMTP,
235
            _XNEWSLETTER_ACCOUNTS_TYPE_VAL_GMAIL        => _AM_XNEWSLETTER_ACCOUNTS_TYPE_GMAIL,
236
        ];
237
        $ret['type']           = $this->getVar('accounts_type');
238
        $ret['type_text']      = $accounts_types[$this->getVar('accounts_type')];
239
        $ret['name']           = $this->getVar('accounts_name');
240
        $ret['yourname']       = $this->getVar('accounts_yourname');
241
        $ret['yourmail']       = $this->getVar('accounts_yourmail');
242
        $ret['username']       = $this->getVar('accounts_username');
243
        $ret['password']       = $this->getVar('accounts_password');
244
        $ret['server_in']      = $this->getVar('accounts_server_in');
245
        $ret['port_in']        = $this->getVar('accounts_port_in');
246
        $ret['securetype_in']  = $this->getVar('accounts_securetype_in');
247
        $ret['server_out']     = $this->getVar('accounts_server_out');
248
        $ret['port_out']       = $this->getVar('accounts_port_out');
249
        $ret['securetype_out'] = $this->getVar('accounts_securetype_out');
250
        $ret['use_bmh']        = $this->getVar('accounts_use_bmh');
251
        $ret['inbox']          = $this->getVar('accounts_inbox');
252
        $ret['hardbox']        = $this->getVar('accounts_hardbox');
253
        $ret['movehard']       = $this->getVar('accounts_movehard');
254
        $ret['softbox']        = $this->getVar('accounts_softbox');
255
        $ret['movesoft']       = $this->getVar('accounts_movesoft');
256
        $ret['default']        = $this->getVar('accounts_default');
257
        $ret['default_text']   = $this->getVar('accounts_default') == 1 ? _YES : _NO;
258
        $ret['created']        = formatTimestamp($this->getVar('accounts_created'), 's');
259
        $ret['submitter']      = \XoopsUser::getUnameFromId($this->getVar('accounts_submitter'));
260
        return $ret;
261
    }
262
}
263