Completed
Push — master ( 266444...2ebe1b )
by Michael
01:31
created

admin/main.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
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * Contact module
14
 *
15
 * @copyright   XOOPS Project (https://xoops.org)
16
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @author      Kazumi Ono (aka Onokazu)
18
 * @author      Trabis <[email protected]>
19
 * @author      Hossein Azizabadi (AKA Voltan)
20
 */
21
22
use Xmf\Request;
23
24
// Call header
25
require __DIR__ . '/admin_header.php';
26
// Display Admin header
27
xoops_cp_header();
28
global $xoopsModuleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
29
// Define default value
30
$level      = '';
31
32
$saveinfo = $xoopsModuleConfig['saveinfo'];
33
$sendmail = $xoopsModuleConfig['sendmail'];
34
35
$op         = Request::getString('op', 'list');
36
$contact_id = Request::getInt('id', 0);
37
38
// Define scripts
39
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
40
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
41
$GLOBALS['xoTheme']->addScript(XOOPS_URL . '/modules/contact/assets/js/admin.js');
42
// Add module stylesheet
43
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/contact/assets/css/admin.css');
44
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
45
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
46
47
switch ($op) {
48
    case 'list':
49
        $contact            = [];
50
        $contact['perpage'] = xoops_getModuleOption('admin_perpage', 'contact');
51
        $contact['order']   = 'DESC';
52
        $contact['sort']    = 'contact_id';
53
54
        // get limited information
55
        $contact['limit'] = Request::getInt('limit', 0);
56
57
        // get start information
58
        $contact['start'] = Request::getInt('start', 0);
59
60
        $contact_numrows = $contactHandler->contactGetCount('contact_cid');
61
        $contacts        = $contactHandler->contactGetAdminList($contact, 'contact_cid');
62
63
        if ($contact_numrows > $contact['limit']) {
64
            $contact_pagenav = new XoopsPageNav($contact_numrows, $contact['limit'], $contact['start'], 'start', 'limit=' . $contact['limit']);
65
            $contact_pagenav = $contact_pagenav->renderNav(4);
66
        } else {
67
            $contact_pagenav = '';
68
        }
69
70
        $GLOBALS['xoopsTpl']->assign('contacts', $contacts);
71
        $GLOBALS['xoopsTpl']->assign('contact_pagenav', $contact_pagenav);
72
        $level = 'list';
73
        break;
74
75
    case 'reply':
76
        if ($contact_id > 0) {
77
            /** @var Contact $obj */
78
            $obj = $contactHandler->get($contact_id);
79
            if ($obj->getVar('contact_cid') != 0) {
80
                redirect_header('main.php', 3, _AM_CONTACT_CANTREPLY);
81
            }
82
            /** @var XoopsThemeForm $form */
83
            $form = $obj->contactReplyForm();
84
            $GLOBALS['xoopsTpl']->assign('replyform', $form->render());
85
            $GLOBALS['xoopsTpl']->assign('replylist', $contactHandler->contactGetReply($contact_id));
86
        } else {
87
            redirect_header('main.php', 3, _AM_CONTACT_MSG_EXIST);
88
        }
89
        $level = 'reply';
90
        break;
91
92
    case 'doreply':
93
        // check email
94
        if ('' === Request::getString('contact_mailto', '', 'POST')) {
95
            redirect_header('main.php', 3, _MD_CONTACT_MES_NOVALIDEMAIL);
96
        }
97
98
        // Info Processing
99
        $contact = $contactHandler->contactInfoProcessing();
100
101
        // insert in DB
102
        if (1 === $saveinfo) {
103
            $obj = $contactHandler->create();
104
            $obj->setVars($contact);
105
106
            if (!$contactHandler->insert($obj)) {
107
                redirect_header('main.php', 3, '4');
108
            }
109
110
            $contactHandler->contactAddReply($contact['contact_cid']);
111
        }
112
113
        // send mail can seet message
114
        $message = _MD_CONTACT_MES_SENDERROR;
115
        if (1 === $sendmail) {
116
            $message = $contactHandler->contactReplyMail($contact);
117
        } elseif (1 === $saveinfo) {
118
            $message = _MD_CONTACT_MES_SAVEINDB;
119
        }
120
121
        redirect_header('main.php', 3, $message);
122
123
        $level = 'doreply';
124
        break;
125
126
    case 'view':
127
        $obj = $contactHandler->get($contact_id);
128
129
        if (!$obj) {
130
            redirect_header('main.php', 3, _AM_CONTACT_MSG_EXIST);
131
        }
132
133
        $contact                       = [];
134
        $contact                       = $obj->toArray();
135
        $contact['contact_id']         = $obj->getVar('contact_id');
136
        $contact['contact_uid']        = $obj->getVar('contact_uid');
137
        $contact['contact_name']       = $obj->getVar('contact_name');
138
        $contact['contact_owner']      = XoopsUser::getUnameFromId($obj->getVar('contact_uid'));
139
        $contact['contact_subject']    = $obj->getVar('contact_subject');
140
        $contact['contact_mail']       = $obj->getVar('contact_mail');
141
        $contact['contact_url']        = $obj->getVar('contact_url');
142
        $contact['contact_create']     = formatTimestamp($obj->getVar('contact_create'), _MEDIUMDATESTRING);
143
        $contact['contact_icq']        = $obj->getVar('contact_icq');
144
        $contact['contact_company']    = $obj->getVar('contact_company');
145
        $contact['contact_location']   = $obj->getVar('contact_location');
146
        $contact['contact_phone']      = $obj->getVar('contact_phone');
147
        $contact['contact_department'] = $obj->getVar('contact_department');
148
        $contact['contact_ip']         = $obj->getVar('contact_ip');
149
        $contact['contact_message']    = $obj->getVar('contact_message');
150
        $contact['contact_address']    = $obj->getVar('contact_address');
151
152
        $GLOBALS['xoopsTpl']->assign('contact', $contact);
153
        $GLOBALS['xoopsTpl']->assign('replylist', $contactHandler->contactGetReply($contact_id));
154
155
        $level = 'view';
156
        break;
157
158
    case 'delete':
159
        if ($contact_id > 0) {
160
            // Prompt message
161
            xoops_confirm(['id' => $contact_id], 'main.php?op=dodelete', _AM_CONTACT_MSG_DELETE);
162
        } else {
163
            redirect_header('main.php', 3, _AM_CONTACT_MSG_EXIST);
164
        }
165
166
        $level = 'delete';
167
        break;
168
169
    case 'dodelete':
170
        if (!$contact_id > 0) {
171
            redirect_header('main.php', 3, _AM_CONTACT_MSG_EXIST);
172
            //            xoops_cp_footer();
173
            //            exit();
174
        }
175
176
        $criteria = new CriteriaCompo();
177
        $criteria->add(new Criteria('contact_id', $contact_id));
178
        $criteria->add(new Criteria('contact_cid', $contact_id), 'OR');
179
180
        if (!$contactHandler->deleteAll($criteria)) {
181
            redirect_header('main.php', 1, _AM_CONTACT_MSG_DELETEERROR);
182
            //            xoops_cp_footer();
183
            //            exit();
184
        }
185
186
        redirect_header('main.php', 1, _AM_CONTACT_MSG_DELETED);
187
    //        xoops_cp_footer();
188
    //        exit();
189
    //        break;
190
}
191
192
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation(basename(__FILE__)));
193
$GLOBALS['xoopsTpl']->assign('level', $level);
194
195
// Call template file
196
$GLOBALS['xoopsTpl']->display(XOOPS_ROOT_PATH . '/modules/contact/templates/admin/contact_main.tpl');
197
// Call footer
198
require __DIR__ . '/admin_footer.php';
199