function createForm()
    {
        $f = new Am_Form();
        $f->addHidden('s')->setValue($this->getFiltered('s'));
        $f->addHidden('e')->setValue($this->getParam('e'));
        $g = $f->addGroup('newsletter', array('id' => 'newsletter-group'))->setLabel(___('Untick checkbox to cancel subscription'));
        $g->setSeparator("<br />\n");
        $ids = $this->view->guest->getLists();
        foreach ($this->lists as $l) {
            $title = $l->title;
            if ($l->desc) {
                $title .= " - " . $l->desc;
            }
            $el = $g->addCheckbox($l->pk())->setContent($title);
            if (in_array($l->list_id, $ids) && !$this->_request->isPost()) {
                $el->setAttribute('checked');
            }
            // checked by default
        }
        if (count($this->lists) > 1) {
            $f->addCheckbox('unsubscribe')->setLabel(___('Cancel all Subscriptions'));
            $f->addScript()->setScript(<<<CUT
jQuery(document).ready(function(\$) {
    \$("input#unsubscribe-0").change(function(){
        \$("#row-newsletter-group").toggle(!this.checked);
    });
});
CUT
);
        }
        $f->addSubmit('do', array('value' => ___('Change Subscription')));
        return $f;
    }
Exemplo n.º 2
0
 /**
  * Prepare form to be used in the grid
  */
 public function initForm()
 {
     $this->form->setDataSources(array($this->getCompleteRequest()));
     foreach ($this->getVariablesList() as $k) {
         $this->form->addHidden($this->getId() . '_' . $k)->setValue($this->request->get($k, ""));
     }
     $this->form->addSaveButton(___("Save"));
 }
Exemplo n.º 3
0
 function indexAction()
 {
     $form = new Am_Form();
     $form->setAction(REL_ROOT_URL . '/cancel/repeat');
     $psOptions = array();
     foreach ($this->getDi()->paysystemList->getAllPublic() as $ps) {
         $psOptions[$ps->getId()] = $this->renderPaysys($ps);
     }
     $paysys = $form->addAdvRadio('paysys_id')->setLabel(___('Payment System'))->loadOptions($psOptions);
     $paysys->addRule('required', ___('Please choose a payment system'));
     if (count($psOptions) == 1) {
         $paysys->setValue(key($psOptions));
         $paysys->toggleFrozen(true);
     }
     $form->addHidden('id')->setValue($this->getFiltered('id'));
     $form->addSaveButton(___('Make Payment'));
     $this->view->form = $form;
     $this->view->display('cancel.phtml');
 }
