19 private string $inout =
'inbox';
21 public function __construct()
23 parent::__construct();
26 public function execute()
28 $isAjax = $this->root->mContext->mRequest->getRequest(
'ajax') == 1;
30 if (
'in' == $this->root->mContext->mRequest->getRequest(
'inout')) {
31 $this->inout =
'inbox';
32 $redirectAction =
'index';
34 $this->inout =
'outbox';
35 $redirectAction =
'send';
38 $this->setUrl(
'index.php?action=' . $redirectAction);
41 $delid = $this->root->mContext->mRequest->getRequest(
'delmsg');
44 error_log(
'Delete All Action - inout: ' . $this->inout .
', isAjax: ' . $isAjax .
', delid: ' . print_r($delid,
true));
47 if (!is_array($delid) || 0 == count($delid)) {
49 header(
'Content-Type: application/json');
50 echo json_encode([
'success' =>
false,
'error' => _MD_MESSAGE_DELETEMSG2]);
53 $this->setErr(_MD_MESSAGE_DELETEMSG2);
58 $modHand = xoops_getmodulehandler($this->inout, _MY_DIRNAME);
62 $success_messages = [];
65 foreach ($delid as $boxid) {
67 $modObj = $modHand->get($boxid);
69 if (!is_object($modObj)) {
70 $errors[$boxid] = _MD_MESSAGE_ACTIONMSG1;
71 $failed_ids[] = $boxid;
75 if ($modObj->get(
'uid') != $this->root->mContext->mXoopsUser->get(
'uid')) {
76 $errors[$boxid] = _MD_MESSAGE_ACTIONMSG2;
77 $failed_ids[] = $boxid;
81 if ($modHand->delete($modObj)) {
82 $deleted_ids[] = $boxid;
86 $errors[$boxid] = _MD_MESSAGE_ACTIONMSG4;
87 $failed_ids[] = $boxid;
92 $final_success = count($failed_ids) === 0 && count($deleted_ids) > 0;
95 if (count($deleted_ids) > 0) {
99 if (count($failed_ids) > 0) {
101 if (defined(
'_MD_MESSAGE_DELETEMSG_FAIL_NUM')) {
105 $final_message .= count($failed_ids) .
" message(s) failed to delete.";
108 if (empty($final_message)) {
109 $final_message = _MD_MESSAGE_DELETEMSG2;
114 header(
'Content-Type: application/json');
116 'success' => $final_success,
117 'message' => trim($final_message),
118 'deleted_count' => count($deleted_ids),
119 'failed_count' => count($failed_ids),
120 'deleted_ids' => $deleted_ids,
121 'failed_ids' => $failed_ids,
123 'inout' => $this->inout
128 if ($final_success) {
131 } elseif (count($deleted_ids) > 0) {
133 $this->setErr(trim($final_message));
136 $this->setErr(count($errors) > 0 ? _MD_MESSAGE_ACTIONMSG4 : _MD_MESSAGE_DELETEMSG2);
143 public function executeView(&$render)