Passed
Push — master ( 4761c2...696f77 )
by
unknown
05:50 queued 19s
created

class/Form/GroupsForm.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Suico\Form;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
*/
15
16
/**
17
 * @category        Module
18
 * @package         suico
19
 * @copyright       {@link https://xoops.org/ XOOPS Project}
20
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
21
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
22
 */
23
24
use Xmf\Module\Helper\Permission;
25
use XoopsFormButton;
26
use XoopsFormDhtmlTextArea;
27
use XoopsFormEditor;
28
use XoopsFormElementTray;
29
use XoopsFormFile;
30
use XoopsFormHidden;
31
use XoopsFormLabel;
32
use XoopsFormSelect;
33
use XoopsFormSelectUser;
34
use XoopsFormText;
35
use XoopsLists;
36
use XoopsModules\Suico;
37
use XoopsThemeForm;
38
39
require_once \dirname(__DIR__, 2) . '/include/common.php';
40
$moduleDirName = \basename(\dirname(__DIR__, 2));
41
//$helper = Suico\Helper::getInstance();
42
$permHelper = new Permission();
43
\xoops_load('XoopsFormLoader');
44
45
/**
46
 * Class GroupsForm
47
 */
48
class GroupsForm extends XoopsThemeForm
49
{
50
    public $targetObject;
51
    public $helper;
52
53
    /**
54
     * Constructor
55
     *
56
     * @param $target
57
     */
58
    public function __construct($target)
59
    {
60
        $this->helper       = $target->helper;
61
        $this->targetObject = $target;
62
        $title              = $this->targetObject->isNew() ? \sprintf(\AM_SUICO_GROUPS_ADD) : \sprintf(\AM_SUICO_GROUPS_EDIT);
63
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
64
        $this->setExtra('enctype="multipart/form-data"');
65
        //include ID field, it's needed so the module knows if it is a new form or an edited form
66
        $hidden = new XoopsFormHidden(
67
            'group_id', $this->targetObject->getVar(
68
            'group_id'
69
        )
70
        );
71
        $this->addElement($hidden);
72
        unset($hidden);
73
        // Group_id
74
        $this->addElement(
75
            new XoopsFormLabel(\AM_SUICO_GROUPS_GROUP_ID, $this->targetObject->getVar('group_id'), 'group_id')
76
        );
77
        // Owner_uid
78
        $this->addElement(
79
            new XoopsFormSelectUser(
80
                \AM_SUICO_GROUPS_OWNER_UID, 'owner_uid', false, $this->targetObject->getVar(
81
                'owner_uid'
82
            ), 1, false
83
            ),
84
            false
85
        );
86
        // Group_title
87
        $this->addElement(
88
            new XoopsFormText(
89
                \AM_SUICO_GROUPS_GROUP_TITLE, 'group_title', 50, 255, $this->targetObject->getVar(
90
                'group_title'
91
            )
92
            ),
93
            false
94
        );
95
        // Group_desc
96
        if (\class_exists('XoopsFormEditor')) {
97
            $editorOptions           = [];
98
            $editorOptions['name']   = 'group_desc';
99
            $editorOptions['value']  = $this->targetObject->getVar('group_desc', 'e');
100
            $editorOptions['rows']   = 5;
101
            $editorOptions['cols']   = 40;
102
            $editorOptions['width']  = '100%';
103
            $editorOptions['height'] = '400px';
104
            //$editorOptions['editor'] = xoops_getModuleOption('suico_editor', 'suico');
105
            //$this->addElement( new \XoopsFormEditor(AM_SUICO_GROUPS_GROUP_DESC, 'group_desc', $editorOptions), false  );
106
            if ($this->helper->isUserAdmin()) {
107
                $descEditor = new XoopsFormEditor(
108
                    \AM_SUICO_GROUPS_GROUP_DESC, $this->helper->getConfig(
109
                    'suicoEditorAdmin'
110
                ), $editorOptions, $nohtml = false, $onfailure = 'textarea'
111
                );
112
            } else {
113
                $descEditor = new XoopsFormEditor(
114
                    \AM_SUICO_GROUPS_GROUP_DESC, $this->helper->getConfig(
115
                    'suicoEditorUser'
116
                ), $editorOptions, $nohtml = false, $onfailure = 'textarea'
117
                );
118
            }
119
        } else {
120
            $descEditor = new XoopsFormDhtmlTextArea(
121
                \AM_SUICO_GROUPS_GROUP_DESC, 'description', $this->targetObject->getVar(
122
                'description',
123
                'e'
124
            ), 5, 50
125
            );
126
        }
127
        $this->addElement($descEditor);
128
        // Group_img
129
        $group_img   = $this->targetObject->getVar('group_img') ?: 'blank.png';
130
        $uploadDir   = '/uploads/suico/groups/';
131
        $imgtray     = new XoopsFormElementTray(\AM_SUICO_GROUPS_GROUP_IMG, '<br>');
132
        $imgpath     = \sprintf(\AM_SUICO_FORMIMAGE_PATH, $uploadDir);
133
        $imageselect = new XoopsFormSelect($imgpath, 'group_img', $group_img);
134
        $imageArray  = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDir);
135
        foreach ($imageArray as $image) {
136
            $imageselect->addOption($image, $image);
137
        }
138
        $imageselect->setExtra(
139
            "onchange='showImgSelected(\"image_group_img\", \"group_img\", \"" . $uploadDir . '", "", "' . XOOPS_URL . "\")'"
140
        );
141
        $imgtray->addElement($imageselect);
142
        $imgtray->addElement(
143
            new XoopsFormLabel(
144
                '', "<br><img src='" . XOOPS_URL . '/' . $uploadDir . '/' . $group_img . "' name='image_group_img' id='image_group_img' alt='' style='max-width:300px'>"
145
            )
146
        );
147
        $fileseltray = new XoopsFormElementTray('', '<br>');
148
        $fileseltray->addElement(
149
            new XoopsFormFile(\AM_SUICO_FORMUPLOAD, 'group_img', $this->helper->getConfig('maxsize'))
150
        );
151
        $fileseltray->addElement(new XoopsFormLabel(''));
152
        $imgtray->addElement($fileseltray);
153
        $this->addElement($imgtray);
154
        // Data_creation
155
        $this->addElement(
156
            new \XoopsFormTextDateSelect(
157
                \AM_SUICO_GROUPS_DATE_CREATED, 'date_created', 0, \formatTimestamp($this->targetObject->getVar('date_created'), 's')
0 ignored issues
show
formatTimestamp($this->t...r('date_created'), 's') of type string is incompatible with the type integer expected by parameter $value of XoopsFormTextDateSelect::__construct(). ( Ignorable by Annotation )

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

157
                \AM_SUICO_GROUPS_DATE_CREATED, 'date_created', 0, /** @scrutinizer ignore-type */ \formatTimestamp($this->targetObject->getVar('date_created'), 's')
Loading history...
158
            )
159
        );
160
        // Data_update
161
        $this->addElement(
162
            new \XoopsFormTextDateSelect(
163
                \AM_SUICO_GROUPS_DATE_UPDATED, 'date_updated', 0, \formatTimestamp($this->targetObject->getVar('date_updated'), 's')
164
            )
165
        );
166
        $this->addElement(new XoopsFormHidden('op', 'save'));
167
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
168
    }
169
}
170