Example #1
0
function ym_get_pack_by_id($id)
{
    foreach (ym_get_packs() as $pack) {
        if ($pack['id'] == $id) {
            return $pack;
        }
    }
    return FALSE;
}
function ym_firesale_subs()
{
    // get all subs
    $packs = ym_get_packs();
    foreach ($packs as $key => $pack) {
        $pack_id = $pack['id'];
        $base_price = $pack['cost'];
        $fire_original_cost = isset($pack['pre_firesale_cost']) ? $pack['pre_firesale_cost'] : FALSE;
        $is_currently_firesale = isset($pack['on_fire_sale']) ? $pack['on_fire_sale'] : FALSE;
        if ($ym_firesale_id = ym_firesale_exists($pack_id, YM_APP_TYPE_SUB)) {
            // a fire sale exists for this pack
            $tier_data = ym_firesale_get_current_tier($ym_firesale_id);
            $tier_data = $tier_data[0];
            if (!$fire_original_cost) {
                // starting a fire sale
                $pack['pre_firesale_cost'] = $base_price;
                ym_firesale_log(array('doing' => 'StartingPricingModel', 'packId' => $pack_id, 'tierId' => $tier_data->fire_tier_id, 'tierPacket' => $tier_data));
                ym_fire_sale_start($tier_data->fire_id);
            }
            // check for tier change
            if ($base_price != $tier_data->fire_price) {
                if ($tier_data) {
                    $pack['cost'] = $tier_data->fire_price;
                    $pack['on_fire_sale'] = TRUE;
                    ym_firesale_log(array('doing' => 'TierChange', 'packId' => $pack_id, 'newPrice' => $tier_data->fire_price, 'currentPrice' => $base_price, 'tierId' => $tier_data->fire_tier_id, 'tierPacket' => $tier_data));
                    ym_firesale_tier_log($tier_data->fire_tier_id);
                    ym_fire_tier_start($tier_data->fire_tier_id);
                } else {
                    // no tier
                    $pack['cost'] = $fire_original_cost;
                    unset($pack['pre_firesale_cost']);
                    unset($pack['on_fire_sale']);
                    ym_firesale_log(array('doing' => 'EndPricingModel', 'packId' => $pack_id, 'newPrice' => $fire_original_cost, 'currentPrice' => $base_price, 'tierId' => $tier_data->fire_tier_id, 'tierPacket' => $tier_data));
                }
            }
        } else {
            if ($is_currently_firesale == 1) {
                // firesale needs resetting as it has ended
                $pack['cost'] = $fire_original_cost;
                unset($pack['pre_firesale_cost']);
                unset($pack['on_fire_sale']);
                ym_firesale_log(array('doing' => 'EndPricingModel', 'packId' => $pack_id, 'newPrice' => $fire_original_cost, 'currentPrice' => $base_price));
            }
        }
        // store the pack
        $packs[$key] = $pack;
    }
    // store the packs
    $obj_packs = get_option('ym_packs');
    $obj_packs->packs = $packs;
    update_option('ym_packs', $obj_packs);
}
/**
 * code to run on the login page.. could be custom feedback or some js.
 * add_action('ym_return_true','yourfunction'); will fire up here :)
 *
 */
