function ym_mm_invoice_subs($data)
{
    $user_id = $data['user_id'];
    $pack_id = $data['pack_id'];
    $user_data = $data['user_data'];
    $data = get_option('ym_mm_invoicing');
    if (!$data->subscription_enabled) {
        return;
    }
    if (is_array($user_id)) {
        $user_id = implode($user_id);
    }
    global $ym_mm_type, $ym_mm_title, $ym_mm_cost;
    $ym_mm_type = __('Subscription', 'ym_mailmanager');
    $ym_mm_title = ym_get_pack_label($user_data->pack_id);
    $ym_mm_cost = $user_data->currency . ' ' . $user_data->amount;
    ym_mm_parse_and_send($user_id, $data->subscription_subject, $data->subscription_message);
}
    function getButtonOverride($pack, $user_id, $override_price = FALSE)
    {
        if (!$this->sslcheck()) {
            return;
        }
        $button_code = $this->get_button_code($pack, $user_id, $override_price);
        $button_code = apply_filters('ym_additional_code', $button_code, $this->code, $pack['id']);
        $button_code_html = '';
        foreach ($button_code as $item => $val) {
            $button_code_html .= '<input type="hidden" name="' . $item . '" value="' . $val . '" />' . "\n";
        }
        $r = '
<form action="' . $this->action_url . '" method="post" class="ym_form ' . $this->code . '_form" name="' . $this->code . '_form" id="' . $this->code . '_form" target="ym_pro_iframe">
	<fieldset>
		<strong>' . ym_get_pack_label($pack['id']) . '</strong><br />
		';
        if ($override_price) {
            $r .= '<strong>' . $override_price . ' ' . ym_get_currency($pack['id']) . ' ' . __('First Period', 'ym') . '</strong><br />';
        }
        $r .= '
		' . $button_code_html . '
		<input type="image" src="' . $this->logo . '" border="0" name="submit" alt="' . $this->membership_words . '" id="ym_paypal_pro_button" />
	</fieldset>
</form>
';
        $r .= '
<script type="text/javascript">' . "\n\tjQuery('#ym_paypal_pro_button').click(function() {\n\t\tevent.preventDefault();\n\t\tjQuery('." . $this->code . "_form').submit();\n\t\tjQuery('.ym_form').slideUp();\n\t\tjQuery('#ym_pro_iframe_control').slideDown();\n\t});\n</script>\n";
        $r .= '
<br />
<div id="ym_pro_iframe_control" style="display: none; text-align: center;">
	<iframe name="ym_pro_iframe" id="ym_pro_iframe" style="width: 580px; height: 550px;';
        //	if ($margin) {
        if (defined('subscribe.php')) {
            $r .= ' margin-left: -130px;';
        }
        $r .= ' border: 0px;" scrolling="no">Loading...</iframe>
</div>
<br />
';
        return $r;
    }
function ym_render_subscription_form($predata)
{
    global $ym_formgen, $duration_str, $link, $ym_res, $ym_package_types;
    $data = $predata;
    $data['id'] = isset($data['id']) ? $data['id'] : 0;
    if ($data['id']) {
        echo '<input type="hidden" name="id" value="' . $data['id'] . '" />';
    }
    echo '
	<table class="form-table">';
    $ym_formgen->render_form_table_text_row(__('Admin Name', 'ym'), 'admin_name', $data['admin_name'], __('A Handy Name for the Admin Interface', 'ym'));
    $ym_formgen->render_form_table_text_row(__('Price', 'ym'), 'cost', $data['cost'], __('The Price in digits, no currency symbol needed', 'ym'));
    $types = array();
    if ($ym_package_types) {
        foreach ($ym_package_types->types as $k => $v) {
            $types[$k] = $v;
        }
    }
    $types['new'] = __('Create a New Type', 'ym');
    echo '<tr><th>' . __('Package Type', 'ym') . '</th><td><select name="account_type" class="account_type_selector">';
    foreach ($types as $k => $v) {
        echo '<option value="' . $k . '" ';
        if ($data['account_type'] && strtolower($v) == strtolower($data['account_type'])) {
            echo ' selected="selected" ';
        }
        echo ' >';
        echo $v;
        echo '</option>';
    }
    echo '</select></td></tr>';
    echo '<tr class="new_account_type_entry"><th>' . __('New Package Type', 'ym');
    echo '<div style="color: gray; margin-top: 5px; font-size: 11px;">';
    echo __('Create a new Package Type', 'ym');
    echo '</th><td><input type="text" name="new_account_type" value="" /></td></tr>';
    echo '
<tr>
	<th>' . __('Duration', 'ym') . ':
	<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('The Length of the Subscription', 'ym') . '</div>
	</th>
	<td>
		<table><tr>
			<td>
				<input class="ym_input" style="width: 50px; font-family:\'Lucida Grande\',Verdana; font-size: 11px; text-align: right;" name="duration" value="' . $data['duration'] . '">
			</td>
			<td>
				<select name="duration_type">
				';
    foreach ($duration_str as $str => $val) {
        echo '<option value="' . $str . '"';
        if ($str == $data['duration_type']) {
            echo ' selected="selected"';
        }
        echo '>' . $val . '</option>';
    }
    echo '
				</select>
			</td>
		</tr></table>
	</td>
</tr>
';
    /**
    Basic with trial
    */
    $trial = ym_packs_gateways_trial_on();
    if ($trial) {
        echo '<tr class="basic_with_trial table_divider"><td></td><th><h4>' . __('Trial Options', 'ym') . '</h4></th></tr>';
        echo '<tr class="basic_with_trial"><th>' . __('Enable Trial Period', 'ym');
        echo '</th><td><input type="checkbox" name="trial_on" value="1" ';
        if (isset($data['trial_on'])) {
            if ($data['trial_on'] == 1) {
                echo 'checked="checked"';
            }
        }
        echo ' /></td></tr>';
        echo '<tr class="basic_with_trial"><th>' . __('Trial Price', 'ym');
        echo '</th><td><input tpye="text" name="trial_cost" value="' . $data['trial_cost'] . '" /></td></tr>';
        echo '
<tr class="basic_with_trial">
	<th>' . __('Trial Duration', 'ym') . ':
	<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('The Length of the Trial Subscription', 'ym') . '</div>
	</th>
	
	<td>
		<table><tr>
			<td>
				<input class="ym_input" style="width: 50px; font-family:\'Lucida Grande\',Verdana; font-size: 11px; text-align: right;" name="trial_duration" value="' . $data['trial_duration'] . '">
			</td>
			<td>
				<select name="trial_duration_type">
				';
        foreach ($duration_str as $str => $val) {
            echo '<option value="' . $str . '"';
            if (isset($data['trial_duration_type'])) {
                if ($str == $data['trial_duration_type']) {
                    echo ' selected="selected"';
                }
            }
            echo '>' . $val . '</option>';
        }
        echo '
				</select>
			</td>
		</tr></table>
	</td>
</tr>
';
    }
    /**
    Advanced
    */
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Additional Package Options', 'ym') . '</h4></th></tr>';
    $cycles = array(0 => 'Ongoing');
    for ($x = 1; $x <= 59; $x++) {
        $cycles[$x] = $x;
    }
    $ym_formgen->tr_class = 'advanced';
    $ym_formgen->style = 'display: none;';
    $ym_formgen->render_combo_from_array_row(__('Package Reoccurance', 'ym'), 'num_cycles', $cycles, $data['num_cycles'], __('How many times the subscription repeats', 'ym'), $data['num_cycles']);
    $currencies = ym_get_currencies();
    if (!$data['currency']) {
        $data['currency'] = ym_get_currency();
    }
    $ym_formgen->render_combo_from_array_row(__('Payment Currency', 'ym'), 'currency', $currencies, $data['currency'], __('Currency for Package', 'ym'));
    $roles = new WP_Roles();
    $roles_array = array_reverse($roles->role_names);
    $ym_formgen->render_combo_from_array_row(__('WordPress Role', 'ym'), 'role', $roles_array, $data['role'], __('Grant these Role set to the User', 'ym'));
    $ym_formgen->render_form_table_textarea_row(__('Package Description', 'ym'), 'description', $data['description'], __('Only used with the [description] Package Template Argument. Check Advanced -> Messages -> Templates', 'ym'));
    $ym_formgen->render_form_table_checkbox_row(__('Hide Old Content', 'ym'), 'hide_old_content', $data['hide_old_content'], __('Hide content created and protected prior to the member&#39;s current subscription start date', 'ym'));
    $ym_formgen->render_form_table_checkbox_row(__('Hide from Standard Subscription page', 'ym'), 'hide_subscription', $data['hide_subscription'], __('When enabled, this package would only be available directly from ym_register shortcode or from a coupon', 'ym'));
    $ym_formgen->render_form_table_checkbox_row(__('Hide Admin Bar', 'ym'), 'hide_admin_bar', $data['hide_admin_bar']);
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Expire Options', 'ym') . '</h4></th></tr>';
    echo '<tr class="advanced"><th>' . __('Set Subscription Expiry Date', 'ym');
    echo '<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('Users will expire at the start of this date', 'ym') . '</div></th>';
    $value = $data['force_end_date'] ? $data['force_end_date'] : '';
    if ($value) {
        $value = date('d/m/Y', $value);
    }
    echo '<td>
					<input type="text" name="force_end_date" id="dateclear" value="' . $value . '" class="ym_yearpicker" /> <a href="#nowhere" onclick="ym_clear_target(\'dateclear\');">' . __('Clear Date', 'ym') . '
				</td></tr>';
    echo '<tr class="advanced"><th>' . __('On Expire Drop User to:', 'ym') . '</th>';
    echo '<td>';
    echo '<select name="on_expire_drop_to">';
    echo '<option value="">' . __('Inactive', 'ym') . '</option>';
    foreach (ym_get_packs() as $pack) {
        if ($data['id'] == $pack['id']) {
            continue;
        }
        echo '<option value="' . $pack['id'] . '" ';
        if ($data['on_expire_drop_to'] == $pack['id']) {
            echo 'selected="selected"';
        }
        echo '>';
        echo '(' . $pack['id'] . ') ' . ym_get_pack_label($pack['id']);
        echo '</option>';
    }
    echo '</select>';
    echo '</td></tr>';
    // gateway disable
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Payment Gateway Options', 'ym') . '</h4></th></tr>';
    echo '
	<tr class="advanced">
		<td colspan="2"><p>' . __('This filtering is also subject to Payment Gateway filters, for example, the Free Gateway can never be used to buy a non Free Package (so you do not have to deselect it here if this package is not free)', 'ym') . '</p></td>
	</tr>
	<tr class="advanced"><th>' . __('Allow Gateways', 'ym');
    echo '<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('You can select gateways to use with this Pack', 'ym') . '</div></th>';
    echo '<td>';
    echo '<ul>';
    global $ym_active_modules;
    foreach ((array) $ym_active_modules as $key => $module) {
        echo '<li>';
        echo '<label for="disable_module_' . $key . '">';
        echo '<input type="checkbox" id="disable_module_' . $key . '" name="gateway_disable[]" value="' . $module . '" ';
        // checked?
        if (FALSE !== array_search($module, $data['gateway_disable'])) {
            echo 'checked="checked"';
        }
        echo ' /> ';
        $way = new $module();
        echo $way->name;
        echo '</label>';
        echo '</li>';
    }
    echo '</ul>';
    echo '</td>';
    echo '</tr>';
    // URLS
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Package Speicifc Redirects', 'ym') . '</h4></th></tr>';
    $ym_formgen->render_form_table_url_row(__('Success URL', 'ym'), 'success_redirect', $data['success_redirect'], __('Where to redirect the user to on Successful Transaction, aka Thank You Page', 'ym'));
    echo '
	<tr class="advanced">
		<td colspan="2"><p>' . __('If you need Pack Specific redirects you can configure these here, you can leave these blank and the default redirects configured under Advanced->Security will be used', 'ym') . '</p></td>
	</tr>
	';
    $ym_formgen->render_form_table_url_row(__('Login Redirect URL', 'ym'), 'login_redirect_url', $data['login_redirect_url'], __('Where to redirect the user to on Login', 'ym'));
    $ym_formgen->render_form_table_url_row(__('WP Admin Block URL', 'ym'), 'wpadmin_disable_redirect_url', $data['wpadmin_disable_redirect_url'], __('Where to redirect the user to on WP Admin Access', 'ym'));
    $ym_formgen->render_form_table_url_row(__('Logout Redirect URL', 'ym'), 'logout_redirect_url', $data['logout_redirect_url'], __('Where to redirect the user to on Logout', 'ym'));
    $ym_formgen->render_form_table_url_row(__('First Login URL', 'ym'), 'first_login', $data['first_login'], __('Where to redirect on the user first login with this package', 'ym'));
    // Group Membership
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Group Membership', 'ym') . '</h4></th></tr>';
    $ym_formgen->render_form_table_text_row(__('Total Allowed Child Accounts', 'ym'), 'child_accounts_allowed', $data['child_accounts_allowed']);
    echo '<tr class="advanced"><td colspan="2"><p>' . __('A Group Leader can create child accounts, these child accounts normally inherit the parents package type, optionally you can allow the group admin to choose which Package Type the child account uses from a subset of the available Package Types (this will exclude the parent package type from being selectable unless you select it below). Further more you can allow Packages to be available, allowing you a Group Leader, to create a child account, which itself can have children. If packages are allowed they are applied to a child account at zero cost', 'ym') . '</p></td></tr>';
    echo '<tr class="advanced"><td>' . __('Use Inherit Mode', 'ym') . '</td><td><input type="checkbox" name="inherit_mode" id="ym_inherit_mode" ';
    $score = 0;
    foreach ($data['child_accounts_package_types'] as $v => $count) {
        $score += $count;
    }
    global $ym_packs;
    foreach ($ym_packs->packs as $pack) {
        if (in_array($pack['id'], $data['child_accounts_packages'])) {
            $score++;
        }
    }
    if (!$score) {
        echo 'checked="checked"';
    }
    echo ' /></td></tr>';
    echo '<tr class="ym_inherit_mode_off"><td>' . __('Available Package Types', 'ym') . '</td><td><table>';
    foreach ($ym_package_types->types as $v) {
        if (strtolower($v) == 'guest') {
            continue;
        }
        echo '<tr><td>';
        echo $v;
        echo '</td><td>';
        echo '<input type="text" name="child_accounts_package_types[' . $v . ']" value="' . (isset($data['child_accounts_package_types'][$v]) ? $data['child_accounts_package_types'][$v] : 0) . '" /> ';
        echo '</td></tr>';
    }
    echo '</table></td></tr>';
    echo '<tr class="ym_inherit_mode_off"><td>' . __('Available Packages', 'ym') . '</td><td><table>';
    foreach ($ym_packs->packs as $pack) {
        echo '<tr><td>';
        echo ym_get_pack_label($pack['id']);
        echo '</td><td>';
        echo '<input type="checkbox" name="child_accounts_packages[]" value="' . $pack['id'] . '" ' . (in_array($pack['id'], $data['child_accounts_packages']) ? 'checked="checked"' : '') . ' /> ';
        echo '</td></tr>';
    }
    echo '</table></td></tr>';
    /**
    ALL
    */
    echo '<tr class="basic table_divider"><td></td><th><h4>' . __('Payment Gateway Specific Fields', 'ym') . '</h4></th></tr>';
    // gateway fields
    ym_packs_gateways_extra_fields_display($data);
    echo '</table>';
}
Exemple #4
0
    function invoice_tab()
    {
        $invoice = new ym_invoice();
        global $wpdb;
        if (ym_post('user_id')) {
            $user_id = ym_post('user_id');
            $op = ym_post('op', '');
            $undo = ym_post('undo', FALSE);
            $user = new YourMember_User($user_id);
            if ($undo) {
                $data = array('status' => YM_STATUS_PENDING, 'status_str' => __('Invoice Undo', 'ym'));
                $user->update($data);
                $user->save();
                $packet = array('user_id' => $user_id, 'status' => FALSE);
                do_action('ym_invoice_status_update', $packet);
            } else {
                if ($op == 'resend') {
                    $invoice->generate_invoice($user, $invoice);
                    echo '<div id="message" class="updated"><p>' . __('Inovice Resent', 'ym') . '</p></div>';
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Invoice Resent', 'ym'), $user_id);
                } else {
                    if ($op == 'active') {
                        $data = array('status' => YM_STATUS_ACTIVE, 'status_str' => __('Invoice Paid', 'ym'), 'amount' => intval(ym_post('amount', 0)), 'last_pay_date' => time());
                        $current_status = $user->status;
                        if ($current_status == YM_STATUS_GRACE) {
                            $extend = $user->last_pay_date;
                            $packdata = ym_get_pack_by_id($user->pack_id);
                            $data['expire_date'] = $user->expiry_time($packdata['duration'], $packdata['duration_type'], $extend);
                        }
                        // check for force end
                        if (isset($packdata['force_end_date'])) {
                            $force_end_date = $packdata['force_end_date'];
                            if ($force_end_date > time()) {
                                // greater than now
                                @ym_log_transaction(YM_ACCESS_EXTENSION, 'Adjustment (Force End Date): ' . $force_end_date, $user_id);
                                $data['expire_date'] = $force_end_date;
                            }
                        }
                        $data['amount'] = preg_replace('/[^\\d\\.]/', '', $data['amount']);
                        $data['amount'] = number_format($data['amount'], 2, '.', '');
                        $user->update($data, TRUE);
                        $optional = ym_post('optional');
                        if (!$optional) {
                            $optional = __('Invoice Paid', 'ym');
                        }
                        @ym_log_transaction(YM_IPN, $optional, $user_id);
                        @ym_log_transaction(YM_PAYMENT, $data['amount'], $user_id);
                        @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'], $user_id);
                        echo '<div id="message" class="updated"><p>' . __('Updated and Activated the User', 'ym') . '</p></div>';
                        $packet = array('user_id' => $user_id, 'pack_id' => $user->pack_id, 'status' => TRUE);
                        $invoice = new ym_invoice();
                        $invoice->notify_user($packet);
                        do_action('ym_invoice_status_update', $packet);
                    }
                }
            }
        }
        echo '<div id="poststuff" class="wrap">';
        ym_box_top(__('Invoice Management', 'ym'));
        $search = ym_post('ym_invoice_search', false);
        if ($search) {
            $query = 'SELECT u.user_id AS ID FROM ' . $wpdb->usermeta . ' u
				LEFT JOIN ' . $wpdb->usermeta . ' s ON s.user_id = u.user_id
				LEFT JOIN ' . $wpdb->users . ' us ON us.id = u.user_id
				WHERE
				u.meta_key = \'ym_payment_type\' AND u.meta_value = \'invoice\' 
				AND s.meta_key = \'ym_status\'
				AND (
					us.user_login LIKE \'%' . $search . '%\'
					OR
					us.user_email LIKE \'%' . $search . '%\'
				)
				ORDER BY ID DESC
				';
        } else {
            $query = 'SELECT u.user_id AS ID FROM ' . $wpdb->prefix . 'usermeta u
				LEFT JOIN ' . $wpdb->prefix . 'usermeta s ON s.user_id = u.user_id
				WHERE
				u.meta_key = \'ym_payment_type\' AND u.meta_value = \'invoice\' 
				AND s.meta_key = \'ym_status\'
				ORDER BY ID DESC
				';
        }
        $results = $wpdb->get_results($query);
        // quick search
        if ($wpdb->num_rows != 0 || $search) {
            // render search form
            echo '
<form action="" method="post" style="float: right;">
<fieldset>
	' . __('Username/Email Search:', 'ym') . '
	<input type="text" name="ym_invoice_search" value="' . $search . '" />
	<input type="submit" value="' . __('Search', 'ym') . '" />
</fieldset>
</form>';
        }
        echo '<p>' . __('Here you can update users based on the honouring of their invoice, you can use the Info to store field to store extra IPN style info such as a Cheque Number', 'ym') . '</p>';
        if ($wpdb->num_rows == 0) {
            echo ym_display_message(__('No Users are Invoice Pending', 'ym'), 'error');
        } else {
            echo '<table class="widefat">';
            echo '<tr>
				<th>' . __('Member', 'ym') . '</th>
				<th>' . __('Invoice Ref', 'ym') . '</th>
				<th>' . __('Purchasing', 'ym') . '</th>
				<th>' . __('Paid/Invoiced On Date', 'ym') . '</th>
				<th>' . __('Member Status', 'ym') . '</th>
				<th>' . __('Payment', 'ym') . '</th>
			</tr>';
            foreach ($results as $row) {
                $user = new YourMember_User($row->ID);
                echo '<tr>';
                echo '<td>(' . $row->ID . ') ' . $user->data->user_email;
                echo '<br />';
                if ($user->data->user_email != $user->data->user_login) {
                    echo $user->data->user_login . ' ';
                }
                echo $user->data->display_name;
                echo '</td>';
                echo '<td>#' . $user->invoice_id . '</td>';
                echo '<td>' . ym_get_pack_label($user->pack_id) . '</td>';
                echo '<td nowrap="nowrap" style="';
                // go red if overdue
                $limit = $user->invoiced_date + 86400 * $invoice->invoice_limit;
                // last pay date is invoiced on date
                // limit is due date for this invoice
                if (time() > $limit && $user->status != YM_STATUS_ACTIVE) {
                    echo 'background: red;';
                } else {
                    if (time() < $limit && $user->status != YM_STATUS_ACTIVE) {
                        echo 'background: #EFEFEF;';
                    }
                }
                echo '">';
                if ($user->status != YM_STATUS_ACTIVE) {
                    echo __('Invoiced', 'ym') . ' ' . date(YM_DATE, $user->invoiced_date);
                    echo '<br />' . __('Due', 'ym') . ' ' . date(YM_DATE, $limit);
                } else {
                    echo date(YM_DATE, $user->last_pay_date);
                }
                echo '</td>';
                echo '<td>' . $user->status . ' - ' . $user->status_str . '</td>';
                echo '<td>
				<form action="" method="post">
				<table><tr><td nowrap="nowrap">
					<input type="hidden" name="search" value="' . $search . '" />
					<input type="hidden" name="user_id" value="' . $row->ID . '" />
					';
                if ($user->status == YM_STATUS_ACTIVE) {
                    echo $user->amount;
                    // last ipn
                    $query = 'SELECT data FROM ' . $wpdb->prefix . 'ym_transaction WHERE action_id = ' . YM_IPN . ' AND user_id = ' . $row->ID . ' ORDER BY id DESC LIMIT 1';
                    $data = $wpdb->get_var($query);
                    if (substr($data, 0, 2) != 'a:') {
                        echo ' - ';
                        echo $data;
                    }
                    echo '</td><td>';
                    echo '</td><td>';
                    echo '
					<input type="hidden" name="undo" value="1" />
					<input type="submit" class="button-secondary deletelink" style="float: right;" value="' . __('Undo Active', 'ym') . '" />
					';
                } else {
                    echo '
					<label for="amount">' . __('Payment Amount', 'ym') . '</label> 
					<br />
					<label for="optional">' . __('Info to Store', 'ym') . ' 
					</td><td>
					<input type="text" name="amount" id="amount" value="" size="4" />
					<br />
					<input type="text" name="optional" id="optional" value="" size="4" /></label> 
					';
                    echo '</td><td>';
                    echo '
					<input type="submit" class="button-secondary deletelink" style="float: right;" value="' . __('Payment Recieved - Make Active', 'ym') . '" onclick="jQuery(\'#op_' . $row->ID . '\').val(\'active\');" />
					';
                    echo '</td><td>';
                    echo '
					<input type="submit" class="button-secondary" style="float: right;" value="' . __('Resend Invoice', 'ym') . '" onclick="jQuery(\'#op_' . $row->ID . '\').val(\'resend\');" />
					';
                }
                echo '
					<input type="hidden" name="op" id="op_' . $row->ID . '" value="" />
				</td></tr></table>
				</form>
					</td>';
                echo '</tr>';
            }
            echo '</table>';
        }
        ym_box_bottom();
        echo '</div>';
    }
