<?php

require_once 'classes/AffiliatePlugin.php';

/**
* @package Plugins
*/
class PluginIdevaffiliate extends AffiliatePlugin
{
    function getVariables()
    {
        /* Specification
              itemkey     - used to identify variable in your other functions
              type        - text,textarea,yesno,password,hidden ( type hidden are variables used by CE and are required )
              description - description of the variable, displayed in ClientExec
        */
    
        $variables = array (
                   /*T*/"Plugin Name"/*/T*/ => array (
                                        "type"=>"hidden",
                                        "description"=>"Used By CE to show plugin - must match how you call the action function names",
                                        "value"=>/*T*/"iDevAffiliate"/*/T*/
                                       ),
                   /*T*/'Enabled'/*/T*/       => array(
                                        "type"          => "yesno",
                                        "description"   => /*T*/"When enabled, iDevAffiliate will be notified of new sales."/*/T*/,
                                        "value"         => "0",
                                    ),
                   /*T*/"Description"/*/T*/ => array (
                                        "type"=>"hidden",
                                        "description"=>/*T*/"Description viewable by admin in server settings"/*/T*/,
                                        "value"=>/*T*/"Plugin for iDevAffiliate to notify when new orders are accepted."/*/T*/
                                       ),
                   /*T*/"Image URL"/*/T*/ => array (
                                        "type"=>"text",
                                        "description"=>/*T*/"The full URL to iDevAffiliate's sale.php.  Example: http://mydomain.com/idevaffiliate/sale.php"/*/T*/,
                                        "value"=>"http://mydomain.com/idevaffiliate/sale.php"
                                       ),
                   /*T*/"Sale Amount Variable"/*/T*/ => array (
                                        "type"=>"text",
                                        "description"=>/*T*/"The variable that iDevAffiliate uses for the sale amount."/*/T*/,
                                        "value"=>"idev_saleamt"
                                       ),
                   /*T*/"Invoice Number Variable"/*/T*/ => array (
                                        "type"=>"text",
                                        "description"=>/*T*/"The variable that iDevAffiliate uses for the invoice number."/*/T*/,
                                        "value"=>"idev_ordernum"
                                       ),
                   /*T*/"Include Tax"/*/T*/ => array (
                                        "type"=>"yesno",
                                        "description"=>/*T*/"Whether tax should be included in the affiliate amount."/*/T*/,
                                        "value"=>"0"
                                       ),
        );
        return $variables;
    }
    
    function getImage($args)
    {
        require_once 'modules/billing/models/Invoice.php';
        $invoice = new Invoice($this->user, $args['invoiceNumber']);
        if ($args['Include Tax'] == 0 && $invoice->getTax() > 0) {
            $args['invoiceAmount'] = $invoice->getPriceExludingTax();
        }
        $this->logger->log(4, 'Generating iDevAffiliate hidden sale image (Amount: $'.$args['invoiceAmount'].' Invoice #: '.$args['invoiceNumber'].')');
        return '<img border="0" src="'.$args['Image URL'].'?'.$args['Sale Amount Variable'].'='.$args['invoiceAmount'].'&'.$args['Invoice Number Variable'].'='.$args['invoiceNumber'].'" width="1" height="1">';
    }
}
?>