Exemplo n.º 4
0
    public function createForm($label, $cc_mask = null)
    {
        $form = new Am_Form('cc-paymill');
        $name = $form->addGroup()->setLabel(___("Cardholder Name\n" . 'cardholder first and last name, exactly as on the card'));
        $name->addRule('required', ___('Please enter credit card holder name'));
        $name_f = $name->addText('cc_name_f', array('size' => 15, 'id' => 'cc_name_f'));
        $name_f->addRule('required', ___('Please enter credit card holder first name'))->addRule('regex', ___('Please enter credit card holder first name'), '|^[a-zA-Z_\' -]+$|');
        $name_l = $name->addText('cc_name_l', array('size' => 15, 'id' => 'cc_name_l'));
        $name_l->addRule('required', ___('Please enter credit card holder last name'))->addRule('regex', ___('Please enter credit card holder last name'), '|^[a-zA-Z_\' -]+$|');
        $cc = $form->addText('', array('autocomplete' => 'off', 'size' => 22, 'maxlength' => 22, 'id' => 'cc_number'))->setLabel(___('Credit Card Number'), ___('for example: 1111-2222-3333-4444'));
        if ($cc_mask) {
            $cc->setAttribute('placeholder', $cc_mask);
        }
        $cc->addRule('required', ___('Please enter Credit Card Number'))->addRule('regex', ___('Invalid Credit Card Number'), '/^[0-9 -]+$/');
        class_exists('Am_Form_CreditCard', true);
        // preload element
        $expire = $form->addElement(new Am_Form_Element_CreditCardExpire('cc_expire'))->setLabel(___("Card Expire\n" . 'Select card expiration date - month and year'));
        $code = $form->addPassword('', array('autocomplete' => 'off', 'size' => 4, 'maxlength' => 4, 'id' => 'cc_code'))->setLabel(___('Credit Card Code'), sprintf(___('The "Card Code" is a three- or four-digit security code that is printed on the back of credit cards in the card\'s signature panel (or on the front for American Express cards).'), '<br>', '<br>'));
        $code->addRule('required', ___('Please enter Credit Card Code'))->addRule('regex', ___('Please enter Credit Card Code'), '/^\\s*\\d{3,4}\\s*$/');
        /**/
        $fieldSet = $form->addFieldset(___('Address Info'))->setLabel(___("Address Info\n" . '(must match your credit card statement delivery address)'));
        $street = $fieldSet->addText('cc_street')->setLabel(___('Street Address'))->addRule('required', ___('Please enter Street Address'));
        $city = $fieldSet->addText('cc_city')->setLabel(___('City'))->addRule('required', ___('Please enter City'));
        $zip = $fieldSet->addText('cc_zip')->setLabel(___('ZIP'))->addRule('required', ___('Please enter ZIP code'));
        $country = $fieldSet->addSelect('cc_country')->setLabel(___('Country'))->setId('f_cc_country')->loadOptions(Am_Di::getInstance()->countryTable->getOptions(true));
        $country->addRule('required', ___('Please enter Country'));
        $group = $fieldSet->addGroup()->setLabel(___('State'));
        $group->addRule('required', ___('Please enter State'));
        $stateSelect = $group->addSelect('cc_state')->setId('f_cc_state')->loadOptions($stateOptions = Am_Di::getInstance()->stateTable->getOptions(@$_REQUEST['cc_country'], true));
        $stateText = $group->addText('cc_state')->setId('t_cc_state');
        $disableObj = $stateOptions ? $stateText : $stateSelect;
        $disableObj->setAttribute('disabled', 'disabled')->setAttribute('style', 'display: none');
        /**/
        $form->addSubmit('', array('value' => $label));
        $form->addHidden('id')->setValue($this->_request->get('id'));
        $form->addHidden('paymill_token', 'id=paymill_token')->addRule('required');
        //$key = json_encode($this->plugin->getConfig('public_key'));
        $key = $this->plugin->getConfig('public_key');
        $amount = $this->invoice->isFirstPayment() ? $this->invoice->first_total : $this->invoice->second_total;
        $amount = sprintf('%.02f', $amount) * 100;
        $form->addProlog('<script type="text/javascript" src="https://bridge.paymill.com/"></script>');
        $form->addScript()->setScript("var PAYMILL_PUBLIC_KEY = '" . $key . "';");
        if ($this->testMode) {
            $form->addScript()->setScript("var PAYMILL_TEST_MODE = true;");
        }
        $form->addScript()->setScript(file_get_contents(dirname(__FILE__) . '/../../default/views/public/js/json2.min.js'));
        $form->addScript()->setScript(<<<CUT
jQuery(function(\$){
    \$("form#cc-paymill").submit(function(event){
        var frm = \$(this);
        \$('.submit-button').attr("disabled", "disabled");
                
        if (frm.find("input[name=paymill_token]").val() > '')
            return true; // submit the form!
        event.stopPropagation();

        paymill.createToken({
            number:         frm.find("#cc_number").val(),       // required
            exp_month:      frm.find("[name='cc_expire[m]']").val(), // required
            exp_year:       frm.find("[name='cc_expire[y]']").val(),  // required
            cvc:            frm.find("#cc_code").val(),          // required
            amount_int:     {$amount},   // required, z.B. "4900" for 49.00 EUR
            currency:       '{$this->invoice->currency}',          // required
            cardholder:     frm.find("#cc_name_f").val() + " " + frm.find("#cc_name_l").val()    // optional
        }, function(error, result){ // handle response
            if (error) {
                frm.find("input[type=submit]").prop('disabled', null);
                var el = frm.find("#cc_number");
                var cnt = el.closest(".element");
                cnt.addClass("error");
                cnt.find("span.error").remove();
                
                var errorMessage = '';
                switch (error.apierror)
                {
                    case 'internal_server_error':
                        errorMessage = 'Communication with PSP failed';
                        break;
                    case 'invalid_public_key':
                        errorMessage = 'Invalid Public Key';
                        break;
                    case 'unknown_error':
                        errorMessage = 'Unknown Error';
                        break;

                    case '3ds_cancelled':
                        errorMessage = 'Password Entry of 3-D Secure password was cancelled by the user';
                        break;
                    case 'field_invalid_card_number':
                        errorMessage = 'Missing or invalid creditcard number';
                        break;
                    case 'field_invalid_card_exp_year':
                        errorMessage = 'Missing or invalid expiry year';
                        break;
                    case 'field_invalid_card_exp_month':
                        errorMessage = 'Missing or invalid expiry month';
                        break;
                    case 'field_invalid_card_exp':
                        errorMessage = 'Card is no longer valid or has expired';
                        break;
                    case 'field_invalid_card_cvc':
                        errorMessage = 'Invalid checking number';
                        break;
                    case 'field_invalid_card_holder':
                        errorMessage = 'Invalid cardholder';
                        break;
                    case 'field_invalid_amount_int':
                        errorMessage = 'Invalid or missing amount for 3-D Secure';
                        break;
                    case 'field_invalid_amount':
                        errorMessage = 'Invalid or missing amount for 3-D Secure deprecated, see blog post';
                        break;
                    case 'field_invalid_currency':
                        errorMessage = 'Invalid or missing currency code for 3-D Secure';
                        break;
                    case 'field_invalid_account_number':
                        errorMessage = 'Missing or invalid bank account number';
                        break;
                    case 'field_invalid_account_holder':
                        errorMessage = 'Missing or invalid bank account holder';
                        break;
                    case 'field_invalid_bank_code':
                        errorMessage = 'Missing or invalid bank code ';
                        break;
                    default:
                        errorMessage = error.apierror;
                }
                el.after("<span class='error'><br />"+errorMessage+"</span>");
            } else {
                frm.find("input[name=paymill_token]").val(result.token);
                frm.submit();
            }
        });                
        frm.find("input[type=submit]").prop('disabled', 'disabled');
        return false;
    });
});   
CUT
);
        return $form;
    }
