%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.bkp |
<?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 = "COM_SIMPLEREGISTRATION_EMAIL_EXIST"; $type = "error"; $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."'"; $db->setQuery($query3); $result = $db->query(); /******insert other data*/ //table columns $query1 = "insert into #__user_other_info (user_id,pfrom,pdate,name,address,country,message) VALUES ('".$last_id."','".$_REQUEST['pfrom']."','".$_REQUEST['pdate']."','".$_REQUEST['name']."','".$_REQUEST['address']."','".$_REQUEST['country']."','".$_REQUEST['message']."')"; $db->setQuery($query1); $db->query(); foreach($_REQUEST['pcode'] as $key=>$value) { $query2 = "insert into #__user_product_details (user_id,pcode,qty) VALUES ('".$last_id."','".$_REQUEST['pcode'][$key]."','".$_REQUEST['qty'][$key]."')"; 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 = "index.php?option=com_simpleregistration&view=registrationform&Itemid=157"; $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; } }