primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,358 @@
<?php
/**
* @package JEM
* @copyright (C) 2013-2024 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license https://www.gnu.org/licenses/gpl-3.0 GNU/GPL
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Log\Log;
/**
* JEM Component Attendees Controller
*
* @package JEM
*
*/
class JemControllerAttendees extends BaseController
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* redirect to events page
*/
public function back()
{
$this->setRedirect(Route::_(JemHelperRoute::getMyEventsRoute(), false));
$this->redirect();
}
/**
* addtask
*/
public function attendeeadd()
{
// Check for request forgeries
Session::checkToken('request') or jexit('Invalid Token');
$jinput = Factory::getApplication()->input;
$eventid = $jinput->getInt('id', 0);
$status = $jinput->getInt('status', 0);
$checkseries = $jinput->getString('series', '');
$comment = '';
$fid = $jinput->getInt('Itemid', 0);
$uids = explode(',', $jinput->getString('uids', ''));
\Joomla\Utilities\ArrayHelper::toInteger($uids);
$uids = array_filter($uids);
$uids = array_unique($uids);
$total = is_array($uids) ? count($uids) : 0;
$msg = '';
if ($jinput->get('task', 0,'string')=="attendeeadd") {
$places = $jinput->input->getInt('places', 0);
} else {
if ($status == 1)
{
$places = $jinput->input->getInt('addplaces', 0);
}
else
{
$places = $jinput->input->getInt('cancelplaces', 0);
}
}
if($checkseries == "on"){
$checkseries = 1;
}else{
$checkseries = 0;
}
JemHelper::addLogEntry("Got attendee add - event: {$eventid}, status: {$status}, users: " . implode(',', $uids), __METHOD__, Log::DEBUG);
if ($total < 1) {
$msg = '0 ' . Text::_('COM_JEM_REGISTERED_USERS_ADDED');
} else {
PluginHelper::importPlugin('jem');
$dispatcher = JemFactory::getDispatcher();
// We have to check all users first if there are already records for given event.
// If not we have to add the records and than on success send the emails.
$modelEventItem = $this->getModel('event');
$modelAttendees = $this->getModel('attendees'); // required to ensure JemModelAttendees is loaded
$regs = JemModelAttendees::getRegisteredUsers($eventid);
$errMsgs = array();
$errMsg = '';
$skip = 0;
$error = 0;
$changed = 0;
// Get event
try {
$event = $modelEventItem->getItem($eventId);
}
catch (Exception $e) {
$event = false;
}
// If event has 'seriesbooking' active and $series is true then get all recurrence events of series from now (register or unregister)
if($event->recurrence_type){
if(($event->seriesbooking && $checkseries)) {
$events = $modelEventItem->getListRecurrenceEventsbyId($eventid, $event->recurrence_first_id, time());
}
}
if (!isset($events) || !count ($events)){
$events [] = clone $event;
}
foreach ($events as $key => $row) {
$skip = $error = $changed = 0;
foreach ($uids as $uid) {
if (array_key_exists($uid, $regs)) {
$reg = $regs[$uid];
$old_status = ($reg->status == 1 && $reg->waiting == 1) ? 2 : $reg->status;
if (!empty($reg->id) && ($old_status != $status)) {
JemHelper::addLogEntry("Change user {$uid} already registered for event {$row->id}.", __METHOD__, Log::DEBUG);
$reg_id = $modelEventItem->adduser($row->id, $uid, $status, $places, $comment, $errMsg, $reg->id);
if ($reg_id) {
$res = $dispatcher->triggerEvent('onEventUserRegistered', array($reg_id));
++$changed;
} else {
JemHelper::addLogEntry(implode(' - ', array("Model returned error while changing registration of user {$uid}", $errMsg)), __METHOD__, Log::DEBUG);
if (!empty($errMsg)) {
$errMsgs[] = $errMsg;
}
++$error;
}
} else {
JemHelper::addLogEntry("Skip user {$uid} already registered for event {$row->id}.", __METHOD__, Log::DEBUG);
++$skip;
}
} else {
$reg_id = $modelEventItem->adduser($row->id, $uid, $status, $places, $comment, $errMsg);
if ($reg_id) {
$res = $dispatcher->triggerEvent('onEventUserRegistered', array($reg_id));
} else {
JemHelper::addLogEntry(implode(' - ', array("Model returned error while adding user {$uid}", $errMsg)), __METHOD__, Log::DEBUG);
if (!empty($errMsg)) {
$errMsgs[] = $errMsg;
}
++$error;
}
}
}
$cache = Factory::getCache('com_jem');
$cache->clean();
$msg = ($total - $skip - $error - $changed) . ' ' . Text::_('COM_JEM_REGISTERED_USERS_ADDED') . ' [ID: ' . $row->id . ']';
if ($changed > 0) {
$msg .= ', ' . $changed . ' ' . Text::_('COM_JEM_REGISTERED_USERS_CHANGED');
}
$errMsgs = array_unique($errMsgs);
if (count($errMsgs)) {
$msg .= '<br />' . implode('<br />', $errMsgs);
}
}
}
$this->setRedirect(Route::_('index.php?option=com_jem&view=attendees&id='.$eventid.'&Itemid='.$fid, false), $msg);
}
/**
* removetask
*/
public function attendeeremove()
{
// Check for request forgeries
Session::checkToken('request') or jexit('Invalid Token');
$jinput = Factory::getApplication()->input;
$cid = $jinput->get('cid', array(), 'array');
$id = $jinput->getInt('id', 0);
$fid = $jinput->getInt('Itemid', 0);
$total = is_array($cid) ? count($cid) : 0;
if ($total < 1) {
throw new Exception(Text::_('COM_JEM_SELECT_ITEM_TO_DELETE'), 500);
}
$modelAttendeeList = $this->getModel('attendees');
PluginHelper::importPlugin('jem');
$dispatcher = JemFactory::getDispatcher();
$modelAttendeeItem = $this->getModel('attendee');
// We need information about every entry to delete for mailer.
// But we should first delete the entry and than on success send the mails.
foreach ($cid as $reg_id) {
$modelAttendeeItem->setId($reg_id);
$entry = $modelAttendeeItem->getData();
if($modelAttendeeList->remove(array($reg_id))) {
$res = $dispatcher->triggerEvent('onEventUserUnregistered', array($entry->event, $entry));
} else {
$error = true;
}
}
if (!empty($error)) {
echo "<script> alert('".$modelAttendeeList->getError()."'); window.history.go(-1); </script>\n";
}
$cache = Factory::getCache('com_jem');
$cache->clean();
$msg = $total.' '.Text::_('COM_JEM_REGISTERED_USERS_DELETED');
$this->setRedirect(Route::_('index.php?option=com_jem&view=attendees&id='.$id.'&Itemid='.$fid, false), $msg);
}
///@todo Add function to change registration status.
/**
* toggletask
*/
public function attendeetoggle()
{
// Check for request forgeries
Session::checkToken('request') or jexit('Invalid Token');
$jinput = Factory::getApplication()->input;
$id = $jinput->getInt('id', 0);
$fid = $jinput->getInt('Itemid', 0);
$model = $this->getModel('attendee');
$model->setId($id);
$attendee = $model->getData();
$res = $model->toggle();
$type = 'message';
if ($res)
{
PluginHelper::importPlugin('jem');
$dispatcher = JemFactory::getDispatcher();
$res = $dispatcher->triggerEvent('onUserOnOffWaitinglist', array($id));
if ($attendee->waiting) {
$msg = Text::_('COM_JEM_ADDED_TO_ATTENDING');
} else {
$msg = Text::_('COM_JEM_ADDED_TO_WAITING');
}
}
else
{
$msg = Text::_('COM_JEM_WAITINGLIST_TOGGLE_ERROR').': '.$model->getError();
$type = 'error';
}
$this->setRedirect(Route::_('index.php?option=com_jem&view=attendees&id='.$attendee->event.'&Itemid='.$fid, false), $msg, $type);
$this->redirect();
}
/**
* Exporttask
* view: attendees
*/
public function export()
{
// Check for request forgeries
Session::checkToken('request') or jexit('Invalid Token');
$app = Factory::getApplication();
$params = $app->getParams();
$jemconfig = JemConfig::getInstance()->toRegistry();
$enableemailadress = $params->get('enableemailaddress', 0);
$separator = $jemconfig->get('csv_separator', ';');
$delimiter = $jemconfig->get('csv_delimiter', '"');
$csv_bom = $jemconfig->get('csv_bom', '1');
$userfield = $jemconfig->get('globalattribs.global_regname', 1) ? 'name' : 'username';
$comments = $jemconfig->get('regallowcomments', 0);
$model = $this->getModel('attendees');
$datas = $model->getData();
$event = $model->getEvent();
$waitinglist = isset($event->waitinglist) ? $event->waitinglist : false;
header('Content-Type: text/csv; charset=utf-8');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename=attendees_event_' . $event->id . '.csv');
header('Pragma: no-cache');
$export = fopen('php://output', 'w');
ob_end_clean();
if ($csv_bom ==1 ) {
//add BOM to fix UTF-8 in Excel
fputs($export, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
}
$cols = array();
$cols[] = Text::_('COM_JEM_NUM');
$cols[] = Text::_($jemconfig->get('globalattribs.global_regname', 1) ? 'COM_JEM_NAME' : 'COM_JEM_USERNAME');
if ($enableemailadress == 1) {
$cols[] = Text::_('COM_JEM_EMAIL');
}
$cols[] = Text::_('COM_JEM_REGDATE');
$cols[] = Text::_('COM_JEM_STATUS');
$cols[] = Text::_('COM_JEM_PLACES');
if ($comments) {
$cols[] = Text::_('COM_JEM_COMMENT');
}
fputcsv($export, $cols, $separator, $delimiter);
$i = 0;
foreach ($datas as $data)
{
$cols = array();
$cols[] = ++$i;
$cols[] = $data->$userfield;
if ($enableemailadress == 1) {
$cols[] = $data->email;
}
$cols[] = empty($data->uregdate) ? '' : HTMLHelper::_('date',$data->uregdate, Text::_('DATE_FORMAT_LC5'));
$status = isset($data->status) ? $data->status : 1;
if ($status < 0) {
$txt_stat = 'COM_JEM_ATTENDEES_NOT_ATTENDING';
} elseif ($status > 0) {
$txt_stat = $data->waiting ? 'COM_JEM_ATTENDEES_ON_WAITINGLIST' : 'COM_JEM_ATTENDEES_ATTENDING';
} else {
$txt_stat = 'COM_JEM_ATTENDEES_INVITED';
}
$cols[] = Text::_($txt_stat);
$cols[] = $data->places;
if ($comments) {
$comment = strip_tags($data->comment);
// comments are limited to 255 characters in db so we don't need to truncate them on export
$cols[] = $comment;
}
fputcsv($export, $cols, $separator, $delimiter);
}
fclose($export);
$app->close();
}
}
?>

