Example #1
0
 /**
  * Generates the
  *
  * @param   string  $booking      - The booking
  * @param   string  $text         - The text
  * @param   string  $subject      - The subject
  * @param   string  $destination  - Where should the generated file been send
  *
  * @return  string
  */
 public static function generateTicket($booking, $text, $subject, $destination = "D")
 {
     $fn = "ticket-" . MatukioHelperUtilsBooking::getBookingId($booking->id) . ".pdf";
     // Check if PDF was already created
     if (JFile::exists($fn)) {
         return $fn;
     }
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Matukio by compojoom.com');
     $pdf->SetTitle($subject);
     $pdf->SetSubject($subject);
     $pdf->SetKeywords('Ticket, Matukio, compojoom');
     // remove default header/footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // add a page
     $pdf->AddPage();
     $pdf->writeHTML($text, true, false, true, false, '');
     // Close and output PDF document
     // This method has several options, check the source code documentation for more information.
     return $pdf->Output($fn, $destination);
 }
 /**
  * Displays the form
  *
  * @param   string  $tpl  - The template
  *
  * @throws  Exception
  * @return  mixed|void
  */
 public function display($tpl = null)
 {
     $cid = JFactory::getApplication()->input->getInt('cid', 0);
     $user = JFactory::getUser();
     // Booking id!!
     $uid = JFactory::getApplication()->input->getInt('uid', 0);
     $uuid = JFactory::getApplication()->input->get('uuid', 0);
     if (empty($cid)) {
         throw new Exception(JText::_("COM_MATUKIO_NO_ID"), 404);
     }
     // Load event (use model function)
     $emodel = JModelLegacy::getInstance('Event', 'MatukioModel');
     $event = $emodel->getItem($cid);
     $booking = null;
     if (!empty($uuid)) {
         $model = JModelLegacy::getInstance('Booking', 'MatukioModel');
         $booking = $model->getBooking($uuid);
         if (empty($booking)) {
             throw new Exception(JText::_("COM_MATUKIO_NO_BOOKING_FOUND"), 404);
         }
         $uid = $booking->id;
     }
     // With Payment Step or without?
     $steps = 3;
     if (empty($event->fees)) {
         $steps = 2;
     }
     $fields_p1 = MatukioHelperUtilsBooking::getBookingFields(1);
     $fields_p2 = MatukioHelperUtilsBooking::getBookingFields(2);
     $fields_p3 = MatukioHelperUtilsBooking::getBookingFields(3);
     // MatukioHelperUtilsBasic::expandPathway(JTEXT::_('COM_MATUKIO_EVENTS'), JRoute::_("index.php?option=com_matukio&view=eventlist"));
     // Add event to breadcrumb :)
     MatukioHelperUtilsBasic::expandPathway(JTEXT::_($event->title), JRoute::_("index.php?option=com_matukio&view=event&id=" . $cid));
     MatukioHelperUtilsBasic::expandPathway(JTEXT::_('COM_MATUKIO_EVENT_BOOKING'), "");
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin("payment");
     $gateways = $dispatcher->trigger('onTP_GetInfo', array(MatukioHelperPayment::$matukio_payment_plugins));
     $payment = array();
     foreach ($gateways as $gway) {
         $payment[] = array("name" => $gway->id, "title" => $gway->name);
     }
     if (empty($payment)) {
         // If no payment plugins enabled then set Steps to 2 :)
         $steps = 2;
     }
     $this->gateways = $gateways;
     $this->event = $event;
     $this->uid = $uid;
     $this->uuid = $uuid;
     $this->booking = $booking;
     $this->user = $user;
     $this->steps = $steps;
     $this->payment = $payment;
     $this->fields_p1 = $fields_p1;
     $this->fields_p2 = $fields_p2;
     $this->fields_p3 = $fields_p3;
     parent::display($tpl);
 }
 /**
  * Displays the participant edit form
  *
  * @param   string  $tpl  - The template
  *
  * @throws  Exception
  * @return  mixed|void
  */
 public function display($tpl = null)
 {
     $booking_id = JFactory::getApplication()->input->getInt('booking_id', 0);
     $model = $this->getModel();
     $booking = null;
     if (!empty($booking_id)) {
         $booking = $model->getBooking();
     }
     if (!$booking) {
         $booking = JTable::getInstance('bookings', 'Table');
         $event_id = JFactory::getApplication()->input->getInt("event_id", 0);
         if (!empty($event_id)) {
             $booking->semid = $event_id;
         }
         $booking->uuid = MatukioHelperPayment::getUuid(true);
     }
     $db = JFactory::getDbo();
     $db->setQuery("SELECT r.id AS value, CONCAT(a.title, ' ', r.begin) AS text FROM #__matukio_recurring AS r LEFT JOIN #__matukio AS a ON r.event_id = a.id ");
     $events = (array) $db->loadObjectList();
     $this->event_select = JHtml::_('select.genericlist', $events, 'event_id', '', 'value', 'text', $booking->semid);
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin("payment");
     $gateways = $dispatcher->trigger('onTP_GetInfo', array(MatukioHelperPayment::$matukio_payment_plugins));
     $payment = array();
     foreach ($gateways as $gway) {
         $payment[] = array("name" => $gway->id, "title" => $gway->name);
     }
     // Booking status
     $options[] = array("value" => MatukioHelperUtilsBooking::$PENDING, "text" => MatukioHelperUtilsBooking::getBookingStatusName(MatukioHelperUtilsBooking::$PENDING));
     $options[] = array("value" => MatukioHelperUtilsBooking::$ACTIVE, "text" => MatukioHelperUtilsBooking::getBookingStatusName(MatukioHelperUtilsBooking::$ACTIVE));
     $options[] = array("value" => MatukioHelperUtilsBooking::$WAITLIST, "text" => MatukioHelperUtilsBooking::getBookingStatusName(MatukioHelperUtilsBooking::$WAITLIST));
     $options[] = array("value" => MatukioHelperUtilsBooking::$ARCHIVED, "text" => JText::_("COM_MATUKIO_ARCHIVED"));
     $options[] = array("value" => MatukioHelperUtilsBooking::$DELETED, "text" => JText::_("COM_MATUKIO_DELETED"));
     $this->status_select = JHtml::_('select.genericlist', $options, 'status', '', 'value', 'text', $booking->status);
     $marks[] = array("value" => 0, "text" => JText::_("COM_MATUKIO_NONE"));
     $marks[] = array("value" => 1, "text" => "1");
     $marks[] = array("value" => 2, "text" => "2");
     $marks[] = array("value" => 3, "text" => "3");
     $marks[] = array("value" => 4, "text" => "4");
     $marks[] = array("value" => 5, "text" => "5");
     $marks[] = array("value" => 6, "text" => "6");
     $this->mark_select = JHtml::_('select.genericlist', $marks, 'mark', '', 'value', 'text', $booking->mark);
     $this->select_checkedin = MatukioHelperInput::getRadioButtonBool("checked_in", "checked_in", $booking->checked_in);
     $this->booking = $booking;
     $this->payment = $payment;
     $this->addToolbar();
     parent::display($tpl);
 }
 */
