Beispiel #1
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"));
 }
 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');
 }
Beispiel #3
0
 public function indexAction()
 {
     /* @var $invoice Invoice */
     $invoice = $this->getDi()->invoiceTable->findBySecureId($this->getParam('secure_id'), 'payment-link');
     if (!$invoice || $invoice->status != Invoice::PENDING) {
         throw new Am_Exception_InternalError(sprintf('Unknow invoice [%s] or invoice is already processed', filterId($this->getParam('secure_id'))));
     }
     if (!$invoice->due_date && sqlDate($invoice->tm_added) < sqlDate("-" . Invoice::DEFAULT_DUE_PERIOD . " days")) {
         throw new Am_Exception_InputError(___('Invoice is expired'));
     } elseif ($invoice->due_date && $invoice->due_date < sqlDate('now')) {
         throw new Am_Exception_InputError(___('Invoice is expired'));
     }
     $form = new Am_Form();
     if (!$invoice->paysys_id) {
         $psOptions = array();
         foreach (Am_Di::getInstance()->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->toggleFrozen(true);
         }
     }
     $form->addSaveButton(___('Pay'));
     $this->view->invoice = $invoice;
     $this->view->form = $form;
     $form->setDataSources(array($this->getRequest()));
     if ($form->isSubmitted() && $form->validate()) {
         $vars = $form->getValue();
         if (!$invoice->paysys_id) {
             $invoice->setPaysystem($vars['paysys_id']);
             $invoice->save();
         }
         $payProcess = new Am_Paysystem_PayProcessMediator($this, $invoice);
         $result = $payProcess->process();
         throw new Am_Exception_InternalError(sprintf('Error occurred while trying proccess invoice [%s]', filterId($invoice->public_id)));
     }
     $this->view->layoutNoMenu = true;
     $this->view->display('pay.phtml');
 }
 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;
 }
Beispiel #5
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;
    }
Beispiel #6
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;
        }
    }