Completed
Push — master ( 592643...f454c2 )
by Michael
03:05 queued 01:21
created

Attachment::getForm()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 35
rs 9.36
c 0
b 0
f 0
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    GNU General Public License 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 Attachment
37
 */
38
class Attachment extends \XoopsObject
39
{
40
    public $helper = null;
41
42
    //Constructor
43
44
    public function __construct()
45
    {
46
        $this->helper = Helper::getInstance();
47
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
48
        $this->initVar('attachment_id', XOBJ_DTYPE_INT, null, false);
49
        $this->initVar('attachment_letter_id', XOBJ_DTYPE_INT, null, false);
50
        $this->initVar('attachment_name', XOBJ_DTYPE_TXTBOX, null, false, 200);
51
        $this->initVar('attachment_type', XOBJ_DTYPE_TXTBOX, null, false, 100);
52
        $this->initVar('attachment_submitter', XOBJ_DTYPE_INT, null, false);
53
        $this->initVar('attachment_created', XOBJ_DTYPE_INT, time(), false);
54
        $this->initVar('attachment_size', XOBJ_DTYPE_INT, 0, false);
55
        $this->initVar('attachment_mode', XOBJ_DTYPE_INT, _XNEWSLETTER_ATTACHMENTS_MODE_ASATTACHMENT, false);
56
    }
57
58
    /**
59
     * @param bool $action
60
     *
61
     * @return \XoopsThemeForm
62
     */
63
    public function getForm($action = false)
64
    {
65
        global $xoopsDB;
66
67
        if (false === $action) {
68
            $action = $_SERVER['REQUEST_URI'];
69
        }
70
71
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_ATTACHMENT_ADD) : sprintf(_AM_XNEWSLETTER_ATTACHMENT_EDIT);
72
73
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
74
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
75
        $form->setExtra('enctype="multipart/form-data"');
76
77
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_ATTACHMENT_NAME, $this->getVar('attachment_name')));
78
79
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_ATTACHMENT_SIZE, "<span title='" . $this->getVar('attachment_size') . " B'>" . xnewsletter_bytesToSize1024($this->getVar('attachment_size')) . '</span>'));
80
81
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_ATTACHMENT_TYPE, $this->getVar('attachment_type')));
82
83
        // attachment_mode
84
        $mode_select = new \XoopsFormRadio(_AM_XNEWSLETTER_ATTACHMENT_MODE, 'attachment_mode', $this->getVar('attachment_mode'));
85
        $mode_select->addOption(_XNEWSLETTER_ATTACHMENTS_MODE_ASATTACHMENT, _AM_XNEWSLETTER_ATTACHMENT_MODE_ASATTACHMENT);
86
        $mode_select->addOption(_XNEWSLETTER_ATTACHMENTS_MODE_ASLINK, _AM_XNEWSLETTER_ATTACHMENT_MODE_ASLINK);
87
        //$mode_select->addOption(_XNEWSLETTER_ATTACHMENTS_MODE_AUTO, _AM_XNEWSLETTER_ATTACHMENT_MODE_AUTO);  // for future features
88
        $form->addElement($mode_select);
89
90
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_ATTACHMENT_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
91
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_ATTACHMENT_CREATED, formatTimestamp($time, 's')));
0 ignored issues
show
Bug introduced by
The variable $time does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
92
93
        $form->addElement(new \XoopsFormHidden('op', 'save_attachment'));
94
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
95
96
        return $form;
97
    }
98
}
99