function ym_reg_flow_logic_options($intro = FALSE, $item = FALSE)
{
    $data = ym_reg_flow_fields();
    $customs = $data['custom'];
    $r = '<div style="display: block; clear: both;">';
    if (!$item) {
        $item = array('iflogic' => '', 'iflogic_quantity_loggedin' => '', 'iflogic_quantity_pack' => '', 'iflogic_quantity_custom' => '', 'iflogic_quantity_custom_compare' => '', 'iflogic_quantity_field' => '', 'iflogic_quantity_entry' => '', 'iflogic_quantity_memberfor_value' => '', 'iflogic_quantity_memberfor_unit' => '', 'iflogic_showhide' => '');
    }
    if (!$intro) {
        $r .= '<p>' . __('You can apply display logic to decide wheather to show/hide', 'ym') . '</p>';
    }
    $r .= '
								<p>' . __('For Fields you can use * to match something or leave blank to match empty', 'ym') . '</p>
								<div class="iflogiccontrol">
								
								' . __('If user', 'ym') . ' <select name="iflogic[]" class="iflogic">
								';
    $r .= '
									<option value="">' . __('Select', 'ym') . '</option>
									<option value="loggedin" ' . ($item['iflogic'] == 'loggedin' ? 'selected="selected"' : '') . ' >' . __('Is Logged In', 'ym') . '</option>
									<option value="buying" ' . ($item['iflogic'] == 'buying' ? 'selected="selected"' : '') . ' >' . __('Buying Pack', 'ym') . ' </option>
									<option value="currentlyon" ' . ($item['iflogic'] == 'currentlyon' ? 'selected="selected"' : '') . ' >' . __('Currently On Pack', 'ym') . '</option>
									<option value="accounttype" ' . ($item['iflogic'] == 'accounttype' ? 'selected="selected"' : '') . ' >' . __('Account Type is', 'ym') . '</option>
									<option value="filledin" ' . ($item['iflogic'] == 'filledin' ? 'selected="selected"' : '') . ' >' . __('Custom Field', 'ym') . '</option>
									<option value="servervar" ' . ($item['iflogic'] == 'servervar' ? 'selected="selected"' : '') . ' >' . __('$_SERVER Variable', 'ym') . '</option>
									<option value="getvar" ' . ($item['iflogic'] == 'getvar' ? 'selected="selected"' : '') . ' >' . __('$_GET Variable', 'ym') . '</option>
									<option value="postvar" ' . ($item['iflogic'] == 'postvar' ? 'selected="selected"' : '') . ' >' . __('$_POST Variable', 'ym') . '</option>
									<option value="cookievar" ' . ($item['iflogic'] == 'cookievar' ? 'selected="selected"' : '') . ' >' . __('$_COOKIE Variable', 'ym') . '</option>';
    //<!--								<option value="memberfor">' . __('Been a Member for at least', 'ym') . '</option>-->
    $r .= '
									<option value="registeredfor" ' . ($item['iflogic'] == 'registeredfor' ? 'selected="selected"' : '') . ' >' . __('Been Registered for at least', 'ym') . '</option>
									<option value="expiresin" ' . ($item['iflogic'] == 'expiresin' ? 'selected="selected"' : '') . ' >' . __('Expires in more than', 'ym') . '</option>
								</select>
								
								<select name="iflogic_quantity_loggedin[]" class="logicoption loggedin" style="' . ($item['iflogic'] == 'loggedin' ? '' : 'display: none;') . '">
									<option value="1" ' . ($item['iflogic_quantity_loggedin'] == 1 ? 'selected="selected"' : '') . ' >Yes</option>
									<option value="0" ' . ($item['iflogic_quantity_loggedin'] == 0 ? 'selected="selected"' : '') . ' >No</option>
								</select>
								<select name="iflogic_quantity_pack[]" class="logicoption buying" style="' . ($item['iflogic'] == 'buying' ? '' : 'display: none;') . '">
								';
    $packoptions = '';
    global $ym_packs;
    foreach ($ym_packs->packs as $pack) {
        $label = ym_get_pack_label($pack['id']);
        $packoptions .= '<option value="' . $pack['id'] . '"';
        if ($pack['id'] == $item['iflogic_quantity_pack']) {
            $packoptions .= 'selected="selected"';
        }
        $packoptions .= '>(' . $pack['id'] . ') ' . $label . '</option>';
    }
    $r .= $packoptions;
    $r .= '
								</select>

								<select name="iflogic_quantity_pack[]" class="logicoption currentlyon" style="' . ($item['iflogic'] == 'currentlyon' ? '' : 'display: none;') . '">
								';
    $r .= '<option value="0">' . __('No Pack', 'ym') . '</option>';
    $r .= $packoptions;
    $r .= '
								</select>

								<select name="iflogic_quantity_custom[]" class="logicoption accounttype" style="' . ($item['iflogic'] == 'accounttype' ? '' : 'display: none;') . '">
								';
    global $ym_package_types;
    foreach ($ym_package_types->types as $type) {
        $r .= '<option value="' . $type . '"';
        if ($type == $item['iflogic_quantity_custom']) {
            $r .= ' selected="selected" ';
        }
        $r .= '>' . $type . '</option>';
    }
    $r .= '
								</select>

								<select name="iflogic_quantity_custom[]" class="logicoption filledin" style="' . ($item['iflogic'] == 'filledin' ? '' : 'display: none;') . '">
								';
    // customs
    $exclude = array('subscription_introduction', 'subscription_options', 'terms_and_conditions');
    $ok = FALSE;
    foreach ($customs as $custom) {
        $nice = $custom['nice'];
        $cid = $custom['id'];
        if (!in_array($label, $exclude)) {
            $r .= '<option value="' . $cid . '" ';
            if ($cid == $item['iflogic_quantity_custom']) {
                $r .= ' selected="selected" ';
            }
            $r .= '>' . $nice . '</option>';
            $ok = TRUE;
        }
    }
    if (!$ok) {
        $r .= '<option value="">No Available Fields</option>';
    }
    $r .= '
								</select>
								<label class="logicoption filledin" style="' . ($item['iflogic'] == 'filledin' ? '' : 'display: none;') . '">' . __('Field Value:', 'ym') . ' 
									<input type="text" name="iflogic_quantity_custom_compare[]" value="' . $item['iflogic_quantity_custom_compare'] . '" /></label>
								
								<label class="logicoption servervar getvar postvar cookievar" style="' . (substr($item['iflogic'], -3, 3) == 'var' ? '' : 'display: none;') . '">' . __('Field Name:', 'ym') . ' 
									<input type="text" name="iflogic_quantity_field[]" value="' . $item['iflogic_quantity_field'] . '" /></label>
								<label class="logicoption servervar getvar postvar cookievar" style="' . (substr($item['iflogic'], -3, 3) == 'var' ? '' : 'display: none;') . '">' . __('Field Value:', 'ym') . ' 
									<input type="text" name="iflogic_quantity_entry[]" value="' . $item['iflogic_quantity_entry'] . '" /></label>
								
								<input class="logicoption memberfor registeredfor expiresin" style="' . ($item['iflogic'] == 'memberfor' || $item['iflogic'] == 'registeredfor' || $item['iflogic'] == 'expiresin' ? '' : 'display: none;') . '" type="text" name="iflogic_quantity_memberfor_value[]" />
								<select class="logicoption memberfor registeredfor expiresin" name="iflogic_quantity_memberfor_unit[]" style="' . ($item['iflogic'] == 'memberfor' || $item['iflogic'] == 'registeredfor' || $item['iflogic'] == 'expiresin' ? '' : 'display: none;') . '">
									<option value="hour" ' . ($item['iflogic_quantity_memberfor_unit'] == 'hour' ? 'selected="selected"' : '') . ' >' . __('Hour', 'ym') . '</option>
									<option value="day" ' . ($item['iflogic_quantity_memberfor_unit'] == 'day' ? 'selected="selected"' : '') . ' >' . __('Day', 'ym') . '</option>
									<option value="week" ' . ($item['iflogic_quantity_memberfor_unit'] == 'week' ? 'selected="selected"' : '') . ' >' . __('Week', 'ym') . '</option>
									<option value="month" ' . ($item['iflogic_quantity_memberfor_unit'] == 'month' ? 'selected="selected"' : '') . ' >' . __('Month', 'ym') . '</option>
									<option value="year" ' . ($item['iflogic_quantity_memberfor_unit'] == 'year' ? 'selected="selected"' : '') . ' >' . __('Year', 'ym') . '</option>
								</select>
								
								<span class="logicoption loggedin buying currentlyon accounttype filledin servervar getvar postvar cookievar memberfor registeredfor expiresin" style="' . ($item['iflogic'] != '' ? '' : 'display: none;') . '">
									' . __(' then ', 'ym') . '

									<select name="iflogic_showhide[]">
										<option value="show" ' . ($item['iflogic_showhide'] == 'show' ? 'selected="selected"' : '') . '>' . __('Show', 'ym') . '</option>
										<option value="hide" ' . ($item['iflogic_showhide'] == 'hide' ? 'selected="selected"' : '') . '>' . __('Hide', 'ym') . '</option>
									</select>
								</span>

								</div>
';
    $r .= '</div>';
    return $r;
}
';
$last_pack_id = FALSE;
foreach ($fields as $key => $value) {
    echo '
<tr>
';
    echo ' ';
    if (substr($key, 0, 8) == 'ym_pack_') {
        list($pack_id, $item) = explode('-', substr($key, 8));
        if (!$last_pack_id || $last_pack_id != $pack_id) {
            echo '<td colspan="2"><input type="submit" class="button-secondary" value="' . __('Save', 'ym') . '" style="float: right;" /><hr /><br /></td></tr><tr>';
            $last_pack_id = $pack_id;
        }
        echo '<th>';
        echo 'Pack: ';
        echo ym_get_pack_label($pack_id);
        echo ':<br />';
        echo ucwords(str_replace('_', ' ', $item));
    } else {
        echo '<th>' . __('Base/Default', 'ym') . ': ';
        echo ucwords(str_replace('_', ' ', $key));
    }
    echo '</th>
	<td style="vertical-align: top;">' . site_url() . '
		<input class="ym_input" style="width: 400px;" name="' . $key . '" value="' . $value . '" />
	</td>
</tr>
	';
}
echo '</table>';
echo '<input type="submit" class="button-primary" value="' . __('Save', 'ym') . '" style="float: right;" />';
 function notify_user($packet, $nomore = false)
 {
     if (isset($this->nomore_email) && $this->nomore_email) {
         return;
     }
     $this->nomore_email = $nomore;
     global $ym_res;
     $user = get_userdata($packet['user_id']);
     $message_id = '';
     // make sure its an int
     if ($packet['status']) {
         $packet['status'] = 1;
     } else {
         $packet['status'] = 0;
     }
     if (isset($packet['post_id']) && $packet['post_id']) {
         $message_id = 'post_' . $packet['status'];
     } else {
         if (isset($packet['ppack_id']) && $packet['ppack_id']) {
             $message_id = 'ppack_' . $packet['status'];
         } else {
             $message_id = 'pack_' . $packet['status'];
         }
     }
     $target = $subject = $message = $target_scan = '';
     $do = FALSE;
     if (method_exists($this, 'messages')) {
         // if data returned then send email here
         // otherwise no send or payment gateway handles
         // data returns message to send
         $data = $this->messages($message_id, $user, $packet);
         if ($data) {
             $target = $data['to'];
             $subject = $data['subject'];
             $message = $data['message'];
             $target_scan = $data['target_scan'];
             $do = TRUE;
         }
     } else {
         $target = $user->display_name . ' <' . $user->user_email . '>';
         $display_name = $user->display_name;
         // use default messages
         switch ($message_id) {
             case 'post_1':
                 if ($ym_res->payment_gateway_enable_post_success) {
                     $do = TRUE;
                 }
                 $target_scan = 'payment_gateway_email_post_success';
                 $posttitle = get_the_title($packet['post_id']);
                 $posttitle = strip_tags($posttitle);
                 $postlink = get_permalink($packet['post_id']);
                 $subject = $ym_res->payment_gateway_subject_post_success;
                 $subject = str_replace('[blogname]', get_option('blogname'), $subject);
                 $subject = str_replace('[post_title]', $posttitle, $subject);
                 $message = $ym_res->payment_gateway_message_post_success;
                 $message = str_replace('[display_name]', $display_name, $message);
                 $message = str_replace('[post_title]', $posttitle, $message);
                 $message = str_replace('[post_link]', $postlink, $message);
                 $message = str_replace('[blogname]', get_option('blogname'), $message);
                 break;
             case 'post_0':
                 if ($ym_res->payment_gateway_enable_post_failed) {
                     $do = TRUE;
                 }
                 $target_scan = 'payment_gateway_email_post_failed';
                 $posttitle = get_the_title($packet['post_id']);
                 $posttitle = strip_tags($posttitle);
                 $subject = $ym_res->payment_gateway_subject_post_failed;
                 $subject = str_replace('[blogname]', get_option('blogname'), $subject);
                 $subject = str_replace('[post_title]', $posttitle, $subject);
                 $message = $ym_res->payment_gateway_message_post_failed;
                 $message = str_replace('[display_name]', $display_name, $message);
                 $message = str_replace('[post_title]', $posttitle, $message);
                 $message = str_replace('[blogname]', get_option('blogname'), $message);
                 break;
             case 'ppack_1':
                 if ($ym_res->payment_gateway_enable_ppack_success) {
                     $do = TRUE;
                 }
                 $target_scan = 'payment_gateway_email_ppack_success';
                 $pack_data = ym_get_bundle($packet['ppack_id']);
                 $posts = ym_get_bundle_posts($packet['ppack_id']);
                 $post_urls = '';
                 foreach ($posts as $post) {
                     $post_urls .= '<a href="' . get_permalink($post->post_id) . '">' . get_the_title($post->post_id) . '</a><br />';
                 }
                 $subject = $ym_res->payment_gateway_subject_ppack_success;
                 $subject = str_replace('[blogname]', get_option('blogname'), $subject);
                 $subject = str_replace('[pack_title]', $pack_data->name, $subject);
                 $message = $ym_res->payment_gateway_message_ppack_success;
                 $message = str_replace('[display_name]', $display_name, $message);
                 $message = str_replace('[pack_name]', $pack_data->name, $message);
                 $message = str_replace('[posts_in_pack]', $post_urls, $message);
                 $message = str_replace('[blogname]', get_option('blogname'), $message);
                 break;
             case 'ppack_0':
                 if ($ym_res->payment_gateway_enable_ppack_failed) {
                     $do = TRUE;
                 }
                 $target_scan = 'payment_gateway_email_ppack_failed';
                 $pack_data = ym_get_bundle($packet['ppack_id']);
                 $subject = $ym_res->payment_gateway_subject_ppack_failed;
                 $subject = str_replace('[blogname]', get_option('blogname'), $subject);
                 $subject = str_replace('[pack_title]', $pack_data->name, $subject);
                 $message = $ym_res->payment_gateway_message_ppack_failed;
                 $message = str_replace('[display_name]', $display_name, $message);
                 $message = str_replace('[pack_name]', $pack_data->name, $message);
                 $message = str_replace('[blogname]', get_option('blogname'), $message);
                 break;
             case 'pack_1':
                 if ($ym_res->payment_gateway_enable_subscription_success) {
                     $do = TRUE;
                 }
                 $target_scan = 'payment_gateway_email_subscription_success';
                 $label = ym_get_pack_label($packet['pack_id']);
                 $label = strip_tags($label);
                 $user = new YourMember_User($packet['user_id']);
                 $expire = $user->expire_date;
                 $f = YM_DATE;
                 $expire = date($f, $expire);
                 $subject = $ym_res->payment_gateway_subject_subscription_success;
                 $subject = str_replace('[blogname]', get_option('blogname'), $subject);
                 $subject = str_replace('[pack_label]', $label, $subject);
                 $message = $ym_res->payment_gateway_message_subscription_success;
                 $message = str_replace('[display_name]', $display_name, $message);
                 $message = str_replace('[pack_label]', $label, $message);
                 $message = str_replace('[pack_expire]', $expire, $message);
                 $message = str_replace('[blogname]', get_option('blogname'), $message);
                 break;
             case 'pack_0':
                 if ($ym_res->payment_gateway_enable_subscription_failed) {
                     $do = TRUE;
                 }
                 $target_scan = 'payment_gateway_email_subscription_failed';
                 $label = ym_get_pack_label($packet['pack_id']);
                 $label = strip_tags($label);
                 $subject = $ym_res->payment_gateway_subject_subscription_failed;
                 $subject = str_replace('[blogname]', get_option('blogname'), $subject);
                 $subject = str_replace('[pack_label]', $label, $subject);
                 $message = $ym_res->payment_gateway_message_subscription_failed;
                 $message = str_replace('[display_name]', $display_name, $message);
                 $message = str_replace('[pack_label]', $label, $message);
                 $message = str_replace('[blogname]', get_option('blogname'), $message);
                 break;
         }
     }
     remove_all_shortcodes();
     // login user to alow shortcodes to behave
     wp_set_current_user($packet['user_id']);
     // apply ym_user_custom shortcode
     add_shortcode('ym_user_is', 'ym_user_is');
     add_shortcode('ym_user_is_not', 'ym_user_is_not');
     add_shortcode('ym_user_custom', 'ym_shortcode_user');
     $message = do_shortcode($message);
     // transaction log ID
     global $ym_this_transaction_id;
     $log_id = 'YMTRANS_' . $ym_this_transaction_id;
     $message = str_replace('[ym_log_id]', $log_id, $message);
     $message_prepend = __('This is a copy of a Message not sent', 'ym');
     if ($do) {
         ym_email($target, $subject, $message);
         $message_prepend = __('This is a copy of a Message sent', 'ym');
     }
     // additional targets?
     if (is_array($ym_res->{$target_scan})) {
         $subject = 'CC: ' . $subject;
         $message = $message_prepend . '<br /><br />' . $message;
         foreach ($ym_res->{$target_scan} as $target) {
             if ($target) {
                 ym_email($target, $subject, $message);
             }
         }
     }
 }
