<?php
defined('_JEXEC') or die;

class Plgcl_hlusers extends JPlugin
{
    private $config=null;

	public function __construct(& $subject, $config)
	{
		parent::__construct($subject, $config);
		// Include Field Class & Field Model
		/*foreach (glob(JPATH_ADMINISTRATOR . '/components/com_jsn/helpers/fields/*.php') as $filename) {
			require_once $filename;
		}
		JFormHelper::addFieldPath(JPATH_ADMINISTRATOR.'/components/com_jsn/models/fields');
		JFormHelper::addRulePath(JPATH_ADMINISTRATOR.'/components/com_jsn/models/rule');*/
		
		// Load Config
		$this->config = JComponentHelper::getParams('com_jsn');

		// Activate email when user change it
		require_once(JPATH_ADMINISTRATOR.'/components/com_jsn/defines.php');
		if($this->config->get('activatenewmail',0) && JSN_TYPE != 'free')
		{
			$lang = JFactory::getLanguage();
			$lang->load('com_jsn');
			$this->activateNewEmail();
		}
	}
        
        public function onUserAfterSave($data, $isNew, $result, $error)
	{
		$userId = JArrayHelper::getValue($data, 'id', 0, 'int');
                
                $db = JFactory::getDbo();
                
                $query2 = $db->getQuery(true);
                $query2->select('a.*')->from('#__jsn_users AS a')->where('a.id = '.$userId);
                $db->setQuery( $query2 );
		$result = $db->loadObject();
					
                $query3="INSERT INTO cl_hlusers.users(strName,strTel, nCtrID, nManagerID)
                    VALUES(".$result->firstname.", ".$result->phone.", ".$result->country.", 0)";
		$db->setQuery($query3);
		$db->execute(); 
        }
}
?>