<?php

echo '	<div class="wrap" id="poststuff">';
ym_coupon_update();
if ($coupon_id = ym_get('coupon_id')) {
    $coupon = ym_get_coupon($coupon_id);
    if (ym_post('edit')) {
        echo ym_start_box(__('Edit coupon: "', 'ym') . $coupon->name . '"');
        ym_render_coupon_edit($coupon_id);
        echo ym_end_box();
    }
    if (ym_post('view')) {
        echo ym_start_box(__('View Users who used Coupon: "', 'ym') . $coupon->name . '"');
        ym_render_coupon_view($coupon_id);
        echo '<form method="POST">
		<input type="hidden" name="ym_coupon_id" value="' . $coupon_id . '" />
		<input class="button" type="submit" name="ym_start_xls_coupon" value="' . __('Export Data', 'ym') . '" />
		 </form>';
        echo ym_end_box();
    }
} else {
    echo ym_start_box(__('Coupon', 'ym'));
    ym_render_coupons();
    echo ym_end_box();
}
echo '</div>';
function yss_s3_list()
{
    get_currentuserinfo();
    global $yss_db, $wpdb, $date_format, $current_user;
    $header_style = 'border-bottom: 1px solid silver; font-weight: bold;';
    $sql = 'SELECT *
			FROM ' . $yss_db . ' 
			ORDER BY id';
    $s3s = $wpdb->get_results($sql);
    echo ym_start_box('Videos');
    echo '<p>' . __('Videos can be associated with content or Package types. When associated, they take on the page or post permissions including post purchased. Non associated videos are accessible by all.', 'yss') . '</p>';
    echo '<p>' . __('YSS will attempt to use Streaming, then Download and finally S3', 'yss') . '</p>';
    echo '<p>' . __('Note: YSS does not support non FLV files in a streaming distribution under FlowPlayer. It just does not work!', 'yss') . '</p>';
    echo '	<table class="widefat form-table" style="width: 100%;" cellspacing="0">
			<thead>
			<tr>
				<td style="' . $header_style . '">' . __('ID', 'yss') . '</td>
				<td style="' . $header_style . '">' . __('Bucket', 'yss') . '</td>
				<td style="' . $header_style . '">' . __('Resource Path', 'yss') . '</td>
				<td style="' . $header_style . '">' . __('Distribution', 'yss') . '</td>
				<td style="' . $header_style . ' width: 150px; text-align: center;">' . __('Limited Access (<span title="Video protected by Your Members Package Types">ACs</span>)', 'yss') . '</td>
				<td style="' . $header_style . ' width: 150px; text-align: center;">' . __('Limited Access (<span title="Video protected via access to Posts/Pages protected by YM">Posts</span>)', 'yss') . '</td>
				<td style="' . $header_style . '">' . __('Posted', 'yss') . '</td>
				<td style="' . $header_style . '">' . __('Action', 'yss') . '</td>
			</tr>
			</thead>
			<tbody>';
    if ($s3s) {
        foreach ($s3s as $s3) {
            $date = date($date_format, strtotime($s3->postDate));
            //			$user = get_userdata($s3->user);
            $stream_distribute = YM_ADMIN_INDEX_URL . '&ym_page=ym-hook-yss_content&task=stream&id=' . $s3->id;
            $download_distribute = YM_ADMIN_INDEX_URL . '&ym_page=ym-hook-yss_content&task=dload&id=' . $s3->id;
            $dl = $s = 'No';
            if ($s3->distribution) {
                $distribution = json_decode($s3->distribution);
                if (isset($distribution->download) && $distribution->download) {
                    $dl = 'Yes';
                }
                if (isset($distribution->streaming) && $distribution->streaming) {
                    $s = 'Yes';
                }
            }
            echo '<tr>
					<td>' . $s3->id . '</td>
					<td>' . $s3->bucket . '</td>
					<td>' . $s3->resource_path . '</td>
					<td>
					';
            if (!get_option('yss_cloudfront_id') || !get_option('yss_cloudfront_private')) {
                echo '
						N/A
					';
            } else {
                echo '
						DL: <a href="' . $download_distribute . '">' . $dl . '</a>
						S: <a href="' . $stream_distribute . '">' . $s . '</a>
					';
            }
            echo '
					</td>
					<td style="text-align:center; font-weight: bold;">
						' . ($s3->account_types ? __('<span style="color: green;">' . implode(', ', explode('||', $s3->account_types)) . '</span>', 'yss') : __('<span style="color: red;">No</span>', 'yss')) . '
					</td>					
					<td style="text-align:center; font-weight: bold;">
						' . ($s3->members ? __('<span style="color: green;">Yes</span>', 'yss') : __('<span style="color: red;">No</span>', 'yss')) . '
					</td>
					<td>' . $date . ' by ' . $current_user->user_login . '</td>
					<td style="line-height: 2em;">
						<a href="' . YM_ADMIN_INDEX_URL . '&ym_page=ym-hook-yss_content&task=edit&id=' . $s3->id . '">Edit</a> | <a href="' . YM_ADMIN_INDEX_URL . '&ym_page=ym-hook-yss_content&task=delete&id=' . $s3->id . '" class="deletelink">Delete</a>
					</td>
				</tr>
				';
        }
    } else {
        echo '	<tr>
				<td colspan="6">' . __('You have yet to add any videos.', 'yss') . '</td>
			</tr>';
    }
    echo '</tbody>';
    echo '			</table>';
    echo '<input type="hidden" name="id" id="yss_edit_id" value="" />';
    echo '
<p class="submit" style="text-align: right;">
	<input type="hidden" name="task" value="add" />
	<input type="submit" value="Add New Video" />
</p>';
    echo ym_end_box();
}
function ym_membership_content_page($with_boxes = false, $with_snippets = TRUE, $with_expires = FALSE, $show = 'posts,bundles,premium')
{
    get_currentuserinfo();
    global $current_user, $wpdb, $ym_res;
    $snippet_length = 200;
    $max_loops = 30;
    $html = '';
    $membership_level = ym_get_user_package_type($current_user->ID);
    $posts = false;
    $show = explode(',', $show);
    if (in_array('posts', $show)) {
        if ($pp = ym_render_my_purchased_posts($current_user->ID, false, true, $with_expires, $with_snippets)) {
            if ($with_boxes) {
                $html .= ym_start_box(__('My Purchased Posts', 'ym'));
            }
            $html .= $pp;
            if ($with_boxes) {
                $html .= ym_end_box();
            }
        }
    }
    if (in_array('bundles', $show)) {
        // bundle
        if ($bundles = ym_render_my_purchased_bundles($current_user->ID, $with_expires, TRUE, $with_snippets)) {
            if ($with_boxes) {
                $html .= ym_start_box(__('My Purchased Bundles', 'ym'));
            }
            $html .= $bundles;
            if ($with_boxes) {
                $html .= ym_end_box();
            }
        }
    }
    if (in_array('premium', $show)) {
        $sql = 'SELECT DISTINCT(ID), post_title, post_date, post_content
				FROM
					' . $wpdb->posts . ' p
					JOIN ' . $wpdb->postmeta . ' pm ON (
						p.ID = pm.post_id
						AND p.post_status = "publish"
						AND pm.meta_key = "_ym_account_type"
						AND pm.meta_value LIKE "%' . $membership_level . '%"
						AND post_type = "post"
					)
				ORDER BY post_date DESC';
        $results = $wpdb->get_results($sql);
        $loops = 0;
        if ($members_pages = count($results)) {
            foreach ($results as $id => $obj) {
                if (!ym_user_has_access($obj->ID)) {
                    $membership_pages--;
                    continue;
                }
                $published = date(YM_DATEFORMAT, strtotime($obj->post_date));
                $full_content = apply_filters('the_content', $obj->post_content);
                $title = $obj->post_title;
                if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
                    $title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($title);
                    $full_content = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($full_content);
                }
                $row = '<tr>
				<td style="border-top: 1px solid silver;">
					<div style="margin-bottom: 5px;"><a href="' . get_permalink($obj->ID) . '">' . $title . '</a></div>
					';
                if ($with_snippets) {
                    $content = substr(strip_tags($full_content), 0, $snippet_length);
                    //$content = preg_replace("'\[/?\s?private\s?\]'i",'', $content);
                    $ending = strlen($full_content) > strip_tags($snippet_length) ? '...' : '';
                    $row .= '<div style="font-size: 10px; margin-bottom: 5px;">' . $content . $ending . '</div>';
                }
                $row .= '
				</td>
				<td style="vertical-align: top; border-top: 1px solid silver;">' . $published . '</td>
			</tr>';
                $posts .= $row;
                $loops++;
                if ($loops >= $max_loops) {
                    break;
                }
            }
        }
        $table_intro = 'Showing the most recent ' . $loops . ' posts of a total ' . $members_pages . ' available to you.';
        $html .= $ym_res->members_content_divider_html;
        if ($with_boxes) {
            $html .= ym_start_box(__('Premium Content', 'ym'));
        }
        $html .= '	<div class="premium_content_intro">' . __('Your membership level is:', "ym") . ' <strong>' . $membership_level . '</strong>. 	
				' . __('You have access to a total of', "ym") . ' ' . $members_pages . ' ' . __('premium', 'ym') . ' ' . ($members_pages == 1 ? __('post', 'ym') : __('posts', 'ym')) . ' 
			</div>';
        if ($members_pages > 0) {
            $html .= $table_intro;
            $html .= '<div style="padding-top: 10px; margin-bottom: 10px;">
				<table style="width: 100%" cellspacing="0" cellpadding="2">
				<tr>
					<th style="text-align: left;">Post Title</th>
					<th style="width: 160px; text-align: left;">Published</th>
				</tr>
					' . $posts . '
			</table></div>';
        }
        if ($with_boxes) {
            $html .= ym_end_box();
        }
    }
    return $html;
}
function ym_show_generic_log($log_type_id = false, $user_id = false)
{
    if ($actions = ym_get_transaction_actions($log_type_id)) {
        foreach ($actions as $i => $log_type) {
            echo ym_start_box($log_type->name);
            echo '<p>' . $log_type->description . '</p>';
            if ($transactions = ym_get_all_logs($log_type->id, $user_id)) {
                echo '<table class="ym_table form-table">
				<thead>
					<tr>';
                if (!$user_id) {
                    echo '	<th>' . __('User ID', 'ym') . '</th>
				<th>' . __('User', 'ym') . '</th>
				<th>' . __('User Email', 'ym') . '</th>';
                }
                echo '		<th>' . __('Log Type', 'ym') . '</th>
				<th>' . __('Data', 'ym') . '</th>
				<th>' . __('Date', 'ym') . '</th>
					</tr>
				</thead>
				<tbody>';
                foreach ($transactions as $transaction) {
                    $mod = unserialize($transaction->data);
                    if (!$user_id) {
                        $user = get_userdata($transaction->user_id);
                    }
                    echo '<tr>';
                    if (!$user_id) {
                        echo '	<td>' . $transaction->user_id . '</td>
							<td><a alt="View user profile" title="View user profile" href="' . YM_ADMIN_URL . 'user-edit.php?user_id=' . $transaction->user_id . '" target="_top">' . $user->user_login . '</a></td>
							<td>' . $user->user_email . '</td>';
                    }
                    echo '	<td>' . (is_array($mod) ? '<pre>' . print_r($mod, true) . '</pre>' : $mod) . '</td>
						<td>' . date(YM_DATE, $transaction->unixtime + get_option('gmt_offset') * 3600) . '</td>
					</tr>';
                }
                echo '</tbody>
				</table>';
            } else {
                echo __('<em>There are no logs for this type.</em>', 'ym');
            }
            echo ym_end_box();
        }
    }
}
<?php

