XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
deleteAction.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
18{
19 // No need for $mActionForm property here
20 private string $inout = 'inbox';
21
22 public function __construct()
23 {
24 if (method_exists('AbstractAction', '__construct')) {
25 parent::__construct();
26 }
27 }
28
29 public function execute()
30 {
31 $isAjax = $this->root->mContext->mRequest->getRequest('ajax') == 1;
32
33 if ('in' == $this->root->mContext->mRequest->getRequest('inout')) {
34 $this->inout = 'inbox';
35 } else {
36 $this->inout = 'outbox';
37 }
38
39 // Remove duplicate handler initialization
40 $modHand = xoops_getmodulehandler($this->inout, _MY_DIRNAME);
41 $boxid = (int)$this->root->mContext->mRequest->getRequest($this->inout);
42 $modObj = $modHand->get($boxid);
43
44 // --- Validation ---
45 if (!is_object($modObj)) {
46 if ($isAjax) {
47 header('Content-Type: application/json');
48 echo json_encode(['success' => false, 'error' => _MD_MESSAGE_ACTIONMSG1]);
49 exit; // Add exit here
50 }
51 $this->setErr(_MD_MESSAGE_ACTIONMSG1);
52 return;
53 }
54
55 if ($modObj->get('uid') != $this->root->mContext->mXoopsUser->get('uid')) {
56 if ($isAjax) {
57 header('Content-Type: application/json');
58 echo json_encode(['success' => false, 'error' => _MD_MESSAGE_ACTIONMSG2]);
59 exit;
60 }
61 $this->setErr(_MD_MESSAGE_ACTIONMSG2);
62 return;
63 }
64
65 // --- Deletion Attempt ---
66 if ($modHand->delete($modObj)) {
67 if ($isAjax) {
68 header('Content-Type: application/json');
69 echo json_encode([
70 'success' => true,
71 'message' => _MD_MESSAGE_ACTIONMSG3,
72 'deleted_id' => $boxid,
73 'inout' => $this->inout
74 ]);
75 exit;
76 }
77 $this->setErr(_MD_MESSAGE_ACTIONMSG3);
78 } else {
79 if ($isAjax) {
80 header('Content-Type: application/json');
81 echo json_encode(['success' => false, 'error' => _MD_MESSAGE_ACTIONMSG4]);
82 exit;
83 }
84 $this->setErr(_MD_MESSAGE_ACTIONMSG4);
85 }
86 }
87
93 public function executeView(&$render)
94 {
95 // No view rendering needed for delete, especially for AJAX
96 }
97}