Exemplo n.º 5
0
    public function createForm($label, $cc_mask = null)
    {
        $form = new Am_Form('cc-stripe');
        $name = $form->addGroup()->setLabel(___("Cardholder Name\n" . 'cardholder first and last name, exactly as on the card'));
        $name->addRule('required', ___('Please enter credit card holder name'));
        $name_f = $name->addText('cc_name_f', array('size' => 15, 'id' => 'cc_name_f'));
        $name_f->addRule('required', ___('Please enter credit card holder first name'))->addRule('regex', ___('Please enter credit card holder first name'), '|^[a-zA-Z_\' -]+$|');
        $name_l = $name->addText('cc_name_l', array('size' => 15, 'id' => 'cc_name_l'));
        $name_l->addRule('required', ___('Please enter credit card holder last name'))->addRule('regex', ___('Please enter credit card holder last name'), '|^[a-zA-Z_\' -]+$|');
        $cc = $form->addText('', array('autocomplete' => 'off', 'size' => 22, 'maxlength' => 22, 'id' => 'cc_number'))->setLabel(___('Credit Card Number'), ___('for example: 1111-2222-3333-4444'));
        if ($cc_mask) {
            $cc->setAttribute('placeholder', $cc_mask);
        }
        $cc->addRule('required', ___('Please enter Credit Card Number'))->addRule('regex', ___('Invalid Credit Card Number'), '/^[0-9 -]+$/');
        class_exists('Am_Form_CreditCard', true);
        // preload element
        $expire = $form->addElement(new Am_Form_Element_CreditCardExpire('cc_expire'))->setLabel(___("Card Expire\n" . 'Select card expiration date - month and year'));
        $expire->addRule('required', ___('Please enter Credit Card expiration date'));
        $code = $form->addPassword('', array('autocomplete' => 'off', 'size' => 4, 'maxlength' => 4, 'id' => 'cc_code'))->setLabel(___('Credit Card Code'), sprintf(___('The "Card Code" is a three- or four-digit security code that is printed on the back of credit cards in the card\'s signature panel (or on the front for American Express cards).'), '<br>', '<br>'));
        $code->addRule('required', ___('Please enter Credit Card Code'))->addRule('regex', ___('Please enter Credit Card Code'), '/^\\s*\\d{3,4}\\s*$/');
        $fieldSet = $form->addFieldset(___('Address Info'))->setLabel(___("Address Info\n" . '(must match your credit card statement delivery address)'));
        $street = $fieldSet->addText('cc_street')->setLabel(___('Street Address'))->addRule('required', ___('Please enter Street Address'));
        $city = $fieldSet->addText('cc_city')->setLabel(___('City '))->addRule('required', ___('Please enter City'));
        $zip = $fieldSet->addText('cc_zip')->setLabel(___('ZIP'))->addRule('required', ___('Please enter ZIP code'));
        $country = $fieldSet->addSelect('cc_country')->setLabel(___('Country'))->setId('f_cc_country')->loadOptions(Am_Di::getInstance()->countryTable->getOptions(true));
        $country->addRule('required', ___('Please enter Country'));
        $group = $fieldSet->addGroup()->setLabel(___('State'));
        $group->addRule('required', ___('Please enter State'));
        /** @todo load correct states */
        $stateSelect = $group->addSelect('cc_state')->setId('f_cc_state')->loadOptions($stateOptions = Am_Di::getInstance()->stateTable->getOptions(@$_REQUEST['cc_country'], true));
        $stateText = $group->addText('cc_state')->setId('t_cc_state');
        $disableObj = $stateOptions ? $stateText : $stateSelect;
        $disableObj->setAttribute('disabled', 'disabled')->setAttribute('style', 'display: none');
        $form->addSubmit('', array('value' => $label));
        $form->addHidden('id')->setValue($this->_request->get('id'));
        $form->addHidden('stripe_info', 'id=stripe_info')->addRule('required');
        $key = json_encode($this->plugin->getConfig('public_key'));
        $form->addScript()->setScript(file_get_contents(dirname(__FILE__) . '/../../default/views/public/js/json2.min.js'));
        $form->addScript()->setScript(<<<CUT
jQuery(function(\$){
    function am_make_base_auth(user, password) {
        return "Basic " + btoa(user + ':' + password);
    }
    \$("form#cc-stripe").submit(function(event){
        var frm = \$(this);
        if (frm.find("input[name=stripe_info]").val() > '')
            return true; // submit the form!
        event.stopPropagation();
        Stripe.setPublishableKey({$key});
        Stripe.createToken({
            number: frm.find("#cc_number").val(),
            cvc: frm.find("#cc_code").val(),
            exp_month: frm.find("[name='cc_expire[m]']").val(),
            exp_year: frm.find("[name='cc_expire[y]']").val(),
            name: frm.find("#cc_name_f").val() + " " + frm.find("#cc_name_l").val(),
            address_zip : frm.find("[name=cc_zip]").val(),
            address_line1 : frm.find("[name=cc_street]").val(),
            address_country : frm.find("[name=cc_country]").val(),
            address_city : frm.find("[name=cc_city]").val(),
            address_state : frm.find("[name=cc_state]").val()
            
        }, function(status, response){ // handle response
            if (status == '200')
            {
                frm.find("input[name=stripe_info]").val(JSON.stringify(response));
                frm.submit();
            } else {
                frm.find("input[type=submit]").prop('disabled', null);
                var msg;
                if (response.error.type == 'card_error')
                    msg = response.error.message;
                else
                    msg = 'Payment failure, please try again later';
                var el = frm.find("#cc_number");
                var cnt = el.closest(".element");
                cnt.addClass("error");
                cnt.find("span.error").remove();
                el.after("<span class='error'><br />"+msg+"</span>");
            }
        });
        frm.find("input[type=submit]").prop('disabled', 'disabled');
        return false;
    });
});   
CUT
);
        $form->setDataSources(array($this->_request, new HTML_QuickForm2_DataSource_Array($this->getDefaultValues($this->invoice->getUser()))));
        return $form;
    }
