Example #1
0
 function display($tpl = null)
 {
     $tmpl = JRequest::getVar('tmpl');
     if (empty($tmpl)) {
         JRequest::setVar('tmpl', 'component');
     }
     $user = JFactory::getUser();
     if (!oseMscPublic::isUserAdmin($user)) {
         $app = JFactory::getApplication('ADMIN');
         $app->redirect('index.php', 'You do not has access to this page');
     }
     $model = $this->getModel();
     $model->checkViewExists();
     $this->loadViewJs();
     $this->loadGridJs();
     $OSESoftHelper = new OSESoftHelper();
     $footer = $OSESoftHelper->renderOSETM();
     $this->assignRef('footer', $footer);
     $preview_menus = $OSESoftHelper->getPreviewMenus();
     $this->assignRef('preview_menus', $preview_menus);
     $this->assignRef('OSESoftHelper', $OSESoftHelper);
     $title = JText::_('OSE Membership™ Configuration');
     $this->assignRef('title', $title);
     parent::display($tpl);
 }
 public static function save()
 {
     $result = array();
     $post = JRequest::get('post');
     $member_id = JRequest::getInt('member_id');
     $mailing = array();
     foreach ($post as $key => $value) {
         if (strstr($key, 'mailing_')) {
             $mailingKey = preg_replace('/mailing_/', '', $key, 1);
             $mailing[$mailingKey] = $value;
         }
     }
     if (empty($mailing)) {
         $result['success'] = true;
         $result['title'] = JText::_('Done');
         $result['content'] = JText::_('Nothing need to save!');
     }
     //oseExit($billinfo);
     $db = oseDB::instance();
     //$member_id = JRequest::getInt('member_id',0);
     $query = " SELECT count(*) FROM `#__osemsc_mailing` WHERE user_id='{$member_id}'";
     $db->setQuery($query);
     $num = $db->loadResult();
     //oseExit($db->_sql);
     if (empty($num)) {
         $keys = array_keys($mailing);
         $keys = '`' . implode('`,`', $keys) . '`';
         $fields = $db->getTableFields('#__osemsc_mailing');
         foreach ($mailing as $key => $value) {
             $my = JFactory::getUser();
             if (oseMscPublic::isUserAdmin($my)) {
                 if (!isset($fields['#__osemsc_mailing'][$key])) {
                     $query = "ALTER TABLE `#__osemsc_mailing` ADD `{$key}` TEXT NULL DEFAULT NULL";
                     $db->setQuery($query);
                     if (!oseDB::query()) {
                         $result['success'] = false;
                         $result['title'] = JText::_('Error');
                         $result['content'] = JText::_('Fail Saving Mailing Info.');
                     }
                 }
             }
         }
         $values = array();
         foreach ($mailing as $key => $value) {
             $values[] = $db->Quote($value);
         }
         $values = implode(',', $values);
         $query = "INSERT INTO `#__osemsc_mailing` (`user_id`,{$keys}) VALUES ('{$member_id}',{$values});";
     } else {
         foreach ($mailing as $key => $value) {
             $values[] = "`{$key}`=" . $db->Quote($value);
         }
         $values = implode(',', $values);
         $query = " UPDATE `#__osemsc_mailing` SET {$values}" . " WHERE `user_id` ={$member_id}";
     }
     //echo $query;exit;
     $db->setQuery($query);
     if (!oseDB::query()) {
         $result['success'] = false;
         $result['title'] = JText::_('Error');
         $result['content'] = JText::_('Failed Saving Mailing Info.');
     } else {
         $result['success'] = true;
         $result['title'] = JText::_('Done');
         $result['content'] = JText::_('Saved User\'s Mailing Info.');
     }
     return $result;
 }
	public static function save()
    {
    	$result = array();

		$result['success'] = true;
		$result['title'] = JText::_('Done');
		$result['content'] = JText::_('Saved User Billing Info.');

    	$post = JRequest::get('post');

    	$user = oseMscPublic::getUser();
    	$member_id = $user->id;

    	if(!empty($post['juser_firstname'])) 
    	{
    		$post['bill_firstname'] = $post['juser_firstname'];
    	}

    	if(!empty($post['juser_lastname']))
    	{
    		$post['bill_lastname'] = $post['juser_lastname'];
    	}

		$billinfo = array();
		foreach($post as $key => $value)
		{
			if(strstr($key,'bill_'))
			{
				$billKey = str_replace('bill_','',$key);
				$billinfo[$billKey] = $value;
			}
		}

		if(empty($billinfo))
		{
			$result['success'] = true;
			$result['title'] = JText::_('Done');
			$result['content'] = JText::_('Nothing need to save!');
		}
		//oseExit($billinfo);
    	$db = oseDB::instance();
    	//$member_id = JRequest::getInt('member_id',0);
    	$query = " SELECT count(*) FROM `#__osemsc_billinginfo` WHERE user_id='{$member_id}'";
    	$db->setQuery($query);
    	$num = $db->loadResult();

		$fields = $db->getTableFields('#__osemsc_billinginfo');

		foreach($billinfo as $key => $value)
		{
			$my = JFactory::getUser();

			if(!isset($fields['#__osemsc_billinginfo'][$key]))
			{
    			if(oseMscPublic::isUserAdmin($my))
				{
					$query = "ALTER TABLE `#__osemsc_billinginfo` ADD `{$key}` TEXT NULL DEFAULT NULL";
					$db->setQuery($query);
					if (!oseDB::query())
					{
						$result['success'] = false;
						$result['title'] = JText::_('Error');
						$result['content'] = JText::_('Fail Saving Joomla User Info.');
					}
				}
				else
				{
					//unset($billinfo[$key]);
				}
			}

		}

    	if (empty ($num)) {
    		$keys = array_keys($billinfo);
    		$keys = '`'.implode('`,`',$keys).'`';

			/*
    		foreach($billinfo as $key => $value)
    		{
    			$billinfo[$key] = $db->Quote($value);
    		}

			$values = implode(',',$billinfo);

			if (empty($values))
			{
				$result['success'] = true;
				$result['title'] = JText::_('Done');
				$result['content'] = JText::_('Nothing need to save!');
			}
			$query = "INSERT INTO `#__osemsc_billinginfo` (`user_id`,{$keys}) VALUES ('{$member_id}',{$values});";

			$db->setQuery($query);
			*/
			$billinfo['user_id'] = $user->id;
			if (!oseDB::insert('#__osemsc_billinginfo',$billinfo)) {
				$result['success'] = false;
				$result['title'] = JText::_('Error');
				$result['content'] = JText::_('Fail Saving Joomla User Info.');

			}
		} else {
			if(count($billinfo) > 0)
			{
				/*
				foreach($billinfo as $key => $value)
	    		{
	    			$billinfo[$key] = "`{$key}`=".$db->Quote($value);
	    		}

	    		$values = implode(',',$billinfo);

				$query = " UPDATE `#__osemsc_billinginfo` SET {$values}"
						." WHERE `user_id` ={$member_id}"
						;
				$db->setQuery($query);
				*/
				$billinfo['user_id'] = $user->id;
				if (!oseDB::update('#__osemsc_billinginfo','user_id',$billinfo)) {
					$result['success'] = false;
					$result['title'] = JText::_('Error');
					$result['content'] = JText::_('Fail Saving Joomla User Info.');

				}
			}

		}
		//echo $query;exit;

    	return $result;

    }
	public static function save( $params )
    {
    	//$post = JRequest::get('post');

    	$member_id = $params['member_id'];

    	if(empty($member_id))
    	{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Error');

			return $result;
    	}

		$post = JRequest::get('post');
		$bill = array();

		foreach($post as $key => $value)
		{
			if(strstr($key,'bill_'))
			{
				$billKey = preg_replace('/bill_/','',$key,1);
				$bill[$billKey] = $value;
			}
		}

		$bill['firstname'] = $post['juser_firstname'];
		$bill['lastname'] = $post['juser_lastname'];
		//oseExit($billinfo);
    	$db = oseDB::instance();

    	$query = " SELECT count(*) FROM `#__osemsc_billinginfo` WHERE user_id='{$member_id}'";
    	$db->setQuery($query);
    	$num = $db->loadResult();
    	 //oseExit($db->_sql);
    	if (empty ($num)) {
    		$keys = array_keys($bill);
    		$keys = '`'.implode('`,`',$keys).'`';
    		$fields = $db->getTableFields('#__osemsc_billinginfo');

    		foreach($bill as $key => $value)
    		{
    			$my = JFactory::getUser();
    			if(oseMscPublic::isUserAdmin($my))
    			{
    				if(!isset($fields['#__osemsc_billinginfo'][$key]))
					{
						$query = "ALTER TABLE `#__osemsc_billinginfo` ADD `{$key}` TEXT NULL DEFAULT NULL";
						$db->setQuery($query);
						if (!oseDB::query())
						{
							$result['success'] = false;
							$result['title'] = JText::_('Error');
							$result['content'] = JText::_('Fail Saving Joomla User Info.');
						}
	    			}
    			}
			else
			{
				if($key == 'vat_number')
				{
					if(!isset($fields['#__osemsc_billinginfo']['vat_number']))
					{
						$query = "ALTER TABLE `#__osemsc_billinginfo` ADD `{$key}` TEXT NULL DEFAULT NULL";
						$db->setQuery($query);
						if (!oseDB::query())
						{
							$result['success'] = false;
							$result['title'] = JText::_('Error');
							$result['content'] = JText::_('Fail Saving Joomla User Info.');
						}
					}
				}
					
			}
					
    		}
    		$values = array();

    		foreach($bill as $key => $value)
    		{
    			$values[] = $db->Quote($value);
    		}

    		$values = implode(',',$values);

			$query = "INSERT INTO `#__osemsc_billinginfo` (`user_id`,{$keys}) VALUES ('{$member_id}',{$values});";
		} else {

			foreach($bill as $key => $value)
    		{
    			$values[] = "`{$key}`=".$db->Quote($value);
    		}

    		$values = implode(',',$values);

			$query = " UPDATE `#__osemsc_billinginfo` SET {$values}"
					." WHERE `user_id` ={$member_id}"
					;
		}
		//echo $query;exit;
		$db->setQuery($query);

		if (!oseDB::query()) {
			$result['success'] = false;
			$result['title'] = JText::_('Error');
			$result['content'] = JText::_('Fail Saving Joomla User Info.');

		} else {


			$result['success'] = true;
			$result['title'] = JText::_('Done');
			$result['content'] = JText::_('Saved User Billing Info.');

		}
    	return $result;

    }
	public static function save( $params )
    {
    	$member_id = $params['member_id'];
//print_r($_POST); exit;
    	if(empty($member_id))
    	{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Error');

			return $result;
    	}

		$post = JRequest::get('post');
		$mailing = array();

		foreach($post as $key => $value)
		{
			if(strstr($key,'mailing_'))
			{
				$mailingKey = preg_replace('/mailing_/','',$key,1);
				$mailing[$mailingKey] = $value;
			}
		}
    	$db = oseDB::instance();

		$query = "CREATE TABLE IF NOT EXISTS `#__osemsc_mailing` (
			  `user_id` int(11) NOT NULL default '0',
			  `company` varchar(200) default NULL,
			  `addr1` text COMMENT 'address 1',
			  `addr2` text COMMENT 'address 2',
			  `city` varchar(100) default NULL,
			  `state` varchar(100) default NULL COMMENT 'State ID',
			  `country` varchar(100) default NULL COMMENT 'Country ID',
			  `postcode` varchar(20) default NULL,
			  `telephone` varchar(20) default NULL,
			  `sector` varchar(20) default NULL,
			  PRIMARY KEY  (`user_id`)
			) ENGINE=MyISAM DEFAULT CHARSET=latin1;	";

		$db->setQuery($query);
		$db->query();

    	$query = " SELECT count(*) FROM `#__osemsc_mailing` WHERE user_id='{$member_id}'";
    	$db->setQuery($query);
    	$num = $db->loadResult();
    	 //oseExit($db->_sql);
    	if (empty ($num)) {
    		$keys = array_keys($mailing);
    		$keys = '`'.implode('`,`',$keys).'`';
    		$fields = $db->getTableFields('#__osemsc_mailing');

    		foreach($mailing as $key => $value)
    		{
    			$my = JFactory::getUser();
    			if(oseMscPublic::isUserAdmin($my))
    			{
    				if(!isset($fields['#__osemsc_mailing'][$key]))
					{
						$query = "ALTER TABLE `#__osemsc_mailing` ADD `{$key}` TEXT NULL DEFAULT NULL";
						$db->setQuery($query);
						if (!oseDB::query())
						{
							$result['success'] = false;
							$result['title'] = JText::_('Error');
							$result['content'] = JText::_('Fail Saving Mailing Info.');
						}
	    			}
    			}
    		}
    		$values = array();

    		foreach($mailing as $key => $value)
    		{
    			$values[] = $db->Quote($value);
    		}

    		$values = implode(',',$values);

			$query = "INSERT INTO `#__osemsc_mailing` (`user_id`,{$keys}) VALUES ('{$member_id}',{$values});";
		} else {

			foreach($mailing as $key => $value)
    		{
    			$values[] = "`{$key}`=".$db->Quote($value);
    		}

    		$values = implode(',',$values);

			$query = " UPDATE `#__osemsc_mailing` SET {$values}"
					." WHERE `user_id` ={$member_id}"
					;
		}
		//echo $query;exit;
		$db->setQuery($query);

		if (!oseDB::query()) {
			$result['success'] = false;
			$result['title'] = JText::_('Error');
			$result['content'] = JText::_('Failed Saving Mailing Info.');

		} else {


			$result['success'] = true;
			$result['title'] = JText::_('Done');
			$result['content'] = JText::_('Saved User\'s Mailing Info.');

		}
    	return $result;
    }