View File

@ -0,0 +1,376 @@
<?php
/**
* @package JEM
* @copyright (C) 2013-2024 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license https://www.gnu.org/licenses/gpl-3.0 GNU/GPL
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
require_once (JPATH_COMPONENT_SITE.'/classes/controller.form.class.php');
/**
* Event Controller
*/
class JemControllerEvent extends JemControllerForm
{
protected $view_item = 'editevent';
protected $view_list = 'eventslist';
protected $_id = 0;
/**
* Method to add a new record.
*
* @return boolean True if the event can be added, false if not.
*/
public function add()
{
if (!parent::add()) {
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
}
}
/**
* Method override to check if you can add a new record.
*
* @param array An array of input data.
*
* @return boolean
*/
protected function allowAdd($data = array())
{
// Initialise variables.
$user = JemFactory::getUser();
$categoryId = \Joomla\Utilities\ArrayHelper::getValue($data, 'catid', Factory::getApplication()->input->getInt('catid', 0), 'int');
if ($user->can('add', 'event', false, $categoryId ? $categoryId : false)) {
return true;
}
// In the absense of better information, revert to the component permissions.
return parent::allowAdd();
}
/**
* Method override to check if you can edit an existing record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*/
protected function allowEdit($data = array(), $key = 'id')
{
// Initialise variables.
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$user = JemFactory::getUser();
if (isset($data['access'])) {
$access = $data['access'];
} else {
$record = $this->getModel()->getItem($recordId);
$access = isset($record->access) ? $record->access : 0;
}
if (!in_array($access, $user->getAuthorisedViewLevels())) {
return false;
}
if (isset($data['created_by'])) {
$created_by = $data['created_by'];
} else {
$record = $this->getModel()->getItem($recordId);
$created_by = isset($record->created_by) ? $record->created_by : false;
}
if ($user->can('edit', 'event', $recordId, $created_by)) {
return true;
}
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
/**
* Method to cancel an edit.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return boolean True if access level checks pass, false otherwise.
*/
public function cancel($key = 'a_id')
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
parent::cancel($key);
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
}
/**
* Method to edit an existing record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if access level check and checkout passes, false otherwise.
*/
public function edit($key = null, $urlVar = 'a_id')
{
$result = parent::edit($key, $urlVar);
return $result;
}
/**
* Method to add a new record based on existing record.
*
* @return boolean True if the event can be added, false if not.
*/
public function copy()
{
if (!parent::add()) {
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
}
}
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*/
public function getModel($name = 'editevent', $prefix = '', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
/**
* Gets the URL arguments to append to an item redirect.
*
* @param int $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the id.
*
* @return string The arguments to append to the redirect URL.
*/
protected function getRedirectToItemAppend($recordId = null, $urlVar = 'a_id')
{
// Need to override the parent method completely.
$jinput = Factory::getApplication()->input;
$tmpl = $jinput->getCmd('tmpl', '');
$layout = $jinput->getCmd('layout', 'edit');
$task = $jinput->getCmd('task', '');
$append = '';
// Setup redirect info.
if ($tmpl) {
$append .= '&tmpl='.$tmpl;
}
$append .= '&layout=edit';
if ($recordId) {
$append .= '&'.$urlVar.'='.$recordId;
}
elseif (($task === 'copy') && ($fromId = $jinput->getInt('a_id', 0))) {
$append .= '&from_id='.$fromId;
}
$itemId = $jinput->getInt('Itemid', 0);
$catId = $jinput->getInt('catid', 0);
$locId = $jinput->getInt('locid', 0);
$date = $jinput->getCmd('date', '');
$return = $this->getReturnPage();
if ($itemId) {
$append .= '&Itemid='.$itemId;
}
if ($catId) {
$append .= '&catid='.$catId;
}
if ($locId) {
$append .= '&locid='.$locId;
}
if ($date) {
$append .= '&date='.$date;
}
if ($return) {
$append .= '&return='.base64_encode($return);
}
return $append;
}
/**
* Get the return URL.
*
* If a "return" variable has been passed in the request
*
* @return string The return URL.
*/
protected function getReturnPage()
{
$uri = Uri::getInstance();
$return = Factory::getApplication()->input->get('return', null, 'base64');
if (empty($return) || !Uri::isInternal(base64_decode($return))) {
if (!empty($this->_id)) {
return Route::_(JemHelperRoute::getEventRoute($this->_id));
}
return $uri->base();
}
else {
return base64_decode($return);
}
}
/**
* Function that allows child controller access to model data
* after the data has been saved.
* Here used to trigger the jem plugins, mainly the mailer.
*
* @param JModel(Legacy) $model The data model object.
* @param array $validData The validated data.
*
* @return void
*/
protected function _postSaveHook($model, $validData = array())
{
$task = $this->getTask();
if ($task == 'save') {
$isNew = $model->getState('editevent.new');
$this->_id = $model->getState('editevent.id');
// trigger all jem plugins
PluginHelper::importPlugin('jem');
$dispatcher = JemFactory::getDispatcher();
$dispatcher->triggerEvent('onEventEdited', array($this->_id, $isNew));
// but show warning if mailer is disabled
if (!PluginHelper::isEnabled('jem', 'mailer')) {
Factory::getApplication()->enqueueMessage(Text::_('COM_JEM_GLOBAL_MAILERPLUGIN_DISABLED'), 'notice');
}
}
}
/**
* Method to save a record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if successful, false otherwise.
*/
public function save($key = null, $urlVar = 'a_id')
{
// echo "<pre/>";print_R($_POST);die;
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$result = parent::save($key, $urlVar);
// If ok, redirect to the return page.
if ($result) {
$this->setRedirect($this->getReturnPage());
}
return $result;
}
/**
* Saves the registration to the database
*/
public function userregister()
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$id = Factory::getApplication()->input->getInt('rdid', 0);
$rid = Factory::getApplication()->input->getInt('regid', 0);
// Get the model
$model = $this->getModel('Event', 'JemModel');
$reg = $model->getUserRegistration($id);
if ($reg !== false && $reg->id != $rid) {
$msg = Text::_('COM_JEM_ALREADY_REGISTERED') . ' [id: ' . $reg->id . ']';
$this->setRedirect(Route::_(JemHelperRoute::getEventRoute($id), false), $msg, 'error');
$this->redirect();
return;
}
$model->setId($id);
$register_id = $model->userregister();
if (!$register_id)
{
$msg = $model->getError();
$this->setRedirect(Route::_(JemHelperRoute::getEventRoute($id), false), $msg, 'error');
$this->redirect();
return;
}
JemHelper::updateWaitingList($id);
PluginHelper::importPlugin('jem');
$dispatcher = JemFactory::getDispatcher();
$dispatcher->triggerEvent('onEventUserRegistered', array($register_id, $reg->places));
$cache = Factory::getCache('com_jem');
$cache->clean();
$msg = Text::_('COM_JEM_REGISTRATION_THANKS_FOR_RESPONSE');
$this->setRedirect(Route::_(JemHelperRoute::getEventRoute($id), false), $msg);
}
/**
* Deletes a registered user
*/
public function delreguser()
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$id = Factory::getApplication()->input->getInt('rdid', 0);
// Get/Create the model
$model = $this->getModel('Event', 'JemModel');
$model->setId($id);
$model->delreguser();
JemHelper::updateWaitingList($id);
PluginHelper::importPlugin('jem');
$dispatcher = JemFactory::getDispatcher();
$dispatcher->triggerEvent('onEventUserUnregistered', array($id));
$cache = Factory::getCache('com_jem');
$cache->clean();
$msg = Text::_('COM_JEM_UNREGISTERED_SUCCESSFULL');
$this->setRedirect(Route::_(JemHelperRoute::getEventRoute($id), false), $msg);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,165 @@
<?php
/**
* @package JEM
* @copyright (C) 2013-2024 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license https://www.gnu.org/licenses/gpl-3.0 GNU/GPL
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
require_once (JPATH_COMPONENT_SITE.'/classes/controller.form.class.php');
/**
* Event Controller
*/
class JemControllerMailto extends JemControllerForm
{
// protected $view_item = 'editevent';
// protected $view_list = 'eventslist';
protected $_id = 0;
public function getModel($name = 'mailto', $prefix = '', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
public function save($key = NULL, $urlVar = NULL){
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));
$app = Factory::getApplication();
$model = $this->getModel('mailto');
$data = $model->getData();
$uri = Uri::getInstance();
$form = $model->getForm();
$post_link = $this->input->post->get('link', '', 'post');
$currentUri = $uri->toString() . '&link='.$post_link;
if (!$form)
{
$app->enqueueMessage($model->getError(), 'error');
return false;
}
if (!$model->validate($form, $data))
{
$errors = $model->getErrors();
foreach ($errors as $error)
{
$errorMessage = $error;
if ($error instanceof Exception)
{
$errorMessage = $error->getMessage();
}
$app->enqueueMessage($errorMessage, 'error');
}
$this->setRedirect($currentUri);
}
$headers = array (
'Content-Type:',
'MIME-Version:',
'Content-Transfer-Encoding:',
'bcc:',
'cc:'
);
foreach ($data as $key => $value)
{
foreach ($headers as $header)
{
if (is_string($value) && strpos($value, $header) !== false)
{
$app->enqueueMessage(403, 'error');
}
}
}
unset($headers, $fields);
$siteName = $app->get('sitename');
$link = JemMailtoHelper::validateHash($this->input->post->get('link', '', 'post'));
// Verify that this is a local link
if (!$link || !Uri::isInternal($link))
{
// Non-local url...
$app->enqueueMessage( Text::_('COM_JEM_MAILTO_EMAIL_NOT_SENT'), 'error');
$this->setRedirect($currentUri);
}
$subject_default = Text::sprintf('COM_JEM_MAILTO_SENT_BY', $data['sender']);
$subject = $data['subject'] !== '' ? $data['subject'] : $subject_default;
$error = false;
if (!$data['emailto'] || !JMailHelper::isEmailAddress($data['emailto']))
{
$error = Text::sprintf('COM_JEM_MAILTO_EMAIL_INVALID', $data['emailto']);
$app->enqueueMessage( $error, 'error');
}
// Check for a valid from address
if (!$data['emailfrom'] || !JMailHelper::isEmailAddress($data['emailfrom']))
{
$error = Text::sprintf('COM_JEM_MAILTO_EMAIL_INVALID', $data['emailfrom']);
$app->enqueueMessage( $error, 'error');
}
if ($error)
{
return $this->setRedirect($currentUri);
return false;
}
$msg = Text::_('COM_JEM_MAILTO_EMAIL_MSG');
$body = sprintf($msg, $siteName, $data['sender'], $data['emailfrom'], $link);
// To send we need to use punycode.
$data['emailfrom'] = JStringPunycode::emailToPunycode($data['emailfrom']);
$data['emailfrom'] = JMailHelper::cleanAddress($data['emailfrom']);
$data['emailto'] = JStringPunycode::emailToPunycode($data['emailto']);
$from = array($data['emailfrom'], $data['sender']);
// Clean the email data
$subject = JMailHelper::cleanSubject($subject);
$body = JMailHelper::cleanBody($body);
//--------------start new code ------------
$mailer = Factory::getMailer();
$mailer->setSender($from);
$mailer->addRecipient($data['emailto']);
$mailer->setSubject($subject);
$mailer->setBody($body);
$mailer->isHTML();
try{
if (!$mailer->send())
{
$app->enqueueMessage( Text::_('COM_JEM_MAILTO_EMAIL_NOT_SENT'), 'error');
$this->setRedirect($currentUri);
return false;
}
}catch(Exception $e){
$app->enqueueMessage($e->getMessage(), 'notice');
$this->setRedirect($currentUri);
return false;
}
$currentUri .= '&layout=sent';
$this->setRedirect($currentUri);
//--------------end new code ------------
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
* @package JEM
* @copyright (C) 2013-2024 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license https://www.gnu.org/licenses/gpl-3.0 GNU/GPL
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
/**
* JEM Component Myevents Controller
*
* @package JEM
*
*/
class JemControllerMyevents extends BaseController
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Logic to publish events
*
* @access public
* @return void
*/
public function publish()
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$app = Factory::getApplication();
$input = $app->input;
$cid = $input->get('cid', array(), 'array');
if (empty($cid)) {
Factory::getApplication()->enqueueMessage(Text::_('COM_JEM_SELECT_ITEM_TO_PUBLISH'), 'notice');
$this->setRedirect(JemHelperRoute::getMyEventsRoute());
return;
}
$model = $this->getModel('myevents');
if (!$model->publish($cid, 1)) {
echo "<script> alert('".$model->getError()."'); window.history.go(-1); </script>\n";
}
$total = count($cid);
$msg = $total.' '.Text::_('COM_JEM_EVENT_PUBLISHED');
$this->setRedirect(JemHelperRoute::getMyEventsRoute(), $msg);
}
/**
* Logic for canceling an event and proceed to add a venue
*/
public function unpublish()
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$app = Factory::getApplication();
$input = $app->input;
$cid = $input->get('cid', array(), 'array');
if (empty($cid)) {
Factory::getApplication()->enqueueMessage(Text::_('COM_JEM_SELECT_ITEM_TO_UNPUBLISH'), 'notice');
$this->setRedirect(JemHelperRoute::getMyEventsRoute());
return;
}
$model = $this->getModel('myevents');
if (!$model->publish($cid, 0)) {
echo "<script> alert('".$model->getError()."'); window.history.go(-1); </script>\n";
}
$total = count($cid);
$msg = $total.' '.Text::_('COM_JEM_EVENT_UNPUBLISHED');
$this->setRedirect(JemHelperRoute::getMyEventsRoute(), $msg);
}
/**
* Logic to trash events
*
* @access public
* @return void
*/
public function trash()
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$app = Factory::getApplication();
$input = $app->input;
$cid = $input->get('cid', array(), 'array');
if (empty($cid)) {
Factory::getApplication()->enqueueMessage(Text::_('COM_JEM_SELECT_ITEM_TO_TRASH'), 'notice');
$this->setRedirect(JemHelperRoute::getMyEventsRoute());
return;
}
$model = $this->getModel('myevents');
if (!$model->publish($cid, -2)) {
echo "<script> alert('".$model->getError()."'); window.history.go(-1); </script>\n";
}
$total = count($cid);
$msg = $total.' '.Text::_('COM_JEM_EVENT_TRASHED');
$this->setRedirect(JemHelperRoute::getMyEventsRoute(), $msg);
}
}
?>

