Add DELETE Event button into 'My Submitted Events'

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #87077 by Antonello Mancuso
Add DELETE Event button into 'My Submitted Events' was created by Antonello Mancuso
Hello there,
I'm writing to have support about a customization i must do.
My boss want added a button into 'My Submitted Events' to directly Delete an event from Front End.
I perfectly read that Joomla doesn't support this kind of stuff, but for security reasons, we can't allow normal user to entr into back end to simply delete an event!
So.. these are steps I thought to solve the problem:
1) write a custom function to add into ..\com_eventbooking\helper\database.php
public static function deleteEvent($id)
Code:
{ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->delete('*') ->from('#___eb_events') ->where('id=' . (int) $id); //this is the event ID $db->setQuery($query); return $db->loadObject(); }
2) Add a correspondant function into ..\com_eventbooking\controller\event.php
3) trigger the task with a link such as:
Code:
$link = JRoute::_('index.php?option=com_eventbooking&task=deleteEvent&id='.$row->id); <a class="btn" href="<?php echo $link ; ?>"><i class="<?php echo $class;?>"></i><?php echo $text ; ?></a>
I know I'm missing something. Practically I have not understand how to create the 'task'. It is sufficient the function I wrote upward?
I need a bit of help from you guys.
Any idea is well accepted!
Thanks !!

Eng. Antonello Mancuso

Please Log in or Create an account to join the conversation.

More
8 years 8 months ago #87114 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Add DELETE Event button into 'My Submitted Events'
Hi

1. There are something wrong with your code:

- The method should be moved into components/com_eventbooking/controller/event.php instead of in the file you wrote

- Instead of calling return $db->loadObject();, you must call $db->execute(); to execute the query

2. The link will need to have this format

$link = JRoute::_('index.php?option=com_eventbooking&task=event.deleteEvent&id='.$row->id);

(with that format of task variable, it will call deleteEvent method in Event controller)

3. However, as you can see, it also introduce security issue here, everyone who know the link can type the URL in the browser and then, the event will be deleted

So to be safe, maybe you should only give super admin permission to delete event. to do that, add this code to the beginning of the method

$user = JFactory::getUser();
if (!$user->authorise('core.admin'))
{
throw new Exception('You do not have permission to delete event', 403);
}

Something like that should help

Tuan
The following user(s) said Thank You: Antonello Mancuso

Please Log in or Create an account to join the conversation.

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #87129 by Antonello Mancuso
Replied by Antonello Mancuso on topic Add DELETE Event button into 'My Submitted Events'
Thanks Tuan. I read your suggestions and I will try to apply them.
Just a couple of stuffs more...
1) I want that, not only Admin, but also author of an event can delete its own events (this is the 'core feature'). To do that, have I to add a 2nd argument to my custom function
Code:
public static function deleteEvent($id,$group)
and retrieve author's group from the event or this can be done directly into the function as you did with $user= JFactory::getUser(); ??
2) (this is a bit more difficult) Because modifying events booking core stuff is not reccommended (it's necessary to overwrite Event controller after each upgrade and I'm a freelance.. At some point I'll be no more here to do this), what do you think if I create a simple (the simpliest one, no configuration, no admin setting, etc.. just the minimum essential stuff) plugin and into core php file of this plugin I add something like:
Code:
require_once JPATH_ROOT . '/components/com_eventbooking/controller/event.php'; class plgButtonDelEvents extends JPlugin { //code about database query and user authorization }
Then I can copy it in the right folder (website_root/plugin/eventbooking/) so that I'll not lost this function after each upgrade?

This thing will definitive solve my problem !!
Thanks !!

P.S. Send me a private message with your Paypal email/account number.

Eng. Antonello Mancuso

Please Log in or Create an account to join the conversation.

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #87138 by Antonello Mancuso
Replied by Antonello Mancuso on topic Add DELETE Event button into 'My Submitted Events'
OK Tuan,
I know you do not like to 'debug' code so... sorry about that. But...
You'll find attached my first plugin ever :laugh: . It should be possible to directly install it !!
I courtesy need you to:
- check if I imported right libraries;
- check DB queries;
- tell me if I can still trigger the task with the same previous link.
Code:
$link = JRoute::_('index.php?option=com_eventbooking&task=event.deleteEvent&id='.$row->id);
or task name now is different.
Many Thanks !!!

P.S. Send me that PM ;)

Eng. Antonello Mancuso
Attachments:

Please Log in or Create an account to join the conversation.

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #87140 by Antonello Mancuso
Replied by Antonello Mancuso on topic Add DELETE Event button into 'My Submitted Events'
Update:
I installed my plugin and make some trials but... with my plugin installed I cannot even Create an event with Events Booking because when I click Save button, page remain blank without return to My Submitted Event page, but Event is created anyway.
I then tried to directly delete an event with that link, but it doesn't work :huh: :( .
So.. there's for sure something wrong...
Waiting for a tip :laugh: ...

Eng. Antonello Mancuso

Please Log in or Create an account to join the conversation.

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #87197 by Antonello Mancuso
Replied by Antonello Mancuso on topic Add DELETE Event button into 'My Submitted Events'
I moved the method into components/com_eventbooking/controller/event.php but it doesn't work either.
I will look better on How To override a core class in Joomla :blink: .

Eng. Antonello Mancuso

Please Log in or Create an account to join the conversation.

More
8 years 8 months ago #87242 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Add DELETE Event button into 'My Submitted Events'
Move the code to components/com_eventbooking/controller/event.php as I said, right now, there is no way to override controller class like the one you are trying to do

Then submit a support ticket, I will try to ask my dev to check the code to see what's wrong and correct it for you

Regards,

Tuan
The following user(s) said Thank You: Antonello Mancuso

Please Log in or Create an account to join the conversation.

  • Antonello Mancuso
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #87292 by Antonello Mancuso
Replied by Antonello Mancuso on topic Add DELETE Event button into 'My Submitted Events'
Ticket added. Hoping you will find a better solution. Thanks!

Eng. Antonello Mancuso

Please Log in or Create an account to join the conversation.

Moderators: Tuan Pham Ngoc