/trunk/controllers/eventsbasket/controller.php
PHP | 740 lines | 612 code | 95 blank | 33 comment | 54 complexity | ef6655110911fda61fa1a79f1170eb65 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
-
-
- class Eventsbasketcontroller {
-
- private $basket;
-
- public function __construct( PeacockCarterFrameworkRegistry $registry, $directCall )
- {
- $this->registry = $registry;
- require_once( FRAMEWORK_PATH . 'models/eventsbasket/eventsbasket.php');
- $this->basket = new Eventsbasket( $this->registry );
- $this->basket->checkBasket();
- if( $directCall == true )
- {
- $this->registry->getObject('template')->getPage()->setTitle('Your basket');
- $urlBits = $this->registry->getURLBits();
- if( !isset( $urlBits[1] ) )
- {
- $this->viewBasket();
- }
- else
- {
- switch( $urlBits[1] )
- {
- case 'view':
- $this->viewBasket();
- break;
- case 'ping':
- $this->ping();
- break;
- case 'add-product':
- echo $this->addProduct( $urlBits[2], 1);
- break;
- case 'edit':
- $this->editBasket( intval( $urlBits[2] ) );
- break;
- case 'checkout':
- $this->checkout();
- break;
- case 'payment':
- $this->paymentPage( intval( $urlBits[2] ), false );
- break;
- case 'pay-offline':
- $this->paymentPage( intval( $urlBits[2] ), true );
- break;
- case 'remove':
- $this->removeEvent( intval( $urlBits[2] ) );
- break;
- case 'confirm-order':
- $this->confirmOrder( intval( $urlBits[2] ) );
- break;
- default:
- $this->viewBasket();
- break;
- }
- }
-
- }
- }
-
- private function ping()
- {
- require_once( FRAMEWORK_PATH . 'lib/payment/paypalevents.class.php' );
- $this->gateway = new Gateway( $this->registry );
- $this->gateway->processPingBack();
- exit();
- }
-
- public function smallBasket()
- {
- // set our embedded property
- $this->embedded = true;
- // check that the basket is not empty
- if( $this->basket->isEmpty() == false )
- {
- // basket isn't empty so use the basket template, and set the numBasketItems and basketCost template variables
- $this->registry->getObject('template')->addTemplateBit('eventsbasket', 'ebasket.tpl.php');
- $this->registry->getObject('template')->getPage()->addPPTag('ebasketCost', $this->basket->getTotal());
- //$this->registry->getObject('template')->getPage()->addPPTag('shippingCost', $this->basket->getShippingCost());
- }
- else
- {
- // basket is empty - so use the empty basket template
- $this->registry->getObject('template')->addTemplateBit('eventsbasket', 'ebasket-empty.tpl.php');
- }
-
- }
-
- private function viewBasket()
- {
- $path = 'events';
- require_once( FRAMEWORK_PATH . 'models/content.php');
- require_once( FRAMEWORK_PATH . 'models/page/model.php');
- $this->model = new Pagecontent( $this->registry, 0, $this->registry->getObject('db')->sanitizeData( $path ) );
- $this->registry->getObject('menubuilder')->buildMenu( $this->model->getID() );
-
- $url = $this->registry->buildURL(array('eventsbasket', 'checkout'), '', false, true );
- $this->registry->getObject('template')->getPage()->addTag( 'checkout_url', $url );
- //echo $url;
- if( $this->basket->isEmpty() )
- {
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/empty.tpl.php', 'footer.tpl.php');
-
- }
- else
- {
- $contents = $this->basket->getContents();
- $cache = $this->registry->getObject('db')->cacheData( $contents );
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/view.tpl.php', 'footer.tpl.php');
- $this->registry->getObject('template')->getPage()->addTag( 'basket', array( 'DATA', $cache ) );
- $this->registry->getObject('template')->getPage()->addTag( 'total', $this->basket->getTotal() );
-
- foreach( $contents as $content )
- {
- //discount amount > 0 insert template bit
- if( isset( $content['discount_amount'] ) && $content['discount_amount'] > 0 )
- {
- $this->registry->getObject('template')->addTemplateBit('nbd_discount' . $content['basket_id'], 'eventsbasket/discount.tpl.php', array( 'discount_percentage' => $content['discount_percentage'], 'discount_amount' => $content['discount_amount'], 'basket_subtotal' => $content['basket_subtotal'] ) );
- }
- }
- }
-
- }
-
- private function editBasket( $bid )
- {
- $path = 'events';
- require_once( FRAMEWORK_PATH . 'models/content.php');
- require_once( FRAMEWORK_PATH . 'models/page/model.php');
- $this->model = new Pagecontent( $this->registry, 0, $this->registry->getObject('db')->sanitizeData( $path ) );
- $this->registry->getObject('menubuilder')->buildMenu( $this->model->getID() );
-
- $session_id = session_id();
- $ip_address = $_SERVER ['REMOTE_ADDR'];
- $uid = $this->registry->getObject('authenticate')->getUserID();
- if( $this->registry->getObject('authenticate')->isLoggedIn() == true )
- {
-
- $sql = "SELECT a.*, a.ID as aid, b.event_session FROM eventbasket_attendees a, eventbasket b WHERE b.ID = {$bid} AND a.user_id={$uid} AND a.basket_id= b.ID";
- }
- else
- {
- $sql = "SELECT a.*, a.ID as aid, b.event_session FROM eventbasket_attendees a, eventbasket b WHERE b.ID = {$bid} AND a.session_id='{$session_id}' AND a.ip_address='{$ip_address}' AND a.basket_id= b.ID";
- }
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows( ) > 0 )
- {
- if( isset( $_POST ) && is_array($_POST) && count( $_POST ) > 0 )
- {
- $nums = 0;
- if( isset( $_POST['attendee'] ) && is_array($_POST['attendee']) && count( $_POST['attendee'] ) > 0 )
- {
- $current_attendees = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $current_attendees[$row['aid']] = $row;
- }
-
- //delete removed attendees
- foreach( $current_attendees as $current_attendee )
- {
- if( !in_array( $current_attendee['ID'], array_keys( $_POST['attendee'] ) ) )
- {
- $aid = $this->registry->getObject('db')->sanitizeData( $current_attendee['ID'] );
- $sql = "DELETE FROM eventbasket_attendees WHERE ID = {$aid} AND basket_id = " . $bid;
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- }
-
- //update remaining attendees
- foreach( $_POST['attendee'] as $attendee )
- {
- $update = array();
- $update['name'] = $this->registry->getObject('db')->sanitizeData( $attendee['name'] );
- $update['email'] = $this->registry->getObject('db')->sanitizeData( $attendee['email'] );
- $update['phone'] = $this->registry->getObject('db')->sanitizeData( $attendee['phone'] );
- $update['organisation'] = $this->registry->getObject('db')->sanitizeData( $attendee['organisation'] );
- $update['organisation_type'] = $this->registry->getObject('db')->sanitizeData( $attendee['organisation_type'] );
- $update['dietary'] = $this->registry->getObject('db')->sanitizeData( $attendee['dietary'] );
- $update['access'] = $this->registry->getObject('db')->sanitizeData( $attendee['access'] );
- $this->registry->getObject('db')->updateRecords( 'eventbasket_attendees', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $attendee['ID'] ) );
- $nums++;
-
- if( isset( $attendee['workshop'] ) && is_array($attendee['workshop']) && count($attendee['workshop'] ) > 0 )
- {
- foreach( $attendee['workshop'] as $workshop => $preference )
- {
- $update = array();
- $update['preference'] = $this->registry->getObject('db')->sanitizeData( $preference );
- $this->registry->getObject('db')->updateRecords( 'eventbasket_attendees_workshops', $update, 'workshop_id = ' . $this->registry->getObject('db')->sanitizeData( $workshop ) . ' AND attendee_id = ' . $this->registry->getObject('db')->sanitizeData( $attendee['ID'] ) );
- }
-
- }
-
- }
- }
- else
- {
- $sql = "DELETE FROM eventbasket_attendees WHERE basket_id = " . $bid;
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- $sql = "UPDATE eventbasket SET attendees = {$nums} WHERE ID =" . $bid;
- $this->registry->getObject('db')->executeQuery( $sql );
- $this->registry->redirectUser(array('eventsbasket'),'Booking updated','Thank you for updating your booking.',false);
-
- }
- else
- {
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addPPTag( 'attendees', array( 'SQL', $cache ) );
- while( $data = $this->registry->getObject('db')->getRows() )
- {
- $sid = $data['event_session'];
- //organisation types
- switch( $data['organisation_type'] )
- {
- case 'public':
- $this->registry->getObject('template')->getPage()->addPPTag( 'nbd_public' . $data['aid'], 'selected="selected"' );
- break;
- case 'private':
- $this->registry->getObject('template')->getPage()->addPPTag( 'nbd_private' . $data['aid'], 'selected="selected"' );
- break;
- case 'voluntary':
- $this->registry->getObject('template')->getPage()->addPPTag( 'nbd_voluntary' . $data['aid'], 'selected="selected"' );
- break;
- case 'social':
- $this->registry->getObject('template')->getPage()->addPPTag( 'nbd_social' . $data['aid'], 'selected="selected"' );
- break;
- case 'individual':
- $this->registry->getObject('template')->getPage()->addPPTag( 'nbd_individual' . $data['aid'], 'selected="selected"' );
- break;
- default;
- $this->registry->getObject('template')->getPage()->addPPTag( 'nbd_individual' . $data['aid'], 'selected="selected"' );
- break;
- }
-
- }
-
- //get the time slots and workshops for this session
- $sql = "SELECT s.ID as slot_id, DATE_FORMAT(s.time, '%H:%i') as time, s.heading, s.description FROM event_sessions_slots s WHERE s.session_id = {$sid} AND ( SELECT COUNT(*) FROM event_sessions_slots_workshops w WHERE s.ID = w.slot_id ) > 0 ORDER BY s.ID ASC";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows() > 0 )
- {
- $slots = array();
- while( $data = $this->registry->getObject('db')->getRows() )
- {
- $slots[] = $data;
- }
-
- $cache = $this->registry->getObject('db')->cacheData( $slots );
- $this->registry->getObject('template')->getPage()->addTag( 'slots', array( 'DATA', $cache ) );
-
- //workshops
- $workshops = array();
- $sql = "SELECT ID as wid, slot_id, name as workshop FROM event_sessions_slots_workshops WHERE session_id = {$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- if( in_array( $row['slot_id'], array_keys( $workshops ) ) )
- {
- $workshops[ $row['slot_id'] ][] = $row;
- }
- else
- {
- $workshops[ $row['slot_id'] ] = array();
- $workshops[ $row['slot_id'] ][] = $row;
- }
- }
-
- foreach( $workshops as $record => $details )
- {
- $cache = $this->registry->getObject('db')->cacheData( $details );
- $this->registry->getObject('template')->getPage()->addTag( 'workshops-' . $record, array( 'DATA', $cache ) );
- }
-
- //get attendee preferences
- $sql = "SELECT w.* FROM eventbasket_attendees_workshops w, eventbasket_attendees a WHERE w.attendee_id = a.ID AND a.basket_id = {$bid}";
- $this->registry->getObject('db')->executeQuery( $sql );
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $row['attendee_id'] . $row['workshop_id'], $row['preference'] );
- }
-
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/edit-book-with-workshops.tpl.php', 'footer.tpl.php');
-
- }
- else
- {
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/edit-book-without-workshops.tpl.php', 'footer.tpl.php');
- }
-
- $this->registry->getObject('template')->getPage()->addTag( 'bid', $bid );
-
- }
-
- }
- else
- {
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/noattendees.tpl.php', 'footer.tpl.php' );
- }
-
- }
-
-
- /**
- * Remove a course from the basket
- * @param int $bid the basket ID
- */
- private function removeEvent( $bid )
- {
- $session_id = session_id();
- $ip_address = $_SERVER ['REMOTE_ADDR'];
- if( $this->registry->getObject('authenticate')->isLoggedIn() == true )
- {
- $uid = $this->registry->getObject('authenticate')->getUserID();
- $sql = "DELETE FROM eventbasket WHERE user_id={$uid} AND ID=" . $bid;
- $this->registry->getObject('db')->executeQuery( $sql );
- $sql = "DELETE FROM eventbasket_attendees WHERE user_id={$uid} AND basket_id=" . $bid;
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- else
- {
- $sql = "DELETE FROM eventbasket WHERE session_id='{$session_id}' AND ip_address='{$ip_address}' AND ID=" . $bid;
- $this->registry->getObject('db')->executeQuery( $sql );
- $sql = "DELETE FROM eventbasket_attendees WHERE session_id='{$session_id}' AND ip_address='{$ip_address}' AND basket_id=" . $bid;
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- $this->registry->redirectUser( array('eventsbasket'), 'Event removed', 'The event has been removed from your basket', false );
-
- }
-
- private function checkout()
- {
- //find out if all the sessions in the basket can be paid for online. redirect accordingly
- $session_id = session_id();
- $ip_address = $_SERVER ['REMOTE_ADDR'];
- $path = 'events';
- require_once( FRAMEWORK_PATH . 'models/content.php');
- require_once( FRAMEWORK_PATH . 'models/page/model.php');
- $this->model = new Pagecontent( $this->registry, 0, $this->registry->getObject('db')->sanitizeData( $path ) );
- $this->registry->getObject('menubuilder')->buildMenu( $this->model->getID() );
-
- if( $this->basket->isEmpty() )
- {
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/empty.tpl.php', 'footer.tpl.php');
- }
- else
- {
- $contents = $this->basket->getContents();
- $sessions = count($contents);
- $payment = 0;
- $onlinePaymentCost = 0;
- $offlinePaymentCost = 0;
- foreach( $contents as $content )
- {
- $sql = "SELECT * FROM event_sessions WHERE pay_online = 1 AND ID =" . $content['event_session'];
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows() > 0 )
- {
- $payment = $payment + 1;
- $onlinePaymentCost += $content['basket_subtotal'];
- }
- else
- {
- $payment = $payment;
- $offlinePaymentCost += $content['basket_subtotal'];
- }
- }
- $this->registry->getObject('template')->getPage()->addTag('pay_online', number_format($onlinePaymentCost,2) );
- $this->registry->getObject('template')->getPage()->addTag('pay_offline', number_format($offlinePaymentCost, 2) );
-
- if( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 )
- {
- // create the order
- $required = array( 'name' => 'Name', 'address' => 'Address', 'city' => 'City', 'county' =>'County', 'postcode' =>'Postcode', 'email' => 'Email address', 'phone' => 'Telephone number' );
- $errors = array();
- foreach( array_keys( $required ) as $r )
- {
- if( ! isset( $_POST[ $r ]) || $_POST[ $r ] == '' )
- {
- $processable = false;
- $error = array();
- $error['errora'] = $required[ $r ] . " is a required field";
- $errors[] = $error;
- }
- }
-
- if( empty( $errors ) )
- {
- $order = array();
- $order['user_id'] = $this->registry->getObject('authenticate')->getUserID();
- $order['session_id'] = $session_id;
- $order['ip_address'] = $ip_address;
- $order['payment'] = ( $payment == 0 ) ? 'offline' : 'online';
- $order['invoice_name'] = $this->registry->getObject('db')->sanitizeData( $_POST['name'] );
- $order['invoice_company'] = $this->registry->getObject('db')->sanitizeData( $_POST['organisation'] );
- $order['invoice_address'] = $this->registry->getObject('db')->sanitizeData( $_POST['address'] );
- $order['invoice_address_linetwo'] = $this->registry->getObject('db')->sanitizeData( $_POST['address_linetwo'] );
- $order['invoice_city'] = $this->registry->getObject('db')->sanitizeData( $_POST['city'] );
- $order['invoice_country'] = $this->registry->getObject('db')->sanitizeData( $_POST['county'] );
- $order['invoice_postcode'] = $this->registry->getObject('db')->sanitizeData( $_POST['postcode'] );
- $order['invoice_email'] = $this->registry->getObject('db')->sanitizeData( $_POST['email'] );
- $order['invoice_telephone'] = $this->registry->getObject('db')->sanitizeData( $_POST['phone'] );
-
- $order['cost'] = $onlinePaymentCost+$offlinePaymentCost;
- $order['online_cost'] = $onlinePaymentCost;
- $order['offline_cost'] = $offlinePaymentCost;
-
- $this->registry->getObject('db')->insertRecords( 'eventorders', $order );
- $order_id = $this->registry->getObject('db')->lastInsertID();
-
- $contents = $this->basket->getContents();
- foreach( $contents as $content )
- {
- //workshops
- $sql = "SELECT w.* FROM eventbasket_attendees_workshops w, eventbasket_attendees a WHERE w.attendee_id = a.ID AND a.basket_id = " . $content['basket_id'];
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows() > 0 )
- {
- $workshops = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $workshops[] = $row;
- }
- }
-
- //attendees
- $sql = "SELECT * FROM eventbasket_attendees WHERE basket_id=" . $content['basket_id'];
- $this->registry->getObject('db')->executeQuery( $sql );
- $atts = array();
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $atts[] = $row;
- }
- $flag_check = false;
- foreach( $atts as $at )
- {
- $insert = array();
- $insert['session_ID'] = $this->registry->getObject('db')->sanitizeData( $content['event_session'] );
- $insert['name'] = $this->registry->getObject('db')->sanitizeData( $at['name'] );
- $insert['email'] = $this->registry->getObject('db')->sanitizeData( $at['email'] );
- $insert['phone'] = $this->registry->getObject('db')->sanitizeData( $at['phone'] );
- $insert['organisation'] = $this->registry->getObject('db')->sanitizeData( $at['organisation'] );
- $insert['organisation_type'] = $this->registry->getObject('db')->sanitizeData( $at['organisation_type'] );
- $insert['job_title'] = $this->registry->getObject('db')->sanitizeData( $at['job_title'] );
- $insert['dietary'] = $this->registry->getObject('db')->sanitizeData( $at['dietary'] );
- $insert['access'] = $this->registry->getObject('db')->sanitizeData( $at['access'] );
- $insert['cancelled'] = 0;
- $insert['order'] = $this->registry->getObject('db')->sanitizeData( $order_id );
- $this->registry->getObject('db')->insertRecords( 'event_session_attendees', $insert );
- $aid = $this->registry->getObject('db')->lastInsertID();
-
- if( isset( $workshops ) && is_array($workshops) && count( $workshops ) > 0 )
- {
- foreach( $workshops as $workshop )
- {
- if( $workshop['attendee_id'] == $at['ID'] )
- {
- $insert = array();
- $insert['attendee_id'] = $this->registry->getObject('db')->sanitizeData( $aid );
- $insert['workshop_id'] = $this->registry->getObject('db')->sanitizeData( $workshop['workshop_id'] );
- $insert['preference'] = $this->registry->getObject('db')->sanitizeData( $workshop['preference'] );
- $this->registry->getObject('db')->insertRecords( 'event_session_attendees_workshops', $insert );
-
- }
- }
- }
-
- }
-
-
- }
-
- //email confirmation that the order has been created
- $this->emailAdmin('invoice', $order_id, $order['cost'] );
- $ad = $_POST['address'] .', ' . $_POST['address_linetwo'] . ', ' . $_POST['city'] . ', ' . $_POST['county'] . ', ' . $_POST['postcode'];
- $this->emailCustomer('invoice', $order_id, $order['cost'], $_POST['email'], $_POST['name'], $ad, $_POST['telephone'], 'Invoice' );
-
- $this->emptyBasket();
-
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/placed-invoice.tpl.php', 'footer.tpl.php');
-
- $this->registry->redirectUser( array( 'eventsbasket', 'payment', $order_id ), 'Order placed', 'Thank you. Your order has been placed, we are now taking you to the payment details page', false );
- }
- else
- {
- // errors on submit
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/checkout.tpl.php', 'footer.tpl.php');
- $this->registry->getObject('template')->addTemplateBit( 'form_errors', 'eventsbasket/errors.tpl.php' );
- foreach( $_POST as $pkey => $pdata )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'form_' . $pkey, $pdata );
- }
-
- $cache = $this->registry->getObject('db')->cacheData( $errors );
- $this->registry->getObject('template')->getPage()->addTag( 'errors', array( 'DATA', $cache ) );
- }
-
-
-
- }
- else
- {
- if( $this->registry->getObject('authenticate')->isLoggedIn() )
- {
- $sql = "SELECT u.*, e.* FROM users u LEFT JOIN users_extra e ON u.ID = e.user_id WHERE u.ID =" . $this->registry->getObject('authenticate')->getUserID();
- $this->registry->getObject('db')->executeQuery( $sql );
- $data = $this->registry->getObject('db')->getRows();
- $this->registry->getObject('template')->dataToTags( $data, 'form_' );
- }
-
- // confirm to place
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/checkout.tpl.php', 'footer.tpl.php');
-
- }
- }
-
- }
-
- private function paymentPage( $order, $request_pay_offline=false )
- {
- $path = 'events';
- require_once( FRAMEWORK_PATH . 'models/content.php');
- require_once( FRAMEWORK_PATH . 'models/page/model.php');
- $this->model = new Pagecontent( $this->registry, 0, $this->registry->getObject('db')->sanitizeData( $path ) );
- $this->registry->getObject('menubuilder')->buildMenu( $this->model->getID() );
-
- $sql = "SELECT * FROM eventorders WHERE cancelled = 0 AND ID = {$order} LIMIT 1";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows() == 1 )
- {
- $data = $this->registry->getObject('db')->getRows();
- //print_r($order);
- $offline_cost = number_format($data['offline_cost'], 2);
- $online_cost = number_format($data['online_cost'], 2);
- $total_cost = number_format( ($offline_cost + $online_cost), 2 );
- $this->registry->getObject('template')->getPage()->addTag( 'online_cost', $online_cost );
- $this->registry->getObject('template')->getPage()->addTag( 'offline_cost', $offline_cost );
- $this->registry->getObject('template')->getPage()->addTag( 'reference', $order );
-
- if( $request_pay_offline==false )
- {
- if( $data['online_cost'] > 0 && $data['online_paid'] == 0 )
- {
- //there is an online cost and it hasn't been paid.
- $this->registry->getObject('template')->getPage()->addTag( 'confirm', '' );
- require_once( FRAMEWORK_PATH . 'lib/payment/paypal.class.php' );
- $this->gateway = new Gateway( $this->registry );
- $html = $this->gateway->paymentHTML();
- $this->registry->getObject('template')->getPage()->addTag( 'paypal', $html );
- $this->registry->getObject('template')->getPage()->addPPTag( 'total_cost', number_format($online_cost,2) );
- $this->registry->getObject('template')->getPage()->addPPTag( 'sitename', $this->registry->getSetting('sitename') );
- $this->registry->getObject('template')->getPage()->addPPTag( 'paypal_email_address',$this->registry->getSetting('store.paypal.email') );
- $notify_url = $this->registry->buildURL( array( 'eventsbasket', 'ping' ), '', false );
- $this->registry->getObject('template')->getPage()->addPPTag( 'notify_url', $notify_url );
- $thanks_url = $this->registry->buildURL( array( 'eventsbasket', 'ping-thanks' ), '', false );
- $this->registry->getObject('template')->getPage()->addPPTag( 'thanks_url', $thanks_url );
- $cancel_url = $this->registry->buildURL( array( 'eventsbasket', 'ping-cancel' ), '', false );
- $this->registry->getObject('template')->getPage()->addPPTag( 'cancel_url', $cancel_url );
-
- $this->registry->getObject('template')->addTemplateBit( 'content', 'eventsbasket/pay.tpl.php' );
- $this->registry->getObject('template')->getPage()->addTag( 'online_cost_message', ' This is the amount that you will be charged through Paypal.' );
- $this->registry->getObject('template')->getPage()->addTag( 'offline_cost_message', ' This amount will need to be paid separately offline by cheque or BACS (details will be emailed to you).' );
- $this->registry->getObject('template')->getPage()->addTag( 'confirm', '' );
-
- }
- elseif( ($data['offline_cost'] > 0 && $data['offline_paid'] == 0) && ($data['online_cost'] == 0 || $data['online_paid'] == 1) )
- {
- //there is an offline cost and no online cost or the online cost has already been paid for.
- $this->registry->getObject('template')->getPage()->addTag( 'paypal', '' );
- $this->registry->getObject('template')->getPage()->addTag( 'total_cost', $total_cost );
- $this->registry->getObject('template')->getPage()->addTag( 'online_cost_message', '' );
- $this->registry->getObject('template')->getPage()->addTag( 'offline_cost_message', '' );
- $this->registry->getObject('template')->addTemplateBit( 'content', 'eventsbasket/pay-only-offline.tpl.php' );
- $this->registry->getObject('template')->getPage()->addTag( 'confirm', 'Your order has been confirmed. Please arrange to pay the offline cost by cheque or BACS (details will be emailed to you). Thank you again.' );
-
- }
- else
- {
- //the order has been paid for in full.
- $this->registry->getObject('template')->addTemplateBit( 'content', 'eventsbasket/paid-in-full.tpl.php' );
- $this->registry->getObject('template')->getPage()->addTag( 'online', ($data['online_cost'] > 0) ? 'The amount you paid online was: �' . $data['online_cost'] : '' );
- $this->registry->getObject('template')->getPage()->addTag( 'offline', ($data['offline_cost'] > 0) ? 'The amount you paid offline was: �' . $data['offline_cost'] : '' );
- }
- }
- else
- {
- $update = array();
- $update['offline_cost'] = $this->registry->getObject('db')->sanitizeData( $total_cost );
- $update['online_cost'] = 0;
- $this->registry->getObject('db')->updateRecords( 'eventorders', $update, 'ID=' . $order );
-
- $this->registry->getObject('template')->getPage()->addTag( 'total_cost', $total_cost );
- $this->registry->getObject('template')->getPage()->addTag( 'offline_cost', $total_cost );
- $this->registry->getObject('template')->getPage()->addTag( 'offline_cost_message', ' This amount will need to be paid separately offline by cheque or BACS (details will be emailed to you).' );
- $this->registry->getObject('template')->addTemplateBit( 'content', 'eventsbasket/pay-offline.tpl.php' );
- $this->registry->getObject('template')->getPage()->addTag( 'confirm', 'Your order has been confirmed. Please arrange to pay the offline cost by cheque or BACS (details will be emailed to you). Thank you again.' );
- }
-
- $this->registry->getObject('template')->getPage()->addTag( 'order', $order );
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'eventsbasket/payment.tpl.php', 'footer.tpl.php');
- }
- else
- {
- $this->registry->errorPage( 'Invalid order', 'Sorry, the order you selected was not found');
- }
- }
-
- private function emailCustomer( $type, $oid, $cost, $email, $na, $address, $phone, $payment )
- {
- $this->registry->getObject('mailout')->startFresh();
- $this->registry->getObject('mailout')->setTo( $email);
- $this->registry->getObject('mailout')->setSender( $this->registry->getSetting('adminEmailAddress'));
- $this->registry->getObject('mailout')->setFromName( $this->registry->getSetting('cms_name') );
- $this->registry->getObject('mailout')->setSubject( $this->registry->getSetting('sitename') . ' Event Booking Submission');
- $this->registry->getObject('mailout')->buildFromTemplates('customerorder-'. $type . '.tpl.php');
- //$tags = $this->values;
- $tags[ 'cost' ] = $cost;
- $tags[ 'order_id' ] = $oid;
- $tags[ 'name' ] = $na;
- $tags[ 'address' ] = $address;
- $tags[ 'phone' ] = $phone;
- $tags[ 'payment' ] = $payment;
- $tags[ 'bookings' ] = $this->buildDetailsForEmail();
- $tags[ 'email' ] = $email;
- $this->registry->getObject('mailout')->replaceTags( $tags );
- $this->registry->getObject('mailout')->setMethod('sendmail');
- $this->registry->getObject('mailout')->send();
-
-
- $this->registry->getObject('mailout')->startFresh();
- $this->registry->getObject('mailout')->setTo( "bookings@equalitysouthwest.org.uk" );
- $this->registry->getObject('mailout')->setSender( $this->registry->getSetting('adminEmailAddress'));
- $this->registry->getObject('mailout')->setFromName( $this->registry->getSetting('cms_name') );
- $this->registry->getObject('mailout')->setSubject( $this->registry->getSetting('sitename') . ' Event Booking Submission');
- $this->registry->getObject('mailout')->buildFromTemplates('customerorder-'. $type . '.tpl.php');
- //$tags = $this->values;
- $tags[ 'cost' ] = $cost;
- $tags[ 'order_id' ] = $oid;
- $tags[ 'name' ] = $na;
- $tags[ 'address' ] = $address;
- $tags[ 'phone' ] = $phone;
- $tags[ 'payment' ] = $payment;
- $tags[ 'bookings' ] = $this->buildDetailsForEmail();
- $tags[ 'email' ] = $email;
- $this->registry->getObject('mailout')->replaceTags( $tags );
- $this->registry->getObject('mailout')->setMethod('sendmail');
- $this->registry->getObject('mailout')->send();
- }
-
- private function buildDetailsForEmail()
- {
- $contents = $this->basket->getContents();
- $bookings_for_email = "";
- foreach( $contents as $content )
- {
- $bookings_for_email .= "Event: " . $content['event_name']."
-
- Attendees: ";
- $sql = "SELECT * FROM eventbasket_attendees WHERE basket_id=" . $content['basket_id'];
- $this->registry->getObject('db')->executeQuery( $sql );
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $bookings_for_email .= " " . $row['name'] ."; ";
-
- }
- $bookings_for_email .= "
-
- Date: ".$content['event_date_full']."
-
- Venue: " . $content['venue_name_full'] ."
-
- Time: " . $content['start_time'] ." - " . $content['end_time'] ."
-
- Price: �".$content['event_price']."
-
- ";
-
-
- }
-
- return $bookings_for_email;
- }
-
- private function emailAdmin( $type, $oid, $cost )
- {
- $this->registry->getObject('mailout')->startFresh();
- $this->registry->getObject('mailout')->setTo( $this->registry->getSetting('adminEmailAddress') );
- $this->registry->getObject('mailout')->setSender( $this->registry->getSetting('adminEmailAddress') );
- $this->registry->getObject('mailout')->setFromName( $this->registry->getSetting('cms_name') );
- $this->registry->getObject('mailout')->setSubject( $this->registry->getSetting('sitename') . ' Event Booking Submission');
- $this->registry->getObject('mailout')->buildFromTemplates('neworder-'. $type . '.tpl.php');
- //$tags = $this->values;
- $tags[ 'cost' ] = $cost;
- $tags[ 'order_id' ] = $oid;
- $this->registry->getObject('mailout')->replaceTags( $tags );
- $this->registry->getObject('mailout')->setMethod('sendmail');
- $this->registry->getObject('mailout')->send();
-
- $this->registry->getObject('mailout')->startFresh();
- $this->registry->getObject('mailout')->setTo( "bookings@equalitysouthwest.org.uk" );
- $this->registry->getObject('mailout')->setSender( $this->registry->getSetting('adminEmailAddress') );
- $this->registry->getObject('mailout')->setFromName( $this->registry->getSetting('cms_name') );
- $this->registry->getObject('mailout')->setSubject( $this->registry->getSetting('sitename') . ' Event Booking Submission');
- $this->registry->getObject('mailout')->buildFromTemplates('neworder-'. $type . '.tpl.php');
- //$tags = $this->values;
- $tags[ 'cost' ] = $cost;
- $tags[ 'order_id' ] = $oid;
- $this->registry->getObject('mailout')->replaceTags( $tags );
- $this->registry->getObject('mailout')->setMethod('sendmail');
- $this->registry->getObject('mailout')->send();
- }
-
- private function emptyBasket()
- {
- $contents = $this->basket->getContents();
- $bookings_for_email = "";
- foreach( $contents as $content )
- {
- // remove the basket stuff!
- $sql = "DELETE FROM eventbasket WHERE ID=" . $content['basket_id'];
- $this->registry->getObject('db')->executeQuery( $sql );
- $sql = "DELETE w.* FROM eventbasket_attendees_workshops w, eventbasket_attendees a WHERE a.ID = w.attendee_id AND a.basket_id=" . $content['basket_id'];
- $this->registry->getObject('db')->executeQuery( $sql );
- $sql = "DELETE FROM eventbasket_attendees WHERE basket_id=" . $content['basket_id'];
- $this->registry->getObject('db')->executeQuery( $sql );
-
-
- }
- }
-
-
-
- }
-
-
- ?>