Exemple #1
0
 function getIntegrationFormElements(HTML_QuickForm2_Container $container)
 {
     $container->addSelect('blog_id', '', array('options' => $this->getBlogs()))->setLabel(array('Blog where user should be added', 'By default user will be added to main blog with the same permissions'));
     $groups = $this->getParentPlugin()->getManagedUserGroups();
     $options = array();
     foreach ($groups as $g) {
         $options[$g->getId()] = $g->getTitle();
     }
     $container->addSelect('gr', array(), array('options' => $options))->setLabel($this->getTitle() . ' usergroup');
     parent::getIntegrationFormElements($container);
 }
    public function addPayoutInputs(HTML_QuickForm2_Container $fieldSet)
    {
        $el = $fieldSet->addSelect('aff_payout_type')->setLabel(___('Affiliate Payout Type'))->loadOptions(array_merge(array('' => ___('Not Selected'))));
        foreach (Am_Aff_PayoutMethod::getEnabled() as $method) {
            $el->addOption($method->getTitle(), $method->getId());
        }
        $fieldSet->addScript()->setScript('
/**** show only options for selected payout method */
$(function(){
$("#' . $el->getId() . '").change(function()
{
    for (i in this.options)
    {
        var v = this.options[i].value;
        (i == this.selectedIndex) ?
            $(":input[name^=aff_"+v+"_]").parents(".row").show() :
            $(":input[name^=aff_"+v+"_]").parents(".row").hide();
    }
}).change();
});
/**** end of payout method options */
');
        foreach ($this->getDi()->userTable->customFields()->getAll() as $f) {
            if (strpos($f->name, 'aff_') === 0) {
                $f->addToQf2($fieldSet);
            }
        }
    }
Exemple #3
0
    public function insertBrick(HTML_QuickForm2_Container $form)
    {
        $base_name = 'product_id_' . $form->getId();
        $name = self::$bricksAdded ? $base_name . '_' . self::$bricksAdded : $base_name;
        $products = $this->getProductsFiltered();
        if (!$products) {
            if ($this->getConfig('require', self::REQUIRE_DEFAULT) == self::REQUIRE_NEVER) {
                return;
            }
            throw new Am_Exception_QuietError(___("There are no products available for purchase. Please come back later."));
        }
        self::$bricksAdded++;
        if ($this->getConfig('require', self::REQUIRE_DEFAULT) != self::REQUIRE_NEVER) {
            self::$bricksWhichCanBeRequiredAdded++;
        }
        if ($this->getConfig('require', self::REQUIRE_DEFAULT) == self::REQUIRE_ALTERNATE) {
            self::$bricksAlternateAdded++;
        }
        $options = $shortOptions = $attrs = $dataOptions = array();
        if ($this->getConfig('empty-option')) {
            $shortOptions[null] = $this->getConfig('empty-option-text', ___('Please select'));
            $options[null] = '<span class="am-product-title am-product-empty">' . $shortOptions[null] . '</span><span class="am-product-terms"></span><span class="am-product-desc"></span>';
            $attrs[null] = array();
            $dataOptions[null] = array('value' => null, 'label' => $options[null], 'selected' => false, 'variable_qty' => false, 'qty' => 1);
        }
        foreach ($this->getBillingPlans($products) as $plan) {
            $p = $plan->getProduct();
            $pid = $p->product_id . '-' . $plan->plan_id;
            $options[$pid] = $this->renderProduct($p, $plan);
            $shortOptions[$pid] = $this->shortRender($p, $plan);
            $attrs[$pid] = array('data-first_price' => $plan->first_price, 'data-second_price' => $plan->second_price);
            $dataOptions[$pid] = array('label' => $options[$pid], 'value' => $pid, 'variable_qty' => $plan->variable_qty, 'qty' => $plan->qty, 'selected' => false);
        }
        $inputType = $this->getConfig('input-type', 'advradio');
        if (count($options) == 1) {
            if ($this->getConfig('hide_if_one')) {
                $inputType = 'none';
            } elseif ($inputType != 'checkbox') {
                $inputType = 'hidden';
            }
        }
        $oel = null;
        //outer element
        switch ($inputType) {
            case 'none':
                list($pid, $label) = each($options);
                $oel = $el = $form->addHidden($name, $attrs[$pid]);
                $el->setValue($pid);
                $el->toggleFrozen(true);
                break;
            case 'checkbox':
                $data = array();
                foreach ($this->getBillingPlans($products) as $plan) {
                    $p = $plan->getProduct();
                    $data[$p->product_id . '-' . $plan->pk()] = array('data-first_price' => $plan->first_price, 'data-second_price' => $plan->second_price, 'options' => array('value' => $p->product_id . '-' . $plan->pk(), 'label' => $this->renderProduct($p, $plan), 'variable_qty' => $plan->variable_qty, 'qty' => $plan->qty, 'selected' => false));
                }
                if ($this->getConfig('display-popup')) {
                    $oel = $gr = $form->addGroup();
                    $gr->addStatic()->setContent(sprintf('<div id="%s-preview"></div>', $name));
                    $gr->addStatic()->setContent(sprintf('<div><a id="%s" class="local-link" href="javascript:;" data-title="%s">%s</a></div>', $name, $this->___('Membership Type'), $this->___('Add Membership')));
                    $gr->addStatic()->setContent(sprintf('<div id="%s-list" style="height:350px; overflow-y:scroll; display:none">', $name));
                    $el = $gr->addElement(new Am_Form_Element_SignupCheckboxGroup($name, $data, 'checkbox'));
                    $gr->addStatic()->setContent('</div>');
                    $form->addScript()->setScript(<<<CUT
\$(function(){
   \$('#{$name}').click(function(){
        \$('#{$name}-list').amPopup({
            title : \$(this).data('title'),
            width : 450
        });
        return false;
   })
   \$('#{$name}-list input[type=checkbox]').change(function(){
        \$('#{$name}-preview').empty();
        \$('#{$name}-list input[name^=product][type=checkbox]:checked').each(function(){
            \$('#{$name}-preview').
                append(
                    \$('<div style="margin-bottom:0.2em" class="am-selected-product-row"></div>').
                        append('[<a href="javascript:;" class="local-link" onclick="\$(\\'#{$name}-list input[type=checkbox][value=' + \$(this).val() + ']\\').prop(\\'checked\\', \\'\\').change(); return false;">X</a>] ').
                        append(\$(this).parent().html().replace(/<input.*>/, ''))
                );
        })
   }).change()
});
CUT
);
                } else {
                    $oel = $el = $form->addElement(new Am_Form_Element_SignupCheckboxGroup($name, $data, 'checkbox'));
                }
                break;
            case 'select':
                $oel = $el = $form->addSelect($name);
                foreach ($shortOptions as $pid => $label) {
                    $el->addOption($label, $pid, empty($attrs[$pid]) ? null : $attrs[$pid]);
                }
                break;
            case 'hidden':
            case 'advradio':
            default:
                $data = array();
                $first = 0;
                foreach ($options as $pid => $label) {
                    $data[$pid] = $attrs[$pid];
                    $data[$pid]['options'] = $dataOptions[$pid];
                    if (!$first++ && Am_Di::getInstance()->request->isGet()) {
                        // pre-check first option
                        $data[$pid]['options']['selected'] = true;
                    }
                }
                $oel = $el = $form->addElement(new Am_Form_Element_SignupCheckboxGroup($name, $data, $inputType == 'advradio' ? 'radio' : $inputType));
                break;
        }
        $oel->setLabel($this->___('Membership Type'));
        if ($this->getConfig('no_label')) {
            $oel->setAttribute('class', 'no-label');
        }
        switch ($this->getConfig('require', self::REQUIRE_DEFAULT)) {
            case self::REQUIRE_DEFAULT:
                if (self::$bricksWhichCanBeRequiredAdded == 1) {
                    $el->addRule('required', $this->___('Please choose a membership type'));
                }
                break;
            case self::REQUIRE_ALWAYS:
                $el->addRule('required', $this->___('Please choose a membership type'));
                break;
            case self::REQUIRE_NEVER:
                break;
            case self::REQUIRE_ALTERNATE:
                if (self::$bricksAlternateAdded == 1) {
                    $f = $form;
                    while ($container = $f->getContainer()) {
                        $f = $container;
                    }
                    $f->addRule('callback2', $this->___('Please choose a membership type'), array($this, 'formValidate'));
                }
                break;
            default:
                throw new Am_Exception_InternalError('Unknown require type [%s] for product brick', $this->getConfig('require', self::REQUIRE_DEFAULT));
        }
        if (self::$bricksAdded == 1) {
            $script = <<<EOF
jQuery(function(\$){
    \$(":checkbox[name^='product_id'], select[name^='product_id'], :radio[name^='product_id']").change(function(){
        var el = \$(this);
        var show = el.is(":checked") || el.is(":selected");
        el.closest("label").find(".am-product-qty")
            .toggle(show).prop("disabled", !show);
        if (this.type == 'radio')
        {   // in case of radio elements we must disable not-selected
            el.closest("form")
                .find("label:has(input[name='"+this.name+"']:not(:checked)) .am-product-qty")
                .hide().prop("disabled", true);
        }
    });
});
EOF;
            $form->addScript()->setScript($script);
        }
    }
Exemple #4
0
 public function getIntegrationFormElements(HTML_QuickForm2_Container $container)
 {
     $groups = $this->getManagedUserGroups();
     $options = array();
     foreach ($groups as $g) {
         $options[$g->getId()] = $g->getTitle();
     }
     $container->addSelect('gr', array(), array('options' => $options))->setLabel($this->getTitle() . ' usergroup');
 }
Exemple #5
0
 public function insertBrick(\HTML_QuickForm2_Container $form)
 {
     $user = Am_Di::getInstance()->auth->getUser();
     $options = array_filter(array($user->login, $user->name_f, $user->name_l, $user->data()->get('_wordpress_nickname'), $user->name_f . ' ' . $user->name_l, $user->name_l . ' ' . $user->name_f));
     $form->addSelect('_wordpress_display')->setLabel($this->___('Display name publicly as'))->loadOptions(array_combine($options, $options));
 }
Exemple #6
0
    public function addPayoutInputs(HTML_QuickForm2_Container $fieldSet)
    {
        $el = $fieldSet->addSelect('aff_payout_type')->setLabel(___('Affiliate Payout Type'))->loadOptions(array_merge(array('' => ___('Not Selected'))));
        foreach (Am_Aff_PayoutMethod::getEnabled() as $method) {
            $el->addOption($method->getTitle(), $method->getId());
        }
        $fieldSet->addScript()->setScript('
/**** show only options for selected payout method */
$(function(){
$("#' . $el->getId() . '").change(function()
{
    var selected = $("#' . $el->getId() . '").val();
    $("option", $(this)).each(function(){
        var option = $(this).val();
        if(option == selected){
            $("input[name^=aff_"+option+"_]").closest(".row").show();
        }else{
            $("input[name^=aff_"+option+"_]").closest(".row").hide();
        }
    });
}).change();
});
/**** end of payout method options */
');
        foreach ($this->getDi()->userTable->customFields()->getAll() as $f) {
            if (strpos($f->name, 'aff_') === 0) {
                $f->addToQf2($fieldSet);
            }
        }
    }
Exemple #7
0
 public function insertBrick(HTML_QuickForm2_Container $form)
 {
     $name = self::$bricksAdded ? 'product_id_' . self::$bricksAdded : 'product_id';
     self::$bricksAdded++;
     $products = $this->getProductsFiltered();
     if (!$products) {
         throw new Am_Exception_InputError(___("There are no products available for purchase. Please come back later."));
     }
     $options = $shortOptions = array();
     foreach ($products as $p) {
         foreach ($p->getBillingPlans(true) as $plan) {
             $options[$p->product_id . '-' . $plan->plan_id] = $this->renderProduct($p, $plan);
             $shortOptions[$p->product_id . '-' . $plan->plan_id] = $this->shortRender($p, $plan);
             $attrs[$p->product_id . '-' . $plan->plan_id] = array('data-first_price' => $plan->first_price, 'data-second_price' => $plan->second_price);
         }
     }
     if (count($options) == 1) {
         $el = $form->addAdvRadio($name);
         list($pid, $label) = each($options);
         $el->addOption($label, $pid, $attrs[$pid]);
         $el->setValue($pid)->toggleFrozen(true);
     } else {
         switch ($this->getConfig('input-type')) {
             case 'checkbox':
                 $el = $form->addGroup($name);
                 foreach ($products as $p) {
                     // @todo add select for billing plans
                     // right now default billing plan wil be used
                     $el->addCheckbox($p->product_id, array('value' => $p->product_id, 'data-first_price' => $p->getBillingPlan()->first_price, 'data-second_price' => $p->getBillingPlan()->second_price))->setContent($this->renderProduct($p, $p->getBillingPlan()));
                 }
                 break;
             case 'select':
                 $el = $form->addSelect($name);
                 foreach ($shortOptions as $pid => $label) {
                     $el->addOption($label, $pid, $attrs[$pid]);
                 }
                 break;
             case 'advradio':
             default:
                 $el = $form->addAdvRadio($name);
                 $first = 0;
                 foreach ($options as $pid => $label) {
                     if (!$first++ && Am_Di::getInstance()->request->isGet()) {
                         // pre-check first option
                         $attrs[$pid]['checked'] = 'checked';
                     }
                     $el->addOption($label, $pid, $attrs[$pid]);
                 }
                 break;
         }
     }
     // only the first brick is requried
     if (self::$bricksAdded <= 1) {
         $el->addRule('required', $this->___('Please choose a membership type'));
     }
     $el->setLabel($this->___('Membership Type'));
 }