コード例 #1
0
ファイル: slavesubs.php プロジェクト: ZoiaoDePeixe/akeebasubs
    /**
     * Renders custom fields in the form, allowing the subscriber to enter the
     * dependent users
     *
     * @param  array  $cache
     *
     * @return  array  The custom fields definitions
     */
    public function onSubscriptionFormRenderPerSubFields($cache)
    {
        $fields = array();
        // Make sure we have a level
        if (!array_key_exists('subscriptionlevel', $cache)) {
            return $fields;
        }
        // Make sure this leve supports slave subscriptions
        $level = $cache['subscriptionlevel'];
        if (!array_key_exists($level, $this->maxSlaves)) {
            return $fields;
        }
        $maxSlaves = $this->maxSlaves[$level];
        if ($maxSlaves <= 0) {
            return $fields;
        }
        JLoader::import('joomla.user.helper');
        $javascript_fetch = '';
        $javascript_validate = '';
        if (!isset($cache['useredit']) || !$cache['useredit']) {
            $useredit = false;
        } else {
            $useredit = $cache['useredit'];
        }
        for ($i = 0; $i < $maxSlaves; $i++) {
            if (array_key_exists('slaveusers', $cache['subcustom'])) {
                $allSlaves = $cache['subcustom']['slaveusers'];
            } else {
                $allSlaves = array();
            }
            if (array_key_exists($i, $allSlaves)) {
                $current = $allSlaves[$i];
            } else {
                $current = '';
            }
            $html = '<input type="text" class="slaves" name="subcustom[slaveusers][' . $i . ']" id="slaveuser' . $i . '" value="' . htmlentities($current) . '" />';
            $userExists = false;
            if (!empty($current)) {
                $userExists = JUserHelper::getUserId($current) > 0;
            }
            // Setup the field
            $field = array('id' => 'slaveuser' . $i, 'label' => JText::sprintf('PLG_AKEEBASUBS_SLAVESUBS_ADDONUSER_LBL', $i + 1), 'elementHTML' => $html, 'invalidLabel' => JText::_('PLG_AKEEBASUBS_SLAVESUBS_INVALID_LBL'), 'isValid' => empty($current) || $userExists, 'validationClass' => 'slavesubsValidation');
            // Add the field to the return output
            $fields[] = $field;
            // Add Javascript
            $javascript_fetch .= <<<ENDJS
result.slaveusers[{$i}] = \$('#slaveuser{$i}').val();

ENDJS;
            $javascript_validate .= <<<JS

\$('#slaveuser{$i}').parents('div.control-group').removeClass('error has-error success has-success');
if(!response.subcustom_validation.slaveuser{$i}) {
\t\$('#slaveuser{$i}').parents('div.control-group').addClass('error has-error');
\t\$('#slaveuser{$i}_invalid').css('display','inline-block');
\tthisIsValid = false;
} else {
\t\$('#slaveuser{$i}').parents('div.control-group').removeClass('error has-error');
\t\$('#slaveuser{$i}_invalid').css('display','none');
\tthisIsValid = true;
}

JS;
        }
        if (!$useredit) {
            $javascript = <<<JS

;// This comment is intentionally put here to prevent badly written plugins from causing a Javascript error
// due to missing trailing semicolon and/or newline in their code.
(function(\$) {
\t\$(document).ready(function(){
\t\taddToSubValidationFetchQueue(plg_akeebasubs_slavesubs_fetch);
\t\taddToSubValidationQueue(plg_akeebasubs_slavesubs_validate);
\t});
})(akeeba.jQuery);

function plg_akeebasubs_slavesubs_fetch()
{
\tvar result = {
\t\tslaveusers: {}
\t};

\t(function(\$) {
{$javascript_fetch}
\t})(akeeba.jQuery);

\treturn result;
}

function plg_akeebasubs_slavesubs_validate(response)
{
\tvar thisIsValid = true;
\t(function(\$) {
{$javascript_validate}

\t})(akeeba.jQuery);

\treturn thisIsValid;
}

JS;
            $document = JFactory::getDocument();
            $document->addScriptDeclaration($javascript);
        } else {
            require_once JPATH_ROOT . '/components/com_akeebasubs/helpers/js.php';
            AkeebasubsHelperJs::addSelector('input.slaves');
        }
        return $fields;
    }
コード例 #2
0
ファイル: default.php プロジェクト: ZoiaoDePeixe/akeebasubs
				<?php 
                }
                ?>
			</div>
		</div>

	<?php 
            }
        }
    }
}
$subfieldsHTML = trim(@ob_get_clean());
if (!empty($subfieldsHTML)) {
    // Do I have to inject any plugin validators?
    require_once JPATH_ROOT . '/components/com_akeebasubs/helpers/js.php';
    AkeebasubsHelperJs::deployValidator();
    ?>
	<fieldset>
		<legend><?php 
    echo JText::_('COM_AKEEBASUBS_LEVEL_PERSUBFIELDS');
    ?>
</legend>
		<form class="form form-horizontal" method="post" action="<?php 
    echo JRoute::_('index.php?option=com_akeebasubs&view=subscriptions&task=save', false);
    ?>
">
		<?php 
    echo $subfieldsHTML;
    ?>
			<button type="submit" class="btn btn-primary pull-right">
				<?php