<?php defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . 'interfaces/Validator_interface.php';

class CompanyValidator implements Validator_interface
{
	private $params;

	public function __construct(&$params=null)
	{
        $this->params =& $params;
	}

	public function is_valid(&$data)
	{
		if (!empty($data['cId']) && $data['cId'] != $this->params->cId)
		{
			throw new Exception(lang('COMPANY_SWAPPED'));
			return false;
		}

		if (!$this->params->bId && !empty($data['bId']) && !empty($data['isRecurring']))
		{
			$this->params->bId = $data['bId'];
		}

		if (sal_mod_active(BRANCH_MOD))
		{
			if (!empty($data['bId']) && $data['bId'] != $this->params->bId)
			{
				throw new Exception(lang('BRANCH_SWAPPED'));
				return false;
			}
		}

		return true;
	}
}

