/** * Certicates / revokes certification of the booking * * @throws Exception - if query fails * @return void */ public function certificate() { $input = JFactory::getApplication()->input; $booking_ids = $input->get("cid", array(), 'array'); $database = JFactory::getDBO(); if (count($booking_ids)) { $uids = implode(',', $booking_ids); $database->setQuery("SELECT * FROM #__matukio_bookings WHERE id IN ({$uids})"); $rows = $database->loadObjectList(); if ($database->getErrorNum()) { throw new Exception($database->stderr(), 42); } foreach ($rows as $row) { if ($this->task == "certificate") { $database->setQuery("UPDATE #__matukio_bookings SET certificated='1' WHERE id='{$row->id}'"); $certmail = 6; } if ($this->task == "uncertificate") { $database->setQuery("UPDATE #__matukio_bookings SET certificated='0' WHERE id='{$row->id}'"); $certmail = 7; } if (!$database->execute()) { throw new Exception($database->stderr(), 42); } $event = MatukioHelperUtilsEvents::getEventRecurring($row->semid); MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $row->id, $certmail); } } $link = 'index.php?option=com_matukio&view=bookings'; $this->setRedirect($link); }
public static function saveEvent($frontend = false) { $database = JFactory::getDBO(); $input = JFactory::getApplication()->input; $caid = $input->getInt('caid', 0); $cancel = $input->getInt('cancel', 0); $deldatei1 = $input->get('deldatei1', 0); $deldatei2 = $input->get('deldatei2', 0); $deldatei3 = $input->get('deldatei3', 0); $deldatei4 = $input->get('deldatei4', 0); $deldatei5 = $input->get('deldatei5', 0); $vorlage = $input->getInt('vorlage', 0, 'string'); $id = $input->getInt('id', 0); $art = $input->getInt('art', 2); $neudatum = MatukioHelperUtilsDate::getCurrentDate(); $recurring = $input->getInt("recurring", 0); $isNew = true; JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); // Zeit formatieren $_begin_date = $input->get('_begin_date', '0000-00-00', 'string'); $_end_date = $input->get('_end_date', '0000-00-00', 'string'); $_booked_date = $input->get('_booked_date', '0000-00-00', 'string'); if ($id > 0) { $kurs = JTable::getInstance('Matukio', 'Table'); $kurs->load($id); $isNew = false; } if ($vorlage > 0) { $kurs = JTable::getInstance('Matukio', 'Table'); $kurs->load($vorlage); } $post = JRequest::get('post'); // Allow HTML for certain fields $post['description'] = JRequest::getVar('description', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['booking_mail'] = JRequest::getVar('booking_mail', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['certificate_code'] = JRequest::getVar('certificate_code', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['shortdesc'] = JRequest::getVar('shortdesc', '', 'post', 'html', JREQUEST_ALLOWHTML); $post['place'] = JRequest::getVar('place', '', 'post', 'html', JREQUEST_ALLOWHTML); $row = JTable::getInstance('Matukio', 'Table'); $row->load($id); if (!$row->bind($post)) { throw new Exception($row->getError(), 42); } // Zuweisung der aktuellen Zeit if ($id == 0) { $row->publishdate = $neudatum; } $row->updated = $neudatum; if ($cancel != $row->cancelled && MatukioHelperSettings::_("notify_participants_cancel", 1)) { $tempmail = 9 + $cancel; $events = MatukioHelperUtilsEvents::getEventsRecurringOnEventId($row->id); foreach ($events as $e) { $database->setQuery("SELECT * FROM #__matukio_bookings WHERE semid='{$e->id}'"); $rows = $database->loadObjectList(); for ($i = 0, $n = count($rows); $i < $n; $i++) { MatukioHelperUtilsEvents::sendBookingConfirmationMail($e, $rows[$i]->id, $tempmail); } } } $row->cancelled = $cancel; $row->catid = $caid; // Zuweisung der Startzeit $row->begin = JFactory::getDate($_begin_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false); // Zuweisung der Endzeit $row->end = JFactory::getDate($_end_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false); // Zuweisung der Buchungszeit $row->booked = JFactory::getDate($_booked_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false); // Neue Daten eintragen $row->description = str_replace('<br>', '<br />', $row->description); $row->description = str_replace('\\"', '"', $row->description); $row->description = str_replace("'", "'", $row->description); $row->fees = str_replace(",", ".", $row->fees); $row->different_fees_override = ""; $different_fees_override = $input->get("different_fees_override", array(), 'Array'); if (count($different_fees_override)) { // Check if element 0 is not empty if (!empty($different_fees_override[0]["title"])) { $row->different_fees_override = json_encode($different_fees_override); } } if ($row->id > 0 or $vorlage > 0) { if ($deldatei1 != 1) { $row->file1 = $kurs->file1; $row->file1code = $kurs->file1code; } if ($deldatei2 != 1) { $row->file2 = $kurs->file2; $row->file2code = $kurs->file2code; } if ($deldatei3 != 1) { $row->file3 = $kurs->file3; $row->file3code = $kurs->file3code; } if ($deldatei4 != 1) { $row->file4 = $kurs->file4; $row->file4code = $kurs->file4code; } if ($deldatei5 != 1) { $row->file5 = $kurs->file5; $row->file5code = $kurs->file5code; } } if ($row->id > 0) { $row->hits = $kurs->hits; } $fileext = explode(' ', strtolower(MatukioHelperSettings::getSettings('file_endings', 'txt zip pdf'))); $filesize = MatukioHelperSettings::getSettings('file_maxsize', 500) * 1024; $fehler = array('', '', '', '', '', '', '', '', '', ''); if (!empty($_FILES['datei1'])) { if (is_file($_FILES['datei1']['tmp_name']) and $_FILES['datei1']['size'] > 0) { if ($_FILES['datei1']['size'] > $filesize) { $fehler[0] = str_replace("SEM_FILE", $_FILES['datei1']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei1ext = array_pop(explode(".", strtolower($_FILES['datei1']['name']))); if (!in_array($datei1ext, $fileext)) { $fehler[1] = str_replace("SEM_FILE", $_FILES['datei1']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[0] == "" and $fehler[1] == "") { if ($deldatei1 != 1) { $row->file1 = $_FILES['datei1']['name']; $row->file1code = base64_encode(file_get_contents($_FILES['datei1']['tmp_name'])); } else { $row->file1 = ""; $row->file1code = ""; } } } } else { // Delete file if ($deldatei1 == 1) { $row->file1 = ""; $row->file1code = ""; } } if (!empty($_FILES['datei2'])) { if (is_file($_FILES['datei2']['tmp_name']) and $_FILES['datei2']['size'] > 0) { if ($_FILES['datei2']['size'] > $filesize) { $fehler[2] = str_replace("SEM_FILE", $_FILES['datei2']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei2ext = array_pop(explode(".", strtolower($_FILES['datei2']['name']))); if (!in_array($datei2ext, $fileext)) { $fehler[3] = str_replace("SEM_FILE", $_FILES['datei2']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[2] == "" and $fehler[3] == "") { $row->file2 = $_FILES['datei2']['name']; $row->file2code = base64_encode(file_get_contents($_FILES['datei2']['tmp_name'])); } } } else { // Delete file if ($deldatei2 == 1) { $row->file2 = ""; $row->file2code = ""; } } if (!empty($_FILES['datei3'])) { if (is_file($_FILES['datei3']['tmp_name']) and $_FILES['datei3']['size'] > 0) { if ($_FILES['datei3']['size'] > $filesize) { $fehler[4] = str_replace("SEM_FILE", $_FILES['datei3']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei3ext = array_pop(explode(".", strtolower($_FILES['datei3']['name']))); if (!in_array($datei3ext, $fileext)) { $fehler[5] = str_replace("SEM_FILE", $_FILES['datei3']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[4] == "" and $fehler[5] == "") { $row->file3 = $_FILES['datei3']['name']; $row->file3code = base64_encode(file_get_contents($_FILES['datei3']['tmp_name'])); } } } else { // Delete file if ($deldatei3 == 1) { $row->file3 = ""; $row->file3code = ""; } } if (!empty($_FILES['datei4'])) { if (is_file($_FILES['datei4']['tmp_name']) and $_FILES['datei4']['size'] > 0) { if ($_FILES['datei4']['size'] > $filesize) { $fehler[6] = str_replace("SEM_FILE", $_FILES['datei4']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei4ext = array_pop(explode(".", strtolower($_FILES['datei4']['name']))); if (!in_array($datei4ext, $fileext)) { $fehler[7] = str_replace("SEM_FILE", $_FILES['datei4']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[6] == "" and $fehler[7] == "") { $row->file4 = $_FILES['datei4']['name']; $row->file4code = base64_encode(file_get_contents($_FILES['datei4']['tmp_name'])); } } } else { // Delete file if ($deldatei4 == 1) { $row->file4 = ""; $row->file4code = ""; } } if (!empty($_FILES['datei5'])) { if (is_file($_FILES['datei5']['tmp_name']) and $_FILES['datei5']['size'] > 0) { if ($_FILES['datei5']['size'] > $filesize) { $fehler[8] = str_replace("SEM_FILE", $_FILES['datei5']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE')); } $datei5ext = array_pop(explode(".", strtolower($_FILES['datei5']['name']))); if (!in_array($datei5ext, $fileext)) { $fehler[9] = str_replace("SEM_FILE", $_FILES['datei5']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE')); } if ($fehler[8] == "" and $fehler[9] == "") { $row->file5 = $_FILES['datei5']['name']; $row->file5code = base64_encode(file_get_contents($_FILES['datei5']['tmp_name'])); } } } else { // Delete file if ($deldatei5 == 1) { $row->file5 = ""; $row->file5code = ""; } } // Eingaben ueberpruefen $speichern = true; // Template?? Deprecated if ($art == 3) { if (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->pattern, 'leer')) { $speichern = false; $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_FILLED_OUT_ALL_REQUIRED_FIELDS'); } } else { if (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->semnum, 'leer') or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->title, 'leer') or $row->catid == 0 or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->shortdesc, 'leer')) { $speichern = false; $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_FILLED_OUT_ALL_REQUIRED_FIELDS'); } elseif (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->maxpupil, 'nummer') or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->nrbooked, 'nummer')) { $speichern = false; $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_TYPED_A_NUMBER'); } else { $database->setQuery("SELECT id FROM #__matukio WHERE semnum='{$row->semnum}' AND id!='{$row->id}'"); $rows = $database->loadObjectList(); if (count($rows) > 0) { $speichern = false; $htxt = JTEXT::_('COM_MATUKIO_NOT_UNIQUE_NUMBERS'); if ($id < 1) { $htxt .= " " . JTEXT::_('COM_MATUKIO_EVENT_NOT_STORED'); } $fehler[] = $htxt; } } } // Kurs speichern if ($speichern == true) { // Trigger plugin event $results = $dispatcher->trigger('onBeforeSaveEvent', $row); // Check if we already created recurring events if ($recurring == 1) { $edited = $input->getInt("recurring_edited", 0); if ($row->recurring_created && $edited && $row->id > 0) { // Delete old recurring events $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->delete("#__matukio_recurring")->where("event_id = " . $row->id); $db->setQuery($query); $db->execute(); // Maybe set booking status to deleted too? } else { // Set it to 1 $row->recurring_created = 1; } } if (!$row->check()) { throw new Exception($database->stderr(), 42); } if (!$row->store()) { throw new Exception($database->stderr(), 42); } $row->checkin(); // Trigger plugin event $results = $dispatcher->trigger('onAfterSaveEvent', array('com_matukio.event', &$row, $isNew)); // Create recurring events if ($recurring == 1) { $dates_string = $input->get("recurring_dates", '', 'string'); if (!empty($dates_string)) { $bdate = explode(" ", $row->begin); $bdate = $bdate[0]; // Add begin date (if not already in there) if (strpos($dates_string, $bdate) === false) { $dates_string = $bdate . "," . "{$dates_string}"; } $dates = explode(",", $dates_string); $begin_date = new DateTime($row->begin); $end_date = new DateTime($row->end); $closing_date = new DateTime($row->booked); $diff = $begin_date->diff($end_date); $diff2 = $begin_date->diff($closing_date); $start_time = $begin_date->format("H:i:s"); $year = date('Y'); foreach ($dates as $d) { $rec_start = new DateTime($d . " " . $start_time); $rec_end = clone $rec_start; $rec_end->add($diff); $rec_close = clone $rec_start; $rec_close->add($diff2); $robj = new stdClass(); $robj->event_id = $row->id; $robj->semnum = MatukioHelperUtilsEvents::createNewEventNumber($year); $robj->begin = $rec_start->format("Y-m-d H:i:s"); $robj->end = $rec_end->format("Y-m-d H:i:s"); $robj->booked = $rec_close->format("Y-m-d H:i:s"); $robj->published = 1; $rect = JTable::getInstance('Recurring', 'MatukioTable'); if (!$rect->bind($robj)) { throw new Exception($rect->getError(), 42); } if (!$rect->check()) { throw new Exception($rect->getError(), 42); } if (!$rect->store()) { throw new Exception($rect->getError(), 42); } } } } else { // Delete the current date from recurring table and insert the new one // Delete old recurring events $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select("*")->from("#__matukio_recurring")->where("event_id = " . $row->id); $db->setQuery($query); $recd = $db->loadObjectList(); // Switch from recurring events to none recurring if (count($recd) > 1) { $query = $db->getQuery(true); $query->delete("#__matukio_recurring")->where("event_id = " . $row->id); $db->setQuery($query); $db->execute(); // Insert it ones MatukioHelperRecurring::saveRecurringDateForEvent($row); } elseif (count($recd) == 1) { // Ugly hack $recd = $recd[0]; $rect = JTable::getInstance('Recurring', 'MatukioTable'); $recd->semnum = $row->semnum; $recd->begin = $row->begin; $recd->end = $row->end; $recd->booked = $row->booked; $recd->published = $row->published; // We just update the date if (!$rect->bind($recd)) { throw new Exception($rect->getError(), 42); } if (!$rect->check()) { throw new Exception($rect->getError(), 42); } if (!$rect->store()) { throw new Exception($rect->getError(), 42); } } else { // Insert date into recurring table // Add recurring date MatukioHelperRecurring::saveRecurringDateForEvent($row); } } // Trigger plugin event $results = $dispatcher->trigger('onAfterSaveRecurring', $row); } // Ausgabe der Kurse $fehlerzahl = array_unique($fehler); if (count($fehlerzahl) > 1) { $fehler = array_unique($fehler); if ($fehler[0] == "") { $fehler = array_slice($fehler, 1); } $fehler = implode("<br />", $fehler); JFactory::getApplication()->enqueueMessage($fehler, 'Warning'); } // Notify Admin BCC of event creation if (MatukioHelperSettings::getSettings('sendmail_operator', '') != '' && $isNew && $speichern) { $mailer = JFactory::getMailer(); $mainframe = JFactory::getApplication(); $sender = $mainframe->getCfg('fromname'); $from = $mainframe->getCfg('mailfrom'); $user = JFactory::getUser($row->publisher); $replyname = $user->name; $replyto = $user->email; $subject = JText::_("COM_MATUKIO_NEW_EVENT_CREATED"); $body = JText::_("COM_MATUKIO_NEW_EVENT_CREATED") . "\n\n"; $body .= JText::_("COM_MATUKIO_EVENT_DETAILS") . ":\n\n"; $body .= JText::_("COM_MATUKIO_TITLE") . ":\t\t" . $row->title . "\n"; $body .= JText::_("COM_MATUKIO_RECURRING_SEMNUM") . ":\t\t" . $row->semnum . "\n"; $body .= JText::_("COM_MATUKIO_BEGIN") . ":\t\t" . $row->begin . "\n"; $body .= JText::_("COM_MATUKIO_END") . ":\t\t" . $row->end . "\n"; $body .= JText::_("COM_MATUKIO_EVENT_DEFAULT_PLACE") . ":\t\t" . $row->place . "\n"; $body .= JText::_("COM_MATUKIO_EVENT_DEFAULT_SHORT_DESCRIPTION") . ":\t\t" . $row->shortdesc . "\n"; $body .= JText::_("COM_MATUKIO_PUBLISHER") . ":\t\t" . $user->name . "\n"; $success = $mailer->sendMail($from, $sender, explode(",", MatukioHelperSettings::getSettings('sendmail_operator', '')), $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null, $replyto, $replyname); } // Send an notification email to all users with new event details @since 4.3.0 if (MatukioHelperSettings::getSettings('sendmail_newevent', 1) && $isNew && $speichern) { // We send an notification of the new event to all users / user group if (MatukioHelperSettings::_("sendmail_newevent_group", 0)) { // Filter users to the given group if not 0 (all) given jimport('joomla.access.access'); $ids = JAccess::getUsersByGroup(MatukioHelperSettings::_("sendmail_newevent_group", 0)); $query = "SELECT * FROM #__users WHERE block = 0 AND id IN (" . implode(",", $ids) . ")"; $db->setQuery($query); $users = $db->loadObjectList(); } else { // Get all users $query = "SELECT * FROM #__users WHERE block = 0"; $db->setQuery($query); $users = $db->loadObjectList(); } $mailer = JFactory::getMailer(); // Set an empty category here - TODO query it from #__category table $row->category = ""; $tmpl = MatukioHelperTemplates::getEmailBody("mail_newevent", $row, null); // Use HTML or text E-Mail if (MatukioHelperSettings::getSettings('email_html', 1)) { // Start html output $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n"; $body .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n"; $body .= "<head>\n"; $body .= "</head>\n"; $body .= "<body>\n"; $body .= $tmpl->value; $body .= "</body>\n</html>"; } else { $body = $tmpl->value_text; } $subject = $tmpl->subject; $mainframe = JFactory::getApplication(); $sender = $mainframe->getCfg('fromname'); $from = $mainframe->getCfg('mailfrom'); // Loop and sent mail foreach ($users as $u) { $success = $mailer->sendMail($from, $sender, $u->email, $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null); $mailer->ClearAllRecipients(); } // E-Mail to Admin / Operator etc. if (MatukioHelperSettings::getSettings('sendmail_operator', '') != "") { $success = $mailer->sendMail($from, $sender, explode(",", MatukioHelperSettings::getSettings('sendmail_operator', '')), $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null); $mailer->ClearAllRecipients(); } } $obj = new StdClass(); $obj->id = $row->id; $obj->error = $row->fehler; $obj->error_count = count($fehlerzahl); $obj->saved = $speichern; $obj->event = $row; return $obj; }
} else { $cid = JFactory::getApplication()->input->getInt('cid', 0); $uid = JFactory::getApplication()->input->getInt('booking_id', 0); if (!empty($cid)) { $link = JRoute::_('index.php?option=com_matukio&view=event&id=' . $cid); } else { $link = JRoute::_('index.php?option=com_matukio&view=eventlist'); } if (empty($cid) && empty($uid)) { $this->setRedirect($link, "COM_MATUKIO_NO_ID"); return; } $msg = JText::_("COM_MATUKIO_BOOKING_ANNULATION_SUCESSFULL"); $database = JFactory::getDBO(); $user = JFactory::getuser(); MatukioHelperUtilsEvents::sendBookingConfirmationMail($cid, $user->id, 2, true); if (!empty($uid)) { $database->setQuery("DELETE FROM #__matukio_bookings WHERE id = '" . $uid . "'"); } else { if ($user->id == 0) { JError::raiseError(403, "COM_MATUKIO_NO_ACCESS"); return; } else { $database->setQuery("DELETE FROM #__matukio_bookings WHERE semid = " . $cid . " AND userid = '" . $user->id . "'"); } } if (!$database->execute()) { JError::raiseError(500, $database->getError()); $msg = JText::_("COM_MATUKIO_BOOKING_ANNULATION_FAILED") . " " . $database->getErrror(); } $this->setRedirect($link, $msg);
/** * Confirms (notfies organizer + participants) an event * * @param object $event - An recurring event * * @return bool * @throws Exception on Error */ public static function confirmRecurringEvent($event) { // First update event $db = JFactory::getDbo(); if (MatukioHelperSettings::_("booking_confirmation", 1)) { // Notify participants and organizer over the event is taking place $db->setQuery("SELECT * FROM #__matukio_bookings WHERE semid = " . $event->id); $rows = $db->loadObjectList(); if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 42); } foreach ($rows as $row) { MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $row->id, 12); } } return true; }
/** * OLD Booking method for old form * * @todo move into a nice function for both backend / Frontend / old and new form * @return mixed */ public function bookevent() { $database = JFactory::getDBO(); $my = JFactory::getUser(); $id = JFactory::getApplication()->input->getInt('cid', 0); $uid = JFactory::getApplication()->input->getInt('uid', 0); $catid = JFactory::getApplication()->input->getInt('catid', 0); $nrbooked = JFactory::getApplication()->input->getInt('nrbooked', 0); $name = JFactory::getApplication()->input->get('name', '', 'string'); $email = JFactory::getApplication()->input->get('email', '', 'string'); $dispatcher = JDispatcher::getInstance(); // Edit own booking $booking_id = JFactory::getApplication()->input->getInt('booking_id', 0); // AGBs $veragb = JFactory::getApplication()->input->get('veragb', 0, 'string'); $isWaitlist = false; $reason = ""; // Load event (use model function) $emodel = JModelLegacy::getInstance('Event', 'MatukioModel'); $row = $emodel->getItem($id); $usrid = $my->id; $art = 2; if ($uid > 0) { $usrid = $uid; $art = 4; } $sqlid = $usrid; if ($name != "" and $email != "" or $usrid == 0) { $usrid = 0; $sqlid = -1; } // Pruefung ob Buchung erfolgreich durchfuehrbar $database->setQuery("SELECT * FROM #__matukio_bookings WHERE semid='{$id}' AND userid='{$sqlid}'"); $temp = $database->loadObjectList(); if (!empty($booking_id)) { $temp = null; } $gebucht = MatukioHelperUtilsEvents::calculateBookedPlaces($row); $gebucht = $gebucht->booked; $allesok = 1; $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_SUCCESSFULL'); $pflichtfeld = false; $fields = MatukioHelperUtilsEvents::getAdditionalFieldsFrontend($row); for ($i = 0; $i < 20; $i++) { $test = $fields[0][$i]; if (!empty($test)) { $res = explode("|", $test); if (trim($res[1]) == "1") { $value = JFactory::getApplication()->input->get("zusatz" . ($i + 1), '', 'string'); if (empty($value)) { $pflichtfeld = true; } } } } if ($my->id > 0) { $name = $my->name; $email = $my->email; } // } if (empty($name) || empty($email)) { $allesok = 0; $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL'); $reason = JTEXT::_('COM_MATUKIO_NO_NAME_OR_EMAIL'); } elseif ($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() > $row->booked) { $allesok = 0; $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL'); $reason = JTEXT::_('COM_MATUKIO_EXCEEDED'); } elseif ($row->maxpupil - $gebucht - $nrbooked < 0 && $row->stopbooking == 1) { $allesok = 0; $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL'); $reason = JTEXT::_('COM_MATUKIO_MAX_PARTICIPANT_NUMBER_REACHED'); } elseif ($row->maxpupil - $gebucht - $nrbooked < 0 && $row->stopbooking == 0) { $allesok = 2; $ueber1 = JTEXT::_('COM_MATUKIO_ADDED_WAITLIST'); $reason = JTEXT::_('COM_MATUKIO_YOU_ARE_BOOKED_ON_THE_WAITING_LIST'); $isWaitlist = true; } elseif (MatukioHelperSettings::getSettings('agb_text', '') != "" && $veragb != "1") { $allesok = 0; $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_NOT_SUCCESSFULL'); $reason = JTEXT::_('COM_MATUKIO_AGB_NOT_ACCEPTED'); } if ($art == 4) { $allesok = 1; $ueber1 = JTEXT::_('COM_MATUKIO_BOOKING_WAS_SUCCESSFULL'); } $link = JRoute::_(MatukioHelperRoute::getEventRoute($row->id, $catid), false); $msg = ""; $neu = ""; // Alles in Ordnung if ($allesok > 0) { // Buchung eintragen $neu = JTable::getInstance('bookings', 'Table'); if (!$neu->bind(JRequest::get('post'))) { return JError::raiseError(500, $database->stderr()); } if (!empty($booking_id)) { $neu->id = $booking_id; } $neu->semid = $id; $neu->userid = $usrid; // Hmm really do that? $neu->name = $name; $neu->email = $email; $neu->bookingdate = MatukioHelperUtilsDate::getCurrentDate(); $neu->name = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->name); $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); // Set booking status to active @since 3.1 $neu->status = MatukioHelperUtilsBooking::$ACTIVE; if (!empty($row->fees)) { $neu->payment_method = "cash"; $payment_brutto = $row->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 { // Perhaps delete this invalid field, or display an error?! TODO } } $neu->payment_brutto = $payment_brutto; } $results = $dispatcher->trigger('onBeforeSaveBooking', $neu, $row); // Set status since @3.1 if ($isWaitlist) { // We book to the waitlist, let's set the booking like that then $neu->status = MatukioHelperUtilsBooking::$WAITLIST; } elseif (empty($row->fees)) { // We set the status to active because no payment is done.. so no reason to not confirm them $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()); exit; } if (!$neu->store()) { JError::raiseError(500, $database->stderr()); exit; } $neu->checkin(); $ueber1 = JText::_("COM_MATUKIO_BOOKING_WAS_SUCCESSFULL"); if ($usrid == 0) { $usrid = $neu->id * -1; } if (MatukioHelperSettings::getSettings("oldbooking_redirect_after", "bookingpage") == "bookingpage") { $link = JRoute::_(MatukioHelperRoute::getEventRoute($row->id, $catid, 1, $neu->id), false); } elseif (MatukioHelperSettings::getSettings("oldbooking_redirect_after", "bookingpage") == "eventpage") { $link = JRoute::_(MatukioHelperRoute::getEventRoute($row->id, $catid, 0, $neu->id), false); } else { // Eventlist overview $link = JRoute::_("index.php?option=com_matukio&view=eventlist"); } if ($art == 4) { MatukioHelperUtilsEvents::sendBookingConfirmationMail($row, $neu->id, 8); } else { MatukioHelperUtilsEvents::sendBookingConfirmationMail($row, $neu->id, 1); } } else { $link = JRoute::_(MatukioHelperRoute::getEventRoute($row->id, $catid), false); } $this->setRedirect($link, $ueber1 . " " . $reason); }
/** * 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); } }
/** * Removes an or multiple events * * @throws Exception - If db queries fail * @return void */ public function remove() { $cid = JFactory::getApplication()->input->get('cid', array(), 'array'); $db = JFactory::getDBO(); if (count($cid)) { $cids = implode(',', $cid); // Notify users if (MatukioHelperSettings::_("notify_participants_delete", 1)) { $db->setQuery("SELECT * FROM #__matukio_bookings WHERE id IN (" . $cids . ")"); $bookings = $db->loadObjectList(); if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 42); } foreach ($bookings as $b) { $event = MatukioHelperUtilsEvents::getEventRecurring($b->semid); MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $b->id, 4); } } // Delete events $query = "DELETE FROM #__matukio_recurring where id IN (" . $cids . ")"; $db->setQuery($query); if (!$db->execute()) { throw new Exception($db->getErrorMsg(), 42); } // Delete old bookings $db->setQuery("DELETE FROM #__matukio_bookings WHERE semid IN (" . $cids . ")"); if (!$db->execute()) { throw new Exception($db->getErrorMsg(), 42); } } $msg = JText::_("COM_MATUKIO_DELETE_SUCCESS"); $this->setRedirect('index.php?option=com_matukio&view=recurring', $msg); }
/** * Update Booking status and redirect to event art 1 * * @return void - Redirects to event view */ public function status() { $uuid = JFactory::getApplication()->input->get('uuid', ''); $pg_plugin = JFactory::getApplication()->input->get('pg_plugin', ''); $uid = JFactory::getApplication()->input->getInt('uid', 0); $dispatcher = JDispatcher::getInstance(); // Import the right plugin here! JPluginHelper::importPlugin('payment', $pg_plugin); $data = $dispatcher->trigger('onTP_Processpayment', array(JRequest::get("post"))); $model = $this->getModel('PPayment', 'MatukioModel'); $booking = $model->getBooking($uuid); if (empty($booking)) { JError::raise(E_ERROR, "500", JText::_("COM_MATUKIO_BOOKING_NOT_FOUND")); } $event = $model->getEvent($booking->semid); $payment_status = $data[0]['status']; // Update Payment status $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->update("#__matukio_bookings")->where("uuid = " . $db->quote($uuid))->set("payment_status = " . $db->quote($payment_status)); $db->setQuery($query); $db->execute(); $msg = JText::_("COM_MATUKIO_THANK_YOU"); // Check if there is an error, if yes if ($data[0]['status'] == "E") { $status = MatukioHelperUtilsBooking::$PENDING; if (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.) $status = MatukioHelperUtilsBooking::$ACTIVE; } // Update status to not paid $query = $db->getQuery(true); $query->update("#__matukio_bookings")->where("uuid = " . $db->quote($uuid))->set("paid = 0")->set("status = " . $db->quote($status))->set("payment_plugin_data = " . $db->quote($data[0]['raw_data'])); $db->setQuery($query); $db->execute(); $view = $this->getView("PPayment", "html"); $model = $this->getModel('PPayment', 'MatukioModel'); $view->setModel($model, true); $view->data = $data; $view->setLayout("error"); $view->display(); return; } elseif ($data[0]['status'] == "C") { $status = MatukioHelperUtilsBooking::$ACTIVE; if (MatukioHelperSettings::_("booking_always_inactive", 0)) { // We check if the booking always active setting is set - if yes the booking is always!! active (except waitlist delete etc.) $status = MatukioHelperUtilsBooking::$PENDING; } // Update status to paid and set the booking to active $query = $db->getQuery(true); $query->update("#__matukio_bookings")->where("uuid = " . $db->quote($uuid))->set("paid = 1")->set("status = " . $db->quote($status))->set("payment_plugin_data = " . $db->quote($data[0]['raw_data'])); $db->setQuery($query); $db->execute(); $msg = JText::_("COM_MATUKIO_PAYMENT_SUCCESSFULL"); } elseif ($data[0]['status'] == "P") { $status = MatukioHelperUtilsBooking::$PENDING; // Exclusion for cash plugin if ($pg_plugin == "cash") { $status = MatukioHelperUtilsBooking::$ACTIVE; if (MatukioHelperSettings::_("booking_always_inactive", 0)) { // We check if the booking always active setting is set - if yes the booking is always!! active (except waitlist delete etc.) $status = MatukioHelperUtilsBooking::$PENDING; } } if (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.) $status = MatukioHelperUtilsBooking::$ACTIVE; } // Update status to not paid $query = $db->getQuery(true); $query->update("#__matukio_bookings")->where("uuid = " . $db->quote($uuid))->set("paid = 0")->set("status = " . $db->quote($status))->set("payment_plugin_data = " . $db->quote($data[0]['raw_data'])); $db->setQuery($query); $db->execute(); $msg = JText::_("COM_MATUKIO_PAYMENT_PENDING"); } // We send the booking confirmation here.. MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $booking->id, 1); // Link to event art = 1 $eventid_l = $event->id . ':' . JFilterOutput::stringURLSafe($event->title); $catid_l = $event->catid . ':' . JFilterOutput::stringURLSafe(MatukioHelperCategories::getCategoryAlias($event->catid)); // Link back to the form if (MatukioHelperSettings::getSettings("oldbooking_redirect_after", "bookingpage") == "bookingpage") { $bplink = "index.php?option=com_matukio&view=booking&uuid=" . $booking->uuid; $needles = array('category' => 0); $item = MatukioHelperRoute::_findItem($needles); if ($item) { $bplink .= '&Itemid=' . $item->id; } $link = JRoute::_($bplink); } elseif (MatukioHelperSettings::getSettings("oldbooking_redirect_after", "bookingpage") == "eventpage") { $link = JRoute::_(MatukioHelperRoute::getEventRoute($eventid_l, $catid_l, 0, $uid, $uuid), false); } else { // Eventlist overview $link = JRoute::_(MatukioHelperRoute::getEventlistRoute(0, 0), false); } $this->setRedirect($link, $msg); }
/** * Save old booking form event * * @return object */ function saveoldevent() { // 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 = 0; $notify_participant = $input->getInt("notify_participant", 0); $notify_participant_invoice = $input->getInt("notify_participant_invoice", 0); $uuid = $input->get('uuid', 0, 'string'); $nrbooked = $input->getInt('nrbooked', 1); $userid = $input->getInt('userid', 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 } 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; $neu->bookingdate = MatukioHelperUtilsDate::getCurrentDate(); $neu->name = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->name); $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); $neu->nrbooked = $nrbooked; if (!empty($event->fees)) { $neu->payment_method = "cash"; // TODO Update to diffrent fees if ($nrbooked > 0) { $neu->payment_brutto = $event->fees * $nrbooked; } else { $neu->payment_brutto = $event->fees; } } if (empty($neu->uuid)) { $neu->uuid = MatukioHelperPayment::getUuid(true); } 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, false); } $viewteilnehmerlink = JRoute::_("index.php?option=com_matukio&view=participants&cid=" . $event->id . "&art=2"); $msg = JText::_("COM_MATUKIO_BOOKING_EDITED"); $this->setRedirect($viewteilnehmerlink, $msg); }
/** * Cancels / uncancels the event * * @param string $task * * @return object * @throws Exception */ public function cancel($task = 'cancelEvent') { // Check authorization if (!JFactory::getUser()->authorise('core.edit', 'com_matukio')) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); } $ids = JFactory::getApplication()->input->get('cid', array(), 'array'); if ($task == 'cancelEvent') { $cancelled = 1; } else { $cancelled = 0; } if (count($ids)) { // First update event $db = JFactory::getDbo(); $cids = implode(',', $ids); $db->setQuery("UPDATE #__matukio SET cancelled = '" . $cancelled . "' WHERE id IN (" . $cids . ") "); if (!$db->execute()) { throw new Exception($db->getErrorMsg(), 500); } // Update recurring events $db->setQuery("UPDATE #__matukio_recurring SET cancelled = " . $db->quote($cancelled) . " WHERE event_id IN (" . $cids . ")"); if (!$db->execute()) { throw new Exception($db->getErrorMsg(), 500); } if (MatukioHelperSettings::_("booking_stornoconfirmation", 1)) { foreach ($ids as $id) { $events = MatukioHelperUtilsEvents::getEventsRecurringOnEventId($id); foreach ($events as $e) { // Notify participants over the change $db->setQuery("SELECT * FROM #__matukio_bookings WHERE semid = " . $e->id . ""); $rows = $db->loadObjectList(); if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 42); } foreach ($rows as $row) { if ($cancelled == 0) { MatukioHelperUtilsEvents::sendBookingConfirmationMail($e, $row->id, 9); } else { MatukioHelperUtilsEvents::sendBookingConfirmationMail($e, $row->id, 10); } } // Delete old bookings // Maybe $db->setQuery("UPDATE #__matukio_bookings SET status = 4 WHERE semid = " . $e->id . ""); } } } } $msg = ""; $link = JRoute::_('index.php?option=com_matukio&view=eventlist&art=2'); $this->setRedirect($link); }
/** * Change the booking status * * @param array $cid - The cid * @param int $status - The status to which the booking should be changed * @param boolean $notifyParticipant - Should the participant be notified (by email) * * @throws Exception - DB Error * * @return bool */ public static function changeStatusBooking($cid, $status = 1, $notifyParticipant = true) { if (count($cid)) { $db = JFactory::getDBO(); $cids = implode(',', $cid); $db->setQuery("UPDATE #__matukio_bookings SET status = " . $db->quote($status) . " WHERE id IN (" . $cids . ")"); if (!$db->execute()) { throw new Exception($db->getErrorMsg(), 42); } if ($notifyParticipant) { $db->setQuery("SELECT * FROM #__matukio_bookings WHERE id IN (" . $cids . ")"); $bookings = $db->loadObjectList(); if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 42); } foreach ($bookings as $b) { $event = MatukioHelperUtilsEvents::getEventRecurring($b->semid); if ($status == self::$ACTIVE) { // Notify users of the activation MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $b->id, 1, false, $b); } elseif ($status == self::$DELETED) { // Notify users of the organizer delete MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $b->id, 3, false, $b); } elseif ($status == self::$PENDING) { // Notify users of the organizer delete MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $b->id, 1, false, $b); } else { throw new Exception("Uknown Status: " . $status, "42"); } } } } return true; }
/** * OLD booking form * * @return object */ public function saveOld() { $database = JFactory::getDBO(); $input = JFactory::getApplication()->input; // Backend $art = 4; $id = $input->getInt("id", 0); $event_id = $input->getInt('event_id', 0); // Hardcoded to get it working, could cause some new bugs $uid = 0; $uuid = $input->getInt('uuid', 0); $nrbooked = $input->getInt('nrbooked', 1); $userid = $input->getInt('userid', 0); $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'); } $event = JTable::getInstance('matukio', 'Table'); $event->load($event_id); $reason = ""; if (!empty($uid)) { if ($uid < 0) { // Setting booking to changed booking $userid = $uid; // uid = Negativ $art = 4; } } // Checking old required fields - backward compatibilty - only frontend 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; if (empty($id)) { $neu->bookingdate = MatukioHelperUtilsDate::getCurrentDate(); } $neu->name = MatukioHelperUtilsBasic::cleanHTMLfromText($neu->name); $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); $neu->nrbooked = $nrbooked; if (!empty($event->fees)) { $neu->payment_method = "cash"; if ($nrbooked > 0) { $neu->payment_brutto = $event->fees * $nrbooked; } else { $neu->payment_brutto = $event->fees; } } 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"); // 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_FIELD_APPLY'); $link = 'index.php?option=com_matukio&controller=bookings&task=editBooking&booking_id=' . $neu->id; break; case 'save': default: $msg = JText::_('COM_MATUKIO_BOOKING_FIELD_SAVE'); $link = 'index.php?option=com_matukio&view=bookings'; break; } $this->setRedirect($link, $msg); }
/** * Cert user * * @throws Exception - if access is denied! * @return void */ public function certificateUser() { if (!JFactory::getUser()->authorise('core.edit.own', 'com_matukio')) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $msg = JTEXT::_("COM_MATUKIO_SEND_USER_CERTIFICATE"); $database = JFactory::getDBO(); $cid = JFactory::getApplication()->input->getInt('cid', 0); $uid = JFactory::getApplication()->input->getInt('uid', 0); $database->setQuery("SELECT * FROM #__matukio_bookings WHERE id='" . $uid . "'"); $row = $database->loadObject(); if ($row->certificated == 0) { $cert = 1; $certmail = 6; } else { $cert = 0; $certmail = 7; } $database->setQuery("UPDATE #__matukio_bookings SET certificated = " . $database->quote($cert) . " WHERE id='" . $uid . "'"); if (!$database->execute()) { throw new Exception($database->getError(), 500); } $event = MatukioHelperUtilsEvents::getEventEditTemplate($row->semid); MatukioHelperUtilsEvents::sendBookingConfirmationMail($event, $uid, $certmail); $link = JRoute::_('index.php?option=com_matukio&view=participants&art=2&cid=' . $cid); $this->setRedirect($link, $msg); }
/** * Removes an or multiple events * * @throws Exception - If db queries fail * @return void */ public function remove() { $cid = JFactory::getApplication()->input->get('cid', array(), 'array'); JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); $db = JFactory::getDBO(); if (count($cid)) { // Notify users if (MatukioHelperSettings::_("notify_participants_delete", 1)) { foreach ($cid as $id) { $events = MatukioHelperUtilsEvents::getEventsRecurringOnEventId($id); foreach ($events as $e) { $db->setQuery("SELECT * FROM #__matukio_bookings WHERE semid = " . $db->quote($e->id) . " AND status = 1"); $bookings = $db->loadObjectList(); if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 500); } foreach ($bookings as $b) { MatukioHelperUtilsEvents::sendBookingConfirmationMail($e, $b->id, 4); } // Delete old bookings $db->setQuery("UPDATE #__matukio_bookings SET status = 4 WHERE semid = " . $db->quote($e->id)); if (!$db->execute()) { throw new Exception($db->getErrorMsg(), 42); } } } } foreach ($cid as $c) { // Delete recurring events MatukioHelperRecurring::deleteRecurringEvents($c); } // Delete events $cids = implode(',', $cid); $query = "DELETE FROM #__matukio where id IN (" . $cids . ")"; $db->setQuery($query); if (!$db->execute()) { throw new Exception($db->getErrorMsg(), 500); } } // Trigger the onContentChangeState event. $result = $dispatcher->trigger('onEventAfterDelete', array('com_matukio.event', $cid)); $msg = JText::_("COM_MATUKIO_DELETE_SUCCESS"); $this->setRedirect('index.php?option=com_matukio&view=eventlist', $msg); }