View File

@ -0,0 +1,97 @@
<?php
/**
* @package JEM
* @copyright (C) 2013-2024 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license https://www.gnu.org/licenses/gpl-3.0 GNU/GPL
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
/**
* JEM Component Myvenues Controller
*
* @package JEM
*
*/
class JemControllerMyvenues extends BaseController
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Logic to publish venues
*
* @access public
* @return void
*/
public function publish()
{
$this->setStatus(1, 'COM_JEM_VENUE_PUBLISHED');
}
/**
* Logic unpublish venues
*/
public function unpublish()
{
$this->setStatus(0, 'COM_JEM_VENUE_UNPUBLISHED');
}
/**
* Logic to trash venues - NOT SUPPORTED YET
*
* @access public
* @return void
*/
/*
public function trash()
{
$this->setStatus(-2, 'COM_JEM_VENUE_TRASHED');
}
*/
/**
* Logic to publish/unpublish/trash venues
*
* @access protected
* @return void
*/
protected function setStatus($status, $message)
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$app = Factory::getApplication();
$input = $app->input;
$cid = $input->get('cid', array(), 'array');
if (empty($cid)) {
Factory::getApplication()->enqueueMessage(Text::_('COM_JEM_SELECT_ITEM_TO_PUBLISH'), 'notice');
$this->setRedirect(JemHelperRoute::getMyVenuesRoute());
return;
}
$model = $this->getModel('myvenues');
if (!$model->publish($cid, $status)) {
echo "<script> alert('" . $model->getError() . "'); window.history.go(-1); </script>\n";
}
$total = count($cid);
$msg = $total . ' ' . Text::_($message);
$this->setRedirect(JemHelperRoute::getMyVenuesRoute(), $msg);
}
}
?>

