function wikiplugin_payment( $data, $params )
{
	global $smarty;

	require_once 'lib/smarty_tiki/function.payment.php';
	return '^~np~' . smarty_function_payment($params, $smarty) . '~/np~^';
}
예제 #2
0
function wikiplugin_trade($data, $params, $offset)
{
    global $smarty, $userlib, $prefs, $user, $headerlib;
    global $cclitelib;
    require_once 'lib/payment/cclitelib.php';
    global $paymentlib;
    require_once 'lib/payment/paymentlib.php';
    static $iPluginTrade = 0;
    $default = array('inputtitle' => '', 'wanted' => 'n', 'action' => tra('Continue'), 'registry' => '', 'currency' => '');
    $params = array_merge($default, $params);
    if (empty($params['registry'])) {
        $params['registry'] = $cclitelib->get_registry();
    }
    if (empty($params['currency'])) {
        $params['currency'] = $cclitelib->get_currency($params['registry']);
    }
    $iPluginTrade++;
    $smarty->assign('iPluginTrade', $iPluginTrade);
    $params['price'] = floatval(preg_replace('/^\\D*([\\d\\.]*)/', '$1', $params['price']));
    $smarty->assign('wp_trade_other_user_set', empty($params['other_user']) ? 'n' : 'y');
    $smarty->assign('wp_trade_action', $params['action']);
    //	$smarty->assign( 'wp_trade_quantity_edit', $params['quantity'] <= 0 ? 'y' : 'n');	// TODO
    //	$smarty->assign( 'wp_trade_quantity', abs($params['quantity']));
    if (isset($_POST['wp_trade_offset']) && $_POST['wp_trade_offset'] == $offset && !empty($_POST['wp_trade_other_user'])) {
        $params['other_user'] = $_POST['wp_trade_other_user'];
    }
    $params['other_user'] = trim($params['other_user'], '|');
    $other_users = explode('|', $params['other_user']);
    $other_users = array_map('trim', $other_users);
    $other_users = array_filter($other_users, array($userlib, 'user_exists'));
    $other_users = array_filter($other_users);
    if (!empty($other_users)) {
        $info = $userlib->get_user_info($other_users[0]);
    } else {
        $info = array();
    }
    $smarty->assign('wp_trade_offset', $offset);
    $smarty->assign('wp_trade_price', $params['price']);
    $smarty->assign('wp_trade_other_user', $info);
    $smarty->assign('wp_trade_currentuser', $params['currentuser']);
    if ($params['wanted'] == 'n') {
        if (empty($params['inputtitle'])) {
            $params['inputtitle'] = 'Payment of %0 %1 from user %2 to %3';
        }
    } else {
        if (empty($params['inputtitle'])) {
            $params['inputtitle'] = 'Request payment of %0 %1 to user %2 from %3';
        }
    }
    $desc = tr($params['inputtitle'], number_format($params['price'], 2), $params['currency'], $user, $params['other_user']);
    if (!empty($info) && $info['waiting'] == null) {
        // user clicked "continue" (probably)
        if (isset($_POST['wp_trade_offset']) && $_POST['wp_trade_offset'] == $offset) {
            $id = $paymentlib->request_payment($desc, $params['price'], $prefs['payment_default_delay'], null, $params['currency']);
            if (empty($user)) {
                return '{REMARKSBOX(type=warning, title=Plugin Trade Error)}' . tra('Please log in.') . '{REMARKSBOX}';
            } else {
                $params['main_user'] = $user;
            }
            $params['invoice'] = $id;
            $paymentlib->register_behavior($id, 'complete', 'perform_trade', array($params));
            //$smarty->assign( 'wp_trade_title', $desc );
            require_once 'lib/smarty_tiki/function.payment.php';
            return '^~np~' . smarty_function_payment(array('id' => $id), $smarty) . '~/np~^';
        } else {
            if ($prefs['payment_system'] == 'cclite' && isset($_POST['cclite_payment_amount']) && isset($_POST['invoice'])) {
                require_once 'lib/smarty_tiki/function.payment.php';
                $params['id'] = $_POST['invoice'];
                return '^~np~' . smarty_function_payment($params, $smarty) . '~/np~^';
            }
        }
    } else {
        if ($info['waiting'] != null) {
            return '{REMARKSBOX(type=warning, title=Plugin Trade Error)}' . tra('The user ') . '<em>' . $info['login'] . '</em>' . tra(' needs to validate their account.') . '{REMARKSBOX}';
        }
    }
    $smarty->assign('wp_trade_title', $desc);
    return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_trade.tpl') . '~/np~';
}
예제 #3
0
function wikiplugin_memberpayment($data, $params, $offset)
{
    global $prefs, $user;
    static $iPluginMemberpayment = 0;
    $userlib = TikiLib::lib('user');
    $smarty = TikiLib::lib('smarty');
    $iPluginMemberpayment++;
    $smarty->assign('iPluginMemberpayment', $iPluginMemberpayment);
    $smarty->assign('returnurl', !empty($params['returnurl']) ? $params['returnurl'] : '');
    $params['price'] = floatval($params['price']);
    $default = array('currentuser' => 'n', 'inputtitle' => '', 'inputtitleonly' => 'n', 'howtitle' => '', 'howtitleonly' => 'n', 'paytitle' => '', 'paytitleonly' => 'n', 'hideperiod' => 'n', 'periodslabel' => 'Number of periods:');
    $params = array_merge($default, $params);
    $smarty->assign('hideperiod', $params['hideperiod']);
    $smarty->assign('periodslabel', $params['periodslabel']);
    //true if continue button has been hit
    $post = isset($_POST['wp_member_offset']);
    $oneuser = false;
    if (($info = $userlib->get_group_info($params['group'])) && ($info['expireAfter'] > 0 || $info['anniversary'] > '')) {
        $attributelib = TikiLib::lib('attribute');
        $paymentlib = TikiLib::lib('payment');
        $tikilib = TikiLib::lib('tiki');
        $smarty->assign('wp_member_offset', $offset);
        $smarty->assign('wp_member_price', $params['price']);
        if ($post) {
            $periods = (int) $_POST['wp_member_periods'];
            $freeperiods = 0;
            if ($periods && !empty($params['freeperiods'])) {
                // give free periods (purchase of at least 1 full real period required)
                $freeperiods = (int) $params['freeperiods'];
                $periods += $freeperiods;
            }
            $smarty->assign('wp_member_postperiods', $periods);
            $oneuser = $params['currentuser'] == 'y' ? array($user) : explode('|', $_POST['wp_member_users']);
            $oneuser = count($oneuser) == 1 ? true : false;
            if ($oneuser) {
                $extendinfo = $userlib->get_extend_until_info($user, $params['group'], $periods);
                $paidterm = $extendinfo['interval'];
            }
        }
        if (!empty($info['expireAfter'])) {
            $smarty->assign('wp_member_expireafter', true);
            if ($info['expireAfter'] == 1) {
                $days = tra('day');
            } elseif ($info['expireAfter'] > 1) {
                $days = tra('days');
            }
            $info['termString'] = $info['expireAfter'] . ' ' . $days;
            //set up subscription parameters for paypal - interval (D, M or Y) and number of intervals are required
            if ($prefs['payment_system'] == 'paypal' && $oneuser) {
                if ($paidterm->y > 2 || $paidterm->y <= 2 && $paidterm->y > 0 && $paidterm->m == 0) {
                    $ppinterval = 'Y';
                    $ppunits = $paidterm->y;
                    //maximum number of days that can be specified in paypal is 90 for subscriptions
                } elseif ($paidterm->days > 90) {
                    $ppinterval = 'M';
                    $ppunits = $paidterm->m + $paidterm->y * 12;
                } else {
                    $ppinterval = 'D';
                    $ppunits = $paidterm->days;
                }
                $beg = isset($extendinfo['new']) && $extendinfo['new'] === false ? tra('by') : tra('for');
                $info['descString'] = $beg . ' ' . $info['expireAfter'] * $periods . ' ' . $days;
            }
        }
        $smarty->assign('wp_member_prorated', 0);
        // default
        if ($info['anniversary'] > '') {
            if (strlen($info['anniversary']) == 4) {
                $ann_month = substr($info['anniversary'], 0, 2);
                $ann_day = substr($info['anniversary'], 2, 2);
                $ppinterval = 'Y';
                $fakedate = DateTime::createFromFormat('m-d', $ann_month . '-' . $ann_day);
                $info['termString'] = tr('Annual, commencing %0 %1 each year', tra($fakedate->format('M')), $fakedate->format('j'));
            } elseif (strlen($info['anniversary']) == 2) {
                $ann_month = 0;
                $ann_day = $info['anniversary'];
                $ppinterval = 'M';
                $info['termString'] = tr('Monthly, commencing on day %0 each month', $ann_day);
            }
            if ($oneuser) {
                $info['descString'] = 'to ' . $tikilib->get_short_date($extendinfo['timestamp'], $user);
            }
            $smarty->assign('wp_member_anniversary_month', $ann_month);
            $smarty->assign('wp_member_anniversary_day', $ann_day);
            if ($params['currentuser'] == 'y') {
                $extend_until_info = $userlib->get_extend_until_info($user, $params['group']);
                if (!empty($extend_until_info['ratio_prorated_first_period']) && $extend_until_info['ratio_prorated_first_period'] > 0 && $extend_until_info['ratio_prorated_first_period'] < 1) {
                    $smarty->assign('wp_member_prorated', round($extend_until_info['ratio_prorated_first_period'] * $params['price'], 2));
                }
            }
        }
        $smarty->assign('wp_member_group', $info);
        $smarty->assign('wp_member_currentuser', $params['currentuser']);
        // setup free period display
        if (!empty($params['freeperiods'])) {
            if (isset($extendinfo['ratio_prorated_first_period']) && $extendinfo['ratio_prorated_first_period'] > 0 && $extendinfo['ratio_prorated_first_period'] < 1) {
                $smarty->assign('wp_member_freeperiods', $params['freeperiods'] - 1);
                $smarty->assign('wp_member_freeprorated', 1);
            } else {
                $smarty->assign('wp_member_freeperiods', $params['freeperiods']);
                $smarty->assign('wp_member_freeprorated', 0);
            }
        } else {
            $smarty->assign('wp_member_freeperiods', 0);
            $smarty->assign('wp_member_freeprorated', 0);
        }
        $smarty->assign('wp_member_requestpending', 'n');
        $smarty->assign('wp_member_title', $params['inputtitle']);
        $smarty->assign('wp_member_titleonly', $params['inputtitleonly']);
        $smarty->assign('wp_member_paymentid', 0);
        if (isset($params['currentuser']) && $params['currentuser'] == 'y' && !empty($params['preventdoublerequest']) && $params['preventdoublerequest'] == 'y') {
            $attname = 'tiki.memberextend.' . $info['id'];
            $attributes = $attributelib->get_attributes('user', $user);
            if (isset($attributes[$attname])) {
                $smarty->assign('wp_member_requestpending', 'y');
                $smarty->assign('wp_member_paymentid', $attributes[$attname]);
                if (!empty($params['paytitle'])) {
                    $smarty->assign('wp_member_title', $params['paytitle']);
                    $smarty->assign('wp_member_titleonly', $params['paytitleonly']);
                }
            }
        }
        if (isset($_POST['wp_member_offset']) && $_POST['wp_member_offset'] == $offset && !empty($_POST['wp_member_periods'])) {
            $users = $params['currentuser'] == 'y' ? array($user) : explode('|', $_POST['wp_member_users']);
            $users = array_map('trim', $users);
            $users = array_filter($users, array($userlib, 'user_exists'));
            $users = array_filter($users);
            $smarty->assign('wp_member_users', count($users));
            if (!empty($params['preventdoublerequest']) && $params['preventdoublerequest'] == 'y') {
                foreach ($users as $u) {
                    $attname = 'tiki.memberextend.' . $info['id'];
                    $attributes = $attributelib->get_attributes('user', $u);
                    if (isset($attributes[$attname])) {
                        return '{REMARKSBOX(type=warning, title=Plugin Memberpayment Error)}' . tra('The user ') . $u . tra(' already has a pending extension request payment invoice ') . $attributes[$attname] . '{REMARKSBOX}';
                    }
                }
            }
            if ($prefs['payment_system'] == 'paypal' && $oneuser) {
                $rounded = round($periods);
                if ($ppinterval == 'Y' && $rounded <= 5 || $ppinterval == 'M' && $rounded <= 24 || $ppinterval == 'D' && $rounded <= 90) {
                    $smarty->assign('wp_member_subscribeok', 'y');
                    if (isset($ppunits)) {
                        $smarty->assign('wp_member_periodset', $ppunits);
                    } else {
                        $smarty->assign('wp_member_periodset', round($periods));
                    }
                    if (isset($ppinterval)) {
                        $smarty->assign('wp_member_interval', $ppinterval);
                    }
                    //when parameters don't fit within paypal limits
                } else {
                    $smarty->assign('wp_member_subscribeok', 'n');
                }
            }
            if (count($users) == 1) {
                $mem = isset($extendinfo['new']) && $extendinfo['new'] === false ? 'Extend membership' : 'Membership';
                $term = !empty($info['descString']) ? ' ' . $info['descString'] : '';
                $desc = tr('%0 to %1 %2 for %3', $mem, $params['group'], $term, reset($users));
            } else {
                $perplural = $periods > 1 ? tra('periods') : tra('period');
                $desc = tr('Membership to %0 for %1 users for %2 %3', $params['group'], count($users), $periods, $perplural);
            }
            //calculate cost
            $cost = 0;
            if (!empty($info['expireAfter'])) {
                $cost = round(count($users) * ($periods - $freeperiods) * $params['price'], 2);
            }
            if ($info['anniversary'] > '') {
                foreach ($users as $u) {
                    $extendinfo = $userlib->get_extend_until_info($u, $params['group'], $periods);
                    $extendinfo['freeperiods'] = $freeperiods;
                    if (!empty($extendinfo['ratio_prorated_first_period']) && $extendinfo['ratio_prorated_first_period'] > 0 && $extendinfo['ratio_prorated_first_period'] < 1) {
                        $smarty->assign('wp_member_prorated', round($extendinfo['ratio_prorated_first_period'] * $params['price'], 2));
                    }
                    if ($extendinfo['freeperiods'] > 0 && $extendinfo['ratio_prorated_first_period'] < 1 && $extendinfo['ratio_prorated_first_period'] > 0) {
                        $extendinfo['ratio'] = $extendinfo['ratio'] - $extendinfo['ratio_prorated_first_period'];
                        $extendinfo['freeperiods']--;
                    }
                    $cost += ($extendinfo['ratio'] - $extendinfo['freeperiods']) * $params['price'];
                }
                $cost = round($cost, 2);
            }
            $id = $paymentlib->request_payment($desc, $cost, $prefs['payment_default_delay']);
            $paymentlib->register_behavior($id, 'complete', 'extend_membership', array($users, $params['group'], $periods, $info['id']));
            foreach ($users as $u) {
                $attributelib->set_attribute('user', $u, 'tiki.memberextend.' . $info['id'], $id);
            }
            $paymentlib->register_behavior($id, 'cancel', 'cancel_membership_extension', array($users, $info['id']));
            $smarty->assign('wp_member_title', $params['howtitle']);
            $smarty->assign('wp_member_titleonly', $params['howtitleonly']);
            require_once 'lib/smarty_tiki/function.payment.php';
            return '^~np~' . smarty_function_payment(array('id' => $id), $smarty) . '~/np~^';
        } else {
            if ($prefs['payment_system'] == 'cclite' && isset($_POST['cclite_payment_amount']) && isset($_POST['invoice'])) {
                require_once 'lib/smarty_tiki/function.payment.php';
                return '^~np~' . smarty_function_payment(array('id' => $_POST['invoice']), $smarty) . '~/np~^';
            }
        }
        return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_memberpayment.tpl') . '~/np~';
    } elseif ($info['expireAfter'] == 0 && $params['group'] == $info['groupName']) {
        return '{REMARKSBOX(type=warning, title=Plugin Memberpayment Error)}' . tra('The group ') . '<em>' . $info['groupName'] . '</em>' . tra(' does not have a membership term.') . tra(' Go to ') . '<em>' . tra('Admin > Groups') . '</em>' . tra(' to specify a term for this group by automatically unassigning users after a certain number of days.') . '{REMARKSBOX}';
    } else {
        return '{REMARKSBOX(type=warning, title=Plugin Memberpayment Error)}' . tra('The group ') . '<em>' . $params['group'] . '</em>' . tra(' does not exist') . '{REMARKSBOX}';
    }
}
예제 #4
0
function wikiplugin_datachannel($data, $params)
{
    static $execution = 0;
    global $prefs, $smarty, $headerlib;
    $executionId = 'datachannel-exec-' . ++$execution;
    if (isset($params['price']) && $params['price'] == 0) {
        // Convert things like 0.00 to empty
        unset($params['price']);
    }
    $fields = array();
    $inputfields = array();
    $lines = explode("\n", $data);
    $lines = array_map('trim', $lines);
    $lines = array_filter($lines);
    $js = '';
    if (!isset($params['array_values'])) {
        $params['array_values'] = 'n';
    }
    foreach ($lines as $line) {
        $parts = explode(',', $line, 2);
        $parts = array_map('trim', $parts);
        if (count($parts) == 2) {
            if (strpos($parts[1], 'external') === 0) {
                // e.g. "fieldid,external=fieldname"
                $moreparts = explode('=', $parts[1], 2);
                $moreparts = array_map('trim', $moreparts);
                if (count($moreparts) < 2) {
                    $moreparts[1] = $parts[0];
                    // no fieldname supplied so use same as fieldid
                }
                $fields[$parts[0]] = $moreparts[0];
                if ($params['array_values'] === 'y' && preg_match('/[\\[\\]\\.#\\=]/', $moreparts[1])) {
                    // check for [ ] = or . which would be a jQuery selector
                    // might select multiple inputs
                    $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("' . $moreparts[1] . '").serialize()));';
                } else {
                    // otherwise it's an id
                    $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("#' . $moreparts[1] . '").val()));';
                }
                $inputfields[$parts[0]] = 'external';
            } elseif (strpos($parts[1], 'hidden') === 0) {
                $moreparts = explode('=', $parts[1], 2);
                $moreparts = array_map('trim', $moreparts);
                $fields[$parts[0]] = $moreparts[1];
                $inputfields[$parts[0]] = 'hidden';
            } else {
                $fields[$parts[0]] = $parts[1];
                $inputfields[$parts[0]] = $parts[1];
            }
        }
    }
    $groups = Perms::get()->getGroups();
    $config = Tiki_Profile_ChannelList::fromConfiguration($prefs['profile_channels']);
    if ($config->canExecuteChannels(array($params['channel']), $groups, true)) {
        $smarty->assign('datachannel_execution', $executionId);
        if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['datachannel_execution']) && $_POST['datachannel_execution'] == $executionId && $config->canExecuteChannels(array($params['channel']), $groups)) {
            $input = array_intersect_key(array_map('trim', $_POST), $inputfields);
            $itemIds = array();
            // process possible arrays in post
            if ($params['array_values'] === 'y') {
                foreach ($input as $key => $val) {
                    if (!empty($val)) {
                        parse_str($val, $vals);
                        if (is_array($vals)) {
                            // serialized collection of inputs
                            $arr = array();
                            if ($key == 'itemId') {
                                foreach ($vals as $v) {
                                    // itemId[x,y,z]
                                    if (is_array($v)) {
                                        $arr = array_merge($arr, $v);
                                    }
                                }
                                $itemIds = $arr;
                            } else {
                                foreach ($vals as $v) {
                                    // fieldname[x=>a,y=>b,z=>c]
                                    if (is_array($v)) {
                                        foreach ($v as $k => $kv) {
                                            if (in_array($k, $itemIds)) {
                                                // check if sent in itemIds array
                                                $arr[] = $kv;
                                                // (e.g. from trackerlist checkboxes)
                                            }
                                        }
                                    } else {
                                        $arr = $val;
                                        // not an array, so use the initial string val
                                    }
                                }
                            }
                            $input[$key] = $arr;
                        }
                    }
                }
            }
            $inputs = array();
            if ($params['array_values'] === 'y' && !empty($itemIds)) {
                $cid = count($itemIds);
                for ($i = 0; $i < $cid; $i++) {
                    // reorganise array
                    $arr = array();
                    foreach (array_keys($input) as $k) {
                        if (isset($input[$k]) && is_array($input[$k])) {
                            $arr[$k] = $input[$k][$i];
                        } else {
                            $arr[$k] = $input[$k];
                        }
                    }
                    $inputs[] = $arr;
                }
            } else {
                $inputs[] = $input;
            }
            $static = $params;
            $unsets = wikiplugin_datachannel_info();
            // get defined params
            $unsets = array_keys($unsets['params']);
            foreach ($unsets as $un) {
                // remove defined params leaving user supplied ones
                unset($static[$un]);
            }
            if (!empty($params['price'])) {
                global $paymentlib;
                require_once 'lib/payment/paymentlib.php';
                $desc = empty($params['paymentlabel']) ? tr('Datachannel:', $prefs['site_language']) . ' ' . $params['channel'] : $params['paymentlabel'];
                $posts = array();
                foreach ($input as $key => $post) {
                    $posts[$key] = $post;
                    $desc .= '/' . $post;
                }
                $id = $paymentlib->request_payment($desc, $params['price'], $prefs['payment_default_delay']);
                $paymentlib->register_behavior($id, 'complete', 'execute_datachannel', array($data, $params, $posts, $executionId));
                require_once 'lib/smarty_tiki/function.payment.php';
                return '^~np~' . smarty_function_payment(array('id' => $id), $smarty) . '~/np~^';
            }
            foreach ($inputs as $input) {
                $userInput = array_merge($input, $static);
                Tiki_Profile::useUnicityPrefix(uniqid());
                $profiles = $config->getProfiles(array($params['channel']));
                $profile = reset($profiles);
                $profile->removeSymbols();
                Tiki_Profile::useUnicityPrefix(uniqid());
                $installer = new Tiki_Profile_Installer();
                //TODO: What is the following line for? Future feature to limit capabilities of data channels?
                //$installer->limitGlobalPreferences( array() );
                // jb tiki6: looks like if set to an empty array it would prevent any prefs being set
                // i guess the idea is to be able to restrict the settable prefs to only harmless ones for security
                $installer->setUserData($userInput);
                if (!empty($params['debug']) && $params['debug'] === 'y') {
                    $installer->setDebug();
                }
                $params['emptyCache'] = isset($params['emptyCache']) ? $params['emptyCache'] : 'all';
                $installer->install($profile, $params['emptyCache']);
            }
            if (empty($params['returnURI'])) {
                $params['returnURI'] = $_SERVER['HTTP_REFERER'];
            }
            // default to return to same page
            if (empty($params['debug']) || $params['debug'] != 'y') {
                if (isset($params['quietReturn']) && $params['quietReturn'] == 'y') {
                    return true;
                } else {
                    header('Location: ' . $params['returnURI']);
                }
                die;
            }
            $smarty->assign('datachannel_feedbacks', array_merge($installer->getFeedback(), $profile->getFeedback()));
        }
        $smarty->assign('datachannel_inputfields', $inputfields);
        $smarty->assign('datachannel_fields', $fields);
        $smarty->assign('button_label', !empty($params['buttonLabel']) ? $params['buttonLabel'] : 'Go');
        $smarty->assign('form_class_attr', !empty($params['class']) ? ' class="' . $params['class'] . '"' : '');
        if (!empty($js)) {
            $headerlib->add_js("function datachannel_form_submit{$execution}() {{$js}\nreturn true;\n}");
            $smarty->assign('datachannel_form_onsubmit', ' onsubmit="return datachannel_form_submit' . $execution . '();"');
        } else {
            $smarty->assign('datachannel_form_onsubmit', '');
        }
        return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_datachannel.tpl') . '~/np~';
    }
}
예제 #5
0
function wikiplugin_payment($data, $params)
{
    $smarty = TikiLib::lib('smarty');
    require_once 'lib/smarty_tiki/function.payment.php';
    return '^~np~' . smarty_function_payment($params, $smarty) . '~/np~^';
}
function wikiplugin_memberpayment( $data, $params, $offset )
{
	global $smarty, $userlib, $prefs, $user, $headerlib;
	global $paymentlib; require_once 'lib/payment/paymentlib.php';
	static $iPluginMemberpayment = 0;
	$attributelib = TikiLib::lib('attribute');

	$iPluginMemberpayment++;
	$smarty->assign('iPluginMemberpayment', $iPluginMemberpayment);
	$params['price'] = floatval($params['price']);
	$default = array( 'currentuser'=>'n', 'inputtitle'=>'', 'howtitle' => '');
	$params = array_merge($default, $params);

	if ( ( $info = $userlib->get_group_info($params['group']) ) && ( $info['expireAfter'] > 0 || $info['anniversary'] > '') ) {
		$smarty->assign('wp_member_offset', $offset);
		$smarty->assign('wp_member_price', $params['price']);
		if (($info['expireAfter']/365)*365 == $info['expireAfter'] && $info['expireAfter'] >= 365) {
			$info['expireAfterYear'] = $info['expireAfter']/365;
		}
		$smarty->assign('wp_member_group', $info);
		$smarty->assign('wp_member_currentuser', $params['currentuser']);
		$smarty->assign('wp_member_prorated', 0); // default
		
		if ($info['anniversary'] > '') {
			if (strlen($info['anniversary']) == 4) {
				$ann_month = substr($info['anniversary'], 0, 2);
				$ann_day = substr($info['anniversary'], 2, 2);
			} elseif (strlen($info['anniversary']) == 2) {
				$ann_month = 0;
				$ann_day = $info['anniversary'];
			}
			$smarty->assign('wp_member_anniversary_month', $ann_month);
			$smarty->assign('wp_member_anniversary_day', $ann_day);
			if ($params['currentuser'] == 'y') {
				$extend_until_info = $userlib->get_extend_until_info($user, $params['group']);
				if (!empty($extend_until_info['ratio_prorated_first_period']) && $extend_until_info['ratio_prorated_first_period'] < 1) {
					$smarty->assign('wp_member_prorated', round($extend_until_info['ratio_prorated_first_period'] * $params['price'], 2));
				}	
			}
		}
		
		// setup free period display
		if (!empty($params['freeperiods'])) {
			if (isset($extend_until_info['ratio_prorated_first_period']) && $extend_until_info['ratio_prorated_first_period'] < 1) {
				$smarty->assign('wp_member_freeperiods', $params['freeperiods'] - 1);
				$smarty->assign('wp_member_freeprorated', 1);
			} else {
				$smarty->assign('wp_member_freeperiods', $params['freeperiods']);
				$smarty->assign('wp_member_freeprorated', 0);
			}
		} else {
			$smarty->assign('wp_member_freeperiods', 0);
			$smarty->assign('wp_member_freeprorated', 0);
		}
		
		$smarty->assign('wp_member_requestpending', 'n');
        $smarty->assign('wp_member_paymentid', 0);
		if (isset($params['currentuser']) && $params['currentuser'] == 'y' && !empty($params['preventdoublerequest']) && $params['preventdoublerequest'] == 'y') {
			$attname = 'tiki.memberextend.' . $info['id'];
			$attributes = $attributelib->get_attributes('user', $user);
			if (isset($attributes[$attname])) {
				$smarty->assign('wp_member_requestpending', 'y');
				$smarty->assign('wp_member_paymentid', $attributes[$attname]);
			}
		}
		
		if ( isset($_POST['wp_member_offset']) && $_POST['wp_member_offset'] == $offset && !empty($_POST['wp_member_periods'])) {
			$users = $params['currentuser'] == 'y'? array($user): explode('|', $_POST['wp_member_users']);
			$users = array_map('trim', $users);
			$users = array_filter($users, array( $userlib, 'user_exists' ));
			$users = array_filter($users);

			if (!empty($params['preventdoublerequest']) && $params['preventdoublerequest'] == 'y') {
				foreach ($users as $u) {
					$attname = 'tiki.memberextend.' . $info['id']; 
					$attributes = $attributelib->get_attributes('user', $u);
					if (isset($attributes[$attname])) {
						return '{REMARKSBOX(type=warning, title=Plugin Memberpayment Error)}' . tra('The user ') . $u 
					. tra(' already has a pending extension request payment invoice ') . $attributes[$attname] . '{REMARKSBOX}';
					}
				}
			}
			$periods = (int) $_POST['wp_member_periods'];

			if ( count($users) == 1 ) {
				$desc = tr('Membership to %0 for %1 (x%2)', $params['group'], reset($users), $periods);
			} else {
				$desc = tr('Membership to %0 for %1 users (x%2)', $params['group'], count($users), $periods);
			}

			$cost = round(count($users) * $periods * $params['price'], 2);
			// reduce cost due to prorated amount if applicable
			if (empty($params['freeperiods']) && $info['anniversary'] > '') {
				foreach ($users as $u) {
					$extend_until_info = $userlib->get_extend_until_info($u, $params['group'], $periods);
					$cost = $cost - (1 - $extend_until_info['ratio_prorated_first_period']) * $params['price'];
				}
				$cost = round($cost, 2);
			} elseif ($periods && !empty($params['freeperiods'])) { 
				// give free periods (purchase of at least 1 full real period required)
				$periods += $params['freeperiods'];
			}

			$id = $paymentlib->request_payment($desc, $cost, $prefs['payment_default_delay']);
			$paymentlib->register_behavior($id, 'complete', 'extend_membership', array( $users, $params['group'], $periods, $info['id'] ));

			foreach ($users as $u) {
				$attributelib->set_attribute('user', $u, 'tiki.memberextend.' . $info['id'], $id);
			}
			$paymentlib->register_behavior($id, 'cancel', 'cancel_membership_extension', array( $users, $info['id'] ));

			$smarty->assign('wp_member_title', $params['howtitle']);
			require_once 'lib/smarty_tiki/function.payment.php';
			return '^~np~' . smarty_function_payment(array( 'id' => $id ), $smarty) . '~/np~^';
		} else if ($prefs['payment_system'] == 'cclite' && isset($_POST['cclite_payment_amount']) && isset($_POST['invoice'])) {
			require_once 'lib/smarty_tiki/function.payment.php';
			return '^~np~' . smarty_function_payment(array( 'id' => $_POST['invoice'] ), $smarty) . '~/np~^';
		}

		$smarty->assign('wp_member_title', $params['inputtitle']);
		return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_memberpayment.tpl') . '~/np~';
	} elseif ($info['expireAfter'] == 0 && $params['group'] == $info['groupName']) {
		return '{REMARKSBOX(type=warning, title=Plugin Memberpayment Error)}' . tra('The group ') . '<em>' . $info['groupName'] 
				. '</em>' . tra(' does not have a membership term.') . tra(' Go to ') . '<em>' . tra('Admin > Groups') . '</em>' 
				. tra(' to specify a term for this group by automatically unassigning users after a certain number of days.') 
				. '{REMARKSBOX}';
	} else {
		return '{REMARKSBOX(type=warning, title=Plugin Memberpayment Error)}' . tra('The group ') . '<em>' . $params['group'] 
				. '</em>' . tra(' does not exist') . '{REMARKSBOX}';
	}
}