Confirm   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B getFormConfirm() 0 38 6
1
<?php
2
3
namespace XoopsModules\Wgfilemanager\Common;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * Custom form confirm for XOOPS modules
17
 *
18
 * @copyright     2020 XOOPS Project (https://xoops.org)
19
 * @license        GPL 2.0 or later
20
 * @package        general
21
 * @author         Goffy - Email:<[email protected]> - Website:<https://xoops.org>
22
 *
23
 *
24
 * Example:
25
    $customConfirm = new Common\Confirm(
26
        ['ok' => 1, 'item_id' => $itemId, 'op' => 'delete'],
27
        $_SERVER['REQUEST_URI'],
28
        \sprintf(\_MA_MYMODULE_FORM_SURE_DELETE,
29
        $itemsObj->getCaption()));
30
    $form = $customConfirm->getFormConfirm();
31
    $GLOBALS['xoopsTpl']->assign('form', $form->render());
32
 */
33
34
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
35
36
/**
37
 * Class Object Confirm
38
 */
39
class Confirm
40
{
41
    private $hiddens = [];
42
    private $action  = '';
43
    private $title   = '';
44
    private $label   = '';
45
    private $object  = '';
46
47
    /**
48
     * @public function constructor class
49
     * @param        $hiddens
50
     * @param        $action
51
     * @param        $object
52
     * @param string $title
53
     * @param string $label
54
     */
55
    public function __construct($hiddens, $action, $object, $title = '', $label = '')
56
    {
57
        $this->hiddens = $hiddens;
58
        $this->action  = $action;
59
        $this->object  = $object;
60
        $this->title   = $title;
61
        $this->label   = $label;
62
    }
63
64
    /**
65
     * @public function getFormConfirm
66
     * @return \XoopsThemeForm
67
     */
68
    public function getFormConfirm()
69
    {
70
        $moduleDirName      = \basename(__DIR__);
71
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
72
        //in order to be accessable from user and admin area this should be place in language common.php
73
        if (!\defined('CO_' . $moduleDirNameUpper . '_DELETE_CONFIRM')) {
74
            \define('CO_' . $moduleDirNameUpper . '_DELETE_CONFIRM', 'Confirm delete');
75
            \define('CO_' . $moduleDirNameUpper . '_DELETE_LABEL', 'Do you really want to delete:');
76
        }
77
78
        // Get Theme Form
79
        if ('' === $this->action) {
80
            $this->action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER');
81
        }
82
        if ('' === $this->title) {
83
            $this->title = \constant('CO_' . $moduleDirNameUpper . '_DELETE_CONFIRM');
84
        }
85
        if ('' === $this->label) {
86
87
            $this->label = \constant('CO_' . $moduleDirNameUpper . '_DELETE_LABEL');
88
        }
89
90
        \xoops_load('XoopsFormLoader');
91
        $form = new \XoopsThemeForm($this->title, 'formConfirm', $this->action, 'post', true);
92
        $form->setExtra('enctype="multipart/form-data"');
93
        $form->addElement(new \XoopsFormLabel($this->label, $this->object));
94
        //hiddens
95
        foreach ($this->hiddens as $key => $value) {
96
            $form->addElement(new \XoopsFormHidden($key, $value));
97
        }
98
        $form->addElement(new \XoopsFormHidden('ok', 1));
99
        $buttonTray = new \XoopsFormElementTray('');
100
        $buttonTray->addElement(new \XoopsFormButton('', 'confirm_submit', \_YES, 'submit'));
101
        $buttonBack = new \XoopsFormButton('', 'confirm_back', \_NO, 'button');
102
        $buttonBack->setExtra('onclick="history.go(-1);return true;"');
103
        $buttonTray->addElement($buttonBack);
104
        $form->addElement($buttonTray);
105
        return $form;
106
    }
107
}
108