Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Template Name: User Dashboard
- *
- * This template must be assigned to a page
- * in order for it to work correctly
- *
- */
- auth_redirect_login(); // if not logged in, redirect to login page
- nocache_headers();
- global $userdata;
- get_currentuserinfo(); // grabs the user info and puts into vars
- // check to see if we want to pause or restart the ad
- if(!empty($_GET['action'])) :
- $d = trim($_GET['action']);
- $aid = trim($_GET['aid']);
- // make sure author matches ad. Prevents people from trying to hack other peoples ads
- $sql = $wpdb->prepare("SELECT wposts.post_author "
- . "FROM $wpdb->posts wposts "
- . "WHERE ID = $aid "
- . "AND post_author = $userdata->ID");
- $checkauthor = $wpdb->get_row($sql);
- if($checkauthor != null) { // author check is ok. now update ad status
- if ($d == 'pause') {
- $my_ad = array();
- $my_ad['ID'] = $aid;
- $my_ad['post_status'] = 'draft';
- wp_update_post($my_ad);
- } elseif ($d == 'restart') {
- $my_ad = array();
- $my_ad['ID'] = $aid;
- $my_ad['post_status'] = 'publish';
- wp_update_post($my_ad);
- } else {
- //echo "nothing here";
- }
- }
- endif;
- // return all the blog cat and sub cat ids so we can filter them out
- $blogcats = cp_get_blog_cat_ids();
- // retrieve all the ads for the current user and don't include blog posts
- /////////////////////////////////////////////////
- // remember to change the hardcoded cat ids!
- /////////////////////////////////////////////////
- $sql = "SELECT ID, post_title, post_name, post_status, post_date "
- . "FROM $wpdb->posts "
- . "WHERE post_author = $userdata->ID AND post_type = 'post' "
- . "AND (post_status = 'publish' OR post_status = 'pending' OR post_status = 'draft') "
- . "AND $wpdb->posts.ID NOT IN (
- SELECT tr.object_id
- FROM $wpdb->term_relationships AS tr
- INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
- WHERE tt.taxonomy = 'category'
- AND tt.term_id IN ($blogcats)
- ) "
- . "ORDER BY ID DESC";
- $pageposts = $wpdb->get_results($sql);
- $i = 1;
- ?>
- <?php get_header(); ?>
- <!-- CONTENT -->
- <div class="content">
- <div class="content_botbg">
- <div class="content_res">
- <!-- left block -->
- <div class="content_left">
- <div class="shadowblock_out">
- <div class="shadowblock">
- <h2 class="dotted"><span class="colour"><?php printf(__("%s's Dashboard", 'cp'), $userdata->user_login); ?></span></h2>
- <p><?php _e('Below you will find a listing of all your classified ads. Click on one of the options to perform a specific task. If you have any questions, please contact the site administrator.','cp');?></p>
- <table border="0" cellpadding="4" cellspacing="1" class="tblwide">
- <thead>
- <tr>
- <th width="5px"> </th>
- <th class="text-left"> <?php _e('Title','cp');?></th>
- <th><?php _e('Status','cp');?></th>
- <th width="80px"><div style="text-align: center;"><?php _e('Options','cp');?></div></th>
- </tr>
- </thead>
- <tbody>
- <?php if ($pageposts): ?>
- <?php foreach ($pageposts as $post): ?>
- <?php setup_postdata($post); ?>
- <?php
- // check to see if ad is legacy or not and then format date based on WP options
- if(get_post_meta($post->ID, 'expires', true))
- $expire_date = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime(get_post_meta($post->ID, 'expires', true)));
- else
- $expire_date = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime(get_post_meta($post->ID, 'cp_sys_expire_date', true)));
- // get the ad total cost and legacy check
- if (get_post_meta($post->ID, 'cp_totalcost', true))
- $total_cost = get_post_meta($post->ID, 'cp_totalcost', true);
- else
- $total_cost = get_post_meta($post->ID, 'cp_sys_total_ad_cost', true);
- // get the prune period and legacy check
- // if (get_post_meta($post->ID, 'cp_sys_ad_duration', true))
- // $prun_period = get_post_meta($post->ID, 'cp_sys_ad_duration', true);
- // else
- // $prun_period = get_option('cp_prun_period');
- // now let's figure out what the ad status and options should be
- // it's a live and published ad
- if ($post->post_status == 'publish') {
- $poststatus = __('Live','cp');
- $fontcolor = '#33CC33';
- $postimage = 'ad-pause.png';
- $postalt = __('pause ad','cp');
- $postaction = 'pause';
- // it's a pending ad which gives us several possibilities
- } elseif ($post->post_status == 'pending') {
- // ad is free and waiting to be approved
- if ($total_cost == 0) {
- $poststatus = __('awaiting approval','cp');
- $fontcolor = '#C00202';
- $postimage = '';
- $postalt = '';
- $postaction = 'pending';
- // ad hasn't been paid for yet
- } else {
- $poststatus = __('awaiting payment','cp');
- $fontcolor = '#C00202';
- $postimage = '';
- $postalt = '';
- $postaction = 'pending';
- }
- } elseif ($post->post_status == 'draft') {
- // current date is past the expires date so mark ad ended
- if (strtotime(date('Y-m-d H:i:s')) > (strtotime($expire_date))) {
- $poststatus = __('ended','cp') . '<br/><p class="small">(' . $expire_date . ')</p>';
- $fontcolor = '#666666';
- $postimage = '';
- $postalt = '';
- $postaction = 'ended';
- // ad has been paused by ad owner
- } else {
- $poststatus = __('offline','cp');
- $fontcolor = '#bbbbbb';
- $postimage = 'ad-start-blue.png';
- $postalt = __('restart ad','cp');
- $postaction = 'restart';
- }
- } else {
- $poststatus = '—';
- }
- ?>
- <tr class="even">
- <td class="text-right"><?php echo $i; ?>.</td>
- <td><h3>
- <?php if ($post->post_status == 'pending' || $post->post_status == 'draft' || $poststatus == 'ended' || $poststatus == 'offline') { ?>
- <?php the_title(); ?>
- <?php } else { ?>
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
- <?php } ?>
- </h3>
- <div class="meta"><?php the_category(', ') ?> | <?php the_time(get_option('date_format'))?></div>
- </td>
- <td class="text-center"><span style="color:<?php echo $fontcolor ?>;"><?php echo ucfirst($poststatus) ?></span></td>
- <td class="text-center">
- <?php
- if ($post->post_status == 'pending' && $postaction != 'ended') {
- // show the paypal button if the ad has not been paid for yet
- if ($total_cost != 0) {
- echo cp_dashboard_paypal_button($post->ID, 'dashboard');
- } else {
- echo '—';
- }
- } elseif ($post->post_status == 'draft' && $postaction == 'ended') {
- if (get_option('cp_allow_relist') == 'yes') {
- // show the paypal button so they can relist their ad only
- // if it's not a legacy ad and they originally paid to list
- if (($total_cost != 0) && get_post_meta($post->ID, 'cp_totalcost', true) == '') {
- echo cp_dashboard_paypal_button($post->ID, 'dashboard');
- echo __('Relist Ad', 'cp');
- } else {
- echo '—';
- }
- } else {
- echo '—';
- }
- } else { ?>
- <a href="<?php echo CP_EDIT_URL; ?>?aid=<?php the_id(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/pencil.png" title="" alt="" border="0" /></a>
- <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=<?php echo $postaction; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $postimage; ?>" title="" alt="" border="0" /></a>
- <?php } ?>
- </td>
- </tr>
- <?php
- $i++;
- endforeach;
- ?>
- <?php else : ?>
- <tr class="even">
- <td colspan="4">
- <div class="pad10"></div>
- <p class="text-center"><?php _e('You currently have no classified ads.','cp');?></p>
- <div class="pad25"></div>
- </td>
- </tr>
- <?php endif; ?>
- </tbody>
- </table>
- </div><!-- /shadowblock -->
- </div><!-- /shadowblock_out -->
- </div><!-- /content_left -->
- <?php get_sidebar('user'); ?>
- <div class="clr"></div>
- </div><!-- /content_res -->
- </div><!-- /content_botbg -->
- </div><!-- /content -->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement