/** * Perform bulk actions * * @uses Route::get * @uses Route::uri * @uses Request::post * @uses Request::redirect * @uses PM::bulk_delete * @uses Message::success * @uses Message::error * @uses DB::select */ public function action_bulk() { $id = (int) $this->request->param('id', 0); switch ($id) { case PM::INBOX: $destination = 'inbox'; break; case PM::OUTBOX: $destination = 'outbox'; break; case PM::DRAFTS: $destination = 'drafts'; break; default: $destination = 'list'; } $redirect = Route::get('user/message')->uri(array('action' => $destination)); $post = $this->request->post(); $this->title = __('Bulk Actions'); // If deletion is not desired, redirect to list if (isset($post['no']) and $this->valid_post()) { $this->request->redirect($redirect); } // If deletion is confirmed if (isset($post['yes']) and $this->valid_post()) { $ids = array_filter($post['items']); PM::bulk_delete($ids); Message::success(__('The delete has been performed!')); $this->request->redirect($redirect); } if ($this->valid_post('message-bulk-actions')) { if (isset($post['operation']) and empty($post['operation'])) { Message::error(__('No bulk operation selected.')); $this->request->redirect($redirect); } if (!isset($post['messages']) or (!is_array($post['messages']) or !count(array_filter($post['messages'])))) { Message::error(__('No messages selected.')); $this->request->redirect($redirect); } try { if ($post['operation'] == 'delete') { $ids = array_filter($post['messages']); // Filter out unchecked messages $this->title = __('Delete Messages'); $items = DB::select('id', 'subject')->from('messages')->where('id', 'IN', $ids)->execute()->as_array('id', 'subject'); $view = View::factory('form/confirm_multi')->set('action', '')->set('items', $items); $this->response->body($view); return; } $this->_bulk_update($post); Message::success(__('The update has been performed!')); $this->request->redirect($redirect); } catch (Exception $e) { Message::error(__('The update has not been performed!')); Log::error('Message updates failed: ' . $e->getMessage()); } } // always redirect to list, if no action performed $this->request->redirect($redirect); }