Exemplo n.º 6
0
 protected function createForm()
 {
     $form = new Am_Form();
     $form->addCsrf();
     $form->addText('login', array('disabled' => 'disabled'))->setLabel(___('Username'));
     $pass0 = $form->addPassword('pass0')->setLabel(___('New Password'));
     $pass0->addRule('minlength', ___('The password should be at least %d characters long', $this->getDi()->config->get('pass_min_length', 4)), $this->getDi()->config->get('pass_min_length', 4));
     $pass0->addRule('maxlength', ___('Your password is too long'), $this->getDi()->config->get('pass_max_length', 32));
     $pass0->addRule('required', 'This field is required');
     if ($this->getDi()->config->get('require_strong_password')) {
         $pass0->addRule('regex', ___('Password should contain at least 2 capital letters, 2 or more numbers and 2 or more special chars'), $this->getDi()->userTable->getStrongPasswordRegex());
     }
     $pass1 = $form->addPassword('pass1')->setLabel(___('Confirm Password'));
     $pass1->addRule('eq', ___('Passwords do not match'), $pass0);
     $form->addHidden(self::SECURITY_VAR);
     $form->addSaveButton(___('Change Password'));
     return $form;
 }
Exemplo n.º 7
0
    public function createDeclarationForm()
    {
        $form = new Am_Form('dd-declaretion');
        $form->addProlog('<h2>Declaration</h2>');
        $form->addAdvCheckbox('i_agree')->setLabel('I wish to start Direct Debit')->addRule('required');
        $form->addSaveButton('Proceed');
        $form->addEpilog(<<<CUT
<h2>Information</h2>
<p>All the normal Direct Debit safeguards and guarantees
apply. No changes in the amount, date, frequency to be debited can be made
without notifying you at least five (5) working days in advance of your
account being debited. In the event of error, you are entitled to an immediate
refund from your Bank or Building Society. You have the right to cancel a Direct
Debit Instruction at any time simply by writing to your Bank or Building
Society, with a copy to us.</p>
CUT
);
        $form->addHidden(Am_Controller::ACTION_KEY)->setValue($this->getRequest()->getActionName());
        $form->addHidden('id')->setValue($this->getFiltered('id'));
        return $form;
    }