/*
* $Id: ym-profile_content.php 1670 2011-12-16 14:12:47Z BarryCarlyon $
* $Revision: 1670 $
* $Date: 2011-12-16 14:12:47 +0000 (Fri, 16 Dec 2011) $
*/
get_currentuserinfo();
global $current_user, $ym_res;
$html = '';
$html .= '<div class="wrap" id="poststuff">
	<h2>' . __('Members Content', 'ym') . '</h2>';
$html .= ym_membership_content_page(true);
$html .= @$ym_res->members_content_divider2_html;
if (current_user_can('publish_posts')) {
    $html .= ym_start_box(__('My Sold Posts', 'ym'));
    $html .= __('<p>This section displays a list of the posts and pages that you have authored and have sold.</p>', 'ym');
    echo $html;
    $html = '';
    ym_render_all_posts_purchased(false, false, $current_user->ID);
    $html .= ym_end_box();
}
$html .= '</div>';
echo $html;
Beispiel #6
0
 function ym_email_message_content()
 {
     $invoice = new ym_invoice();
     echo '<div id="ym_payment_gateway_invoice">';
     echo ym_start_box(__('Invoice Gateway Emails', 'ym'));
     echo '<table class="form-table">';
     global $ym_formgen;
     $ym_formgen->render_form_table_text_row(__('Invoice Email Subject', 'ym'), 'invoice_email_subject', $invoice->invoice_email_subject, __('When sending a Invoice Email use this subject, supports [blogname]', 'ym'));
     $ym_formgen->render_form_table_wp_editor_row(__('Invoice Email Message', 'ym'), 'invoice_email_message', $invoice->invoice_email_message, __('Use this message, supports [user_name], [pack_name], [pack_cost] (includes Currency Code), [pay_days], [ym_user_custom], [ym_user_is], [ym_user_is_not], [ym_user_custom_is] and [ym_user_custom_is_not]', 'ym'));
     echo '</table>';
     echo ym_end_box();
     echo '</div>';
 }
