function init()
    {
        $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array('_count' => 1, 'use_count' => 10, 'discount' => 10, 'discount_type' => '%', 'user_use_count' => 1, '_code_len' => 8)));
        if (!$this->record->isLoaded()) {
            $this->addElement('text', '_count', array('size' => 20))->setLabel(___("Coupons Count\nhow many coupons need to be generated"))->addRule('gt', 'Should be greater than 0', 0);
        }
        $this->addElement('text', 'use_count', array('size' => 20))->setLabel(___("Coupons Usage Count\n" . "how many times coupon can be used"));
        $discountGroup = $this->addElement('group')->setLabel(array('Discount'));
        $discountGroup->addElement('text', 'discount', array('size' => 5))->addRule('gt', 'must be greater than 0', 0);
        $discountGroup->addElement('select', 'discount_type')->loadOptions(array(Coupon::DISCOUNT_PERCENT => '%', Coupon::DISCOUNT_NUMBER => Am_Currency::getDefault()));
        $this->addElement('textarea', 'comment')->setLabel(___("Comment\nfor admin reference"));
        /// advanced settings
        $fs = $this->addAdvFieldset('advanced')->setLabel(___('Advanced Settings'));
        if (!$this->record->isLoaded()) {
            $fs->addElement('text', '_code_len', array('size' => 20))->setLabel(array(___("Code Length\ngenerated coupon code length\nbetween 5 and 32")))->addRule('gt', 'Should be greater than 4', 4)->addRule('lt', 'Should be less then 33', 33);
        }
        $fs->addElement('text', 'user_use_count', array('size' => 20))->setLabel(___("User Coupon Usage Count\nhow many times a coupon code can be used by customer"));
        $dateGroup = $fs->addElement('group')->setLabel(___("Dates\ndate range when coupon can be used"));
        $dateGroup->addCheckbox('_date-enable', array('class' => 'enable_date'));
        $begin = $dateGroup->addDate('begin_date');
        $expire = $dateGroup->addDate('expire_date');
        $fs->addElement('advcheckbox', 'is_recurring')->setLabel(___("Apply to recurring?\n" . "apply coupon discount to recurring rebills?"));
        $fs->addElement('advcheckbox', 'is_disabled')->setLabel(___("Is Disabled?\n" . "If you disable this coupons batch, it will\n" . "not be available for new purchases.\n" . "Existing invoices are not affected.\n"));
        $fs->addElement('select', 'product_ids', array('multiple' => 1, 'class' => 'magicselect'))->loadOptions(Am_Di::getInstance()->productTable->getOptions())->setLabel(___("Products\n" . "coupons can be used with selected products only.\n" . "if nothing selected, coupon can be used with any product"));
        $jsCode = <<<CUT
