contract AtpcCoin is StandardToken {

    /* Public variables of the token */

    string public name;
    uint8 public decimals;
    string public symbol;
    string public version = 'H1.0';
    uint256 public unitsOneEthCanBuy;     // How many units of your coin can be bought by 1 ETH?
    uint256 public totalEthInWei;
    address public fundsWallet;           // Where should the raised ETH go?
    address public owner;
    bool public isICOOver;
    bool public isICOActive;


    constructor() public {
        balances[msg.sender] = 190800000000000000000000000;
        totalSupply = 190800000000000000000000000;
        name = "ATPC Coin";
        decimals = 18;
        symbol = "ATPC";
        unitsOneEthCanBuy = 1460;
        fundsWallet = msg.sender;
        owner = msg.sender;
        isICOOver = false;
        isICOActive = true;
    }

    modifier ownerFunc(){
      require(msg.sender == owner);
      _;
    }

    function transferAdmin(address _to, uint256 _value) ownerFunc returns (bool success) {
        //Default assumes totalSupply can't be over max (2^256 - 1).
        if (balances[msg.sender] >= _value && _value > 0) {
            balances[msg.sender] -= _value;
            balances[_to] += _value;
            emit Transfer(msg.sender, _to, _value);
            return true;
        } else { return false; }
    }

    function changeICOState(bool isActive, bool isOver) public ownerFunc payable {
      isICOOver = isOver;
      isICOActive = isActive;
    }

    function changePrice(uint256 price) public ownerFunc payable {
      unitsOneEthCanBuy = price;
    }

    function() public payable {
        require(!isICOOver);
        require(isICOActive);

        totalEthInWei = totalEthInWei + msg.value;
        uint256 amount = msg.value * unitsOneEthCanBuy;
        require(balances[fundsWallet] >= amount);

        balances[fundsWallet] = balances[fundsWallet] - amount;
        balances[msg.sender] = balances[msg.sender] + amount;
        emit Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain

        //Transfer ether to fundsWallet
        fundsWallet.transfer(msg.value);
    }

    /* Approves and then calls the receiving contract */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);

        //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
        //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
        //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
        if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
        return true;
    }
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
    allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);

    //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
    //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
    //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
    if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
    return true;
}

/* Approves and then calls the receiving contract */