Advertisement
Guest User

escritorio.php

a guest
May 17th, 2010
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.91 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Template Name: User Dashboard
  4.  *
  5.  * This template must be assigned to a page
  6.  * in order for it to work correctly
  7.  *
  8. */
  9.  
  10. auth_redirect_login(); // if not logged in, redirect to login page
  11. nocache_headers();
  12.  
  13. global $userdata;
  14. get_currentuserinfo(); // grabs the user info and puts into vars
  15.  
  16. // check to see if we want to pause or restart the ad
  17. if(!empty($_GET['action'])) :
  18.     $d = trim($_GET['action']);
  19.     $aid = trim($_GET['aid']);
  20.  
  21.     // make sure author matches ad. Prevents people from trying to hack other peoples ads
  22.     $sql = $wpdb->prepare("SELECT wposts.post_author "
  23.        . "FROM $wpdb->posts wposts "
  24.        . "WHERE ID = $aid "
  25.        . "AND post_author = $userdata->ID");
  26.  
  27.     $checkauthor = $wpdb->get_row($sql);
  28.  
  29.     if($checkauthor != null) { // author check is ok. now update ad status
  30.  
  31.         if ($d == 'pause') {
  32.             $my_ad = array();
  33.             $my_ad['ID'] = $aid;
  34.             $my_ad['post_status'] = 'draft';
  35.             wp_update_post($my_ad);
  36.  
  37.         } elseif ($d == 'restart') {
  38.             $my_ad = array();
  39.             $my_ad['ID'] = $aid;
  40.             $my_ad['post_status'] = 'publish';
  41.             wp_update_post($my_ad);
  42.  
  43.         } else {
  44.             //echo "nothing here";
  45.         }
  46.  
  47.     }
  48.  
  49. endif;
  50.  
  51.  
  52. // return all the blog cat and sub cat ids so we can filter them out
  53. $blogcats = cp_get_blog_cat_ids();
  54.  
  55. // retrieve all the ads for the current user and don't include blog posts
  56. /////////////////////////////////////////////////
  57. // remember to change the hardcoded cat ids!
  58. /////////////////////////////////////////////////
  59. $sql = "SELECT ID, post_title, post_name, post_status, post_date "
  60.      . "FROM $wpdb->posts "
  61.      . "WHERE post_author = $userdata->ID AND post_type = 'post' "
  62.      . "AND (post_status = 'publish' OR post_status = 'pending' OR post_status = 'draft') "
  63.      . "AND $wpdb->posts.ID NOT IN (
  64.            SELECT tr.object_id
  65.            FROM $wpdb->term_relationships AS tr
  66.            INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
  67.            WHERE tt.taxonomy = 'category'
  68.            AND tt.term_id IN ($blogcats)
  69.            ) "
  70.      . "ORDER BY ID DESC";
  71.  
  72.  
  73. $pageposts = $wpdb->get_results($sql);
  74.  
  75. $i = 1;
  76. ?>
  77.  
  78. <?php get_header(); ?>
  79.  
  80.  
  81. <!-- CONTENT -->
  82.   <div class="content">
  83.  
  84.     <div class="content_botbg">
  85.  
  86.       <div class="content_res">
  87.  
  88.  
  89.         <!-- left block -->
  90.         <div class="content_left">
  91.  
  92.             <div class="shadowblock_out">
  93.             <div class="shadowblock">
  94.  
  95.                 <h2 class="dotted"><span class="colour"><?php printf(__("%s's Dashboard", 'cp'), $userdata->user_login); ?></span></h2>
  96.  
  97.                 <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>
  98.  
  99.                 <table border="0" cellpadding="4" cellspacing="1" class="tblwide">
  100.                     <thead>
  101.                         <tr>
  102.                             <th width="5px">&nbsp;</th>
  103.                             <th class="text-left">&nbsp;<?php _e('Title','cp');?></th>
  104.                             <th><?php _e('Status','cp');?></th>
  105.                             <th width="80px"><div style="text-align: center;"><?php _e('Options','cp');?></div></th>
  106.                         </tr>
  107.                     </thead>
  108.                     <tbody>
  109.  
  110.                     <?php if ($pageposts): ?>
  111.  
  112.                         <?php foreach ($pageposts as $post): ?>
  113.  
  114.                         <?php setup_postdata($post); ?>
  115.  
  116.                         <?php                    
  117.                             // check to see if ad is legacy or not and then format date based on WP options
  118.                             if(get_post_meta($post->ID, 'expires', true))
  119.                                 $expire_date = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime(get_post_meta($post->ID, 'expires', true)));
  120.                             else
  121.                                 $expire_date = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime(get_post_meta($post->ID, 'cp_sys_expire_date', true)));
  122.  
  123.                            
  124.                             // get the ad total cost and legacy check
  125.                             if (get_post_meta($post->ID, 'cp_totalcost', true))
  126.                                 $total_cost = get_post_meta($post->ID, 'cp_totalcost', true);
  127.                             else
  128.                                 $total_cost = get_post_meta($post->ID, 'cp_sys_total_ad_cost', true);
  129.  
  130.                             // get the prune period and legacy check
  131.                             //  if (get_post_meta($post->ID, 'cp_sys_ad_duration', true))
  132.                             //      $prun_period = get_post_meta($post->ID, 'cp_sys_ad_duration', true);
  133.                             //  else
  134.                             //      $prun_period = get_option('cp_prun_period');
  135.  
  136.  
  137.                             // now let's figure out what the ad status and options should be
  138.                             // it's a live and published ad
  139.                             if ($post->post_status == 'publish') {
  140.  
  141.                                 $poststatus = __('Live','cp');
  142.                                 $fontcolor = '#33CC33';
  143.                                 $postimage = 'ad-pause.png';
  144.                                 $postalt =  __('pause ad','cp');
  145.                                 $postaction = 'pause';
  146.  
  147.                             // it's a pending ad which gives us several possibilities
  148.                             } elseif ($post->post_status == 'pending') {
  149.  
  150.  
  151.                                 // ad is free and waiting to be approved
  152.                                 if ($total_cost == 0) {
  153.                                     $poststatus = __('awaiting approval','cp');
  154.                                     $fontcolor = '#C00202';
  155.                                     $postimage = '';
  156.                                     $postalt = '';
  157.                                     $postaction = 'pending';
  158.  
  159.                                 // ad hasn't been paid for yet
  160.                                 } else {
  161.                                     $poststatus = __('awaiting payment','cp');
  162.                                     $fontcolor = '#C00202';
  163.                                     $postimage = '';
  164.                                     $postalt = '';
  165.                                     $postaction = 'pending';
  166.                                 }
  167.  
  168.                                
  169.  
  170.                             } elseif ($post->post_status == 'draft') {
  171.  
  172.                                 // current date is past the expires date so mark ad ended
  173.                                 if (strtotime(date('Y-m-d H:i:s')) > (strtotime($expire_date))) {
  174.                                     $poststatus = __('ended','cp') . '<br/><p class="small">(' . $expire_date . ')</p>';
  175.                                     $fontcolor = '#666666';
  176.                                     $postimage = '';
  177.                                     $postalt = '';
  178.                                     $postaction = 'ended';
  179.  
  180.                                 // ad has been paused by ad owner
  181.                                 } else {
  182.                                     $poststatus = __('offline','cp');
  183.                                     $fontcolor = '#bbbbbb';
  184.                                     $postimage = 'ad-start-blue.png';
  185.                                     $postalt = __('restart ad','cp');
  186.                                     $postaction = 'restart';
  187.                                 }
  188.  
  189.                             } else {
  190.                                     $poststatus = '&mdash;';
  191.                             }
  192.                         ?>
  193.  
  194.  
  195.                         <tr class="even">
  196.                             <td class="text-right"><?php echo $i; ?>.</td>
  197.                             <td><h3>
  198.                                 <?php if ($post->post_status == 'pending' || $post->post_status == 'draft' || $poststatus == 'ended' || $poststatus == 'offline') { ?>
  199.  
  200.                                     <?php the_title(); ?>
  201.  
  202.                                 <?php } else { ?>
  203.  
  204.                                     <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  205.  
  206.                                 <?php } ?>    
  207.                                 </h3>
  208.  
  209.                                 <div class="meta"><?php the_category(', ') ?> | <?php the_time(get_option('date_format'))?></div>
  210.  
  211.                             </td>
  212.  
  213.                             <td class="text-center"><span style="color:<?php echo $fontcolor ?>;"><?php echo ucfirst($poststatus) ?></span></td>
  214.  
  215.                             <td class="text-center">
  216.                                 <?php
  217.  
  218.                                 if ($post->post_status == 'pending' && $postaction != 'ended') {
  219.  
  220.                                     // show the paypal button if the ad has not been paid for yet
  221.                                     if ($total_cost != 0) {
  222.                                         echo cp_dashboard_paypal_button($post->ID, 'dashboard');
  223.                                     } else {
  224.                                         echo '&mdash;';
  225.                                     }
  226.  
  227.                                 } elseif ($post->post_status == 'draft' && $postaction == 'ended') {
  228.  
  229.                                     if (get_option('cp_allow_relist') == 'yes') {
  230.                                         // show the paypal button so they can relist their ad only
  231.                                         // if it's not a legacy ad and they originally paid to list
  232.                                         if (($total_cost != 0) && get_post_meta($post->ID, 'cp_totalcost', true) == '') {
  233.                                             echo cp_dashboard_paypal_button($post->ID, 'dashboard');
  234.                                             echo __('Relist Ad', 'cp');
  235.                                         } else {
  236.                                             echo '&mdash;';
  237.                                         }
  238.                                     } else {
  239.                                         echo '&mdash;';
  240.                                     }
  241.  
  242.  
  243.                                 } else { ?>
  244.  
  245.                               <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>&nbsp;&nbsp;
  246.                               <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;action=<?php echo $postaction; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $postimage; ?>" title="" alt="" border="0" /></a>
  247.  
  248.                           <?php } ?>
  249.  
  250.  
  251.                             </td>
  252.                         </tr>
  253.  
  254.                         <?php
  255.                         $i++;
  256.                    
  257.                         endforeach;
  258.                         ?>
  259.  
  260.                     <?php else : ?>
  261.  
  262.                         <tr class="even">
  263.                             <td colspan="4">
  264.  
  265.                                 <div class="pad10"></div>
  266.  
  267.                         <p class="text-center"><?php _e('You currently have no classified ads.','cp');?></p>
  268.  
  269.                         <div class="pad25"></div>
  270.  
  271.                         </td>
  272.                         </tr>
  273.  
  274.                     <?php endif; ?>
  275.  
  276.  
  277.                     </tbody>
  278.                 </table>
  279.  
  280.  
  281.  
  282.             </div><!-- /shadowblock -->
  283.  
  284.             </div><!-- /shadowblock_out -->
  285.  
  286.  
  287.  
  288.         </div><!-- /content_left -->
  289.  
  290.  
  291.         <?php get_sidebar('user'); ?>
  292.  
  293.         <div class="clr"></div>
  294.  
  295.  
  296.       </div><!-- /content_res -->
  297.  
  298.     </div><!-- /content_botbg -->
  299.  
  300.   </div><!-- /content -->
  301.  
  302.  
  303. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement