%PDF- %PDF-
| Direktori : /home1/lightco1/www/lightingrepublic.com.au/components/com_simpleregistration/ |
| Current File : //home1/lightco1/www/lightingrepublic.com.au/components/com_simpleregistration/controller.php |
<?php
/**
* @version controller.php 2013-08-29 20:25:00 UTC zanardi
* @package GiBi SimpleRegistration
* @author GiBiLogic
* @authorEmail info@gibilogic.com
* @authorUrl http://www.gibilogic.com
* @copyright Copyright (C) 2011-2013 GiBiLogic. All rights reserved.
* @license GNU/GPL v2 or later
*/
defined('_JEXEC') or die('The way is shut');
jimport('joomla.application.component.controller');
jimport('joomla.html.parameter');
class SimpleregistrationController extends JControllerLegacy
{
private $url = 'index.php?option=com_simpleregistration&view=registrationform';
function __construct($config=array())
{
parent::__construct($config);
$this->app = JFactory::getApplication();
$this->db = JFactory::getDbo();
}
// show registration form
function display()
{
if (!$this->app->input->get('view')) {
$this->app->input->set('view', 'registrationform');
}
parent::display(false);
}
// create new user
function save()
{
if ($this->app->input->get('return','')) {
$this->url = base64_decode(JFactory::getApplication()->input->get('return',''));
}
jimport('joomla.filter.filterinput');
$filter = JFilterInput::getInstance();
$email = $filter->clean($this->app->input->getString('email'));
// Check that e-mail is not already taken
$query = 'SELECT COUNT(*) FROM #__users WHERE email = ' . $this->db->quote($email);
$this->db->setQuery($query);
if ($this->db->loadResult() > 0) {
$message = JText::_('COM_SIMPLEREGISTRATION_EMAIL_EXIST');//"COM_SIMPLEREGISTRATION_EMAIL_EXIST";
$type = "error";
$url = "index.php?option=com_simpleregistration&view=registrationform&Itemid=157";
$this->setRedirect($url, $message, $type);
//$this->setRedirect($this->url, $message, $type);
return false;
}
jimport('joomla.application.component.helper');
$params = JComponentHelper::getParams('com_simpleregistration');
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
$lang = JFactory::getLanguage();
$lang->load('com_user');
$lang->load('com_users');
if (!JMailHelper::isEmailAddress($email)) {
JError::raiseWarning('', JText::_('SIMPLEREGISTRATION_EMAIL_NOT_VALID'));
return false;
}
$user = JFactory::getUser(0);
$usersParams = JComponentHelper::getParams('com_users');
$usertype = $usersParams->get('new_usertype');
$name = $filter->clean(JRequest::getVar('name'));
$data = array();
$data['name'] = $name;
$data['email'] = $email;
$data['email1'] = $email;
$data['gid'] = $usertype;
$data['sendEmail'] = 0;
if ($params->get('extractusername', 0) == 1) {
$tmp_array = explode('@', $email);
$data['username'] = $tmp_array[0];
}
else {
$data['username'] = $email;
}
if ($params->get('requestpassword', 0) == 0) {
$password = JUserHelper::genRandomPassword();
}
else {
$password = $filter->clean(JRequest::getVar('password'));
}
$data['password'] = $password;
$data['password1'] = $password;
$data['password2'] = $password;
require_once(JPATH_COMPONENT. '/models/registration.php');
$model = new SimpleregistrationModelRegistration();
$activation = $model->register($data);
/****************DK**********************/
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query = "select id from #__users where email='".$_REQUEST['email']."' order by id DESC LIMIT 1";
$db->setQuery($query);
$results = $db->loadObject();
$last_id = $results->id;
/* USER CAN DIRECTLY ACTIVATED*/
//$query3 = "UPDATE #__users SET block=0,activation='' WHERE id='".$last_id."'";
// $query3 = "UPDATE #__users SET block=0 WHERE id='".$last_id."'";
//$db->setQuery($query3);
//$result = $db->query();
/************* FILE UPLOAD *****************/
//Retrieve file details from uploaded file, sent from upload form
$file = JRequest::getVar('file_upload', null, 'files', 'array');
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name']);
//Set up the source and destination of the file
$src = $file['tmp_name'];
$ext =substr($filename,strrpos($filename,'.'));
$newfilename = time().rand(1,9999).$ext;
$dest = JPATH_BASE ."/media/userdata" . DS . $newfilename;
//echo $dest = JPATH_COMPONENT . DS . "uploads" . DS . $newfilename;
if( JFile::upload($src, $dest) )
{
//JFile::upload($src, $dest2);
//$dest2 = "userdata" . DS . $newfilename;
//echo $src=$_FILES['file_upload']['tmp_name'];
//echo move_uploaded_file($src,$dest2);
//exit;
}
else{
exit;
}
/****************** END FILE UPLOAD ***********************/
/******insert other data*/
//table columns
$query1 = "insert into #__user_other_info (user_id,pfrom,pdate,name,address,country,message,preceipt_file_name) VALUES ('".$last_id."','".$_REQUEST['pfrom']."','".$_REQUEST['pdate']."','".$_REQUEST['name']."','".$_REQUEST['address']."','".$_REQUEST['country']."','".$_REQUEST['message']."','".$newfilename."')";
$db->setQuery($query1);
$db->query();
foreach($_REQUEST['pcode'] as $key=>$value)
{
$query2 = "insert into #__user_product_details (user_id,pcode,qty,shop_name,purchase_date,receipt_file_name) VALUES ('".$last_id."','".$_REQUEST['pcode'][$key]."','".$_REQUEST['qty'][$key]."','".$_REQUEST['pfrom']."','".$_REQUEST['pdate']."','".$newfilename."')";
if($value != NULL) {
$db->setQuery($query2);
$db->query();
}
}
#### MAIL ####
$mailer = JFactory::getMailer();
//sender email
$sender = array( $_REQUEST['email'],$_REQUEST['name'] );
$mailer->setSender($sender);
//Recipient email
$recipient = "info@lightingrepublic.hk";
$mailer->addRecipient($recipient);
$body = "Purchased From:".$_REQUEST['pfrom']."\n"."Date:".$_REQUEST['date']."\n"."Name:".$_REQUEST['name']."\n"."Address:".$_REQUEST['address']."\n"."Country:".$_REQUEST['country']."\n"."Email:".$_REQUEST['email']."\n"."Message:".$_REQUEST['message']."\n";
$mailer->setSubject('New User Registration');
$mailer->setBody($body);
//file attached
$mailer->addAttachment($_REQUEST['file']['temp']);
$send = $mailer->Send();
#### END MAIL ####
/*$parts = explode("@",$_REQUEST['email']);
$username = $parts[0];*/
/****************** END DK ************************/
switch ($activation) {
case 'useractivate':
$message = JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE');
break;
case 'adminactivate':
$message = JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY');
break;
default:
$message = "Username: ".$data['username']."<br/>"."Email: ".$data['email']."<br/><br/>".JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS');
}
if ($params->get('autologin', 0) == 1) {
$credentials = array("username" => $data['username'], "password" => $data['password']);
$this->app->login($credentials);
}
//$this->setRedirect($this->url, $message);
//$url = "become-a-citizen&Itemid=157";
$url = "index.php?option=com_simpleregistration&view=registrationform";
$this->setRedirect($url, $message);
}
function chkUsername() {
if( $username = JRequest::getVar( 'username', '', 'get' ) ) {
$db =& JFactory::getDBO();
$query = 'SELECT id FROM #__users'
. ' WHERE username = '.$db->Quote( $username );
$db->setQuery( $query );
$result=$db->loadObject();
if ($result) {
$response['html'] = $username.JText::_( 'COM_AA4J_UNAME_NOT_AVAILABLE' );
$response['msg'] = 'false';
} else {
$response['html'] = JText::_( 'COM_AA4J_UNAME_AVAILABLE' );
$response['msg'] = 'true';
}
}
else {
$response['html'] = JText::_( 'COM_AA4J_INVALID' );
$response['msg'] = 'false';
}
//header('Content-type: application/json');
echo (json_encode( $response )) ;
//echo "asdfasdfasdfasdf";
return true;
}
function chkSkucode() {
if( $skucode = JRequest::getVar( 'skucode', '', 'get' ) ) {
$db =& JFactory::getDBO();
$query = 'SELECT virtuemart_product_id FROM #__virtuemart_products'
. ' WHERE product_sku = '.$db->Quote( $skucode );
$db->setQuery( $query );
$result=$db->loadObject();
if ($result) {
$response['html'] = "ok";
$response['msg'] = 'true';
} else {
$response['html'] = "Invalid Code";
$response['msg'] = 'false';
}
}
else {
$response['html'] = "Invalid Code";
$response['msg'] = 'false';
}
echo (json_encode( $response )) ;
return true;
}
}