Advertisement
dangavin

Delete Entries based on Payment Status & Entry Time

Oct 2nd, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.10 KB | None | 0 0
  1. /*
  2.  * Check all of our Entries that have been created.
  3.  * If they are 24 hours old & Payment Status is
  4.  * processing then we will delete them, and automatically
  5.  * re-open our Gravity Form.
  6.  *
  7.  * Dan Gavin
  8.  */
  9.  
  10. function gf_published_entry_time( $entry, $form ) {
  11.  
  12.     global $wpdb;
  13.    
  14.     // Get all Entries for our form ID 1
  15.     $entries =  RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
  16.     foreach ($entries as $entry){
  17.        
  18.         // Check to see if the User has paid or not
  19.  
  20.         // Created on
  21.         $time = strtotime($entry['date_created']);
  22.         // Time on Day Ago
  23.         $sub_time = '-24 hour';
  24.         $add_time = '+24 hour';
  25.         $one_day_ago = strtotime($sub_time);
  26.        
  27.         if(
  28.             $entry['payment_status'] == 'Processing' &&
  29.             $time >= $one_day_ago
  30.         ){
  31.        
  32.         // This is here because I am showing the exact time of creation, is there a workaround?
  33.         if ( function_exists( 'date_default_timezone_set' ) )
  34.             date_default_timezone_set('America/Chicago'); //this overwrite all settings!!
  35.            
  36.         // It's sooner than 24 hours, so let's show a counter and expiration date
  37.         $time_left = $time - $one_day_ago;
  38.         $days_left = floor($time_left / 86400); // 86400 = seconds per day
  39.         $hours_left = floor(($time_left - $days_left * 86400) / 3600); // 3600 = seconds per hour
  40.         $mins_left = floor(($time_left - $days_left - $hours_left * 3600) / 60); // 60 = seconds per min
  41.         echo '<b>'.$entry["6.3"].' '.$entry["6.6"].'</b>';
  42.         echo '<br/>Created on: '.date_i18n('M d, Y h:i a', $time);
  43.         $total_time = strtotime($add_time, $time);
  44.         echo "<br/>$hours_left hours & $mins_left min remaining";
  45.         echo '<br/><i>This entry will be deleted on '.date_i18n('M d, Y h:i a', $total_time).'</i><br/><br/>';
  46.        
  47.         // This is here because I am showing the exact time of creation, is there a workaround?
  48.         // This resets the timezone, without this it messes up the counters...
  49.         if ( function_exists( 'date_default_timezone_set' ) )
  50.             date_default_timezone_set('UTC'); //this overwrite all settings!!
  51.            
  52.         } else {
  53.        
  54.             echo '<p><b>'.$entry["6.3"].' '.$entry["6.6"].'</b> hase been deleted.</p>';
  55.             // Get our Leads
  56.             $lead_id                = $entry['id'];
  57.             $lead_table             = RGFormsModel::get_lead_table_name();
  58.             $lead_notes_table       = RGFormsModel::get_lead_notes_table_name();
  59.             $lead_detail_table      = RGFormsModel::get_lead_details_table_name();
  60.             $lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();
  61.        
  62.             // Delete from detail long
  63.             $sql = $wpdb->prepare( " DELETE FROM $lead_detail_long_table
  64.                                     WHERE lead_detail_id IN(
  65.                                     SELECT id FROM $lead_detail_table WHERE lead_id=%d
  66.                                     )", $lead_id );
  67.             $wpdb->query( $sql );
  68.        
  69.             // Delete from lead details
  70.             $sql = $wpdb->prepare( "DELETE FROM $lead_detail_table WHERE lead_id=%d", $lead_id );
  71.             $wpdb->query( $sql );
  72.        
  73.             // Delete from lead notes
  74.             $sql = $wpdb->prepare( "DELETE FROM $lead_notes_table WHERE lead_id=%d", $lead_id );
  75.             $wpdb->query( $sql );
  76.        
  77.             // Delete from lead
  78.             $sql = $wpdb->prepare( "DELETE FROM $lead_table WHERE id=%d", $lead_id );
  79.             $wpdb->query( $sql );
  80.            
  81.         }
  82.     }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement