public function createForm() { $mainForm = new Am_Form_Admin(); $form = $mainForm->addFieldset()->setLabel(___('Admin Settings')); $login = $form->addText('login')->setLabel(___('Admin Username')); $login->addRule('required')->addRule('length', ___('Length of username must be from %d to %d', 4, 16), array(4, 16))->addRule('regex', ___('Admin username must be alphanumeric in small caps'), '/^[a-z][a-z0-9_-]+$/'); $set = $form->addGroup()->setLabel(___('First and Last Name')); $set->setSeparator(' '); $set->addText('name_f'); $set->addText('name_l'); $pass = $form->addPassword('_passwd')->setLabel(___('New Password')); $pass->addRule('length', ___('Length of admin password must be from %d to %d', 6, 16), array(6, 16)); $pass->addRule('neq', ___('Password must not be equal to username'), $login); $pass0 = $form->addPassword('_passwd0')->setLabel(___('Confirm New Password')); $pass0->addRule('eq', ___('Passwords must be the same'), $pass); $form->addText('email')->setLabel(___('E-Mail Address'))->addRule('required'); $super = $form->addAdvCheckbox('super_user')->setId('super-user')->setLabel(___('Super Admin')); //Only Super Admin has access to this page $record = $this->grid->getRecord(); if ($this->getDi()->authAdmin->getUserId() == $record->get('admin_id')) { $super->toggleFrozen(true); } if ($this->getDi()->authAdmin->getUserId() != $record->get('admin_id')) { $group = $form->addGroup('perms')->setId('perms')->setLabel(___('Permissions'))->setSeparator('<br />'); foreach ($this->getDi()->authAdmin->getPermissionsList() as $perm => $title) { if (is_string($title)) { $group->addCheckbox($perm)->setContent($title); } else { $gr = $group->addGroup($perm); $gr->addStatic()->setContent('<div>'); $gr->addStatic()->setContent('<strong>' . $title['__label'] . '</strong>'); $gr->addStatic()->setContent('<div style="padding-left:1em">'); unset($title['__label']); foreach ($title as $k => $v) { $gr->addCheckbox($k)->setContent($v); $gr->addStatic()->setContent(' '); } $gr->addStatic()->setContent('</div>'); $gr->addStatic()->setContent('</div>'); } } $mainForm->addScript()->setScript(<<<CUT \$('#super-user').change(function(){ \$('#row-perms').toggle(!this.checked); }).change(); CUT ); } $self_password = $mainForm->addFieldset()->setLabel(___('Authentification'))->addPassword('self_password')->setLabel(___("Your Password\n" . "enter your current password\n" . "in order to edit admin record")); $self_password->addRule('callback', ___('Wrong password'), array($this, 'checkSelfPassword')); return $mainForm; }
function createForm() { $form = new Am_Form_Admin(); $form->addText('title', array('size' => 80))->setLabel(___('Title'))->addRule('required'); $form->addText('desc', array('size' => 80))->setLabel(___('Description')); $sel = $form->addSelect('access', array('size' => 1, 'id' => 'newsletter-access'))->setLabel(___('Access')); $sel->loadOptions(array(NewsletterList::ACCESS_RESTRICTED => ___('Restricted Access'), NewsletterList::ACCESS_USERS => ___('Access allowed for all Users'), NewsletterList::ACCESS_GUESTS_AND_USERS => ___('Access allowed for all Users and Guests'))); $form->addScript()->setScript(<<<CUT jQuery(document).ready(function(\$) { \$("#newsletter-access").change(function(){ \$("select.category").closest(".row").toggle(\$(this).val() == 0); }).change(); }); CUT ); $form->addElement(new Am_Form_Element_ResourceAccess())->setName('_access')->setLabel(___('Access Permissions'))->setAttribute('without_period', 'true'); return $form; }
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 createForm() { $form = new Am_Form_Admin(); $form->addAdvRadio('is_custom')->loadOptions(array(0 => ___('Use Pre-Defined Template'), 1 => ___('Define Custom Html Message')))->setValue(0); $form->addTextarea('content', array('rows' => '7', 'class' => 'row-wide el-wide'))->setLabel(___("Content\n" . 'You can use all user specific placeholders here eg. %user.login%, %user.name_f%, %user.name_l% etc.'))->addRule('required'); $form->addText('url', array('class' => 'el-wide', 'rel' => 'form-pre-defined'))->setLabel(___('Link')); $form->addAdvcheckbox('is_blank', array('rel' => 'form-pre-defined'))->setLabel(___('Open Link in New Window')); $form->addScript()->setScript(<<<CUT \$('[name=is_custom]').change(function(){ \$('[rel=form-pre-defined]').closest('.row').toggle(\$('[name=is_custom]:checked').val() == 0) }).change(); CUT ); $sel = $form->addMagicSelect('_target')->setLabel(___('Target By User')); $cats = $pr = $gr = array(); foreach ($this->getDi()->userGroupTable->getSelectOptions() as $k => $v) { $gr['user_group_id-' . $k] = 'Group: ' . $v; } $options = array('free' => ___('All'), 'user_id' => ___('Specific User')) + ($cats ? array(___('Product Categories') => $cats) : array()) + ($gr ? array(___('User Groups') => $gr) : array()) + ($pr ? array(___('Products') => $pr) : array()); $sel->loadOptions($options); //$sel->addRule('required'); $sel->setJsOptions('{onChange:function(val){ $("input[name^=_loginOrEmail]").closest(\'.row\').toggle(val.hasOwnProperty("user_id")); }}'); $loginGroup = $form->addGroup(''); $loginGroup->setLabel(___('E-Mail Address or Username')); $loginGroup->addHidden('_savedLoginOrEmail')->setValue(''); $login = $loginGroup->addText('_loginOrEmail[]'); $label_add_user = ___('Add User'); $loginGroup->addHtml()->setHtml(<<<CUT <div><a href="javascript:void(null);" id="target-user_id-add" class="local">{$label_add_user}</a></div> CUT ); $form->addElement(new Am_Form_Element_ResourceAccess('_raccess', array('without_free' => true)))->setLabel('Target By Product'); $gr = $form->addGroup()->setSeparator(' ')->setLabel(___("Dates\n" . 'date range when notification is shown')); $gr->addDate('begin', array('placeholder' => ___('Begin Date'))); $gr->addDate('expire', array('placeholder' => ___('Expire Date'))); $form->addScript('script')->setScript(<<<CUT \$("input[name^=_loginOrEmail]").autocomplete({ minLength: 2, source: window.rootUrl + "/admin-users/autocomplete" }); CUT ); $delIcon = $this->getDi()->view->icon('delete'); $form->addScript('script2')->setScript(<<<CUT var arr = \$('[name=_savedLoginOrEmail]').val().split(',').reverse(); \$('[name^=_loginOrEmail]').val(arr.pop()); for (var i in arr) { var \$field = addEmailOrLogin(\$('#target-user_id-add')); \$field.val(arr[i]); } function addEmailOrLogin(context) { var \$field = \$('<input tyep="text" name="_loginOrEmail[]" />'); \$(context).before('<br />'); \$(context).before(\$field); \$(context).before('<a href="javascript:void(null)" onclick="\$(this).prev().remove();\$(this).prev().remove();\$(this).next().remove();\$(this).remove()">{$delIcon}</a>'); \$(context).before('<br />'); \$field.autocomplete({ minLength: 2, source: window.rootUrl + "/admin-users/autocomplete" }); return \$field; } \$('#target-user_id-add').click(function(){ addEmailOrLogin(this); }) CUT ); $form->addText('limit', array('placeholder' => ___('Unlimited')))->setLabel(___("Limit Number of Display per User\n" . 'keep it empty for unlimited')); return $form; }
function createForm() { $form = new Am_Form_Admin(); $record = $this->getRecord(); $plugins = $this->getDi()->plugins_newsletter->loadEnabled()->getAllEnabled(); if ($record->isLoaded()) { if ($record->plugin_id) { $group = $form->addFieldset(); $group->setLabel(ucfirst($record->plugin_id)); $form->addStatic()->setLabel(___('Plugin List Id'))->setContent(Am_Controller::escape($record->plugin_list_id)); } } else { if (count($plugins) > 1) { $sel = $form->addSelect('plugin_id')->setLabel(___('Plugin')); $sel->addOption(___('Standard'), ''); foreach ($plugins as $pl) { if (!$pl->canGetLists() && $pl->getId() != 'standard') { $sel->addOption($pl->getTitle(), $pl->getId()); } } } foreach ($plugins as $pl) { $group = $form->addFieldset($pl->getId())->setId('headrow-' . $pl->getId()); $group->setLabel($pl->getTitle()); } $form->addText('plugin_list_id')->setLabel(___("Plugin List Id\nvalue required")); $form->addScript()->setScript(<<<END \$(function(){ function showHidePlugins(el, skip) { var txt = \$("input[name='plugin_list_id']"); var enabled = el.size() && (el.val() != ''); txt.closest(".row").toggle(enabled); if (enabled) txt.rules("add", { required : true}); else if(skip) txt.rules("remove", "required"); var selected = (el.size() && el.val()) ? el.val() : 'standard'; \$("[id^='headrow-']").hide(); \$("[id=headrow-"+selected+"-legend]").show(); \$("[id=headrow-"+selected+"-pluginoptions]").show(); \$("[id=headrow-"+selected+"]").show(); } \$("select[name='plugin_id']").change(function(){ showHidePlugins(\$(this), true); }); showHidePlugins(\$("select[name='plugin_id']"), false); }); END ); } $form->addText('title', array('class' => 'el-wide'))->setLabel(___('Title'))->addRule('required'); $form->addText('desc', array('class' => 'el-wide'))->setLabel(___('Description')); $form->addAdvCheckbox('hide')->setLabel(___("Hide\n" . "do not display this item in members area")); $form->addAdvCheckbox('auto_subscribe')->setLabel(___("Auto-Subscribe users to list\n" . "once it becomes accessible for them")); foreach ($plugins as $pl) { $group = $form->addElement(new Am_Form_Container_PrefixFieldset('_vars'))->setId('headrow-' . $pl->getId() . '-pluginoptions'); $gr = $group->addElement(new Am_Form_Container_PrefixFieldset($pl->getId())); $pl->getIntegrationFormElements($gr); } $group = $form->addFieldset('access')->setLabel(___('Access')); $group->addElement(new Am_Form_Element_ResourceAccess())->setName('_access')->setLabel(___('Access Permissions'))->setAttribute('without_free_without_login', 'true')->setAttribute('without_period', 'true'); return $form; }
function createForm() { $form = new Am_Form_Admin(); $form->setAttribute('enctype', 'multipart/form-data'); $form->setAttribute('target', '_top'); $maxFileSize = min(ini_get('post_max_size'), ini_get('upload_max_filesize')); $el = $form->addElement(new Am_Form_Element_Upload('path', array(), array('prefix' => 'video')))->setLabel(___("Video/Audio File\n" . "(max upload size %s)\n" . "You can use this feature only for video and\naudio formats that %ssupported by %s%s", $maxFileSize, $this->getDi()->config->get('video_player', 'Flowplayer') == 'Flowplayer' ? '<a href="http://flowplayer.org/documentation/installation/formats.html" class="link" target="_blank">' : '<a href="http://www.longtailvideo.com/support/jw-player/28836/media-format-support/" class="link" target="_blank">', $this->getDi()->config->get('video_player', 'Flowplayer') == 'Flowplayer' ? 'Flowplayer' : 'JWPlayer', '</a>'))->setId('form-path'); $jsOptions = <<<CUT { onFileAdd : function (info) { var txt = \$(this).closest("form").find("input[name='title']"); if (txt.data('changed-value')) return; txt.val(info.name); } } CUT; $el->setJsOptions($jsOptions); $form->addScript()->setScript(<<<CUT \$(function(){ \$("input[name='title']").change(function(){ \$(this).data('changed-value', true); }); }); CUT ); $el->addRule('required'); $form->addUpload('poster_id', null, array('prefix' => 'video-poster'))->setLabel(___("Poster Image\n" . "applicable only for video files")); $form->addText('title', array('class' => 'el-wide'))->setLabel(___('Title'))->addRule('required', 'This field is required'); $form->addText('desc', array('class' => 'el-wide'))->setLabel(___('Description')); $form->addAdvCheckbox('hide')->setLabel(___("Hide\n" . "do not display this item link in members area")); $form->addElement(new Am_Form_Element_PlayerConfig('config'))->setLabel(___("Player Configuration\n" . 'this option is applied only for video files')); $form->addSelect('tpl')->setLabel(___("Template\nalternative template for this video\n" . "aMember will look for templates in [application/default/views/] folder\n" . "and in theme's [/] folder\n" . "and template filename must start with [layout]"))->loadOptions($this->getTemplateOptions()); $form->addElement(new Am_Form_Element_ResourceAccess())->setName('_access')->setLabel(___('Access Permissions')); $form->addText('no_access_url', array('class' => 'el-wide'))->setLabel(___("No Access URL\n" . "customer without required access will see link to this url in " . "the player window\nleave empty if you want to redirect to " . "default 'No access' page")); $this->addCategoryToForm($form); $fs = $form->addAdvFieldset('meta', array('id' => 'meta'))->setLabel(___('Meta Data')); $fs->addText('meta_title', array('class' => 'el-wide'))->setLabel(___('Title')); $fs->addText('meta_keywords', array('class' => 'el-wide'))->setLabel(___('Keywords')); $fs->addText('meta_description', array('class' => 'el-wide'))->setLabel(___('Description')); $form->addEpilog('<div class="info">' . ___('In case of video do not start play before full download and you use <a class="link" href="http://en.wikipedia.org/wiki/MPEG-4_Part_14">mp4 format</a> more possible that metadata (moov atom) is located at the end of file. There is special programs that allow to relocate this metadata to the beginning of your file and allow play video before full download (On Linux mashine you can use <em>qt-faststart</em> utility to do it). Also your video editor can has option to locate metadata at beginning of file (something like <em>FastStart</em> or <em>Web Optimized</em> option). You need to relocate metadata for this file and reupload it to aMember. You can use such utilites as <em>AtomicParsley</em> or similar to check your file structure.') . '</div>'); return $form; }
public function addInvoiceAction() { $this->getDi()->authAdmin->getUser()->checkPermission('grid_invoice', 'insert'); $form = new Am_Form_Admin('add-invoice'); $tm_added = $form->addDate('tm_added')->setLabel(___('Date')); $tm_added->setValue($this->getDi()->sqlDate); $tm_added->addRule('required'); $comment = $form->addText('comment', array('class' => 'el-wide'))->setLabel(___("Comment\nfor your reference")); $form->addElement(new Am_Form_Element_ProductsWithQty('product_id'))->setLabel(___('Products'))->loadOptions($this->getDi()->billingPlanTable->selectAllSorted())->addRule('required'); $form->addSelect('paysys_id')->setLabel(___('Payment System'))->setId('add-invoice-paysys_id')->loadOptions(array('' => '') + $this->getDi()->paysystemList->getOptions()); $couponEdit = $form->addText('coupon')->setLabel(___('Coupon'))->setId('p-coupon'); $action = $form->addAdvRadio('_action')->setLabel(___('Action'))->setId('add-invoice-action')->loadOptions(array('pending' => ___('Just Add Pending Invoice'), 'pending-payment' => ___('Add Invoice and Payment/Access Manually'), 'pending-send' => ___('Add Pending Invoice and Send Link to Pay It to Customer')))->setValue('pending'); $receipt = $form->addText('receipt')->setLabel(___('Receipt#'))->setId('add-invoice-receipt'); $tm_due = $form->addDate('tm_due')->setLabel(___('Due Date')); $tm_due->setValue(sqlDate('+7 days')); $tm_due->setId('add-invoice-due'); $message = $form->addTextarea('message', array('class' => 'el-wide'))->setLabel(___("Message\nwill be included to email to user")); $message->setId('add-invoice-message'); $form->addElement('email_link', 'invoice_pay_link')->setLabel(___('Email Template with Payment Link')); $form->addScript()->setScript(' $("[name=_action]").change(function(){ var val = $("[name=_action]:checked").val(); $("#add-invoice-receipt").closest("div.row").toggle(val == "pending-payment") $("#add-invoice-due").closest("div.row").toggle(val == "pending-send") $("#add-invoice-message").closest("div.row").toggle(val == "pending-send") $("[name=invoice_pay_link]").closest("div.row").toggle(val == "pending-send") }).change(); '); $script = <<<CUT \$("input#p-coupon").autocomplete({ minLength: 2, source: window.rootUrl + "/admin-coupons/autocomplete" }); CUT; $form->addScript('script')->setScript($script); $form->addSaveButton(); $form->setDataSources(array($this->getRequest())); do { if ($form->isSubmitted() && $form->validate()) { $vars = $form->getValue(); $invoice = $this->getDi()->invoiceRecord; $invoice->setUser($this->getDi()->userTable->load($this->user_id)); $invoice->tm_added = sqlTime($vars['tm_added']); if ($vars['coupon']) { $invoice->setCouponCode($vars['coupon']); $error = $invoice->validateCoupon(); if ($error) { $couponEdit->setError($error); break; } } foreach ($vars['product_id'] as $plan_id => $qty) { $p = $this->getDi()->billingPlanTable->load($plan_id); $pr = $p->getProduct(); try { $invoice->add($pr, $qty); } catch (Am_Exception_InputError $e) { $form->setError($e->getMessage()); break 2; } } $invoice->comment = $vars['comment']; $invoice->calculate(); switch ($vars['_action']) { case 'pending': if (!$this->_addPendingInvoice($invoice, $form, $vars)) { break 2; } break; case 'pending-payment': if (!$this->_addPendingInvoiceAndPayment($invoice, $form, $vars)) { break 2; } break; case 'pending-send': if (!$this->_addPendingInvoiceAndSend($invoice, $form, $vars)) { break 2; } break; default: throw new Am_Exception_InternalError(sprintf('Unknown action [%s] as %s::%s', $vars['_action'], __CLASS__, __METHOD__)); } $this->getDi()->adminLogTable->log("Add Invoice (#{$invoice->invoice_id}/{$invoice->public_id}, Billing Terms: " . new Am_TermsText($invoice) . ")", 'invoice', $invoice->invoice_id); return $this->redirectLocation(REL_ROOT_URL . '/admin-user-payments/index/user_id/' . $this->user_id); } // if } while (false); $this->view->content = '<h1>' . ___('Add Invoice') . ' (<a href="' . REL_ROOT_URL . '/admin-user-payments/index/user_id/' . $this->user_id . '">' . ___('return') . '</a>)</h1>' . (string) $form; $this->view->display('admin/user-layout.phtml'); }
public function createConfigForm(Am_Grid_Editable $grid) { $form = new Am_Form_Admin(); $record = $grid->getRecord($grid->getCurrentAction()); if (empty($record->type)) { $record->type = null; } if (empty($record->tier)) { $record->tier = 0; } $globalOptions = AffCommissionRule::getTypes(); $record->type && !isset($globalOptions[$record->type]) && ($globalOptions[$record->type] = $record->getTypeTitle()); $cb = $form->addSelect('type')->setLabel('Type')->loadOptions($globalOptions); if ($record->isGlobal()) { $cb->toggleFrozen(true); } $form->addScript()->setScript(<<<CUT \$(function(){ \$("select#type-0").change(function(){ var val = \$(this).val(); \$("fieldset#multiplier").toggle(val == 'multi'); \$("fieldset#commission").toggle(val != 'multi'); var checked = val.match(/^global-/); \$("#conditions").toggle(!checked); \$("#sort_order-0").closest(".row").toggle(!checked); }).change(); \$("#condition-select").change(function(){ var val = \$(this).val(); \$(this.options[this.selectedIndex]).prop("disabled", true); this.selectedIndex = 0; \$('input[name="_conditions_status[' + val + ']"]').val(1); \$('#row-'+val).show(); }); \$("#conditions .row").not("#row-condition-select").each(function(){ var val = /row-(.*)/i.exec(this.id).pop(); if (!\$('input[name="_conditions_status[' + val + ']"]').val()) { \$(this).hide(); } else { \$("#condition-select option[value='"+val+"']").prop("disabled", true); } \$(this).find(".element-title").append(" <a href='javascript:' class='hide-row'>X</a> "); }); \$(document).on('click',"a.hide-row",function(){ var row = \$(this).closest(".row"); var id = row.hide().attr("id"); var val = /row-(.*)/i.exec(id).pop(); \$('input[name="_conditions_status[' + val + ']"]').val(0); \$("#condition-select option[value='"+val+"']").prop("disabled", false); }); \$('#used-type').change(function(){ \$('#used-batch_id, #used-code').hide(); switch (\$(this).val()) { case 'batch' : \$('#used-batch_id').show(); break; case 'coupon' : \$('#used-code').show(); break; } }).change() }); CUT ); $comment = $form->addText('comment', array('size' => 40))->setLabel('Rule title - for your own reference'); if ($record->isGlobal()) { $comment->toggleFrozen(true); } else { $comment->addRule('required', 'This field is required'); } if (!$record->isGlobal()) { $form->addInteger('sort_order')->setLabel('Sort order - rules with lesser values executed first'); } if (!$record->isGlobal()) { $set = $form->addFieldset('', array('id' => 'conditions'))->setLabel('Conditions'); $set->addSelect('', array('id' => 'condition-select'))->setLabel('Add Condition')->loadOptions(array('' => ___('Select Condition...'), 'first_time' => ___('First Time Purchase of Product'), 'coupon' => ___('By Used Coupon'), 'paysys_id' => ___('By Used Payment System'), 'product_id' => ___('By Product'), 'product_category_id' => ___('By Product Category'), 'aff_group_id' => ___('By Affiliate Group Id'), 'aff_sales_count' => ___('By Affiliate Sales Count'), 'aff_items_count' => ___('By Affiliate Item Sales Count'), 'aff_sales_amount' => ___('By Affiliate Sales Amount'), 'aff_product_id' => ___('By Affiliate Active Product'), 'aff_product_category_id' => ___('By Affiliate Active Product Category'))); $set->addHidden('_conditions_status[product_id]'); $set->addMagicSelect('_conditions[product_id]', array('id' => 'product_id'))->setLabel(___("This rule is for particular products\n" . 'if none specified, rule works for all products'))->loadOptions(Am_Di::getInstance()->productTable->getOptions()); $set->addHidden('_conditions_status[product_category_id]'); $el = $set->addMagicSelect('_conditions[product_category_id]', array('id' => 'product_category_id'))->setLabel(___("This rule is for particular product categories\n" . "if none specified, rule works for all product categories")); $el->loadOptions(Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions()); $set->addHidden('_conditions_status[aff_group_id]'); $el = $set->addMagicSelect('_conditions[aff_group_id]', array('id' => 'aff_group_id'))->setLabel(___("This rule is for particular affiliate groups\n" . "you can add user groups and assign it to customers in User editing form")); $el->loadOptions(Am_Di::getInstance()->userGroupTable->getSelectOptions()); $set->addHidden('_conditions_status[aff_sales_count]'); $gr = $set->addGroup('_conditions[aff_sales_count]', array('id' => 'aff_sales_count'))->setLabel(___("Affiliate sales count\n" . "trigger this commission if affiliate made more than ... sales within ... days before the current date\n" . "(only count of new invoices is calculated)")); $gr->addStatic()->setContent('use only if affiliate referred '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' invoices within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); $set->addHidden('_conditions_status[aff_items_count]'); $gr = $set->addGroup('_conditions[aff_items_count]', array('id' => 'aff_items_count'))->setLabel(___("Affiliate items count\n" . "trigger this commission if affiliate made more than ... item sales within ... days before the current date\n" . "(only count of items in new invoices is calculated")); $gr->addStatic()->setContent('use only if affiliate made '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' item sales within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); $set->addHidden('_conditions_status[aff_sales_amount]'); $gr = $set->addGroup('_conditions[aff_sales_amount]', array('id' => 'aff_sales_amount'))->setLabel(___("Affiliate sales amount\n" . "trigger this commission if affiliate made more than ... sales within ... days before the current date\n" . "(only new invoices calculated)")); $gr->addStatic()->setContent('use only if affiliate made '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' ' . Am_Currency::getDefault() . ' in commissions within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); $set->addHidden('_conditions_status[coupon]'); $gr = $set->addGroup('_conditions[coupon]', array('id' => 'coupon'))->setLabel(___('Used coupon')); $gr->setSeparator(' '); $gr->addSelect('used')->loadOptions(array('1' => 'Used', '0' => "Didn't Use")); $gr->addSelect('type')->setId('used-type')->loadOptions(array('any' => ___('Any Coupon'), 'batch' => ___("Coupon From Batch"), 'coupon' => ___("Specific Coupon"))); $gr->addSelect('batch_id')->setId('used-batch_id')->loadOptions($this->getDi()->couponBatchTable->getOptions()); $gr->addText('code', array('size' => 10))->setId('used-code'); $set->addHidden('_conditions_status[paysys_id]'); $set->addMagicSelect('_conditions[paysys_id]', array('id' => 'paysys_id'))->setLabel(___('This rule is for particular payment system'))->loadOptions(Am_Di::getInstance()->paysystemList->getOptions()); $set->addHidden('_conditions_status[first_time]'); $set->addStatic('_conditions[first_time]', array('id' => 'first_time'))->setLabel(___("First Time Purchase of Product"))->setContent("<div><strong>✓</strong></div>"); $set->addHidden('_conditions_status[aff_product_id]'); $set->addMagicSelect('_conditions[aff_product_id]', array('id' => 'aff_product_id'))->setLabel(___("Apply this rule if affiliate has active access to"))->loadOptions(Am_Di::getInstance()->productTable->getOptions()); $set->addHidden('_conditions_status[aff_product_category_id]'); $el = $set->addMagicSelect('_conditions[aff_product_category_id]', array('id' => 'aff_product_category_id'))->setLabel(___("Apply this rule if affiliate has active access to")); $el->loadOptions(Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions()); } $set = $form->addFieldset('', array('id' => 'commission'))->setLabel('Commission'); if ($record->tier == 0) { $set->addElement(new Am_Form_Element_AffCommissionSize(null, null, 'first_payment'))->setLabel(___("Commission for First Payment\ncalculated for first payment in each invoice")); $set->addElement(new Am_Form_Element_AffCommissionSize(null, null, 'recurring'))->setLabel(___("Commission for Rebills")); $group = $set->addGroup('')->setLabel(___("Commission for Free Signup\ncalculated for first customer invoice only")); $group->addText('free_signup_c', array('size' => 5)); $group->addStatic()->setContent(' ' . Am_Currency::getDefault()); //->addRule('gte', 'Value must be a valid number > 0, or empty (no text)', 0); } else { $set->addText('first_payment_c')->setLabel(___("Commission\n% of commission received by referred affiliate")); } if (!$record->isGlobal()) { $set = $form->addFieldset('', array('id' => 'multiplier'))->setLabel('Multipier'); $set->addText('multi', array('size' => 5, 'placeholder' => '1.0'))->setLabel(___("Multiply commission calculated by the following rules\n" . "to number specified in this field. To keep commission untouched, enter 1 or delete this rule")); //->addRule('gt', 'Values must be greater than 0.0', 0.0); } return $form; }
function createForm() { $form = new Am_Form_Admin('am-form-email'); $form->setDataSources(array($this->getRequest())); $form->setAction($this->getUrl(null, 'preview')); if ($options = $this->getDi()->emailTemplateLayoutTable->getOptions()) { $form->addSelect('email_template_layout_id')->setLabel(___('Layout'))->loadOptions(array('' => ___('No Layout')) + $options); } $gr = $form->addGroup()->setLabel(___("Reply To\n" . "mailbox for replies to message"))->setSeparator(' '); $sel = $gr->addSelect('reply_to')->loadOptions($this->getReplyToOptions()); $id = $sel->getId(); $gr->addText('reply_to_other', array('placeholder' => ___('Email Address')))->setId($id . '-other')->persistentFreeze(true); // ??? why is it necessary? but it is $gr->addScript()->setScript(<<<CUT \$('#{$id}').change(function(){ \$('#{$id}-other').toggle(\$(this).val() == 'other'); }).change(); CUT ); $subj = $form->addText('subject', array('class' => 'el-wide'))->setLabel(___('Email Subject')); $subj->persistentFreeze(true); // ??? why is it necessary? but it is $subj->addRule('required', ___('Subject is required')); // $arch = $form->addElement('advcheckbox', 'do_archive')->setLabel(array('Archive Message', 'if you are sending it to newsletter subscribers')); $format = $form->addGroup(null)->setLabel(___('E-Mail Format')); $format->setSeparator(' '); $format->addRadio('format', array('value' => 'html'))->setContent(___('HTML Message')); $format->addRadio('format', array('value' => 'text'))->setContent(___('Plain-Text Message')); $group = $form->addGroup('', array('id' => 'body-group', 'class' => 'no-label'))->setLabel(___('Message Text')); $group->addStatic()->setContent('<div class="mail-editor">'); $group->addStatic()->setContent('<div class="mail-editor-element">'); $group->addElement('textarea', 'body', array('id' => 'body-0', 'rows' => '15', 'class' => 'el-wide')); $group->addStatic()->setContent('</div>'); $group->addStatic()->setContent('<div class="mail-editor-element">'); $this->tagsOptions = Am_Mail_TemplateTypes::getInstance()->getTagsOptions('send_signup_mail'); $tagsOptions = array(); foreach ($this->tagsOptions as $k => $v) { $tagsOptions[$k] = "{$k} - {$v}"; } $sel = $group->addSelect('', array('id' => 'insert-tags')); $sel->loadOptions(array_merge(array('' => ''), $tagsOptions)); $group->addStatic()->setContent('</div>'); $group->addStatic()->setContent('</div>'); $fileChooser = new Am_Form_Element_Upload('files', array('multiple' => '1'), array('prefix' => 'email')); $form->addElement($fileChooser)->setLabel(___('Attachments')); foreach ($this->searchUi->getHidden() as $k => $v) { $form->addHidden($k)->setValue($v); } $id = 'body-0'; $vars = ""; foreach ($this->tagsOptions as $k => $v) { $vars .= sprintf("[%s, %s],\n", Am_Controller::getJson($v), Am_Controller::getJson($k)); } $vars = trim($vars, "\n\r,"); if ($this->queue_id) { $form->addHidden('queue_id')->setValue($this->queue_id); } $form->addScript('_bodyscript')->setScript(<<<CUT \$(function(){ \$('select#insert-tags').change(function(){ var val = \$(this).val(); if (!val) return; \$("#{$id}").insertAtCaret(val); \$(this).prop("selectedIndex", -1); }); if (CKEDITOR.instances["{$id}"]) { delete CKEDITOR.instances["{$id}"]; } var editor = null; \$("input[name='format']").change(function() { if (window.configDisable_rte) return; if (!this.checked) return; if (this.value == 'html') { if (!editor) { editor = initCkeditor("{$id}", { placeholder_items: [ {$vars} ],entities_greek: false}); } \$('select#insert-tags').hide(); } else { if (editor) { editor.destroy(); editor = null; } \$('select#insert-tags').show(); } }).change(); }); CUT ); $this->getDi()->hook->call(Am_Event::MAIL_SIMPLE_INIT_FORM, array('form' => $form)); $buttons = $form->addGroup('buttons'); $buttons->addSubmit('send', array('value' => ___('Preview'))); return $form; }
function createForm() { $form = new Am_Form_Admin(); $form->setAttribute('enctype', 'multipart/form-data'); $form->setAttribute('target', '_top'); $maxFileSize = min(ini_get('post_max_size'), ini_get('upload_max_filesize')); $el = $form->addElement(new Am_Form_Element_Upload('path', array(), array('prefix' => 'video')))->setLabel(___("Video File\n(max upload size %s)", $maxFileSize))->setId('form-path'); $jsOptions = <<<CUT { onFileAdd : function (info) { var txt = \$(this).closest("form").find("input[name='title']"); if (txt.data('changed-value')) return; txt.val(info.name); } } CUT; $el->setJsOptions($jsOptions); $form->addScript()->setScript(<<<CUT \$(function(){ \$("input[name='title']").change(function(){ \$(this).data('changed-value', true); }); }); CUT ); $el->addRule('required'); $form->addText('title', array('size' => 50))->setLabel(___('Title'))->addRule('required', 'This field is required'); $form->addText('desc', array('size' => 50))->setLabel(___('Description'))->addRule('required', 'This field is required'); $form->addAdvCheckbox('hide')->setLabel(___("Hide\n" . "do not display this item link in members area")); $form->addElement(new Am_Form_Element_ResourceAccess())->setName('_access')->setLabel(___('Access Permissions')); return $form; }
protected function createForm() { $form = new Am_Form_Admin('EmailTemplate'); $form->addElement(new Am_Form_Element_Html('info'))->setLabel(___('Template'))->setHtml(sprintf('<div><strong>%s</strong><br /><small>%s</small></div>', $this->escape($this->getParam('name')), $this->escape($this->getParam('label')))); $form->addElement('hidden', 'name'); $langOptions = $this->getLanguageOptions($this->getDi()->config->get('lang.enabled', array($this->getDi()->config->get('lang.default', 'en')))); /* @var $lang HTML_QuickForm2_Element */ $lang = $form->addElement('select', 'lang')->setId('lang')->setLabel(___('Language'))->loadOptions($langOptions); if (count($langOptions) == 1) { $lang->toggleFrozen(true); } $lang->addRule('required'); if ($options = $this->getDi()->emailTemplateLayoutTable->getOptions()) { $form->addSelect('email_template_layout_id')->setLabel(___('Layout'))->loadOptions(array('' => ___('No Layout')) + $options); } $tt = Am_Mail_TemplateTypes::getInstance()->find($this->getParam('name')); if ($tt && !empty($tt['isAdmin'])) { $op = array('-1' => Am_Controller::escape(sprintf('%s <%s>', Am_Di::getInstance()->config->get('site_title') . ' Admin', Am_Di::getInstance()->config->get('admin_email')))); foreach (Am_Di::getInstance()->adminTable->findBy() as $admin) { $op[$admin->pk()] = Am_Controller::escape(sprintf('%s <%s>', $admin->getName(), $admin->email)); } $form->addMagicSelect('_admins', array('value' => 'default'))->setLabel(___('Admin Recipients'))->loadOptions($op)->addRule('required'); } else { $form->addText('bcc', array('class' => 'el-wide', 'placeholder' => ___('Email Addresses Separated by Comma')))->setLabel(___("BCC\n" . "blind carbon copy allows the sender of a message to conceal the person entered in the Bcc field from the other recipients"))->addRule('callback', ___('Please enter valid e-mail addresses'), array('Am_Validate', 'emails')); } $form->addScript()->setScript(<<<CUT \$("#checkbox-recipient-other").change(function(){ \$("#row-input-recipient-emails").toggle(this.checked); }).change(); CUT ); $body = $form->addElement(new Am_Form_Element_MailEditor($this->getParam('name'))); $form->addElement('hidden', 'label')->setValue($this->getParam('label')); return $form; }
function run() { $form = new Am_Form_Admin('form-grid-merge'); $form->setAttribute('name', 'merge'); $user = $this->grid->getRecord(); $login = $form->addText('login'); $login->setId('login')->setLabel(___("Username of Source User\nmove information from")); $login->addRule('callback', ___('Can not find user with such username'), array($this, 'checkUser')); $login->addRule('callback', ___('You can not merge user with itself'), array($this, 'checkIdenticalUser')); $target = $form->addStatic()->setContent(sprintf('<div>%s</div>', Am_Controller::escape($user->login))); $target->setLabel(___("Target User\nmove information to")); $script = <<<CUT \$("input#login").autocomplete({ minLength: 2, source: window.rootUrl + "/admin-users/autocomplete" }); CUT; $form->addStatic('', array('class' => 'no-label'))->setContent('<div class="info"><strong>' . ___("WARNING! Once [Merge] button clicked, all invoices, payments, logs\n" . "and other information regarding 'Source User' will be moved\n" . "to the 'Target User' account. 'Source User' account will be deleted.\n" . "There is no way to undo this operation!") . '</strong></div>'); $form->addScript('script')->setScript($script); foreach ($this->grid->getVariablesList() as $k) { $form->addHidden($this->grid->getId() . '_' . $k)->setValue($this->grid->getRequest()->get($k, "")); } $form->addSaveButton(___("Merge")); $form->setDataSources(array($this->grid->getCompleteRequest())); if ($form->isSubmitted() && $form->validate()) { $values = $form->getValue(); $this->merge($this->grid->getRecord(), Am_Di::getInstance()->userTable->findFirstByLogin($values['login'])); $this->grid->redirectBack(); } else { echo $this->renderTitle(); echo $form; } }
function changePaysysAction() { $form = new Am_Form_Admin(); $form->setDataSources(array($this->_request)); $form->addStatic()->setContent(___('If you are moving from one payment processor, you can use this page to switch existing subscription from one payment processor to another. It is possible only if full credit card info is stored on aMember side.')); $ccPlugins = $echeckPlugins = array(); foreach ($this->getModule()->getPlugins() as $ps) { if ($ps instanceof Am_Paysystem_CreditCard) { $ccPlugins[$ps->getId()] = $ps->getTitle(); } elseif ($ps instanceof Am_Paysystem_Echeck) { $echeckPlugins[$ps->getId()] = $ps->getTitle(); } } if (count($ccPlugins) < 2) { $ccPlugins = array(); } if (count($echeckPlugins) < 2) { $echeckPlugins = array(); } $options = array('' => '-- ' . ___('Please select') . ' --') + ($ccPlugins ? array(___('Credit Card Plugins') => $ccPlugins) : array()) + ($echeckPlugins ? array(___('Echeck Plugins') => $echeckPlugins) : array()); $from = $form->addSelect('from', array('id' => 'paysys_from'))->setLabel('Move Active Invoices From')->loadOptions($options); $from->addRule('required'); $to = $form->addSelect('to', array('id' => 'paysys_to'))->setLabel('Move To')->loadOptions($options); $to->addRule('required'); $to->addRule('neq', ___('Values must not be equal'), $from); $form->addScript()->setScript(<<<CUT jQuery(function(\$){ \$("#paysys_from").on('change', function(){ \$("#paysys_to").find('option').removeAttr("disabled"); \$("#paysys_to").removeAttr("disabled","disabled"); val_from = \$(this).val(); if (!val_from){ \$("#paysys_to").val(''); \$("#paysys_to").attr("disabled","disabled"); return; } val_to = \$("#paysys_to").val(); if(val_from == val_to) \$("#paysys_to").val(''); obj_to = \$("#paysys_to").find('option[value="'+\$(this).val()+'"]'); obj_to.attr("disabled","disabled"); \$("#paysys_to").find('optgroup[label!="'+obj_to.parent().attr('label')+'"]').find('option').attr("disabled","disabled"); }).change(); }); CUT ); $form->addSaveButton(); if ($form->isSubmitted() && $form->validate()) { $vars = $form->getValue(); $updated = $this->getDi()->db->query("UPDATE ?_invoice SET paysys_id=? WHERE paysys_id=? AND status IN (?a)", $vars['to'], $vars['from'], array(Invoice::RECURRING_ACTIVE)); $this->view->content = "{$updated} rows changed. New rebills for these invoices will be handled with [{$vars['to']}]"; } else { $this->view->content = (string) $form; } $this->view->title = ___("Change Paysystem"); $this->view->display('admin/layout.phtml'); }
public function createConfigForm(Am_Grid_Editable $grid) { $form = new Am_Form_Admin(); $record = $grid->getRecord($grid->getCurrentAction()); if (empty($record->type)) { $record->type = null; } $globalOptions = AffCommissionRule::getTypes(); foreach (Am_Di::getInstance()->db->selectCol("SELECT DISTINCT `type` FROM ?_aff_commission_rule") as $type) { if (AffCommissionRule::isGlobalType($type) && $type != $record->type) { unset($globalOptions[$type]); } } $cb = $form->addSelect('type')->setLabel('Type')->loadOptions($globalOptions); if ($record->isGlobal()) { $cb->toggleFrozen(true); } $form->addScript()->setScript(<<<CUT \$(function(){ \$("select#type-0").change(function(){ var val = \$(this).val(); \$("fieldset#multiplier").toggle(val == 'multi'); \$("fieldset#commission").toggle(val != 'multi'); var checked = val.match(/^global-/); \$("#conditions").toggle(!checked); \$("#sort_order-0").closest(".row").toggle(!checked); \$("#comment-0").closest(".row").toggle(!checked); }).change(); \$("#condition-select").change(function(){ var val = \$(this).val(); \$(this.options[this.selectedIndex]).prop("disabled", true); this.selectedIndex = 0; \$('#'+val).show(); }); \$("#conditions .row").not("#row-condition-select").each(function(){ if (!\$(":input:filled", this).not(".magicselect").length && !\$(".magicselect-item", this).length) \$(this).hide(); else \$("#condition-select option[value='"+this.id+"']").prop("disabled", true); \$(this).find(".element-title").append(" <a href='javascript:' class='hide-row'>X</a> "); }); \$("a.hide-row").live('click',function(){ var row = \$(this).closest(".row"); row.find("a.hide-row").remove(); var id = row.hide().attr("id"); \$("#condition-select option[value='"+id+"']").prop("disabled", false); }); }); CUT ); $form->addText('comment', array('size' => 40))->setLabel('Rule title - for your own reference')->addRule('required', 'This field is required'); $form->addInteger('sort_order')->setLabel('Sort order - rules with lesser values executed first'); if (!$record->isGlobal()) { $set = $form->addFieldset('', array('id' => 'conditions'))->setLabel('Conditions'); $set->addSelect('', array('id' => 'condition-select'))->setLabel('Add Condition')->loadOptions(array('' => 'Select Condition...', 'row-product_id' => 'By Product', 'row-product_category_id' => 'By Product Category', 'row-aff_group_id' => 'By Affiliate Group Id', 'row-aff_sales_count' => 'By Affiliate Sales Count', 'row-aff_sales_amount' => 'By Affiliate Sales Amount')); $set->addMagicSelect('_conditions[product_id]', array('id' => 'product_id'))->setLabel(array('This rule is for particular products', 'if none specified, rule works for all products'))->loadOptions(Am_Di::getInstance()->productTable->getOptions()); $el = $set->addMagicSelect('_conditions[product_category_id]', array('id' => 'product_category_id'))->setLabel(array('This rule is for particular product categories', 'if none specified, rule works for all product categories')); $el->loadOptions(Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions()); $el = $set->addMagicSelect('_conditions[aff_group_id]', array('id' => 'aff_group_id'))->setLabel(array('This rule is for particular affiliate groups', 'you can add user groups and assign it to customers in User editing form')); $el->loadOptions(Am_Di::getInstance()->userGroupTable->getSelectOptions()); $gr = $set->addGroup('_conditions[aff_sales_count]', array('id' => 'aff_sales_count'))->setLabel(array('Affiliate sales count', 'trigger this commission if affiliate made more than ... sales within ... days before the current date' . PHP_EOL . '(recurring: affiliate sales count will be recalculated on each rebill)')); $gr->addStatic()->setContent('use only if affiliate made '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' commissions within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); $gr = $set->addGroup('_conditions[aff_sales_amount]', array('id' => 'aff_sales_amount'))->setLabel(array('Affiliate sales amount', 'trigger this commission if affiliate made more than ... sales within ... days before the current date' . PHP_EOL . '(recurring: affiliate sales count will be recalculated on each rebill)')); $gr->addStatic()->setContent('use only if affiliate made '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' ' . Am_Currency::getDefault() . ' in commissions within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); } $set = $form->addFieldset('', array('id' => 'commission'))->setLabel('Commission'); if ($record->type != AffCommissionRule::TYPE_GLOBAL_2) { $set->addElement(new Am_Form_Element_AffCommissionSize(null, null, 'first_payment'))->setLabel(___("Commission for First Payment\ncalculated for first payment in each invoice")); $set->addElement(new Am_Form_Element_AffCommissionSize(null, null, 'recurring'))->setLabel(___("Commission for Rebills")); $set->addText('free_signup_c')->setLabel(___("Commission for Free Signup\ncalculated for first customer invoice only")); //->addRule('gte', 'Value must be a valid number > 0, or empty (no text)', 0); } else { $set->addText('first_payment_c')->setLabel(___("Second Level Commission\n% of commission received by referred affiliate")); } if (!$record->isGlobal()) { $set = $form->addFieldset('', array('id' => 'multiplier'))->setLabel('Multipier'); $set->addText('multi', array('size' => 5, 'placeholder' => '1.0'))->setLabel(array(___("Multiply commission calculated by the following rules\n to number specified in this field. To keep commission untouched, enter 1 or delete this rule"))); //->addRule('gt', 'Values must be greater than 0.0', 0.0); } return $form; }