02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

public function __construct($dbo=NULL, $useDate=NULL) {...}<br />

public function buildCalendar() {...}<br />

public function displayEvent($id) {...}<br />

public function displayForm() {...}<br />

public function processForm() {...}<br />

/**<br />

* Confirms that an event should be deleted <strong>and</strong> does so<br />

*<br />

* Upon clicking the button to delete an event, this<br />

* generates a confirmation box. If the user confirms,<br />

* this deletes the event from the database <strong>and</strong> sends the<br />

* user back out to the main calendar view. If the user<br />

* decides not to delete the event, they're sent back to<br />

* the main calendar view without deleting anything.<br />

*<br />

* @param int $id the event ID<br />

* @return mixed the form if confirming, void or error if deleting<br />

*/<br />

public function confirmDelete($id)<br />

{<br />

/*<br />

* Make sure an ID was passed<br />

*/<br />

if ( empty($id) ) { return NULL; }<br />

/*<br />

* Make sure the ID is an integer<br />

*/<br />

$id = preg_replace('/[^0-9]/', '', $id);<br />

/*<br />

* If the confirmation form was submitted <strong>and</strong> the form<br />

* has a valid token, check the form submission<br />

*/<br />

if ( isset($_POST['confirm_delete'])<br />

&& $_POST['token']==$_SESSION['token'] )<br />

{<br />

/*<br />

* If the deletion is confirmed, remove the event<br />

* from the database<br />

*/<br />

if ( $_POST['confirm_delete']=="Yes, Delete It" )<br />

{<br />

$sql = "DELETE FROM `events`<br />

WHERE `event_id`=:id<br />

CHAPTER 5 ■ ADD CONTROLS TO CREATE, EDIT, AND DELETE EVENTS<br />

193

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!