function paymentSend($cids = array())
    {
        $query = 'SELECT * FROM #__ticketmaster_orders
			      WHERE ordercode IN ( ' . $cids . ' )
				  GROUP BY ordercode';
        $db = JFactory::getDBO();
        ## Do the query now
        $db->setQuery($query);
        $data = $db->loadObjectList();
        ## Getting the email now -- ID 101 from message center.
        $sql = "SELECT * FROM #__ticketmaster_emails WHERE emailid = 104";
        $db->setQuery($sql);
        $mail = $db->loadObject();
        ## Including required paths to calculator.
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
        include_once $path_include;
        ## getting the required data for the configuration:
        $query = 'SELECT priceformat, valuta FROM #__ticketmaster_config WHERE configid = 1';
        $db = JFactory::getDBO();
        $db->setQuery($query);
        $config = $db->loadObject();
        ## Include the functions for price views.
        $file_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'functions.php';
        include_once $file_include;
        for ($i = 0, $n = count($data); $i < $n; $i++) {
            $row = $data[$i];
            ## Getting the order amount.
            $total = _getAmount($row->ordercode);
            $price = showprice($config->priceformat, $total, $config->valuta);
            ## Check if the order has been paid:
            $sql = 'SELECT COUNT(orderid) AS total, userid
					FROM #__ticketmaster_orders
					WHERE paid = 1
					AND ordercode = ' . (int) $row->ordercode . '';
            $db->setQuery($sql);
            $item = $db->loadObject();
            ## Check if the order has been paid:
            $sql = 'SELECT c.name, c.emailaddress, c.firstname
					FROM #__ticketmaster_clients AS c, #__ticketmaster_orders AS o
					WHERE o.userid = c.userid
					AND o.ordercode = ' . (int) $row->ordercode . '';
            $db->setQuery($sql);
            $client = $db->loadObject();
            if ($item->total == 0) {
                $sql = 'SELECT  a.*, t.*, e.eventname, c.*,
					  t.ticketdate, t.starttime, t.location, t.locationinfo, a.paid, e.groupname, t.eventcode
					  FROM #__ticketmaster_orders AS a, #__ticketmaster_clients AS c,
					  #__ticketmaster_events AS e, #__ticketmaster_tickets AS t
					  WHERE a.userid = c.userid
					  AND a.eventid = e.eventid
					  AND a.ticketid = t.ticketid
					  AND ordercode = ' . (int) $row->ordercode . '
					  GROUP BY a.orderid';
                $db->setQuery($sql);
                $order_info = $db->loadObjectList();
                $orders = '<ul>';
                $k = 0;
                for ($i2 = 0, $n2 = count($order_info); $i2 < $n2; $i2++) {
                    $ticketdata = $order_info[$i2];
                    $price = showprice($config->priceformat, $ticketdata->ticketprice, $config->valuta);
                    $orders .= '<li>[ ' . $ticketdata->orderid . ' ] - <strong>' . $ticketdata->ticketname . '</strong> [ ' . $price . ' ]</li>';
                    $k = 1 - $k;
                }
                $orders .= '</ul>';
                ## Getting the order amount.
                $total = _getAmount($row->ordercode);
                $price = showprice($config->priceformat, $total, $config->valuta);
                ## encode the link;
                $encoded = base64_encode('payfororder=' . $row->ordercode);
                $paymentlink = JURI::root() . 'index.php?option=com_ticketmaster&controller=validate&task=pay&order=' . $encoded;
                $message = str_replace('%%PRICE%%', $price, $mail->mailbody);
                $message = str_replace('%%NAME%%', $client->name, $message);
                $message = str_replace('%%FIRSTNAME%%', $client->firstname, $message);
                $message = str_replace('%%ORDERCODE%%', $row->ordercode, $message);
                $message = str_replace('%%ORDERLIST%%', $orders, $message);
                $message = str_replace('%%PAYMENTLINK%%', $paymentlink, $message);
                ## Imaport mail functions:
                jimport('joomla.mail.mail');
                ## Set the sender of the email:
                $sender[0] = $mail->from_email;
                $sender[1] = $mail->from_name;
                ## Compile mailer function:
                $obj = JFactory::getMailer();
                $obj->setSender($sender);
                $obj->isHTML(true);
                $obj->setBody($message);
                $obj->addRecipient($client->emailaddress);
                ## Send blind copy to site admin?
                if ($mail->receive_bcc == 1) {
                    if ($mail->reply_to_email != '') {
                        $obj->addRecipient($mail->reply_to_email);
                    }
                }
                ## Add reply to and subject:
                $obj->addReplyTo($sender);
                $obj->setSubject($mail->mailsubject);
                if ($mail->published == 1) {
                    $sent = $obj->Send();
                }
            }
        }
        return true;
    }
    function paymentResender($cid = array())
    {
        ## Make cids safe, against SQL injections
        JArrayHelper::toInteger($data);
        ## Implode cids for more actions (when more selected)
        $cids = implode(',', $cid);
        $query = 'SELECT * FROM #__ticketmaster_orders
			      WHERE ordercode IN ( ' . $cids . ' )
				  GROUP BY ordercode';
        $db = JFactory::getDBO();
        ## Do the query now
        $db->setQuery($query);
        $data = $db->loadObjectList();
        ## Getting the email now -- ID 101 from message center.
        $sql = "SELECT * FROM #__ticketmaster_emails WHERE emailid = 101";
        $db->setQuery($sql);
        $mail = $db->loadObject();
        ## Including required paths to calculator.
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
        include_once $path_include;
        ## getting the required data for the configuration:
        $query = 'SELECT priceformat, valuta FROM #__ticketmaster_config WHERE configid = 1';
        $db = JFactory::getDBO();
        $db->setQuery($query);
        $config = $db->loadObject();
        ## Include the functions for price views.
        $file_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'functions.php';
        include_once $file_include;
        for ($i = 0, $n = count($data); $i < $n; $i++) {
            $row = $data[$i];
            ## Getting the order amount.
            $total = _getAmount($row->ordercode);
            $price = showprice($config->priceformat, $total, $config->valuta);
            ## Check if the order has been paid:
            $sql = 'SELECT COUNT(orderid) AS total, userid 
					FROM #__ticketmaster_orders 
					WHERE paid != 1
					AND ordercode = ' . (int) $row->ordercode . '';
            $db->setQuery($sql);
            $item = $db->loadObject();
            ## Check if the order has been paid:
            $sql = 'SELECT c.name, c.emailaddress, c.firstname
					FROM #__ticketmaster_clients AS c, #__ticketmaster_orders AS o 
					WHERE o.userid = c.userid
					AND o.ordercode = ' . (int) $row->ordercode . '';
            $db->setQuery($sql);
            $client = $db->loadObject();
            if ($item->total > 0) {
                ## Getting the order amount.
                $total = _getAmount($row->ordercode);
                $price = showprice($config->priceformat, $total, $config->valuta);
                ## encode the link;
                $encoded = base64_encode('payfororder=' . $row->ordercode);
                $paymentlink = JURI::root() . 'index.php?option=com_ticketmaster&controller=validate&task=pay&order=' . $encoded;
                $message = str_replace('%%PRICE%%', $price, $mail->mailbody);
                $message = str_replace('%%NAME%%', $client->name, $message);
                $message = str_replace('%%FIRSTNAME%%', $client->firstname, $message);
                $message = str_replace('%%ORDERCODE%%', $row->ordercode, $message);
                $message = str_replace('%%PAYMENTLINK%%', $paymentlink, $message);
                ## Imaport mail functions:
                jimport('joomla.mail.mail');
                ## Set the sender of the email:
                $sender[0] = $mail->from_email;
                $sender[1] = $mail->from_name;
                ## Compile mailer function:
                $obj = JFactory::getMailer();
                $obj->setSender($sender);
                $obj->isHTML(true);
                $obj->setBody($message);
                $obj->addRecipient($client->emailaddress);
                ## Send blind copy to site admin?
                if ($mail->receive_bcc == 1) {
                    if ($mail->reply_to_email != '') {
                        $obj->addRecipient($mail->reply_to_email);
                    }
                }
                ## Add reply to and subject:
                $obj->addReplyTo($sender);
                $obj->setSubject($mail->mailsubject);
                if ($mail->published == 1) {
                    $sent = $obj->Send();
                }
            }
        }
    }
    public function SendWaitingList()
    {
        $mainframe = JFactory::getApplication();
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'functions.php';
        include_once $path_include;
        $db = JFactory::getDBO();
        ## Loading the configuration table.
        $sql = 'SELECT * FROM #__ticketmaster_config WHERE configid = 1';
        $db->setQuery($sql);
        $configuration = $db->loadObject();
        ## Getting the desired info from the configuration table
        $sql = 'SELECT * FROM #__ticketmaster_emails WHERE emailid = 102';
        $db->setQuery($sql);
        $config = $db->loadObject();
        $sql = 'SELECT  a.*, t.*, e.eventname, c.*, 
			  t.ticketdate, t.starttime, t.location, t.locationinfo, e.groupname, t.eventcode
			  FROM #__ticketmaster_waitinglist AS a, #__ticketmaster_clients AS c,
			  #__ticketmaster_events AS e, #__ticketmaster_tickets AS t
			  WHERE a.userid = c.userid
			  AND a.eventid = e.eventid
			  AND a.ticketid = t.ticketid
			  AND a.ordercode = ' . $this->eid . '';
        $db->setQuery($sql);
        $data = $db->loadObjectList();
        $orders = '<ul>';
        $k = 0;
        for ($i = 0, $n = count($data); $i < $n; $i++) {
            $row =& $data[$i];
            $price = showprice($configuration->priceformat, $row->ticketprice, $configuration->valuta);
            $ticketdate = date($configuration->dateformat, strtotime($row->ticketdate));
            $customer = $row->firstname . ' ' . $row->name;
            $recipient = $row->emailaddress;
            $orders .= '<li>[ ' . $row->orderid . ' ] - [ ' . $ticketdate . ' ] - <strong>' . $row->ticketname . '</strong> [ ' . $price . ' ]</li>';
            $k = 1 - $k;
        }
        $orders .= '</ul>';
        ## Including required paths to calculator.
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
        include_once $path_include;
        $date = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
        $date = date($configuration->dateformat, strtotime($date));
        ## Get the paid amount:
        $to_be_paid = _getAmount($this->eid);
        $price = showprice($configuration->priceformat, $to_be_paid, $configuration->valuta);
        $total_tickets = count($data);
        $encoded = base64_encode('ordercode=' . $this->eid);
        $paymentlink = JURI::root() . 'index.php?option=com_ticketmaster&controller=validate&task=confirm&order=' . $encoded;
        $message = str_replace('%%NAME%%', $customer, $config->mailbody);
        $message = str_replace('%%ORDERCODE%%', $this->eid, $message);
        $message = str_replace('%%ORDERDATE%%', $date, $message);
        $message = str_replace('%%TICKETS%%', $total_tickets, $message);
        $message = str_replace('%%CONFIRMATIONLINK%%', $paymentlink, $message);
        $message = str_replace('%%PRICE%%', $price, $message);
        $message = str_replace('%%COUNT_OF_DAYS%%', $configuration->removal_days, $message);
        $message = str_replace('%%ORDERLIST%%', $orders, $message);
        $message = str_replace('%%COMPANYNAME%%', $configuration->companyname, $message);
        $message = str_replace('%%COMPANYADDRESS%%', $configuration->address1, $message);
        $message = str_replace('%%COMPANYCITY%%', $configuration->city, $message);
        $message = str_replace('%%PHONENUMBER%%', $configuration->phone, $message);
        ## Imaport mail functions:
        jimport('joomla.mail.mail');
        ## Set the sender of the email:
        $sender[0] = $config->from_email;
        $sender[1] = $config->from_name;
        ## Compile mailer function:
        $obj = JFactory::getMailer();
        $obj->setSender($sender);
        $obj->isHTML(true);
        $obj->setBody($message);
        $obj->addRecipient($recipient);
        $obj->addAttachment($attachment);
        ## Send blind copy to site admin?
        if ($config->receive_bcc == 1) {
            if ($config->reply_to_email != '') {
                $obj->addRecipient($config->reply_to_email);
            }
        }
        ## Add reply to and subject:
        $obj->addReplyTo($config->reply_to_email);
        $obj->setSubject($config->mailsubject);
        if ($config->published == 1) {
            $sent = $obj->Send();
        }
        $query = 'UPDATE #__ticketmaster_waitinglist SET sent = 1 WHERE ordercode =  ' . $this->eid . '';
        ## Do the query now
        $db->setQuery($query);
        ## When query goes wrong.. Show message with error.
        if (!$db->query()) {
            $this->setError($db->getErrorMsg());
            return false;
        }
        return true;
    }
    $document->addStyleSheet(JURI::root(true) . '/administrator/components/com_ticketmaster/assets/bootstrap/css/bootstrap.css');
    $document->addScript(JURI::root(true) . '/administrator/components/com_ticketmaster/assets/bootstrap/js/bootstrap.js');
}
$document->addScript(JURI::root(true) . '/components/com_ticketmaster/assets/j3-lightbox/js/jquery.colorbox.js');
$document->addScript(JURI::root(true) . '/components/com_ticketmaster/assets/j3-lightbox/js/colorbox.js');
$document->addStyleSheet(JURI::root(true) . '/components/com_ticketmaster/assets/j3-lightbox/css/colorbox.css');
include_once 'components/com_ticketmaster/assets/functions.php';
## Getting the global DB session
$session =& JFactory::getSession();
## Gettig the orderid if there is one.
$ordercode = $session->get('ordercode');
## Including required paths to calculator.
$path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
include_once $path_include;
## Total for this order:
$total = _getAmount($session->get('ordercode'));
$fees = _getFees($session->get('ordercode'));
$ordertotal = $total - $fees;
## Getting the parameters for this view:
$params = JComponentHelper::getParams('com_ticketmaster');
$gmaps_width = $params->get('gmaps_width', '200');
$gmaps_heigth = $params->get('gmaps_heigth', '200');
$show_venuebuttons = $params->get('show_venuebuttons', 1);
$button_color = $params->get('button_color', 'btn');
$show_venue_events = $params->get('show_venue_events', '1');
$show_venuedetails = $params->get('show_venuedetails', '1');
$button_color = $params->get('button_color', 'btn');
$button = 'btn ' . $button_color;
## Redirection link in JRoute:
$gotocart = JRoute::_('index.php?option=com_ticketmaster&view=cart');
if ($this->extended->seat_chart != '') {
## Adding the mediabox functions.
$document->addScript(JURI::root(true) . '/administrator/components/com_ticketmaster/assets/lightbox/mediabox.js');
$document->addStyleSheet(JURI::root(true) . '/administrator/components/com_ticketmaster/assets/lightbox/mediabox.css');
## Getting the global DB session
$session =& JFactory::getSession();
## Gettig the orderid if there is one.
$ordercode = $session->get('ordercode');
include_once 'components/com_ticketmaster/assets/functions.php';
## Including required paths to calculator.
$path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
include_once $path_include;
## Including required paths to calculator.
$path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'encrypt.ordercode.php';
include_once $path_include;
## Getting the total to pay :)
$ordertotal = _getAmount($ordercode);
$fees = _getFees($ordercode);
$discount = _getDiscount($ordercode);
$count = count($this->items);
## Check if this is Joomla 2.5 or 3.0.+
$isJ30 = version_compare(JVERSION, '3.0.0', 'ge');
if (!$isJ30) {
    JHTML::_('behavior.mootools');
    if ($this->config->load_bootstrap == 1) {
        ## Adding mootools for J!2.5
        JHTML::_('behavior.modal');
        ## Include the tooltip behaviour.
        JHTML::_('behavior.tooltip', '.hasTip');
        $document->addScript('https://code.jquery.com/jquery-latest.js');
        $document->addStyleSheet(JURI::root(true) . '/administrator/components/com_ticketmaster/assets/bootstrap/css/bootstrap.css');
        $document->addScript(JURI::root(true) . '/administrator/components/com_ticketmaster/assets/bootstrap/js/bootstrap.js');
    public function doConfirm()
    {
        global $mainframe, $option;
        $db = JFactory::getDBO();
        ## Making the query for getting the config
        $sql = 'SELECT  * FROM #__ticketmaster_config WHERE configid = 1';
        $db->setQuery($sql);
        $config = $db->loadObject();
        ## include the functions for price views.
        $file_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'functions.php';
        include_once $file_include;
        ## Date definition - Change if you like.
        $orderdate = date($config->dateformat, strtotime($order->ticketdate));
        ## Required helpers to create this PDF invoice
        ## Do NOT edit the required files! It will damage your component.
        include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'pdf' . DS . 'fpdf' . DS . 'fpdf.php';
        include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'pdf' . DS . 'fpdi_ean13.php';
        ## Making the query for getting the order
        $sql = 'SELECT  a.*, t.*, e.eventname, c.*, 
			  t.ticketdate, t.starttime, t.location, t.locationinfo, a.paid, e.groupname, t.eventcode
			  FROM #__ticketmaster_orders AS a, #__ticketmaster_clients AS c,
			  #__ticketmaster_events AS e, #__ticketmaster_tickets AS t
			  WHERE a.userid = c.userid
			  AND a.eventid = e.eventid
			  AND a.ticketid = t.ticketid
			  AND ordercode = ' . $this->eid . '';
        $db->setQuery($sql);
        $order = $db->loadObject();
        ## initiate FPDI
        $pdf =& new FPDI_EAN13();
        ## add a page
        $pdf->AddPage();
        ## set the sourcefile
        $sourcePDF = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'orderconfirmation.pdf';
        $pdf->setSourceFile($sourcePDF);
        ## import page 1
        $tplIdx = $pdf->importPage(1);
        ## use the imported page and place it at point 0,0 with a width of 210 mm (A4 Format)
        $pdf->useTemplate($tplIdx, 0, 0, 210);
        ## Getting the order date:
        $orderdate = date($config->dateformat, strtotime($order->orderdate));
        $logo = explode("-", $config->position_logo_confirmation);
        $folder = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'images' . DS;
        $pdf->Image($folder . 'confirmation_logo.jpg', $logo[0], $logo[1], 0, 20);
        #############################################
        ## WRITING THE ORDERDATE                   ##
        #############################################
        ## Writing the orderdate on the confirmation.
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 63);
        $pdf->Write(0, JText::_('COM_TICKETMASTER_ORDERDATE') . ': ' . $orderdate);
        ###############################################
        ## WRITING THE COMPANY INFORMATION ON TICKET ##
        ###############################################
        ##Writing the company name
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 14);
        $pdf->Write(0, utf8_decode($config->companyname));
        ##Writing the company address
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 18);
        $pdf->Write(0, utf8_decode($config->address1));
        ##Writing the company zipcode+city
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 22);
        $pdf->Write(0, $config->zipcode . ' ' . utf8_decode($config->city));
        ##Writing the company phone
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 26);
        $pdf->Write(0, JText::_('COM_TICKETMASTER_PHONE') . ' ' . utf8_decode($config->phone));
        ##Writing the company email
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 30);
        $pdf->Write(0, $config->email);
        ##Writing the company website
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 34);
        $pdf->Write(0, $config->website);
        ################################################
        ## WRITING THE CUSTOMER INFORMATION ON TICKET ##
        ################################################
        ## Writing the clientname.
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(135, 51);
        $pdf->Write(0, utf8_decode($order->name));
        ## Writing the client address.
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(135, 55);
        $pdf->Write(0, utf8_decode($order->address));
        ## Writing the zipcode & city.
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(135, 59);
        $pdf->Write(0, $order->zipcode . ' ' . utf8_decode($order->city));
        ## Writing the zipcode & city.
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(135, 63);
        $pdf->Write(0, $order->emailaddress);
        #############################################
        ## WRITING THE ORDER CONFIRMATION TEXT     ##
        #############################################
        ## Writing the orderdate on the confirmation.
        $pdf->SetFont('Arial', '', 11);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(7, 79);
        $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_ORDERCONFIRMATION')) . ' ' . $this->eid);
        #############################################
        ## WRITING THE GRID TOP TEXTURES HERE      ##
        #############################################
        $pdf->SetFont('Arial', 'B', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(14, 88);
        $pdf->Write(0, JText::_('ID#'));
        $pdf->SetFont('Arial', 'B', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(27, 88);
        $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TICKETINFORMATION')));
        $pdf->SetFont('Arial', 'B', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(129, 88);
        $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_DATE')));
        $pdf->SetFont('Arial', 'B', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(159, 88);
        $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TIME')));
        $pdf->SetFont('Arial', 'B', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(182, 88);
        $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_PRICE')));
        #############################################
        ## WRITING THE GRID - PLEASE DONT CHANGE   ##
        #############################################
        ## Making the query for getting the order
        $sql = 'SELECT  a.*, t.*, e.eventname, c.*, 
			  t.ticketdate, t.starttime, t.location, t.locationinfo, a.paid, e.groupname, t.eventcode
			  FROM #__ticketmaster_orders AS a, #__ticketmaster_clients AS c,
			  #__ticketmaster_events AS e, #__ticketmaster_tickets AS t
			  WHERE a.userid = c.userid
			  AND a.eventid = e.eventid
			  AND a.ticketid = t.ticketid
			  AND ordercode = ' . $this->eid . '';
        $db->setQuery($sql);
        $items = $db->loadObjectList();
        ## Setting the startgrid, DON'T change this!
        $height1 = 100;
        $height2 = 104;
        $totalprice = 0.0;
        ## Setting font color & font
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $k = 0;
        for ($i = 0, $n = count($items); $i < $n; $i++) {
            $row =& $items[$i];
            ## Writing the itemid on the left collumn
            ## Make sure they are centered, see function below
            $chars = strlen($row->orderid);
            if ($chars == 1) {
                $pdf->SetXY(15, $height1);
            }
            if ($chars == 2) {
                $pdf->SetXY(13, $height1);
            }
            if ($chars == 3) {
                $pdf->SetXY(12, $height1);
            }
            if ($chars == 4) {
                $pdf->SetXY(11, $height1);
            }
            if ($chars == 5) {
                $pdf->SetXY(10, $height1);
            }
            $pdf->Write(0, $row->orderid);
            ## Event information, first line
            $pdf->SetXY(27, $height1);
            if ($row->parentname != $row->ticketname) {
                $pdf->Write(0, utf8_decode($row->eventcode) . ' / ' . utf8_decode($row->parentname) . ' - ' . utf8_decode($row->ticketname));
            } else {
                $pdf->Write(0, utf8_decode($row->eventcode) . ' / ' . utf8_decode($row->ticketname));
            }
            ## Event information, second line
            $pdf->SetXY(27, $height2);
            $pdf->Write(0, utf8_decode($row->location) . ' - ' . utf8_decode($row->locationinfo));
            ## Event information, the date field
            $pdf->SetXY(125, $height1);
            $ticketdate = date($config->dateformat, strtotime($order->ticketdate));
            $pdf->Write(0, $ticketdate);
            ## Event information, the date field
            $pdf->SetXY(159, $height1);
            $pdf->Write(0, $row->starttime);
            ## Event information, the date field
            if ($config->use_euros_in_pdf == 1) {
                ## Fixing the euro issue..
                $price = showprice($config->priceformat, $row->ticketprice, '');
                $price = chr(128) . ' ' . $price;
            } elseif ($config->use_euros_in_pdf == 2) {
                $price = showprice($config->priceformat, $row->ticketprice, '');
                $price = chr(0xa3) . ' ' . $price;
            } else {
                $price = showprice($config->priceformat, $row->ticketprice, $config->valuta);
            }
            $pdf->SetXY(178, $height1);
            $pdf->Write(0, $price);
            ## Add extra row to the FOR loop.
            $height1 = $height1 + 10;
            $height2 = $height2 + 10;
            $totalprice = (double) $totalprice + $price;
            $k = 1 - $k;
        }
        #############################################
        ## WRITING THE TOTALS OF THE ORDER         ##
        #############################################
        $pdf->Line(174, 250, 200, 250);
        ## Including required paths to calculator.
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
        include_once $path_include;
        $total = _getAmount($this->eid);
        $fees = _getFees($this->eid);
        if ($config->use_euros_in_pdf == 1) {
            ## Fixing the euro issue..
            $price = showprice($config->priceformat, $total - $fees, '');
            $price = chr(128) . ' ' . $price;
        } elseif ($config->use_euros_in_pdf == 2) {
            $price = showprice($config->priceformat, $total - $fees, '');
            $price = chr(0xa3) . ' ' . $price;
        } else {
            $price = showprice($config->priceformat, $total - $fees, $config->valuta);
        }
        ## Event information, the price field
        $pdf->SetXY(175, 255);
        $pdf->Write(0, $price);
        if ($config->variable_transcosts == 1) {
            ## Event information, the price field
            $pdf->SetXY(150, 259);
            $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TOTALFEE')));
            ## Event information, the price field
            $pdf->SetXY(150, 267);
            $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TOTAL')));
            if ($config->use_euros_in_pdf == 1) {
                ## Fixing the euro issue..
                $price = showprice($config->priceformat, $fees, '');
                $price = chr(128) . ' ' . $price;
            } elseif ($config->use_euros_in_pdf == 2) {
                $price = showprice($config->priceformat, $fees, '');
                $price = chr(0xa3) . ' ' . $price;
            } else {
                $price = showprice($config->priceformat, $fees, $config->valuta);
            }
            $pdf->SetXY(175, 259);
            $pdf->Write(0, $price);
            ## Draw a line to count total amount
            $pdf->Line(174, 263, 200, 263);
            if ($config->use_euros_in_pdf == 1) {
                ## Fixing the euro issue..
                $price = showprice($config->priceformat, $total, '');
                $price = chr(128) . ' ' . $price;
            } elseif ($config->use_euros_in_pdf == 2) {
                $price = showprice($config->priceformat, $total, '');
                $price = chr(0xa3) . ' ' . $price;
            } else {
                $price = showprice($config->priceformat, $total, $config->valuta);
            }
            $pdf->SetXY(175, 267);
            $pdf->Write(0, $price);
            $pdf->SetXY(150, 255);
            $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_SUBTOTAL')));
        } else {
            if ($config->transactioncosts != 0) {
                ## Event information, the price field
                $pdf->SetXY(150, 259);
                $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TOTALFEE')));
                ## Event information, the price field
                $pdf->SetXY(150, 267);
                $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TOTAL')));
                $totalfee = $config->transactioncosts;
                $fees = number_format($totalfee, 2, ',', '.');
                if ($config->use_euros_in_pdf == 1) {
                    ## Fixing the euro issue..
                    $price = showprice($config->priceformat, $config->transactioncosts, '');
                    $price = chr(128) . ' ' . $price;
                } elseif ($config->use_euros_in_pdf == 2) {
                    $price = showprice($config->priceformat, $config->transactioncosts, '');
                    $price = chr(0xa3) . ' ' . $price;
                } else {
                    $price = showprice($config->priceformat, $config->transactioncosts, $config->valuta);
                }
                $pdf->SetXY(175, 259);
                $pdf->Write(0, $price);
                ## Draw a line to count total amount
                $pdf->Line(174, 263, 200, 263);
                if ($config->use_euros_in_pdf == 1) {
                    ## Fixing the euro issue..
                    $price = showprice($config->priceformat, $total, '');
                    $price = chr(128) . ' ' . $price;
                } elseif ($config->use_euros_in_pdf == 2) {
                    $price = showprice($config->priceformat, $total, '');
                    $price = chr(0xa3) . ' ' . $price;
                } else {
                    $price = showprice($config->priceformat, $total, $config->valuta);
                }
                $pdf->SetXY(175, 267);
                $pdf->Write(0, $price);
                $pdf->SetXY(150, 255);
                $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_SUBTOTAL')));
            }
        }
        $file = basename(tempnam('.', 'tmp'));
        rename($file, JPATH_SITE . DS . 'tmp' . DS . $this->eid . '.pdf');
        $file .= '.pdf';
        ## Save PDF to file now!!
        $pdf->Output(JPATH_SITE . DS . 'tmp' . DS . $file, 'F');
        ## Now move the file away for security reasons
        ## Import the Joomla! Filesystem.
        jimport('joomla.filesystem.file');
        ## Copy the file to a new directory.
        $src = JPATH_SITE . DS . 'tmp' . DS . $file;
        ## The new name for the ticket
        $dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'confirmation' . DS . $this->eid . '.pdf';
        ## Copy the file now.
        JFile::copy($src, $dest);
        ## The old temporary file needs to be deleted.
        JFile::delete($src);
    }
    function send()
    {
        $db = JFactory::getDBO();
        ## Making the query for getting the orders
        $sql = 'SELECT  a.*, c.name, c.emailaddress, c.firstname, e.eventname,  t.ticket_size, t.ticket_orientation, t.combine_multitickets
			  FROM #__ticketmaster_orders AS a, #__ticketmaster_clients AS c, #__ticketmaster_events AS e, #__ticketmaster_tickets AS t 
			  WHERE a.userid = c.userid
			  AND a.eventid = e.eventid
			  AND t.ticketid = a.ticketid
			  AND ordercode = ' . (int) $this->eid . '';
        $db->setQuery($sql);
        $info = $db->loadObjectList();
        $k = 0;
        $row =& $info[0];
        if ($row->combine_multitickets && count($info) > 1) {
            $fname = $this->combinetickets($info);
            $attachment[] = $fname;
            $name = $row->name;
            $email = $row->emailaddress;
            $event = $row->eventname;
        } else {
            for ($i = 0, $n = count($info); $i < $n; $i++) {
                $row =& $info[$i];
                ## Tickets are saved as: eTicket-1000
                ## Create attachments the same as saved
                $attachment[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'eTicket-' . $row->orderid . '.pdf';
                $name = $row->name;
                $email = $row->emailaddress;
                $event = $row->eventname;
                $k = 1 - $k;
            }
        }
        ## We do now need to get the mail that wil send the ticket.
        ## Using email ID: #1
        ## We need to select all information.
        $sql = "SELECT * FROM #__ticketmaster_emails WHERE emailid = 1 ";
        $db->setQuery($sql);
        $mail = $db->loadObject();
        #### NEW FOR 3.0.2 - EXTRA DATA IN THE EMAIL FOR TICKETS! ####
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'functions.php';
        include_once $path_include;
        ## Loading the configuration table.
        $sql = 'SELECT * FROM #__ticketmaster_config WHERE configid = 1';
        $db->setQuery($sql);
        $configuration = $db->loadObject();
        $sql = 'SELECT  a.*, t.*, e.eventname, c.*, 
			  t.ticketdate, t.starttime, t.location, t.locationinfo, a.paid, e.groupname, t.eventcode
			  FROM #__ticketmaster_orders AS a, #__ticketmaster_clients AS c,
			  #__ticketmaster_events AS e, #__ticketmaster_tickets AS t
			  WHERE a.userid = c.userid
			  AND a.eventid = e.eventid
			  AND a.ticketid = t.ticketid
			  AND ordercode = ' . $this->eid . '
			  GROUP BY a.orderid';
        $db->setQuery($sql);
        $data = $db->loadObjectList();
        include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'classes' . DS . 'special.tickets.class.php';
        if ($configuration->send_multi_ticket_only == 1) {
            ## Create the new multi ticket.
            $multi = new special((int) $this->eid);
            $multi->create();
            ## Clearing the old fashion PDF:
            unset($attachment);
            ## Send the multi ticket only as attachment: multi-[ordercode]
            $attachment[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'multi-' . (int) $this->eid . '.pdf';
            $attachment_admin[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'multi-' . (int) $this->eid . '.pdf';
        }
        $sql = 'SELECT COUNT(orderid) AS total 
		      FROM #__ticketmaster_orders 
			  WHERE ordercode = ' . (int) $this->eid . '
			  AND paid = 0';
        $ordering_code = $this->eid;
        $db->setQuery($sql);
        $status = $db->loadObjectList();
        if ($status->total > 0) {
            $paymentstatus = '<font color="#FF0000">' . JText::_('COM_TICKETMASTER_ORDERSTATUS_UNPAID') . '</font>';
        } else {
            $paymentstatus = '<font color="#006600">' . JText::_('COM_TICKETMASTER_ORDERSTATUS_PAID') . '</font>';
        }
        $orders = '<ul>';
        $k = 0;
        for ($i = 0, $n = count($data); $i < $n; $i++) {
            $row = $data[$i];
            $price = showprice($configuration->priceformat, $row->ticketprice, $configuration->valuta);
            $ticketdate = date($configuration->dateformat, strtotime($row->ticketdate));
            if ($row->firstname != '') {
                $customer = $row->firstname . ' ' . $row->name;
            } else {
                $customer = $row->name;
            }
            $recipient = $row->emailaddress;
            $userid = $row->userid;
            $orders .= '<li>[ ' . $row->orderid . ' ] - [ ' . $ticketdate . ' ] - <strong>' . $row->ticketname . '</strong> [ ' . $price . ' ]</li>';
            $k = 1 - $k;
        }
        $orders .= '</ul>';
        ## Including required paths to calculator.
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
        include_once $path_include;
        ## Get the paid amount:
        $to_be_paid = _getAmount($ordering_code);
        $price = showprice($configuration->priceformat, $to_be_paid, $configuration->valuta);
        $total_tickets = count($data);
        #### END ADDONG FOR EMAIL ####
        $countattachments = count($attachment);
        $message = str_replace('%%NAME%%', $customer, $mail->mailbody);
        $subject = str_replace('%%EVENTNAME%%', $event, $mail->mailsubject);
        $message = str_replace('%%ORDERCODE%%', $this->eid, $message);
        $message = str_replace('%%TICKETS%%', $total_tickets, $message);
        $message = str_replace('%%PRICE%%', $price, $message);
        $message = str_replace('%%ORDERLIST%%', $orders, $message);
        $message = str_replace('%%PAYMENTSTATUS%%', $paymentstatus, $message);
        $message = str_replace('%%COMPANYNAME%%', $configuration->companyname, $message);
        $message = str_replace('%%COMPANYADDRESS%%', $configuration->address1, $message);
        $message = str_replace('%%COMPANYCITY%%', $configuration->city, $message);
        $message = str_replace('%%PHONENUMBER%%', $configuration->phone, $message);
        if ($countattachments > 0) {
            ## Imaport mail functions:
            jimport('joomla.mail.mail');
            ## Set the sender of the email:
            $sender[0] = $mail->from_email;
            $sender[1] = $mail->from_name;
            ## Compile mailer function:
            $obj = JFactory::getMailer();
            $obj->setSender($sender);
            $obj->isHTML(true);
            $obj->setBody($message);
            $obj->addRecipient($email);
            if ($configuration->send_pdf_tickets == 1) {
                $obj->addAttachment($attachment);
            }
            ## Send blind copy to site admin?
            if ($mail->receive_bcc == 1) {
                if ($mail->reply_to_email != '') {
                    $obj->addRecipient($mail->reply_to_email);
                }
            }
            ## Add reply to and subject:
            $obj->addReplyTo($sender);
            $obj->setSubject($subject);
            if ($mail->published == 1) {
                $sent = $obj->Send();
            }
            ## Add the ordercode & userid to $vars
            $vars['ordercode'] = $this->eid;
            $vars['userid'] = $userid;
            ## TRIGGER INVOICING PLUGIN AND RELATED onAfterSendTickets
            JPluginHelper::importPlugin('rdmediahelpers');
            $dispatcher = JDispatcher::getInstance();
            $dispatcher->trigger('OnAfterSentTickets', array($vars));
            if ($configuration->send_multi_ticket_admin == 1) {
                ## Check if the multi ticket is there:
                $attachment = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'multi-' . (int) $this->eid . '.pdf';
                if (!file_exists($attachment)) {
                    ## Create the new multi ticket.
                    $multi = new special((int) $this->eid);
                    $multi->create();
                    ## Send the multi ticket only as attachment: multi-[ordercode]
                    $attachment = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'multi-' . (int) $this->eid . '.pdf';
                }
                ## Now preapre message for the admin:
                $admin = JFactory::getMailer();
                ## Set the sender of the email:
                $sender[0] = $mail->from_email;
                $sender[1] = $mail->from_name;
                ## Compile mailer function:
                $admin->setSender($sender);
                $admin->isHTML(true);
                $admin->setBody($message);
                $admin->addRecipient($configuration->email);
                $admin->addAttachment($attachment);
                $admin->addReplyTo($sender);
                $admin->setSubject($subject);
                $sent = $admin->Send();
            }
        }
        ## Updating the order, PDF sent = 1
        $query = 'UPDATE #__ticketmaster_orders' . ' SET pdfsent = 1' . ' WHERE ordercode = ' . (int) $this->eid . '';
        ## Do the query now
        $db->setQuery($query);
        ## When query goes wrong.. Show message with error.
        if (!$db->query()) {
            exit('Query went wrong in sendonpayment.class.php');
            return false;
        }
        ## Updating the order, PDF sent = 1
        $query = 'UPDATE #__ticketmaster_tickets' . ' SET ticketssent = ticketssent+' . (int) $countattachments . '' . ' WHERE ticketid = ' . (int) $info->ticketid . '';
        ## Do the query now
        $db->setQuery($query);
        ## When query goes wrong.. Show message with error.
        if (!$db->query()) {
            $this->setError($db->getErrorMsg());
            return false;
        }
    }
Example #8
0
    function remove()
    {
        $orderid = JRequest::getInt('orderid', 0);
        ## Getting the database.
        $db = JFactory::getDBO();
        $session =& JFactory::getSession();
        $ordercode = $session->get('ordercode');
        ## Making the tickets inactive, they still be present at the database.
        $update = 'SELECT o.* , t.parent AS parentticket
				  FROM #__ticketmaster_orders  AS o, #__ticketmaster_tickets AS t
				  WHERE orderid = ' . (int) $orderid . '
				  AND o.ticketid = t.ticketid
				  AND ordercode = ' . $ordercode . '';
        $db->setQuery($update);
        $tdata = $db->loadObject();
        ## Update the tickets-totals that where removed.
        $query = 'UPDATE #__ticketmaster_tickets' . ' SET totaltickets = totaltickets+1' . ' WHERE ticketid = ' . (int) $tdata->ticketid . ' ';
        ## Do the query now
        $db->setQuery($query);
        ## When query goes wrong.. Show message with error.
        if (!$db->query()) {
            $this->setError($db->getErrorMsg());
            return false;
        }
        if ($tdata->parentticket != 0) {
            ## Update the tickets-totals that where removed.
            $query = 'UPDATE #__ticketmaster_tickets' . ' SET totaltickets = totaltickets+1' . ' WHERE ticketid = ' . $tdata->parentticket . ' ';
            ## Do the query now
            $db->setQuery($query);
            ## When query goes wrong.. Show message with error.
            if (!$db->query()) {
                $this->setError($db->getErrorMsg());
                return false;
            }
        }
        if ($tdata->seat_sector != 0) {
            $query = 'UPDATE #__ticketmaster_coords 
					  SET booked = 0, orderid = 0 
					  WHERE orderid = ' . $tdata->orderid . ' ';
            ## Do the query now
            $db->setQuery($query);
            ## When query goes wrong.. Show message with error.
            if (!$db->query()) {
                $this->setError = $db->getErrorMsg();
                return false;
            }
        }
        ## Now delete the selected tickets.
        $query = 'DELETE FROM #__ticketmaster_orders WHERE orderid = "' . (int) $orderid . '" 
				  AND ordercode = "' . (int) $ordercode . '" ';
        ## Do the query now	and delete all selected invoices.
        $db->setQuery($query);
        ## When query goes wrong.. Show message with error.
        if (!$db->query()) {
            $this->setError($db->getErrorMsg());
            return false;
        }
        ## Making the query for showing all the cars in list function
        $sql = 'SELECT * FROM #__ticketmaster_config WHERE configid = 1';
        $db->setQuery($sql);
        $data = $db->loadObject();
        ## Including some functionality.
        include_once 'components/com_ticketmaster/assets/functions.php';
        ## Including required paths to calculator.
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
        include_once $path_include;
        ## Total for this order:
        $total = _getAmount($session->get('ordercode'));
        $fees = _getFees($session->get('ordercode'));
        $order = $total - $fees;
        $result = showprice($data->priceformat, $order, $data->valuta);
        echo $result;
    }
    function paypal()
    {
        // Load user_profile plugin language
        $lang = JFactory::getLanguage();
        $lang->load('plg_rdmedia_paypal', JPATH_ADMINISTRATOR);
        ## Include the confirmation class to sent the tickets.
        $path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'classes' . DS . 'createtickets.class.php';
        $override = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'classes' . DS . 'override' . DS . 'createtickets.class.php';
        ## using $sig, $tx, validate that payment was successful
        $item_number_array = explode(':', strval(JRequest::getVar('item_number')));
        $item_number = intval(@$item_number_array[0]);
        $action = strval(JRequest::getVar('action'));
        $tx = strval(JRequest::getVar('tx'));
        $st = strval(JRequest::getVar('st'));
        $sig = strval(JRequest::getVar('sig'));
        ## Initializing cURL
        $request = curl_init();
        ## Set request options to paypal
        curl_setopt_array($request, array(CURLOPT_URL => $this->url, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query(array('cmd' => '_notify-synch', 'tx' => $tx, 'at' => $this->paypal_authcode)), CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => FALSE));
        ## Execute request and get response and status code
        $response = curl_exec($request);
        $status = curl_getinfo($request, CURLINFO_HTTP_CODE);
        ## Close connection
        curl_close($request);
        ## Check the status and success message from paypal.
        if ($status == 200 and strpos($response, 'SUCCESS') === 0) {
            ## Remove SUCCESS part (7 characters long)
            $response = substr($response, 7);
            ## URL decode
            $response = urldecode($response);
            ## Turn into associative array
            preg_match_all('/^([^=\\s]++)=(.*+)/m', $response, $m, PREG_PATTERN_ORDER);
            $response = array_combine($m[1], $m[2]);
            ## Fix character encoding if different from UTF-8 (in my case)
            if (isset($response['charset']) and strtoupper($response['charset']) !== 'UTF-8') {
                foreach ($response as $key => &$value) {
                    $value = mb_convert_encoding($value, 'UTF-8', $response['charset']);
                }
                $response['charset_original'] = $response['charset'];
                $response['charset'] = 'UTF-8';
            }
            ## Sort on keys for readability (handy when debugging)
            ksort($response);
            ### Showing the result for test environments.
            ### print_r($response);
            if ($response['payment_status'] != 'Completed') {
                ## Show error.
            } else {
                ## Connecting the database
                $db = JFactory::getDBO();
                ## Current date for database.
                $trans_date = date("d-m-Y H:i");
                ## Getting the transaction info from PP.
                $payment_id = $response['txn_id'];
                ## Check that txn_id has not been previously processed
                $sql = 'SELECT COUNT(pid) AS total 
						FROM #__ticketmaster_transactions 
						WHERE transid = "' . $payment_id . '" ';
                $db->setQuery($sql);
                $results = $db->loadObject();
                if ($results->total > 0) {
                    ## Show error on failed - Transaction may not exsist in DB.
                    $msg = JText::_('COM_TICKETMSTER_PP_TRANSACTION_PROCESSED');
                    $this->_showmsg($this->failure_tpl, $msg);
                } else {
                    ## Paid amount to PayPal
                    $payment_amount = $response['mc_gross'];
                    ## Get the email address from the buyer.
                    $payer_email = $response['payer_email'];
                    ## Get the order information sent by PP.
                    $orderid = $response['custom'];
                    ## Including required paths to calculator.
                    $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
                    include_once $path_include;
                    ## Getting the amounts for this order.
                    $amount = _getAmount($response['custom'], 1);
                    ##Requested amount for this order.
                    $amount_req = number_format($amount, 2, '', '');
                    ## Sent amount by PP (needs the same notation as ours)
                    $amount_pp = number_format($response['mc_gross'], 2, '', '');
                    ## Check if the amount is the same as the paid amount.
                    if ($amount_req != $amount_pp) {
                        ## Amounts are not the same. Show the message to the client.
                        $msg = JText::_('COM_TICKETMSTER_PP_AMOUNT_IS_NOT_CORRECTLY');
                        $this->_showmsg($this->failure_tpl, $msg);
                    } else {
                        ## Getting the latest logged in user.
                        $user =& JFactory::getUser();
                        JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tables');
                        $row =& JTable::getInstance('transaction', 'Table');
                        ## Pickup All Details and create foo=bar&baz=boom&cow=milk&php=hypertext+processor
                        $payment_details = http_build_query($response);
                        $payment_type = 'PayPal';
                        $orderid = $response['custom'];
                        ## Now store all data in the transactions table
                        $row->transid = $response['txn_id'];
                        $row->userid = $user->id;
                        $row->details = $payment_details;
                        $row->amount = $response['mc_gross'];
                        $row->type = 'PayPal';
                        $row->email_paypal = $response['payer_email'];
                        $row->orderid = $response['custom'];
                        ## Store data
                        $row->store();
                        $query = 'UPDATE #__ticketmaster_orders' . ' SET paid = 1, published = 1' . ' WHERE ordercode = ' . (int) $response['custom'] . '';
                        ## Do the query now
                        $db->setQuery($query);
                        ## When query goes wrong.. Show message with error.
                        if (!$db->query()) {
                            $this->setError($db->getErrorMsg());
                            return false;
                        }
                        $query = 'SELECT * FROM #__ticketmaster_orders WHERE ordercode = ' . (int) $response['custom'] . '';
                        ## Do the query now
                        $db->setQuery($query);
                        $data = $db->loadObjectList();
                        $k = 0;
                        for ($i = 0, $n = count($data); $i < $n; $i++) {
                            $row =& $data[$i];
                            ## Check if the override is there.
                            if (file_exists($override)) {
                                ## Yes, now we use it.
                                require_once $override;
                            } else {
                                ## No, use the standard
                                require_once $path;
                            }
                            if (isset($row->orderid)) {
                                $creator = new ticketcreator((int) $row->orderid);
                                $creator->doPDF();
                            }
                            $k = 1 - $k;
                        }
                        ## Include the confirmation class to sent the tickets.
                        $path_include = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'classes' . DS . 'sendonpayment.class.php';
                        include_once $path_include;
                        ## Sending the ticket immediatly to the client.
                        $creator = new sendonpayment((int) $response['custom']);
                        $creator->send();
                        ## Removing the session, it's not needed anymore.
                        $session =& JFactory::getSession();
                        $session->clear($response['custom']);
                        $session->clear('ordercode');
                        $session->clear('coupon');
                        ## Getting the desired info from the configuration table
                        $sql = "SELECT * FROM #__ticketmaster_emails WHERE emailid = " . (int) $this->success_tpl . "";
                        $db->setQuery($sql);
                        $config = $db->loadObject();
                        ## Getting the desired info from the configuration table
                        $sql = "SELECT * FROM #__users WHERE id = " . (int) $user->id . "";
                        $db->setQuery($sql);
                        $user = $db->loadObject();
                        echo '<h1>' . $config->mailsubject . '</h1>';
                        $message = str_replace('%%TID%%', $response['txn_id'], $config->mailbody);
                        $message = str_replace('%%OID%%', $response['custom'], $message);
                        $message = str_replace('%%AMOUNT%%', $response['mc_gross'], $message);
                        $message = str_replace('%%DATE%%', $trans_date, $message);
                        $message = str_replace('%%NAME%%', $user->name, $message);
                        $message = str_replace('%%EMAIL%%', $response['payer_email'], $message);
                        ## Imaport mail functions:
                        jimport('joomla.mail.mail');
                        ## Set the sender of the email:
                        $sender[0] = $config->from_email;
                        $sender[1] = $config->from_name;
                        ## Compile mailer function:
                        $obj = JFactory::getMailer();
                        $obj->setSender($sender);
                        $obj->isHTML(true);
                        $obj->setBody($message);
                        $obj->addRecipient($user->email);
                        ## Send blind copy to site admin?
                        if ($config->receive_bcc == 1) {
                            if ($config->reply_to_email != '') {
                                $obj->addRecipient($obj->reply_to_email);
                            }
                        }
                        ## Add reply to and subject:
                        $obj->addReplyTo($config->reply_to_email);
                        $obj->setSubject($config->mailsubject);
                        if ($mail->published == 1) {
                            $sent = $obj->Send();
                        }
                        echo $message;
                    }
                }
            }
        } else {
            ## Amounts are not the same. Show the message to the client.
            $msg = JText::_('COM_TICKETMSTER_PP_TRANSACTION_FAILED');
            $this->_showmsg($this->failure_tpl, $msg);
        }
    }
    public function create()
    {
        $db = JFactory::getDBO();
        ## Making the query for getting the config
        $sql = 'SELECT  * FROM #__ticketmaster_config WHERE configid = 1';
        $db->setQuery($sql);
        $config = $db->loadObject();
        ## include the functions for price views.
        $file_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'functions.php';
        include_once $file_include;
        ## Required helpers to create this PDF invoice
        ## Do NOT edit the required files! It will damage your component.
        include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'pdf' . DS . 'fpdf' . DS . 'fpdf.php';
        include_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'pdf' . DS . 'fpdi_ean13.php';
        ## Making the query for getting the order
        $sql = 'SELECT  a.*, t.*, e.eventname, c.*, 
			  t.ticketdate, t.starttime, t.location, t.locationinfo, a.paid, e.groupname, t.eventcode
			  FROM #__ticketmaster_orders AS a, #__ticketmaster_clients AS c,
			  #__ticketmaster_events AS e, #__ticketmaster_tickets AS t
			  WHERE a.userid = c.userid
			  AND a.eventid = e.eventid
			  AND a.ticketid = t.ticketid
			  AND ordercode = ' . $this->eid . '';
        $db->setQuery($sql);
        $order = $db->loadObject();
        $db = JFactory::getDBO();
        ## Making the query for getting the config
        $sql = 'SELECT  * FROM #__ticketmaster_config WHERE configid = 1';
        $db->setQuery($sql);
        $config = $db->loadObject();
        ## CSetting the size of the document.
        $pdf = new FPDI_EAN13('P', 'mm', 'A4');
        ## add a page
        $pdf->AddPage();
        ## Getting the order date:
        $orderdate = date($config->dateformat, strtotime($order->orderdate));
        ### setting the header for the page: (w) 210mm x (h) 90mm
        $folder = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'images' . DS;
        $pdf->Image($folder . 'header.jpg', 0, 0, 210, 90);
        ## Including required paths to calculator.
        $path_include = JPATH_SITE . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'helpers' . DS . 'get.amount.php';
        include_once $path_include;
        $total = _getAmount($this->eid, 0, 0);
        $fees = _getFees($this->eid);
        $discount = _getDiscount($this->eid);
        ###############################################
        ## WRITING THE COMPANY INFORMATION ON TICKET ##
        ###############################################
        if ($config->address_format_company == '') {
            ##Writing the company name
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(10, 35);
            $pdf->Write(0, utf8_decode($config->companyname));
            ##Writing the company address
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(10, 45);
            $pdf->Write(0, utf8_decode($config->address1));
            ##Writing the company zipcode+city
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(10, 50);
            $pdf->Write(0, $config->zipcode . ' ' . utf8_decode($config->city));
            ##Writing the company phone
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(10, 55);
            $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_PHONE')) . ' ' . utf8_decode($config->phone));
            ##Writing the company email
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(10, 60);
            $pdf->Write(0, $config->email);
            ##Writing the company website
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(10, 65);
            $pdf->Write(0, $config->website);
            $start_height = $pdf->GetY() + 10;
        } else {
            if (ini_get('magic_quotes_gpc') == '1') {
                $body = stripslashes($config->address_format_company);
            } else {
                $body = utf8_decode($config->address_format_company);
            }
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(10, 40);
            $pdf->MultiCell(0, 5, "{$body}", 0, 'L', 0);
            $start_height = $pdf->GetY() + 10;
        }
        ################################################
        ## WRITING THE CUSTOMER INFORMATION ON TICKET ##
        ################################################
        if ($order->gender == 1) {
            $salutation = JText::_('COM_TICKETMASTER_MR');
        } else {
            if ($order->gender == 2) {
                $salutation = JText::_('COM_TICKETMASTER_MRS');
            } else {
                if ($order->gender == 3) {
                    $salutation = JText::_('COM_TICKETMASTER_MISS');
                } else {
                    $salutation = JText::_('COM_TICKETMASTER_FAMILY');
                }
            }
        }
        if ($config->address_format_client == '') {
            ## Writing the clientname.
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(135, 51);
            if ($order->firstname == '') {
                $pdf->Write(0, utf8_decode($order->name));
            } else {
                $pdf->Write(0, utf8_decode($salutation) . utf8_decode($order->firstname) . ' ' . utf8_decode($order->name));
            }
            ## Writing the client address.
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(135, 55);
            $pdf->Write(0, utf8_decode($order->address));
            ## Writing the zipcode & city.
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(135, 59);
            $pdf->Write(0, $order->zipcode . ' ' . utf8_decode($order->city));
            ## Writing the zipcode & city.
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(135, 63);
            $pdf->Write(0, $order->emailaddress);
        } else {
            $sql = 'SELECT * FROM #__ticketmaster_country
			  	  WHERE country_id = ' . $order->country_id . '';
            $db->setQuery($sql);
            $obj = $db->loadObject();
            $client_address = str_replace('%%FIRSTNAME%%', utf8_decode($order->firstname), $config->address_format_client);
            $client_address = str_replace('%%LASTNAME%%', utf8_decode($order->name), $client_address);
            $client_address = str_replace('%%SALUTATION%%', utf8_decode($salutation), $client_address);
            $client_address = str_replace('%%ADDRESS1%%', utf8_decode($order->address), $client_address);
            $client_address = str_replace('%%ADDRESS2%%', utf8_decode($order->address2), $client_address);
            $client_address = str_replace('%%ZIPCODE%%', utf8_decode($order->zipcode), $client_address);
            $client_address = str_replace('%%CITY%%', utf8_decode($order->city), $client_address);
            $client_address = str_replace('%%COUNTRY_FULL%%', utf8_decode($obj->country), $client_address);
            $client_address = str_replace('%%COUNTRY_2D%%', utf8_decode($obj->country_2_code), $client_address);
            $client_address = str_replace('%%COUNTRY_3D%%', utf8_decode($obj->country_3_code), $client_address);
            if (ini_get('magic_quotes_gpc') == '1') {
                $body = stripslashes($client_address);
            } else {
                $body = $client_address;
            }
            $pdf->SetFont('Arial', '', 9);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetXY(135, 51);
            $pdf->MultiCell(0, 5, "{$body}", 0, 'L', 0);
        }
        ## PRINT THE TICKETS NOW IN LIST ##
        ## FIRST WE HAVE TO GET ALL ITEMS FOR THIS TICKET ##
        $sql = 'SELECT  a.*, t.*, e.eventname, c.*, 
			  t.ticketdate, t.starttime, t.location, t.locationinfo, a.paid, e.groupname, t.eventcode, t.show_end_date, t.end_date
			  FROM #__ticketmaster_orders AS a, #__ticketmaster_clients AS c,
			  #__ticketmaster_events AS e, #__ticketmaster_tickets AS t
			  WHERE a.userid = c.userid
			  AND a.eventid = e.eventid
			  AND a.ticketid = t.ticketid
			  AND ordercode = ' . $this->eid . '
			  GROUP BY a.orderid';
        $db->setQuery($sql);
        $data = $db->loadObjectList();
        ## Setting the order number:
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetXY(10, $start_height);
        $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_ENTRANCE_TICKETS_FOR')) . ' ' . $this->eid);
        ## Writing the name customer:
        $pdf->SetXY(10, $start_height + 5);
        if ($order->firstname == '') {
            $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TICKETS_FOR_CUSTOMER')) . ' ' . utf8_decode($order->name));
        } else {
            $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TICKETS_FOR_CUSTOMER')) . ' ' . utf8_decode($order->firstname) . ' ' . utf8_decode($order->name));
        }
        $pdf->SetXY(10, $start_height + 10);
        $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_TICKETS_ORDER_DATE')) . ' ' . $orderdate);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->Line(10, 105, 200, 105);
        ## Setting the startgrid, DO NOT change this!
        $height = 105;
        $height = $pdf->GetY() + 20;
        ## Setting font color & font for all items below:
        $pdf->SetFont('Arial', '', 9);
        $pdf->SetTextColor(0, 0, 0);
        $k = 0;
        for ($i = 0, $n = count($data); $i < $n; $i++) {
            $row = $data[$i];
            if ($row->seat_sector != 0) {
                $sql = 'SELECT * FROM #__ticketmaster_coords WHERE id = ' . (int) $row->seat_sector . '';
                $db->setQuery($sql);
                $seat = $db->loadObject();
                $seatnumber = JText::_('COM_TICKETMASTER_SEAT_NR') . ': ' . $seat->row_name . $seat->seatid;
                $pdf->SetXY(10, $height + 2);
                if ($row->parentname != $row->ticketname) {
                    $pdf->SetFont('Arial', '', 9);
                    $pdf->Write(0, utf8_decode($row->eventname) . ' (' . utf8_decode($row->eventcode) . ') - ' . utf8_decode($row->ticketname) . ' - ' . utf8_decode($seatnumber));
                } else {
                    $pdf->SetFont('Arial', '', 9);
                    $pdf->Write(0, utf8_decode($row->eventcode) . ' / ' . utf8_decode($row->ticketname) . ' - ' . utf8_decode($seatnumber));
                }
            } else {
                $pdf->SetXY(10, $height + 2);
                if ($row->parentname != $row->ticketname) {
                    $pdf->SetFont('Arial', '', 9);
                    $pdf->Write(0, utf8_decode($row->eventname) . ' (' . utf8_decode($row->eventcode) . ') - ' . utf8_decode($row->ticketname));
                } else {
                    $pdf->SetFont('Arial', '', 9);
                    $pdf->Write(0, utf8_decode($row->eventcode) . ' / ' . utf8_decode($row->ticketname));
                }
            }
            $pdf->SetXY(10, $height + 7);
            if ($row->show_end_date != 1) {
                $ticketdate = date($config->dateformat, strtotime($row->ticketdate));
            } else {
                $ticketdate = date($config->dateformat, strtotime($row->ticketdate)) . ' - ' . date($config->dateformat, strtotime($row->end_date));
            }
            if ($config->use_euros_in_pdf == 2) {
                ## Fixing the euro issue..
                $price = showprice($config->priceformat, $row->ticketprice, '');
                $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_ORDER')) . ' ' . $row->orderid . ' :: ' . utf8_decode(JText::_('COM_TICKETMASTER_PDF_PRICE')) . ' ' . chr(128) . ' ' . $price . ' :: ' . JText::_('COM_TICKETMASTER_PDF_DATE') . ' ' . $ticketdate);
            } elseif ($config->use_euros_in_pdf == 3) {
                $price = showprice($config->priceformat, $row->ticketprice, '');
                $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_ORDER')) . ' ' . $row->orderid . ' :: ' . utf8_decode(JText::_('COM_TICKETMASTER_PDF_PRICE')) . ' ' . chr(0xa3) . ' ' . $price . ' :: ' . JText::_('COM_TICKETMASTER_PDF_DATE') . ' ' . $ticketdate);
            } else {
                $price = showprice($config->priceformat, $row->ticketprice, $config->valuta);
                $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_ORDER')) . $row->orderid . ' :: ' . utf8_decode(JText::_('COM_TICKETMASTER_PDF_PRICE')) . ' ' . $price . ' :: ' . JText::_('COM_TICKETMASTER_PDF_DATE') . ' ' . $ticketdate);
            }
            ## Getting the heigth for the closing line -- will only show after the for loop has been completed:
            $y = $pdf->GetY();
            ## Creating the QR Code for printing.
            if ($row->pdf_use_qrcode == 1) {
                ## Creating the code:
                $code = $row->ordercode . $row->orderid;
                ## Getting the barcode from the EAN script.
                $pdf->EAN13(1, 1, $code, $order->pdf_use_qrcode, 1);
                $session = JFactory::getSession();
                ## Gettig the orderid if there is one.
                $barcode = $session->get('barcode');
                $remoteFile = 'http://chart.apis.google.com/chart?chs=' . $config->qr_width . 'x' . $config->qr_width . '&cht=qr&chld=L|0&chl=' . $barcode . '';
                $localFile = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'classes' . DS . 'cache' . DS . $barcode . '.png';
                self::get_qr_image($remoteFile, $localFile);
                ## Gettin the genrated code.
                $cache_folder = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'classes' . DS . 'cache' . DS;
                $pdf->Image($cache_folder . $barcode . '.png', 175, $height, 20, 20);
                $pdf->SetDrawColor(193, 193, 193);
                jimport('joomla.filesystem.file');
                ## We do want to remove the QR code again.
                ## It is not needed anymore, as ticket has been printed.
                JFile::delete($cache_folder . $barcode . '.png');
                $session->clear('barcode');
            } else {
                ## Writing the code on the ticket.
                $pdf->EAN13(160, $height, $row->barcode, 0);
                $pdf->SetDrawColor(193, 193, 193);
                $pdf->Line(10, $height + 20, 200, $height + 20);
            }
            $pdf->SetXY(10, $height + 12);
            $pdf->SetFont('Arial', '', 9);
            $pdf->Write(0, utf8_decode(JText::_('COM_TICKETMASTER_BARCODE')) . ': ' . $row->barcode);
            $height = $height + 25;
            ## Path to a combined ticket is as below:
            $combined_ticket = JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'eTickets-' . $this->eid . '.pdf';
            ## remove tickets if there is a combined one.
            if (file_exists($combined_ticket)) {
                jimport('joomla.filesystem.file');
                JFile::delete($combined_ticket);
            }
            ## Path to a normal ticket is as below:
            $path = JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'eTicket-' . $row->orderid . '.pdf';
            ## Remove single ticket
            if (file_exists($path)) {
                jimport('joomla.filesystem.file');
                JFile::delete($path);
            }
            $space_left = 290 - $pdf->GetY();
            if ($space_left < 40) {
                $pdf->AddPage();
                // page break.
                ### setting the header for the page: (w) 210mm x (h) 90mm
                $folder = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'assets' . DS . 'images' . DS;
                $pdf->Image($folder . 'header.jpg', 0, 0, 210, 90);
                ## Set margin for next page:
                $height = 50;
            }
        }
        $file = basename(tempnam('.', 'tmp'));
        rename($file, JPATH_SITE . DS . 'tmp' . DS . 'multi-' . $this->eid . '.pdf');
        $file .= '.pdf';
        ## Save PDF to file now!!
        $pdf->Output(JPATH_SITE . DS . 'tmp' . DS . $file, 'F');
        ## Now move the file away for security reasons
        ## Import the Joomla! Filesystem.
        jimport('joomla.filesystem.file');
        ## Copy the file to a new directory.
        $src = JPATH_SITE . DS . 'tmp' . DS . $file;
        ## The new name for the ticket
        $dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ticketmaster' . DS . 'tickets' . DS . 'multi-' . $this->eid . '.pdf';
        ## Copy the file now.
        JFile::copy($src, $dest);
        ## The old temporary file needs to be deleted.
        JFile::delete($src);
    }