function ym_login_js()
{
    // gateways
    $gateways = get_option('ym_modules');
    foreach ($gateways as $way) {
        if (ym_get('from_gateway') == $way) {
            $js = new $way();
            if (isset($js->callback_script)) {
                $js = $js->callback_script;
                global $current_user;
                get_currentuserinfo();
                $js = str_replace('[user_id]', $current_user->ID, $js);
                $js = str_replace('[pack_id]', ym_get('pack_id'), $js);
                $js = str_replace('[post_id]', ym_get('post_id'), $js);
                $js = str_replace('[post_pack_id]', ym_get('post_pack_id'), $js);
                $js = str_replace('[item_code]', ym_get('item'), $js);
                $cost = 0;
                $account_type = '';
                if (ym_get('pack_id')) {
                    foreach (ym_get_packs() as $pack) {
                        if ($pack['id'] == ym_get('pack_id')) {
                            $cost = $pack['cost'];
                            $account_type = $pack['account_type'];
                            break;
                        }
                    }
                } else {
                    if (ym_get('post_id')) {
                        // post
                        $cost = get_post_meta(ym_get('post_id'), '_ym_post_purchasable_cost', true);
                    } else {
                        if (ym_get('post_pack_id')) {
                            // bundle
                            $bundle = ym_get_bundle(ym_get('post_pack_id'));
                            $cost = $bundle->cost;
                        }
                    }
                }
                $js = str_replace('[cost]', $cost, $js);
                $js = str_replace('[account_type]', $account_type, $js);
                add_shortcode('if_cb_pack', 'ym_login_js_cb_pack');
                add_shortcode('if_cb_post', 'ym_login_js_cb_post');
                add_shortcode('if_cb_bundle', 'ym_login_js_cb_bundle');
                $js = do_shortcode($js);
                $js = apply_filters('ym_login_js', $js);
                echo $js;
            }
            do_action('ym_return_true');
        }
    }
    // enctype not on payment buttons please!
    if (isset($_REQUEST['ym_subscribe'])) {
        return;
    }
    // it only breaks zombaio.....
    // but payment gateways arn't specific classed.
    // check for zombaio
    echo '
<script type="text/javascript">
jQuery(document).ready(function() {
	jQuery(\'form\').attr(\'enctype\', \'multipart/form-data\');
});
</script>
';
}
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>';
}
Example #5
0
function ymfire_admin_page()
{
    global $wpdb, $firetypes, $saletypes, $ym_formgen;
    $firesale = ym_request('firesale');
    $months = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    echo '<div class="wrap" id="poststuff">';
    $fire_id = ym_request('fire_id');
    $tier_id = ym_request('tier_id');
    if ($firesale == 'toggle') {
        $firesale = '';
        if ($fire_id) {
            $sql = 'SELECT fire_enable FROM ' . $wpdb->ym_app_models . ' WHERE fire_id = ' . $fire_id;
            $enabled = $wpdb->get_var($sql);
            $enabled = $enabled ? 0 : 1;
            $sql = 'UPDATE ' . $wpdb->ym_app_models . ' SET fire_enable = ' . $enabled . ' WHERE fire_id = ' . $fire_id;
            $wpdb->query($sql);
        }
    } else {
        if ($firesale == 'delete') {
            $firesale = '';
            if ($fire_id) {
                $wpdb->query('DELETE FROM ' . $wpdb->ym_app_models . ' WHERE fire_id = ' . $fire_id);
                $wpdb->query('DELETE FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_id = ' . $fire_id);
            }
            if ($tier_id) {
                $wpdb->query('DELETE FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_tier_id = ' . $tier_id);
            }
        } else {
            if ($firesale == 'enable') {
                // enabling a tier
                $sql = 'SELECT * FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_tier_id = ' . $tier_id;
                $thetier = $wpdb->get_results($sql);
                $thetier = $thetier[0];
                $fire_id = $thetier->fire_id;
                $tier_order = $thetier->fire_order;
                // reoder (order by)
                $tiers = array();
                foreach (ym_firesale_get_all_tiers($fire_id) as $tier) {
                    $tiers[$tier->fire_order] = $tier;
                }
                unset($tiers[$tier_order]);
                array_unshift($tiers, $thetier);
                foreach ($tiers as $order => $tier) {
                    $sql = 'UPDATE ' . $wpdb->ym_app_models_tiers . ' SET fire_order = ' . $order . ' WHERE fire_tier_id = ' . $tier->fire_tier_id;
                    $wpdb->query($sql);
                }
                echo '<p>Tier Order was updated, if the Pricing Model is not active, it has not been activated yet</p>';
                $firesale = '';
            }
        }
    }
    if ($firesale == 'newtier') {
        $fire_id = ym_post('ym_firesale_add_post_tiers_fire_id');
        $fire_id = str_replace('firesale_', '', $fire_id);
        // put to end
        $sql = 'SELECT fire_order FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_id = ' . $fire_id . ' ORDER BY fire_order DESC LIMIT 1';
        $order = $wpdb->get_var($sql);
        if ($order) {
            $order++;
        } else {
            $order = 0;
        }
        $fire_tiers = array();
        $limit_bys = ym_post('ym_new_firesale_limit_by');
        $limit_sales = ym_post('ym_new_firesale_limit_sales');
        $limit_dates = ym_post('ym_date_ym_new_firesale_limit_time');
        $limit_months = ym_post('ym_month_ym_new_firesale_limit_time');
        $limit_years = ym_post('ym_year_ym_new_firesale_limit_time');
        $limit_hours = ym_post('ym_hour_ym_new_firesale_limit_time');
        $limit_mins = ym_post('ym_min_ym_new_firesale_limit_time');
        $limit_by_hours = ym_post('ym_new_firesale_limit_hours');
        foreach (ym_post('ym_new_firesale_price') as $tier_price) {
            $fire_tiers[] = array('tier_price' => $tier_price, 'tier_limit_by' => $limit_bys[0], 'tier_limit_sales' => $limit_sales[0], 'tier_limit_time' => strtotime($limit_dates[0] . ' ' . $months[$limit_months[0]] . ' ' . $limit_years[0] . ' ' . $limit_hours[0] . ':' . $limit_mins[0]), 'tier_limit_hours' => $limit_by_hours[0]);
        }
        foreach ($fire_tiers as $tier) {
            $limit_var = 0;
            switch ($tier['tier_limit_by']) {
                case 2:
                    // hours
                    $limit_by = 2;
                    $limit_var = $tier['tier_limit_hours'];
                    break;
                case 1:
                    // time
                    $limit_by = 1;
                    $limit_var = $tier['tier_limit_time'];
                    break;
                case 0:
                default:
                    //sales
                    $limit_by = 0;
                    $limit_var = $tier['tier_limit_sales'];
            }
            $sql = 'INSERT INTO ' . $wpdb->ym_app_models_tiers . '(fire_id, fire_price, fire_limit_by, fire_limit_var, fire_order)
					VALUES (
						' . $fire_id . ',
						\'' . $tier['tier_price'] . '\',
						' . $limit_by . ',
						' . $limit_var . ',
						' . $order . '
					)';
            $wpdb->query($sql);
            echo ym_start_box('Pricing Models');
            if ($wpdb->insert_id) {
                echo '<div class="message" id="success"><p>Tier Added</p></div>';
            } else {
                echo '<div class="message" id="error"><p>Tier was not added</p></div>';
            }
            echo ym_end_box();
        }
        echo '<meta http-equiv="refresh" content="3;' . YM_PPP_ADMIN_URL . '" />';
    }
    if ($firesale == 'edit') {
        echo ym_start_box('Pricing Models');
        $tier_data = 'SELECT * FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_tier_id = ' . $tier_id;
        $tier_data = $wpdb->get_results($tier_data);
        if ($tier_data[0]) {
            $tier_data = $tier_data[0];
            //editing a tier
            echo '<form action="" method="post">
					<fieldset>';
            echo '
<input type="hidden" name="firesale" value="edittier" />
<input type="hidden" name="tier_id" value="' . $tier_id . '"/>
';
            echo '<table>';
            $ym_formgen->render_form_table_text_row('Price', 'ym_new_firesale_price[]', $tier_data->fire_price, 'Price for this Tier');
            $ym_formgen->render_combo_from_array_row('Limit By', 'ym_new_firesale_limit_by[]', $saletypes, $tier_data->fire_limit_by, 'What kind of Tier');
            $ym_formgen->render_form_table_text_row('Limit By Sales', 'ym_new_firesale_limit_sales[]', !$tier_data->fire_limit_by ? $tier_data->fire_limit_var : '', 'Tier ends after this many sales of this Tier');
            $ym_formgen->render_form_table_datetime_picker_row('Limit By Time', 'ym_new_firesale_limit_time[]', $tier_data->fire_limit_by ? $tier_data->fire_limit_var : '', 'Tier ends at this date');
            $ym_formgen->render_form_table_text_row('Hours', 'ym_new_firesale_limit_hours[]', $tier_data->fire_limit_by == 2 ? $tier_data->fire_limit_var : '', 'Expire Tier this many hours after it starts');
            echo '<tr><td colspan="5" style="border-top: 1px solid grey;">&nbsp;</td></tr>';
            echo '</table>';
            echo '
				<p class="submit" style="text-align: right;">
					<input type="submit" value="' . __('Update Pricing Model Tier', 'ym') . ' &raquo;" />
				</p>';
            echo '</fieldset></form>';
        } else {
            echo '<p>Could not find that Tier</p>';
            $firesale = '';
        }
        echo ym_end_box();
    }
    if ($firesale == 'edittier') {
        $fire_tiers = array();
        $limit_bys = ym_post('ym_new_firesale_limit_by');
        $limit_sales = ym_post('ym_new_firesale_limit_sales');
        $limit_dates = ym_post('ym_date_ym_new_firesale_limit_time');
        $limit_months = ym_post('ym_month_ym_new_firesale_limit_time');
        $limit_years = ym_post('ym_year_ym_new_firesale_limit_time');
        $limit_hours = ym_post('ym_hour_ym_new_firesale_limit_time');
        $limit_mins = ym_post('ym_min_ym_new_firesale_limit_time');
        $limit_by_hours = ym_post('ym_new_firesale_limit_hours');
        foreach (ym_post('ym_new_firesale_price') as $tier_price) {
            $fire_tiers[] = array('tier_price' => $tier_price, 'tier_limit_by' => $limit_bys[0], 'tier_limit_sales' => $limit_sales[0], 'tier_limit_time' => strtotime($limit_dates[0] . ' ' . $months[$limit_months[0]] . ' ' . $limit_years[0] . ' ' . $limit_hours[0] . ':' . $limit_mins[0]), 'tier_limit_hours' => $limit_by_hours[0]);
        }
        foreach ($fire_tiers as $tier) {
            $limit_var = 0;
            switch ($tier['tier_limit_by']) {
                case 2:
                    // hours
                    $limit_by = 2;
                    $limit_var = $tier['tier_limit_hours'];
                    break;
                case 1:
                    // time
                    $limit_by = 1;
                    $limit_var = $tier['tier_limit_time'];
                    break;
                case 0:
                default:
                    //sales
                    $limit_by = 0;
                    $limit_var = $tier['tier_limit_sales'];
            }
            $data = array('fire_price' => $tier['tier_price'], 'fire_limit_by' => $limit_by, 'fire_limit_var' => $limit_var);
            $wpdb->update($wpdb->ym_app_models_tiers, $data, array('fire_tier_id' => $tier_id));
            echo ym_start_box('Pricing Models');
            if ($wpdb->rows_affected) {
                echo '<p>Tier Updated</p>';
            } else {
                echo '<p>Tier was not updated</p>';
            }
            echo ym_end_box();
        }
        echo '<meta http-equiv="refresh" content="3;' . YM_PPP_ADMIN_URL . '" />';
    }
    if (empty($firesale)) {
        echo '<div style="width: 43%; float: left;">';
        echo ym_start_box('Pricing Models');
        $firesales = ym_firesale_get_all();
        echo '<h2>All Pricing Models</h2>';
        echo '<p>Click the Link to enable/disable</p>';
        echo '<table style="width: 100%;">';
        echo '<tr><th>Pricing Model Name</th><th>Type</th><th>Tiers</th><th>Enabled</th><th>Edit</th><th>Delete</th></tr>';
        foreach ($firesales as $firesale) {
            if ($firesale->fire_id) {
                echo '<tr>';
                echo '<td>(' . $firesale->fire_id . ')' . $firesale->fire_name . '</td>';
                echo '<td style="text-align: center;">' . $firetypes[$firesale->fire_type] . '</td>';
                echo '<td style="text-align: center;"><a href="#showtiers" class="ym_showtiers" id="tiers_' . $firesale->fire_id . '">' . $firesale->tiers . '</a></td>';
                echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=toggle&fire_id=' . $firesale->fire_id . '">' . ($firesale->fire_enable ? 'Yes' : 'No') . '</a></td>';
                //					echo '<td style="text-align: center;"><a href="admin.php?page=' . YM_ADMIN_DIR . 'ym-index.php&ym_page=ym-other&action=ym_app&firesale=edit&fire_id=' . $firesale->fire_id . '">E</a></td>';
                echo '<td style="text-align: center;"><a href="#addtier" class="ym_firesale_add_post_tier" id="firesale_' . $firesale->fire_id . '">Add Tier</a></td>';
                echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=delete&fire_id=' . $firesale->fire_id . '">X</a></td>';
                echo '</tr>';
                foreach (ym_firesale_get_all_tiers($firesale->fire_id) as $tier) {
                    echo '<tr style="display: none;" class="tiers_' . $firesale->fire_id . '">';
                    echo '<td style="text-align: center;">ID: ' . $tier->fire_tier_id . ' Tier: ' . $tier->fire_order . '</td>';
                    echo '<td style="text-align: center;">' . $saletypes[$tier->fire_limit_by] . '(' . ($tier->fire_limit_by == 1 ? date('r', $tier->fire_limit_var) : $tier->fire_limit_var) . ')</td>';
                    echo '<td></td>';
                    //						echo '<td style="text-align: center;">' . ($tier->fire_tier_started ? 'Yes' : '<a href="admin.php?page=' . YM_ADMIN_DIR . 'ym-index.php&ym_page=ym-other&action=ym_app&firesale=enable&tier_id=' . $tier->fire_tier_id . '">No</a>') . '</td>';
                    echo '<td style="text-align: center;">' . ($tier->fire_tier_started ? 'Yes' : 'No') . '</td>';
                    echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=edit&tier_id=' . $tier->fire_tier_id . '">E</a></td>';
                    echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=delete&tier_id=' . $tier->fire_tier_id . '">X</a></td>';
                    echo '</tr>';
                }
            }
        }
        echo '</table>';
        echo ym_end_box();
        echo '</div>';
        echo '<div style="width: 55%; float: right;">';
        echo ym_start_box('New Pricing Model');
        echo '
<form action="" method="post">
	<fieldset>
		<legend>Create a new Pricing Model</legend>
		<input type="hidden" name="firesale" value="new" />
		<table class="form-table">
		';
        $ym_formgen->render_form_table_text_row('Pricing Model Name', 'ym_new_firesale_name', '', 'A handy name to Remember');
        $ym_formgen->render_combo_from_array_row('Pricing Model Type', 'ym_new_firesale_type', $firetypes, '', 'What type of Pricing Model');
        echo '
		</table>
		<p class="submit" style="text-align: right;">
			<input type="submit" value="' . __('Create Pricing Model', 'ym') . ' &raquo;" />
		</p>
	</fieldset>
</form>';
        echo ym_end_box();
        echo '</div>';
    } else {
        if ($firesale == 'new') {
            echo ym_start_box('Pricing Model');
            echo '<form action="" method="post">
				<fieldset>
					<input type="hidden" name="firesale" value="create" />
			';
            $firesale = array('fire_name' => ym_post('ym_new_firesale_name') ? ym_post('ym_new_firesale_name') : 'pricing_model_' . date('dMY_His', time()), 'fire_type' => ym_post('ym_new_firesale_type'));
            echo '<p>Creating a new Pricing Model: <strong>' . $firesale['fire_name'] . '</strong> of Type: <strong>' . $firetypes[$firesale['fire_type']] . '</strong></p>';
            echo '<input type="hidden" name="ym_new_firesale_name" value="' . $firesale['fire_name'] . '" />';
            echo '<input type="hidden" name="ym_new_firesale_type" value="' . $firesale['fire_type'] . '" />';
            echo '<table class="form-table">';
            switch ($firesale['fire_type']) {
                case 2:
                    // pppp pack
                    $packs = array();
                    foreach (ym_get_ppp_packs() as $pack) {
                        $packs[$pack->id] = $pack->name . ' (' . number_format($pack->cost, 2) . ')';
                    }
                    $ym_formgen->render_combo_from_array_row('Post Pack', 'ym_new_firesale_target_id', $packs, '', 'Which post pack to apply this Model to?');
                    $ym_formgen->render_form_table_radio_row('End Sale', 'ym_end_firesale_ppp', 0, 'Take Post Pack off Sale after Last Tier');
                    break;
                case 1:
                    // subsc
                    $packs = array();
                    foreach (ym_get_packs() as $pack) {
                        $packs[$pack['id']] = $pack['account_type'] . ' (' . $pack['duration'] . ' ' . $pack['duration_type'] . ') ' . $pack['cost'];
                    }
                    $ym_formgen->render_combo_from_array_row('Pack', 'ym_new_firesale_target_id', $packs, '', 'Which pack to apply this Model to?');
                    break;
                case 0:
                default:
                    // get all ppp's
                    $posts = array();
                    foreach (ym_get_all_ppp_posts() as $post) {
                        $posts[$post->ID] = $post->post_title;
                    }
                    $ym_formgen->render_combo_from_array_row('Post', 'ym_new_firesale_target_id', $posts, '', 'Which post to apply this Model to?');
                    $ym_formgen->render_form_table_radio_row('End Sale', 'ym_end_firesale_ppp', 0, 'Take Post off Sale after Last Tier');
                    break;
            }
            echo '<tr><td colspan="2"><p>Tiers</p></td></tr>';
            echo '<tr><td><a href="#addtier" id="ym_firesale_addtier">Click to Add Tier</a></td></tr>';
            echo '</table>';
            echo '<p class="submit" style="text-align: right;">
				<input type="submit" value="' . __('Create Pricing Model', 'ym') . ' &raquo;" />
			</p>';
            echo '</fieldset></form>';
            echo ym_end_box();
        } else {
            if ($firesale == 'create') {
                echo ym_start_box('Pricing Models');
                $firesale = array('fire_name' => ym_post('ym_new_firesale_name') ? ym_post('ym_new_firesale_name') : 'pricing_model_' . date('dMY_His', time()), 'fire_type' => ym_post('ym_new_firesale_type'), 'fire_type_id' => ym_post('ym_new_firesale_target_id'), 'fire_end_action' => ym_post('ym_end_firesale_ppp') ? ym_post('ym_end_firesale_ppp') : 0);
                // get tiers
                $fire_tiers = array();
                $limit_bys = ym_post('ym_new_firesale_limit_by');
                $limit_sales = ym_post('ym_new_firesale_limit_sales');
                $limit_dates = ym_post('ym_date_ym_new_firesale_limit_time');
                $limit_months = ym_post('ym_month_ym_new_firesale_limit_time');
                $limit_years = ym_post('ym_year_ym_new_firesale_limit_time');
                $limit_hours = ym_post('ym_hour_ym_new_firesale_limit_time');
                $limit_mins = ym_post('ym_min_ym_new_firesale_limit_time');
                $limit_by_hours = ym_post('ym_new_firesale_limit_hours');
                foreach (ym_post('ym_new_firesale_price') as $key => $tier_price) {
                    $fire_tiers[] = array('tier_price' => $tier_price, 'tier_limit_by' => $limit_bys[$key], 'tier_limit_sales' => $limit_sales[$key], 'tier_limit_time' => strtotime($limit_dates[$key] . ' ' . $months[$limit_months[$key]] . ' ' . $limit_years[$key] . ' ' . $limit_hours[$key] . ':' . $limit_mins[$key]), 'tier_limit_hours' => $limit_by_hours[$key]);
                }
                // DATABASE!
                $sql = 'INSERT INTO ' . $wpdb->ym_app_models . '(fire_name, fire_type, fire_type_id, fire_end_option) VALUES (\'' . $firesale['fire_name'] . '\', \'' . $firesale['fire_type'] . '\', \'' . $firesale['fire_type_id'] . '\', \'' . $firesale['fire_end_action'] . '\')';
                $wpdb->query($sql);
                if (FALSE !== ($firesale_id = $wpdb->insert_id)) {
                    echo '<p>Added the Pricing Models ' . $firesale['fire_name'];
                    // tiers
                    foreach ($fire_tiers as $key => $tier) {
                        $limit_var = 0;
                        switch ($tier['tier_limit_by']) {
                            case 2:
                                // hours
                                $limit_by = 2;
                                $limit_var = $tier['tier_limit_hours'];
                                break;
                            case 1:
                                // time
                                $limit_by = 1;
                                $limit_var = $tier['tier_limit_time'];
                                break;
                            case 0:
                            default:
                                //sales
                                $limit_by = 0;
                                $limit_var = $tier['tier_limit_sales'];
                        }
                        $sql = 'INSERT INTO ' . $wpdb->ym_app_models_tiers . '(fire_id, fire_price, fire_limit_by, fire_limit_var, fire_order)
						VALUES (
							' . $firesale_id . ',
							\'' . $tier['tier_price'] . '\',
							' . $limit_by . ',
							' . $limit_var . ',
							' . $key . '
						)';
                        $wpdb->query($sql);
                        if ($wpdb->insert_id) {
                            echo '<br />Tier Added';
                        }
                    }
                    echo '</p>';
                    echo '<meta http-equiv="refresh" content="3;' . YM_PPP_ADMIN_URL . '" />';
                } else {
                    echo '<p>There was a problem adding the Pricing Model: ' . $firesale['fire_name'] . '</p>';
                }
                echo ym_end_box();
            } else {
                // bad firesale function
            }
        }
    }
    echo '
		<div id="ym_firesale_add_post_tiers_form" style="display: none; clear: both;">';
    echo ym_start_box('Adding a Tier');
    echo '
		<form method="post" action="">
			<fieldset>
				<legend>Add a Tier to the selected Pricing Model</legend>
				<input type="hidden" name="ym_firesale_add_post_tiers_fire_id" id="ym_firesale_add_post_tiers_fire_id" />
				<input type="hidden" name="firesale" value="newtier" />
				
				<table id="ym_firesale_add_post_tiers">
				</table>
				
				<p class="submit" style="text-align: right;">
					<input type="submit" value="' . __('Add New Pricing Model Tier', 'ym') . ' &raquo;" />
				</p>
			</fieldset>
		</form>
		';
    echo ym_end_box();
    echo '
		</div>';
    echo '</div>';
    echo '<table id="ym_firesale_tier_source">';
    ym_fire_tier_form();
    echo '</table>';
}
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;
}
Example #7
0
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);
}
Example #8
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>';
}