View File

@ -0,0 +1,275 @@
<?php
/**
* @package JEM
* @copyright (C) 2013-2024 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license https://www.gnu.org/licenses/gpl-3.0 GNU/GPL
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Session\Session;
require_once (JPATH_COMPONENT_SITE.'/classes/controller.form.class.php');
/**
* Venue Controller
*/
class JemControllerVenue extends JemControllerForm
{
protected $view_item = 'editvenue';
protected $view_list = 'venues';
/**
* Method to add a new record.
*
* @return boolean True if the event can be added, false if not.
*/
public function add()
{
if (!parent::add()) {
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
}
}
/**
* Method override to check if you can add a new record.
*
* @param array An array of input data.
*
* @return boolean
*/
protected function allowAdd($data = array())
{
// Initialise variables.
$user = JemFactory::getUser();
// venues don't have a category yet
//$categoryId = \Joomla\Utilities\ArrayHelper::getValue($data, 'catid', Factory::getApplication()->input->getInt('catid', 0), 'int');
if ($user->can('add', 'venue')) {
return true;
}
// In the absense of better information, revert to the component permissions.
return parent::allowAdd();
}
/**
* Method override to check if you can edit an existing record.
* @todo: check if the user is allowed to edit/save
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*/
protected function allowEdit($data = array(), $key = 'id')
{
// Initialise variables.
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$user = JemFactory::getUser();
if (isset($data['created_by'])) {
$created_by = $data['created_by'];
} else {
$record = $this->getModel()->getItem($recordId);
$created_by = isset($record->created_by) ? $record->created_by : false;
}
if ($user->can('edit', 'venue', $recordId, $created_by)) {
return true;
}
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
/**
* Method to cancel an edit.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return Boolean True if access level checks pass, false otherwise.
*/
public function cancel($key = 'a_id')
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
parent::cancel($key);
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
}
/**
* Method to edit an existing record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if access level check and checkout passes, false otherwise.
*/
public function edit($key = null, $urlVar = 'a_id')
{
$result = parent::edit($key, $urlVar);
return $result;
}
/**
* Method to add a new record based on existing record.
*
* @return boolean True if the venue can be added, false if not.
*/
public function copy()
{
if (!parent::add()) {
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
}
}
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*/
public function getModel($name = 'editvenue', $prefix = '', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
/**
* Gets the URL arguments to append to an item redirect.
*
* @param int $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the id.
*
* @return string The arguments to append to the redirect URL.
*/
protected function getRedirectToItemAppend($recordId = null, $urlVar = 'a_id')
{
// Need to override the parent method completely.
$jinput = Factory::getApplication()->input;
$tmpl = $jinput->getCmd('tmpl', '');
$layout = $jinput->getCmd('layout', 'edit');
$task = $jinput->getCmd('task', '');
$append = '';
// Setup redirect info.
if ($tmpl) {
$append .= '&tmpl='.$tmpl;
}
$append .= '&layout=edit';
if ($recordId) {
$append .= '&'.$urlVar.'='.$recordId;
}
elseif (($task === 'copy') && ($fromId = $jinput->getInt('a_id', 0))) {
$append .= '&from_id='.$fromId;
}
$itemId = $jinput->getInt('Itemid', 0);
//$catId = $jinput->getInt('catid', 0);
$return = $this->getReturnPage();
if ($itemId) {
$append .= '&Itemid='.$itemId;
}
//if ($catId) {
// $append .= '&catid='.$catId;
//}
if ($return) {
$append .= '&return='.base64_encode($return);
}
return $append;
}
/**
* Get the return URL.
*
* If a "return" variable has been passed in the request
*
* @return string The return URL.
*/
protected function getReturnPage()
{
$uri = Uri::getInstance();
$return = Factory::getApplication()->input->get('return', null, 'base64');
if (empty($return) || !Uri::isInternal(base64_decode($return))) {
return $uri->base();
}
else {
return base64_decode($return);
}
}
/**
* Function that allows child controller access to model data
* after the data has been saved.
* Here used to trigger the jem plugins, mainly the mailer.
*
* @param JModel(Legacy) $model The data model object.
* @param array $validData The validated data.
*
* @return void
*/
protected function _postSaveHook($model, $validData = array())
{
$task = $this->getTask();
if ($task == 'save') {
$isNew = $model->getState('editvenue.new');
$id = $model->getState('editvenue.id');
// trigger all jem plugins
PluginHelper::importPlugin('jem');
$dispatcher = JemFactory::getDispatcher();
$dispatcher->triggerEvent('onVenueEdited', array($id, $isNew));
// but show warning if mailer is disabled
if (!PluginHelper::isEnabled('jem', 'mailer')) {
Factory::getApplication()->enqueueMessage(Text::_('COM_JEM_GLOBAL_MAILERPLUGIN_DISABLED'), 'notice');
}
}
}
/**
* Method to save a record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean True if successful, false otherwise.
*/
public function save($key = null, $urlVar = 'a_id')
{
// Check for request forgeries
Session::checkToken() or jexit('Invalid Token');
$result = parent::save($key, $urlVar);
// If ok, redirect to the return page.
if ($result) {
$this->setRedirect($this->getReturnPage());
}
return $result;
}
}