defined('_JEXEC') or die('Restricted access');
$mainconfig = JFactory::getConfig();
$filename = $this->events[0]->title;
//var_dump($this->events);
if (count($this->events) > 1) {
    $filename = $mainconfig->get('sitename') . " - Events";
}
$icsdata = "BEGIN:VCALENDAR\n";
$icsdata .= "VERSION:2.0\n";
$icsdata .= "PRODID:" . MatukioHelperUtilsBasic::getSitePath() . "\n";
$icsdata .= "METHOD:PUBLISH\n";
foreach ($this->events as $event) {
    $user = JFactory::getuser($event->publisher);
    $icsdata .= "BEGIN:VEVENT\n";
    $icsdata .= "UID:" . MatukioHelperUtilsBooking::getBookingId($event->id) . "\n";
    $icsdata .= "ORGANIZER;CN=\"" . $user->name . "\":MAILTO:" . $user->email . "\n";
    $icsdata .= "SUMMARY:" . JText::_($event->title) . "\n";
    if ($event->webinar == 1) {
        $location = JText::_("COM_MATUKIO_WEBINAR");
    } elseif ($event->place_id != 0) {
        $locobj = MatukioHelperUtilsEvents::getLocation($event->place_id);
        $location = $locobj->location;
    } else {
        $location = $event->place;
    }
    $icsdata .= "LOCATION:" . str_replace("(\r\n|\n|\r)", ", ", $location) . "\n";
    $icsdata .= "DESCRIPTION:" . str_replace("(\r\n|\n|\r)", " ", $event->shortdesc) . "\n";
    $icsdata .= "CLASS:PUBLIC\n";
    $icsdata .= "DTSTART:" . strftime("%Y%m%dT%H%M%S", JFactory::getDate($event->begin)->toUnix()) . "\n";
    $icsdata .= "DTEND:" . strftime("%Y%m%dT%H%M%S", JFactory::getDate($event->end)->toUnix()) . "\n";
						<tr class="success">
							<td colspan="2"><?php 
echo JText::_("COM_MATUKIO_INFORMATIONS");
?>
</td>
						</tr>
						<tr>
							<td width="100" align="left" class="key">
								<?php 
echo JText::_('COM_MATUKIO_BOOKING_ID');
?>
							</td>
							<td>
								<?php 
if (!empty($this->booking->id)) {
    echo MatukioHelperUtilsBooking::getBookingId($this->booking->id) . " (" . $this->booking->id . ")";
}
?>
							</td>
						</tr>
						<tr>
							<td align="left" class="key">
								<?php 
echo JText::_('COM_MATUKIO_BOOKING_DATE');
?>
							</td>
							<td>
								<?php 
echo $this->booking->bookingdate;
?>
							</td>
for ($i = 0; $i < count($this->mybookedEvents); $i++) {
    $event = $this->mybookedEvents[$i];
    // Hack for multiple bookings with the same event
    if (empty($cureventid)) {
        $cureventid = $event->id;
    } else {
        if ($cureventid != $event->id) {
            // Reset
            $bcount = 0;
            $cureventid = $event->id;
        }
    }
    // Check if we are able to book
    $buchopt = MatukioHelperUtilsEvents::getEventBookableArray(1, $event, $user->id);
    $link = JRoute::_("index.php?option=com_matukio&view=booking&uuid=" . $buchopt[2][$bcount]->uuid);
    $booking_id = MatukioHelperUtilsBooking::getBookingId($buchopt[2][$bcount]->id);
    // Image
    // Todo Update Sometime
    $zusimage = "";
    $zusbild = 0;
    $linksbild = MatukioHelperUtilsBasic::getComponentImagePath() . "2701.png";
    $zusimage = MatukioHelperUtilsBasic::getComponentImagePath() . "2606.png";
    if ($user->id == 0) {
        $zusimage = "";
    }
    if ($event->cancelled == 1) {
        $linksbild = MatukioHelperUtilsBasic::getComponentImagePath() . "2604.png";
        $zusimage = MatukioHelperUtilsBasic::getComponentImagePath() . "2200.png";
    }
    if ($event->image != "" and MatukioHelperSettings::getSettings('event_image', 1) == 1) {
        $linksbild = MatukioHelperUtilsBasic::getEventImagePath(1) . $event->image;
 /**
  * Cancels the booking
  *
  * @throws  Exception - if access is denied!
  * @return object
  */
 public function activateBooking()
 {
     if (!JFactory::getUser()->authorise('core.edit.own', 'com_matukio')) {
         throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403);
     }
     $eventid = JFactory::getApplication()->input->getInt('cid', 0);
     $link = JRoute::_("index.php?option=com_matukio&view=participants&cid=" . $eventid . "&art=2");
     $msg = JText::_("COM_MATUKIO_BOOKING_SET_ACTIVE_SUCCESSFULL");
     $booking_ids = JFactory::getApplication()->input->get('uid', array(), 'array');
     // Set db status to deleted @since 3.1
     MatukioHelperUtilsBooking::changeStatusBooking($booking_ids, MatukioHelperUtilsBooking::$ACTIVE, true);
     $this->setRedirect($link, $msg);
 }
 /**
  * Shows the form
  *
  * @param   string  $tpl  - The tmpl
  *
  * @return  bool|mixed|object
  */
 public function display($tpl = NULL)
 {
     $database = JFactory::getDBO();
     $my = JFactory::getuser();
     $dateid = JFactory::getApplication()->input->getInt('dateid', 1);
     $catid = JFactory::getApplication()->input->getInt('catid', 0);
     $search = JFactory::getApplication()->input->get('search', '', 'string');
     $limit = JFactory::getApplication()->input->getInt('limit', 5);
     $limitstart = JFactory::getApplication()->input->getInt('limitstart', 0);
     $cid = JFactory::getApplication()->input->getInt('cid', 0);
     $uid = JFactory::getApplication()->input->getInt('uid', 0);
     $todo = JFactory::getApplication()->input->get('todo', 'print_eventlist');
     // print_eventlist, print_booking, print_myevents, print
     $rows = null;
     $status = null;
     $headertext = null;
     $neudatum = MatukioHelperUtilsDate::getCurrentDate();
     if ($limitstart < 0) {
         $limitstart = 0;
     }
     $ttlimit = "";
     if ($limit > 0) {
         $ttlimit = "\nLIMIT {$limitstart}, {$limit}";
     }
     /**
      * 65O9805443904 =    public ?!
      * 653O875032490 =    Meine Angebote
      * 6530387504345 =  Meine Buchungen / Buchungsbestätigung ?!
      *
      * 3728763872762 =
      * csv
      */
     $where = array();
     $where[] = "a.pattern = ''";
     $where[] = "a.published = '1'";
     switch ($todo) {
         case "print_eventlist":
             $navioben = explode(" ", MatukioHelperSettings::getSettings('frontend_topnavshowmodules', 'SEM_NUMBER SEM_SEARCH SEM_CATEGORIES SEM_RESET'));
             break;
         case "print_booking":
             $navioben = explode(" ", MatukioHelperSettings::getSettings('frontend_topnavbookingmodules', 'SEM_NUMBER SEM_SEARCH SEM_CATEGORIES SEM_RESET'));
             break;
         case "print_myevents":
             $navioben = explode(" ", MatukioHelperSettings::getSettings('frontend_topnavoffermodules', 'SEM_NUMBER SEM_SEARCH SEM_CATEGORIES SEM_RESET'));
             break;
         case "print_teilnehmerliste":
             $navioben = "";
             break;
     }
     if ($todo != "print_teilnehmerliste" && $todo != "csvlist" && $todo != "certificate" && $todo != "invoice") {
         if (in_array('SEM_TYPES', $navioben)) {
             switch ($dateid) {
                 case "1":
                     $where[] = "a.end > '{$neudatum}'";
                     break;
                 case "2":
                     $where[] = "a.end <= '{$neudatum}'";
                     break;
             }
         }
     }
     switch ($todo) {
         default:
         case "print_eventlist":
             if (!in_array('SEM_TYPES', $navioben)) {
                 $where[] = "r.end > '{$neudatum}'";
             }
             if ((isset($_GET["catid"]) or in_array('SEM_CATEGORIES', $navioben)) and $catid > 0) {
                 $where[] = "a.catid ='{$catid}'";
             }
             $headertext = JTEXT::_('COM_MATUKIO_EVENTS');
             if ($cid) {
                 $where[] = "r.id= '{$cid}'";
                 $headertext = JTEXT::_('COM_MATUKIO_EVENT');
             }
             $database->setQuery("SELECT a.*, r.*, cc.title AS category FROM #__matukio_recurring AS r" . "\nLEFT JOIN #__matukio AS a ON r.event_id = a.id" . "\nLEFT JOIN #__categories AS cc ON cc.id = a.catid" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nAND (r.semnum LIKE'%{$search}%' OR a.teacher LIKE '%{$search}%' OR a.title LIKE '%{$search}%'" . " OR a.shortdesc LIKE '%{$search}%' OR a.description LIKE '%{$search}%')");
             $rows = $database->loadObjectList();
             // Abzug der Kurse, die wegen Ausbuchung nicht angezeigt werden sollen
             if (!$cid) {
                 $abid = array();
                 foreach ($rows as $row) {
                     if ($row->stopbooking == 2) {
                         $gebucht = MatukioHelperUtilsEvents::calculateBookedPlaces($row);
                         if ($row->maxpupil - $gebucht->booked < 1) {
                             $abid[] = $row->id;
                         }
                     }
                 }
                 if (count($abid) > 0) {
                     $abid = implode(',', $abid);
                     $where[] = "r.id NOT IN ({$abid})";
                 }
             }
             $database->setQuery("SELECT a.*, r.*, cc.title AS category FROM #__matukio_recurring AS r" . "\nLEFT JOIN #__matukio AS a ON r.event_id = a.id" . "\nLEFT JOIN #__categories AS cc" . "\nON cc.id = a.catid" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nAND (a.semnum LIKE'%{$search}%' OR a.teacher LIKE '%{$search}%' OR a.title LIKE '%{$search}%' OR a.shortdesc LIKE '%{$search}%' OR a.description LIKE '%{$search}%')" . "\nORDER BY r.begin" . $ttlimit);
             $rows = $database->loadObjectList();
             $status = array();
             $paid = array();
             $abid = array();
             for ($i = 0, $n = count($rows); $i < $n; $i++) {
                 $row =& $rows[$i];
                 $gebucht = MatukioHelperUtilsEvents::calculateBookedPlaces($row);
                 $gebucht = $gebucht->booked;
                 if (MatukioHelperUtilsDate::getCurrentDate() > $row->booked or $row->maxpupil - $gebucht < 1 and $row->stopbooking == 1 or $my->id == $row->publisher and MatukioHelperSettings::getSettings('booking_ownevents', 1) == 0) {
                     $status[$i] = JTEXT::_('COM_MATUKIO_UNBOOKABLE');
                 } elseif ($row->maxpupil - $gebucht < 1 && $row->stopbooking == 0) {
                     $status[$i] = JTEXT::_('COM_MATUKIO_BOOKING_ON_WAITLIST');
                 } elseif ($row->maxpupil - $gebucht < 1 && $row->stopbooking == 2) {
                     $abid[] = $row->id;
                 } else {
                     $status[$i] = JTEXT::_('COM_MATUKIO_NOT_EXCEEDED');
                 }
                 $database->setQuery("SELECT * FROM #__matukio_bookings WHERE semid='{$row->id}' AND userid='{$my->id}'");
                 $temp = $database->loadObjectList();
                 if (count($temp) > 0) {
                     $status[$i] = JTEXT::_('COM_MATUKIO_ALREADY_BOOKED');
                     if ($temp[0]->paid == 1) {
                         $rows[$i]->fees = $rows[$i]->fees . " - " . JTEXT::_('COM_MATUKIO_PAID');
                     }
                 }
                 $rows[$i]->codepic = "";
             }
             break;
             // My bookings ?!
         // My bookings ?!
         case "print_booking":
             $headertext = JTEXT::_('COM_MATUKIO_MY_BOOKINGS') . " - " . $my->name;
             if (in_array('SEM_CATEGORIES', $navioben) and $catid > 0) {
                 $where[] = "a.catid ='{$catid}'";
             }
             $where[] = "cc.userid = '" . $my->id . "'";
             if ($cid) {
                 $where[] = "cc.semid = '" . $cid . "'";
                 $headertext = JTEXT::_('COM_MATUKIO_BOOKING_CONFIRMATION') . " - " . $my->name;
             }
             $database->setQuery("SELECT a.*, r.*, cat.title AS category, cc.bookingdate AS bookingdate, cc.id AS bookid, cc.status AS bookingstatus\r\n\t\t\t\t\tFROM #__matukio_recurring AS r\r\n\t\t\t\t\tLEFT JOIN #__matukio AS a ON r.event_id = a.id\r\n\t\t\t\t\tLEFT JOIN #__matukio_bookings AS cc ON cc.semid = r.id\r\n\t\t\t\t\tLEFT JOIN #__categories AS cat ON cat.id = a.catid" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nAND (r.semnum LIKE'%{$search}%' OR a.teacher LIKE '%{$search}%' OR a.title LIKE '%{$search}%' OR a.shortdesc LIKE '%{$search}%'\r\n                        OR a.description LIKE '%{$search}%')" . "\nORDER BY r.begin" . $ttlimit);
             $rows = $database->loadObjectList();
             $status = array();
             for ($i = 0, $n = count($rows); $i < $n; $i++) {
                 $row =& $rows[$i];
                 $database->setQuery("SELECT * FROM #__matukio_bookings WHERE semid = '{$row->id}' ORDER BY id");
                 $temps = $database->loadObjectList();
                 $status[$i] = MatukioHelperUtilsBooking::getBookingStatusName($row->bookingstatus);
                 $rows[$i]->codepic = $row->bookid;
                 if ($temps[0]->paid == 1) {
                     $rows[$i]->fees = $rows[$i]->fees . " - " . JTEXT::_('COM_MATUKIO_PAID');
                 }
             }
             break;
             // My events ?!
         // My events ?!
         case "print_myevents":
             if (in_array('SEM_CATEGORIES', $navioben) and $catid > 0) {
                 $where[] = "a.catid ='{$catid}'";
             }
             $where[] = "a.publisher = '" . $my->id . "'";
             $database->setQuery("SELECT a.*, r.* cat.title AS category FROM #__matukio_recurring AS r\r\n\t\t\t \t    LEFT JOIN #__matukio AS a ON r.eventid = a.id\r\n\t\t\t\t\tLEFT JOIN #__categories AS cat ON cat.id = a.catid" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nAND (r.semnum LIKE'%{$search}%' OR a.teacher LIKE '%{$search}%' OR a.title LIKE '%{$search}%' OR a.shortdesc LIKE '%{$search}%' OR a.description LIKE '%{$search}%')" . "\nORDER BY r.begin" . $ttlimit);
             $rows = $database->loadObjectList();
             $status = array();
             $headertext = JTEXT::_('COM_MATUKIO_MY_OFFERS') . " - " . $my->name;
             for ($i = 0, $n = count($rows); $i < $n; $i++) {
                 $row =& $rows[$i];
                 $status[$i] = MatukioHelperUtilsBooking::getBookingStatusName($row->bookingstatus);
                 $rows[$i]->codepic = "";
             }
             break;
         case "print_teilnehmerliste":
             // TODO implement userchecking
             $art = JFactory::getApplication()->input->getInt('art', 0);
             $this->art = $art;
             if ($art == 1) {
                 $this->setLayout("signaturelist");
             } else {
                 $this->setLayout("participants");
             }
             break;
         case "csvlist":
             // TODO implement userchecking
             $art = JFactory::getApplication()->input->getInt('art', 0);
             $this->art = $art;
             $this->cid = $cid;
             $this->setLayout("csv");
             break;
         case "certificate":
             // TODO implement userchecking
             $art = JFactory::getApplication()->input->getInt('art', 0);
             $uid = JFactory::getApplication()->input->getInt('uid', 0);
             $this->art = $art;
             $this->uid = $uid;
             $this->setLayout("certificate");
             break;
         case "invoice":
             // TODO implement userchecking
             $art = JFactory::getApplication()->input->getInt('art', 0);
             $uid = JFactory::getApplication()->input->getInt('uid', 0);
             $this->art = $art;
             $this->uid = $uid;
             $this->setLayout("invoice");
             break;
     }
     $this->rows = $rows;
     $this->status = $status;
     $this->headertext = $headertext;
     parent::display($tpl);
 }
    echo '<label for="conf_payment_total" width="100" title="' . JText::_("COM_MATUKIO_TOTAL_AMOUNT") . '">';
    echo JText::_("COM_MATUKIO_TOTAL_AMOUNT");
    echo '</label>';
    echo '</td>';
    echo "<td>";
    echo "<div id=\"conf_payment_total\"></div>";
    echo "</tr>";
    echo "</td>";
    echo "</table>";
}
// AGB
echo "<br />";
$agb = MatukioHelperSettings::getSettings("agb_text", "");
if (!empty($agb)) {
    $link = JURI::ROOT() . "index.php?tmpl=component&s=" . MatukioHelperUtilsBasic::getRandomChar() . "&option=" . JFactory::getApplication()->input->get('option') . "&view=agb";
    echo MatukioHelperUtilsBooking::getCheckbox("agb", " ", false);
    echo "<a href=\"" . $link . "\" class=\"modal cjmodal\" rel=\"{handler: 'iframe', size: {x:700, y:500}}\">";
    echo JTEXT::_('COM_MATUKIO_TERMS_AND_CONDITIONS');
    echo "</a>";
}
?>
	</div>
	<div id="mat_control">
		<div id="mat_control_inner">
			<button id="btn_back" class="mat_button"><?php 
echo JTEXT::_("COM_MATUKIO_BACK");
?>
</button>
			<button id="btn_next" class="mat_button"><?php 
echo JTEXT::_("COM_MATUKIO_NEXT");
?>
    echo $invoice_image;
    ?>
				</td>
				<td>
					<?php 
    echo $l->comment;
    ?>
				</td>
				<td style="text-align: center">
					<?php 
    echo $bstatus;
    ?>
				</td>
				<td>
					<?php 
    echo MatukioHelperUtilsBooking::getBookingId($l->id) . " (" . $l->id . ")";
    ?>
				</td>
			</tr>
			<?php 
    $i++;
}
?>

	</table>
	</div>
	</div>
	<table>
		</tbody>
		<tfoot>
		<tr>
 /**
  * Generates the csv booking details
  *
  * @param   object  $booking    - The booking
  * @param   object  $event      - The event
  * @param   string  $separator  - The separator
  *
  * @return  string
  */
 public static function getExportCSVBookingDetails($booking, $event, $separator = ";")
 {
     $html = "";
     $html .= "'" . $booking->nrbooked . "';";
     if (MatukioHelperSettings::getSettings('oldbookingform', 0) == 1) {
         // Old booking form
         if ($booking->userid < 1) {
             if (isset($booking->aname)) {
                 $html .= "'" . $booking->aname . "';";
             } else {
                 $html .= "'" . $booking->name . "';";
             }
             if (isset($booking->aemail)) {
                 $html .= "'" . $booking->aemail . "';";
             } else {
                 $html .= "'" . $booking->email . "';";
             }
         } else {
             $user = JFactory::getUser($booking->userid);
             $html .= "'" . $user->name . "';";
             $html .= "'" . $user->email . "';";
         }
     } else {
         // New booking form fields
         $fields = MatukioHelperUtilsBooking::getBookingFields();
         $fields = MatukioHelperUtilsBooking::getBookingFields();
         $fieldvals = explode(";", $booking->newfields);
         $value = array();
         foreach ($fieldvals as $val) {
             $tmp = explode("::", $val);
             if (count($tmp) > 1) {
                 $value[$tmp[0]] = $tmp[1];
             } else {
                 $value[$tmp[0]] = "";
             }
         }
         foreach ($fields as $field) {
             if ($field->type != "spacer" && $field->type != "spacertext") {
                 if (!empty($value[$field->id])) {
                     $html .= "'" . str_replace($separator, " ", $value[$field->id]) . "'" . $separator;
                 } else {
                     $html .= "''" . $separator;
                 }
             }
         }
     }
     return $html;
 }
    }
    if ($row->showbooked > 0) {
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_CLOSING_DATE') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell(JHTML::_('date', $row->booked), 'd', 'l', '', 'sem_list_row') . "</tr>";
    }
    if ($row->teacher != "") {
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_TUTOR') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell($row->teacher, 'd', 'l', '', 'sem_list_row') . "</tr>";
    }
    if ($row->target != "") {
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_TARGET_GROUP') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell($row->target, 'd', 'l', '', 'sem_list_row') . "</tr>";
    }
    $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_CITY') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell($row->place, 'd', 'l', '', 'sem_list_row') . "</tr>";
    if ($row->nrbooked > 0) {
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_MAX_PARTICIPANT') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell($row->maxpupil, 'd', 'l', '', 'sem_list_row') . "</tr>";
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_BOOKINGS') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell($gebucht, 'd', 'l', '', 'sem_list_row') . "</tr>";
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_BOOKABLE') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell($freieplaetze, 'd', 'l', '', 'sem_list_row') . "</tr>";
    }
    if ($row->fees > 0) {
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_FEES') . ":", 'd', 'l', '', 'sem_list_row') . MatukioHelperUtilsEvents::getTableCell(MatukioHelperSettings::getSettings('currency_symbol', '$') . " " . $row->fees, 'd', 'l', '', 'sem_list_row') . "</tr>";
    }
    if ($row->description != "") {
        $row->description = str_replace("images/", "../images/", $row->description);
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(MatukioHelperUtilsEvents::getCleanedMailText($row->description), 'd', 'l', '100%', 'sem_list_row', 2) . "</tr>";
    }
    if ($row->codepic != "") {
        $html .= "<tr>" . MatukioHelperUtilsEvents::getTableCell(MatukioHelperUtilsBooking::getBookingIdCodePicture($row->codepic), 'd', 'c', '100%', 'sem_list_row', 2) . "</tr>";
    }
    $html .= "\n</table><br />";
}
$html .= MatukioHelperUtilsBasic::getCopyright();
$html .= "</div></body></html>";
echo $html;
$html .= "\n<title>" . $mainconfig->get('config.sitename') . " - " . JTEXT::_('COM_MATUKIO_EVENTS') . "</title>";
$html .= "\n<link>" . JURI::root() . "index.php?tmpl=component&amp;option=" . JFactory::getApplication()->input->get('option') . "&amp;view=eventlist</link>";
$html .= "\n<description>" . $mainconfig->get('config.sitename') . " - Events" . "</description>";
$html .= "\n<language>" . $sprache->getTag() . "</language>";
$html .= "\n<copyright>" . $mainconfig->get('config.fromname') . "</copyright>";
$html .= "\n<ttl>60</ttl>";
$html .= "\n<pubDate>" . date("r") . "</pubDate>";
foreach ($this->rows as $row) {
    $user = JFactory::getuser($row->publisher);
    $cancelled = "";
    if ($row->cancelled == 1) {
        $cancelled = " - " . JTEXT::_('COM_MATUKIO_CANCELLED');
    }
    $html .= "\n<item>";
    $html .= "\n<title>" . $row->title . $cancelled . "</title>";
    $html .= "\n<description>" . JTEXT::_('COM_MATUKIO_BEGIN') . ": " . JHTML::_('date', $row->begin, MatukioHelperSettings::getSettings('date_format_small', 'd-m-Y, H:i')) . " - " . $row->shortdesc . "</description>";
    $eventid_l = $row->id . ':' . JFilterOutput::stringURLSafe($row->title);
    $catid_l = $row->catid . ':' . JFilterOutput::stringURLSafe(MatukioHelperCategories::getCategoryAlias($row->catid));
    $link = JRoute::_(MatukioHelperRoute::getEventRoute($eventid_l, $catid_l), true, 2);
    $html .= "\n<link>" . $link . "</link>";
    if (MatukioHelperSettings::getSettings('frontend_showownerdetails', 1) > 0) {
        $html .= "\n<author>" . $user->name . ", " . $user->email . "</author>";
    }
    $html .= "\n<guid>" . MatukioHelperUtilsBooking::getBookingId($row->id) . "</guid>";
    $html .= "\n<category>" . $row->category . "</category>";
    $html .= "\n<pubDate>" . date("r", strtotime($row->publishdate)) . "</pubDate>";
    $html .= "\n</item>";
}
$html .= "\n</channel>";
$html .= "\n</rss>";
echo $html;
 /**
  * Saves the form
  *
  * @throws  Exception
  * @return  object
  */
 public function save()
 {
     $input = JFactory::getApplication()->input;
     if ($input->getInt("oldform", 0) == 1) {
         $this->saveOld();
         return;
     }
     $database = JFactory::getDBO();
     $dispatcher = JDispatcher::getInstance();
     // Backend
     $art = 4;
     $event_id = $input->getInt('event_id', 0);
     $uid = $input->getInt('uid', 0);
     $userid = $input->getInt('userid', 0);
     $id = $input->getInt("id", 0);
     $notify_participant = $input->getInt("notify_participant", 0);
     $notify_participant_invoice = $input->getInt("notify_participant_invoice", 0);
     $payment_method = $input->get('payment', '', 'string');
     if (empty($event_id)) {
         JError::raiseError(404, 'COM_MATUKIO_NO_ID');
     }
     // Load event (use events helper function)
     $event = MatukioHelperUtilsEvents::getEventRecurring($event_id);
     // Different fees @since 3.0
     $different_fees = $event->different_fees;
     $reason = "";
     if (!empty($uid)) {
         if ($uid < 0) {
             // Setting booking to changed booking
             $userid = $uid;
             // uid = Negativ
         }
     }
     // Checking old required fields - backward compatibilty - only frontend - we allow everything here..
     if ($art == 4) {
         $allesok = 1;
         $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_SUCCESSFULL');
     }
     // Buchung eintragen
     $neu = JTable::getInstance('bookings', 'Table');
     if (!$neu->bind(JRequest::get('post'))) {
         return JError::raiseError(500, $database->stderr());
     }
     $neu->semid = $event->id;
     $neu->userid = $userid;
     $firstname = $input->get('firstname', '', 'string');
     $lastname = $input->get('lastname', '', 'string');
     if (empty($id)) {
         $neu->bookingdate = MatukioHelperUtilsDate::getCurrentDate();
     }
     $neu->name = trim($firstname . " " . $lastname);
     $neu->email = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->email);
     $neu->zusatz1 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz1);
     $neu->zusatz2 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz2);
     $neu->zusatz3 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz3);
     $neu->zusatz4 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz4);
     $neu->zusatz5 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz5);
     $neu->zusatz6 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz6);
     $neu->zusatz7 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz7);
     $neu->zusatz8 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz8);
     $neu->zusatz9 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz9);
     $neu->zusatz10 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz10);
     $neu->zusatz11 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz11);
     $neu->zusatz12 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz12);
     $neu->zusatz13 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz13);
     $neu->zusatz14 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz14);
     $neu->zusatz15 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz15);
     $neu->zusatz16 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz16);
     $neu->zusatz17 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz17);
     $neu->zusatz18 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz18);
     $neu->zusatz19 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz19);
     $neu->zusatz20 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz20);
     $fields = MatukioHelperUtilsBooking::getBookingFields();
     if (!empty($fields)) {
         $newfields = "";
         for ($i = 0; $i < count($fields); $i++) {
             $field = $fields[$i];
             $name = $field->field_name;
             $newfields .= $field->id;
             $newfields .= "::";
             $newfields .= $input->get($name, '', 'string');
             $newfields .= ";";
         }
         $neu->newfields = $newfields;
         if (!empty($event->fees)) {
             $neu->payment_method = $payment_method;
             if ($different_fees == 0) {
                 $payment_brutto = $event->fees * $neu->nrbooked;
                 $coupon_code = $neu->coupon_code;
                 if (!empty($coupon_code)) {
                     $cdate = new DateTime();
                     $db = JFactory::getDBO();
                     $query = $db->getQuery(true);
                     $query->select('*')->from('#__matukio_booking_coupons')->where('code = ' . $db->quote($coupon_code));
                     $db->setQuery($query);
                     $coupon = $db->loadObject();
                     if (!empty($coupon)) {
                         if ($coupon->procent == 1) {
                             // Get a procent value
                             $payment_brutto = round($payment_brutto * ((100 - $coupon->value) / 100), 2);
                         } else {
                             $payment_brutto = $payment_brutto - $coupon->value;
                         }
                     } else {
                         // Raise an error
                         JError::raise(E_ERROR, 500, JText::_("COM_MATUKIO_INVALID_COUPON_CODE"));
                     }
                 }
                 $neu->payment_brutto = $payment_brutto;
             } else {
                 // Different fees @since 3.0
                 $payment_brutto = MatukioHelperFees::getPaymentTotal($event);
                 $neu->payment_brutto = $payment_brutto;
                 $difarray = array("places" => $input->get("places", array(), 'Array'), "types" => $input->get("ticket_fees", array(), 'Array'));
                 $neu->different_fees = json_encode($difarray);
             }
             // Taxes
             if ($neu->payment_brutto > 0) {
                 // Lets check if there are any
                 if ($event->tax_id == 0) {
                     // No taxes
                     $neu->payment_netto = $neu->payment_brutto;
                     $neu->payment_tax = 0.0;
                 } else {
                     $db = JFactory::getDbo();
                     $query = $db->getQuery(true);
                     $query->select("*")->from("#__matukio_taxes")->where("id = " . $db->quote($event->tax_id) . " AND published = 1");
                     $db->setQuery($query);
                     $tax = $db->loadObject();
                     if (empty($tax)) {
                         // Houston we have a problem
                         throw new Exception("Invalid tax value! Please select the correct tax in the event edit form.");
                     } else {
                         // Calculate netto
                         $minfac = 100 / (100 + $tax->value);
                         $neu->payment_netto = $neu->payment_brutto * $minfac;
                         $neu->payment_tax = $neu->payment_brutto - $neu->payment_netto;
                     }
                 }
             }
         }
     }
     $results = $dispatcher->trigger('onBeforeSaveBooking', $neu, $event);
     if (!$neu->check()) {
         return JError::raiseError(500, $database->stderr());
     }
     if (!$neu->store()) {
         return JError::raiseError(500, $database->stderr());
     }
     $neu->checkin();
     $results = $dispatcher->trigger('onAfterBooking', $neu, $event);
     $ueber1 = JText::_("COM_MATUKIO_BOOKING_WAS_SUCCESSFULL");
     if ($userid == 0) {
         $userid = $neu->id * -1;
     }
     // Send new confirmation mail
     if ($notify_participant) {
         MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $neu->id, 11, false, $neu, $notify_participant_invoice);
     }
     switch ($this->task) {
         case 'apply':
             $msg = JText::_('COM_MATUKIO_BOOKING_APPLY');
             $link = 'index.php?option=com_matukio&controller=editbooking&task=editBooking&booking_id=' . $neu->id;
             break;
         case 'save':
         default:
             $msg = JText::_('COM_MATUKIO_BOOKING_SAVE');
             $link = 'index.php?option=com_matukio&view=bookings';
             break;
     }
     $this->setRedirect($link, $msg);
 }
    $html .= "\n<tr>" . MatukioHelperUtilsEvents::getTableCell(JText::_('COM_MATUKIO_NAME') . ':', 'd', 'l', '20%', 'sem_rowd') . MatukioHelperUtilsEvents::getTableCell($nametemp, 'd', 'l', '80%', 'sem_rowd') . "</tr>";
}
$html .= "\n<tr>" . MatukioHelperUtilsEvents::getTableCell(JText::_('COM_MATUKIO_TITLE') . ':', 'd', 'l', '20%', 'sem_rowd') . MatukioHelperUtilsEvents::getTableCell(JText::_($this->event->title), 'd', 'l', '80%', 'sem_rowd') . "</tr>";
// Veranstaltungsnummer anzeigen
if ($this->event->semnum != "") {
    $html .= "\n<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_NUMBER') . ':', 'd', 'l', '20%', 'sem_rowd') . MatukioHelperUtilsEvents::getTableCell($this->event->semnum, 'd', 'l', '80%', 'sem_rowd') . "</tr>";
}
// Status anzeigen
$htxt = $buchopt[1];
if ($this->event->nrbooked < 1) {
    $htxt = JTEXT::_('COM_MATUKIO_CANNOT_BOOK_ONLINE');
}
$html .= "\n<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_STATUS') . ':', 'd', 'l', '20%', 'sem_rowd') . MatukioHelperUtilsEvents::getTableCell($htxt, 'd', 'l', '80%', 'sem_rowd') . "</tr>";
// Buchungs-ID anzeigen
if (count($buchopt[2]) > 0) {
    $html .= "\n<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_BOOKING_ID') . ':', 'd', 'l', '20%', 'sem_rowd') . MatukioHelperUtilsEvents::getTableCell(MatukioHelperUtilsBooking::getBookingId($buchopt[2][0]->id), 'd', 'l', '80%', 'sem_rowd') . "</tr>";
}
// Falls abgesagt Formatierung aendern
$htx1 = "";
$htx2 = "";
if ($this->event->cancelled == 1) {
    $htx1 = "\n<span class=\"sem_cancelled\">" . JTEXT::_('COM_MATUKIO_CANCELLED') . " </span>(<del>";
    $htx2 = "</del>)";
}
// Beginn anzeigen
if ($this->event->showbegin > 0) {
    $html .= "\n<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_BEGIN') . ':', 'd', 'l', '20%', 'sem_rowd') . MatukioHelperUtilsEvents::getTableCell($htx1 . JHTML::_('date', $this->event->begin, MatukioHelperSettings::getSettings('date_format', 'd-m-Y, H:i')) . MatukioHelperUtilsDate::getTimezone($this->event->begin) . $htx2, 'd', 'l', '80%', 'sem_rowd') . "</tr>";
}
// Ende anzeigen
if ($this->event->showend > 0) {
    $html .= "\n<tr>" . MatukioHelperUtilsEvents::getTableCell(JTEXT::_('COM_MATUKIO_END') . ':', 'd', 'l', '20%', 'sem_rowd') . MatukioHelperUtilsEvents::getTableCell($htx1 . JHTML::_('date', $this->event->end, MatukioHelperSettings::getSettings('date_format', 'd-m-Y, H:i')) . MatukioHelperUtilsDate::getTimezone($this->event->end) . $htx2, 'd', 'l', '80%', 'sem_rowd') . "</tr>";
 /**
  * Displays the event form
  *
  * @param   string  $tpl  - The template
  *
  * @throws  Exception
  * @return  void
  */
 public function display($tpl = null)
 {
     $input = JFactory::getApplication()->input;
     $model = $this->getModel();
     $art = $input->getInt('art', 0);
     $database = JFactory::getDBO();
     $dateid = $input->getInt('dateid', 1);
     // Event id
     $cid = $input->getInt('id', 0);
     // Booking id!!
     $uid = $input->getInt('uid', 0);
     $uuid = $input->get('uuid', '');
     $dispatcher = JDispatcher::getInstance();
     $booking = "";
     $user = JFactory::getUser();
     if ($art == 1) {
         // Updated 2.2.4 to show the cancel booking button if logged in!
         $booking = MatukioHelperUtilsBooking::getBooking($uid, $cid);
     }
     // Fix if uid / booking not found or booking as not registered user
     if (empty($booking)) {
         $art = 0;
     }
     // Category id
     $catid = $input->getInt('catid', 0);
     $search = $input->get('search', '', 'string');
     $limit = $input->getInt('limit', 5);
     // TODO Pagination should be updated to Joomla Framework
     $limitstart = $input->getInt('limitstart', 0);
     $params = JComponentHelper::getParams('com_matukio');
     $menuitemid = $input->get('Itemid');
     if ($menuitemid) {
         $site = new JSite();
         $menu = $site->getMenu();
         $menuparams = $menu->getParams($menuitemid);
         $params->merge($menuparams);
     }
     $menu_cid = $params->get('eventId', 0);
     if (empty($cid)) {
         if (empty($menu_cid)) {
             JError::raiseError('404', JTEXT::_("COM_MATUKIO_NO_ID"));
         } else {
             $cid = $menu_cid;
         }
     }
     $row = $model->getItem($cid, true);
     if ($art == 3) {
         if ($uid > 0) {
             $database->setQuery("SELECT * FROM #__matukio_bookings WHERE id='" . $uid . "'");
             $temp = $database->loadObjectList();
             $userid = $temp[0]->userid;
             if ($userid == 0) {
                 $uid = $uid * -1;
             } else {
                 $uid = $userid;
             }
         }
     } else {
         if ($uid > 0) {
             $database->setQuery("SELECT * FROM #__matukio_bookings WHERE id='{$uid}'");
             $temp = $database->loadObjectList();
             if ($temp[0]->userid != 0 || $art != 1) {
                 $uid = $temp[0]->userid;
             } else {
                 $uid = $uid * -1;
             }
         }
     }
     if ($art == 0) {
         // Hits erhoehen
         $database->setQuery("UPDATE #__matukio_recurring SET hits=hits+1 WHERE id='{$cid}'");
         if (!$database->execute()) {
             throw new Exception("COM_MATUKIO_ERROR_ADDING_HIT" . ":" . $row->getError());
         }
         // Ausgabe des Kurses
         // MatukioHelperUtilsBasic::expandPathway(JTEXT::_('COM_MATUKIO_EVENTS'), JRoute::_("index.php?option=com_matukio"));
     } elseif ($art == 1 or $art == 2) {
         if ($user->id > 0) {
             MatukioHelperUtilsBasic::expandPathway(JTEXT::_('COM_MATUKIO_MY_BOOKINGS'), JRoute::_("index.php?option=com_matukio&view=eventlist&art=1"));
         }
     } else {
         MatukioHelperUtilsBasic::expandPathway(JTEXT::_('COM_MATUKIO_MY_OFFERS'), JRoute::_("index.php?option=com_matukio&view=eventlist&art=2"));
     }
     // Add category link to breadcrumb
     MatukioHelperUtilsBasic::expandPathway($row->category, JRoute::_("index.php?option=com_matukio&view=eventlist&art=" . $art . "&catid=" . $row->catid . ":" . JFilterOutput::stringURLSafe($row->category)));
     // Add event to breadcrumb
     MatukioHelperUtilsBasic::expandPathway($row->title, "");
     $ueberschrift = array(JTEXT::_('COM_MATUKIO_DESCRIPTION'), $row->shortdesc);
     if (empty($row)) {
         JError::raiseError('404', JTEXT::_("COM_MATUKIO_NO_ID"));
         return;
     }
     $locobj = null;
     if ($row->place_id > 0) {
         $locobj = MatukioHelperUtilsEvents::getLocation($row->place_id);
     }
     $title = JFactory::getDocument()->getTitle();
     JFactory::getDocument()->setTitle($title . " - " . JText::_($row->title));
     JPluginHelper::importPlugin('content');
     $this->jevent = new stdClass();
     $results = $dispatcher->trigger('onContentAfterDisplay', array('com_matukio.event', &$row, &$params, 0));
     $this->jevent->afterDisplayContent = trim(implode("\n", $results));
     $this->id = $cid;
     $this->art = $art;
     $this->event = $row;
     $this->uid = $uid;
     $this->uuid = $uuid;
     $this->search = $search;
     $this->catid = $catid;
     $this->limit = $limit;
     $this->limitstart = $limitstart;
     $this->dateid = $dateid;
     $this->ueberschrift = $ueberschrift;
     $this->booking = $booking;
     $this->user = $user;
     $this->location = $locobj;
     parent::display($tpl);
 }
				<td align="left" class="key">
					<?php 
    echo JText::_('COM_MATUKIO_EMAIL');
    ?>
:
				</td>
				<td>
					<input type="text" class="sem_inputbox" id="email" name="email" value="" size="20"/>
				</td>
			</tr>
		<?php 
} else {
    $fields = MatukioHelperUtilsBooking::getBookingFields();
    foreach ($fields as $field) {
        if ($field->type != 'spacer') {
            MatukioHelperUtilsBooking::printFieldElement($field, false, -1, "small");
        }
    }
    ?>
		<?php 
}
?>
		<tr>
			<td colspan="2">
				<div align="right">
					<input type="submit" value="<?php 