Beispiel #7
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_download_list()
{
    get_currentuserinfo();
    global $ym_dl_db, $wpdb, $date_format, $current_user, $ym_upload_root;
    if (!is_dir($ym_upload_root)) {
        if (@mkdir($ym_upload_root, 0664)) {
            ym_display_message(__('The uploads directory did not exist so it was created and the permissions set to 664. Please make sure to update these permissions if you are not happy with them.'));
        } else {
            ym_display_message(__('The uploads directory does not exist and it could not be created. Please make sure that "' . $ym_upload_root . '" is present and writeable by PHP before adding any downloads.', 'ym'), 'error');
        }
    }
    $header_style = 'border-bottom: 1px solid silver; font-weight: bold;';
    $downloadurl = get_option('ym_dl_url');
    $downloadtype = get_option('ym_dl_type');
    $sort = ym_request('sort', "title");
    $sql = 'SELECT *
			FROM ' . $ym_dl_db . ' 
			ORDER BY ' . $sort;
    $download = $wpdb->get_results($sql);
    echo '<p>' . __('Downloads can be associated with pages and posts. When associated, they take on the page or post permissions including post purchased. Non associated downloads are accessible by all.', 'ym') . '</p>';
    echo ym_start_box('All Downloads');
    if (!is_writeable($ym_upload_root)) {
        ym_display_message(__('The uploads directory is not writeable by PHP and therefore anything uploaded using this tool will fail. Please set the permissions and then refresh this page to see if you have been successful.', 'ym'), 'error');
    }
    echo '			<table style="width: 100%;" cellspacing="0" class="ym_table">
						<tr>
							<th><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=id">' . __('ID', "ym") . '</a></td>
							<th><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=title">' . __('Title', "ym") . '</a></td>
							<th><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=filename">' . __('File', "ym") . '</a></td>
							<th style="width: 150px; text-align: center;">' . __('Limited Access', "ym") . '</td>
							<th style="width: 140px; text-align: center;">' . __('File Exists?', "ym") . '</td>
							<th style="width: 200px;"><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=postDate">' . __('Posted', "ym") . '</a></td>
							<th style="width: 130px;">' . __('Action', "ym") . '</td>
						</tr>';
    if ($download) {
        foreach ($download as $d) {
            $date = date($date_format, strtotime($d->postDate));
            $path = get_option('siteurl') . "/wp-content/uploads/";
            $file = str_replace($path, "", $d->filename);
            $links = explode("/", $file);
            $file = end($links);
            $user = get_userdata($d->user);
            $abs_file = ym_get_abs_file($d->filename);
            $edit_link = YM_ADMIN_URL . '&ym_page=ym-content-downloads&action=edit&id=' . $d->id . '&sort=' . $sort;
            $delete_link = YM_ADMIN_URL . '&ym_page=ym-content-downloads&action=delete&id=' . $d->id . '&sort=' . $sort;
            echo '	<tr>
						<td>' . $d->id . '</td>
						<td>' . $d->title . '</td>
						<td>' . $file . '</td>
						<td style="text-align:center; font-weight: bold;">
							' . ($d->members ? __('<span style="color: green;">Yes</span>', 'ym') : __('<span style="color: red;">No</span>', 'ym')) . '
						</td>
						<td style="text-align:center; font-weight: bold;">
							' . (file_exists($abs_file) ? __('<span style="color: green;">Yes</span>', 'ym') : __('<span style="color: red;">No</span>', 'ym')) . '
						</td>
						<td>' . $date . ' by ' . $current_user->user_login . '</td>
						<td style="line-height: 2em;">
							<a class="button" href="' . $edit_link . '">' . __('Edit', 'ym') . '</a>
							<a class="button" href="' . $delete_link . '">' . __('Delete', 'ym') . '</a>
						</td>
					</tr>';
        }
    } else {
        echo '	<tr>
					<td colspan="6">' . __('No downloads have been added yet.', "ym") . '</td>
				</tr>';
    }
    echo '			</table>';
    echo '	<p class="submit">
				<form action=""	method="post" id="ym_dl_add" name="add_download">
					<input type="hidden" name="action" value="add" />
					<input type="submit" class="button" name="" value="' . __('Add New Download', "ym") . '" />
				</form>
			</p>';
    echo ym_end_box();
}