public function initConfigForm(Am_Form $form) { $el = $form->addSelect('type', array('id' => 'newsletter-type-select'))->setLabel('Type'); $el->addOption('Single Checkbox', 'checkbox'); $el->addOption('Checkboxes for Selected Lists', 'checkboxes'); $lists = $form->addMagicSelect('lists', array('id' => 'newsletter-lists-select'))->setLabel(array('Lists', 'All List will be displayed if none selected')); $lists->loadOptions(Am_Di::getInstance()->newsletterListTable->getAdminOptions()); $form->addScript()->setScript(<<<CUT jQuery(document).ready(function(\$) { \$("#newsletter-type-select").change(function(){ var val = \$(this).val(); \$("#row-newsletter-lists-select").toggle(val == 'checkboxes'); }).change(); }); CUT ); $form->addAdvCheckbox('unchecked')->setLabel(array('Default unchecked', 'Must the checkboxes be initially unchecked?')); }
public function _initConfigForm(Am_Form $form) { $sel = $form->addMagicSelect('products')->setLabel(___("Products\nkeep empty to report all products")); $sel->loadOptions($this->getDi()->productTable->getOptions()); }
public function initConfigForm(Am_Form $form) { $form->addMagicSelect('product_ids')->loadOptions(Am_Di::getInstance()->productTable->getOptions())->setLabel(___("Add Subscription to the following products\n" . "right after signup form has been submitted, " . "subscription will be added only for new users")); }
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; } }
public function initConfigForm(Am_Form $form) { Am_Di::getInstance()->plugins_payment->loadEnabled(); $ps = $form->addMagicSelect('paysystems')->setLabel(array('Payment Options', 'if none selected, all enabled will be displayed'))->loadOptions(Am_Di::getInstance()->paysystemList->getOptionsPublic()); $form->addAdvCheckbox('hide_if_one')->setLabel(array('Hide Select', 'if there is only one choice')); }