Create($crm_db,$crm_user,$crm_host,$crm_pass); $cdc = new MySQL_class; $cdc->Create($cdc_db,$cdc_user,$cdc_host,$cdc_pass); require_once('JSON.php'); $json = new Services_JSON(); //********** return info if($info) { header("location: https://store.dwalliance.com/news/view_article.html?article_id=13976cb80d3e0bcaf0b8e21a0d870ab0"); exit(); } //********** check login if(check_login_email($email,$password,$code,$cdc)) { el("success"); $u_id = get_uid_email($email,$password,$code,$cdc); } else { echo"DWERROR: Login failed."; exit(); } //********* Create or Update a List if($create_list || $update_list) { $list_name = trim($list_name); if(!$list_name) { echo("DWERROR: no email list name"); exit(); } $emp_id = get_end_user_uid_email($owner_email,$code,$cdc); if(!$list_id) { $list_id = make_rand(); $query = "insert into $BLASTER_LIST_NAME set blaster_list_id = '$list_id', list_name = '".addslashes($list_name)."', employee_id = '$emp_id', brand = '$code' "; $crm->Insert($query); $send[list_id] = $list_id; echo $json->encode($send); exit(); } else { // make sure the list is there $query = "select employee_id from $BLASTER_LIST_NAME where brand = '$code' and blaster_list_id = '$list_id' "; $data = $crm->mydata($query); if(!$data[employee_id][0]) { echo"DWERROR: the list was not found, invalid list_id"; exit(); } if($data[employee_id][0]!=$emp_id) { echo"DWERROR: \"$owner_email\" is not the owner of this list"; exit(); } $query = "update $BLASTER_LIST_NAME set list_name = '".addslashes($list_name)."' where blaster_list_id = '$list_id' and employee_id = '$emp_id' and brand = '$code' "; $crm->update($query); $send[list_id] = $list_id; echo $json->encode($send); exit(); } } if($view_lists) { $query = "select list_name, employee_id, blaster_list_id from $BLASTER_LIST_NAME where brand = '$code' "; $data = $crm->mydata($query); if(!$data[list_name][0]) { echo"DWERROR: you must create a list first"; exit(); } for($a=0;$aencode($send_packet); exit(); } if($upload_list) { $emp_id = get_end_user_uid_email($owner_email,$code,$cdc); if(!$list_id) { echo"DWERROR: no list_id"; exit(); } $query = "select employee_id, list_name from $BLASTER_LIST_NAME where brand = '$code' and blaster_list_id = '$list_id' "; $data = $crm->mydata($query); if(!$data[employee_id][0]) { echo"DWERROR: the list was not found, invalid list_id"; exit(); } if(!$list_data) { echo"DWERROR: no list data"; exit(); } if($data[employee_id][0]!=$emp_id) { echo"DWERROR: \"$owner_email\" is not the owner of this list"; exit(); } $vars = get_object_vars($json->decode(ss($list_data))); $no_dupes[] = ''; for($a=0;$amydata($query); if($data[blaster_list_id][0]) { $query = "update $BLASTER_LIST set json_packet = '".ass($vars[vars][$a])."' where email = '".ass($the_email)."' and blaster_list_id = '$list_id' and brand = '$code' "; $crm->Update($query); echo "\n".$vars[email][$a]." updated"; } else { $query = "insert into $BLASTER_LIST set blaster_list_id = '$list_id', email = '".ass($the_email)."', json_packet = '".ass($vars[vars][$a])."', brand = '$code' "; $crm->Insert($query); echo "\n".$vars[email][$a]." inserted"; } $no_dupe[]=$the_email; } } else { if($vars[email][$a]!="") { echo "\n".$vars[email][$a]." invalid"; } } } exit(); } if($list_eblast) { if($owner_email) { $emp_id = get_end_user_uid_email($owner_email,$code,$cdc); $by_emp = "and employee_id = '$emp_id' "; } if($list_id) { $list_id = "and list_id = '$list_id' "; } $query = "select employee_id, list_id, email_message_id, subject, date_to_send, time_stamp from $CRM_EMAIL_MESSAGE where brand = '$code' $by_emp $list_id "; $data = $crm->mydata($query); for($a=0;$aencode($send); exit(); } if($delete_eblast) { $emp_id = get_end_user_uid_email($owner_email,$code,$cdc); $query = "select count(*) as count from $CRM_EMAIL_TO where message_sent_id = '$email_message_id' "; $data = $sql->mydata($query); // make sure this was not already sent to .... if($data[count][0]) { echo"DWERROR: This message was already sent and cannot be deleted."; exit(); } $query = "select email_message_id, date_to_send from $CRM_EMAIL_MESSAGE where brand = '$code' and employee_id = '$emp_id' and email_message_id = '".ass($email_message_id)."' "; $data = $crm->mydata($query); if(!$data[email_message_id][0]) { echo"DWERROR: email message not found for \"$owner_email / $email_message_id\" "; exit(); } $query = "delete from $CRM_EMAIL_MESSAGE where email_message_id = '".ass($email_message_id)."' and employee_id = '$emp_id' and brand = '$code' "; $crm->Delete($query); echo"DWSUCCESS"; exit(); } if($create_eblast || $update_eblast) { $emp_id = get_end_user_uid_email($owner_email,$code,$cdc); if(!$list_id) { echo"DWERROR: no list_id"; exit(); } $query = "select employee_id, list_name from $BLASTER_LIST_NAME where brand = '$code' and blaster_list_id = '$list_id' "; $data = $crm->mydata($query); if(!$data[employee_id][0]) { echo"DWERROR: the list was not found, invalid list_id"; exit(); } if($data[employee_id][0]!=$emp_id) { echo"DWERROR: \"$owner_email\" is not the owner of this list"; exit(); } if(!trim($text_body)) { echo"DWERROR: no text_body"; exit(); } if(!trim($subject)) { echo"DWERROR: no subject"; exit(); } if(!trim($from_name)) { echo"DWERROR: no from_name"; exit(); } if(!trim($from_email)) { echo"DWERROR: no from_email"; exit(); } if($data[employee_id][0]!=$emp_id) { echo"\nFound list \"".ss($data[list_name][0])."\" owned by $owner_email."; } if($update_eblast) { eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc); } if($create_eblast && $email_message_id) { echo"DWERROR: no email message id"; exit(); } if(!trim($date_to_send)) { echo"DWERROR: no date_to_send"; exit(); } if(substr($date_to_send,10,2)!='00' && substr($date_to_send,10,2)!='15' && substr($date_to_send,10,2)!='30' && substr($date_to_send,10,2)!='45') { echo"DWERROR: in correct time $date_to_send \"".substr($date_to_send,10,2)."\", valid are on the hour(00) 15 after, 30 after or 45 after"; exit(); } if(date("YmdHi")>$date_to_send) { echo"DWWARNING: this message will not be sent because the date is for the past."; } $html_body = ss($html_body); $text_body = ss($text_body); $zero = '00'; if(!$email_message_id) { $email_message_id = make_rand(); $query = "insert into $CRM_EMAIL_MESSAGE set list_id = '$list_id', email_message_id = '$email_message_id', from_email = '".ass($from_email)."', from_name = '".ass($from_name)."', subject = '".ass($subject)."', body = '".ass($text_body)."', html_body = '".ass($html_body)."', date_to_send = '$date_to_send$zero', employee_id = '$emp_id', brand = '$code' "; $crm->Insert($query); echo"eblast created"; } else { $query = "update $CRM_EMAIL_MESSAGE set from_email = '".ass($from_email)."', from_name = '".ass($from_name)."', subject = '".ass($subject)."', body = '".ass($text_body)."', html_body = '".ass($html_body)."', list_id = '$list_id', date_to_send = '$date_to_send$zero' where email_message_id = '$email_message_id' and employee_id = '$emp_id' and brand = '$code' "; $crm->Update($query); echo"eblast updated"; } // purge old links $query = "delete from $BLASTER_LIST_REDIRECT where email_message_id = '$email_message_id' and brand = '$code' "; $crm->mydata($query); // get the urls $links = get_links($html_body); for($a=0;$aInsert($query); } $send[email_message_id] = $email_message_id; $send[links] = $links; echo $json->encode($stats); exit(); } if($eblast_stats) { eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc); // get number of sent $query = "select count(message_sent_id) as count from $CRM_EMAIL_TO where message_sent_id = '$email_message_id' and brand = '$code' "; $data = $crm->mydata($query); $stats[sent] = $data[count][0]; // get number of opened $query = "select count(distinct(email)) as count from $BLASTER_LIST_OPENED where email_message_id = '$email_message_id' and brand = '$code' "; $data = $crm->mydata($query); $stats[opened] = $data[count][0]; // get the number of emails that unsubscribed because of this message $query = "select count(email_message_id) as count from $BLASTER_LIST_UNSUBSCRIBE where email_message_id = '$email_message_id' and brand = '$code' "; $data = $crm->mydata($query); $stats[unsubscribed] = $data[count][0]; // get number of bounces $bounce = new MySQL_class; $bounce->Create($email_db,$email_user,$email_host,$email_pass); $query = "select count(email) as count from $BOUNCED_EMAIL where email_message_id = '$email_message_id' "; $data = $bounce->mydata($query); $stats[bounced] = $data[count][0]; // get number of click throughs $query = "select $BLASTER_LIST_REDIRECT.url, count(distinct($BLASTER_LIST_REDIRECT_USAGE.email)) as count from $BLASTER_LIST_REDIRECT, $BLASTER_LIST_REDIRECT_USAGE where $BLASTER_LIST_REDIRECT.brand = '$code' and $BLASTER_LIST_REDIRECT_USAGE.id = $BLASTER_LIST_REDIRECT.id and $BLASTER_LIST_REDIRECT.email_message_id = '$email_message_id' group by $BLASTER_LIST_REDIRECT.url "; $click_data = $crm->mydata($query); for($a=0;$aencode($stats); exit(); } if($get_sent) { eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc); $query = "select email_address, date_format(time_stamp, '%Y-%m-%d') as date, date_format(time_stamp, '%H:%i:%s') as time from $CRM_EMAIL_TO where message_sent_id = '$email_message_id' and brand = '$code' "; $data = $crm->mydata($query); for($a=0;$aencode($sent); exit(); } if($get_bounced) { eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc); $bounce = new MySQL_class; $bounce->Create($email_db,$email_user,$email_host,$email_pass); $query = "select email, date_format(date, '%Y-%m-%d') as date, date_format(date, '%H:%i:%s') as time from $BOUNCED_EMAIL where email_message_id = '$email_message_id' "; $data = $bounce->mydata($query); for($a=0;$aencode($bounced); exit(); } if($get_opened) { eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc); $query = "select email, date_format(time_stamp, '%Y-%m-%d') as date, date_format(time_stamp, '%H:%i:%s') as time from $BLASTER_LIST_OPENED where email_message_id = '$email_message_id' and brand = '$code' "; $data = $crm->mydata($query); for($a=0;$aencode($opened); exit(); } if($get_unsubscribed) { eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc); $query = "select email, date_format(time_stamp, '%Y-%m-%d') as date, date_format(time_stamp, '%H:%i:%s') as time from $BLASTER_LIST_UNSUBSCRIBE where email_message_id = '$email_message_id' and brand = '$code' "; $data = $crm->mydata($query); for($a=0;$aencode($unsubscribed); exit(); } if($get_clicked) { eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc); $query = "select $BLASTER_LIST_REDIRECT.url, $BLASTER_LIST_REDIRECT_USAGE.email, date_format($BLASTER_LIST_REDIRECT_USAGE.time_stamp, '%Y-%m-%d') as date, date_format($BLASTER_LIST_REDIRECT_USAGE.time_stamp, '%H:%i:%s') as time from $BLASTER_LIST_REDIRECT, $BLASTER_LIST_REDIRECT_USAGE where $BLASTER_LIST_REDIRECT.brand = '$code' and $BLASTER_LIST_REDIRECT_USAGE.id = $BLASTER_LIST_REDIRECT.id and $BLASTER_LIST_REDIRECT.email_message_id = '$email_message_id' order by $BLASTER_LIST_REDIRECT.url,$BLASTER_LIST_REDIRECT_USAGE.email,$BLASTER_LIST_REDIRECT_USAGE.time_stamp"; $data = $crm->mydata($query); for($a=0;$aencode($clicked); exit(); } echo"DWWARNING: No action requested"; exit(); function eb_owner_ship_test($owner_email,$email_message_id,$code,$crm,$cdc) { global $CRM_EMAIL_MESSAGE,$CDC; $emp_id = get_end_user_uid_email($owner_email,$code,$cdc); if(!$email_message_id) { echo"DWERROR: no email_message_id"; exit(); } $query = "select employee_id from $CRM_EMAIL_MESSAGE where email_message_id = '$email_message_id' and brand = '$code' "; $data = $crm->mydata($query); if(!$data[employee_id][0]) { echo"DWERROR: no message for email_message_id \"$email_message_id\""; exit(); } if($data[employee_id][0]!=$emp_id) { echo"DWERROR: this message is not owned by \"$owner_email\""; exit(); } } ?>