\$(".enable_date").prop("checked", \$("input[name=expire_date]").val() ? "checked" : "");   
\$(".enable_date").live("change", function(){
    var dates = \$(this).parent().find("input[type=text]");
    dates.prop('disabled', \$(this).prop("checked") ? '' : 'disabled');
}).trigger("change");
CUT;
        $fs->addScript('script')->setScript($jsCode);
    }
    function init()
    {
        $this->setAttribute('enctype', 'multipart/form-data');
        $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array('_count' => 1, 'use_count' => 10, 'discount' => 10, 'discount_type' => '%', 'user_use_count' => 1, '_code_len' => 8, '_source' => 1)));
        $this->addText('use_count', array('size' => 5))->setLabel(___("Coupons Usage Count\n" . 'how many times coupon can be used'));
        $discountGroup = $this->addGroup()->setLabel(___('Discount'));
        $discountGroup->setSeparator(' ');
        $discountGroup->addText('discount', array('size' => 5));
        $discountGroup->addSelect('discount_type')->loadOptions(array(Coupon::DISCOUNT_PERCENT => '%', Coupon::DISCOUNT_NUMBER => Am_Currency::getDefault()));
        $this->addTextarea('comment', array('class' => 'el-wide'))->setLabel(___("Comment\nfor admin reference"));
        if (!$this->record->isLoaded()) {
            $source = $this->addFieldset('source')->setLabel(___('Coupon Codes'));
            $source->addAdvRadio('_source')->setId('coupon-source')->loadOptions(array(AdminCouponsController::SOURCE_GENERATE => ___('Generate Random Coupon Codes (You will be able to alter codes later if you want)'), AdminCouponsController::SOURCE_FILE => ___('Import Pre-Defined List of Coupon Codes from CSV File (One coupon code per line)')));
            $source->addText('_count', array('size' => 5, 'rel' => 'source-generate'))->setLabel(___("Coupons Count\nhow many coupons need to be generated"))->addRule('gt', ___('Should be greater than 0'), 0);
            $source->addText('_code_len', array('size' => 5, 'rel' => 'source-generate'))->setLabel(___("Code Length\ngenerated coupon code length\nbetween 5 and 32"))->addRule('gt', ___('Should be greater than %d', 4), 4)->addRule('lt', ___('Should be less then %d', 33), 33);
            $source->addFile('file[]', array('class' => 'styled', 'rel' => 'source-file'))->setLabel(___('File'));
            $s_generate = AdminCouponsController::SOURCE_GENERATE;
            $s_file = AdminCouponsController::SOURCE_FILE;
            $this->addScript()->setScript(<<<CUT
\$('[name=_source]').change(function(){
    \$('[rel=source-generate]').closest('.row').toggle(\$('[name=_source]:checked').val() == {$s_generate});
    \$('[rel=source-file]').closest('.row').toggle(\$('[name=_source]:checked').val() == {$s_file});
}).change();
CUT
);
        }
        $fs = $this->addAdvFieldset(null, array('id' => 'coupon-batch'))->setLabel(___('Advanced Settings'));
        $fs->addText('user_use_count', array('size' => 20))->setLabel(___("User Coupon Usage Count\nhow many times a coupon code can be used by customer"));
        $dateGroup = $fs->addGroup()->setLabel(___("Dates\ndate range when coupon can be used"));
        $dateGroup->setSeparator(' ');
        $dateGroup->addCheckbox('_date-enable', array('class' => 'enable_date'));
        $begin = $dateGroup->addDate('begin_date');
        $expire = $dateGroup->addDate('expire_date');
        $fs->addAdvCheckbox('is_recurring')->setLabel(___("Apply to recurring?\n" . "apply coupon discount to recurring rebills?"));
        $fs->addAdvCheckbox('is_disabled')->setLabel(___("Is Disabled?\n" . "If you disable this coupons batch, it will\n" . "not be available for new purchases.\n" . "Existing invoices are not affected.\n"));
        $product_categories = array();
        foreach (Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions() as $id => $title) {
            $product_categories['CATEGORY-' . $id] = $title;
        }
        $fs->addMagicSelect('product_ids')->loadOptions(array(___('Products') => Am_Di::getInstance()->productTable->getOptions(), ___('Product Categories') => $product_categories))->setLabel(___("Products\n" . "coupons can be used with selected products only.\n" . "if nothing selected, coupon can be used with any product"));
        $jsCode = <<<CUT
\$(".enable_date").prop("checked", \$("input[name=expire_date]").val() ? "checked" : "");
\$(document).on("change",".enable_date", function(){
    var dates = \$(this).parent().find("input[type=text]");
    dates.prop('disabled', \$(this).prop("checked") ? '' : 'disabled');
})
\$(".enable_date").change();
CUT;
        $fs->addScript('script')->setScript($jsCode);
        $require_options = $prevent_options = array();
        foreach (Am_Di::getInstance()->productTable->getOptions() as $id => $title) {
            $title = Am_Controller::escape($title);
            $require_options['ACTIVE-' . $id] = ___('ACTIVE subscription for %s', '"' . $title . '"');
            $require_options['EXPIRED-' . $id] = ___('EXPIRED subscription for %s', '"' . $title . '"');
            $prevent_options['ACTIVE-' . $id] = ___('ACTIVE subscription for %s', '"' . $title . '"');
            $prevent_options['EXPIRED-' . $id] = ___('EXPIRED subscription for %s', '"' . $title . '"');
        }
        $require_group_options = $prevent_group_options = array();
        foreach (Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions() as $id => $title) {
            $title = Am_Controller::escape($title);
            $require_group_options['CATEGORY-ACTIVE-' . $id] = ___('ACTIVE subscription for group %s', '"' . $title . '"');
            $require_group_options['CATEGORY-EXPIRED-' . $id] = ___('EXPIRED subscription for group %s', '"' . $title . '"');
            $prevent_group_options['CATEGORY-ACTIVE-' . $id] = ___('ACTIVE subscription for group %s', '"' . $title . '"');
            $prevent_group_options['CATEGORY-EXPIRED-' . $id] = ___('EXPIRED subscription for group %s', '"' . $title . '"');
        }
        if (count($require_group_options)) {
            $rOptions = array(___('Products') => $require_options, ___('Product Categories') => $require_group_options);
            $pOptions = array(___('Products') => $prevent_options, ___('Product Categories') => $prevent_group_options);
        } else {
            $rOptions = $require_options;
            $pOptions = $prevent_options;
        }
        $fs->addMagicSelect('require_product', array('multiple' => 'multiple', 'class' => 'magicselect'))->setLabel(___("To use coupon from this batch user must have an\n" . "when user uses coupon, it will be checked\n" . "that user has one from the following subscriptions"))->loadOptions($rOptions);
        $fs->addMagicSelect('prevent_if_product', array('multiple' => 'multiple', 'class' => 'magicselect'))->setLabel(___("Disallow use of coupon from this batch if user has\n" . "when user uses coupon, it will be checked\n" . "that he has no any from the following subscriptions"))->loadOptions($pOptions);
    }