function mailmanager_get_recipients()
{
    $recipients = array('wordpress_users' => __('Entire Wordpress User Database', 'ym_mailmanager'), 'wordpress_commenters' => __('All Blog Commenters', 'ym_mailmanager'), 'wordpress_guest_commenters' => __('All Guest Commenters (No user account)', 'ym_mailmanager'), 'wordpress_registered_commenters' => __('All Registered Commenters', 'ym_mailmanager'));
    if ($ym_account_types = get_option('ym_account_types')) {
        $recipients['ym_all_active'] = __('Your Members Active Users', 'ym_mailmanager');
        $recipients['ym_all_inactive'] = __('Your Members Inactive Users', 'ym_mailmanager');
        $recipients['ym_all_expired'] = __('Your Members Expired Users', 'ym_mailmanager');
        foreach ($ym_account_types->types as $type) {
            $recipients['ym_ac_' . strtolower($type)] = __('Your Members active members of type: ', 'ym_mailmanager') . $type;
        }
    }
    if ($ym_packs = ym_get_packs()) {
        foreach ($ym_packs as $pack) {
            $recipients['ym_pack_' . $pack['id']] = strip_tags(ym_get_pack_label($pack));
        }
    }
    return apply_filters('mailmanager_adjust_recipients', $recipients);
}
Exemple #9
0
function ym_upgrade_links($template = 'sidebar', $pack_id = false, $hide_pack_string = false, $return = false)
{
    get_currentuserinfo();
    global $user, $current_user, $duration_str, $ym_packs;
    $html = '';
    $account_type = ym_get_user_account_type(false, true);
    $username = $current_user->user_login;
    if (!($packs = $ym_packs->packs)) {
        $packs = array();
    }
    $active_modules = get_option('ym_modules');
    $mod_count = count($active_modules);
    $base = add_query_arg(array('ym_subscribe' => 1, 'ud' => 1, 'username' => $username), get_option('siteurl'));
    $html .= '<div class="ym_upgrade_packs">';
    foreach ($packs as $pack) {
        if ($pack_id) {
            if ($pack['id'] != $pack_id) {
                continue;
            }
        }
        if ($pack['hide_subscription']) {
            continue;
        }
        $dur_type = $duration_str[$pack['duration_type']];
        $dur_str = $pack['duration'] == 1 ? rtrim($dur_type, 's') : $dur_type;
        $ac_type = strtolower($pack['account_type']);
        if (in_array($ac_type, array($account_type, 'trial', 'free'))) {
            continue;
        }
        $cost = $pack['cost'];
        $pack_str = false;
        if (!$hide_pack_string) {
            $pack_str = ym_get_pack_label($pack);
        }
        $html .= '<div class="ym_upgrade_pack">';
        if ($pack_str) {
            if ($template != 'sidebar') {
                $html .= '<div class="ym_page_upgrade_pack_string">' . $pack_str . '</div>';
                if ($pack['description'] != '') {
                    $html .= '<div class="ym_page_upgrade_pack_description">' . $pack['description'] . '</div>';
                }
            } else {
                $html .= '<div class="ym_sidebar_upgrade_pack_description">' . $pack_str . '</div>';
            }
        }
        if ($mod_count) {
            if ($active_modules) {
                foreach ($active_modules as $module) {
                    if ($module == 'ym_trial') {
                        continue;
                    } else {
                        if ($module == 'ym_free' && $cost) {
                            continue;
                        }
                    }
                    $obj = new $module();
                    //					$button = $obj->getButton($cost, $pack['duration'], $pack['duration_type'], $pack['account_type'], $pack['product_id'], $pack['num_cycles'], $pack['trial_on'], $pack['trial_cost'], $pack['trial_duration'], $pack['trial_duration_type'], $pack['role'], $pack['hide_old_content'], $pack['zombaio_price_id'], $pack['vat_applicable'], $pack['id']);
                    $button = $obj->getButton($pack['id']);
                    if ($button) {
                        $html .= '<div class="ym_upgrade_button ym_' . $obj->name . '_upgrade">';
                        $html .= $button;
                        $html .= '</div>';
                    }
                }
            }
        } else {
            $html .= __('There are no gateways available at this time.', 'ym');
        }
        $html .= '<div style="padding: 0; margin: 0; clear: both;"></div>';
        $html .= '</div>';
    }
    $html .= '</div>';
    if ($return) {
        return $html;
    } else {
        echo $html;
    }
}
Exemple #10
0
		</div>

		<div style="clear: both; padding-top: 5px;">
			<label>
				<div style="float: left; width: 150px; padding-top: 5px;"><?php 
_e('Package:', 'ym');
?>
</div>
				<div style="float: left; width: 150px;">
					<select name="bkpackage">
					<option value="all">All</option>

				<?php 
global $ym_packs;
foreach ($ym_packs->packs as $pack) {
    echo '<option value="' . $pack['id'] . '">(' . $pack['id'] . ') ' . ($pack['admin_name'] ? $pack['admin_name'] : ym_get_pack_label($pack['id'])) . '</option>';
}
?>
					</select>
				</div>		
			</label>
		</div>

		<div style="clear: both; padding-top: 5px;">
			<label>
				<div style="float: left; width: 150px; padding-top: 5px;"><?php 
_e('Output Format:', 'ym');
?>
</div>
				<div style="float: left; width: 150px;">
					<select name="bkformat">
