| Current Path : /home/digilove/public_html/components/com_marketplace/controllers/ |
| Current File : /home/digilove/public_html/components/com_marketplace/controllers/mpregistration.php |
<?php
/**
* Marketplace - Component Marketplace
* ******************************************************************
*
* PHP version 7.0
*
* @category Component
* @package Joomla
* @author WebKul software private limited <support@webkul.com>
* @copyright 2010 WebKul software private limited
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @version GIT:5.2
* @filesource http://store.webkul.com
* @link Technical Support: webkul.uvdesk.com
* ******************************************************************
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');
jimport('joomla.filesystem.file');
if (!class_exists('VmConfig')) {
include JPATH_ADMINISTRATOR.'/components/com_virtuemart/helpers/config.php';
}
VmConfig::loadConfig();
if (!class_exists('shopFunctionsF')) {
include JPATH_SITE.'/components/com_virtuemart/helpers/shopfunctionsf.php';
}
if (!class_exists('MarketplaceHelper')) {
include JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.
DIRECTORY_SEPARATOR.'com_marketplace'.DIRECTORY_SEPARATOR.'helpers'.
DIRECTORY_SEPARATOR.'marketplace.php';
}
/**
* MarketplaceControllerMpregistration class
*
* @category Component
* @package Joomla
* @author WebKul software private limited <support@webkul.com>
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @link Technical Support: webkul.uvdesk.com
*/
class MarketplaceControllerMpregistration extends JControllerLegacy
{
/**
* Display function
*
* @param boolean $cachable var
* @param [type] $urlparams var
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
parent::display();
}
/**
* GetRegistrationState function
*
* @return void
*/
function getRegistrationState()
{
$db = JFactory::getDBO();
$app = JFactory::getApplication();
$_input = $app->input;
$id = $_input->getInt('ID', 0);
$query=$db->getQuery(true);
$query->select($db->quoteName('virtuemart_state_id'))
->select($db->quoteName('state_name'))
->select($db->quoteName('virtuemart_country_id'))
->from($db->quoteName('#__virtuemart_states'))
->where($db->quoteName('virtuemart_country_id')."=".$db->quote($id));
$db->setQuery($query);
try{
$state_details=$db->loadObjectList();
}catch(Exception $e){
JFactory::getApplication()->enqueueMessage(
$e->getMessage(),
'error'
);
return false;
}
$html = "";
foreach ($state_details as $state) {
$selectedstate='';
if ($state->virtuemart_state_id) {
$selectedstate='selected';
}
$html.= '<option class="country'.$state->virtuemart_country_id.
'" value="'.$state->virtuemart_state_id.'" >'.$state->state_name
.'</option>';
}
echo $html;
JFactory::getApplication()->close();
}
/**
* Undocumented function
*
* @return void
*/
function mpregistrationSave()
{
VmConfig::loadConfig();
$mpregmenuid=plgSystemMarketplace::getMenuId(
'index.php?option=com_marketplace&view=mpregistration'
);
JSession::checkToken() or die('Invalid Token');
$app = JFactory::getApplication();
$jinput=JFactory::getApplication()->input;
$model=$this->getModel('Mpregistration', 'MarketplaceModel');
$requestData = $this->input->post->get('jform', array(), 'array');
$form = $model->getForm();
// To load language of com_users for Joomla Mail
$lang = JFactory::getLanguage();
$extension = 'com_users';
$base_dir = JPATH_SITE;
$lang->load($extension, $base_dir);
$params = JComponentHelper::getParams('com_marketplace');
$recaptcha_enable=trim($params->get('recaptcha_enable'));
$captcha=(boolean)$params->get('captcha');
$plugin = JPluginHelper::getPlugin('captcha', $params->get('captcha'));
if ($recaptcha_enable && $captcha && !empty($plugin)) {
$data = $model->validate($form, $requestData);
if ($data === false) {
$errors = $model->getErrors();
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
if ($errors[$i] instanceof Exception) {
$app->enqueueMessage(
$errors[$i]->getMessage(),
'warning'
);
} else {
$app->enqueueMessage(
$errors[$i],
'warning'
);
}
}
/*Important*/
$this->setRedirect(
JRoute::_(
'index.php?option=com_marketplace&view=mpregis'.
'tration&Itemid='.$mpregmenuid,
false
)
);
return false;
}
}
$postVar = $this->input->getArray($requestData);
$existUser = $model->getJoomlaUserByEmail($postVar['email']);
$postVar["reg_seller"] = $this->input->getInt('reg_seller', 0);
$postVar['existUser'] = $existUser;
if (!$postVar["reg_seller"]) {
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_users/models/');
$user_model = $this->getModel('Registration', 'UsersModel');
$data=array(
"name" => $postVar["name"],
"username" => $postVar["username"],
"password1" => $postVar["password"],
"password2" => $postVar["password2"],
"email1" => $postVar["email"],
"email2" => $postVar["email"]
);
$res=$user_model->register($data);
$user_res = MarketplaceHelper::getUserIdByEmail($postVar["email"]);
$postVar['seller_id'] = $user_res;
}
$customer_id = $postVar['seller_id'];
if ((int)$customer_id && !$model->saveItem($postVar)) {
$session =JFactory::getSession();
$session->set('username', $postVar['username']);
$session->set('email', $postVar['email']);
$session->set('password', $postVar['password']);
$session->set('password2', $postVar['password2']);
$session->set('name', $postVar['name']);
$session->set('company', $postVar['company']);
$session->set(
'virtuemart_country_id',
$postVar['virtuemart_country_id']
);
$session->set('virtuemart_state_id', $postVar['virtuemart_state_id']);
$session->set('first_name', $postVar['first_name']);
$session->set('last_name', $postVar['last_name']);
$session->set('title', $postVar['title']);
$session->set('address_1', $postVar['address_1']);
$session->set('city', $postVar['city']);
$session->set('zip', $postVar['zip']);
$session->set('phone_1', $phone1);
$this->setRedirect(
JRoute::_(
'index.php?option=com_marketplace&view=mpr'.
'egistration&Itemid='.$mpregmenuid,
false
)
);
} else {
$config=JFactory::getConfig();
if (isset($existUser)) {
$body = trim($params->get('mp_temp_convert_seller'));
$subject = trim($params->get('mp_sub_convert_seller'));
$mailer=JFactory::getMailer();
$mailer->setSender($config->get('mailfrom'));
$mailer->addRecipient($postVar['email']);
$mailer->isHtml(true);
/* Replacing Value in Templates*/
$body = str_replace(
'{[USER_NAME]}', ucwords($postVar['username']),
$body
);
$subject= str_replace(
'{[USER_NAME]}', ucwords($postVar['username']),
$subject
);
$body = str_replace(
'{[SELLER_SCREEN]}', ucwords($postVar['name']),
$body
);
$subject= str_replace(
'{[SELLER_SCREEN]}', ucwords($postVar['name']),
$subject
);
$body = str_replace(
'{[SITE_FROM_NAME]}', ucwords($config->get('fromname')),
$body
);
$mailer->setSubject($subject);
$mailer->setBody($body);
$mailer->send();
JFactory::getApplication()->enqueueMessage(
JText::_("COM_MARKETPLACE_CONVERT_SELLER"),
'success'
);
}
$body = trim($params->get('mp_temp_seller_register'));
$subject = trim($params->get('mp_sub_seller_register'));
/* Replacing Value in Templates*/
$body = str_replace(
'{[USER_NAME]}', ucwords($postVar['username']),
$body
);
$subject= str_replace(
'{[USER_NAME]}', ucwords($postVar['username']),
$subject
);
$body = str_replace(
'{[SELLER_SCREEN]}', ucwords($postVar['name']),
$body
);
$subject= str_replace(
'{[SELLER_SCREEN]}', ucwords($postVar['name']),
$subject
);
$body = str_replace(
'{[SITE_FROM_NAME]}', ucwords($config->get('fromname')),
$body
);
$body = str_replace(
'{[SELLERS_VIEW_ADMIN]}', JURI::root().
'administrator/index.php?option=com_marketplace&view=marketplace',
$body
);
$mailer=JFactory::getMailer();
$mailer->setSender($postVar['email']);
$mailer->addRecipient($config->get('mailfrom'));
$mailer->isHtml(true);
$mailer->setSubject($subject);
$mailer->setBody($body);
$mailer->send();
$session =JFactory::getSession();
$session->set('username', '');
$session->set('email', '');
$session->set('password', '');
$session->set('password2', '');
$session->set('name', '');
$session->set('company', '');
$session->set('virtuemart_country_id', '');
$session->set('virtuemart_state_id', '');
$session->set('first_name', '');
$session->set('last_name', '');
$session->set('title', '');
$session->set('address_1', '');
$session->set('city', '');
$session->set('zip', '');
$session->set('phone_1', '');
$this->setRedirect(
JRoute::_(
'index.php?option=com_marketplace&view=mpregistration&la'
.'yout=regmp&customer_id='.$customer_id,
false
)
);
}
}
}