public function createConfirmationForm($vars, $address) { $form = new Am_Form('dd-confirmation'); $name = $this->escape($this->plugin->getConfig('legal_name')); $addr = $this->plugin->getConfig('legal_address'); $form->addProlog(<<<CUT <h1>Confirmation</h1> <strong>{$name}</strong> <br /> {$addr} <br /> <br /> CUT ); $form->addStatic()->setContent($this->escape(sprintf('%s %s', $vars['name_f'], $vars['name_l'])))->setLabel('Name of Account Holder'); $form->addStatic()->setContent($this->escape($vars['account_number']))->setLabel('Bank/Building Society Account Number'); $form->addStatic()->setContent($this->escape($vars['sort_code']))->setLabel('Branch Sort Code'); $street = implode('<br/>', array_map(array($this, 'escape'), array_filter(array($address['address1'], $address['address2'], $address['address3'], $address['address4'])))); $form->addStatic()->setContent(sprintf(' %s<br /> %s<br /> %s<br /> %s<br /> %s<br /> %s', $this->escape($address['bank_name']), $this->escape($address['branch']), $street, $this->escape($address['town']), $this->escape($address['county']), $this->escape($address['postcode'])))->setLabel('Name and full postal address of your Bank or Building Society'); $form->addStatic()->setContent($this->plugin->getConfig('sun'))->setLabel('Service User Number (SUN)'); $form->addStatic()->setContent(Am_Paysystem_SmartDebit::REF_PREFIX . $this->invoice->public_id)->setLabel('Reference'); $form->addStatic(null, array('class' => 'no-label'))->setContent(<<<CUT <strong>Instruction to your Bank or Building Society</strong> <br /><br /> Please pay <strong>{$name}</strong> Direct Debits from the account detailed in this Instruction subject to the safeguards assured by the Direct Debit Guarantee. I understand that this Instruction may remain with <strong>{$name}</strong> and, if so, details will be passed electronically to my Bank/Building Society. CUT ); $g = $form->addGroup(null, array('class' => 'no-label')); $g->setSeparator(' '); $g->addSubmit('confirm', array('value' => 'Confirm')); $g->addSubmit('amend', array('value' => 'Amend')); $g->addSubmit('cancel', array('value' => 'Cancel')); $g->addSubmit('print', array('value' => 'Print')); $form->addScript()->setScript(<<<CUT \$('input[name=print]').click(function(){ window.print(); return false; }) CUT ); $form->addHidden(Am_Controller::ACTION_KEY)->setValue($this->getRequest()->getActionName()); $form->addHidden('id')->setValue($this->getFiltered('id')); return $form; }
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; } }