echo JText::_("COM_MATUKIO_BOOK");
?>
" class="mmat_button"/>
				</div>
			</td>
		<tr>
			<td class="key">
				<?php 
    echo JText::_('COM_MATUKIO_EMAIL');
    ?>
			</td>
			<td>
				<?php 
    echo $this->booking->email;
    ?>
			</td>
		</tr>
	<?php 
} else {
    // New booking form..
    $fields = MatukioHelperUtilsBooking::getBookingFields();
    $fieldvals = explode(";", $this->booking->newfields);
    $value = array();
    foreach ($fieldvals as $val) {
        $tmp = explode("::", $val);
        if (count($tmp) > 1) {
            $value[$tmp[0]] = $tmp[1];
        } else {
            $value[$tmp[0]] = "";
        }
    }
    foreach ($fields as $field) {
        // Not use the Spacer fields
        if ($field->type != "spacer" && $field->type != "spacertext") {
            echo "<tr>";
            echo "<td class=\"key\" width=\"150px\">" . JText::_($field->label) . "</td>";
 /**
  * Publishs / unpublish the booking
  *
  * @return  void
  */
 public function publish()
 {
     $cid = JFactory::getApplication()->input->get('cid', array(), 'array');
     if ($this->task == 'publish') {
         $status = MatukioHelperUtilsBooking::$ACTIVE;
     } else {
         $status = MatukioHelperUtilsBooking::$PENDING;
     }
     MatukioHelperUtilsBooking::changeStatusBooking($cid, $status, true);
     $msg = "";
     $link = 'index.php?option=com_matukio&view=bookings';
     $this->setRedirect($link, $msg);
 }
 /**
  * Save the booking
  *
  * @todo    Change and Update to a function (mixing backend and frontend!!!)
  * @return  object
  */
 public function save()
 {
     // Check authorization
     if (!JFactory::getUser()->authorise('core.edit', 'com_matukio')) {
         return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
     }
     $database = JFactory::getDBO();
     $input = JFactory::getApplication()->input;
     $art = 4;
     $event_id = $input->getInt('event_id', 0);
     $uid = $input->getInt('uid', 0);
     $uuid = $input->getInt('uuid', 0);
     $nrbooked = $input->getInt('nrbooked', 1);
     $userid = $input->getInt('userid', 0);
     $payment_method = $input->get('payment', '', 'string');
     $notify_participant = $input->getInt("notify_participant", 0);
     $notify_participant_invoice = $input->getInt("notify_participant_invoice", 0);
     if (empty($event_id)) {
         return JError::raiseError(404, 'COM_MATUKIO_NO_ID');
     }
     // Load event (use model function)
     $emodel = JModelLegacy::getInstance('Event', 'MatukioModel');
     $event = $emodel->getItem($event_id);
     $reason = "";
     if (!empty($uid)) {
         // Setting booking to changed booking
         $userid = $uid;
         // uid = Negativ
         $art = 4;
     }
     if ($art == 4) {
         $allesok = 1;
         $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_SUCCESSFULL');
     }
     // Buchung eintragen
     $neu = JTable::getInstance('bookings', 'Table');
     if (!$neu->bind(JRequest::get('post'))) {
         return JError::raiseError(500, $database->stderr());
     }
     $neu->semid = $event->id;
     $neu->userid = $userid;
     $firstname = $input->get('firstname', '', 'string');
     $lastname = $input->get('lastname', '', 'string');
     $neu->bookingdate = MatukioHelperUtilsDate::getCurrentDate();
     $neu->name = MatukioHelperUtilsBasic::cleanHTMLfromText($firstname . " " . $lastname);
     $neu->email = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->email);
     $neu->zusatz1 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz1);
     $neu->zusatz2 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz2);
     $neu->zusatz3 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz3);
     $neu->zusatz4 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz4);
     $neu->zusatz5 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz5);
     $neu->zusatz6 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz6);
     $neu->zusatz7 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz7);
     $neu->zusatz8 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz8);
     $neu->zusatz9 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz9);
     $neu->zusatz10 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz10);
     $neu->zusatz11 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz11);
     $neu->zusatz12 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz12);
     $neu->zusatz13 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz13);
     $neu->zusatz14 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz14);
     $neu->zusatz15 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz15);
     $neu->zusatz16 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz16);
     $neu->zusatz17 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz17);
     $neu->zusatz18 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz18);
     $neu->zusatz19 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz19);
     $neu->zusatz20 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz20);
     if (empty($neu->uuid)) {
         $neu->uuid = MatukioHelperPayment::getUuid(true);
     }
     $fields = MatukioHelperUtilsBooking::getBookingFields();
     if (!empty($fields)) {
         $newfields = "";
         for ($i = 0; $i < count($fields); $i++) {
             $field = $fields[$i];
             $name = $field->field_name;
             $newfields .= $field->id;
             $newfields .= "::";
             $newfields .= $input->get($name, '', 'string');
             $newfields .= ";";
         }
         $neu->newfields = $newfields;
         if (!empty($event->fees)) {
             $neu->payment_method = $payment_method;
             $payment_brutto = $event->fees * $neu->nrbooked;
             $coupon_code = $neu->coupon_code;
             if (!empty($coupon_code)) {
                 $cdate = new DateTime();
                 $db = JFactory::getDBO();
                 $query = $db->getQuery(true);
                 $query->select('*')->from('#__matukio_booking_coupons')->where('code = ' . $db->quote($coupon_code) . ' AND published = 1 AND published_up < ' . $db->quote($cdate->format('Y-m-d H:i:s')) . " AND published_down > " . $db->quote($cdate->format('Y-m-d H:i:s')));
                 $db->setQuery($query);
                 $coupon = $db->loadObject();
                 if (!empty($coupon)) {
                     if ($coupon->procent == 1) {
                         // Get a procent value
                         $payment_brutto = round($payment_brutto * ((100 - $coupon->value) / 100), 2);
                     } else {
                         $payment_brutto = $payment_brutto - $coupon->value;
                     }
                 } else {
                     // Raise an error
                     JError::raise(E_ERROR, 500, JText::_("COM_MATUKIO_INVALID_COUPON_CODE"));
                 }
             }
             $neu->payment_brutto = $payment_brutto;
         }
     }
     if (!$neu->check()) {
         return JError::raiseError(500, $database->stderr());
     }
     if (!$neu->store()) {
         return JError::raiseError(500, $database->stderr());
     }
     $neu->checkin();
     $ueber1 = JText::_("COM_MATUKIO_BOOKING_WAS_SUCCESSFULL");
     if ($userid == 0) {
         $userid = $neu->id * -1;
     }
     // Send new confirmation mail
     if ($notify_participant) {
         MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $neu->id, 11, false, $neu, $notify_participant_invoice);
     }
     $viewteilnehmerlink = JRoute::_("index.php?option=com_matukio&view=participants&cid=" . $event->id . "&art=2");
     $msg = JText::_("COM_MATUKIO_BOOKING_EDITED");
     $this->setRedirect($viewteilnehmerlink, $msg);
 }
