public function createForm($grid)
 {
     $form = new Am_Form_Admin();
     $name = $form->addText('name', array('class' => 'el-wide'))->setLabel(___('Title'));
     $r = $grid->getRecord();
     if ($r->isLoaded() && $r->pk() < self::DEFAULT_LAYOUT_THRESHOLD) {
         $name->toggleFrozen('true');
     } else {
         $name->addRule('required');
     }
     $form->addTextarea('layout', array('rows' => 25, 'class' => 'row-wide el-wide'))->setLabel(___("Layout\n" . "use placholder %content% for email output"))->addRule('callback', ___('Your layout has not %content% placeholder'), array($this, 'checkLayout'));
     return $form;
 }
Ejemplo n.º 2
0
 public function createForm()
 {
     $form = new Am_Form_Admin();
     $form->addText('title', array('class' => 'el-wide'))->setLabel(___('Title'))->addRule('required');
     $form->addTextarea('content', array('class' => 'el-wide', 'rows' => 10))->setLabel(___('Content'))->addRule('required');
     return $form;
 }
Ejemplo n.º 3
0
    function createForm()
    {
        $form = new Am_Form_Admin();
        $form->addAdvRadio('is_custom')->loadOptions(array(0 => ___('Use Pre-Defined Template'), 1 => ___('Define Custom Html Message')))->setValue(0);
        $form->addTextarea('content', array('rows' => '7', 'class' => 'row-wide el-wide'))->setLabel(___("Content\n" . 'You can use all user specific placeholders here eg. %user.login%, %user.name_f%, %user.name_l% etc.'))->addRule('required');
        $form->addText('url', array('class' => 'el-wide', 'rel' => 'form-pre-defined'))->setLabel(___('Link'));
        $form->addAdvcheckbox('is_blank', array('rel' => 'form-pre-defined'))->setLabel(___('Open Link in New Window'));
        $form->addScript()->setScript(<<<CUT
\$('[name=is_custom]').change(function(){
    \$('[rel=form-pre-defined]').closest('.row').toggle(\$('[name=is_custom]:checked').val() == 0)
}).change();
CUT
);
        $sel = $form->addMagicSelect('_target')->setLabel(___('Target By User'));
        $cats = $pr = $gr = array();
        foreach ($this->getDi()->userGroupTable->getSelectOptions() as $k => $v) {
            $gr['user_group_id-' . $k] = 'Group: ' . $v;
        }
        $options = array('free' => ___('All'), 'user_id' => ___('Specific User')) + ($cats ? array(___('Product Categories') => $cats) : array()) + ($gr ? array(___('User Groups') => $gr) : array()) + ($pr ? array(___('Products') => $pr) : array());
        $sel->loadOptions($options);
        //$sel->addRule('required');
        $sel->setJsOptions('{onChange:function(val){
                $("input[name^=_loginOrEmail]").closest(\'.row\').toggle(val.hasOwnProperty("user_id"));
        }}');
        $loginGroup = $form->addGroup('');
        $loginGroup->setLabel(___('E-Mail Address or Username'));
        $loginGroup->addHidden('_savedLoginOrEmail')->setValue('');
        $login = $loginGroup->addText('_loginOrEmail[]');
        $label_add_user = ___('Add User');
        $loginGroup->addHtml()->setHtml(<<<CUT
<div><a href="javascript:void(null);" id="target-user_id-add" class="local">{$label_add_user}</a></div>
CUT
);
        $form->addElement(new Am_Form_Element_ResourceAccess('_raccess', array('without_free' => true)))->setLabel('Target By Product');
        $gr = $form->addGroup()->setSeparator(' ')->setLabel(___("Dates\n" . 'date range when notification is shown'));
        $gr->addDate('begin', array('placeholder' => ___('Begin Date')));
        $gr->addDate('expire', array('placeholder' => ___('Expire Date')));
        $form->addScript('script')->setScript(<<<CUT
\$("input[name^=_loginOrEmail]").autocomplete({
        minLength: 2,
        source: window.rootUrl + "/admin-users/autocomplete"
});
CUT
);
        $delIcon = $this->getDi()->view->icon('delete');
        $form->addScript('script2')->setScript(<<<CUT

var arr = \$('[name=_savedLoginOrEmail]').val().split(',').reverse();
\$('[name^=_loginOrEmail]').val(arr.pop());
for (var i in arr) {
    var \$field = addEmailOrLogin(\$('#target-user_id-add'));
    \$field.val(arr[i]);
}

function addEmailOrLogin(context) {
    var \$field = \$('<input tyep="text" name="_loginOrEmail[]" />');
    \$(context).before('<br />');
    \$(context).before(\$field);
    \$(context).before('<a href="javascript:void(null)" onclick="\$(this).prev().remove();\$(this).prev().remove();\$(this).next().remove();\$(this).remove()">{$delIcon}</a>');
    \$(context).before('<br />');
    \$field.autocomplete({
        minLength: 2,
        source: window.rootUrl + "/admin-users/autocomplete"
    });
    return \$field;
}

\$('#target-user_id-add').click(function(){
    addEmailOrLogin(this);
})
CUT
);
        $form->addText('limit', array('placeholder' => ___('Unlimited')))->setLabel(___("Limit Number of Display per User\n" . 'keep it empty for unlimited'));
        return $form;
    }
    public function addInvoiceAction()
    {
        $this->getDi()->authAdmin->getUser()->checkPermission('grid_invoice', 'insert');
        $form = new Am_Form_Admin('add-invoice');
        $tm_added = $form->addDate('tm_added')->setLabel(___('Date'));
        $tm_added->setValue($this->getDi()->sqlDate);
        $tm_added->addRule('required');
        $comment = $form->addText('comment', array('class' => 'el-wide'))->setLabel(___("Comment\nfor your reference"));
        $form->addElement(new Am_Form_Element_ProductsWithQty('product_id'))->setLabel(___('Products'))->loadOptions($this->getDi()->billingPlanTable->selectAllSorted())->addRule('required');
        $form->addSelect('paysys_id')->setLabel(___('Payment System'))->setId('add-invoice-paysys_id')->loadOptions(array('' => '') + $this->getDi()->paysystemList->getOptions());
        $couponEdit = $form->addText('coupon')->setLabel(___('Coupon'))->setId('p-coupon');
        $action = $form->addAdvRadio('_action')->setLabel(___('Action'))->setId('add-invoice-action')->loadOptions(array('pending' => ___('Just Add Pending Invoice'), 'pending-payment' => ___('Add Invoice and Payment/Access Manually'), 'pending-send' => ___('Add Pending Invoice and Send Link to Pay It to Customer')))->setValue('pending');
        $receipt = $form->addText('receipt')->setLabel(___('Receipt#'))->setId('add-invoice-receipt');
        $tm_due = $form->addDate('tm_due')->setLabel(___('Due Date'));
        $tm_due->setValue(sqlDate('+7 days'));
        $tm_due->setId('add-invoice-due');
        $message = $form->addTextarea('message', array('class' => 'el-wide'))->setLabel(___("Message\nwill be included to email to user"));
        $message->setId('add-invoice-message');
        $form->addElement('email_link', 'invoice_pay_link')->setLabel(___('Email Template with Payment Link'));
        $form->addScript()->setScript('
            $("[name=_action]").change(function(){
                var val = $("[name=_action]:checked").val();
                $("#add-invoice-receipt").closest("div.row").toggle(val == "pending-payment")
                $("#add-invoice-due").closest("div.row").toggle(val == "pending-send")
                $("#add-invoice-message").closest("div.row").toggle(val == "pending-send")
                $("[name=invoice_pay_link]").closest("div.row").toggle(val == "pending-send")
            }).change();

        ');
        $script = <<<CUT
        \$("input#p-coupon").autocomplete({
                minLength: 2,
                source: window.rootUrl + "/admin-coupons/autocomplete"
        });
CUT;
        $form->addScript('script')->setScript($script);
        $form->addSaveButton();
        $form->setDataSources(array($this->getRequest()));
        do {
            if ($form->isSubmitted() && $form->validate()) {
                $vars = $form->getValue();
                $invoice = $this->getDi()->invoiceRecord;
                $invoice->setUser($this->getDi()->userTable->load($this->user_id));
                $invoice->tm_added = sqlTime($vars['tm_added']);
                if ($vars['coupon']) {
                    $invoice->setCouponCode($vars['coupon']);
                    $error = $invoice->validateCoupon();
                    if ($error) {
                        $couponEdit->setError($error);
                        break;
                    }
                }
                foreach ($vars['product_id'] as $plan_id => $qty) {
                    $p = $this->getDi()->billingPlanTable->load($plan_id);
                    $pr = $p->getProduct();
                    try {
                        $invoice->add($pr, $qty);
                    } catch (Am_Exception_InputError $e) {
                        $form->setError($e->getMessage());
                        break 2;
                    }
                }
                $invoice->comment = $vars['comment'];
                $invoice->calculate();
                switch ($vars['_action']) {
                    case 'pending':
                        if (!$this->_addPendingInvoice($invoice, $form, $vars)) {
                            break 2;
                        }
                        break;
                    case 'pending-payment':
                        if (!$this->_addPendingInvoiceAndPayment($invoice, $form, $vars)) {
                            break 2;
                        }
                        break;
                    case 'pending-send':
                        if (!$this->_addPendingInvoiceAndSend($invoice, $form, $vars)) {
                            break 2;
                        }
                        break;
                    default:
                        throw new Am_Exception_InternalError(sprintf('Unknown action [%s] as %s::%s', $vars['_action'], __CLASS__, __METHOD__));
                }
                $this->getDi()->adminLogTable->log("Add Invoice (#{$invoice->invoice_id}/{$invoice->public_id}, Billing Terms: " . new Am_TermsText($invoice) . ")", 'invoice', $invoice->invoice_id);
                return $this->redirectLocation(REL_ROOT_URL . '/admin-user-payments/index/user_id/' . $this->user_id);
            }
            // if
        } while (false);
        $this->view->content = '<h1>' . ___('Add Invoice') . ' (<a href="' . REL_ROOT_URL . '/admin-user-payments/index/user_id/' . $this->user_id . '">' . ___('return') . '</a>)</h1>' . (string) $form;
        $this->view->display('admin/user-layout.phtml');
    }