get_results( $wpdb->prepare( "SELECT `thetime`, SUM(`clicks`) as `clicks`, SUM(`impressions`) as `impressions` FROM `" . $wpdb->prefix . "adrotate_stats` WHERE (`thetime` >= '" . $from . "' AND `thetime` <= '" . $until . "') AND `ad` = %d GROUP BY `thetime` ASC;", $id ), ARRAY_A ); $title = $wpdb->get_var( $wpdb->prepare( "SELECT `title` FROM `" . $wpdb->prefix . "adrotate` WHERE `id` = %d;", $id ) ); $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT `user` FROM `" . $wpdb->prefix . "adrotate_linkmeta` WHERE `ad` = %d;", $id ) ); $user = $wpdb->get_results( $wpdb->prepare( "SELECT `user_email`,`display_name` FROM `" . $wpdb->prefix . "users` WHERE `ID` = %d;", $user_id ), ARRAY_A ); $useremail = $user[0]['user_email']; $topic = array( "Report for ad '" . $title . "'" ); $siteurl = get_option('siteurl'); $email = get_option( 'admin_email' ); $x=0; foreach($ads as $ad) { // Prevent gaps in display if($ad['impressions'] == 0) $ad['impressions'] = 0; if($ad['clicks'] == 0) $ad['clicks'] = 0; // Build array $adstats[$x]['day'] = date_i18n("M d Y", $ad['thetime']); $adstats[$x]['clicks'] = $ad['clicks']; $adstats[$x]['impressions'] = $ad['impressions']; $x++; } $x= 0; $adstats1 = array(); foreach ( $ads as $ad ) { // Prevent gaps in display if ( $ad['impressions'] == 0 ) { $ad['impressions'] = 0; } if ( $ad['clicks'] == 0 ) { $ad['clicks'] = 0; } // Build array $adstats1['clicks'] += $ad['clicks']; $adstats1['impressions'] += $ad['impressions']; $x ++; } if($adstats1['clicks']==''){ $adstats1['clicks']=0; } if($adstats1['impressions']==''){ $adstats1['impressions']=0; } if($adstats1) { $dsp = "

 

"; $dsp .= ""; if ($adstats) { foreach ($adstats as $stat) { $dsp .= ""; } }else { $dsp .=""; } $dsp .="
" . $topic[0] . "
DayClicksImpressions
" . $stat['day'] . "" . $stat['clicks'] . "" . $stat['impressions'] . "
Data not Found
"; if(isset($useremail)) { if(get_option('dsp_subject')){ $subject = get_option('dsp_subject')." -" . $month . "/" . $year; }else { $subject = "Ad Report -" . $month . "/" . $year; } if(get_option('dsp_email_template')) { $message = get_option('dsp_email_template'); $message = str_replace('{aduser}',$user[0]['display_name'],$message); $message = str_replace('{adimpression}',$adstats1['impressions'],$message); $message = str_replace('{adclick}', $adstats1['clicks'],$message); $message = str_replace('{adreport}',$dsp,$message); }else{ $url= $siteurl."/wp-admin/admin.php?page=adrotate_email&message='error'"; wp_redirect($url); } $headers = "MIME-Version: 1.0\n" . "From: Paso Roble Daily News <".$email.">\r\n\n" . "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; if (wp_mail($useremail, $subject, $message, $headers)) { $html = '
'; $html .= '

'; $html .= 'Your Email Sent Successfully to '.$user[0]['display_name'].'.'; $html .= '

'; $html .= '
'; echo $html; }else{ $html = '
'; $html .= '

'; $html .= 'Your Email was not Sent to '.$user[0]['display_name'].'. please Try again.'; $html .= '

'; $html .= '
'; echo $html; } } else { $html = '
'; $html .= '

'; $html .= __( 'Please Add user to Ad for Send mail', 'add-rotate-email-addon' ); $html .= '

'; $html .= '
'; echo $html; } } } }