Exemple #1
0
 public function insertBrick(HTML_QuickForm2_Container $form)
 {
     if (!$this->getConfig('questions')) {
         return;
     }
     $questions = array();
     foreach (explode(PHP_EOL, $this->getConfig('questions')) as $line) {
         $line = explode('|', $line);
         $questions[] = array_shift($line);
     }
     $q_id = array_rand($questions);
     $question = $form->addText('question', 'question')->setLabel(array($questions[$q_id], $this->___('Please answer above question')));
     $question->addRule('callback', $this->___('Your answer is wrong'), array($this, 'validate'));
     $form->addHidden('q_id')->setValue($q_id)->toggleFrozen(true);
     //setValue does not work right second time
     $_POST['q_id_sent'] = @$_POST['q_id'];
     $_POST['q_id'] = $q_id;
 }
Exemple #2
0
    public function insertBrick(HTML_QuickForm2_Container $form)
    {
        $paysystems = $this->getPaysystems();
        if (count($paysystems) == 1 && $this->getConfig('hide_if_one')) {
            reset($paysystems);
            $form->addHidden('paysys_id')->setValue(current($paysystems)->getId())->toggleFrozen(true);
            return;
        }
        $psOptions = $psHide = array();
        foreach ($paysystems as $ps) {
            $psOptions[$ps->getId()] = $this->renderPaysys($ps);
            $psHide[$ps->getId()] = Am_Di::getInstance()->plugins_payment->loadGet($ps->getId())->hideBricks();
        }
        $psHide = Am_Controller::getJson($psHide);
        if (count($paysystems) != 1) {
            $attrs = array('id' => 'paysys_id');
            $el0 = $el = $form->addAdvRadio('paysys_id', array('id' => 'paysys_id'), array('intrinsic_validation' => false));
            $first = 0;
            foreach ($psOptions as $k => $v) {
                $attrs = array();
                if (!$first++ && Am_Di::getInstance()->request->isGet()) {
                    $attrs['checked'] = 'checked';
                }
                $el->addOption($v, $k, $attrs);
            }
        } else {
            /** @todo display html here */
            reset($psOptions);
            $el = $form->addStatic('_paysys_id', array('id' => 'paysys_id'))->setContent(current($psOptions));
            $el->toggleFrozen(true);
            $el0 = $form->addHidden('paysys_id')->setValue(key($psOptions));
        }
        $el0->addRule('required', $this->___('Please choose a payment system'), null, HTML_QuickForm2_Rule::SERVER);
        $el0->addFilter('filterId');
        $el->setLabel($this->___('Payment System'));
        $form->addScript()->setScript(<<<CUT
jQuery(document).ready(function(\$) {
    /// hide payment system selection if:
    //   - there are only free products in the form
    //   - there are selected products, and all of them are free
    \$(":checkbox[name^='product_id'], select[name^='product_id'], :radio[name^='product_id']").change(function(){
        var count_free = 0, count_paid = 0, total_count_free = 0, total_count_paid = 0;
        \$(":checkbox[name^='product_id']:checked, select[name^='product_id'] option:selected, :radio[name^='product_id']:checked").each(function(){
            if (\$(this).data('first_price') || \$(this).data('second_price')) 
                count_paid++; 
            else
                count_free++;
        });
        
        \$(":checkbox[name^='product_id'], select[name^='product_id'] option, :radio[name^='product_id']").each(function(){
            if (\$(this).data('first_price') || \$(this).data('second_price')) 
                total_count_paid++; 
            else
                total_count_free++;
        });
        if ( (count_free && !count_paid) || (!total_count_paid && total_count_free))
        { // hide select
            \$("#row-paysys_id").hide().after("<input type='hidden' name='paysys_id' value='free' class='hidden-paysys_id' />");
        } else { // show select
            \$("#row-paysys_id").show();
            \$(".hidden-paysys_id").remove();
        }
    }).change();
    window.psHiddenBricks = [];
    \$("input[name='paysys_id']").change(function(){
        if (!this.checked) return;
        var val = \$(this).val();
        var hideBricks = {$psHide};
        \$.each(window.psHiddenBricks, function(k,v){ \$('#row-'+v+'-0').show(); });
        window.psHiddenBricks = hideBricks[val];
        if (window.psHiddenBricks)
        {
            \$.each(window.psHiddenBricks, function(k,v){ \$('#row-'+v+'-0').hide(); });
        }
    }).change();
});
CUT
);
    }