Exemplo n.º 8
0
 public function createRunForm()
 {
     $form = new Am_Form();
     $form->setAction($this->getUrl(null, 'run'));
     $s = $form->addSelect('paysys_id')->setLabel(___('Choose a plugin'));
     $s->addRule('required');
     foreach ($this->getModule()->getPlugins() as $p) {
         $s->addOption($p->getTitle(), $p->getId());
     }
     $form->addDate('date')->setLabel(___('Run Rebill Manually'))->addRule('required');
     $form->addHidden('back_url');
     $form->addSubmit('run', array('value' => ___('Run')));
     return $form;
 }
Exemplo n.º 9
0
    function run()
    {
        $errors = array();
        $importFields = array('email' => 'email', 'name_f' => 'name_f', 'name_l' => 'name_l');
        $subusers_fields = $this->getDi()->config->get('subusers_fields', array());
        /*        if (in_array('login', $subusers_fields)) {
                    $importFields['login'] = '******';
                }
                if (in_array('pass', $subusers_fields)) {
                    $importFields['pass'] = '******';
                }*/
        foreach ($this->getDi()->config->get('subusers_fields', array()) as $field) {
            $importFields[$field] = $field;
        }
        $form = new Am_Form();
        $form->setAttribute('target', '_top');
        $form->setAttribute('enctype', 'multipart/form-data');
        $form->addStatic()->setContent('<div>' . ___('File should contain CSV list of user records for import in the following format:<br />
<strong>%s</strong>', implode(',', $importFields)) . '</div>');
        $form->addFile('file[]', null, array('prefix' => self::UPLOAD_PREFIX))->setLabel(___('File'))->addRule('required', ___('This field is a requried field'));
        $options = $this->getDi()->subusersSubscriptionTable->getProductOptions($this->reseller, true);
        reset($options);
        if (count($options) == 1) {
            $form->addHidden('groups[0]')->setValue(key($options))->toggleFrozen(true);
        } else {
            $form->addMagicSelect('groups')->setLabel(___('Groups'))->loadOptions($options);
        }
        $form->addSaveButton(___('Do Import'));
        $this->initForm($form);
        if ($form->isSubmitted()) {
            $value = $form->getValue();
            $upload = new Am_Upload($this->getDi());
            $upload->setPrefix(self::UPLOAD_PREFIX)->setTemp(3600);
            $upload->processSubmit('file');
            list($file) = $upload->getUploads();
            if (!$file) {
                throw new Am_Exception_InputError(___('CSV File was not specified'));
            }
            $pn = fopen($file->getFullPath(), 'r');
            while ($res = fgetcsv($pn)) {
                if (count($res) == count($importFields)) {
                    $imp = array();
                    foreach ($importFields as $fieldName => $v) {
                        $imp[$fieldName] = trim(array_shift($res));
                    }
                    $user = Am_Di::getInstance()->userRecord;
                    if ($error = $this->checkUniqEmail($imp['email'])) {
                        $errors[] = $error;
                        continue;
                    }
                    if (isset($imp['login']) && ($error = $this->checkUniqLogin($imp['login']))) {
                        $errors[] = $error;
                        continue;
                    }
                    $user->email = $imp['email'];
                    $user->name_f = $imp['name_f'];
                    $user->name_l = $imp['name_l'];
                    isset($imp['pass']) ? $user->setPass($imp['pass']) : $user->generatePassword();
                    isset($imp['login']) ? $user->login = $imp['login'] : $user->generateLogin();
                    foreach (array('login', 'email', 'pass', 'name_f', 'name_l') as $k) {
                        unset($imp[$k]);
                    }
                    foreach ($imp as $k => $v) {
                        $user->set($k, $v);
                    }
                    $user->data()->set('signup_email_sent', 1);
                    $user->set('subusers_parent_id', $this->reseller->pk());
                    $user->is_approved = 1;
                    $user->save();
                    if ($et = Am_Mail_Template::load('subusers.registration_mail', $user->lang)) {
                        $et->setUser($user);
                        $et->setPassword($user->getPlaintextPass());
                        $et->setReseller($this->reseller);
                        //backward compatibality (reseller_name_f, reseller_name_l, reseller_email)
                        $et->setReseller_name_f($this->reseller->name_f);
                        $et->setReseller_name_l($this->reseller->name_l);
                        $et->setReseller_email($this->reseller->email);
                        if (!empty($value['groups'])) {
                            $userTitle = array();
                            foreach ($this->getDi()->productTable->loadIds($value['groups']) as $product) {
                                $userTitle[] = $product->title;
                            }
                            $et->setUser_product(join(', ', $userTitle));
                            $resellerTitle = array();
                            $conditions = array('subusers_product_id' => $value['groups']);
                            foreach ($this->getDi()->productTable->findBy($conditions) as $product) {
                                $resellerTitle[] = $product->title;
                            }
                            $et->setReseller_product(join(', ', $resellerTitle));
                        }
                        $et->send($user);
                    }
                    $this->getDi()->subusersSubscriptionTable->setForUser($user->pk(), $value['groups']);
                }
            }
            fclose($pn);
            $this->getDi()->modules->get('subusers')->checkAndUpdate($this->reseller);
            if ($errors) {
                $out = '<ul class="errors">';
                foreach ($errors as $error) {
                    $out .= sprintf('<li>%s</li>', $error);
                }
                $out .= "</ul>";
                echo $out . $this->renderBackUrl() . '<br /><br />';
            } else {
                $this->grid->redirectBack();
            }
        } else {
            echo $this->renderTitle();
            echo $form;
        }
    }