Exemple #11
0
function ym_fbook_admin()
{
    global $wpdb, $ym_formgen, $facebook_settings;
    include YM_FBOOK_BASE_DIR . 'includes/ym_facebook_constants.php';
    ym_facebook_settings(TRUE);
    $pricing_data = get_option('ym_fbook_pricing');
    if ($_POST) {
        foreach ($settings as $setting) {
            $facebook_settings->{$setting} = $_POST[$setting];
        }
        // images
        foreach ($images as $image) {
            if (is_uploaded_file($_FILES[$image]['tmp_name'])) {
                $file = $_FILES[$image];
                $ym_upload = new ym_dl_file_upload();
                $ym_upload->upload_dir = $ym_upload_root;
                $ym_upload->max_length_filename = 100;
                $ym_upload->rename_file = false;
                $ym_upload->the_temp_file = $file['tmp_name'];
                $ym_upload->the_file = $file['name'];
                $ym_upload->http_error = $file['error'];
                $ym_upload->replace = "y";
                $ym_upload->do_filename_check = "n";
                if ($ym_upload->upload()) {
                    $filename = $ym_upload_url . $ym_upload->file_copy;
                    $facebook_settings->{$image} = $filename;
                } else {
                    ym_display_message(sprintf(__('unable to move file to %s', 'ym'), $ym_upload->upload_dir), 'error');
                }
            }
        }
        update_option('ym_fbook_options', $facebook_settings);
        echo '<div id="message" class="updated fade"><p>Settings were updated</p></div>';
        $packs = ym_get_packs();
        foreach ($packs as $pack) {
            $id = 'pack_' . $pack['id'];
            $post = 'override_price_' . $id;
            $price = ym_post($post);
            if ($price) {
                $price = number_format((double) $price, 0);
            }
            $pricing_data->{$id} = $price;
        }
        $query = 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key = \'ym_post_purchasable\' AND meta_value = 1';
        foreach ($wpdb->get_results($query) as $post) {
            $id = 'post_' . $post->post_id;
            $post = 'override_price_' . $id;
            $price = ym_post($post);
            if ($price) {
                $price = number_format((double) $price, 0);
            }
            $pricing_data->{$id} = $price;
        }
        $query = 'SELECT id, name FROM ' . $wpdb->prefix . 'ym_post_pack ORDER BY id ASC';
        foreach ($wpdb->get_results($query) as $bundle) {
            $id = 'bundle_' . $bundle->id;
            $post = 'override_price_' . $id;
            $price = ym_post($post);
            if ($price) {
                $price = number_format((double) $price, 0);
            }
            $pricing_data->{$id} = $price;
        }
        $price = ym_post('override_price_post_override');
        if ($price) {
            $price = number_format((double) $price, 0);
        }
        $pricing_data->post_override = $price;
        $price = ym_post('override_price_bundle_override');
        if ($price) {
            $price = number_format((double) $price, 0);
        }
        $pricing_data->bundle_override = $price;
        update_option('ym_fbook_pricing', $pricing_data);
        echo '<div id="message" class="updated fade"><p>Pricings were updated</p></div>';
    }
    echo '
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery(\'#ym_fbook_tabs\').tabs({
			fx: {opacity: \'toggle\'},
			selected: ' . ym_post('ym_fb_tab_select', ym_get('ym_fb_tab_select', 0)) . '
		});
		jQuery(\'.subtabs\').tabs({
			fx: {opacity: \'toggle\'}
		});
		jQuery(\'#tabkiller\').click(function() {
			jQuery(this).hide();
			jQuery(\'.subtabs\').slideUp(function() {
				jQuery(\'.subtabs\').tabs(\'destroy\');
				jQuery(\'.subtabs ul\').hide();
				jQuery(\'.subtabs\').slideDown();
			});
			jQuery(\'#ym_fbook_tabs\').slideUp(function() {
				jQuery(\'#ym_fbook_tabs\').tabs(\'destroy\');
				jQuery(\'#ym_fbook_tabs ul\').hide();
				jQuery(\'#transaction_logging\').hide();
				jQuery(\'#ym_fbook_tabs\').slideDown();
			});
		});
		jQuery(\'#ym_fb\').submit(function() {
			var selected = jQuery(\'#ym_fbook_tabs\').tabs(\'option\', \'selected\');
			jQuery(\'#ym_fb_tab_select\').val(selected);
		});
		jQuery(\'table\').after(\'<p class="submit" style="text-align: right;"><input type="submit" value="Save Settings" /></p>\');
	});
</script>
';
    echo '<div class="wrap" id="poststuff">';
    //	echo '<h2>YourMembers in Facebook | Settings</h2>';
    //	echo '<p style="text-align: right;"><a href="#nowhere" id="tabkiller">Remove Tabs/All Settings on a single page</a></p>';
    echo '<div id="ym_fbook_tabs">';
    echo '<form action="" method="post" enctype="multipart/form-=data" id="ym_fb">';
    $credits = FALSE;
    global $ym_active_modules;
    if (in_array('ym_facebook_credits', $ym_active_modules)) {
        //	if (get_option('ym_facebook_credits')) {
        $credits = TRUE;
    }
    echo '
<ul>
	<li><a href="#guide">Guide</a></li>
	<li><a href="#facebook_settings">Facebook</a></li>
	<li><a href="#settings_settings">Settings</a></li>
	<li><a href="';
    if ($credits) {
        echo '#facebook_credits';
    }
    echo '">Facebook Credits</a></li>
	<li><a href="';
    if ($credits) {
        echo '#facebook_pricing';
    }
    echo '">Facebook Pricing</a></li>
	<li><a href="#share_control">Like/Share</a></li>
	<li><a href="#open_graph">Open Graph</a></li>
	<li><a href="';
    if ($credits) {
        echo '#transaction_logging';
    }
    echo '">Transaction Log</a></li>
</ul>';
    echo '<div id="guide">';
    ym_box_top('Guide');
    echo '<div id="message" class="updated">';
    echo '<p>We have written a guide that should help you get Your Members Facebook Integration Up and Running, you can read it <a href="http://www.yourmembers.co.uk/the-support/guides-tutorials/your-members-facebook-integration/" target="_blank">here</a></p>';
    echo '</div>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="facebook_settings" class="subtabs">';
    echo '
<ul>
	<li><a href="#master_enable">Master Enable</a></li>
	<li><a href="#keys_settings">Application Keys</a></li>
	<li><a href="#canvas_settings">Canvas Settings</a></li>
	<li><a href="#page_settings">Page Settings</a></li>
	<li><a href="#dim_settings">Dimensions</a></li>
	<li><a href="#permissions">Permissions</a></li>
</ul>
';
    echo '<div id="master_enable">';
    ym_box_top('Enable Facebook');
    $review = '';
    if (!$facebook_settings->app_id) {
        $review .= '<div id="message" class="updated"><p>If you havn&#39;t created an app yet, you can do so <a href="http://developers.facebook.com/setup" target="_new">here</a></p></div>';
    }
    echo $review;
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('Enable Facebook', 'enabled', $facebook_settings->enabled, 'If not enabled if a users access the app, they are redirected to the site');
    echo '</table>';
    ym_box_bottom();
    echo '</div>
<div id="keys_settings">';
    ym_box_top('Application Keys');
    $review .= '<p>You can find and review these settings <a href="https://developers.facebook.com/apps/';
    if ($facebook_settings->app_id) {
        $review .= $facebook_settings->app_id;
    }
    $review .= '" target="_new">Here</a></p>';
    echo $review;
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_text_row('Facebook Application ID', 'app_id', $facebook_settings->app_id, 'The application ID');
    $ym_formgen->render_form_table_text_row('Facebook Application Secret', 'app_secret', $facebook_settings->app_secret, 'The application secret');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="canvas_settings">';
    ym_box_top('Canvas Settings');
    echo $review;
    echo '<table class="form-table">';
    echo '<tr><th>Facebook Canvas Name</th><td>http://apps.facebook.com/<input class="ym_input" type="text" name="canvas_url" id="canvas_url" value="' . $facebook_settings->canvas_url . '" /></td></tr>';
    echo '<tr><th>Facebook Canvas Landing</th><td>' . site_url('/') . '<input class="ym_input" type="text" name="canvas_landing" id="canvas_landing" value="' . $facebook_settings->canvas_landing . '" /></td></tr>';
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="page_settings">';
    ym_box_top('Page Settings');
    echo $review;
    echo '<p>If you have a (fan) page vanity url specified the app will do its best to stay in the (fan) page if the session starts on the (fan) page</p>';
    if ($facebook_settings->app_id) {
        echo '<p>You will have needed to have added your Application as a Tab to your Facebook Fan Page, you can do that <a href="http://www.facebook.com/apps/application.php?id=' . $facebook_settings->app_id . '">here</a> and then click <strong>Add to my Page</strong></p>';
    }
    echo '<table class="form-table">';
    echo '<tr><th>Facebook (fan) Page Vanity Url</th><td>http://www.facebook.com/<input class="ym_input" type="text" name="page_url" id="page_url" value="' . $facebook_settings->page_url . '" /></td></tr>';
    echo '<tr><th>Facebook Page Landing</th><td>' . site_url('/') . '<input class="ym_input" type="text" name="page_landing" id="page_landing" value="' . $facebook_settings->page_landing . '" /></td></tr>';
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="dim_settings">';
    ym_box_top('Dimension Settings');
    echo '<table class="form-table">';
    $ym_formgen->render_combo_from_array_row('IFrame Size', 'iframe_size', $iframe_options, $facebook_settings->iframe_size, 'Make sure this setting is set identical to the setting in Facebook Application settings');
    $ym_formgen->render_form_table_text_row('IFrame Height', 'iframe_size_height', $facebook_settings->iframe_size_height, 'If you are using Scrollbars you can specify the height you want here, in px');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="permissions">';
    ym_box_top('Permissions');
    echo '<table class="form-table">';
    echo '<tr><td></td><td style="width: 50px;"></td></tr>';
    $ym_formgen->render_form_table_radio_row('Likewalls - user_likes', 'permission_likewall', $facebook_settings->permission_likewall, 'If using likewalls, we need to extended permissions to get User Likes, as some users have their Likes set to Private');
    $ym_formgen->render_form_table_radio_row('Email Address - email', 'permission_email', $facebook_settings->permission_email, 'For the registration with Facebook you can enable this to pre fill the email entry with their Primary Facebook Email Address. Users will be asked to accept additional permissions.');
    $ym_formgen->render_form_table_radio_row('Offline Access - offline_access', 'permission_offline_access', $facebook_settings->permission_offline_access, 'Access Tokens are on average valid for about an hour. Which means once an hour we have to send the user thru a loop, normally this is transparent. However if you do not want this you can enable offline access to get a longer access key');
    $ym_formgen->render_form_table_radio_row('Offline Access - publish_actions', 'permission_publish_actions', $facebook_settings->permission_publish_actions, 'Part of the new Open Graph Actions');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '</div>';
    echo '<div id="settings_settings" class="subtabs">';
    echo '
<ul>
	<li><a href="#access_settings">Access Settings</a></li>
	<li><a href="#registration_settings">Registration Settings</a></li>
	<li><a href="#content_settings">Content Settings</a></li>
	<li><a href="#comment_settings">Comment Settings</a></li>
	<li><a href="#analytics_settings">Analytics Settings</a></li>
</ul>
';
    echo '<div id="access_settings">';
    ym_box_top('Access Settings');
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('Force Facebook', 'force_facebook', $facebook_settings->force_facebook, 'Make YM Facebook only, force users visting the Website to access via Facebook');
    $ym_formgen->render_form_table_radio_row('Force Application Add', 'force_facebook_auth', $facebook_settings->force_facebook_auth, 'Force a user to be logged into Facebook and authorised the Application');
    $ym_formgen->render_form_table_radio_row('Force WordPress Login', 'force_wordpress_auth', $facebook_settings->force_wordpress_auth, 'Force a user to be logged into WordPress');
    $ym_formgen->render_form_table_radio_row('Require Link', 'require_link', $facebook_settings->require_link, 'Require a User to link their Facebook and WordPress Accounts if Logged in (unless superseeded by above)');
    $ym_formgen->render_form_table_radio_row('Disable the Link Suggested Message', 'disable_link_message', $facebook_settings->disable_link_message, 'When a user is logged out do not prompt them to link/login');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="registration_settings">';
    ym_box_top('Registration Settings');
    echo '<p>Using Hidden Register? You might want to turn on the Email Permission on the Facebook->Permissions Tab</p>';
    echo '<table class="form-table">';
    //	$ym_formgen->render_form_table_radio_row('Register with Facebook', 'register_with_facebook', $facebook_settings->register_with_facebook, 'Allow a user to register a WordPress accout using their Facebook Account as a Base');
    $ym_formgen->render_form_table_radio_row('Hidden Register with Facebook', 'register_with_facebook_hidden', $facebook_settings->register_with_facebook_hidden, 'If a User uses the Facebook App and are not logged into WordPress create them a WordPress Account. If they are found by their username or email address, the two accounts are Auto Linked. (Implies Require Link and Force Redirect)');
    //	$ym_formgen->render_form_table_radio_row('Email Address', 'permission_emailb', $facebook_settings->permission_email, 'For the registration with Facebook you can enable this to pre fill the email entry with their Primary Facebook Email Address. Users will be asked to accept additional permissions.');
    $packs = ym_get_packs();
    $ym_packs = array();
    $ym_packs[0] = 'No Account';
    foreach ($packs as $pack) {
        $ym_packs[$pack['id']] = ym_get_pack_label($pack['id']);
    }
    $ym_formgen->render_combo_from_array_row('Hidden Register Subscription', 'register_with_facebook_hidden_subid', $ym_packs, $facebook_settings->register_with_facebook_hidden_subid, 'Which Subscription To Put a Hidden Regsiter User on. It will <strong>not</strong> prompt for Payment');
    $ym_formgen->render_form_table_text_row('Hidden Register Redirect', 'register_with_facebook_hidden_redirect', $facebook_settings->register_with_facebook_hidden_redirect, 'On Hidden Register Complete Redirect the users to a page');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="content_settings">';
    ym_box_top('Content Settings');
    echo '<p>fb.php status is: ';
    $result = locate_template('fb.php');
    if (empty($result)) {
        echo 'Not Present';
    } else {
        echo 'Present';
    }
    echo '</p>';
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('fb.php', 'enable_fb_php', $facebook_settings->enable_fb_php, 'Enable the use of the Theme File fb.php instead of YM FB Theme, if fb.php is present');
    echo '</table>';
    echo '<p>If you use a theme fb.php file, most of these options are redundant, unless you implement them in your Theme File</p>';
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('Allow Leave Facebook', 'enable_leave_facebook', $facebook_settings->enable_leave_facebook, 'Allow a user to start a website session from inside facebook, if a user vists the blog on Facebook first, they will stay inside Facebook, (is overriden by force facebook)');
    $ym_formgen->render_form_table_radio_row('Post Breakout', 'post_breakout', $facebook_settings->post_breakout, 'when viewing the end post, breakout (overrides Force Facebook)');
    $ym_formgen->render_form_table_radio_row('Page Breakout', 'page_breakout', $facebook_settings->page_breakout, 'when viewing the end page, breakout (overrides Force Facebook)');
    $ym_formgen->render_form_table_radio_row('Use excerpt', 'use_excerpt', $facebook_settings->use_excerpt, 'Use excerpts on post pages? (Template dependant)');
    $menus = array('Auto', 'Slug');
    $query = 'SELECT name FROM ' . $wpdb->prefix . 'term_taxonomy tt LEFT JOIN ' . $wpdb->prefix . 'terms t ON t.term_id = tt.term_id WHERE taxonomy = \'nav_menu\'';
    foreach ($wpdb->get_results($query) as $row) {
        $menus[] = $row->name;
    }
    $ym_formgen->render_combo_from_array_row('Menu Control', 'menu', $menus, $facebook_settings->menu, 'We can use the First non blank menu, or you can pick your own. Menus are controlled <a href="' . site_url('/wp-admin/nav-menus.php') . '">here</a>');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="comment_settings">';
    ym_box_top('Comment Settings');
    echo '<p>You can replace the standard comment form with a Facebook Powered comment form</p>';
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('Use Facebook Comments on Facebook', 'use_facebook_comments', $facebook_settings->use_facebook_comments);
    $ym_formgen->render_form_table_radio_row('Use Facebook Comments on the Site', 'use_facebook_comments_on_site', $facebook_settings->use_facebook_comments_on_site);
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="analytics_settings">';
    ym_box_top('Analytics');
    echo '<p>You need to set the Website URL of the Profile to <strong>' . site_url('?ymfbook=googleanalytics') . '</strong> in order for Check Status to succeed</p>';
    echo '<p>Its recommended you use a separate profile under the same domain to track the Facebook Application</p>';
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_text_row('Google Analytics Profile ID', 'google_analytics_profile_id', $facebook_settings->google_analytics_profile_id, 'Uses the Standard code with this ID');
    $ym_formgen->render_form_table_textarea_row('Tracking Code', 'analytics_tracking_code', $facebook_settings->analytics_tracking_code, 'This will override the standard Google Analytics Code');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '</div>';
    if ($credits) {
        echo '<div id="facebook_credits">';
        ym_box_top(__('Facebook Credits', 'ym_facebook'));
        echo __('<p>Facebook Credits can only be used inside Facebook</p>', 'ym_facebook');
        echo sprintf(__('<p>You will need a Credits Callback URL, please use this: <strong>%s</strong></p>', 'ym_facebook'), site_url('?ym_process=ym_facebook_credits'));
        ym_box_bottom();
        ym_box_top(__('Primary Button', 'ym_facebook'));
        echo __('<p>In line with the Facebook Credits branding guide, you have a choice of three Pay with Facebook Credits Icons</p>', 'ym_facebook');
        $select = $facebook_settings->logo;
        echo '<table class="form-table">';
        echo '<tr><th>' . __('Option A', 'ym_facebook') . '</th>
			<td>
				<input type="radio" name="logo" id="logoa" value="' . YM_IMAGES_DIR_URL . 'pg/facebook_credits_a.png" ' . ($select == YM_IMAGES_DIR_URL . 'pg/facebook_credits_a.png' ? 'checked="checked"' : '') . ' />
				<label for="logoa">
					<img src="' . YM_IMAGES_DIR_URL . 'pg/facebook_credits_a.png" />
				</label>
			</td>
		</tr>';
        echo '<tr><th>' . __('Option B', 'ym_facebook') . '</th>
			<td>
				<input type="radio" name="logo" id="logob" value="' . YM_IMAGES_DIR_URL . 'pg/facebook_credits_b.png" ' . ($select == YM_IMAGES_DIR_URL . 'pg/facebook_credits_b.png' ? 'checked="checked"' : '') . ' />
				<label for="logob">
					<img src="' . YM_IMAGES_DIR_URL . 'pg/facebook_credits_b.png" />
				</label>
			</td>
		</tr>';
        echo '<tr><th>' . __('Option C', 'ym_facebook') . '</th>
			<td>
				<input type="radio" name="logo" id="logoc" value="' . YM_IMAGES_DIR_URL . 'pg/facebook_credits_c.png" ' . ($select == YM_IMAGES_DIR_URL . 'pg/facebook_credits_c.png' ? 'checked="checked"' : '') . ' />
				<label for="logoc">
					<img src="' . YM_IMAGES_DIR_URL . 'pg/facebook_credits_c.png" />
				</label>
			</td>
		</tr>';
        echo '</table>';
        ym_box_bottom();
        ym_box_top(__('Credits Dialog Images', 'ym_facebook'));
        echo __('<p>When purchasing a item users are shown a title, description, cost and a icon/logo. You can crontol these logos here</p>', 'ym_facebook');
        echo '<table class="form-table">';
        echo '
		<tr>
			<th>' . __('Subscription Purchase Image', 'ym_facebook') . '</th>
			<td>
				<input type="file" name="credits_purchase_sub_image" id="credits_purchase_sub_image" />';
        if ($facebook_settings->credits_purchase_sub_image) {
            echo '<div style="margin-top: 5px;"><img src="' . $facebook_settings->credits_purchase_sub_image . '" alt="' . __('Subscription Purchase Image', 'ym_facebook') . '" /></div>';
        }
        echo '
			</td>
		</tr>
		<tr>
			<th>' . __('Post Purchase Image', 'ym_facebook') . '</th>
			<td>
				<input type="file" name="credits_purchase_post_image" id="credits_purchase_post_image" />';
        if ($facebook_settings->credits_purchase_post_image) {
            echo '<div style="margin-top: 5px;"><img src="' . $facebook_settings->credits_purchase_post_image . '" alt="' . __('Post Purchase Image', 'ym_facebook') . '" /></div>';
        }
        echo '
			</td>
		</tr>
		<tr>
			<th>' . __('Bundle Purchase Image', 'ym_facebook') . '</th>
			<td>
				<input type="file" name="credits_purchase_bundle_image" id="credits_purchase_bundle_image" />';
        if ($facebook_settings->credits_purchase_bundle_image) {
            echo '<div style="margin-top: 5px;"><img src="' . $facebook_settings->credits_purchase_bundle_image . '" alt="' . __('Bundle Purchase Image', 'ym_facebook') . '" /></div>';
        }
        echo '
			</td>
		</tr>
		';
        echo '</table>';
        ym_box_bottom();
        ym_box_top(__('Other Settings', 'ym_facebook'));
        echo '<table class="form-table">';
        $ym_formgen->render_form_table_radio_row('Exclusive Facebook Credits', 'credits_exclusive', $facebook_settings->credits_exclusive, 'Use only Facebook Credits when inside Facebook');
        echo '<tr><td></td><td><p>';
        echo 'Facebook takes a 30% fee on all transactions.<br />' . 'For Transactions in non USD Facebook pays out based on:<br />' . 'Each Facebook Credit is $0.10 and then converts this into your native currency based on that days exchange rate<br />' . 'So 10 Credits is $1 and 100 is $10<br />' . 'Transactions can only occur in whole credits, so if any math involved results in a decimal prices will be rounded up<br />' . 'Costs can only be in Whole Credits';
        global $ym_res;
        if ($ym_res->currency != 'USD') {
            echo '<br /><br />So you can either specify an exchange rate, or set a Facebook credits price per item on the Facebook Pricing Tab';
            echo '</p></td></tr>';
            $ym_formgen->render_form_table_text_row('Specify a Exchange Rate', 'exchange_rate', $facebook_settings->exchange_rate, 'If you specify an exchange rate, it will be used. Its the Exchange rate for your Currency to USD');
        } else {
            echo '<br /><br />You are using USD, so you do not need to worry about an exchange rate, but you can still set a Facebook credits price per item on the Facebook Pricing Tab';
            echo '</p></td></tr>';
        }
        $ym_formgen->render_combo_from_array_row('Rounding', 'exchange_round', $round_options, $facebook_settings->exchange_round, 'You can control the rounding method if any');
        echo '</table>';
        ym_box_bottom();
        echo '</div>';
        echo '<div id="facebook_pricing" class="subtabs">';
        echo '
<ul>
	<li><a href="#pack_pricing">Pack</a></li>
	<li><a href="#post_pricing">Post</a></li>
	<li><a href="#bundle_pricing">Bundle</a></li>
</ul>
';
        echo '<div id="pack_pricing">';
        ym_box_top('Pack Pricing');
        echo '<p>Remember: 1 Credit is USD 0.10 and pricing is in whole credits, if a override price is set Exchange Rates and Rouding is ignored</p>';
        echo '<table class="form-table">';
        $pricing_data = get_option('ym_fbook_pricing');
        // subs
        $packs = ym_get_packs();
        foreach ($packs as $pack) {
            $id = 'pack_' . $pack['id'];
            $ym_formgen->render_form_table_text_row('Pack Price: ' . ym_get_pack_label($pack['id']), 'override_price_' . $id, $pricing_data->{$id});
        }
        echo '</table>';
        ym_box_bottom();
        echo '</div>';
        echo '<div id="post_pricing">';
        ym_box_top('Post Pricing');
        echo '<p>Remember: 1 Credit is USD 0.10 and pricing is in whole credits, if a override price is set Exchange Rates and Rouding is ignored</p>';
        echo '<table class="form-table">';
        $query = 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key = \'ym_post_purchasable\' AND meta_value = 1';
        foreach ($wpdb->get_results($query) as $post) {
            $id = 'post_' . $post->post_id;
            $postdata = get_post($post);
            $ym_formgen->render_form_table_text_row('Post Price: ' . $postdata->post_title, 'override_price_' . $id, $pricing_data->{$id});
        }
        if (!$wpdb->num_rows) {
            echo '<tr><td></td><th>No Available Posts</th></tr>';
        }
        $ym_formgen->render_form_table_text_row('Default Override Pack Price', 'override_price_post_override', $pricing_data->post_override, 'You can set a default price to override if one is not set');
        echo '</table>';
        ym_box_bottom();
        echo '</div>';
        echo '<div id="bundle_pricing">';
        ym_box_top('Bundle Pricing');
        echo '<p>Remember: 1 Credit is USD 0.10 and pricing is in whole credits, if a override price is set Exchange Rates and Rouding is ignored</p>';
        echo '<table class="form-table">';
        $query = 'SELECT id, name FROM ' . $wpdb->prefix . 'ym_post_pack ORDER BY id ASC';
        foreach ($wpdb->get_results($query) as $bundle) {
            $id = 'bundle_' . $bundle->id;
            $ym_formgen->render_form_table_text_row('Bundle Price: ' . $bundle->name, 'override_price_' . $id, $pricing_data->{$id});
        }
        if (!$wpdb->num_rows) {
            echo '<tr><td></td><th>No Available Bundles</th></tr>';
        }
        $ym_formgen->render_form_table_text_row('Default Override Bundle Price', 'override_price_bundle_override', $pricing_data->bundle_override, 'You can set a default price to override if one is not set');
        echo '</table>';
        ym_box_bottom();
        echo '</div>';
        echo '</div>';
    }
    echo '<div id="share_control" class="subtabs">';
    echo '
<ul>
	<li><a href="#post_control">Post Like/Share</a></li>
	<li><a href="#footer_control">Footer Like/Share</a></li>
	<li><a href="#shortcode_control">Shortcode Like/Share</a></li>
	<li><a href="#likewall_control">Likewall Like/Share</a></li>
</ul>
';
    echo '<div id="post_control">';
    ym_box_top('Post Share Control');
    echo '<p>This are the options for adding Share/Send buttons to Posts/Pages</p>';
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('Enable Facebook Share', 'enable_share', $facebook_settings->enable_share, 'Allow people to share content to Facebook Feeds from within the App');
    $ym_formgen->render_form_table_radio_row('Enable Facebook Send', 'enable_send', $facebook_settings->enable_send, 'Allow people to share content via PM (needs Share to be on)');
    $ym_formgen->render_combo_from_array_row('Share Box to Use', 'share_box', $sharebox_options, $facebook_settings->share_box);
    $ym_formgen->render_form_table_radio_row('Show faces', 'show_faces', $facebook_settings->show_faces, 'Show the faces of Friend who have shared the same link');
    $ym_formgen->render_combo_from_array_row('Verb to Use', 'verb', $verbs, $facebook_settings->verb);
    $ym_formgen->render_combo_from_array_row('Color Scheme', 'color_scheme', $color_schemes, $facebook_settings->color_scheme);
    $ym_formgen->render_combo_from_array_row('Font', 'font', $fonts, $facebook_settings->font, 'The Font to use for the Buttons');
    //	$ym_formgen->render_form_table_text_row('Add a Ref', 'ref', $facebook_settings->ref, 'A reference for tracking');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="footer_control">';
    ym_box_top('Footer Share Control');
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('Enable Facebook Share Footer', 'enable_share_footer', $facebook_settings->enable_share_footer, 'Add a Share button for the whole site in the footer');
    $ym_formgen->render_form_table_radio_row('Enable Facebook Send Footer', 'enable_send_footer', $facebook_settings->enable_send_footer, 'Allow people to share content via PM (needs Share to be on)');
    $ym_formgen->render_combo_from_array_row('Share Box to Use', 'share_box_footer', $sharebox_options, $facebook_settings->share_box_footer);
    $ym_formgen->render_form_table_radio_row('Show faces', 'show_faces_footer', $facebook_settings->show_faces_footer, 'Show the faces of Friend who have shared the same link');
    $ym_formgen->render_combo_from_array_row('Verb to Use', 'verb_footer', $verbs, $facebook_settings->verb_footer);
    $ym_formgen->render_combo_from_array_row('Color Scheme', 'color_scheme_footer', $color_schemes, $facebook_settings->color_scheme_footer);
    $ym_formgen->render_combo_from_array_row('Font', 'font_footer', $fonts, $facebook_settings->font_footer, 'The Font to use for the Buttons');
    //	$ym_formgen->render_form_table_text_row('Add a Ref', 'ref_footer', $facebook_settings->ref_footer, 'A reference for tracking');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="shortcode_control">';
    ym_box_top('Shortcode Share Control');
    echo '<p>You can use the shortcode [ym_fb_like]</p>';
    echo '<p>You can specify a shareurl to use, if not the post permalink will be used</p>';
    //	echo '<p>You can specify a type to use, if not the "post" tab settings will be used, specify "shortcode" to use the below settings, or "footer" to use the footer tab settings</p>';
    echo '<table class="form-table">';
    $ym_formgen->render_form_table_radio_row('Enable Facebook Share Shortcode', 'enable_share_shortcode', $facebook_settings->enable_share_shortcode);
    $ym_formgen->render_form_table_radio_row('Auto Add to the bottom of posts on non Facebook Pages', 'enable_share_auto_nonfb', $facebook_settings->enable_share_auto_nonfb, 'Add a Share button to the bottom of all posts on non Facebook Framed Pages');
    $ym_formgen->render_form_table_radio_row('Enable Facebook Send Shortcode', 'enable_send_shortcode', $facebook_settings->enable_send_shortcode, 'Allow people to share content via PM (needs Share to be on)');
    $ym_formgen->render_combo_from_array_row('Share Box to Use', 'share_box_shortcode', $sharebox_options, $facebook_settings->share_box_shortcode);
    $ym_formgen->render_form_table_radio_row('Show faces', 'show_faces_shortcode', $facebook_settings->show_faces_shortcode, 'Show the faces of Friend who have shared the same link');
    $ym_formgen->render_combo_from_array_row('Verb to Use', 'verb_shortcode', $verbs, $facebook_settings->verb_shortcode);
    $ym_formgen->render_combo_from_array_row('Color Scheme', 'color_scheme_shortcode', $color_schemes, $facebook_settings->color_scheme_shortcode);
    $ym_formgen->render_combo_from_array_row('Font', 'font_shortcode', $fonts, $facebook_settings->font_shortcode, 'The Font to use for the Buttons');
    //	$ym_formgen->render_form_table_text_row('Add a Ref', 'ref_shortcode', $facebook_settings->ref_shortcode, 'A reference for tracking');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<div id="likewall_control">';
    ym_box_top('Likewall Share Control');
    echo '<table class="form-table">';
    //		$ym_formgen->render_form_table_radio_row('Enable Facebook Share LikeWall', 'enable_share_likewall', $facebook_settings->enable_share_likewall, 'Add a Share button for the whole site in the likewall');
    //		$ym_formgen->render_form_table_radio_row('Enable Facebook Send LikeWall', 'enable_send_likewall', $facebook_settings->enable_send_likewall, 'Allow people to share content via PM (needs Share to be on)');
    $ym_formgen->render_combo_from_array_row('Share Box to Use', 'share_box_likewall', $sharebox_options, $facebook_settings->share_box_likewall);
    $ym_formgen->render_form_table_radio_row('Show faces', 'show_faces_likewall', $facebook_settings->show_faces_likewall, 'Show the faces of Friend who have shared the same link');
    $ym_formgen->render_combo_from_array_row('Verb to Use', 'verb_likewall', $verbs, $facebook_settings->verb_likewall);
    $ym_formgen->render_combo_from_array_row('Color Scheme', 'color_scheme_likewall', $color_schemes, $facebook_settings->color_scheme_likewall);
    $ym_formgen->render_combo_from_array_row('Font', 'font_likewall', $fonts, $facebook_settings->font_likewall, 'The Font to use for the Buttons');
    //	$ym_formgen->render_form_table_text_row('Add a Ref', 'ref_likewall', $facebook_settings->ref_likewall, 'A reference for tracking');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '</div>';
    echo '<div id="open_graph">';
    ym_box_top('Open Graph Options');
    echo '<table class="form-table">';
    echo '
	<tr>
		<th>Open Graph Image
			<div style="color: gray; margin-top: 5px; font-size: 11px;">This image is used when a user links/shares content from your site.</div>
		</th>
		<td>
			<input type="file" name="open_graph_image" id="open_graph_image" />';
    if ($facebook_settings->open_graph_image) {
        echo '<div style="margin-top: 5px;"><img src="' . $facebook_settings->open_graph_image . '" alt="Open Graph Image" /></div>';
    }
    echo '
		</td>
	</tr>
	';
    $ym_formgen->render_combo_from_array_row('Default Open Graph Type', 'open_graph_type', $types, $facebook_settings->open_graph_type);
    $ym_formgen->render_form_table_text_row('Admin Ids', 'open_graph_admins', $facebook_settings->open_graph_admins, 'Users who should be linked/denoted as admins for your YM in Facebook, comma separated');
    echo '</table>';
    ym_box_bottom();
    echo '</div>';
    echo '<input type="hidden" name="ym_fb_tab_select" id="ym_fb_tab_select" value="0" />';
    echo '</form>';
    if ($credits) {
        // facebook credits appears to be enabled in YM
        echo '<div id="transaction_logging">';
        ym_box_top('Facebook Credits Transaction Logging');
        include YM_FBOOK_BASE_DIR . 'admin/ym_facebook_transaction_log.php';
        ym_box_bottom();
        echo '</div>';
    }
    echo '</div>';
    echo '</div>';
}
Exemple #12
0
function ym_upgrade_buttons($return = false, $pack_id = false, $user_id = false)
{
    global $wpdb, $duration_str, $current_user, $ym_res, $ym_sys, $ym_packs;
    get_currentuserinfo();
    if (!$user_id) {
        $user_id = $current_user->ID;
    }
    if ($pack_id == 'all') {
        global $ym_packs;
        $html = '';
        foreach ($ym_packs->packs as $pack) {
            if (!$pack['hide_subscription']) {
                $html .= ym_upgrade_buttons(TRUE, $pack['id']);
            }
        }
        if ($return) {
            return $html;
        } else {
            echo $html;
            return;
        }
    }
    $html = '';
    $ym_home = get_option('siteurl');
    if (!$user_id) {
        $html = $ym_res->msg_header . __('Sorry but you must be logged in to upgrade your account', 'ym') . $ym_res->msg_footer;
    } else {
        $user_data = new YourMember_User($user_id);
        $account_type = ym_get_user_account_type(false, true);
        $packs = $ym_packs->packs;
        $trial_taken = get_user_meta($user_id, 'ym_trial_taken', TRUE);
        $active_modules = get_option('ym_modules');
        $modules_dir = YM_MODULES_DIR;
        $base = add_query_arg(array('ym_subscribe' => 1, 'ud' => 1, 'username' => $current_user->user_login), $ym_home);
        if ((!isset($_POST['submit']) || !isset($_POST['subs_opt'])) && !$pack_id) {
            // TODO: Does this code even run?
            $html = '<p class="message register">' . __('Choose an Account Type', 'ym') . '</p>';
            $html .= '<form action="" method="post" class="ym"><div style="clear: both; overflow: auto; padding-bottom: 10px;">';
            // RENDER2
            $packs_shown = 0;
            if ($existing_data = ym_request('ym_subscription')) {
                $default = $existing_data;
            } else {
                //				$default = ym_get_default_pack();
                $default = $user_data->pack_id;
            }
            $did_checked = FALSE;
            foreach ($packs as $pack) {
                if (!$pack['hide_subscription']) {
                    $html .= '<div class="ym_register_form_subs_row">
								<div class="ym_reg_form_pack_radio">
									<input type="radio" ';
                    if ($pack['id'] == $default && !$did_checked) {
                        $html .= 'checked="checked"';
                        $did_checked = TRUE;
                    }
                    $packs_shown++;
                    $html .= ' class="checkbox" id="ym_subscription_' . $pack['id'] . '" name="ym_subscription" value="' . $pack['id'] . '" />
							</div>
							<label for="ym_subscription_' . $pack['id'] . '" class="ym_subs_opt_label ym_reg_form_pack_name">' . ym_get_pack_label($pack['id']) . '</label>
						</div>';
                }
            }
            if (!$packs_shown) {
                $hide_label = true;
            } else {
                if (isset($entry['caption']) && $entry['caption']) {
                    $html .= '<div class="ym_clear">&nbsp;</div><div class="ym_register_form_caption">' . $entry['caption'] . '</div>' . $row;
                }
            }
            // END RENDER2
            if ($packs_shown) {
                //				$html .= '</div><input type="hidden" name="ref" value="'. md5($user_data->amount .'_'. $user_data->duration .'_'. $user_data->duration_type .'_'. $user_data->account_type) .'" />';
                $html .= '<p class="submit"><input type="submit" name="submit" value="' . __('Next &raquo;', 'ym') . '" /></p>';
            } else {
                $html .= '<p>' . __('Sorry there are currently no upgrade/downgrade options available to you.', 'ym') . '</p>';
            }
            $html .= '</form>';
        } else {
            if (!ym_post('subs_opt') && $pack_id != ym_post('ym_subscription')) {
                global $ym_res;
                $html = '<form action="" method="post" class="ym_upgrade_shortcode">';
                $html .= '<input type="hidden" name="ym_subscription" value="' . $pack_id . '" />';
                //				$html .= '<input type="hidden" name="ref" value="'. md5($user_data->amount .'_'. $user_data->duration .'_'. $user_data->duration_type .'_'. $user_data->account_type) .'" />';
                $html .= ym_get_pack_label($pack_id);
                $html .= '&nbsp;<a href="#nowhere" onClick="jQuery(this).parents(\'form\').submit();">Upgrade</a>';
                $html .= '</form>';
                return $html;
            } else {
                $pack = ym_get_pack_by_id($pack_id);
                $cost = $pack['cost'];
                if (!$pack_id) {
                    $html .= '<br /><table width="100%" cellpadding="3" cellspacing="0" border="0" align="center" class="form-table">';
                    if ($cost == 0 || $account_type == 'free') {
                        $html .= '<tr><th>' . __('Create a free account: ', 'ym') . ucwords($account_type) . '</th></tr>';
                    } else {
                        $html .= '<tr><th>' . __('Select Payment Gateway', 'ym') . '</th></tr>';
                        $html .= '<tr><th>' . ym_get_pack_label($pack['id']) . '</th></tr>';
                    }
                }
                if (count($active_modules)) {
                    $buttons_shown = array();
                    foreach ($active_modules as $module) {
                        if ($module == 'ym_free' && $pack['cost'] > 0) {
                            continue;
                        }
                        require_once $modules_dir . $module . '.php';
                        $obj = new $module();
                        $string = $obj->getButton($pack['id']);
                        if ($string) {
                            $buttons_shown[] = $module;
                            $html .= $string;
                        }
                        $string = false;
                        $obj = null;
                    }
                    if (count($buttons_shown) == 1) {
                        $module = array_pop($buttons_shown);
                        $form_code = '<div style="display:none;">' . $html . '</div>';
                        $js = 'document.forms["' . $module . '_form"].submit();';
                        $html = '  <html>
													<head>
														<title>Redirecting...</title>
														<script type="text/javascript">
															function load() {
																' . $js . '
															}
														</script>
													</head>
													<body onload="load();">';
                        $html .= '  <div style="color: #333333; font-size: 14px; margin: 30px 10px; font-family: tahoma; text-align: center; padding: 50px; border: 1px solid silver;">';
                        $html .= '  <div>' . __('You are being redirected. If this page does not refresh in 5 seconds then click', 'ym') . ' <a onclick="document.forms[\'' . $module . '_form\'].submit();">here</a>.</div>
											   <div style="margin-top: 10px;"><img alt="" src="' . YM_IMAGES_DIR_URL . 'loading.gif" /></div>';
                        $html .= '  </div>';
                        $html .= $form_code;
                        $html .= '	  </body>
												</html>';
                        echo $html;
                        die;
                    }
                } else {
                    $html .= __('There are no gateways available at this time.', 'ym');
                }
            }
        }
    }
    if ($return) {
        return $html;
    } else {
        echo $html;
    }
}
Exemple #13
0
 private function sync_packages($plan_id = FALSE)
 {
     if ($plan_id) {
         list($buy, $sub, $pack_id) = explode('_', $plan_id);
         $packages = array(ym_get_pack_by_id($pack_id));
     } else {
         global $ym_packs;
         $packages = $this->pack_filter($ym_packs->packs);
     }
     $r = TRUE;
     foreach ($packages as $pack) {
         $plan_id = 'buy_subscription_' . $pack['id'];
         if (strtolower($pack['duration_type']) == 'm') {
             $dt = 'month';
         } else {
             $dt = 'year';
         }
         list($r_code, $response) = $this->stripe_api_request('plans/' . $plan_id);
         $plan = array('id' => $plan_id, 'amount' => $pack['cost'] * 100, 'currency' => 'usd', 'interval' => $dt, 'name' => ym_get_pack_label($pack['id'], false, false));
         if ($pack['trial_on']) {
             // add free trial
             // not free causes additional charge on plan sub
             $days = 0;
             if ($pack['trial_duration_type'] == 'd') {
                 $days = $pack['trial_duration'];
             } else {
                 if ($pack['trial_duration_type'] == 'm') {
                     $days = $pack['trial_duration'] * 28;
                 } else {
                     $days = $pack['trial_duration'] * 365;
                 }
             }
             $plan['trial_period_days'] = $days;
         }
         if ($r_code == 404) {
             // create
             list($r_code, $response) = $this->stripe_api_request('plans', 'POST', $plan);
             if ($r_code != 200) {
                 $r = FALSE;
             }
         } else {
             if ($r_code == 200) {
                 // update?
                 $call_update = FALSE;
                 foreach ($plan as $key => $value) {
                     if ($response->{$key} != $value) {
                         $call_update = TRUE;
                     }
                 }
                 if ($call_update) {
                     // delete recreate
                     list($r_code, $response) = $this->stripe_api_request('plans/' . $plan_id, 'DELETE');
                     if ($r_code != 200) {
                         $r = FALSE;
                     } else {
                         list($r_code, $response) = $this->stripe_api_request('plans', 'POST', $plan);
                         if ($r_code != 200) {
                             $r = FALSE;
                         }
                     }
                 }
             } else {
                 $r = FALSE;
             }
         }
     }
     return $r;
 }
    /**
    Overrides
    */
    function getButtonOverride($pack, $user_id, $override_price = false)
    {
        $button_code = $this->get_button_code($pack, $user_id, $override_price);
        $button_code = apply_filters('ym_additional_code', $button_code, $this->code, $button_code['item_number']);
        $this->_braintree();
        global $current_user;
        get_currentuserinfo();
        if ($current_user->ID) {
            $user_id = $current_user->ID;
        } else {
            $current_user = get_user_by('login', ym_request('username'));
            if ($current_user->ID) {
                $user_id = $current_user->ID;
            } else {
                echo 'bugger';
                return;
            }
        }
        $customer_id = get_user_meta($user_id, 'ym_braintree_customer_id', true);
        if ($customer_id) {
            // validate the customer is still in braintree
            try {
                $customer = Braintree_Customer::find($customer_id);
            } catch (Exception $e) {
                $customer_id = false;
            }
        }
        if (!$customer_id) {
            // create required
            // shunt the customer into braintree
            $result = Braintree_Customer::create(array('id' => 'ym_' . $current_user->ID, 'email' => $current_user->user_email));
            if ($result->success) {
                $customer_id = $result->customer->id;
                update_user_meta($user_id, 'ym_braintree_customer_id', $customer_id);
            } else {
                echo 'bugger';
                return;
            }
        }
        $r = '';
        $passed = ym_request('code');
        if ($button_code['item_number'] == $passed) {
            $error = ym_request('errormessage');
            if ($error) {
                $r .= '<div class="error"><p>' . $error . '</p></div>';
            }
        }
        // has credit card??
        // get token and update that token?!
        // credit card form driver
        $trData = Braintree_TransparentRedirect::updateCustomerData(array('redirectUrl' => site_url('?ym_process=' . $this->code . '&action=process&code=' . $button_code['item_number']), 'customerId' => $customer_id));
        $r .= '
<form action="' . $this->action_url . '" method="post" class="ym_form ' . $this->code . '_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
	<fieldset>
		';
        if (isset($pack['id'])) {
            $r .= '<strong>' . ym_get_pack_label($pack['id']) . '</strong><br />';
        }
        if ($override_price) {
            $r .= '<br />' . $override_price . ' ' . ym_get_currency() . ' ' . __('First Period', 'ym');
        }
        $key = 'customer';
        global $ym_braintree_magic_number;
        $ym_braintree_magic_number++;
        $r .= '
		<input type="image" class="' . $this->code . '_button" src="' . $this->logo . '" border="0" name="submit" alt="' . $this->membership_words . '" class="ym_braintree_button" data-unique="' . $ym_braintree_magic_number . '" />
	</fieldset>
</form>
<form action="' . Braintree_TransparentRedirect::url() . '" method="post" id="' . $this->code . '_cc_form_unique_' . $ym_braintree_magic_number . '" class="' . $this->code . '_cc_form" style="display: none;" autocomplete="off">
	<input type="hidden" name="tr_data" value="' . htmlentities($trData) . '" />
	<input type="hidden" name="code" value="' . $button_code['item_number'] . '" />
	<div>
		<label for="braintree_credit_card_number">' . __('Credit Card Number', 'ym') . '</label>
		<input type="text" name="' . $key . '[credit_card][number]" id="braintree_credit_card_number" value=""></input>

		<label for="braintree_credit_card_ccv">' . __('Credit Card CCV', 'ym') . '</label>
		<input type="text" name="' . $key . '[credit_card][cvv]" id="braintree_credit_card_ccv" value=""></input>

		<label for="braintree_credit_card_exp">' . __('Credit Card Expiry (mm/yyyy)', 'ym') . '</label>
		<input type="text" size="7" maxlength="7" name="' . $key . '[credit_card][expiration_date]" id="braintree_credit_card_exp" value=""></input>
	</div>
	<input class="submit-button" type="submit" />
	<span class="ym_braintree_icon">&nbsp;&nbsp;&nbsp;&nbsp;</span>
</form>
    	';
        return $r;
    }
';
    $ym_formgen->render_form_table_email_row(__('Email Address', 'ym'), 'email_address');
    $ym_formgen->render_form_table_text_row(__('Username', 'ym'), 'username', '', __('Leave blank to use the email address', 'ym'));
    $ym_formgen->render_form_table_password_row(__('Password', 'ym'), 'password', '', __('Leave blank to auto generate', 'ym'));
    $ym_formgen->render_form_table_password_row(__('Confirm Password', 'ym'), 'c_password');
    if (count($package_type_options)) {
        array_unshift($package_type_options, __('Select', 'ym'));
        $ym_formgen->render_combo_from_array_row(__('Package Type', 'ym'), 'package_type', $package_type_options);
    }
    $options = array();
    // package
    if (count($ym_user->child_accounts_packages)) {
        foreach ($ym_user->child_accounts_packages as $id) {
            $pack = ym_get_pack_by_id($id);
            if ($current_counts[$pack['account_type']] < $allowed_counts[$pack['account_type']]) {
                $options[$id] = ym_get_pack_label($id);
            }
        }
    }
    if (count($options)) {
        $options[0] = __('Select', 'ym');
        ksort($options);
        $label = __('Apply A Package', 'ym');
        if (count($ym_user->child_accounts_packages)) {
            $label = __('Or', 'ym') . ' ' . $label;
        }
        $ym_formgen->render_combo_from_array_row($label, 'package', $options);
    }
    echo '<tr><td colspan="2"><p class="submit"><input type="submit" class="button-primary alignright" value="' . __('Create', 'ym') . '" /></p></td></tr>';
    echo '</table></form></td></tr>';
}
function ym_register_flow($flow_id, $pack_id = false, $widget = false)
{
    global $current_page, $next_page, $the_flow_id, $wpdb, $ym_res, $ym_sys;
    global $post_data, $pack_data;
    $html = $form_top = '';
    $payment_gateway_detected = false;
    if (!is_singular() && !$widget) {
        return __('A Register Flow Error Occurred (Type 0) Not on a Flow Page', 'ym');
    }
    if (!$flow_id) {
        return __('A Register Flow Error Occurred (Type 1) No Flow Selected', 'ym');
    }
    if (ym_post('flowcomplete')) {
        // complete
        $query = 'SELECT complete_text FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id;
        $complete_text = $wpdb->get_var($query);
        if ($complete_text) {
            return '<p>' . $complete_text . '</p>';
        } else {
            return '<p>' . __('Registration/Upgrade is complete', 'ym') . '</p>';
        }
    }
    $flow_pages = 'SELECT flow_pages, complete_button FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id;
    $flow_pages = $wpdb->get_row($flow_pages);
    if (!$flow_pages) {
        return __('A Register Flow Error Occurred (Type 2) Flow Not Found', 'ym');
    }
    $complete_button = $flow_pages->complete_button;
    $the_flow_id = $flow_id;
    // have a flow
    $flow_pages = unserialize($flow_pages->flow_pages);
    $last_page = ym_post('ym_register_flow_page', 0);
    $current_page = ym_post('ym_register_flow_next_page', 0);
    $flowcomplete = ym_post('flowcomplete', 0);
    if (!$current_page) {
        $copy = $flow_pages;
        $current_page = array_shift($copy);
    }
    $next_page = 0;
    while ($next_page == 0 && count($flow_pages)) {
        $page = array_shift($flow_pages);
        if ($page == $current_page) {
            $next_page = array_shift($flow_pages);
        }
    }
    //$permalink = get_permalink();
    $permalink = '';
    if (ym_superuser()) {
        echo '<div class="ym_message"><p class="ym_message_liner">' . __('Warning, entering this flow may change your WordPress role', 'ym') . '</p></div>';
    }
    echo '
<style type="text/css">
	label {
		display: block;
	}
</style>
';
    $form = '
<form action="' . $permalink . '" method="post" enctype="multipart/form-data" id="ym_register_flow_form">
';
    $html .= $form;
    $form_top .= $form;
    $custom_data = get_option('ym_custom_fields');
    $custom_data = $custom_data->entries;
    // required?
    $required_data = isset($_POST['required']) ? $_POST['required'] : array();
    $ok = true;
    $email = true;
    $useremail = true;
    $username = true;
    $coupon = true;
    $dupepassword = true;
    $dont_hidden = array('email_address', 'username', 'signed_request');
    // maintaint
    $post_data = array();
    foreach ($_POST as $field => $entry) {
        if ($field != 'ym_register_flow_page' && $field != 'ym_register_flow_next_page' && $field != 'required' && $field != 'flowcomplete') {
            if (isset($required_data[$field]) && $required_data[$field] == 1 && !$entry) {
                $ok = false;
            }
            if ($field == 'email_address' && !is_email($entry)) {
                $email = false;
                $entry = '';
            } else {
                if ($field == 'email_address') {
                    // verify unique
                    if (email_exists($entry)) {
                        $useremail = false;
                    }
                }
            }
            if ($field == 'username') {
                if (username_exists($entry)) {
                    $username = false;
                }
            }
            if ($field == 'coupon' && $entry) {
                $type = ym_post('coupon_type');
                if ($type == 'coupon_register') {
                    $type = array(0);
                } else {
                    if ($type == 'coupon_upgrade') {
                        $type = array(1);
                    } else {
                        if (!is_int($type)) {
                            // both
                            $type = array(0, 1);
                        }
                    }
                }
                $value = false;
                $coupon_type = '';
                foreach ($type as $t) {
                    $value = ym_validate_coupon($entry, $t);
                    if ($value) {
                        $coupon_type = $t;
                        // TODO: register coupon use
                        break;
                    }
                }
                if ($value) {
                    //valid
                    $post_data['coupon_value'] = $value;
                    $form = '<input type="hidden" name="coupon_value" value="' . $value . '" />';
                    $post_data['coupon_type'] = $coupon_type;
                    $form = '<input type="hidden" name="coupon_type" value="' . $coupon_type . '" />';
                    $coupon = true;
                } else {
                    // not valid
                    $coupon = false;
                }
            }
            //YM duplicate password check
            if ($field == 'ym_password') {
                if (ym_post('ym_password_check') || ym_post('ym_password_dupe')) {
                    $dupepassword = false;
                    if (ym_post('ym_password') == ym_post('ym_password_check')) {
                        $dupepassword = true;
                    }
                }
            }
            if (!isset($post_data[$field])) {
                $post_data[$field] = ym_post($field);
                //$entry;
                if (!in_array($field, $dont_hidden)) {
                    $form = '<input type="hidden" name="' . $field . '" value="' . $entry . '" />
';
                    $html .= $form;
                    $form_top .= $form;
                }
            }
        }
    }
    $call_login = 0;
    if ($_POST) {
        if (!$ok || !$email || !$useremail || !$username || !$coupon || !$dupepassword) {
            $next_page = $current_page;
            $current_page = $last_page;
            if (!$email) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_invalid . '</p></div>';
            }
            if (!$useremail) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_inuse . '</p></div>';
            }
            if (!$username) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_username_inuse . '</p></div>';
            }
            if (!$ok) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_required_fields . '</p></div>';
            }
            if (!$coupon) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_invalid_coupon . '</p></div>';
            }
            if (!$dupepassword) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_invalid_password . '</p></div>';
            }
            $ok = false;
        }
        global $current_user;
        get_currentuserinfo();
        $username = $password = $fb_widget_ok = false;
        // check registation
        if ($ok) {
            if (!$current_user->ID) {
                $email = isset($post_data['email_address']) ? $post_data['email_address'] : '';
                $username = isset($post_data['username']) ? $post_data['username'] : '';
                $password = isset($post_data['password']) ? $post_data['password'] : '';
                if ($email) {
                    // minimum for registeration
                    if (!$username) {
                        $username = $email;
                    }
                    if (username_exists($username)) {
                        // register failed
                        $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_username_inuse . '</p></div>';
                    } else {
                        // able to registers
                        $ym_user = new YourMember_User();
                        $user_id = $ym_user->create($email, false, true, $username, $password);
                        wp_set_current_user($user_id);
                        $call_login = 1;
                    }
                } else {
                    if (ym_post('signed_request')) {
                        $data = ym_facebook_uncode(ym_post('signed_request'));
                        if ($data) {
                            if ($data->registration) {
                                // register!
                                if (email_exists($data->registration->email) || username_exists($data->registration->email)) {
                                    $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_inuse . '</p></div>';
                                } else {
                                    $ym_user = new YourMember_User();
                                    $user_id = $ym_user->create($data->registration->email, false, true, $data->registration->email, $data->registration->password, array('first_name' => $data->registration->first_name, 'last_name' => $data->registration->last_name));
                                    wp_set_current_user($user_id);
                                    $call_login = 1;
                                    $fb_widget_ok = true;
                                }
                            } else {
                                $html .= '<div class="ym_message"><p class="ym_message_liner">' . __('Faecbook Registration Error (2)', 'ym') . '</p></div>';
                            }
                        } else {
                            $html .= '<div class="ym_message"><p class="ym_message_liner">' . __('Faecbook Registration Error (1)', 'ym') . '</p></div>';
                        }
                    }
                }
            } else {
                // update key user entries
                if (isset($post_data['username'])) {
                    if ($username = $post_data['username']) {
                        $query = 'UPDATE ' . $wpdb->users . ' SET user_login = \'' . $username . '\' WHERE ID = ' . $current_user->ID;
                        $wpdb->query($query);
                    }
                }
                if (isset($post_data['password'])) {
                    if ($password = $post_data['password']) {
                        $pw_hash = wp_hash_password($password);
                        $query = 'UPDATE ' . $wpdb->users . ' SET user_pass = \'' . $pw_hash . '\' WHERE ID = ' . $current_user->ID;
                        $wpdb->query($query);
                        $call_login = 1;
                    }
                }
            }
            // customs
            ym_update_custom_fields();
        }
    }
    $gateway_return = ym_request('gateway_return', false);
    if ($gateway_return) {
        // return from gateway into flow
        // all details dropped :-(
        $to_remove = array('gateway_return', 'item', 'ym_register_flow_page', 'ym_register_flow_next_page', 'user_id');
        $query = $_SERVER['QUERY_STRING'];
        foreach ($to_remove as $remove) {
            $query = preg_replace('/' . $remove . '\\=' . "([a-zA-Z0-9_]+)/", '', $query);
        }
        while (substr($query, -1, 1) == '&') {
            $query = substr($query, 0, -1);
        }
        $html = str_replace('<form action=""', '<form action="?' . $query . '"', $html);
        $user_id = ym_request('user_id', false);
        if ($user_id) {
            $call_login = 1;
        }
    }
    $ym_register_user_id = ym_request('ym_register_user_id', false);
    if ($ym_register_user_id) {
        $call_login = 1;
        $user_id = $ym_register_user_id;
    }
    if ($call_login) {
        // temp login
        wp_set_current_user($user_id);
        $html .= '<input type="hidden" name="ym_register_user_id" value="' . $user_id . '" />';
    }
    unset($username);
    unset($password);
    $form = '
	<input type="hidden" name="ym_register_flow_page" value="' . $current_page . '" />
	<input type="hidden" name="ym_register_flow_next_page" value="' . $next_page . '" />
	';
    $html .= $form;
    $form_top .= $form;
    // data maintain whats left
    foreach ($post_data as $key => $item) {
        if (!in_array($key, $dont_hidden)) {
            $form = '
	<input type="hidden" name="' . $key . '" value="' . $item . '" />
	';
            $html .= $form;
            $form_top .= $form;
        }
    }
    // load
    $page = 'SELECT page_fields, button_text FROM ' . $wpdb->prefix . 'ym_register_pages WHERE page_id = ' . $current_page;
    $page = $wpdb->get_row($page);
    if (!$page) {
        return __('A Register Flow Error Occurred (Type 3) Page Not Found', 'ym');
    }
    $page_data = $page->page_fields;
    $next_button = $page->button_text;
    $page_data = unserialize($page_data);
    foreach ($page_data as $item => $field) {
        foreach ($field as $i => $f) {
            $page_data[$item][$i] = stripslashes(urldecode($f));
        }
    }
    $block_logic = array();
    // parse pack data
    $pack_data = false;
    if (isset($post_data['pack_id'])) {
        // load from form
        $pack_id = $post_data['pack_id'];
        // pass thru....
    }
    if ($pack_id) {
        $pack_data = ym_get_pack_by_id($pack_id);
    } else {
        // no pack id :-(
        // default
        $pack_order = ym_get_packs();
        $pack_data = array_shift($pack_order);
    }
    $first_button = true;
    foreach ($page_data as $index => $field_data) {
        $display = true;
        if ($field_data['iflogic']) {
            // block has logic
            $display = false;
            // evaulate the block logic result
            // is it a then or a else?
            switch ($field_data['iflogic']) {
                case 'loggedin':
                    $match = $field_data['iflogic_quantity_loggedin'];
                    $logged_in = is_user_logged_in();
                    if ($logged_in && $match) {
                        // user is logged on and the match is for logged in
                        $this_logic = 'then';
                    } else {
                        if (!$logged_in && !$match) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    }
                    break;
                case 'buying':
                    $match = $field_data['iflogic_quantity_pack'];
                    if (isset($post_data['pack_id']) && $post_data['pack_id'] == $match) {
                        $this_logic = 'then';
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'currentlyon':
                    $match = $field_data['iflogic_quantity_pack'];
                    if (is_user_logged_in()) {
                        global $ym_user;
                        $pack_id = $ym_user->pack_id ? $ym_user->pack_id : 0;
                        if ($pack_id == $match) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'accounttype':
                    $match = $field_data['iflogic_quantity_pack'];
                    $match = strtolower($match);
                    if (is_user_logged_in()) {
                        global $ym_user;
                        $account_type = $ym_user->account_type ? $ym_user->account_type : '';
                        $account_type = strtolower($account_type);
                        if ($account_type == $match) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'filledin':
                    // custom field
                    $field = $field_data['iflogic_quantity_custom'];
                    $value = $field_data['iflogic_quantity_custom_compare'];
                    if (is_user_logged_in()) {
                        $customs = get_user_meta($current_user->ID, 'ym_custom_fields', true);
                        $test = $customs->{$field};
                        if ($test == $value) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'servervar':
                case 'getvar':
                case 'postvar':
                case 'cookievar':
                    $source = '_' . substr($field_data['iflogic'], 0, -3);
                    $match_name = $field_data['iflogic_quantity_field'];
                    $match_value = $field_data['iflogic_quantity_entry'];
                    $current_value = $source[$match_name];
                    if ($current_value == $match_value) {
                        $this_logic = 'then';
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'registeredfor':
                    //				case 'memberfor':
                //				case 'memberfor':
                case 'expiresin':
                    $match_value = $field_data['iflogic_quantity_memberfor_value'];
                    $match_unit = $field_data['iflogic_quantity_memberfor_unit'];
                    if (is_user_logged_in()) {
                        global $ym_user;
                        if ($field_data['iflogic'] == 'registeredfor') {
                            $math_date = strtotime($current_user->user_registered);
                        } else {
                            if ($field_data['iflogic'] == 'expiresin') {
                                $math_data = $ym_user->expire_date;
                            } else {
                                $math_date = '';
                            }
                        }
                        $seconds = ym_register_flow_date_math($match_value, $match_unit);
                        $diff = time() - $math_date;
                        if ($diff > $seconds) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                default:
                    $this_logic = 'else';
            }
            if ($this_logic == 'then' && $field_data['iflogic_showhide'] == 'show' || $this_logic == 'else' && $field_data['iflogic_showhide'] == 'hide') {
                $display = true;
            } else {
                $display = false;
            }
        }
        if ($field_data['label'] == 'page_logic' && ($this_logic == 'then' && $field_data['iflogic_showhide'] == 'hide' || $this_logic == 'else' && $field_data['iflogic_showhide'] == 'hide')) {
            $html .= '
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery(\'#ym_register_flow_form\').submit();
	});
</script>
';
            $html .= '</form>';
            return $html;
        } else {
            if ($field_data['label'] == 'page_logic') {
                // skip the IF and just skip the whole loop if should?
                continue;
            }
        }
        /**
         output render
        */
        $html .= '<span class="' . $field_data['classes'] . '">';
        //open class span
        if ($field_data['types'] == 'freetext' && $display) {
            $html .= '<p>' . nl2br($field_data['names']) . '</p>';
            //names o.0 lol
            /**
            Customs Processor
            */
        } else {
            if ($field_data['types'] == 'custom' && $display) {
                // LIFTED FROM ym.php line 642
                // modded tooooo!
                if ($field_data['names'] == 'terms_and_conditions' && !empty($ym_res->tos)) {
                    $html .= '<p>
						<textarea name="tos" cols="29" rows="5" readonly="readonly">' . $ym_res->tos . '</textarea>';
                    $html .= '</p>';
                    $html .= '<p>
						<label class="ym_label" for="terms_and_conditions">
							<div><input type="checkbox" class="checkbox" name="terms_and_conditions" id="terms_and_conditions" value="1" />
							' . __('I agree to the Terms and Conditions.', 'ym') . '</div>
						</label>
					</p>' . "\n";
                } else {
                    if ($field_data['names'] == 'ym_password') {
                        $html .= '<label for="ym_password">' . $field_data['label'];
                        $html .= '<input type="password" name="' . $field_data['names'] . '" value="" />';
                        $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />';
                        if ($field_data['required']) {
                            $html .= $ym_sys->required_custom_field_symbol;
                        }
                        $html .= '</label>';
                        if (!empty($field_data['options'])) {
                            $html .= '<label for="ym_password_check">' . __('Confirm Password', 'ym');
                            $html .= '<input type="password" name="ym_password_check" value="" />';
                            $html .= '<input type="hidden" name="ym_password_dupe" value="1" />';
                            if ($field_data['required']) {
                                $html .= $ym_sys->required_custom_field_symbol;
                            }
                            $html .= '</label>';
                        }
                    } else {
                        if ($field_data['names'] == 'subscription_introduction' && !empty($ym_res->subs_intro)) {
                            $html .= '<div class="ym_subs_intro">' . $ym_res->subs_intro . '</div>';
                        } else {
                            if ($field_data['names'] == 'subscription_options') {
                                global $ym_packs;
                                $upsell_from = ym_request('gateway_return', false) ? $pack_id : false;
                                // TO DO
                                $pack_data = false;
                                if ($pack_id && !ym_request('gateway_return', false)) {
                                    $pack_data = ym_get_pack_by_id($pack_id);
                                    if ($pack_data) {
                                        $label = ym_get_pack_label($pack_id);
                                        $html .= '<p>' . sprintf(__('You are subscribing to <b>%s</b>', 'ym'), $label) . '</p>';
                                        $html .= '<input type="hidden" name="pack_id" value="' . $pack_id . '" />';
                                    } else {
                                        return __('A Register Flow Error Occurred (Type 4) Specified Pack Not Found', 'ym');
                                    }
                                } else {
                                    $ym_packs->packs = apply_filters('ym_packs', $ym_packs->packs);
                                    foreach ($ym_packs->packs as $pack) {
                                        if ($upsell_from == $pack['id']) {
                                            continue;
                                        }
                                        $label = ym_get_pack_label($pack['id']);
                                        $html .= '<label for="pack_id_' . $pack['id'] . '">';
                                        $html .= '<input type="radio" name="pack_id" id="pack_id_' . $pack['id'] . '" value="' . $pack['id'] . '" />';
                                        $html .= ' ' . $label . ' ';
                                        $html .= '</label>';
                                    }
                                }
                            } else {
                                if ($field_data['names'] == 'birthdate') {
                                    $html .= '<label for="ym_birthdate_month">' . $field_data['label'];
                                    $birthdate_fields = ym_birthdate_fields('ym_birthdate', ym_post('ym_birthdate_month', ''), ym_post('ym_birthdate_day', ''), ym_post('ym_birthdate_year', ''));
                                    $html .= $birthdate_fields;
                                    $html .= '<input type="hidden" name="required[ym_birthdate_month]" value="' . $field_data['required'] . '" />';
                                    $html .= '<input type="hidden" name="required[ym_birthdate_day]" value="' . $field_data['required'] . '" />';
                                    $html .= '<input type="hidden" name="required[ym_birthdate_year]" value="' . $field_data['required'] . '" />';
                                    if ($field_data['required']) {
                                        $html .= $ym_sys->required_custom_field_symbol;
                                    }
                                    $html .= '</label>';
                                } else {
                                    if ($field_data['names'] == 'country') {
                                        $html .= '<label for="ym_country">' . $field_data['label'];
                                        $countries_sel = ym_countries_list('ym_country', ym_post('ym_country', false));
                                        $html .= $countries_sel;
                                        $html .= '<input type="hidden" name="required[ym_country]" value="' . $field_data['required'] . '" />';
                                        if ($field_data['required']) {
                                            $html .= $ym_sys->required_custom_field_symbol;
                                        }
                                        $html .= '</label>';
                                    } else {
                                        // HERE
                                        $this_custom = '';
                                        foreach ($custom_data as $custom) {
                                            $label = $custom['label'];
                                            if (!$label) {
                                                $label = strtolower(str_replace(' ', '_', $custom['name']));
                                            }
                                            if ($label == $field_data['label']) {
                                                // found
                                                $this_custom = $custom;
                                                break;
                                            }
                                        }
                                        if ($this_custom) {
                                            $ro = $this_custom['readonly'] ? 'readonly="readonly"' : '';
                                            // check for special
                                            $value = $this_custom['value'];
                                            if (strpos($value, ':') !== false) {
                                                $array = explode(':', $value);
                                                if (count($array)) {
                                                    switch ($array[0]) {
                                                        case 'cookie':
                                                            $value = ym_cookie($array[1]);
                                                            break;
                                                        case 'session':
                                                            $value = ym_session($array[1]);
                                                            break;
                                                        case 'get':
                                                            $value = ym_get($array[1]);
                                                            break;
                                                        case 'post':
                                                            $value = ym_post($array[1]);
                                                            break;
                                                        case 'request':
                                                        case 'qs':
                                                            $value = ym_request($array[1]);
                                                            break;
                                                        default:
                                                            $value = '';
                                                            break;
                                                    }
                                                    $this_custom['value'] = ym_post($this_custom['name'], $value);
                                                }
                                            } else {
                                                if (is_user_logged_in()) {
                                                    $this_custom['value'] = ym_custom_value($this_custom['id']);
                                                } else {
                                                    $this_custom['value'] = ym_post($this_custom['name'], $this_custom['value']);
                                                }
                                            }
                                            // ro adjust for fields that should not be changed
                                            switch ($this_custom['type']) {
                                                case 'password':
                                                case 'text':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<input type="' . $this_custom['type'] . '" name="' . $this_custom['name'] . '" value="' . $this_custom['value'] . '" ' . $ro . ' />';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'hidden':
                                                    $html .= '<input type="hidden" name="' . $this_custom['name'] . '" value="' . $this_custom['value'] . '" ' . $ro . ' />';
                                                    break;
                                                case 'yesnocheckbox':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<input type="checkbox" name="' . $this_custom['name'] . '" value="1" ' . ($this_custom['value'] ? 'checked="checked"' : '') . ' ' . $ro . ' />';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'yesno':
                                                case 'select':
                                                case 'multiselect':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    if ($this_custom['type'] == 'multiselect') {
                                                        $html .= '<select name="' . $this_custom['name'] . '[]" multiple="multiple"';
                                                    } else {
                                                        $html .= '<select name="' . $this_custom['name'] . '" ';
                                                    }
                                                    $html .= '>';
                                                    if ($this_custom['type'] == 'select' || $this_custom['type'] == 'multiselect') {
                                                        $options = explode(';', $this_custom['available_values']);
                                                    } else {
                                                        $options = array(__('Yes', 'ym'), __('No', 'ym'));
                                                    }
                                                    foreach ($options as $option) {
                                                        if (strpos($option, ':')) {
                                                            list($option, $val) = explode(':', $option);
                                                            $html .= '<option value="' . $option . '" ' . ($option == $this_custom['value'] ? 'selected="selected"' : '') . '>' . $val . '</option>';
                                                        } else {
                                                            $html .= '<option value="' . $option . '" ' . ($option == $this_custom['value'] ? 'selected="selected"' : '') . '>' . $option . '</option>';
                                                        }
                                                    }
                                                    $html .= '
</select>
';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'textarea':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<textarea name="' . $this_custom['name'] . '" cols="29" rows="5" ' . $ro . '>' . $this_custom['value'] . '</textarea>';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'file':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<input type="file" name="' . $this_custom['name'] . '" />';
                                                    $html .= '</label>';
                                                    break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // END LIFT
                /**
                Buttons
                */
            } else {
                if (($field_data['types'] == 'payment_button' || $field_data['types'] == 'payment_action') && $display) {
                    $payment_gateway_detected = true;
                    add_filter('ym_additional_code', 'ym_register_flow_override_return', 10, 3);
                    $enabled = get_option('ym_modules');
                    // use the ym user id function
                    if (ym_get_user_id()) {
                        if (in_array($field_data['names'], $enabled)) {
                            // register flow
                            $class = $field_data['names'];
                            $pay = new $class();
                            if ($first_button) {
                                $html .= '</form>';
                                $first_button = false;
                            }
                            $this_pack = $pack_data;
                            // coupon check
                            if (isset($post_data['coupon_value']) && $post_data['coupon_value']) {
                                // stop
                                // stash
                                $value = ym_apply_coupon($post_data['coupon'], $post_data['coupon_type'], $this_pack['cost']);
                                $type = ym_get_coupon_type($value);
                                if ($type == 'percent') {
                                    // percent cost change
                                    $this_pack['cost'] = $this_pack['cost'] / 100 * $value;
                                } else {
                                    if ($type == 'sub_pack') {
                                        // diff pack
                                        $this_pack = ym_get_pack_by_id($value);
                                    } else {
                                        // other
                                        // new cost
                                        $this_pack['cost'] = $value;
                                    }
                                }
                                ym_register_coupon_use($post_data['coupon'], ym_get_user_id(), 'buy_subscription_' . $pack_data['id']);
                                if (!$this_pack['cost']) {
                                    // change to free
                                    //							$field_data['names'] = 'ym_free';
                                    // lifted from 135 of ym-register.include.php
                                    $code_to_use = 'freebie_code';
                                    // attempt to redirect to the processor.
                                    $loc = $ym_home . '/index.php?ym_process=ym_free&' . $code_to_use . '=buy_subscription_' . $this_pack['id'] . '_' . ym_get_user_id();
                                    if (!headers_sent()) {
                                        header('Location: ' . $loc);
                                        exit;
                                    } else {
                                        echo '<script type="text/javascript">window.location = "' . $loc . '";</script>';
                                    }
                                    die;
                                }
                            }
                            // there will always be pack data becuase I picked the default one earlier
                            // but it will default to the default pack anyway
                            if ($this_pack['cost']) {
                                // && $field_data['names'] != 'ym_free') {
                                //						$gw_button_form = $pay->getButton($this_pack['id'], (isset($post_data['coupon_value']) ? $this_pack['cost'] : false));
                                //						$html .= $gw_button_form;
                                $gw_button_form = $pay->getButton($this_pack['id'], isset($post_data['coupon_value']) ? $this_pack['cost'] : false);
                                if ($field_data['types'] == 'payment_action') {
                                    if (method_exists($pay, 'register_auto_payment_action')) {
                                        $html .= $pay->register_auto_payment_action($this_pack['id'], isset($post_data['coupon_value']) ? $this_pack['cost'] : false, true);
                                    } else {
                                        if ($gw_button_form) {
                                            $html .= $gw_button_form . '
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery(\'.' . $field_data['names'] . '_form\').submit();
	});
</script>
';
                                        }
                                    }
                                } else {
                                    if (method_exists($pay, 'register_payment_action')) {
                                        $html .= $pay->register_payment_action(true);
                                    } else {
                                        $html .= $gw_button_form;
                                    }
                                }
                            } else {
                                if (!$this_pack['cost'] && $field_data['names'] == 'ym_free') {
                                    // free
                                    $gw_button_form = $pay->getButton($this_pack['id'], false);
                                    $html .= $gw_button_form;
                                    if ($field_data['types'] == 'payment_action') {
                                        if (method_exists($pay, 'register_auto_payment_action')) {
                                            $html .= $pay->register_auto_payment_action($this_pack['id'], false, true);
                                        } else {
                                            if ($gw_button_form) {
                                                $html .= '
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery(\'.ym_free_form\').submit();
	});
</script>
';
                                            }
                                        }
                                    } else {
                                        if (method_exists($pay, 'register_payment_action')) {
                                            $html .= $pay->register_payment_action(true);
                                        }
                                    }
                                } else {
                                    if (isset($post_data['coupon_value']) && $post_data['coupon_value']) {
                                        return __('A Register Flow Error Occurred (Type 5) Pack/Coupon Error', 'ym');
                                    }
                                }
                            }
                        }
                    } else {
                        // user not logged in // No User ID Determined
                        return __('In order to continue you need to Register or Login', 'ym');
                    }
                    /**
                    Widgets
                    */
                } else {
                    if ($field_data['types'] == 'widget' && $display) {
                        if ($field_data['names'] == 'login') {
                            // login form
                            $html .= '
	<input type="hidden" name="ym_register_flow_page" value="' . $current_page . '" />
	<input type="hidden" name="ym_register_flow_next_page" value="' . $current_page . '" />
	';
                            //	<input type="hidden" name="ym_register_flow_do_login" value="1" />';
                            $html .= ym_login_form();
                        } else {
                            if ($field_data['names'] == 'register_facebook') {
                                // check for and handle a signed request
                                if ($fb_widget_ok) {
                                    // skippy
                                    $html .= '
					<script type="text/javascript">
						jQuery(document).ready(function() {
							jQuery(\'#ym_register_flow_form\').submit();
						});
					</script>
					';
                                } else {
                                    $html .= '
<iframe src="https://www.facebook.com/plugins/registration?
             client_id=' . get_option('ym_register_flow_fb_app_id') . '&
             redirect_uri=' . get_permalink() . '&
             fields=name,email,first_name,last_name,password"
        scrolling="auto"
        frameborder="no"
        style="border:none"
        allowTransparency="true"
        width="100%"
        height="550">
</iframe>
';
                                    // no next/complete please
                                }
                                $payment_gateway_detected = true;
                            } else {
                                $html .= 'Undefined Widget: (' . $field_data['names'] . ')';
                            }
                        }
                        /**
                        Coupon
                        */
                    } else {
                        if ($field_data['names'] == 'coupon' && $display) {
                            $value = isset($post_data[$field_data['names']]) ? $post_data[$field_data['names']] : '';
                            $html .= '<label for="' . $field_data['names'] . '">' . $field_data['label'];
                            $html .= '<input type="text" name="' . $field_data['names'] . '" id="' . $field_data['names'] . '" value="' . $value . '" />';
                            $html .= '<input type="hidden" name="coupon_type" value="' . $field_data['types'] . '" />';
                            $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />';
                            if ($field_data['required']) {
                                $html .= $ym_sys->required_custom_field_symbol;
                            }
                            $html .= '</label>';
                            /**
                            Display everything else
                            */
                        } else {
                            if ($display) {
                                $value = isset($post_data[$field_data['names']]) ? $post_data[$field_data['names']] : '';
                                $html .= '<label for="' . $field_data['names'] . '">' . $field_data['label'];
                                $html .= '<input type="' . $field_data['types'] . '" name="' . $field_data['names'] . '" id="' . $field_data['names'] . '" value="' . $value . '" />';
                                $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />';
                                if ($field_data['required']) {
                                    $html .= $ym_sys->required_custom_field_symbol;
                                }
                                $html .= '</label>';
                            }
                        }
                    }
                }
            }
        }
        $html .= '</span>';
        //closes class span
    }
    if (!$first_button) {
        // kill id
        $html = str_replace('id="ym_register_flow_form"', '', $html);
        // complete?
        if (!$next_page) {
            $query = 'SELECT complete_url FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id;
            if ($url = $wpdb->get_var($query)) {
                $url = site_url($url);
                $form_top = str_replace('<form action=""', '<form action="' . $url . '"', $form_top);
            }
        }
        // append the form top
        $html .= $form_top;
        // end it
    }
    // payment gateway?
    if (!$payment_gateway_detected) {
        $html .= '<p>';
        if ($next_page) {
            $html .= '<input type="submit" value="' . $next_button . '" />';
        } else {
            $html .= '
<input type="hidden" name="flowcomplete" value="1" />
<input type="submit" value="' . $complete_button . '" />';
        }
        $html .= '</p>';
    }
    $html .= '</form>';
    return $html;
}
function ym_get_user_purchase_history($userID = FALSE, $limit = 5)
{
    if (!$userID) {
        global $current_user;
        get_current_user();
        $userID = $current_user->ID;
    }
    global $wpdb;
    $html = '';
    // get log
    $query = 'SELECT DISTINCT(transaction_id) FROM ' . $wpdb->prefix . 'ym_transaction
		WHERE user_id = ' . $userID . '
		ORDER BY unixtime DESC
		LIMIT ' . $limit;
    foreach ($wpdb->get_results($query) as $trans) {
        $id = $trans->transaction_id;
        $sub = 'SELECT * FROM ' . $wpdb->prefix . 'ym_transaction WHERE transaction_id = ' . $id . ' AND user_id = ' . $userID;
        $data = array();
        foreach ($wpdb->get_results($sub) as $log) {
            $data[$log->action_id] = $log->data;
        }
        if (isset($data[YM_PPP_PURCHASED])) {
            // Pay Per Post
            $html .= '<li>' . __('Content Purchase: ', 'ym') . get_the_title($data[YM_PPP_PURCHASED]) . '</li>';
        } else {
            if (isset($data[YM_PPP_PACK_PURCHASED])) {
                // bundle
                $html .= '<li>' . __('Content Purchase: ', 'ym');
                $bundle = ym_get_bundle($data[YM_PPP_PACK_PURCHASED]);
                $html .= $bundle->name . '</li>';
            } else {
                if (isset($data[YM_PACKAGE_PURCHASED])) {
                    $pack = $data[YM_PACKAGE_PURCHASED];
                    $html .= '<li>';
                    $html .= ym_get_pack_label($pack, FALSE, FALSE);
                    $html .= '</li>';
                } else {
                    if (isset($data[YM_PAYMENT])) {
                        $html .= '<li>' . __('Unknown Payment', 'ym') . ' ' . $data[YM_PAYMENT] . '</li>';
                    }
                }
            }
        }
    }
    if (empty($html)) {
        return FALSE;
    }
    $html = '<ul>' . $html . '</ul>';
    return $html;
}
function ym_members_filters($filters)
{
    global $ym_members_tasks;
    // filters
    ym_box_top(__('Search and Sort', 'ym'));
    echo '<table style="width: 100%;">';
    echo '
<tr><td colspan="10">
<table class="form-table" style="width: 100%;">
<tr><td>
<strong>' . __('Filter Members by:', 'ym') . '</strong>

	<select name="filter_by_option" id="filter_by_option">
		<option value="">' . __('No Filter', 'ym') . '</option>
		<option value="username" ' . ($filters['by_option'] == 'username' ? 'selected="selected"' : '') . '>' . __('Username', 'ym') . '</option>
		<option value="user_email" ' . ($filters['by_option'] == 'user_email' ? 'selected="selected"' : '') . '>' . __('User Email', 'ym') . '</option>
		<option value="package" ' . ($filters['by_option'] == 'package' ? 'selected="selected"' : '') . '>' . __('Package', 'ym') . '</option>
		<option value="package_type" ' . ($filters['by_option'] == 'package_type' ? 'selected="selected"' : '') . '>' . __('Package Type', 'ym') . '</option>
		<option value="custom_field" ' . ($filters['by_option'] == 'custom_field' ? 'selected="selected"' : '') . '>' . __('Custom Field', 'ym') . '</option>
		<option value="status" ' . ($filters['by_option'] == 'status' ? 'selected="selected"' : '') . '>' . __('Status', 'ym') . '</option>
		';
    echo '		
		<option value="">--' . __('User Exposed Fields', 'ym') . '--</option>
		';
    $funbus = '';
    $available = new YourMember_User();
    $available = $available->api_expose();
    foreach ($available as $item) {
        if ($item != 'status' && $item != 'account_type') {
            $funbus .= 'filter_by_text_exposed_' . $item . ' ';
            echo '<option value="exposed_' . $item . '" ' . ($filters['by_option'] == 'exposed_' . $item ? 'selected="selected"' : '') . '>' . ucwords(str_replace('_', ' ', str_replace('account', 'package', $item))) . '</option>';
        }
    }
    echo '
	</select>
</td><td>
<select name="filter_by_text_package" class="filter_by_text filter_by_text_package">
<option value="">' . __('Select', 'ym') . '</option>
<option value="none" ';
    if ('none' == $filters['by_text']) {
        echo 'selected="selected"';
    }
    echo '>' . __('No Package', 'ym') . '</option>';
    global $ym_packs;
    foreach ($ym_packs->packs as $pack) {
        echo '<option value="' . $pack['id'] . '" ';
        if ($pack['id'] == $filters['by_text']) {
            echo 'selected="selected"';
        }
        echo '>' . ym_get_pack_label($pack) . '</option>';
    }
    echo '
</select>

<select name="filter_by_text_package_type" class="filter_by_text filter_by_text_package_type">
<option value="">' . __('Select', 'ym') . '</option>
<option value="none" ';
    if ('none' == $filters['by_text']) {
        echo 'selected="selected"';
    }
    echo '>' . __('No Package Type', 'ym') . '</option>';
    global $ym_package_types;
    foreach ($ym_package_types->types as $type) {
        echo '<option value="' . $type . '" ';
        if ($type == $filters['by_text']) {
            echo 'selected="selected"';
        }
        echo '>' . $type . '</option>';
    }
    echo '
</select>

<select name="filter_by_text_custom_field" class="filter_by_text filter_by_text_custom_field">
	<option value="">' . __('Select', 'ym') . '</option>
	';
    $customs = get_option('ym_custom_fields');
    $order = explode(';', $customs->order);
    foreach ($order as $id) {
        $custom = ym_get_custom_field_by_id($id);
        echo '<option value="' . $id . '" ';
        if ($id == $filters['cf_field']) {
            echo 'selected="selected"';
        }
        echo '>' . $custom['label'] . '</option>';
    }
    echo '
</select>

<select name="filter_by_text_status" class="filter_by_text filter_by_text_status">
	<option value="">' . __('Select', 'ym') . '</option>
	';
    global $status_str;
    foreach ($status_str as $state) {
        echo '<option ';
        if ($state == $filters['by_text']) {
            echo 'selected="selected"';
        }
        echo '>' . $state . '</option>';
    }
    echo '
</select>
</td><td>
<input type="text" name="filter_by_text" class="filter_by_text filter_by_text_username filter_by_text_user_email filter_by_text_custom_field ' . $funbus . '" value="' . $filters['by_text'] . '" size="10">
</td><td style="width: 120px;">
<input type="submit" id="change_filters" name="task" class="button-primary" value="' . $ym_members_tasks['change_filters'] . '" />
</td></tr>
<tr><td style="width: 25%;"></td><td style="width: 25%;"></td><td style="width: 25%;">' . __('Use * to wildcard match', 'ym') . '</td><td style="width: 25%;"></td></tr>
<tr><td>
<strong>' . __('Sort Members by:', 'ym') . '</strong>
<select name="filter_by_order_by">
	<option value="ID" ' . ($filters['order_by'] == 'ID' ? 'selected="selected"' : '') . '>' . __('User ID', 'ym') . '</option>
	<option value="login" ' . ($filters['order_by'] == 'login' ? 'selected="selected"' : '') . '>' . __('User Login', 'ym') . '</option>
	<option value="email" ' . ($filters['order_by'] == 'email' ? 'selected="selected"' : '') . '>' . __('Email Address', 'ym') . '</option>
	<option value="registered" ' . ($filters['order_by'] == 'registered' ? 'selected="selected"' : '') . '>' . __('Registration Date', 'ym') . '</option>
	';
    echo '		
	<option value="">--' . __('User Exposed Fields', 'ym') . '--</option>
	';
    foreach ($available as $item) {
        echo '<option value="exposed_' . $item . '" ' . ($filters['order_by'] == 'exposed_' . $item ? 'selected="selected"' : '') . '>' . ucwords(str_replace('_', ' ', str_replace('account', 'package', $item))) . '</option>';
    }
    echo '
</select>
<td>
</td>
</td><td>
<select name="filter_by_order_by_direction">
	<option value="ASC" ' . ($filters['order_by_direction'] == 'ASC' ? 'selected="selected"' : '') . '>' . __('Ascending', 'ym') . '</option>
	<option value="DESC" ' . ($filters['order_by_direction'] == 'DESC' ? 'selected="selected"' : '') . '>' . __('Descending', 'ym') . '</option>
</select>
</td><td>
<input type="submit" id="change_order" name="task" class="button-primary" value="' . $ym_members_tasks['change_order'] . '" />
</td></tr>

</table>

</td></tr>
';
    echo '</table>';
    ym_box_bottom();
    return;
}