Esempio n. 1
0
	function saveCart($post) {
		$result = array();
		$result['success'] = true;
		$result['reload'] = false;
		$result['script'] = false;
		$result['title'] = JText::_('SUCCESSFUL_ACTIVATION');
		$result['content'] = JText::_('MEMBERSHIP_ACTIVATED_CONTINUE');
		$juser = oseMscAddon::getPost('juser_', $post);
		$password1 = JRequest::getString('juser_password1', '', 'post', JREQUEST_ALLOWRAW);
		$password2 = JRequest::getString('juser_password2', '', 'post', JREQUEST_ALLOWRAW);
		if (oseObject::getValue($juser, 'firstname', false) && oseObject::getValue($juser, 'lastname', false)) {
			$juser['name'] = oseObject::getValue($juser, 'firstname', '') . ' ' . oseObject::getValue($juser, 'lastname', '');
		} else {
			$juser['name'] = oseObject::getValue($juser, 'username', false);
		}
		$juser['password'] = $juser['password1'] = $password1;
		$juser['password2'] = $password2;
		$juser['email1'] = $juser['email'];
		$juser['email2'] = $juser['email'];
		// check unique username
		$list = oseMscAddon::getAddonList('registerOS_body', false, 1, 'obj');
		foreach ($list as $addon) {
			$action_name = oseMscAddon::getActionName($addon, 'formValidate', 'register');
			$updated = oseMscAddon::runAction($action_name, array('inner' => true));
			if (!$updated['success']) {
				return $updated;
			}
		}
		if (!$updated['success']) {
			return $updated;
		}
		// check empty password
		if (empty($juser['password'])) {
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText::_('MUST_SUPPLY_PASSWORD');
			return $result;
		}
		$register = oseMscPublic::juserRegister($juser);
		if (!oseObject::getValue($register, 'success', false)) {
			return $register;
		} else {
			$memConfig = oseMscConfig::getConfig('register', 'obj');
			if ($memConfig->auto_login) {
				$result['reload'] = true;
			}
			$list1 = oseMscAddon::getAddonList('registerOS_header', false, 1, 'obj');
			$list2 = oseMscAddon::getAddonList('registerOS_body', false, 1, 'obj');
			$list3 = oseMscAddon::getAddonList('registerOS_footer', false, 1, 'obj');
			$list = array_merge($list1, $list2, $list3);
			$user = oseObject::getValue($register, 'user');
			$cart = oseMscPublic::getCart();
			$items = $cart->get('items');
			$item = $items[0];
			$params = array();
			$params['msc_id'] = oseMscPublic::getEntryMscId($item);
			$params['msc_option'] = oseObject::getValue($item, 'msc_option');
			$params['payment_mode'] = $post['payment_payment_mode'];
			$params['member_id'] = $user->id;
			$params['payment_method'] = $post['payment_method'];
			foreach ($list as $addon) {
				$action_name = oseMscAddon::getActionName($addon, 'save', 'register');
				$updated = oseMscAddon::runAction($action_name, $params);
				if (!$updated['success']) {
					return $updated;
				}
			}
			$emailConfig = oseMscConfig::getConfig('email', 'obj');
			if (!empty($emailConfig->default_reg_email)) {
				$member = oseRegistry::call('member');
				$email = $member->getInstance('email');
				$emailTempDetail = $email->getDoc($emailConfig->default_reg_email, 'obj');
				if (!empty($emailTempDetail)) {
					$variables = $email->getEmailVariablesRegistration($user->id);
					$variables['user'] = oseObject::setValue($variables['user'], 'password', $juser['password1']);
					$emailParams = $email->buildEmailParams($emailTempDetail->type);
					$emailDetail = $email->transEmail($emailTempDetail, $variables, $emailParams);
					$email->sendEmail($emailDetail, $user->email);
					if ($emailConfig->sendReg2Admin) {
						$email->sendToAdminGroup($emailDetail, $emailConfig->admin_group);
					}
				}
			}
			if ($memConfig->auto_login) {
				$isLogin = $this->login($juser['username'], $juser['password']);
				if (!$isLogin['success']) {
					$session = JFactory::getSession();
					$return = $session->get('oseReturnUrl', base64_encode('index.php?option=com_osemsc&view=login'));
					$result['success'] = false;
					$result['title'] = 'Error';
					$result['content'] = $isLogin['content'];
					$result['returnUrl'] = $return;
					return $result;
				}
			}
			return $result;
		}
	}
	function getOseProfile()
	{
		$user = JFactory::getUser();
    	$member_id = $user->id;
    	
    	$db = oseDB::instance();
    	$msc_id = JRequest::getInt('msc_id');
    	if(empty($msc_id))
    	{
    		$cart= oseMscPublic :: getCart();
    		$items= $cart->get('items');
			$item= $items[0];
			$msc_id = oseMscPublic :: getEntryMscId($item);	
    	}
    	$where = array();
    	if(!empty($msc_id))
    	{
    		$query = "SELECT params FROM `#__osemsc_ext` WHERE `type` = 'profilecontrol' AND `id` = ".$msc_id;
    		$db->setQuery($query);
    		$paymentParams = $db->loadResult();
    		$paymentParams = oseJSON::decode($paymentParams);
    		if(!empty($paymentParams->enable))
    		{
    			$pids = $paymentParams->value;
    			$where[] = " `id` IN (".$pids.")";
    		}
    	}
    	$where[] = " `published` = '1'";
    	$where= oseDB :: implodeWhere($where);
    	$query = "SELECT * FROM `#__osemsc_fields` ".$where." ORDER BY `ordering`";
    	$db->setQuery($query);
    	$items = $db->loadObjectList();
		foreach($items as $item)
		{
			if($item->type == 'radio')
			{
				$params=explode(',',$item->params);
				foreach($params as $param)
				{
					$option = array();
					$option['boxLabel'] = $param;	
					$option['inputValue'] = $param;
					$options[] = $option;
				}
				$item->params = $options;
				unset($options);
			}
			if(!empty($item->params))
			{
				$params=explode(',',$item->params);
				foreach($params as $param)
				{
					$option = array();
					$option['name'] = $param;	
					$options[] = $option;
				}
				$item->data = $options;
				unset($options);
			}
			if(!empty($member_id))
			{
				$query = "SELECT value FROM `#__osemsc_fields_values` WHERE `field_id` = '{$item->id}' AND `member_id` = '{$member_id}'";
				$db->setQuery($query);
				$item->value = $db->loadResult();
			}else{
				$item->value = null;
			}
		}
		$result = array();
		
		$result['total'] = count($items);
		$result['results'] = $items;
		
		return $result;
	}