function askRemoteAccess() { $form = new Am_Form_Admin(); $info = $this->loadRemoteAccess(); if ($info && !empty($info['_tested'])) { return true; } if ($info) { $form->addDataSource(new Am_Request($info)); } $method = $form->addSelect('method', null, array('options' => array('ftp' => 'FTP', 'sftp' => 'SFTP')))->setLabel(___('Access Method')); $gr = $form->addGroup('hostname')->setLabel(___('Hostname')); $gr->addText('host')->addRule('required')->addRule('regex', 'Incorrect hostname value', '/^[\\w\\._-]+$/'); $gr->addHTML('port-label')->setHTML(' <b>Port</b>'); $gr->addText('port', array('size' => 3)); $gr->addHTML('port-notice')->setHTML(' leave empty if default'); $form->addText('user')->setLabel(___('Username'))->addRule('required'); $form->addPassword('pass')->setLabel(___('Password')); // $form->addTextarea('ssh_public_key')->setLabel(___('SSH Public Key')); // $form->addTextarea('ssh_private_key')->setLabel(___('SSH Private Key')); $form->addSubmit('', array('value' => ___('Continue'))); $form->addScript()->setScript(<<<CUT \$(function(){ \$('#method-0').change(function(){ \$('#ssh_public_key-0,#ssh_private_key-0').closest('.row').toggle( \$(this).val() == 'ssh' ); }).change(); }); CUT ); $error = null; $vars = $form->getValue(); if ($form->isSubmitted() && $form->validate() && !($error = $this->tryConnect($vars))) { $vars['_tested'] = true; $this->storeRemoteAccess($vars); return true; } else { //$this->view->title = ___("File Access Credentials Required"); $this->view->title = ___('Upgrade'); $this->view->content = ""; $this->outStepHeader(); if ($error) { $method->setError($error); } $this->view->content .= (string) $form; $this->view->display('admin/layout.phtml'); $this->noDisplay = true; } }
public function run() { $form = new Am_Form_Admin(); $form->setAction($this->getUrl()); $form->setAttribute('name', 'export'); $form->setAttribute('target', '_blank'); $form->addElement('magicselect', 'fields_to_export')->loadOptions($this->getExportOptions())->setLabel(___('Fields To Export')); $form->addElement('select', 'export_type')->loadOptions(Am_Grid_Export_Processor_Factory::getOptions())->setLabel(___('Export Format'))->setId('form-export-type'); foreach (Am_Grid_Export_Processor_Factory::createAll() as $id => $obj) { $obj->buildForm($form->addElement('fieldset', $id)->setId('form-export-options-' . $id)); } $form->addSubmit('export', array('value' => ___('Export'))); $script = <<<CUT (function(\$){ \$(function(){ function update_options(\$sel) { \$('[id^=form-export-options-]').hide(); \$('#form-export-options-' + \$sel.val()).show(); } update_options(\$('#form-export-type')); \$('#form-export-type').bind('change', function() { update_options(\$(this)); }) }) })(jQuery) CUT; $form->addScript('script')->setScript($script); $this->initForm($form); if ($form->isSubmitted()) { $values = $form->getValue(); $fields = array(); foreach ($values['fields_to_export'] as $fieldName) { $fields[$fieldName] = $this->getField($fieldName); } $export = Am_Grid_Export_Processor_Factory::create($values['export_type']); $export->run($this->grid, $this->getDataSource($fields), $fields, $values); exit; } else { echo $this->renderTitle(); echo $form; } }
function replaceProductAction() { $this->getDi()->authAdmin->getUser()->checkPermission('_payment', 'edit'); $item = $this->getDi()->invoiceItemTable->load($this->_request->getInt('id')); $pr = $this->getDi()->productTable->load($item->item_id); $form = new Am_Form_Admin('replace-product-form'); $form->setDataSources(array($this->_request)); $form->method = 'post'; $form->addHidden('id'); $form->addHidden('user_id'); $form->addStatic()->setLabel(___('Replace Product'))->setContent("#{$pr->product_id} [{$pr->title}]"); $sel = $form->addSelect('product_id')->setLabel('To Product'); $options = array('' => '-- ' . ___('Please select') . ' --'); foreach ($this->getDi()->billingPlanTable->getProductPlanOptions() as $k => $v) { if (strpos($k, $pr->pk() . '-') !== 0) { $options[$k] = $v; } } $sel->loadOptions($options); $sel->addRule('required'); $form->addSubmit('_save', array('value' => ___('Save'))); if ($form->isSubmitted() && $form->validate()) { try { list($p, $b) = explode("-", $sel->getValue(), 2); $item->replaceProduct(intval($p), intval($b)); $this->getDi()->adminLogTable->log("Inside invoice: product #{$item->item_id} replaced to product #{$p} (plan #{$b})", 'invoice', $item->invoice_id); return $this->ajaxResponse(array('ok' => true)); } catch (Am_Exception $e) { $sel->setError($e->getMessage()); } } echo $form->__toString(); }
/** @return Am_Form_Admin */ function createMysqlForm() { $form = new Am_Form_Admin(); $el = $form->addText('host')->setLabel('Wordpress MySQL Hostname'); $el->addRule('required', 'This field is required'); $form->addText('user')->setLabel('Wordpress MySQL Username')->addRule('required', 'This field is required'); $form->addPassword('pass')->setLabel('Wordpress MySQL Password'); $form->addText('db')->setLabel('Wordpress MySQL Database Name')->addRule('required', 'This field is required'); $form->addText('prefix')->setLabel('Wordpress Tables Prefix'); $dbConfig = $this->getDi()->getParameter('db'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('host' => $dbConfig['mysql']['host'], 'user' => $dbConfig['mysql']['user'], 'prefix' => 'wp_'))); $el->addRule('callback2', '-', array($this, 'validateDbConnect')); $form->addSubmit(null, array('value' => 'Continue...')); return $form; }
protected function createForm() { $f = new Am_Form_Admin(); $f->addText('user')->setLabel('Enter username of existing user')->addRule('required', 'This field is required'); $f->addText('aff')->setLabel('Enter username of existing affiliate')->addRule('required', 'This field is required'); $f->addText('coupon')->setLabel('Enter coupon code or leave field empty'); $f->addCheckbox('is_first')->setLabel('Is first user invoice?'); $f->addElement(new Am_Form_Element_ProductsWithQty('product_id'))->setLabel(___('Choose products to include into test invoice'))->loadOptions(Am_Di::getInstance()->billingPlanTable->selectAllSorted())->addRule('required'); $f->addSelect('paysys_id')->setLabel(___('Payment System'))->loadOptions(Am_Di::getInstance()->paysystemList->getOptions()); $f->addSubmit('', array('value' => 'Test')); $f->addScript()->setScript(<<<CUT \$(function(){ \$("#user-0, #aff-0" ).autocomplete({ minLength: 2, source: window.rootUrl + "/admin-users/autocomplete" }); }); CUT ); foreach ($this->grid->getVariablesList() as $k) { $kk = $this->grid->getId() . '_' . $k; if ($v = @$_REQUEST[$kk]) { $f->addHidden($kk)->setValue($v); } } return $f; }
protected function createForm() { $f = new Am_Form_Admin(); $f->addText('user')->setLabel('Enter username of existing user')->addRule('required', 'This field is required'); $f->addText('aff')->setLabel('Enter username of existing affiliate')->addRule('required', 'This field is required'); $f->addMagicSelect('product_ids')->setLabel('Choose products to include into test invoice')->loadOptions(Am_Di::getInstance()->productTable->getOptions())->addRule('required', 'This field is required'); $f->addSubmit('', array('value' => 'Test')); $f->addScript()->setScript(<<<CUT \$(function(){ \$("#user-0, #aff-0" ).autocomplete({ minLength: 2, source: window.rootUrl + "/admin-users/autocomplete" }); }); CUT ); foreach ($this->grid->getVariablesList() as $k) { $kk = $this->grid->getId() . '_' . $k; if ($v = @$_REQUEST[$kk]) { $f->addHidden($kk)->setValue($v); } } return $f; }