echo $this->success_url;
?>
"/>

	<input type="hidden" name="custom"
	       value="<?php 
echo MatukioHelperUtilsBooking::getBookingId($this->booking->id);
?>
"/>

	<input type="hidden" name="item_number" value="<?php 
echo $this->item_number;
?>
"/>
	<input type="hidden" name="item_name" value="<?php 
echo $this->event->title . ' - [' . MatukioHelperUtilsBooking::getBookingId($this->booking->id) . ']';
?>
"/>

	<input type="hidden" name="currency_code" value="<?php 
echo $this->currency;
?>
"/>

	<?php 
if (!empty($this->tax_amount)) {
    ?>
  */ ?>
		<input type="hidden" name="amount" value="<?php 
    echo $this->net_amount;
    ?>
 /**
  * NEW Booking method for old and new form
  *
  * @throws  Exception - if db query fails
  * @return  mixed
  */
 public function book()
 {
     $payment_brutto = 0;
     $database = JFactory::getDBO();
     $post = JRequest::get('post');
     $my = JFactory::getUser();
     $input = JFactory::getApplication()->input;
     $event_id = $input->getInt('event_id', 0);
     $uid = $input->getInt('uid', 0);
     $steps = $input->getInt('steps', 3);
     $uuid = $input->get('uuid', 0, 'string');
     $id = $input->getInt('id', 0);
     $booking = null;
     if (!empty($id)) {
         // check if there is really such a booking
         $model = JModelLegacy::getInstance('Booking', 'MatukioModel');
         $booking = $model->getBooking($uuid);
         if (empty($booking)) {
             throw new Exception(JText::_("COM_MATUKIO_NO_BOOKING_FOUND"), 404);
         }
         if ($booking->id != $id) {
             throw new Exception(JText::_("COM_MATUKIO_NO_BOOKING_FOUND"), 404);
         }
     }
     $nrbooked = $input->getInt('nrbooked', 1);
     $catid = $input->getInt('catid', 0);
     $payment_method = $input->get('payment', '', 'string');
     $agb = $input->get('agb', '', 'string');
     $isWaitlist = false;
     $dispatcher = JDispatcher::getInstance();
     if (empty($event_id)) {
         throw new Exception(JText::_("COM_MATUKIO_NO_ID"), 404);
     }
     // Load event (use model function)
     $emodel = JModelLegacy::getInstance('Event', 'MatukioModel');
     $event = $emodel->getItem($event_id);
     $userid = $my->id;
     // Different fees @since 3.0
     $different_fees = $event->different_fees;
     $reason = "";
     $art = 2;
     $temp = null;
     $gebucht = MatukioHelperUtilsEvents::calculateBookedPlaces($event);
     $gebucht = $gebucht->booked;
     $allesok = 1;
     $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_SUCCESSFULL');
     $pflichtfeld = false;
     $fields = MatukioHelperUtilsEvents::getAdditionalFieldsFrontend($event);
     // Checking old required fields - backward compatibilty
     for ($i = 0; $i < 20; $i++) {
         $test = $fields[0][$i];
         if (!empty($test)) {
             $res = explode("|", $test);
             if (trim($res[1]) == "1") {
                 $value = $input->get("zusatz" . ($i + 1), '', 'string');
                 if (empty($value)) {
                     $pflichtfeld = true;
                 }
             }
         }
     }
     if (MatukioHelperSettings::getSettings("captcha", 0) == 1) {
         $ccval = $input->get("ccval", '', 'string');
         $captcha = $input->get("captcha", '', 'string');
         if (empty($captcha)) {
             $allesok = 0;
             $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
             $reason = JTEXT::_('COM_MATUKIO_CAPTCHA_WRONG');
         } elseif (md5($captcha) != $ccval) {
             $allesok = 0;
             $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
             $reason = JTEXT::_('COM_MATUKIO_CAPTCHA_WRONG');
         }
     }
     if (MatukioHelperSettings::getSettings("recaptcha", 0) == 1) {
         require_once JPATH_COMPONENT_ADMINISTRATOR . '/include/recaptcha/recaptchalib.php';
         $key = MatukioHelperSettings::getSettings("recaptcha_private_key", "");
         if (empty($key)) {
             throw new Exception("COM_MATUKIO_YOU_HAVE_TO_SET_A_RECAPTCHA_KEY", 500);
         }
         $resp = recaptcha_check_answer($key, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
         if (!$resp->is_valid) {
             // What happens when the CAPTCHA was entered incorrectly
             $allesok = 0;
             $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
             $reason = JTEXT::_('COM_MATUKIO_CAPTCHA_WRONG') . $resp->error;
         }
     }
     $agbtext = MatukioHelperSettings::getSettings("agb_text", "");
     if ($pflichtfeld) {
         $allesok = 0;
         $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
         $reason = JTEXT::_('COM_MATUKIO_REQUIRED_ADDITIONAL_FIELD_EMPTY');
     } elseif (count($temp) > 0) {
         $allesok = 0;
         $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
         $reason = JTEXT::_('COM_MATUKIO_REGISTERED_FOR_THIS_EVENT');
     } elseif (MatukioHelperUtilsDate::getCurrentDate() > $event->booked) {
         echo "current: " . MatukioHelperUtilsDate::getCurrentDate();
         echo " booking: " . $event->booked;
         $allesok = 0;
         $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
         $reason = JTEXT::_('COM_MATUKIO_EXCEEDED');
     } elseif ($event->maxpupil - $gebucht - $nrbooked < 0 && $event->stopbooking == 1) {
         $allesok = 0;
         $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
         $reason = JTEXT::_('COM_MATUKIO_MAX_PARTICIPANT_NUMBER_REACHED');
     } elseif (!empty($agbtext)) {
         // Has to be on the end
         if (empty($agb)) {
             $allesok = 0;
             $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL');
             $reason = JTEXT::_('COM_MATUKIO_AGB_NOT_ACCEPTED');
         }
     }
     if ($event->maxpupil - $gebucht - $nrbooked < 0 && $event->stopbooking == 0) {
         $allesok = 2;
         $ueber1 = JTEXT::_('COM_MATUKIO_ADDED_WAITLIST');
         $reason = JTEXT::_('COM_MATUKIO_YOU_ARE_BOOKED_ON_THE_WAITING_LIST');
         if (empty($booking)) {
             $isWaitlist = true;
         } else {
             // Prevent switching old booking to waitlist
             if ($booking->status == MatukioHelperUtilsBooking::$WAITLIST) {
                 $isWaitlist = true;
             } else {
                 $isWaitlist = false;
             }
         }
     }
     if ($art == 4) {
         $allesok = 1;
         $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_SUCCESSFULL');
     }
     $results = $dispatcher->trigger('onValidateBooking', $post, $event, $allesok);
     // Alles in Ordnung
     if ($allesok > 0) {
         // Buchung eintragen
         $neu = JTable::getInstance('bookings', 'Table');
         if (!$neu->bind($post)) {
             return JError::raiseError(500, $database->stderr());
         }
         $neu->semid = $event->id;
         $neu->userid = $userid;
         $firstname = $input->get('firstname', '', 'string');
         $lastname = $input->get('lastname', '', 'string');
         $neu->bookingdate = MatukioHelperUtilsDate::getCurrentDate();
         $neu->name = MatukioHelperUtilsBasic::cleanHTMLfromText($firstname . " " . $lastname);
         $neu->email = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->email);
         $neu->zusatz1 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz1);
         $neu->zusatz2 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz2);
         $neu->zusatz3 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz3);
         $neu->zusatz4 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz4);
         $neu->zusatz5 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz5);
         $neu->zusatz6 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz6);
         $neu->zusatz7 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz7);
         $neu->zusatz8 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz8);
         $neu->zusatz9 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz9);
         $neu->zusatz10 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz10);
         $neu->zusatz11 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz11);
         $neu->zusatz12 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz12);
         $neu->zusatz13 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz13);
         $neu->zusatz14 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz14);
         $neu->zusatz15 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz15);
         $neu->zusatz16 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz16);
         $neu->zusatz17 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz17);
         $neu->zusatz18 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz18);
         $neu->zusatz19 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz19);
         $neu->zusatz20 = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->zusatz20);
         $fields = MatukioHelperUtilsBooking::getBookingFields();
         if (!empty($fields)) {
             $newfields = "";
             for ($i = 0; $i < count($fields); $i++) {
                 $field = $fields[$i];
                 $name = $field->field_name;
                 $newfields .= $field->id;
                 $newfields .= "::";
                 $newfields .= $input->get($name, '', 'string');
                 $newfields .= ";";
             }
             $neu->newfields = $newfields;
             if (!empty($event->fees) && $steps > 2) {
                 $neu->payment_method = $payment_method;
                 if ($different_fees == 0) {
                     $payment_brutto = $event->fees * $neu->nrbooked;
                     $coupon_code = $neu->coupon_code;
                     if (!empty($coupon_code)) {
                         $cdate = new DateTime();
                         $db = JFactory::getDBO();
                         $query = $db->getQuery(true);
                         $query->select('*')->from('#__matukio_booking_coupons')->where('code = ' . $db->quote($coupon_code) . ' AND published = 1 AND (published_up < ' . $db->quote($cdate->format('Y-m-d H:i:s')) . ' OR published_up = ' . $db->quote("0000-00-00 00:00:00") . ') ' . 'AND (published_down > ' . $db->quote($cdate->format('Y-m-d H:i:s')) . ' OR published_down = ' . $db->quote("0000-00-00 00:00:00") . ')');
                         $db->setQuery($query);
                         $coupon = $db->loadObject();
                         if (!empty($coupon)) {
                             if ($coupon->procent == 1) {
                                 // Get a procent value
                                 $payment_brutto = round($payment_brutto * ((100 - $coupon->value) / 100), 2);
                             } else {
                                 // Get a real value
                                 $payment_brutto = $payment_brutto - $coupon->value;
                             }
                             // Check how often the coupon is used and if used to often set published to 0 (since 3.0.0)
                             $coupon->hits++;
                             // Check if coupon has to be disabled now
                             if (!empty($coupon->max_hits) && $coupon->hits >= $coupon->max_hits) {
                                 $coupon->published = 0;
                             }
                             $coupontable = JTable::getInstance('coupons', 'Table');
                             if (!$coupontable->bind($coupon)) {
                                 throw new Exception(42, $database->stderr());
                             }
                             if (!$coupontable->check()) {
                                 throw new Exception(42, $database->stderr());
                             }
                             if (!$coupontable->store()) {
                                 throw new Exception(42, $database->stderr());
                             }
                             $coupontable->checkin();
                         } else {
                             // Perhaps delete this invalid field, or display an error?! Should be validated through js normally
                             throw new Exception(JText::_("COM_MATUKIO_INVALID_COUPON_CODE"), 42);
                         }
                     }
                     $neu->payment_brutto = $payment_brutto;
                 } else {
                     // Different fees
                     $payment_brutto = MatukioHelperFees::getPaymentTotal($event);
                     $neu->payment_brutto = $payment_brutto;
                     $difarray = array("places" => $input->get("places", array(), 'Array'), "types" => $input->get("ticket_fees", array(), 'Array'));
                     $neu->different_fees = json_encode($difarray);
                 }
             } elseif (!empty($event->fees)) {
                 if ($different_fees == 0) {
                     // We have disabled payment plugins but a fee
                     // Only calculate total amount
                     $payment_brutto = $event->fees * $neu->nrbooked;
                     $neu->payment_brutto = $payment_brutto;
                 } else {
                     // Different fees
                     $payment_brutto = MatukioHelperFees::getPaymentTotal($event);
                     $neu->payment_brutto = $payment_brutto;
                     $difarray = array("places" => $input->get("places", array(), 'Array'), "types" => $input->get("ticket_fees", array(), 'Array'));
                     $neu->different_fees = json_encode($difarray);
                 }
             }
         } else {
             // Only calculate total amount
             $payment_brutto = $event->fees * $neu->nrbooked;
             $neu->payment_brutto = $event->fees * $neu->nrbooked;
         }
         // Taxes
         if ($neu->payment_brutto > 0) {
             // Lets check if there are any
             if ($event->tax_id == 0) {
                 // No taxes
                 $neu->payment_netto = $neu->payment_brutto;
                 $neu->payment_tax = 0.0;
             } else {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select("*")->from("#__matukio_taxes")->where("id = " . $db->quote($event->tax_id) . " AND published = 1");
                 $db->setQuery($query);
                 $tax = $db->loadObject();
                 if (empty($tax)) {
                     // Houston we have a problem
                     throw new Exception("Invalid tax value! Please select the correct tax in the event edit form.");
                 } else {
                     // Calculate netto
                     $minfac = 100 / (100 + $tax->value);
                     $neu->payment_netto = $neu->payment_brutto * $minfac;
                     $neu->payment_tax = $neu->payment_brutto - $neu->payment_netto;
                 }
             }
         }
         $results = $dispatcher->trigger('onBeforeSaveBooking', $neu, $event);
         // Set status since @3.1
         if (!empty($booking)) {
             // We don't update the status for old bookings
             $neu->status = $booking->status;
         } elseif ($isWaitlist) {
             // We book to the waitlist, let's set the booking like that then
             $neu->status = MatukioHelperUtilsBooking::$WAITLIST;
         } elseif (MatukioHelperSettings::_("booking_always_inactive", 0)) {
             // We set the status to pending
             $neu->status = MatukioHelperUtilsBooking::$PENDING;
         } elseif (empty($event->fees)) {
             // We set the status to active because no payment is done.. so no reason to not confirm them
             $neu->status = MatukioHelperUtilsBooking::$ACTIVE;
         } elseif ($steps == 2) {
             // We set the status to active because no payment can be done.. so no reason to not confirm them
             $neu->status = MatukioHelperUtilsBooking::$ACTIVE;
         } elseif ($payment_method == "cash") {
             // We check if the booking always active setting is set - if yes the booking is always!! active (except waitlist delete etc.)
             $neu->status = MatukioHelperUtilsBooking::$ACTIVE;
         } elseif (MatukioHelperSettings::_("booking_always_active", 0)) {
             // We check if the booking always active setting is set - if yes the booking is always!! active (except waitlist delete etc.)
             $neu->status = MatukioHelperUtilsBooking::$ACTIVE;
         } else {
             // We set the status to pending - this is going to be overwritten by the payment API (if paid etc.)
             $neu->status = MatukioHelperUtilsBooking::$PENDING;
         }
         if (!$neu->check()) {
             JError::raiseError(500, $database->stderr());
         }
         if (!$neu->store()) {
             JError::raiseError(500, $database->stderr());
         }
         $neu->checkin();
         $results = $dispatcher->trigger('onAfterBookingSave', $neu, $event);
         $ueber1 = JText::_("COM_MATUKIO_BOOKING_WAS_SUCCESSFULL");
         $booking_id = $neu->id;
     }
     if ($payment_brutto > 0 && $steps > 2) {
         // Link to the payment form
         $link = JRoute::_("index.php?option=com_matukio&view=paymentform&uuid=" . $uuid);
         $this->setRedirect($link, $reason);
     } else {
         if ($allesok > 0) {
             // We need to send the confirmation here.. we don't send it yet if the event has payment processing
             MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $neu->id, 1);
         }
         // Link to the bookingpage
         if (MatukioHelperSettings::getSettings("oldbooking_redirect_after", "bookingpage") == "bookingpage") {
             $link = JRoute::_("index.php?option=com_matukio&view=booking&uuid=" . $neu->uuid);
         } elseif (MatukioHelperSettings::getSettings("oldbooking_redirect_after", "bookingpage") == "eventpage") {
             $link = JRoute::_(MatukioHelperRoute::getEventRoute($event->id, $catid, 0, $booking_id), false);
         } else {
             // Eventlist overview
             $link = JRoute::_("index.php?option=com_matukio&view=eventlist");
         }
         $this->setRedirect($link, $ueber1 . " " . $reason);
     }
 }
 public static function getEmailBody($row, $buchung, $user)
 {
     $gebucht = self::calculateBookedPlaces($row);
     $gebucht = $gebucht->booked;
     $freieplaetze = $row->maxpupil - $gebucht;
     if ($freieplaetze < 0) {
         $freieplaetze = 0;
     }
     $body = "<p>\n<table cellpadding=\"2\" border=\"0\" width=\"100%\">";
     if (count($buchung) > 0) {
         $body .= "\n<tr><td><b>" . JTEXT::_('COM_MATUKIO_NAME') . "</b>: </td><td>" . $buchung->name . " (" . $user->name . ")" . "</td></tr>";
         $body .= "\n<tr><td><b>" . JTEXT::_('COM_MATUKIO_EMAIL') . "</b>: </td><td>" . $user->email . "</td></tr>";
     }
     if (count($buchung) > 0) {
         $body .= "\n<tr><td><b>" . JTEXT::_('COM_MATUKIO_BOOKING_ID') . "</b>: </td><td>" . MatukioHelperUtilsBooking::getBookingId($buchung->id) . "</td></tr>";
         $body .= "\n<tr><td colspan=\"2\"><hr></td></tr>";
         $body .= "\n<tr><td colspan=\"2\"><b>" . JTEXT::_('COM_MATUKIO_ADDITIONAL_INFO') . "</b></td></tr>";
         $zusfeld = self::getAdditionalFieldsFrontend($row);
         $zusbuch = self::getAdditionalFieldsFrontend($buchung);
         for ($i = 0; $i < count($zusfeld[0]); $i++) {
             if ($zusfeld[0][$i] != "") {
                 $zusart = explode("|", $zusfeld[0][$i]);
                 $body .= "\n<tr><td>" . $zusart[0] . ": </td><td>" . $zusbuch[0][$i] . "</td></tr>";
             }
         }
         if ($row->nrbooked > 1) {
             $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_BOOKED_PLACES') . ": </td><td>" . $buchung->nrbooked . "</td></tr>";
         }
     }
     $body .= "\n<tr><td colspan=\"2\"><hr></td></tr>";
     $body .= "\n<tr><td colspan=\"2\"><b>" . $row->title . "</b></td></tr>";
     $body .= "\n<tr><td colspan=\"2\">" . $row->shortdesc . "</td></tr>";
     if ($row->semnum != "") {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_NUMBER') . ": </td><td>" . $row->semnum . "</td></tr>";
     }
     if ($row->showbegin > 0) {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_BEGIN') . ": </td><td>" . JHTML::_('date', $row->begin, MatukioHelperSettings::getSettings('date_format', 'd-m-Y, H:i')) . "</td></tr>";
     }
     if ($row->showend > 0) {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_END') . ": </td><td>" . JHTML::_('date', $row->end, MatukioHelperSettings::getSettings('date_format', 'd-m-Y, H:i')) . "</td></tr>";
     }
     if ($row->showbooked > 0) {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_CLOSING_DATE') . ": </td><td>" . JHTML::_('date', $row->booked, MatukioHelperSettings::getSettings('date_format', 'd-m-Y, H:i')) . "</td></tr>";
     }
     if ($row->teacher != "") {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_TUTOR') . ": </td><td>" . $row->teacher . "</td></tr>";
     }
     if ($row->target != "") {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_TARGET_GROUP') . ": </td><td>" . $row->target . "</td></tr>";
     }
     $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_CITY') . ": </td><td>" . $row->place . "</td></tr>";
     if (MatukioHelperSettings::getSettings('event_showinfoline', 1) > 0) {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_MAX_PARTICIPANT') . ": </td><td>" . $row->maxpupil . "</td></tr>";
     }
     if ($row->fees > 0) {
         $body .= "\n<tr><td>" . JTEXT::_('COM_MATUKIO_FEES') . ": </td><td>" . MatukioHelperSettings::getSettings('currency_symbol', '$') . " " . $buchung->payment_brutto;
         if (MatukioHelperSettings::getSettings('frontend_usermehrereplaetze', 1) > 0) {
             // $body .= " " . JTEXT::_('COM_MATUKIO_PRO_PERSON');
         }
         $body .= "</td></tr>";
     }
     if ($row->description != "") {
         $body .= "\n<tr><td colspan=\"2\">" . self::getCleanedMailText($row->description) . "</td></tr>";
     }
     $body .= "</table><p>";
     $htxt = str_replace('SEM_HOMEPAGE', "<a href=\"" . JURI::root() . "\">" . JURI::root() . "</a>", JTEXT::_('COM_MATUKIO_FOR_MORE_INFO_VISIT'));
     $body .= $htxt . "</body>";
     return $body;
 }
 /**
  * Generates the barcode and outputs it as header image/jpg
  *
  * @return  string
  */
 public function getBarcode()
 {
     $code = JFactory::getApplication()->input->get("code", '');
     if (empty($code)) {
         echo "No code given";
         return;
     }
     $text = 1;
     $width = 300;
     $height = 50;
     header("Content-type: image/png");
     $im = ImageCreate($width, $height) or die("Cannot Initialize new GD image stream");
     $White = ImageColorAllocate($im, 255, 255, 255);
     $Black = ImageColorAllocate($im, 0, 0, 0);
     ImageInterLace($im, 1);
     $NarrowRatio = 20;
     $WideRatio = 55;
     $QuietRatio = 35;
     $nChars = (strlen($code) + 2) * (6 * $NarrowRatio + 3 * $WideRatio + $QuietRatio);
     $Pixels = $width / $nChars;
     $NarrowBar = (int) (20 * $Pixels);
     $WideBar = (int) (55 * $Pixels);
     $QuietBar = (int) (35 * $Pixels);
     $ActualWidth = ($NarrowBar * 6 + $WideBar * 3 + $QuietBar) * (strlen($code) + 2);
     if ($NarrowBar == 0 || $NarrowBar == $WideBar || $NarrowBar == $QuietBar || $WideBar == 0 || $WideBar == $QuietBar || $QuietBar == 0) {
         ImageString($im, 1, 0, 0, "Image is too small!", $Black);
         ImagePNG($im);
         exit;
     }
     $CurrentBarX = (int) (($width - $ActualWidth) / 2);
     $Color = $White;
     $BarcodeFull = "*" . strtoupper($code) . "*";
     settype($BarcodeFull, "string");
     $FontNum = 3;
     $FontHeight = ImageFontHeight($FontNum);
     $FontWidth = ImageFontWidth($FontNum);
     if ($text != 0) {
         $CenterLoc = (int) (($width - 1) / 2) - (int) ($FontWidth * strlen($BarcodeFull) / 2);
         ImageString($im, $FontNum, $CenterLoc, $height - $FontHeight, "{$BarcodeFull}", $Black);
     } else {
         $FontHeight = -2;
     }
     for ($i = 0; $i < strlen($BarcodeFull); $i++) {
         $StripeCode = MatukioHelperUtilsBooking::getCode99($BarcodeFull[$i]);
         for ($n = 0; $n < 9; $n++) {
             if ($Color == $White) {
                 $Color = $Black;
             } else {
                 $Color = $White;
             }
             switch ($StripeCode[$n]) {
                 case '0':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $NarrowBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $NarrowBar;
                     break;
                 case '1':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $WideBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $WideBar;
                     break;
             }
         }
         $Color = $White;
         ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $QuietBar, $height - 1 - $FontHeight - 2, $Color);
         $CurrentBarX += $QuietBar;
     }
     ImagePNG($im);
     imagedestroy($im);
     jexit();
 }