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.

foreach ( $C as $name => $val )<br />

{<br />

define($name, $val);<br />

}<br />

/*<br />

* Create a lookup array for form actions<br />

*/<br />

$actions = array(<br />

'event_view' => array(<br />

'object' => 'Calendar',<br />

'method' => 'displayEvent'<br />

),<br />

'edit_event' => array(<br />

'object' => 'Calendar',<br />

'method' => 'displayForm'<br />

),<br />

'event_edit' => array(<br />

'object' => 'Calendar',<br />

'method' => 'processForm'<br />

),<br />

'delete_event' => array(<br />

'object' => 'Calendar',<br />

'method' => 'confirmDelete'<br />

)<br />

);<br />

/*<br />

* Make sure the anti-CSRF token was passed <strong>and</strong> that the<br />

* requested action exists in the lookup array<br />

*/<br />

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

{<br />

$use_array = $actions[$_POST['action']];<br />

$obj = new $use_array['object']($dbo);<br />

}<br />

/*<br />

* Check for an ID <strong>and</strong> sanitize it if found<br />

*/<br />

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

{<br />

$id = (int) $_POST['event_id'];<br />

}<br />

else { $id = NULL; }<br />

echo $obj->$use_array['method']($id);<br />

function __autoload($class_name)<br />

{<br />

$filename = '../../../sys/class/class.'<br />

CHAPTER 8 ■ EDITING THE CALENDAR WITH AJAX AND JQUERY<br />

299

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

Saved successfully!

Ooh no, something went wrong!